@curvefi/api 2.63.1 → 2.63.3

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;
package/lib/dao.js CHANGED
@@ -193,7 +193,7 @@ const _extractNetworkFromPoolUrl = (poolUrl) => {
193
193
  return poolUrl.split("/")[4];
194
194
  };
195
195
  export const getVotingGaugeList = () => __awaiter(void 0, void 0, void 0, function* () {
196
- var _a;
196
+ var _a, _b;
197
197
  if (curve.chainId !== 1)
198
198
  throw Error("Ethereum-only method");
199
199
  const gaugeData = Object.values(yield _getAllGauges());
@@ -202,21 +202,21 @@ export const getVotingGaugeList = () => __awaiter(void 0, void 0, void 0, functi
202
202
  if ((gaugeData[i].is_killed || gaugeData[i].hasNoCrv) && Number(gaugeData[i].gauge_controller.gauge_relative_weight) === 0)
203
203
  continue;
204
204
  res.push({
205
- poolUrl: gaugeData[i].poolUrls.swap[0],
206
- network: _extractNetworkFromPoolUrl(gaugeData[i].poolUrls.swap[0]),
205
+ poolUrl: ((_a = gaugeData[i].poolUrls) === null || _a === void 0 ? void 0 : _a.swap[0]) || '',
206
+ network: gaugeData[i].blockchainId,
207
207
  gaugeAddress: gaugeData[i].gauge,
208
- poolAddress: gaugeData[i].swap,
209
- lpTokenAddress: gaugeData[i].swap_token,
208
+ poolAddress: gaugeData[i].swap || '',
209
+ lpTokenAddress: gaugeData[i].swap_token || '',
210
210
  poolName: gaugeData[i].shortName,
211
211
  totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
212
212
  relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
213
- isKilled: (_a = gaugeData[i].is_killed) !== null && _a !== void 0 ? _a : false,
213
+ isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
214
214
  });
215
215
  }
216
216
  return res;
217
217
  });
218
218
  export const userGaugeVotes = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
219
- var _b;
219
+ var _c, _d;
220
220
  if (curve.chainId !== 1)
221
221
  throw Error("Ethereum-only method");
222
222
  address = _getAddress(address);
@@ -243,15 +243,15 @@ export const userGaugeVotes = (address = "") => __awaiter(void 0, void 0, void 0
243
243
  userFutureVeCrv: curve.formatUnits(veCrvBalance * votes[i][1] / BigInt(10000), 18),
244
244
  expired: dt === BigInt(0),
245
245
  gaugeData: {
246
- poolUrl: gaugeData[i].poolUrls.swap[0],
247
- network: _extractNetworkFromPoolUrl(gaugeData[i].poolUrls.swap[0]),
246
+ poolUrl: ((_c = gaugeData[i].poolUrls) === null || _c === void 0 ? void 0 : _c.swap[0]) || '',
247
+ network: gaugeData[i].blockchainId,
248
248
  gaugeAddress: gaugeData[i].gauge,
249
- poolAddress: gaugeData[i].swap,
250
- lpTokenAddress: gaugeData[i].swap_token,
249
+ poolAddress: gaugeData[i].swap || '',
250
+ lpTokenAddress: gaugeData[i].swap_token || '',
251
251
  poolName: gaugeData[i].shortName,
252
252
  totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
253
253
  relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
254
- isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
254
+ isKilled: (_d = gaugeData[i].is_killed) !== null && _d !== void 0 ? _d : false,
255
255
  },
256
256
  });
257
257
  powerUsed += votes[i][1];
@@ -178,6 +178,7 @@ export interface IProfit {
178
178
  price: number;
179
179
  }
180
180
  export interface IGaugesDataFromApi {
181
+ blockchainId: string;
181
182
  gauge: string;
182
183
  swap: string;
183
184
  swap_token: string;
@@ -186,7 +187,7 @@ export interface IGaugesDataFromApi {
186
187
  gauge_relative_weight: string;
187
188
  get_gauge_weight: string;
188
189
  };
189
- poolUrls: {
190
+ poolUrls?: {
190
191
  swap: string[];
191
192
  };
192
193
  is_killed?: boolean;
@@ -263,3 +264,48 @@ export interface IBasePoolShortItem {
263
264
  token: string;
264
265
  }
265
266
  export type TVoteType = "PARAMETER" | "OWNERSHIP";
267
+ export type AbiParameter = {
268
+ type: string;
269
+ name?: string;
270
+ components?: readonly AbiParameter[];
271
+ };
272
+ type CtorMutability = 'payable' | 'nonpayable';
273
+ export type AbiStateMutability = 'pure' | 'view' | CtorMutability;
274
+ export type AbiFunction = {
275
+ type: 'function';
276
+ constant?: boolean;
277
+ gas?: number;
278
+ inputs: readonly AbiParameter[];
279
+ name: string;
280
+ outputs: readonly AbiParameter[];
281
+ payable?: boolean | undefined;
282
+ stateMutability: AbiStateMutability;
283
+ };
284
+ export type AbiConstructor = {
285
+ type: 'constructor';
286
+ inputs: readonly AbiParameter[];
287
+ payable?: boolean;
288
+ stateMutability: CtorMutability;
289
+ };
290
+ export type AbiFallback = {
291
+ type: 'fallback';
292
+ payable?: boolean;
293
+ stateMutability: CtorMutability;
294
+ };
295
+ export type AbiReceive = {
296
+ type: 'receive';
297
+ stateMutability: Extract<AbiStateMutability, 'payable'>;
298
+ };
299
+ export type AbiEvent = {
300
+ type: 'event';
301
+ anonymous?: boolean;
302
+ inputs: readonly AbiParameter[];
303
+ name: string;
304
+ };
305
+ export type AbiError = {
306
+ type: 'error';
307
+ inputs: readonly AbiParameter[];
308
+ name: string;
309
+ };
310
+ export type Abi = (AbiConstructor | AbiError | AbiEvent | AbiFallback | AbiFunction | AbiReceive)[];
311
+ 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.3",
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": {