@curvefi/api 2.66.26 → 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.
- package/lib/cached.d.ts +5 -0
- package/lib/cached.js +45 -0
- package/lib/external-api.d.ts +3 -2
- package/lib/external-api.js +92 -24
- package/lib/factory/deploy.d.ts +52 -14
- package/lib/factory/factory-api.js +1 -1
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +5 -2
- package/lib/pools/subClasses/corePool.js +5 -1
- package/lib/pools/subClasses/statsPool.js +2 -2
- package/lib/pools/utils.js +1 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.js +2 -90
- package/package.json +23 -21
package/lib/cached.d.ts
ADDED
|
@@ -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
|
+
});
|
package/lib/external-api.d.ts
CHANGED
|
@@ -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
|
|
4
|
-
export declare const
|
|
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>>;
|
package/lib/external-api.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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}`);
|
package/lib/factory/deploy.d.ts
CHANGED
|
@@ -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,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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,
|
|
11
|
-
|
|
12
|
-
export declare const
|
|
13
|
-
|
|
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,
|
|
16
|
-
|
|
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,
|
|
19
|
-
|
|
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,
|
|
22
|
-
|
|
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 "../
|
|
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
|
-
|
|
22
|
-
|
|
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
|
|
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 '../../
|
|
12
|
-
import { _getUsdRate, BN, toBN,
|
|
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* () {
|
package/lib/pools/utils.js
CHANGED
|
@@ -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 "../
|
|
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 {
|
|
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.
|
|
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
|
|
21
|
-
"lint": "eslint src",
|
|
22
|
-
"
|
|
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.
|
|
27
|
-
"@eslint/eslintrc": "^3.
|
|
28
|
-
"@eslint/js": "^9.
|
|
29
|
-
"@types/chai": "^5.
|
|
30
|
-
"@types/memoizee": "^0.4.
|
|
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.
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
34
|
-
"@typescript-eslint/parser": "^8.
|
|
35
|
-
"chai": "^5.
|
|
36
|
-
"eslint": "^9.
|
|
37
|
-
"globals": "^
|
|
38
|
-
"mocha": "^11.0
|
|
39
|
-
"typescript": "^5.
|
|
40
|
-
"vue-eslint-parser": "^
|
|
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.
|
|
44
|
-
"bignumber.js": "^9.
|
|
45
|
-
"ethers": "^6.
|
|
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
|
}
|