@curvefi/api 2.28.3 → 2.29.0
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/README.md +6 -0
- package/lib/boosting.js +4 -4
- package/lib/constants/coins/ethereum.js +1 -2
- package/lib/constants/pools/ethereum.js +26 -2
- package/lib/curve.d.ts +2 -2
- package/lib/curve.js +2 -2
- package/lib/external-api.d.ts +11 -1
- package/lib/external-api.js +13 -9
- package/lib/factory/constants.js +4 -0
- package/lib/index.d.ts +10 -5
- package/lib/index.js +1 -0
- package/lib/interfaces.d.ts +2 -1
- package/lib/pools/PoolTemplate.js +2 -2
- package/lib/utils.d.ts +10 -5
- package/lib/utils.js +199 -112
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,6 +140,12 @@ import curve from "@curvefi/api";
|
|
|
140
140
|
(async () => {
|
|
141
141
|
await curve.getTVL();
|
|
142
142
|
// 7870819849.685552
|
|
143
|
+
await curve.getVolume();
|
|
144
|
+
// {
|
|
145
|
+
// totalVolume: 514893871.3481678,
|
|
146
|
+
// cryptoVolume: 162757004.96876568,
|
|
147
|
+
// cryptoShare: 31.609815930147377
|
|
148
|
+
// }
|
|
143
149
|
|
|
144
150
|
const balances1 = await curve.getBalances(['DAI', 'sUSD']);
|
|
145
151
|
// OR const balances1 = await curve.getBalances(['0x6B175474E89094C44Da98b954EedeAC495271d0F', '0x57Ab1ec28D129707052df4dF418D58a2D46d5f51']);
|
package/lib/boosting.js
CHANGED
|
@@ -180,7 +180,7 @@ exports.isApproved = isApproved;
|
|
|
180
180
|
var approveEstimateGas = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
181
181
|
return __generator(this, function (_a) {
|
|
182
182
|
switch (_a.label) {
|
|
183
|
-
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([curve_1.curve.constants.ALIASES.crv], [amount], curve_1.curve.constants.ALIASES.voting_escrow)];
|
|
183
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([curve_1.curve.constants.ALIASES.crv], [amount], curve_1.curve.constants.ALIASES.voting_escrow, false)];
|
|
184
184
|
case 1: return [2 /*return*/, _a.sent()];
|
|
185
185
|
}
|
|
186
186
|
});
|
|
@@ -189,7 +189,7 @@ exports.approveEstimateGas = approveEstimateGas;
|
|
|
189
189
|
var approve = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
190
190
|
return __generator(this, function (_a) {
|
|
191
191
|
switch (_a.label) {
|
|
192
|
-
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([curve_1.curve.constants.ALIASES.crv], [amount], curve_1.curve.constants.ALIASES.voting_escrow)];
|
|
192
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([curve_1.curve.constants.ALIASES.crv], [amount], curve_1.curve.constants.ALIASES.voting_escrow, false)];
|
|
193
193
|
case 1: return [2 /*return*/, _a.sent()];
|
|
194
194
|
}
|
|
195
195
|
});
|
|
@@ -233,7 +233,7 @@ var createLock = function (amount, days) { return __awaiter(void 0, void 0, void
|
|
|
233
233
|
case 0:
|
|
234
234
|
_amount = (0, utils_2.parseUnits)(amount);
|
|
235
235
|
unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
|
|
236
|
-
return [4 /*yield*/, (0, utils_2._ensureAllowance)([curve_1.curve.constants.ALIASES.crv], [_amount], curve_1.curve.constants.ALIASES.voting_escrow)];
|
|
236
|
+
return [4 /*yield*/, (0, utils_2._ensureAllowance)([curve_1.curve.constants.ALIASES.crv], [_amount], curve_1.curve.constants.ALIASES.voting_escrow, false)];
|
|
237
237
|
case 1:
|
|
238
238
|
_a.sent();
|
|
239
239
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.voting_escrow].contract;
|
|
@@ -278,7 +278,7 @@ var increaseAmount = function (amount) { return __awaiter(void 0, void 0, void 0
|
|
|
278
278
|
switch (_a.label) {
|
|
279
279
|
case 0:
|
|
280
280
|
_amount = (0, utils_2.parseUnits)(amount);
|
|
281
|
-
return [4 /*yield*/, (0, utils_2._ensureAllowance)([curve_1.curve.constants.ALIASES.crv], [_amount], curve_1.curve.constants.ALIASES.voting_escrow)];
|
|
281
|
+
return [4 /*yield*/, (0, utils_2._ensureAllowance)([curve_1.curve.constants.ALIASES.crv], [_amount], curve_1.curve.constants.ALIASES.voting_escrow, false)];
|
|
282
282
|
case 1:
|
|
283
283
|
_a.sent();
|
|
284
284
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.voting_escrow].contract;
|
|
@@ -9,7 +9,7 @@ exports.COINS_ETHEREUM = (0, utils_1.lowerCaseValues)({
|
|
|
9
9
|
ycdai: "0x99d1Fa417f94dcD62BfE781a1213c092a47041Bc",
|
|
10
10
|
ycusdc: "0x9777d7E2b60bB01759D0E2f8be2095df444cb07E",
|
|
11
11
|
ycusdt: "0x1bE5d71F2dA660BFdee8012dDc58D024448A0A59",
|
|
12
|
-
|
|
12
|
+
usdp: "0x8E870D67F660D95d5be530380D0eC0bd388289E1",
|
|
13
13
|
adai: "0x028171bCA77440897B824Ca71D1c56caC55b68A3",
|
|
14
14
|
ausdc: "0xBcca60bB61934080951369a648Fb03DF4F96263C",
|
|
15
15
|
ausdt: "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811",
|
|
@@ -34,7 +34,6 @@ exports.COINS_ETHEREUM = (0, utils_1.lowerCaseValues)({
|
|
|
34
34
|
rsv: "0x196f4727526eA7FB1e17b2071B3d8eAA38486988",
|
|
35
35
|
dusd: "0x5BC25f649fc4e26069dDF4cF4010F9f706c23831",
|
|
36
36
|
ust: "0xa47c8bf37f92abed4a126bda807a7b7498661acd",
|
|
37
|
-
usdp: "0x1456688345527bE1f37E9e627DA0837D6f08C925",
|
|
38
37
|
usdn: "0x674C6Ad92Fd080e4004b2312b45f796a192D27a0",
|
|
39
38
|
dai: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
|
40
39
|
usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
@@ -255,8 +255,8 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
255
255
|
gauge_address: '0x64E3C23bfc40722d3B649844055F1D51c1ac041d',
|
|
256
256
|
deposit_address: '0xA50cCc70b6a011CffDdf45057E39679379187287',
|
|
257
257
|
is_lending: true,
|
|
258
|
-
underlying_coins: ['DAI', 'USDC', 'USDT', '
|
|
259
|
-
wrapped_coins: ['ycDAI', 'ycUSDC', 'ycUSDT', '
|
|
258
|
+
underlying_coins: ['DAI', 'USDC', 'USDT', 'USDP'],
|
|
259
|
+
wrapped_coins: ['ycDAI', 'ycUSDC', 'ycUSDT', 'USDP'],
|
|
260
260
|
underlying_coin_addresses: [
|
|
261
261
|
'0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
262
262
|
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
@@ -1599,4 +1599,28 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
1599
1599
|
swap_abi: swap_json_44.default,
|
|
1600
1600
|
gauge_abi: gauge_v5_json_1.default,
|
|
1601
1601
|
},
|
|
1602
|
+
fraxusdp: {
|
|
1603
|
+
name: "fraxusdp",
|
|
1604
|
+
full_name: "fraxusdp",
|
|
1605
|
+
symbol: "fraxusdp",
|
|
1606
|
+
reference_asset: 'USD',
|
|
1607
|
+
swap_address: '0xaE34574AC03A15cd58A92DC79De7B1A0800F1CE3',
|
|
1608
|
+
token_address: '0xFC2838a17D8e8B1D5456E0a351B0708a09211147',
|
|
1609
|
+
gauge_address: '0xfb860600F1bE1f1c72A89B2eF5CAF345aff7D39d',
|
|
1610
|
+
is_plain: true,
|
|
1611
|
+
underlying_coins: ['FRAX', 'USDP'],
|
|
1612
|
+
wrapped_coins: ['FRAX', 'USDP'],
|
|
1613
|
+
underlying_coin_addresses: [
|
|
1614
|
+
'0x853d955aCEf822Db058eb8505911ED77F175b99e',
|
|
1615
|
+
'0x8E870D67F660D95d5be530380D0eC0bd388289E1',
|
|
1616
|
+
],
|
|
1617
|
+
wrapped_coin_addresses: [
|
|
1618
|
+
'0x853d955aCEf822Db058eb8505911ED77F175b99e',
|
|
1619
|
+
'0x8E870D67F660D95d5be530380D0eC0bd388289E1',
|
|
1620
|
+
],
|
|
1621
|
+
underlying_decimals: [18, 18],
|
|
1622
|
+
wrapped_decimals: [18, 18],
|
|
1623
|
+
swap_abi: swap_json_42.default,
|
|
1624
|
+
gauge_abi: gauge_v5_json_1.default,
|
|
1625
|
+
},
|
|
1602
1626
|
});
|
package/lib/curve.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ethers, Contract } from "ethers";
|
|
2
2
|
import { Networkish } from "@ethersproject/networks";
|
|
3
3
|
import { Provider as MulticallProvider, Contract as MulticallContract } from 'ethcall';
|
|
4
|
-
import { IPoolData, IDict, ICurve, INetworkName } from "./interfaces";
|
|
4
|
+
import { IPoolData, IDict, ICurve, INetworkName, IChainId } from "./interfaces";
|
|
5
5
|
export declare const NATIVE_TOKENS: {
|
|
6
6
|
[index: number]: {
|
|
7
7
|
symbol: string;
|
|
@@ -18,7 +18,7 @@ declare class Curve implements ICurve {
|
|
|
18
18
|
multicallProvider: MulticallProvider;
|
|
19
19
|
signer: ethers.Signer | null;
|
|
20
20
|
signerAddress: string;
|
|
21
|
-
chainId:
|
|
21
|
+
chainId: IChainId;
|
|
22
22
|
contracts: {
|
|
23
23
|
[index: string]: {
|
|
24
24
|
contract: Contract;
|
package/lib/curve.js
CHANGED
|
@@ -304,7 +304,7 @@ var Curve = /** @class */ (function () {
|
|
|
304
304
|
// @ts-ignore
|
|
305
305
|
this.signer = null;
|
|
306
306
|
this.signerAddress = '';
|
|
307
|
-
this.chainId =
|
|
307
|
+
this.chainId = 1;
|
|
308
308
|
// @ts-ignore
|
|
309
309
|
this.multicallProvider = null;
|
|
310
310
|
this.contracts = {};
|
|
@@ -337,7 +337,7 @@ var Curve = /** @class */ (function () {
|
|
|
337
337
|
// @ts-ignore
|
|
338
338
|
this.signer = null;
|
|
339
339
|
this.signerAddress = '';
|
|
340
|
-
this.chainId =
|
|
340
|
+
this.chainId = 1;
|
|
341
341
|
// @ts-ignore
|
|
342
342
|
this.multicallProvider = null;
|
|
343
343
|
this.contracts = {};
|
package/lib/external-api.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { IExtendedPoolDataFromApi, ISubgraphPoolData, IDict, INetworkName } from "./interfaces";
|
|
2
2
|
import memoize from "memoizee";
|
|
3
3
|
export declare const _getPoolsFromApi: ((network: INetworkName, poolType: "main" | "crypto" | "factory" | "factory-crypto") => Promise<IExtendedPoolDataFromApi>) & memoize.Memoized<(network: INetworkName, poolType: "main" | "crypto" | "factory" | "factory-crypto") => Promise<IExtendedPoolDataFromApi>>;
|
|
4
|
-
export declare const _getSubgraphData: ((network: INetworkName) => Promise<
|
|
4
|
+
export declare const _getSubgraphData: ((network: INetworkName) => Promise<{
|
|
5
|
+
poolsData: ISubgraphPoolData[];
|
|
6
|
+
totalVolume: number;
|
|
7
|
+
cryptoVolume: number;
|
|
8
|
+
cryptoShare: number;
|
|
9
|
+
}>) & memoize.Memoized<(network: INetworkName) => Promise<{
|
|
10
|
+
poolsData: ISubgraphPoolData[];
|
|
11
|
+
totalVolume: number;
|
|
12
|
+
cryptoVolume: number;
|
|
13
|
+
cryptoShare: number;
|
|
14
|
+
}>>;
|
|
5
15
|
export declare const _getLegacyAPYsAndVolumes: ((network: string) => Promise<IDict<{
|
|
6
16
|
apy: {
|
|
7
17
|
day: number;
|
package/lib/external-api.js
CHANGED
|
@@ -42,7 +42,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports._getHiddenPools = exports._getAllGauges = exports._getFactoryAPYsAndVolumes = exports._getLegacyAPYsAndVolumes = exports._getSubgraphData = exports._getPoolsFromApi = void 0;
|
|
43
43
|
var axios_1 = __importDefault(require("axios"));
|
|
44
44
|
var memoizee_1 = __importDefault(require("memoizee"));
|
|
45
|
-
var curve_1 = require("./curve");
|
|
46
45
|
exports._getPoolsFromApi = (0, memoizee_1.default)(function (network, poolType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
46
|
var url, response;
|
|
48
47
|
var _a;
|
|
@@ -62,15 +61,20 @@ exports._getPoolsFromApi = (0, memoizee_1.default)(function (network, poolType)
|
|
|
62
61
|
});
|
|
63
62
|
exports._getSubgraphData = (0, memoizee_1.default)(function (network) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
63
|
var url, response;
|
|
65
|
-
var _a;
|
|
66
|
-
return __generator(this, function (
|
|
67
|
-
switch (
|
|
64
|
+
var _a, _b, _c, _d;
|
|
65
|
+
return __generator(this, function (_e) {
|
|
66
|
+
switch (_e.label) {
|
|
68
67
|
case 0:
|
|
69
68
|
url = "https://api.curve.fi/api/getSubgraphData/".concat(network);
|
|
70
69
|
return [4 /*yield*/, axios_1.default.get(url, { validateStatus: function () { return true; } })];
|
|
71
70
|
case 1:
|
|
72
|
-
response =
|
|
73
|
-
return [2 /*return*/,
|
|
71
|
+
response = _e.sent();
|
|
72
|
+
return [2 /*return*/, {
|
|
73
|
+
poolsData: (_a = response.data.data.poolList) !== null && _a !== void 0 ? _a : [],
|
|
74
|
+
totalVolume: (_b = response.data.data.totalVolume) !== null && _b !== void 0 ? _b : 0,
|
|
75
|
+
cryptoVolume: (_c = response.data.data.cryptoVolume) !== null && _c !== void 0 ? _c : 0,
|
|
76
|
+
cryptoShare: (_d = response.data.data.cryptoShare) !== null && _d !== void 0 ? _d : 0,
|
|
77
|
+
}];
|
|
74
78
|
}
|
|
75
79
|
});
|
|
76
80
|
}); }, {
|
|
@@ -83,9 +87,9 @@ exports._getLegacyAPYsAndVolumes = (0, memoizee_1.default)(function (network) {
|
|
|
83
87
|
return __generator(this, function (_a) {
|
|
84
88
|
switch (_a.label) {
|
|
85
89
|
case 0:
|
|
86
|
-
if (
|
|
90
|
+
if (network === "kava" || network === "celo")
|
|
87
91
|
return [2 /*return*/, {}]; // Exclude Kava and Celo
|
|
88
|
-
url = "https://
|
|
92
|
+
url = "https://api.curve.fi/api/getMainPoolsAPYs/" + network;
|
|
89
93
|
return [4 /*yield*/, axios_1.default.get(url, { validateStatus: function () { return true; } })];
|
|
90
94
|
case 1:
|
|
91
95
|
data = (_a.sent()).data;
|
|
@@ -110,7 +114,7 @@ exports._getFactoryAPYsAndVolumes = (0, memoizee_1.default)(function (network) {
|
|
|
110
114
|
return __generator(this, function (_b) {
|
|
111
115
|
switch (_b.label) {
|
|
112
116
|
case 0:
|
|
113
|
-
if (
|
|
117
|
+
if (network === "aurora")
|
|
114
118
|
return [2 /*return*/, []]; // Exclude Aurora
|
|
115
119
|
url = "https://api.curve.fi/api/getFactoryAPYs-".concat(network);
|
|
116
120
|
return [4 /*yield*/, axios_1.default.get(url, { validateStatus: function () { return true; } })];
|
package/lib/factory/constants.js
CHANGED
|
@@ -44,6 +44,8 @@ exports.implementationABIDictEthereum = (0, utils_1.lowerCaseKeys)({
|
|
|
44
44
|
"0x55Aa9BF126bCABF0bDC17Fa9E39Ec9239e1ce7A9": MetaUSDBalances_json_1.default,
|
|
45
45
|
"0x33bB0e62d5e8C688E645Dd46DFb48Cd613250067": MetaFraxUSD_json_1.default,
|
|
46
46
|
"0x2EB24483Ef551dA247ab87Cf18e1Cc980073032D": MetaFraxUSDBalances_json_1.default,
|
|
47
|
+
"0xF9B62b61d108232Ef0C9DD143bb3c22c7D4A715a": MetaFraxUSD_json_1.default,
|
|
48
|
+
"0xB172AC2Fe440B5dA74Dc460e5E9d96bc2BF6261F": MetaFraxUSDBalances_json_1.default,
|
|
47
49
|
"0xC6A8466d128Fbfd34AdA64a9FFFce325D57C9a52": MetaBTC_json_1.default,
|
|
48
50
|
"0xc4C78b08fA0c3d0a312605634461A88184Ecd630": MetaBTCBalances_json_1.default,
|
|
49
51
|
"0xECAaecd9d2193900b424774133B1f51ae0F29d9E": MetaBTCRen_json_1.default,
|
|
@@ -223,6 +225,8 @@ exports.implementationBasePoolIdDictEthereum = (0, utils_1.lowerCaseKeys)({
|
|
|
223
225
|
"0x55Aa9BF126bCABF0bDC17Fa9E39Ec9239e1ce7A9": "3pool",
|
|
224
226
|
"0x33bB0e62d5e8C688E645Dd46DFb48Cd613250067": "fraxusdc",
|
|
225
227
|
"0x2EB24483Ef551dA247ab87Cf18e1Cc980073032D": "fraxusdc",
|
|
228
|
+
"0xF9B62b61d108232Ef0C9DD143bb3c22c7D4A715a": "fraxusdp",
|
|
229
|
+
"0xB172AC2Fe440B5dA74Dc460e5E9d96bc2BF6261F": "fraxusdp",
|
|
226
230
|
"0xC6A8466d128Fbfd34AdA64a9FFFce325D57C9a52": "sbtc",
|
|
227
231
|
"0xc4C78b08fA0c3d0a312605634461A88184Ecd630": "sbtc",
|
|
228
232
|
"0xECAaecd9d2193900b424774133B1f51ae0F29d9E": "ren",
|
package/lib/index.d.ts
CHANGED
|
@@ -47,18 +47,23 @@ declare const curve: {
|
|
|
47
47
|
PoolTemplate: typeof PoolTemplate;
|
|
48
48
|
getPool: (poolId: string) => PoolTemplate;
|
|
49
49
|
getUsdRate: (coin: string) => Promise<number>;
|
|
50
|
-
getTVL: (
|
|
50
|
+
getTVL: (network?: import("./interfaces").INetworkName | import("./interfaces").IChainId) => Promise<number>;
|
|
51
51
|
getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<string[] | import("./interfaces").IDict<string[]>>;
|
|
52
52
|
getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
53
53
|
hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
|
|
54
|
-
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string) => Promise<string[]>;
|
|
54
|
+
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
55
55
|
getCoinsData: (...coins: string[] | string[][]) => Promise<{
|
|
56
56
|
name: string;
|
|
57
57
|
symbol: string;
|
|
58
58
|
decimals: number;
|
|
59
59
|
}[]>;
|
|
60
|
+
getVolume: (network?: import("./interfaces").INetworkName | import("./interfaces").IChainId) => Promise<{
|
|
61
|
+
totalVolume: number;
|
|
62
|
+
cryptoVolume: number;
|
|
63
|
+
cryptoShare: number;
|
|
64
|
+
}>;
|
|
60
65
|
factory: {
|
|
61
|
-
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 |
|
|
66
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<ethers.ContractTransaction>;
|
|
62
67
|
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<ethers.ContractTransaction>;
|
|
63
68
|
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransaction>;
|
|
64
69
|
getDeployedPlainPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
@@ -66,7 +71,7 @@ declare const curve: {
|
|
|
66
71
|
getDeployedGaugeAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
67
72
|
fetchRecentlyDeployedPool: typeof fetchRecentlyDeployedFactoryPool;
|
|
68
73
|
estimateGas: {
|
|
69
|
-
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 |
|
|
74
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<number>;
|
|
70
75
|
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<number>;
|
|
71
76
|
deployGauge: (poolAddress: string) => Promise<number>;
|
|
72
77
|
};
|
|
@@ -84,7 +89,7 @@ declare const curve: {
|
|
|
84
89
|
};
|
|
85
90
|
};
|
|
86
91
|
estimateGas: {
|
|
87
|
-
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string) => Promise<number>;
|
|
92
|
+
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<number>;
|
|
88
93
|
};
|
|
89
94
|
boosting: {
|
|
90
95
|
getCrv: (...addresses: string[] | string[][]) => Promise<string | import("./interfaces").IDict<string>>;
|
package/lib/index.js
CHANGED
|
@@ -133,6 +133,7 @@ var curve = {
|
|
|
133
133
|
hasAllowance: utils_2.hasAllowance,
|
|
134
134
|
ensureAllowance: utils_2.ensureAllowance,
|
|
135
135
|
getCoinsData: utils_2.getCoinsData,
|
|
136
|
+
getVolume: utils_2.getVolume,
|
|
136
137
|
factory: {
|
|
137
138
|
deployPlainPool: deploy_1.deployStablePlainPool,
|
|
138
139
|
deployMetaPool: deploy_1.deployStableMetaPool,
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Contract as MulticallContract, Provider as MulticallProvider } from "et
|
|
|
3
3
|
export interface IDict<T> {
|
|
4
4
|
[index: string]: T;
|
|
5
5
|
}
|
|
6
|
-
export type INetworkName = "ethereum" | "polygon" | "avalanche";
|
|
6
|
+
export type INetworkName = "ethereum" | "optimism" | "xdai" | "polygon" | "fantom" | "moonbeam" | "kava" | "arbitrum" | "celo" | "avalanche" | "aurora";
|
|
7
|
+
export type IChainId = 1 | 10 | 100 | 137 | 250 | 1284 | 2222 | 42161 | 42220 | 43114 | 1313161554;
|
|
7
8
|
export type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
|
|
8
9
|
export interface IPoolData {
|
|
9
10
|
name: string;
|
|
@@ -230,7 +230,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
230
230
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
231
231
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
232
232
|
case 4:
|
|
233
|
-
poolsData = (_e.sent());
|
|
233
|
+
poolsData = (_e.sent()).poolsData;
|
|
234
234
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
235
235
|
if (!poolData)
|
|
236
236
|
throw Error("Can't get Volume for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
@@ -268,7 +268,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
268
268
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
269
269
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
270
270
|
case 3:
|
|
271
|
-
poolsData = (_d.sent());
|
|
271
|
+
poolsData = (_d.sent()).poolsData;
|
|
272
272
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
273
273
|
if (!poolData)
|
|
274
274
|
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { IDict, IRewardFromApi } from './interfaces';
|
|
3
|
+
import { IChainId, IDict, INetworkName, IRewardFromApi } from './interfaces';
|
|
4
4
|
export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
5
5
|
export declare const MAX_ALLOWANCE: ethers.BigNumber;
|
|
6
6
|
export declare const _cutZeros: (strn: string) => string;
|
|
@@ -22,16 +22,21 @@ export declare const getBalances: (coins: string[], ...addresses: string[] | str
|
|
|
22
22
|
export declare const _getAllowance: (coins: string[], address: string, spender: string) => Promise<ethers.BigNumber[]>;
|
|
23
23
|
export declare const getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
24
24
|
export declare const hasAllowance: (coins: string[], amounts: (number | string)[], address: string, spender: string) => Promise<boolean>;
|
|
25
|
-
export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumber[], spender: string) => Promise<string[]>;
|
|
26
|
-
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string) => Promise<number>;
|
|
27
|
-
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string) => Promise<string[]>;
|
|
25
|
+
export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumber[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
26
|
+
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<number>;
|
|
27
|
+
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
28
28
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
29
29
|
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
|
30
30
|
export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
|
|
31
31
|
export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
|
|
32
32
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
33
33
|
export declare const getUsdRate: (coin: string) => Promise<number>;
|
|
34
|
-
export declare const getTVL: (
|
|
34
|
+
export declare const getTVL: (network?: INetworkName | IChainId) => Promise<number>;
|
|
35
|
+
export declare const getVolume: (network?: INetworkName | IChainId) => Promise<{
|
|
36
|
+
totalVolume: number;
|
|
37
|
+
cryptoVolume: number;
|
|
38
|
+
cryptoShare: number;
|
|
39
|
+
}>;
|
|
35
40
|
export declare const _setContracts: (address: string, abi: any) => void;
|
|
36
41
|
export declare const _get_small_x: (_x: ethers.BigNumber, _y: ethers.BigNumber, x_decimals: number, y_decimals: number) => BigNumber;
|
|
37
42
|
export declare const _get_price_impact: (_x: ethers.BigNumber, _y: ethers.BigNumber, _small_x: ethers.BigNumber, _small_y: ethers.BigNumber, x_decimals: number, y_decimals: number) => BigNumber;
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getCoinsData = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getRewardsFromApi = exports._getCrvApyFromApi = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
62
|
+
exports.getCoinsData = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getVolume = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getRewardsFromApi = exports._getCrvApyFromApi = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
@@ -301,104 +301,115 @@ var hasAllowance = function (coins, amounts, address, spender) { return __awaite
|
|
|
301
301
|
});
|
|
302
302
|
}); };
|
|
303
303
|
exports.hasAllowance = hasAllowance;
|
|
304
|
-
var _ensureAllowance = function (coins, amounts, spender
|
|
305
|
-
|
|
306
|
-
return
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
304
|
+
var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
305
|
+
if (isMax === void 0) { isMax = true; }
|
|
306
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
307
|
+
var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, gasLimit, _c, _d;
|
|
308
|
+
return __generator(this, function (_e) {
|
|
309
|
+
switch (_e.label) {
|
|
310
|
+
case 0:
|
|
311
|
+
address = curve_1.curve.signerAddress;
|
|
312
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coins, address, spender)];
|
|
313
|
+
case 1:
|
|
314
|
+
allowance = _e.sent();
|
|
315
|
+
txHashes = [];
|
|
316
|
+
i = 0;
|
|
317
|
+
_e.label = 2;
|
|
318
|
+
case 2:
|
|
319
|
+
if (!(i < allowance.length)) return [3 /*break*/, 10];
|
|
320
|
+
if (!allowance[i].lt(amounts[i])) return [3 /*break*/, 9];
|
|
321
|
+
contract = curve_1.curve.contracts[coins[i]].contract;
|
|
322
|
+
_approveAmount = isMax ? exports.MAX_ALLOWANCE : amounts[i];
|
|
323
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
324
|
+
case 3:
|
|
325
|
+
_e.sent();
|
|
326
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 6];
|
|
327
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
328
|
+
case 4:
|
|
329
|
+
gasLimit_1 = (_e.sent()).mul(130).div(100);
|
|
330
|
+
_b = (_a = txHashes).push;
|
|
331
|
+
return [4 /*yield*/, contract.approve(spender, ethers_1.ethers.BigNumber.from(0), __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1 }))];
|
|
332
|
+
case 5:
|
|
333
|
+
_b.apply(_a, [(_e.sent()).hash]);
|
|
334
|
+
_e.label = 6;
|
|
335
|
+
case 6: return [4 /*yield*/, contract.estimateGas.approve(spender, _approveAmount, curve_1.curve.constantOptions)];
|
|
336
|
+
case 7:
|
|
337
|
+
gasLimit = (_e.sent()).mul(130).div(100);
|
|
338
|
+
_d = (_c = txHashes).push;
|
|
339
|
+
return [4 /*yield*/, contract.approve(spender, _approveAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
340
|
+
case 8:
|
|
341
|
+
_d.apply(_c, [(_e.sent()).hash]);
|
|
342
|
+
_e.label = 9;
|
|
343
|
+
case 9:
|
|
344
|
+
i++;
|
|
345
|
+
return [3 /*break*/, 2];
|
|
346
|
+
case 10: return [2 /*return*/, txHashes];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
345
349
|
});
|
|
346
|
-
}
|
|
350
|
+
};
|
|
347
351
|
exports._ensureAllowance = _ensureAllowance;
|
|
348
352
|
// coins can be either addresses or symbols
|
|
349
|
-
var ensureAllowanceEstimateGas = function (coins, amounts, spender
|
|
350
|
-
|
|
351
|
-
return
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
353
|
+
var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
|
|
354
|
+
if (isMax === void 0) { isMax = true; }
|
|
355
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
356
|
+
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, _a, _b;
|
|
357
|
+
return __generator(this, function (_c) {
|
|
358
|
+
switch (_c.label) {
|
|
359
|
+
case 0:
|
|
360
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
361
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
362
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
363
|
+
address = curve_1.curve.signerAddress;
|
|
364
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
365
|
+
case 1:
|
|
366
|
+
allowance = _c.sent();
|
|
367
|
+
gas = 0;
|
|
368
|
+
i = 0;
|
|
369
|
+
_c.label = 2;
|
|
370
|
+
case 2:
|
|
371
|
+
if (!(i < allowance.length)) return [3 /*break*/, 7];
|
|
372
|
+
if (!allowance[i].lt(_amounts[i])) return [3 /*break*/, 6];
|
|
373
|
+
contract = curve_1.curve.contracts[coinAddresses[i]].contract;
|
|
374
|
+
_approveAmount = isMax ? exports.MAX_ALLOWANCE : _amounts[i];
|
|
375
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 4];
|
|
376
|
+
_a = gas;
|
|
377
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
378
|
+
case 3:
|
|
379
|
+
gas = _a + (_c.sent()).toNumber();
|
|
380
|
+
_c.label = 4;
|
|
381
|
+
case 4:
|
|
382
|
+
_b = gas;
|
|
383
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, _approveAmount, curve_1.curve.constantOptions)];
|
|
384
|
+
case 5:
|
|
385
|
+
gas = _b + (_c.sent()).toNumber();
|
|
386
|
+
_c.label = 6;
|
|
387
|
+
case 6:
|
|
388
|
+
i++;
|
|
389
|
+
return [3 /*break*/, 2];
|
|
390
|
+
case 7: return [2 /*return*/, gas];
|
|
391
|
+
}
|
|
392
|
+
});
|
|
385
393
|
});
|
|
386
|
-
}
|
|
394
|
+
};
|
|
387
395
|
exports.ensureAllowanceEstimateGas = ensureAllowanceEstimateGas;
|
|
388
396
|
// coins can be either addresses or symbols
|
|
389
|
-
var ensureAllowance = function (coins, amounts, spender
|
|
390
|
-
|
|
391
|
-
return
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
397
|
+
var ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
398
|
+
if (isMax === void 0) { isMax = true; }
|
|
399
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
400
|
+
var coinAddresses, decimals, _amounts;
|
|
401
|
+
return __generator(this, function (_a) {
|
|
402
|
+
switch (_a.label) {
|
|
403
|
+
case 0:
|
|
404
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
405
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
406
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
407
|
+
return [4 /*yield*/, (0, exports._ensureAllowance)(coinAddresses, _amounts, spender, isMax)];
|
|
408
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
400
411
|
});
|
|
401
|
-
}
|
|
412
|
+
};
|
|
402
413
|
exports.ensureAllowance = ensureAllowance;
|
|
403
414
|
var getPoolNameBySwapAddress = function (swapAddress) {
|
|
404
415
|
var poolsData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
@@ -408,6 +419,16 @@ var getPoolNameBySwapAddress = function (swapAddress) {
|
|
|
408
419
|
})[0][0];
|
|
409
420
|
};
|
|
410
421
|
exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
|
|
422
|
+
var _getTokenAddressBySwapAddress = function (swapAddress) {
|
|
423
|
+
var poolsData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
424
|
+
var res = Object.entries(poolsData).filter(function (_a) {
|
|
425
|
+
var _ = _a[0], poolData = _a[1];
|
|
426
|
+
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|
|
427
|
+
});
|
|
428
|
+
if (res.length === 0)
|
|
429
|
+
return "";
|
|
430
|
+
return res[0][1].token_address;
|
|
431
|
+
};
|
|
411
432
|
var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
412
433
|
var network, promises, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, lpTokenAddress, totalSupply, _c, _d, coin, _e, _f, coin;
|
|
413
434
|
var _g, _h;
|
|
@@ -608,27 +629,39 @@ var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, func
|
|
|
608
629
|
});
|
|
609
630
|
}); };
|
|
610
631
|
exports.getUsdRate = getUsdRate;
|
|
611
|
-
var
|
|
612
|
-
if (
|
|
632
|
+
var _getNetworkName = function (network) {
|
|
633
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
634
|
+
if (typeof network === "number" && curve_1.NETWORK_CONSTANTS[network]) {
|
|
635
|
+
return curve_1.NETWORK_CONSTANTS[network].NAME;
|
|
636
|
+
}
|
|
637
|
+
else if (typeof network === "string" && Object.values(curve_1.NETWORK_CONSTANTS).map(function (n) { return n.NAME; }).includes(network)) {
|
|
638
|
+
return network;
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
throw Error("Wrong network name or id: ".concat(network));
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
var _getChainId = function (network) {
|
|
645
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
646
|
+
if (typeof network === "number" && curve_1.NETWORK_CONSTANTS[network]) {
|
|
647
|
+
return network;
|
|
648
|
+
}
|
|
649
|
+
else if (typeof network === "string" && Object.values(curve_1.NETWORK_CONSTANTS).map(function (n) { return n.NAME; }).includes(network)) {
|
|
650
|
+
var idx = Object.values(curve_1.NETWORK_CONSTANTS).map(function (n) { return n.NAME; }).indexOf(network);
|
|
651
|
+
return Number(Object.keys(curve_1.NETWORK_CONSTANTS)[idx]);
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
throw Error("Wrong network name or id: ".concat(network));
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
var getTVL = function (network) {
|
|
658
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
613
659
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
614
|
-
var
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
switch (_b.label) {
|
|
660
|
+
var promises, allTypesExtendedPoolData;
|
|
661
|
+
return __generator(this, function (_a) {
|
|
662
|
+
switch (_a.label) {
|
|
618
663
|
case 0:
|
|
619
|
-
network = (
|
|
620
|
-
1: "ethereum",
|
|
621
|
-
10: 'optimism',
|
|
622
|
-
100: 'xdai',
|
|
623
|
-
137: "polygon",
|
|
624
|
-
250: "fantom",
|
|
625
|
-
1284: "moonbeam",
|
|
626
|
-
2222: 'kava',
|
|
627
|
-
42220: 'celo',
|
|
628
|
-
43114: "avalanche",
|
|
629
|
-
42161: "arbitrum",
|
|
630
|
-
1313161554: "aurora",
|
|
631
|
-
}[chainId]) !== null && _a !== void 0 ? _a : "ethereum";
|
|
664
|
+
network = _getNetworkName(network);
|
|
632
665
|
promises = [
|
|
633
666
|
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
634
667
|
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
@@ -637,13 +670,67 @@ var getTVL = function (chainId) {
|
|
|
637
670
|
];
|
|
638
671
|
return [4 /*yield*/, Promise.all(promises)];
|
|
639
672
|
case 1:
|
|
640
|
-
allTypesExtendedPoolData =
|
|
673
|
+
allTypesExtendedPoolData = _a.sent();
|
|
641
674
|
return [2 /*return*/, allTypesExtendedPoolData.reduce(function (sum, data) { var _a, _b; return sum + ((_b = (_a = data.tvl) !== null && _a !== void 0 ? _a : data.tvlAll) !== null && _b !== void 0 ? _b : 0); }, 0)];
|
|
642
675
|
}
|
|
643
676
|
});
|
|
644
677
|
});
|
|
645
678
|
};
|
|
646
679
|
exports.getTVL = getTVL;
|
|
680
|
+
var getVolume = function (network) {
|
|
681
|
+
if (network === void 0) { network = curve_1.curve.chainId; }
|
|
682
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
683
|
+
var chainId, _a, mainPoolsData, factoryPoolsData, volume, id, _i, factoryPoolsData_1, pool, lpToken, lpPrice, _b, _c, totalVolume, cryptoVolume, cryptoShare;
|
|
684
|
+
var _d;
|
|
685
|
+
return __generator(this, function (_e) {
|
|
686
|
+
switch (_e.label) {
|
|
687
|
+
case 0:
|
|
688
|
+
network = _getNetworkName(network);
|
|
689
|
+
if (!["moonbeam", "kava", "celo", "aurora"].includes(network)) return [3 /*break*/, 8];
|
|
690
|
+
chainId = _getChainId(network);
|
|
691
|
+
if (curve_1.curve.chainId !== chainId)
|
|
692
|
+
throw Error("To get volume for Moonbeam, Kava, Celo or Aurora connect to the network first");
|
|
693
|
+
return [4 /*yield*/, Promise.all([
|
|
694
|
+
(0, external_api_1._getLegacyAPYsAndVolumes)(network),
|
|
695
|
+
(0, external_api_1._getFactoryAPYsAndVolumes)(network),
|
|
696
|
+
])];
|
|
697
|
+
case 1:
|
|
698
|
+
_a = _e.sent(), mainPoolsData = _a[0], factoryPoolsData = _a[1];
|
|
699
|
+
volume = 0;
|
|
700
|
+
for (id in mainPoolsData) {
|
|
701
|
+
volume += (_d = mainPoolsData[id].volume) !== null && _d !== void 0 ? _d : 0;
|
|
702
|
+
}
|
|
703
|
+
_i = 0, factoryPoolsData_1 = factoryPoolsData;
|
|
704
|
+
_e.label = 2;
|
|
705
|
+
case 2:
|
|
706
|
+
if (!(_i < factoryPoolsData_1.length)) return [3 /*break*/, 7];
|
|
707
|
+
pool = factoryPoolsData_1[_i];
|
|
708
|
+
lpToken = _getTokenAddressBySwapAddress(pool.poolAddress);
|
|
709
|
+
if (!lpToken) return [3 /*break*/, 4];
|
|
710
|
+
return [4 /*yield*/, (0, exports._getUsdRate)(lpToken)];
|
|
711
|
+
case 3:
|
|
712
|
+
_b = _e.sent();
|
|
713
|
+
return [3 /*break*/, 5];
|
|
714
|
+
case 4:
|
|
715
|
+
_b = 0;
|
|
716
|
+
_e.label = 5;
|
|
717
|
+
case 5:
|
|
718
|
+
lpPrice = _b;
|
|
719
|
+
volume += pool.volume * lpPrice;
|
|
720
|
+
_e.label = 6;
|
|
721
|
+
case 6:
|
|
722
|
+
_i++;
|
|
723
|
+
return [3 /*break*/, 2];
|
|
724
|
+
case 7: return [2 /*return*/, { totalVolume: volume, cryptoVolume: 0, cryptoShare: 0 }];
|
|
725
|
+
case 8: return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
726
|
+
case 9:
|
|
727
|
+
_c = _e.sent(), totalVolume = _c.totalVolume, cryptoVolume = _c.cryptoVolume, cryptoShare = _c.cryptoShare;
|
|
728
|
+
return [2 /*return*/, { totalVolume: totalVolume, cryptoVolume: cryptoVolume, cryptoShare: cryptoShare }];
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
exports.getVolume = getVolume;
|
|
647
734
|
var _setContracts = function (address, abi) {
|
|
648
735
|
curve_1.curve.contracts[address] = {
|
|
649
736
|
contract: new ethers_1.Contract(address, abi, curve_1.curve.signer || curve_1.curve.provider),
|