@curvefi/api 2.63.1 → 2.63.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/curve.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ethers, Contract, Networkish, BigNumberish, Numeric, BrowserProvider, JsonRpcProvider, Signer } from "ethers";
2
2
  import { Provider as MulticallProvider, Contract as MulticallContract } from "@curvefi/ethcall";
3
- import { IPoolData, IDict, ICurve, INetworkName, IChainId, IFactoryPoolType } from "./interfaces";
3
+ import { IPoolData, IDict, ICurve, INetworkName, IChainId, IFactoryPoolType, Abi } from "./interfaces";
4
4
  export declare const memoizedContract: () => (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract;
5
5
  export declare const memoizedMulticallContract: () => (address: string, abi: any) => MulticallContract;
6
6
  export declare const NATIVE_TOKENS: {
@@ -14,6 +14,11 @@ export declare const NATIVE_TOKENS: {
14
14
  export declare const NETWORK_CONSTANTS: {
15
15
  [index: number]: any;
16
16
  };
17
+ export type ContractItem = {
18
+ contract: Contract;
19
+ multicallContract: MulticallContract;
20
+ abi: Abi;
21
+ };
17
22
  declare class Curve implements ICurve {
18
23
  provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
19
24
  multicallProvider: MulticallProvider;
@@ -21,10 +26,7 @@ declare class Curve implements ICurve {
21
26
  signerAddress: string;
22
27
  chainId: IChainId;
23
28
  contracts: {
24
- [index: string]: {
25
- contract: Contract;
26
- multicallContract: MulticallContract;
27
- };
29
+ [index: string]: ContractItem;
28
30
  };
29
31
  feeData: {
30
32
  gasPrice?: number;
@@ -263,3 +263,48 @@ export interface IBasePoolShortItem {
263
263
  token: string;
264
264
  }
265
265
  export type TVoteType = "PARAMETER" | "OWNERSHIP";
266
+ export type AbiParameter = {
267
+ type: string;
268
+ name?: string;
269
+ components?: readonly AbiParameter[];
270
+ };
271
+ type CtorMutability = 'payable' | 'nonpayable';
272
+ export type AbiStateMutability = 'pure' | 'view' | CtorMutability;
273
+ export type AbiFunction = {
274
+ type: 'function';
275
+ constant?: boolean;
276
+ gas?: number;
277
+ inputs: readonly AbiParameter[];
278
+ name: string;
279
+ outputs: readonly AbiParameter[];
280
+ payable?: boolean | undefined;
281
+ stateMutability: AbiStateMutability;
282
+ };
283
+ export type AbiConstructor = {
284
+ type: 'constructor';
285
+ inputs: readonly AbiParameter[];
286
+ payable?: boolean;
287
+ stateMutability: CtorMutability;
288
+ };
289
+ export type AbiFallback = {
290
+ type: 'fallback';
291
+ payable?: boolean;
292
+ stateMutability: CtorMutability;
293
+ };
294
+ export type AbiReceive = {
295
+ type: 'receive';
296
+ stateMutability: Extract<AbiStateMutability, 'payable'>;
297
+ };
298
+ export type AbiEvent = {
299
+ type: 'event';
300
+ anonymous?: boolean;
301
+ inputs: readonly AbiParameter[];
302
+ name: string;
303
+ };
304
+ export type AbiError = {
305
+ type: 'error';
306
+ inputs: readonly AbiParameter[];
307
+ name: string;
308
+ };
309
+ export type Abi = (AbiConstructor | AbiError | AbiEvent | AbiFallback | AbiFunction | AbiReceive)[];
310
+ export {};
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import memoize from "memoizee";
11
11
  import { _getAllGaugesFormatted, _getPoolsFromApi } from '../external-api.js';
12
- import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, isMethodExist, getVolumeApiController, } from '../utils.js';
12
+ import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, findAbiFunction, getVolumeApiController, } from '../utils.js';
13
13
  import { curve } from "../curve.js";
14
14
  import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
15
15
  import { GaugePool } from "./gaugePool.js";
@@ -730,8 +730,7 @@ export class PoolTemplate {
730
730
  return [BN(1), toBN(_vp)];
731
731
  }
732
732
  //for crvusd and stable-ng implementations
733
- const isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
734
- if (isUseStoredRates) {
733
+ if (findAbiFunction(curve.contracts[this.address].abi, 'stored_rates').length > 0 && this.isPlain) {
735
734
  const _stored_rates = yield curve.contracts[this.address].contract.stored_rates();
736
735
  return _stored_rates.map((_r, i) => toBN(_r, 36 - this.wrappedDecimals[i]));
737
736
  }
@@ -873,8 +872,8 @@ export class PoolTemplate {
873
872
  return true; // TODO remove this for Kava and ZkSync
874
873
  if (this.gauge.address === curve.constants.ZERO_ADDRESS)
875
874
  throw Error(`${this.name} doesn't have gauge`);
876
- const gaugeContract = curve.contracts[this.gauge.address].contract;
877
- return !('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
875
+ return !findAbiFunction(curve.contracts[this.gauge.address].abi, 'inflation_rate')
876
+ .find((func) => ['', 'uint256'].includes(func.inputs.map((a) => `${a.type}`).join(',')));
878
877
  }
879
878
  statsWrappedBalances() {
880
879
  return __awaiter(this, void 0, void 0, function* () {
@@ -15,7 +15,7 @@ import { withdrawOneCoinWrappedExpected2argsMixin, withdrawOneCoinWrappedExpecte
15
15
  import { withdrawOneCoinWrappedLendingOrCryptoMixin, withdrawOneCoinWrappedMixin } from "./mixins/withdrawOneCoinWrappedMixins.js";
16
16
  import { swapTricrypto2Mixin, swapMetaFactoryMixin, swapCryptoMetaFactoryMixin, swapMixin } from "./mixins/swapMixins.js";
17
17
  import { swapWrappedExpectedAndApproveMixin, swapWrappedTricrypto2Mixin, swapWrappedMixin, swapWrappedRequiredMixin, } from "./mixins/swapWrappedMixins.js";
18
- import { getCountArgsOfMethodByContract } from "../utils.js";
18
+ import { getCountArgsOfMethodByAbi, findAbiSignature } from "../utils.js";
19
19
  export const getPool = (poolId) => {
20
20
  const poolDummy = new PoolTemplate(poolId);
21
21
  class Pool extends PoolTemplate {
@@ -55,7 +55,7 @@ export const getPool = (poolId) => {
55
55
  else if (poolDummy.zap && poolId !== 'susd') {
56
56
  Object.assign(Pool.prototype, depositZapMixin);
57
57
  }
58
- else if (getCountArgsOfMethodByContract(curve.contracts[poolDummy.address].contract, 'add_liquidity') > 2) {
58
+ else if (getCountArgsOfMethodByAbi(curve.contracts[poolDummy.address].abi, 'add_liquidity') > 2) {
59
59
  Object.assign(Pool.prototype, depositLendingOrCryptoMixin);
60
60
  }
61
61
  else {
@@ -92,7 +92,7 @@ export const getPool = (poolId) => {
92
92
  else if (poolDummy.zap && poolId !== 'susd') {
93
93
  Object.assign(Pool.prototype, withdrawZapMixin);
94
94
  }
95
- else if (getCountArgsOfMethodByContract(curve.contracts[poolDummy.address].contract, 'remove_liquidity') > 2) {
95
+ else if (getCountArgsOfMethodByAbi(curve.contracts[poolDummy.address].abi, 'remove_liquidity') > 2) {
96
96
  Object.assign(Pool.prototype, withdrawLendingOrCryptoMixin);
97
97
  }
98
98
  else {
@@ -158,7 +158,7 @@ export const getPool = (poolId) => {
158
158
  else if (poolDummy.zap) { // including susd
159
159
  Object.assign(Pool.prototype, withdrawOneCoinZapMixin);
160
160
  }
161
- else if (getCountArgsOfMethodByContract(curve.contracts[poolDummy.address].contract, 'remove_liquidity_one_coin') > 3) {
161
+ else if (getCountArgsOfMethodByAbi(curve.contracts[poolDummy.address].abi, 'remove_liquidity_one_coin') > 3) {
162
162
  Object.assign(Pool.prototype, withdrawOneCoinLendingOrCryptoMixin);
163
163
  }
164
164
  else {
@@ -183,7 +183,7 @@ export const getPool = (poolId) => {
183
183
  }
184
184
  }
185
185
  // swap and swapEstimateGas
186
- if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve.contracts[poolDummy.address].contract &&
186
+ if (findAbiSignature(curve.contracts[poolDummy.address].abi, 'exchange', 'uint256,uint256,uint256,uint256,bool') &&
187
187
  !(curve.chainId === 100 && poolDummy.id === "tricrypto")) { // tricrypto2 (eth), tricrypto (arbitrum), avaxcrypto (avalanche); 100 is xDAI
188
188
  Object.assign(Pool.prototype, swapTricrypto2Mixin);
189
189
  }
@@ -202,7 +202,7 @@ export const getPool = (poolId) => {
202
202
  if (!poolDummy.isPlain && !poolDummy.isFake) {
203
203
  Object.assign(Pool.prototype, swapWrappedExpectedAndApproveMixin);
204
204
  Object.assign(Pool.prototype, swapWrappedRequiredMixin);
205
- if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve.contracts[poolDummy.address].contract) { // tricrypto2 (eth), tricrypto (arbitrum)
205
+ if (findAbiSignature(curve.contracts[poolDummy.address].abi, 'exchange', 'uint256,uint256,uint256,uint256,bool')) { // tricrypto2 (eth), tricrypto (arbitrum)
206
206
  Object.assign(Pool.prototype, swapWrappedTricrypto2Mixin);
207
207
  }
208
208
  else {
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Contract } from 'ethers';
2
1
  import BigNumber from 'bignumber.js';
3
- import { IBasePoolShortItem, IChainId, IDict, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
2
+ import { Abi, AbiFunction, IBasePoolShortItem, IChainId, IDict, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
4
3
  export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
5
4
  export declare const MAX_ALLOWANCE: bigint;
6
5
  export declare const _cutZeros: (strn: string) => string;
@@ -60,8 +59,9 @@ export declare const getCoinsData: (...coins: string[] | string[][]) => Promise<
60
59
  }[]>;
61
60
  export declare const hasDepositAndStake: () => boolean;
62
61
  export declare const hasRouter: () => boolean;
63
- export declare const getCountArgsOfMethodByContract: (contract: Contract, methodName: string) => number;
64
- export declare const isMethodExist: (contract: Contract, methodName: string) => boolean;
62
+ export declare const findAbiFunction: (abi: Abi, methodName: string) => AbiFunction[];
63
+ export declare const getCountArgsOfMethodByAbi: (abi: Abi, methodName: string) => number;
64
+ export declare const findAbiSignature: (abi: Abi, methodName: string, signature: string) => AbiFunction | undefined;
65
65
  export declare const getPoolName: (name: string) => string;
66
66
  export declare const isStableNgPool: (name: string) => boolean;
67
67
  export declare const assetTypeNameHandler: (assetTypeName: string) => REFERENCE_ASSET;
package/lib/utils.js CHANGED
@@ -569,6 +569,7 @@ export const getVolume = (network = curve.chainId) => __awaiter(void 0, void 0,
569
569
  });
570
570
  export const _setContracts = (address, abi) => {
571
571
  curve.contracts[address] = {
572
+ abi,
572
573
  contract: new Contract(address, abi, curve.signer || curve.provider),
573
574
  multicallContract: new MulticallContract(address, abi),
574
575
  };
@@ -626,16 +627,9 @@ export const getCoinsData = (...coins) => __awaiter(void 0, void 0, void 0, func
626
627
  });
627
628
  export const hasDepositAndStake = () => curve.constants.ALIASES.deposit_and_stake !== curve.constants.ZERO_ADDRESS;
628
629
  export const hasRouter = () => curve.constants.ALIASES.router !== curve.constants.ZERO_ADDRESS;
629
- export const getCountArgsOfMethodByContract = (contract, methodName) => {
630
- const func = contract.interface.fragments.find((item) => item.name === methodName);
631
- if (func) {
632
- return func.inputs.length;
633
- }
634
- else {
635
- return -1;
636
- }
637
- };
638
- export const isMethodExist = (contract, methodName) => contract.interface.fragments.find((item) => item.name === methodName) !== undefined;
630
+ export const findAbiFunction = (abi, methodName) => abi.filter((item) => item.type == 'function' && item.name === methodName);
631
+ export const getCountArgsOfMethodByAbi = (abi, methodName) => { var _a, _b; return (_b = (_a = findAbiFunction(abi, methodName)[0]) === null || _a === void 0 ? void 0 : _a.inputs.length) !== null && _b !== void 0 ? _b : -1; };
632
+ export const findAbiSignature = (abi, methodName, signature) => findAbiFunction(abi, methodName).find((func) => func.inputs.map((i) => `${i.type}`).join(',') == signature);
639
633
  export const getPoolName = (name) => {
640
634
  const separatedName = name.split(": ");
641
635
  if (separatedName.length > 1) {
@@ -645,9 +639,7 @@ export const getPoolName = (name) => {
645
639
  return separatedName[0].trim();
646
640
  }
647
641
  };
648
- export const isStableNgPool = (name) => {
649
- return name.includes('factory-stable-ng');
650
- };
642
+ export const isStableNgPool = (name) => name.includes('factory-stable-ng');
651
643
  export const assetTypeNameHandler = (assetTypeName) => {
652
644
  if (assetTypeName.toUpperCase() === 'UNKNOWN') {
653
645
  return 'OTHER';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.63.1",
3
+ "version": "2.63.2",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -14,7 +14,8 @@
14
14
  "url": "https://github.com/curvefi/curve-js/issues"
15
15
  },
16
16
  "scripts": {
17
- "build": "rm -rf lib && tsc -p tsconfig.build.json"
17
+ "build": "rm -rf lib && tsc -p tsconfig.build.json",
18
+ "lint": "eslint src --ext .ts"
18
19
  },
19
20
  "type": "module",
20
21
  "devDependencies": {