@curvefi/api 2.66.25 → 2.66.27

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.
@@ -0,0 +1,5 @@
1
+ import { IDict, IExtendedPoolDataFromApi, INetworkName, IPoolType } from "./interfaces.js";
2
+ export declare const _getPoolsFromApi: (network: INetworkName, poolType: IPoolType, isLiteChain?: boolean) => Promise<IExtendedPoolDataFromApi>;
3
+ export declare const _getAllPoolsFromApi: (network: INetworkName, isLiteChain?: boolean) => Promise<IExtendedPoolDataFromApi[]>;
4
+ export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
5
+ export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
package/lib/cached.js ADDED
@@ -0,0 +1,45 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import memoize from "memoizee";
11
+ import { uncached_getAllPoolsFromApi, createCrvApyDict, createUsdPricesDict } from './external-api.js';
12
+ import { curve } from "./curve";
13
+ /**
14
+ * This function is used to cache the data fetched from the API and the data derived from it.
15
+ * Note: do not expose this function to the outside world, instead encapsulate it in a function that returns the data you need.
16
+ */
17
+ const _getCachedData = memoize((network, isLiteChain) => __awaiter(void 0, void 0, void 0, function* () {
18
+ const poolsDict = yield uncached_getAllPoolsFromApi(network, isLiteChain);
19
+ const poolLists = Object.values(poolsDict);
20
+ const usdPrices = createUsdPricesDict(poolLists);
21
+ const crvApy = createCrvApyDict(poolLists);
22
+ return { poolsDict, poolLists, usdPrices, crvApy };
23
+ }), {
24
+ promise: true,
25
+ maxAge: 5 * 60 * 1000, // 5m
26
+ primitive: true,
27
+ });
28
+ export const _getPoolsFromApi = (network_1, poolType_1, ...args_1) => __awaiter(void 0, [network_1, poolType_1, ...args_1], void 0, function* (network, poolType, isLiteChain = false) {
29
+ const { poolsDict } = yield _getCachedData(network, isLiteChain);
30
+ return poolsDict[poolType];
31
+ });
32
+ export const _getAllPoolsFromApi = (network_1, ...args_1) => __awaiter(void 0, [network_1, ...args_1], void 0, function* (network, isLiteChain = false) {
33
+ const { poolLists } = yield _getCachedData(network, isLiteChain);
34
+ return poolLists;
35
+ });
36
+ export const _getUsdPricesFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
37
+ const network = curve.constants.NETWORK_NAME;
38
+ const { usdPrices } = yield _getCachedData(network, false);
39
+ return usdPrices;
40
+ });
41
+ export const _getCrvApyFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
42
+ const network = curve.constants.NETWORK_NAME;
43
+ const { crvApy } = yield _getCachedData(network, false);
44
+ return crvApy;
45
+ });
@@ -15,4 +15,5 @@ import { COINS_BSC } from "./bsc.js";
15
15
  import { COINS_FRAXTAL } from "./fraxtal.js";
16
16
  import { COINS_XLAYER } from "./xlayer.js";
17
17
  import { COINS_MANTLE } from "./mantle.js";
18
- export { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum, COINS_POLYGON, aTokensPolygon, COINS_FANTOM, cTokensFantom, aTokensFantom, COINS_AVALANCHE, aTokensAvalanche, COINS_ARBITRUM, COINS_OPTIMISM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_XLAYER, COINS_MANTLE, };
18
+ import { COINS_SONIC } from "./sonic.js";
19
+ export { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum, COINS_POLYGON, aTokensPolygon, COINS_FANTOM, cTokensFantom, aTokensFantom, COINS_AVALANCHE, aTokensAvalanche, COINS_ARBITRUM, COINS_OPTIMISM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_XLAYER, COINS_MANTLE, COINS_SONIC, };
@@ -15,4 +15,5 @@ import { COINS_BSC } from "./bsc.js";
15
15
  import { COINS_FRAXTAL } from "./fraxtal.js";
16
16
  import { COINS_XLAYER } from "./xlayer.js";
17
17
  import { COINS_MANTLE } from "./mantle.js";
18
- export { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum, COINS_POLYGON, aTokensPolygon, COINS_FANTOM, cTokensFantom, aTokensFantom, COINS_AVALANCHE, aTokensAvalanche, COINS_ARBITRUM, COINS_OPTIMISM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_XLAYER, COINS_MANTLE, };
18
+ import { COINS_SONIC } from "./sonic.js";
19
+ export { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum, COINS_POLYGON, aTokensPolygon, COINS_FANTOM, cTokensFantom, aTokensFantom, COINS_AVALANCHE, aTokensAvalanche, COINS_ARBITRUM, COINS_OPTIMISM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_XLAYER, COINS_MANTLE, COINS_SONIC, };
@@ -1,8 +1,6 @@
1
1
  import { lowerCaseValues } from "./utils.js";
2
- import { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, POOLS_DATA_XLAYER, POOLS_DATA_MANTLE, } from './pools/index.js';
3
- import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum, COINS_OPTIMISM, COINS_POLYGON, aTokensPolygon, COINS_FANTOM, cTokensFantom, aTokensFantom, COINS_AVALANCHE, aTokensAvalanche, COINS_ARBITRUM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_XLAYER, COINS_MANTLE, } from "./coins/index.js";
4
- import { POOLS_DATA_SONIC } from "./pools/sonic";
5
- import { COINS_SONIC } from "./coins/sonic";
2
+ import { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, POOLS_DATA_XLAYER, POOLS_DATA_MANTLE, POOLS_DATA_SONIC, } from './pools/index.js';
3
+ import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum, COINS_OPTIMISM, COINS_POLYGON, aTokensPolygon, COINS_FANTOM, cTokensFantom, aTokensFantom, COINS_AVALANCHE, aTokensAvalanche, COINS_ARBITRUM, COINS_XDAI, COINS_MOONBEAM, COINS_AURORA, COINS_KAVA, COINS_CELO, COINS_ZKSYNC, COINS_BASE, COINS_BSC, COINS_FRAXTAL, COINS_XLAYER, COINS_MANTLE, COINS_SONIC, } from "./coins/index.js";
6
4
  const ALIASES_ETHEREUM = lowerCaseValues({
7
5
  "crv": "0xD533a949740bb3306d119CC777fa900bA034cd52", // <--- CHANGE
8
6
  "minter": '0xd061D61a4d941c39E5453435B6345Dc261C2fcE0', // <--- RECOVERED
@@ -16,4 +16,5 @@ import { POOLS_DATA_BSC } from "./bsc.js";
16
16
  import { POOLS_DATA_FRAXTAL } from "./fraxtal.js";
17
17
  import { POOLS_DATA_XLAYER } from "./xlayer.js";
18
18
  import { POOLS_DATA_MANTLE } from "./mantle.js";
19
- export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, POOLS_DATA_XLAYER, POOLS_DATA_MANTLE, };
19
+ import { POOLS_DATA_SONIC } from "./sonic.js";
20
+ export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, POOLS_DATA_XLAYER, POOLS_DATA_MANTLE, POOLS_DATA_SONIC, };
@@ -16,4 +16,5 @@ import { POOLS_DATA_BSC } from "./bsc.js";
16
16
  import { POOLS_DATA_FRAXTAL } from "./fraxtal.js";
17
17
  import { POOLS_DATA_XLAYER } from "./xlayer.js";
18
18
  import { POOLS_DATA_MANTLE } from "./mantle.js";
19
- export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, POOLS_DATA_XLAYER, POOLS_DATA_MANTLE, };
19
+ import { POOLS_DATA_SONIC } from "./sonic.js";
20
+ export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, POOLS_DATA_BSC, POOLS_DATA_FRAXTAL, POOLS_DATA_XLAYER, POOLS_DATA_MANTLE, POOLS_DATA_SONIC, };
@@ -1,7 +1,8 @@
1
1
  import memoize from "memoizee";
2
2
  import { ICurveLiteNetwork, IDaoProposal, IDaoProposalListItem, IDict, IExtendedPoolDataFromApi, IGaugesDataFromApi, INetworkName, IPoolType, IVolumeAndAPYs } from "./interfaces";
3
- export declare const _getPoolsFromApi: ((network: INetworkName, poolType: IPoolType, isLiteChain?: any) => Promise<IExtendedPoolDataFromApi>) & memoize.Memoized<(network: INetworkName, poolType: IPoolType, isLiteChain?: any) => Promise<IExtendedPoolDataFromApi>>;
4
- export declare const _getAllPoolsFromApi: (network: INetworkName, isLiteChain?: boolean) => Promise<IExtendedPoolDataFromApi[]>;
3
+ export declare const uncached_getAllPoolsFromApi: (network: INetworkName, isLiteChain?: boolean) => Promise<Record<IPoolType, IExtendedPoolDataFromApi>>;
4
+ export declare const createUsdPricesDict: (allTypesExtendedPoolData: IExtendedPoolDataFromApi[]) => IDict<number>;
5
+ export declare const createCrvApyDict: (allTypesExtendedPoolData: IExtendedPoolDataFromApi[]) => IDict<[number, number]>;
5
6
  export declare const _getSubgraphData: ((network: INetworkName) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: INetworkName) => Promise<IVolumeAndAPYs>>;
6
7
  export declare const _getVolumes: ((network: string) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: string) => Promise<IVolumeAndAPYs>>;
7
8
  export declare const _getFactoryAPYs: ((network: string) => Promise<IVolumeAndAPYs>) & memoize.Memoized<(network: string) => Promise<IVolumeAndAPYs>>;
@@ -8,37 +8,105 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import memoize from "memoizee";
11
- export const _getPoolsFromApi = memoize((network_1, poolType_1, ...args_1) => __awaiter(void 0, [network_1, poolType_1, ...args_1], void 0, function* (network, poolType, isLiteChain = false) {
11
+ const uncached_getPoolsFromApi = (network_1, poolType_1, ...args_1) => __awaiter(void 0, [network_1, poolType_1, ...args_1], void 0, function* (network, poolType, isLiteChain = false) {
12
12
  var _a;
13
13
  const api = isLiteChain ? "https://api-core.curve.finance/v1/" : "https://api.curve.finance/api";
14
14
  const url = `${api}/getPools/${network}/${poolType}`;
15
15
  return (_a = yield fetchData(url)) !== null && _a !== void 0 ? _a : { poolData: [], tvl: 0, tvlAll: 0 };
16
- }), {
17
- promise: true,
18
- maxAge: 5 * 60 * 1000, // 5m
19
16
  });
20
- export const _getAllPoolsFromApi = (network_1, ...args_1) => __awaiter(void 0, [network_1, ...args_1], void 0, function* (network, isLiteChain = false) {
21
- if (isLiteChain) {
22
- return yield Promise.all([
23
- _getPoolsFromApi(network, "factory-twocrypto", isLiteChain),
24
- _getPoolsFromApi(network, "factory-tricrypto", isLiteChain),
25
- _getPoolsFromApi(network, "factory-stable-ng", isLiteChain),
26
- ]);
17
+ const getPoolTypes = (isLiteChain) => isLiteChain ? ["factory-twocrypto", "factory-tricrypto", "factory-stable-ng"] :
18
+ ["main", "crypto", "factory", "factory-crvusd", "factory-eywa", "factory-crypto", "factory-twocrypto", "factory-tricrypto", "factory-stable-ng"];
19
+ export const uncached_getAllPoolsFromApi = (network_1, ...args_1) => __awaiter(void 0, [network_1, ...args_1], void 0, function* (network, isLiteChain = false) {
20
+ return Object.fromEntries(yield Promise.all(getPoolTypes(isLiteChain).map((poolType) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const data = yield uncached_getPoolsFromApi(network, poolType, isLiteChain);
22
+ return [poolType, data];
23
+ }))));
24
+ });
25
+ export const createUsdPricesDict = (allTypesExtendedPoolData) => {
26
+ var _a, _b;
27
+ const priceDict = {};
28
+ const priceDictByMaxTvl = {};
29
+ for (const extendedPoolData of allTypesExtendedPoolData) {
30
+ for (const pool of extendedPoolData.poolData) {
31
+ const lpTokenAddress = (_a = pool.lpTokenAddress) !== null && _a !== void 0 ? _a : pool.address;
32
+ const totalSupply = pool.totalSupply / (Math.pow(10, 18));
33
+ if (lpTokenAddress.toLowerCase() in priceDict) {
34
+ priceDict[lpTokenAddress.toLowerCase()].push({
35
+ price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
36
+ tvl: pool.usdTotal,
37
+ });
38
+ }
39
+ else {
40
+ priceDict[lpTokenAddress.toLowerCase()] = [];
41
+ priceDict[lpTokenAddress.toLowerCase()].push({
42
+ price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
43
+ tvl: pool.usdTotal,
44
+ });
45
+ }
46
+ for (const coin of pool.coins) {
47
+ if (typeof coin.usdPrice === "number") {
48
+ if (coin.address.toLowerCase() in priceDict) {
49
+ priceDict[coin.address.toLowerCase()].push({
50
+ price: coin.usdPrice,
51
+ tvl: pool.usdTotal,
52
+ });
53
+ }
54
+ else {
55
+ priceDict[coin.address.toLowerCase()] = [];
56
+ priceDict[coin.address.toLowerCase()].push({
57
+ price: coin.usdPrice,
58
+ tvl: pool.usdTotal,
59
+ });
60
+ }
61
+ }
62
+ }
63
+ for (const coin of (_b = pool.gaugeRewards) !== null && _b !== void 0 ? _b : []) {
64
+ if (typeof coin.tokenPrice === "number") {
65
+ if (coin.tokenAddress.toLowerCase() in priceDict) {
66
+ priceDict[coin.tokenAddress.toLowerCase()].push({
67
+ price: coin.tokenPrice,
68
+ tvl: pool.usdTotal,
69
+ });
70
+ }
71
+ else {
72
+ priceDict[coin.tokenAddress.toLowerCase()] = [];
73
+ priceDict[coin.tokenAddress.toLowerCase()].push({
74
+ price: coin.tokenPrice,
75
+ tvl: pool.usdTotal,
76
+ });
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ for (const address in priceDict) {
83
+ if (priceDict[address].length) {
84
+ const maxTvlItem = priceDict[address].reduce((prev, current) => +current.tvl > +prev.tvl ? current : prev);
85
+ priceDictByMaxTvl[address] = maxTvlItem.price;
86
+ }
87
+ else {
88
+ priceDictByMaxTvl[address] = 0;
89
+ }
27
90
  }
28
- else {
29
- return yield Promise.all([
30
- _getPoolsFromApi(network, "main", isLiteChain),
31
- _getPoolsFromApi(network, "crypto", isLiteChain),
32
- _getPoolsFromApi(network, "factory", isLiteChain),
33
- _getPoolsFromApi(network, "factory-crvusd", isLiteChain),
34
- _getPoolsFromApi(network, "factory-eywa", isLiteChain),
35
- _getPoolsFromApi(network, "factory-crypto", isLiteChain),
36
- _getPoolsFromApi(network, "factory-twocrypto", isLiteChain),
37
- _getPoolsFromApi(network, "factory-tricrypto", isLiteChain),
38
- _getPoolsFromApi(network, "factory-stable-ng", isLiteChain),
39
- ]);
91
+ return priceDictByMaxTvl;
92
+ };
93
+ export const createCrvApyDict = (allTypesExtendedPoolData) => {
94
+ var _a, _b;
95
+ const apyDict = {};
96
+ for (const extendedPoolData of allTypesExtendedPoolData) {
97
+ for (const pool of extendedPoolData.poolData) {
98
+ if (pool.gaugeAddress) {
99
+ if (!pool.gaugeCrvApy) {
100
+ apyDict[pool.gaugeAddress.toLowerCase()] = [0, 0];
101
+ }
102
+ else {
103
+ apyDict[pool.gaugeAddress.toLowerCase()] = [(_a = pool.gaugeCrvApy[0]) !== null && _a !== void 0 ? _a : 0, (_b = pool.gaugeCrvApy[1]) !== null && _b !== void 0 ? _b : 0];
104
+ }
105
+ }
106
+ }
40
107
  }
41
- });
108
+ return apyDict;
109
+ };
42
110
  export const _getSubgraphData = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
43
111
  var _a, _b, _c;
44
112
  const data = yield fetchData(`https://api.curve.finance/api/getSubgraphData/${network}`);
@@ -1,25 +1,63 @@
1
1
  import { ethers } from "ethers";
2
- export declare const deployStablePlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, oracleAddress?: string, methodName?: string) => Promise<number>;
3
- export declare const deployStablePlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
4
- export declare const deployStableNgPlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, offpegFeeMultiplier: number | string, assetTypes: Array<0 | 1 | 2 | 3>, implementationIdx: 0, emaTime: number, oracleAddresses: string[], methodNames: string[]) => Promise<number>;
5
- export declare const deployStableNgPlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, offpegFeeMultiplier: number | string, assetTypes: Array<0 | 1 | 2 | 3>, implementationIdx: 0, emaTime: number, oracleAddresses: string[], methodNames: string[]) => Promise<ethers.ContractTransactionResponse>;
2
+ export declare const deployStablePlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, // %
3
+ assetType: 0 | 1 | 2 | 3, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
4
+ implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, // seconds
5
+ oracleAddress?: string, methodName?: string) => Promise<number>;
6
+ export declare const deployStablePlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, // %
7
+ assetType: 0 | 1 | 2 | 3, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
8
+ implementationIdx: 0 | 1 | 2 | 3 | 4 | 5, emaTime?: number, // seconds
9
+ oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
10
+ export declare const deployStableNgPlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, // %
11
+ offpegFeeMultiplier: number | string, assetTypes: Array<0 | 1 | 2 | 3>, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
12
+ implementationIdx: 0, emaTime: number, // seconds
13
+ oracleAddresses: string[], methodNames: string[]) => Promise<number>;
14
+ export declare const deployStableNgPlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, // %
15
+ offpegFeeMultiplier: number | string, assetTypes: Array<0 | 1 | 2 | 3>, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
16
+ implementationIdx: 0, emaTime: number, // seconds
17
+ oracleAddresses: string[], methodNames: string[]) => Promise<ethers.ContractTransactionResponse>;
6
18
  export declare const getDeployedStablePlainPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
7
19
  export declare const _setOracle: (poolAddress: string, oracleAddress: string, methodName: string, estimateGas: boolean) => Promise<ethers.ContractTransactionResponse | number>;
8
20
  export declare const setOracleEstimateGas: (poolAddress: string, oracleAddress?: string, methodName?: string) => Promise<number>;
9
21
  export declare const setOracle: (poolAddress: string, oracleAddress?: string, methodName?: string) => Promise<ethers.ContractTransactionResponse>;
10
- export declare const deployStableMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<number>;
11
- export declare const deployStableMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<ethers.ContractTransactionResponse>;
12
- export declare const deployStableNgMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, offpegFeeMultiplier: number | string, assetType: 0 | 1 | 2 | 3, emaTime: number, implementationIdx: 0, methodName: string, oracleAddress: string) => Promise<number>;
13
- export declare const deployStableNgMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, offpegFeeMultiplier: number | string, emaTime: number, implementationIdx: 0, assetType: 0 | 1 | 2 | 3, methodName: string, oracleAddress: string) => Promise<ethers.ContractTransactionResponse>;
22
+ export declare const deployStableMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, // %
23
+ implementationIdx: 0 | 1) => Promise<number>;
24
+ export declare const deployStableMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, // %
25
+ implementationIdx: 0 | 1) => Promise<ethers.ContractTransactionResponse>;
26
+ export declare const deployStableNgMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, // %
27
+ offpegFeeMultiplier: number | string, assetType: 0 | 1 | 2 | 3, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
28
+ emaTime: number, // seconds
29
+ implementationIdx: 0, methodName: string, oracleAddress: string) => Promise<number>;
30
+ export declare const deployStableNgMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, // %
31
+ offpegFeeMultiplier: number | string, emaTime: number, // seconds
32
+ implementationIdx: 0, assetType: 0 | 1 | 2 | 3, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
33
+ methodName: string, oracleAddress: string) => Promise<ethers.ContractTransactionResponse>;
14
34
  export declare const getDeployedStableMetaPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
15
- export declare const deployCryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, initialPrice: number | string) => Promise<number>;
16
- export declare const deployCryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
35
+ export declare const deployCryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, // %
36
+ outFee: number | string, // %
37
+ allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, // Seconds
38
+ initialPrice: number | string) => Promise<number>;
39
+ export declare const deployCryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, // %
40
+ outFee: number | string, // %
41
+ allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, // Seconds
42
+ initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
17
43
  export declare const getDeployedCryptoPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
18
- export declare const deployTwocryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, initialPrice: number | string) => Promise<number>;
19
- export declare const deployTwocryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
44
+ export declare const deployTwocryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, // %
45
+ outFee: number | string, // %
46
+ allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, // Seconds
47
+ initialPrice: number | string) => Promise<number>;
48
+ export declare const deployTwocryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, // %
49
+ outFee: number | string, // %
50
+ allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number, // Seconds
51
+ initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
20
52
  export declare const getDeployedTwocryptoPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
21
- export declare const deployTricryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, emaTime: number, initialPrices: (number | string)[]) => Promise<number>;
22
- export declare const deployTricryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, emaTime: number, initialPrices: (number | string)[]) => Promise<ethers.ContractTransactionResponse>;
53
+ export declare const deployTricryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, // %
54
+ outFee: number | string, // %
55
+ allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, emaTime: number, // Seconds
56
+ initialPrices: (number | string)[]) => Promise<number>;
57
+ export declare const deployTricryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, // %
58
+ outFee: number | string, // %
59
+ allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, emaTime: number, // Seconds
60
+ initialPrices: (number | string)[]) => Promise<ethers.ContractTransactionResponse>;
23
61
  export declare const getDeployedTricryptoPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
24
62
  export declare const deployGaugeEstimateGas: (pool: string, factory: string) => Promise<number>;
25
63
  export declare const deployGauge: (pool: string, factory: string) => Promise<ethers.ContractTransactionResponse>;
@@ -16,7 +16,7 @@ import twocryptoFactorySwapABI from "../constants/abis/factory-twocrypto/factory
16
16
  import tricryptoFactorySwapABI from "../constants/abis/factory-tricrypto/factory-tricrypto-pool.json" with { type: 'json' };
17
17
  import tricryptoFactoryEthDisabledSwapABI from "../constants/abis/factory-tricrypto/factory-tricrypto-pool-eth-disabled.json" with { type: 'json' };
18
18
  import { getPoolIdByAddress, setFactoryZapContracts } from "./common.js";
19
- import { _getPoolsFromApi } from "../external-api.js";
19
+ import { _getPoolsFromApi } from "../cached.js";
20
20
  import { assetTypeNameHandler, getPoolName, isStableNgPool } from "../utils.js";
21
21
  import StableNgBasePoolZapABI from "../constants/abis/stable-ng-base-pool-zap.json" with { type: 'json' };
22
22
  import MetaStableSwapNGABI from "../constants/abis/factory-stable-ng/meta-stableswap-ng.json" with { type: 'json' };
@@ -18,8 +18,11 @@ function _depositBalancedAmounts(poolBalances, walletBalances, decimals) {
18
18
  // max that can be used according to the lowest relative wallet balance
19
19
  const balancedAmountsForEachScenarioBN = walletBalancesBN.map((_, i) => (walletBalancesBN.map((_, j) => (poolBalancesRatiosBN[j].times(walletBalancesBN[i]).div(poolBalancesRatiosBN[i])))));
20
20
  const firstCoinBalanceForEachScenarioBN = balancedAmountsForEachScenarioBN.map(([a]) => a);
21
- const scenarioWithLowestBalancesBN = firstCoinBalanceForEachScenarioBN.map(String).indexOf(BigNumber.min(...firstCoinBalanceForEachScenarioBN).toString());
22
- return balancedAmountsForEachScenarioBN[scenarioWithLowestBalancesBN].map((a, i) => a.toFixed(decimals[i]));
21
+ // get the scenario with the lowest balances, ignoring scenarios where the wallet balance is zero
22
+ const min = BigNumber.min(...firstCoinBalanceForEachScenarioBN.filter((b) => !b.isZero()));
23
+ const scenarioWithLowestBalancesBN = firstCoinBalanceForEachScenarioBN.map(String).indexOf(min.toString());
24
+ const bestScenario = balancedAmountsForEachScenarioBN[scenarioWithLowestBalancesBN];
25
+ return bestScenario.map((a, i) => walletBalancesBN[i].isZero() ? "0" : a.toFixed(decimals[i]));
23
26
  }
24
27
  // @ts-ignore
25
28
  export const depositBalancedAmountsMixin = {
@@ -3,7 +3,11 @@ import { GaugePool } from "./gaugePool.js";
3
3
  export class CorePool {
4
4
  constructor(id) {
5
5
  var _a, _b;
6
- const poolData = curve.getPoolsData()[id];
6
+ const poolsData = curve.getPoolsData();
7
+ if (!poolsData[id]) {
8
+ throw new Error(`Pool ${id} not found. Available pools: ${Object.keys(poolsData).join(', ')}`);
9
+ }
10
+ const poolData = poolsData[id];
7
11
  this.id = id;
8
12
  this.name = poolData.name;
9
13
  this.fullName = poolData.full_name;
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { curve } from "../../curve.js";
11
- import { _getPoolsFromApi } from '../../external-api.js';
12
- import { _getUsdRate, BN, toBN, _getCrvApyFromApi, _getRewardsFromApi, getVolumeApiController, } from '../../utils.js';
11
+ import { _getPoolsFromApi, _getCrvApyFromApi } from '../../cached.js';
12
+ import { _getUsdRate, BN, toBN, _getRewardsFromApi, getVolumeApiController, } from '../../utils.js';
13
13
  export class StatsPool {
14
14
  constructor(pool) {
15
15
  this.parameters = () => __awaiter(this, void 0, void 0, function* () {
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { getPool } from "./poolConstructor.js";
11
11
  import { curve } from "../curve.js";
12
12
  import { _getRewardsFromApi, _getUsdRate, _setContracts, toBN } from "../utils.js";
13
- import { _getAllPoolsFromApi } from "../external-api.js";
13
+ import { _getAllPoolsFromApi } from "../cached.js";
14
14
  import ERC20Abi from "../constants/abis/ERC20.json" with { type: 'json' };
15
15
  const BATCH_SIZE = 50;
16
16
  const batchedMulticall = (calls) => __awaiter(void 0, void 0, void 0, function* () {
package/lib/utils.d.ts CHANGED
@@ -33,8 +33,6 @@ export declare const _ensureAllowance: (coins: string[], amounts: bigint[], spen
33
33
  export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<number | number[]>;
34
34
  export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<string[]>;
35
35
  export declare const getPoolIdBySwapAddress: (swapAddress: string) => string;
36
- export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
37
- export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
38
36
  export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
39
37
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
40
38
  export declare const getUsdRate: (coin: string) => Promise<number>;
package/lib/utils.js CHANGED
@@ -11,7 +11,8 @@ import { Contract } from 'ethers';
11
11
  import { Contract as MulticallContract } from "@curvefi/ethcall";
12
12
  import BigNumber from 'bignumber.js';
13
13
  import { curve } from "./curve.js";
14
- import { _getAllPoolsFromApi, _getCurveLiteNetworks, _getFactoryAPYs, _getLiteNetworksData, _getSubgraphData, _getVolumes, } from "./external-api.js";
14
+ import { _getCurveLiteNetworks, _getFactoryAPYs, _getLiteNetworksData, _getSubgraphData, _getVolumes, } from "./external-api.js";
15
+ import { _getAllPoolsFromApi, _getUsdPricesFromApi } from "./cached.js";
15
16
  import ERC20Abi from './constants/abis/ERC20.json' with { type: 'json' };
16
17
  import { L2Networks } from './constants/L2Networks.js';
17
18
  import { volumeNetworks } from "./constants/volumeNetworks.js";
@@ -259,95 +260,6 @@ export const getPoolIdBySwapAddress = (swapAddress) => {
259
260
  return "";
260
261
  return poolIds[0][0];
261
262
  };
262
- export const _getUsdPricesFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
263
- var _a, _b;
264
- const network = curve.constants.NETWORK_NAME;
265
- const allTypesExtendedPoolData = yield _getAllPoolsFromApi(network, curve.isLiteChain);
266
- const priceDict = {};
267
- const priceDictByMaxTvl = {};
268
- for (const extendedPoolData of allTypesExtendedPoolData) {
269
- for (const pool of extendedPoolData.poolData) {
270
- const lpTokenAddress = (_a = pool.lpTokenAddress) !== null && _a !== void 0 ? _a : pool.address;
271
- const totalSupply = pool.totalSupply / (Math.pow(10, 18));
272
- if (lpTokenAddress.toLowerCase() in priceDict) {
273
- priceDict[lpTokenAddress.toLowerCase()].push({
274
- price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
275
- tvl: pool.usdTotal,
276
- });
277
- }
278
- else {
279
- priceDict[lpTokenAddress.toLowerCase()] = [];
280
- priceDict[lpTokenAddress.toLowerCase()].push({
281
- price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
282
- tvl: pool.usdTotal,
283
- });
284
- }
285
- for (const coin of pool.coins) {
286
- if (typeof coin.usdPrice === "number") {
287
- if (coin.address.toLowerCase() in priceDict) {
288
- priceDict[coin.address.toLowerCase()].push({
289
- price: coin.usdPrice,
290
- tvl: pool.usdTotal,
291
- });
292
- }
293
- else {
294
- priceDict[coin.address.toLowerCase()] = [];
295
- priceDict[coin.address.toLowerCase()].push({
296
- price: coin.usdPrice,
297
- tvl: pool.usdTotal,
298
- });
299
- }
300
- }
301
- }
302
- for (const coin of (_b = pool.gaugeRewards) !== null && _b !== void 0 ? _b : []) {
303
- if (typeof coin.tokenPrice === "number") {
304
- if (coin.tokenAddress.toLowerCase() in priceDict) {
305
- priceDict[coin.tokenAddress.toLowerCase()].push({
306
- price: coin.tokenPrice,
307
- tvl: pool.usdTotal,
308
- });
309
- }
310
- else {
311
- priceDict[coin.tokenAddress.toLowerCase()] = [];
312
- priceDict[coin.tokenAddress.toLowerCase()].push({
313
- price: coin.tokenPrice,
314
- tvl: pool.usdTotal,
315
- });
316
- }
317
- }
318
- }
319
- }
320
- }
321
- for (const address in priceDict) {
322
- if (priceDict[address].length) {
323
- const maxTvlItem = priceDict[address].reduce((prev, current) => +current.tvl > +prev.tvl ? current : prev);
324
- priceDictByMaxTvl[address] = maxTvlItem.price;
325
- }
326
- else {
327
- priceDictByMaxTvl[address] = 0;
328
- }
329
- }
330
- return priceDictByMaxTvl;
331
- });
332
- export const _getCrvApyFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
333
- var _a, _b;
334
- const network = curve.constants.NETWORK_NAME;
335
- const allTypesExtendedPoolData = yield _getAllPoolsFromApi(network, curve.isLiteChain);
336
- const apyDict = {};
337
- for (const extendedPoolData of allTypesExtendedPoolData) {
338
- for (const pool of extendedPoolData.poolData) {
339
- if (pool.gaugeAddress) {
340
- if (!pool.gaugeCrvApy) {
341
- apyDict[pool.gaugeAddress.toLowerCase()] = [0, 0];
342
- }
343
- else {
344
- apyDict[pool.gaugeAddress.toLowerCase()] = [(_a = pool.gaugeCrvApy[0]) !== null && _a !== void 0 ? _a : 0, (_b = pool.gaugeCrvApy[1]) !== null && _b !== void 0 ? _b : 0];
345
- }
346
- }
347
- }
348
- }
349
- return apyDict;
350
- });
351
263
  export const _getRewardsFromApi = () => __awaiter(void 0, void 0, void 0, function* () {
352
264
  var _a, _b;
353
265
  const network = curve.constants.NETWORK_NAME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.66.25",
3
+ "version": "2.66.27",
4
4
  "description": "JavaScript library for curve.finance",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -17,32 +17,34 @@
17
17
  "url": "https://github.com/curvefi/curve-js/issues"
18
18
  },
19
19
  "scripts": {
20
- "build": "rm -rf lib && tsc -p tsconfig.build.json",
21
- "lint": "eslint src",
22
- "tsc": "tsc -w"
20
+ "build": "rm -rf lib && tsc --project tsconfig.build.json",
21
+ "lint": "eslint src --ext .ts",
22
+ "lint:fix": "eslint src --fix",
23
+ "watch": "tsc --watch",
24
+ "watch:lib": "rm -rf lib && tsc --watch --project tsconfig.build.json"
23
25
  },
24
26
  "type": "module",
25
27
  "devDependencies": {
26
- "@babel/eslint-parser": "^7.25.9",
27
- "@eslint/eslintrc": "^3.2.0",
28
- "@eslint/js": "^9.16.0",
29
- "@types/chai": "^5.0.1",
30
- "@types/memoizee": "^0.4.11",
28
+ "@babel/eslint-parser": "^7.27.1",
29
+ "@eslint/eslintrc": "^3.3.1",
30
+ "@eslint/js": "^9.27.0",
31
+ "@types/chai": "^5.2.2",
32
+ "@types/memoizee": "^0.4.12",
31
33
  "@types/mocha": "^10.0.10",
32
- "@types/node": "^22.10.2",
33
- "@typescript-eslint/eslint-plugin": "^8.18.0",
34
- "@typescript-eslint/parser": "^8.18.0",
35
- "chai": "^5.1.2",
36
- "eslint": "^9.16.0",
37
- "globals": "^15.13.0",
38
- "mocha": "^11.0.1",
39
- "typescript": "^5.7.2",
40
- "vue-eslint-parser": "^9.4.3"
34
+ "@types/node": "^22.15.21",
35
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
36
+ "@typescript-eslint/parser": "^8.32.1",
37
+ "chai": "^5.2.0",
38
+ "eslint": "^9.27.0",
39
+ "globals": "^16.1.0",
40
+ "mocha": "^11.4.0",
41
+ "typescript": "^5.8.3",
42
+ "vue-eslint-parser": "^10.1.3"
41
43
  },
42
44
  "dependencies": {
43
- "@curvefi/ethcall": "6.0.12",
44
- "bignumber.js": "^9.1.2",
45
- "ethers": "^6.13.4",
45
+ "@curvefi/ethcall": "^6.0.13",
46
+ "bignumber.js": "^9.3.0",
47
+ "ethers": "^6.14.1",
46
48
  "memoizee": "^0.4.17"
47
49
  }
48
50
  }