@curvefi/api 1.20.2 → 1.21.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 +46 -39
- package/lib/constants/abis/abis-ethereum.js +138 -0
- package/lib/constants/abis/abis-polygon.js +12 -0
- package/lib/curve.d.ts +4 -4
- package/lib/curve.js +37 -18
- package/lib/factory/constants.d.ts +18 -0
- package/lib/factory/constants.js +149 -0
- package/lib/factory/factory-api.d.ts +2 -0
- package/lib/factory/factory-api.js +273 -0
- package/lib/factory/factory-crypto.d.ts +2 -0
- package/lib/{factory-crypto.js → factory/factory-crypto.js} +41 -54
- package/lib/factory/factory.d.ts +2 -0
- package/lib/{factory.js → factory/factory.js} +66 -64
- package/lib/index.d.ts +2 -2
- package/lib/index.js +6 -4
- package/lib/interfaces.d.ts +51 -2
- package/lib/pools.d.ts +4 -1
- package/lib/pools.js +92 -89
- package/package.json +1 -1
- package/lib/factory-crypto.d.ts +0 -32
- package/lib/factory.d.ts +0 -32
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -53,14 +42,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
53
42
|
exports.getCryptoFactoryPoolData = void 0;
|
|
54
43
|
var ethers_1 = require("ethers");
|
|
55
44
|
var ethcall_1 = require("ethcall");
|
|
56
|
-
var ERC20_json_1 = __importDefault(require("
|
|
57
|
-
var factory_crypto_pool_2_json_1 = __importDefault(require("
|
|
58
|
-
var gauge_factory_json_1 = __importDefault(require("
|
|
45
|
+
var ERC20_json_1 = __importDefault(require("../constants/abis/json/ERC20.json"));
|
|
46
|
+
var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/json/factory-crypto/factory-crypto-pool-2.json"));
|
|
47
|
+
var gauge_factory_json_1 = __importDefault(require("../constants/abis/json/gauge_factory.json"));
|
|
59
48
|
var WETH_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
|
60
49
|
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
61
|
-
function
|
|
50
|
+
function getCryptoFactoryIdsAndSwapAddresses() {
|
|
62
51
|
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i,
|
|
52
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses;
|
|
64
53
|
return __generator(this, function (_e) {
|
|
65
54
|
switch (_e.label) {
|
|
66
55
|
case 0:
|
|
@@ -77,10 +66,10 @@ function getCryptoFactorySwapAddresses() {
|
|
|
77
66
|
}
|
|
78
67
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
79
68
|
case 2:
|
|
80
|
-
|
|
81
|
-
swapAddresses = Object.values(
|
|
82
|
-
|
|
83
|
-
return [2 /*return*/,
|
|
69
|
+
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-crypto-".concat(i), address: addr.toLowerCase() }); });
|
|
70
|
+
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
71
|
+
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
|
|
72
|
+
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
84
73
|
}
|
|
85
74
|
});
|
|
86
75
|
});
|
|
@@ -150,32 +139,27 @@ function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
150
139
|
};
|
|
151
140
|
});
|
|
152
141
|
}
|
|
153
|
-
function
|
|
142
|
+
function getCryptoFactorySymbolsAndNames(factoryTokenAddresses) {
|
|
154
143
|
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
-
var calls, _i, factoryTokenAddresses_1, addr,
|
|
144
|
+
var calls, _i, factoryTokenAddresses_1, addr, res, symbols, names, i;
|
|
156
145
|
return __generator(this, function (_a) {
|
|
157
146
|
switch (_a.label) {
|
|
158
147
|
case 0:
|
|
159
148
|
calls = [];
|
|
160
149
|
for (_i = 0, factoryTokenAddresses_1 = factoryTokenAddresses; _i < factoryTokenAddresses_1.length; _i++) {
|
|
161
150
|
addr = factoryTokenAddresses_1[_i];
|
|
162
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
151
|
+
calls.push(this.contracts[addr].multicallContract.symbol(), this.contracts[addr].multicallContract.name());
|
|
163
152
|
}
|
|
164
153
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
165
154
|
case 1:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
for (i = 0; i <
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
do {
|
|
173
|
-
n++;
|
|
174
|
-
} while (names.indexOf(names[i].slice(0, -4) + "-".concat(n) + "-fV2") !== -1 || existingNames.includes(names[i].slice(0, -4) + "-".concat(n) + "-fV2"));
|
|
175
|
-
names[i] = names[i].slice(0, -4) + "-".concat(n) + "-fV2";
|
|
176
|
-
}
|
|
155
|
+
res = _a.sent();
|
|
156
|
+
symbols = [];
|
|
157
|
+
names = [];
|
|
158
|
+
for (i = 0; i < factoryTokenAddresses.length; i++) {
|
|
159
|
+
symbols.push(res[2 * i]);
|
|
160
|
+
names.push(res[(2 * i) + 1]);
|
|
177
161
|
}
|
|
178
|
-
return [2 /*return*/, names];
|
|
162
|
+
return [2 /*return*/, [symbols, names]];
|
|
179
163
|
}
|
|
180
164
|
});
|
|
181
165
|
});
|
|
@@ -312,46 +296,49 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
312
296
|
}
|
|
313
297
|
function getCryptoFactoryPoolData() {
|
|
314
298
|
return __awaiter(this, void 0, void 0, function () {
|
|
315
|
-
var swapAddresses, tokenAddresses, gaugeAddresses, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i;
|
|
316
|
-
var
|
|
317
|
-
return __generator(this, function (
|
|
318
|
-
switch (
|
|
319
|
-
case 0: return [4 /*yield*/,
|
|
299
|
+
var _a, poolIds, swapAddresses, tokenAddresses, gaugeAddresses, _b, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i;
|
|
300
|
+
var _c, _e;
|
|
301
|
+
return __generator(this, function (_f) {
|
|
302
|
+
switch (_f.label) {
|
|
303
|
+
case 0: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this)];
|
|
320
304
|
case 1:
|
|
321
|
-
|
|
305
|
+
_a = _f.sent(), poolIds = _a[0], swapAddresses = _a[1];
|
|
322
306
|
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
323
307
|
return [4 /*yield*/, getCryptoFactoryTokenAddresses.call(this, swapAddresses)];
|
|
324
308
|
case 2:
|
|
325
|
-
tokenAddresses =
|
|
309
|
+
tokenAddresses = _f.sent();
|
|
326
310
|
setCryptoFactoryTokenContracts.call(this, tokenAddresses);
|
|
327
|
-
(
|
|
311
|
+
(_c = this.constants.LP_TOKENS).push.apply(_c, tokenAddresses); // TODO move to another place
|
|
328
312
|
return [4 /*yield*/, getCryptoFactoryGaugeAddresses.call(this, swapAddresses)];
|
|
329
313
|
case 3:
|
|
330
|
-
gaugeAddresses =
|
|
314
|
+
gaugeAddresses = _f.sent();
|
|
331
315
|
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
332
|
-
(
|
|
333
|
-
return [4 /*yield*/,
|
|
316
|
+
(_e = this.constants.GAUGES).push.apply(_e, gaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })); // TODO move to another place
|
|
317
|
+
return [4 /*yield*/, getCryptoFactorySymbolsAndNames.call(this, tokenAddresses)];
|
|
334
318
|
case 4:
|
|
335
|
-
|
|
319
|
+
_b = _f.sent(), poolSymbols = _b[0], poolNames = _b[1];
|
|
336
320
|
return [4 /*yield*/, getCryptoFactoryCoinAddresses.call(this, swapAddresses)];
|
|
337
321
|
case 5:
|
|
338
|
-
coinAddresses =
|
|
322
|
+
coinAddresses = _f.sent();
|
|
339
323
|
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
340
324
|
return [4 /*yield*/, getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses)];
|
|
341
325
|
case 6:
|
|
342
|
-
underlyingCoinAddresses =
|
|
326
|
+
underlyingCoinAddresses = _f.sent();
|
|
343
327
|
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
344
328
|
return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
|
|
345
329
|
case 7:
|
|
346
|
-
coinAddressNameDict =
|
|
330
|
+
coinAddressNameDict = _f.sent();
|
|
347
331
|
coinAddressNameDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 'ETH';
|
|
348
332
|
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS_LOWER_CASE)];
|
|
349
333
|
case 8:
|
|
350
|
-
coinAddressDecimalsDict =
|
|
334
|
+
coinAddressDecimalsDict = _f.sent();
|
|
351
335
|
coinAddressDecimalsDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 18;
|
|
352
336
|
CRYPTO_FACTORY_POOLS_DATA = {};
|
|
353
|
-
for (i = 0; i <
|
|
354
|
-
CRYPTO_FACTORY_POOLS_DATA[
|
|
337
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
338
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
339
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
340
|
+
full_name: poolNames[i],
|
|
341
|
+
symbol: poolSymbols[i],
|
|
355
342
|
reference_asset: "CRYPTO",
|
|
356
343
|
N_COINS: coinAddresses[i].length,
|
|
357
344
|
is_crypto: true,
|
|
@@ -366,7 +353,7 @@ function getCryptoFactoryPoolData() {
|
|
|
366
353
|
gauge_address: gaugeAddresses[i],
|
|
367
354
|
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
368
355
|
coin_addresses: coinAddresses[i],
|
|
369
|
-
swap_abi: factory_crypto_pool_2_json_1.default
|
|
356
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
370
357
|
gauge_abi: gauge_factory_json_1.default,
|
|
371
358
|
is_factory: true,
|
|
372
359
|
is_crypto_factory: true,
|
|
@@ -51,30 +51,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
51
51
|
exports.getFactoryPoolData = void 0;
|
|
52
52
|
var ethers_1 = require("ethers");
|
|
53
53
|
var ethcall_1 = require("ethcall");
|
|
54
|
-
var ERC20_json_1 = __importDefault(require("
|
|
55
|
-
var swap_json_1 = __importDefault(require("
|
|
56
|
-
var deposit_json_1 = __importDefault(require("
|
|
57
|
-
var gauge_factory_json_1 = __importDefault(require("
|
|
58
|
-
var DepositZapMetaUsdPolygon_json_1 = __importDefault(require("
|
|
59
|
-
var DepositZapMetaBtcPolygon_json_1 = __importDefault(require("
|
|
60
|
-
var MetaUSD_json_1 = __importDefault(require("
|
|
61
|
-
var MetaUSDBalances_json_1 = __importDefault(require("
|
|
62
|
-
var MetaBTC_json_1 = __importDefault(require("
|
|
63
|
-
var MetaBTCBalances_json_1 = __importDefault(require("
|
|
64
|
-
var MetaBTCRen_json_1 = __importDefault(require("
|
|
65
|
-
var MetaBTCBalancesRen_json_1 = __importDefault(require("
|
|
66
|
-
var Plain2Basic_json_1 = __importDefault(require("
|
|
67
|
-
var Plain2Balances_json_1 = __importDefault(require("
|
|
68
|
-
var Plain2ETH_json_1 = __importDefault(require("
|
|
69
|
-
var Plain2Optimized_json_1 = __importDefault(require("
|
|
70
|
-
var Plain3Basic_json_1 = __importDefault(require("
|
|
71
|
-
var Plain3Balances_json_1 = __importDefault(require("
|
|
72
|
-
var Plain3ETH_json_1 = __importDefault(require("
|
|
73
|
-
var Plain3Optimized_json_1 = __importDefault(require("
|
|
74
|
-
var Plain4Basic_json_1 = __importDefault(require("
|
|
75
|
-
var Plain4Balances_json_1 = __importDefault(require("
|
|
76
|
-
var Plain4ETH_json_1 = __importDefault(require("
|
|
77
|
-
var Plain4Optimized_json_1 = __importDefault(require("
|
|
54
|
+
var ERC20_json_1 = __importDefault(require("../constants/abis/json/ERC20.json"));
|
|
55
|
+
var swap_json_1 = __importDefault(require("../constants/abis/json/factoryPools/swap.json"));
|
|
56
|
+
var deposit_json_1 = __importDefault(require("../constants/abis/json/factoryPools/deposit.json"));
|
|
57
|
+
var gauge_factory_json_1 = __importDefault(require("../constants/abis/json/gauge_factory.json"));
|
|
58
|
+
var DepositZapMetaUsdPolygon_json_1 = __importDefault(require("../constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json"));
|
|
59
|
+
var DepositZapMetaBtcPolygon_json_1 = __importDefault(require("../constants/abis/json/factory-v2/DepositZapMetaBtcPolygon.json"));
|
|
60
|
+
var MetaUSD_json_1 = __importDefault(require("../constants/abis/json/factory-v2/MetaUSD.json"));
|
|
61
|
+
var MetaUSDBalances_json_1 = __importDefault(require("../constants/abis/json/factory-v2/MetaUSDBalances.json"));
|
|
62
|
+
var MetaBTC_json_1 = __importDefault(require("../constants/abis/json/factory-v2/MetaBTC.json"));
|
|
63
|
+
var MetaBTCBalances_json_1 = __importDefault(require("../constants/abis/json/factory-v2/MetaBTCBalances.json"));
|
|
64
|
+
var MetaBTCRen_json_1 = __importDefault(require("../constants/abis/json/factory-v2/MetaBTCRen.json"));
|
|
65
|
+
var MetaBTCBalancesRen_json_1 = __importDefault(require("../constants/abis/json/factory-v2/MetaBTCBalancesRen.json"));
|
|
66
|
+
var Plain2Basic_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain2Basic.json"));
|
|
67
|
+
var Plain2Balances_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain2Balances.json"));
|
|
68
|
+
var Plain2ETH_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain2ETH.json"));
|
|
69
|
+
var Plain2Optimized_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain2Optimized.json"));
|
|
70
|
+
var Plain3Basic_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain3Basic.json"));
|
|
71
|
+
var Plain3Balances_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain3Balances.json"));
|
|
72
|
+
var Plain3ETH_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain3ETH.json"));
|
|
73
|
+
var Plain3Optimized_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain3Optimized.json"));
|
|
74
|
+
var Plain4Basic_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain4Basic.json"));
|
|
75
|
+
var Plain4Balances_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain4Balances.json"));
|
|
76
|
+
var Plain4ETH_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain4ETH.json"));
|
|
77
|
+
var Plain4Optimized_json_1 = __importDefault(require("../constants/abis/json/factory-v2/Plain4Optimized.json"));
|
|
78
78
|
var implementationABIDictEthereum = {
|
|
79
79
|
"0x5F890841f657d90E081bAbdB532A05996Af79Fe6": swap_json_1.default,
|
|
80
80
|
"0x213be373FDff327658139C7df330817DAD2d5bBE": MetaUSD_json_1.default,
|
|
@@ -184,9 +184,9 @@ var blackListPolygon = [
|
|
|
184
184
|
];
|
|
185
185
|
var blackListEthereum = [];
|
|
186
186
|
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
187
|
-
function
|
|
187
|
+
function getFactoryIdsAndSwapAddresses() {
|
|
188
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
189
|
-
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i,
|
|
189
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses, blacklist;
|
|
190
190
|
return __generator(this, function (_e) {
|
|
191
191
|
switch (_e.label) {
|
|
192
192
|
case 0:
|
|
@@ -203,10 +203,11 @@ function getFactorySwapAddresses() {
|
|
|
203
203
|
}
|
|
204
204
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
205
205
|
case 2:
|
|
206
|
-
|
|
206
|
+
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-v2-".concat(i), address: addr.toLowerCase() }); });
|
|
207
207
|
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
208
208
|
blacklist = this.chainId === 137 ? blackListPolygon : blackListEthereum;
|
|
209
|
-
|
|
209
|
+
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address) && !blacklist.includes(f.address); });
|
|
210
|
+
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
210
211
|
}
|
|
211
212
|
});
|
|
212
213
|
});
|
|
@@ -271,32 +272,27 @@ function setFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
271
272
|
};
|
|
272
273
|
});
|
|
273
274
|
}
|
|
274
|
-
function
|
|
275
|
+
function getFactorySymbolsAndNames(factorySwapAddresses) {
|
|
275
276
|
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var calls, _i, factorySwapAddresses_3, addr,
|
|
277
|
+
var calls, _i, factorySwapAddresses_3, addr, res, symbols, names, i;
|
|
277
278
|
return __generator(this, function (_a) {
|
|
278
279
|
switch (_a.label) {
|
|
279
280
|
case 0:
|
|
280
281
|
calls = [];
|
|
281
282
|
for (_i = 0, factorySwapAddresses_3 = factorySwapAddresses; _i < factorySwapAddresses_3.length; _i++) {
|
|
282
283
|
addr = factorySwapAddresses_3[_i];
|
|
283
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
284
|
+
calls.push(this.contracts[addr].multicallContract.symbol(), this.contracts[addr].multicallContract.name());
|
|
284
285
|
}
|
|
285
286
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
286
287
|
case 1:
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
for (i = 0; i <
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
do {
|
|
294
|
-
n++;
|
|
295
|
-
} while (names.indexOf(names[i].slice(0, -2) + "-".concat(n) + "-f") !== -1 || existingNames.includes(names[i].slice(0, -2) + "-".concat(n) + "-f"));
|
|
296
|
-
names[i] = names[i].slice(0, -2) + "-".concat(n) + "-f";
|
|
297
|
-
}
|
|
288
|
+
res = _a.sent();
|
|
289
|
+
symbols = [];
|
|
290
|
+
names = [];
|
|
291
|
+
for (i = 0; i < factorySwapAddresses.length; i++) {
|
|
292
|
+
symbols.push(res[2 * i]);
|
|
293
|
+
names.push(res[(2 * i) + 1]);
|
|
298
294
|
}
|
|
299
|
-
return [2 /*return*/, names];
|
|
295
|
+
return [2 /*return*/, [symbols, names]];
|
|
300
296
|
}
|
|
301
297
|
});
|
|
302
298
|
});
|
|
@@ -509,46 +505,46 @@ function setFactoryZapContracts() {
|
|
|
509
505
|
}
|
|
510
506
|
function getFactoryPoolData() {
|
|
511
507
|
return __awaiter(this, void 0, void 0, function () {
|
|
512
|
-
var swapAddresses, swapABIs, gaugeAddresses, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, basePoolAddresses, basePoolAddressCoinsDict, basePoolAddressNameDict, basePoolAddressCoinAddressesDict, basePoolAddressDecimalsDict, basePoolAddressZapDict, FACTORY_POOLS_DATA, i;
|
|
513
|
-
var
|
|
514
|
-
return __generator(this, function (
|
|
515
|
-
switch (
|
|
516
|
-
case 0: return [4 /*yield*/,
|
|
508
|
+
var _a, poolIds, swapAddresses, swapABIs, gaugeAddresses, _b, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, basePoolAddresses, basePoolAddressCoinsDict, basePoolAddressNameDict, basePoolAddressCoinAddressesDict, basePoolAddressDecimalsDict, basePoolAddressZapDict, FACTORY_POOLS_DATA, i;
|
|
509
|
+
var _c, _e;
|
|
510
|
+
return __generator(this, function (_f) {
|
|
511
|
+
switch (_f.label) {
|
|
512
|
+
case 0: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this)];
|
|
517
513
|
case 1:
|
|
518
|
-
|
|
514
|
+
_a = _f.sent(), poolIds = _a[0], swapAddresses = _a[1];
|
|
519
515
|
return [4 /*yield*/, getFactorySwapABIs.call(this, swapAddresses)];
|
|
520
516
|
case 2:
|
|
521
|
-
swapABIs =
|
|
517
|
+
swapABIs = _f.sent();
|
|
522
518
|
setFactorySwapContracts.call(this, swapAddresses, swapABIs);
|
|
523
|
-
(
|
|
519
|
+
(_c = this.constants.LP_TOKENS).push.apply(_c, swapAddresses); // TODO move to another place
|
|
524
520
|
return [4 /*yield*/, getFactoryGaugeAddresses.call(this, swapAddresses)];
|
|
525
521
|
case 3:
|
|
526
|
-
gaugeAddresses =
|
|
522
|
+
gaugeAddresses = _f.sent();
|
|
527
523
|
setFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
528
|
-
(
|
|
529
|
-
return [4 /*yield*/,
|
|
524
|
+
(_e = this.constants.GAUGES).push.apply(_e, gaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })); // TODO move to another place
|
|
525
|
+
return [4 /*yield*/, getFactorySymbolsAndNames.call(this, swapAddresses)];
|
|
530
526
|
case 4:
|
|
531
|
-
|
|
527
|
+
_b = _f.sent(), poolSymbols = _b[0], poolNames = _b[1];
|
|
532
528
|
return [4 /*yield*/, getFactoryReferenceAssets.call(this, swapAddresses)];
|
|
533
529
|
case 5:
|
|
534
|
-
referenceAssets =
|
|
530
|
+
referenceAssets = _f.sent();
|
|
535
531
|
return [4 /*yield*/, getFactoryCoinAddresses.call(this, swapAddresses)];
|
|
536
532
|
case 6:
|
|
537
|
-
coinAddresses =
|
|
533
|
+
coinAddresses = _f.sent();
|
|
538
534
|
setFactoryCoinsContracts.call(this, coinAddresses);
|
|
539
535
|
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
540
536
|
return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
|
|
541
537
|
case 7:
|
|
542
|
-
coinAddressNameDict =
|
|
538
|
+
coinAddressNameDict = _f.sent();
|
|
543
539
|
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS_LOWER_CASE)];
|
|
544
540
|
case 8:
|
|
545
|
-
coinAddressDecimalsDict =
|
|
541
|
+
coinAddressDecimalsDict = _f.sent();
|
|
546
542
|
return [4 /*yield*/, getFactoryIsMeta.call(this, swapAddresses)];
|
|
547
543
|
case 9:
|
|
548
|
-
isMeta =
|
|
544
|
+
isMeta = _f.sent();
|
|
549
545
|
return [4 /*yield*/, getFactoryBasePoolAddresses.call(this, swapAddresses)];
|
|
550
546
|
case 10:
|
|
551
|
-
basePoolAddresses =
|
|
547
|
+
basePoolAddresses = _f.sent();
|
|
552
548
|
setFactoryZapContracts.call(this);
|
|
553
549
|
basePoolAddressCoinsDict = this.chainId === 137 ? basePoolAddressCoinsDictPolygon : basePoolAddressCoinsDictEthereum;
|
|
554
550
|
basePoolAddressNameDict = this.chainId === 137 ? basePoolAddressNameDictPolygon : basePoolAddressNameDictEthereum;
|
|
@@ -556,9 +552,12 @@ function getFactoryPoolData() {
|
|
|
556
552
|
basePoolAddressDecimalsDict = this.chainId === 137 ? basePoolAddressDecimalsDictPolygon : basePoolAddressDecimalsDictEthereum;
|
|
557
553
|
basePoolAddressZapDict = this.chainId === 137 ? basePoolAddressZapDictPolygon : basePoolAddressZapDictEthereum;
|
|
558
554
|
FACTORY_POOLS_DATA = {};
|
|
559
|
-
for (i = 0; i <
|
|
555
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
560
556
|
if (!isMeta[i]) {
|
|
561
|
-
FACTORY_POOLS_DATA[
|
|
557
|
+
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
558
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
559
|
+
full_name: poolNames[i],
|
|
560
|
+
symbol: poolSymbols[i],
|
|
562
561
|
reference_asset: referenceAssets[i],
|
|
563
562
|
N_COINS: coinAddresses[i].length,
|
|
564
563
|
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
@@ -579,7 +578,10 @@ function getFactoryPoolData() {
|
|
|
579
578
|
};
|
|
580
579
|
}
|
|
581
580
|
else {
|
|
582
|
-
FACTORY_POOLS_DATA[
|
|
581
|
+
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
582
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
583
|
+
full_name: poolNames[i],
|
|
584
|
+
symbol: poolSymbols[i],
|
|
583
585
|
reference_asset: referenceAssets[i],
|
|
584
586
|
N_COINS: coinAddresses[i].length,
|
|
585
587
|
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
package/lib/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ declare function init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', p
|
|
|
15
15
|
maxPriorityFeePerGas?: number;
|
|
16
16
|
chainId?: number;
|
|
17
17
|
}): Promise<void>;
|
|
18
|
-
declare function fetchFactoryPools(): Promise<void>;
|
|
19
|
-
declare function fetchCryptoFactoryPools(): Promise<void>;
|
|
18
|
+
declare function fetchFactoryPools(useApi?: boolean): Promise<void>;
|
|
19
|
+
declare function fetchCryptoFactoryPools(useApi?: boolean): Promise<void>;
|
|
20
20
|
declare function setCustomFeeData(customFeeData: {
|
|
21
21
|
gasPrice?: number;
|
|
22
22
|
maxFeePerGas?: number;
|
package/lib/index.js
CHANGED
|
@@ -57,11 +57,12 @@ function init(providerType, providerSettings, options) {
|
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
function fetchFactoryPools() {
|
|
60
|
+
function fetchFactoryPools(useApi) {
|
|
61
|
+
if (useApi === void 0) { useApi = true; }
|
|
61
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
63
|
return __generator(this, function (_a) {
|
|
63
64
|
switch (_a.label) {
|
|
64
|
-
case 0: return [4 /*yield*/, curve_1.curve.fetchFactoryPools()];
|
|
65
|
+
case 0: return [4 /*yield*/, curve_1.curve.fetchFactoryPools(useApi)];
|
|
65
66
|
case 1:
|
|
66
67
|
_a.sent();
|
|
67
68
|
return [2 /*return*/];
|
|
@@ -69,11 +70,12 @@ function fetchFactoryPools() {
|
|
|
69
70
|
});
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
|
-
function fetchCryptoFactoryPools() {
|
|
73
|
+
function fetchCryptoFactoryPools(useApi) {
|
|
74
|
+
if (useApi === void 0) { useApi = true; }
|
|
73
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
74
76
|
return __generator(this, function (_a) {
|
|
75
77
|
switch (_a.label) {
|
|
76
|
-
case 0: return [4 /*yield*/, curve_1.curve.fetchCryptoFactoryPools()];
|
|
78
|
+
case 0: return [4 /*yield*/, curve_1.curve.fetchCryptoFactoryPools(useApi)];
|
|
77
79
|
case 1:
|
|
78
80
|
_a.sent();
|
|
79
81
|
return [2 /*return*/];
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,9 +1,41 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
1
|
+
import { Contract, ethers } from "ethers";
|
|
2
|
+
import { Contract as MulticallContract, Provider as MulticallProvider } from "ethcall";
|
|
2
3
|
export interface DictInterface<T> {
|
|
3
4
|
[index: string]: T;
|
|
4
5
|
}
|
|
6
|
+
export interface ICurve {
|
|
7
|
+
provider: ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider;
|
|
8
|
+
multicallProvider: MulticallProvider;
|
|
9
|
+
signer: ethers.Signer | null;
|
|
10
|
+
signerAddress: string;
|
|
11
|
+
chainId: number;
|
|
12
|
+
contracts: {
|
|
13
|
+
[index: string]: {
|
|
14
|
+
contract: Contract;
|
|
15
|
+
multicallContract: MulticallContract;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
feeData: {
|
|
19
|
+
gasPrice?: number;
|
|
20
|
+
maxFeePerGas?: number;
|
|
21
|
+
maxPriorityFeePerGas?: number;
|
|
22
|
+
};
|
|
23
|
+
constantOptions: {
|
|
24
|
+
gasLimit: number;
|
|
25
|
+
};
|
|
26
|
+
options: {
|
|
27
|
+
gasPrice?: number | ethers.BigNumber;
|
|
28
|
+
maxFeePerGas?: number | ethers.BigNumber;
|
|
29
|
+
maxPriorityFeePerGas?: number | ethers.BigNumber;
|
|
30
|
+
};
|
|
31
|
+
constants: DictInterface<any>;
|
|
32
|
+
}
|
|
33
|
+
export declare type REFERENCE_ASSET = 'USD' | 'EUR' | 'BTC' | 'ETH' | 'LINK' | 'CRYPTO' | 'OTHER';
|
|
5
34
|
export interface PoolDataInterface {
|
|
6
|
-
|
|
35
|
+
name: string;
|
|
36
|
+
full_name: string;
|
|
37
|
+
symbol: string;
|
|
38
|
+
reference_asset: REFERENCE_ASSET;
|
|
7
39
|
N_COINS: number;
|
|
8
40
|
underlying_decimals: number[];
|
|
9
41
|
decimals: number[];
|
|
@@ -56,6 +88,23 @@ export interface PoolDataInterface {
|
|
|
56
88
|
pool_type?: string;
|
|
57
89
|
reward_contract?: string;
|
|
58
90
|
}
|
|
91
|
+
export interface ICoinFromPoolDataApi {
|
|
92
|
+
address: string;
|
|
93
|
+
symbol: string;
|
|
94
|
+
decimals: string;
|
|
95
|
+
}
|
|
96
|
+
export interface IPoolDataFromApi {
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
symbol: string;
|
|
100
|
+
assetTypeName: string;
|
|
101
|
+
address: string;
|
|
102
|
+
lpTokenAddress?: string;
|
|
103
|
+
gaugeAddress?: string;
|
|
104
|
+
implementation: string;
|
|
105
|
+
implementationAddress: string;
|
|
106
|
+
coins: ICoinFromPoolDataApi[];
|
|
107
|
+
}
|
|
59
108
|
export interface RewardsApyInterface {
|
|
60
109
|
token: string;
|
|
61
110
|
symbol: string;
|
package/lib/pools.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { ethers } from "ethers";
|
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
3
|
import { DictInterface, RewardsApyInterface } from './interfaces';
|
|
4
4
|
export declare class Pool {
|
|
5
|
+
id: string;
|
|
5
6
|
name: string;
|
|
7
|
+
fullName: string;
|
|
8
|
+
symbol: string;
|
|
6
9
|
referenceAsset: string;
|
|
7
10
|
swap: string;
|
|
8
11
|
zap: string | null;
|
|
@@ -72,7 +75,7 @@ export declare class Pool {
|
|
|
72
75
|
getTokenApy: () => Promise<[baseApy: string, boostedApy: string]>;
|
|
73
76
|
getRewardsApy: () => Promise<RewardsApyInterface[]>;
|
|
74
77
|
};
|
|
75
|
-
constructor(
|
|
78
|
+
constructor(id: string);
|
|
76
79
|
calcLpTokenAmount: (amounts: string[], isDeposit?: boolean) => Promise<string>;
|
|
77
80
|
calcLpTokenAmountWrapped: (amounts: string[], isDeposit?: boolean) => Promise<string>;
|
|
78
81
|
private getParameters;
|