@curvefi/api 1.20.0 → 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 +5 -5
- package/lib/curve.js +42 -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} +44 -54
- package/lib/factory/factory.d.ts +2 -0
- package/lib/{factory.js → factory/factory.js} +73 -64
- package/lib/index.d.ts +3 -2
- package/lib/index.js +7 -4
- package/lib/interfaces.d.ts +51 -2
- package/lib/pools.d.ts +5 -1
- package/lib/pools.js +122 -90
- 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
|
});
|
|
@@ -255,6 +239,9 @@ function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
|
|
|
255
239
|
if (addr in existingCoinAddrNameDict) {
|
|
256
240
|
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
257
241
|
}
|
|
242
|
+
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
243
|
+
coinAddrNamesDict[addr] = "MKR";
|
|
244
|
+
}
|
|
258
245
|
else {
|
|
259
246
|
newCoinAddresses.push(addr);
|
|
260
247
|
}
|
|
@@ -309,46 +296,49 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
309
296
|
}
|
|
310
297
|
function getCryptoFactoryPoolData() {
|
|
311
298
|
return __awaiter(this, void 0, void 0, function () {
|
|
312
|
-
var swapAddresses, tokenAddresses, gaugeAddresses, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i;
|
|
313
|
-
var
|
|
314
|
-
return __generator(this, function (
|
|
315
|
-
switch (
|
|
316
|
-
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)];
|
|
317
304
|
case 1:
|
|
318
|
-
|
|
305
|
+
_a = _f.sent(), poolIds = _a[0], swapAddresses = _a[1];
|
|
319
306
|
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
320
307
|
return [4 /*yield*/, getCryptoFactoryTokenAddresses.call(this, swapAddresses)];
|
|
321
308
|
case 2:
|
|
322
|
-
tokenAddresses =
|
|
309
|
+
tokenAddresses = _f.sent();
|
|
323
310
|
setCryptoFactoryTokenContracts.call(this, tokenAddresses);
|
|
324
|
-
(
|
|
311
|
+
(_c = this.constants.LP_TOKENS).push.apply(_c, tokenAddresses); // TODO move to another place
|
|
325
312
|
return [4 /*yield*/, getCryptoFactoryGaugeAddresses.call(this, swapAddresses)];
|
|
326
313
|
case 3:
|
|
327
|
-
gaugeAddresses =
|
|
314
|
+
gaugeAddresses = _f.sent();
|
|
328
315
|
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
329
|
-
(
|
|
330
|
-
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)];
|
|
331
318
|
case 4:
|
|
332
|
-
|
|
319
|
+
_b = _f.sent(), poolSymbols = _b[0], poolNames = _b[1];
|
|
333
320
|
return [4 /*yield*/, getCryptoFactoryCoinAddresses.call(this, swapAddresses)];
|
|
334
321
|
case 5:
|
|
335
|
-
coinAddresses =
|
|
322
|
+
coinAddresses = _f.sent();
|
|
336
323
|
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
337
324
|
return [4 /*yield*/, getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses)];
|
|
338
325
|
case 6:
|
|
339
|
-
underlyingCoinAddresses =
|
|
326
|
+
underlyingCoinAddresses = _f.sent();
|
|
340
327
|
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
341
328
|
return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
|
|
342
329
|
case 7:
|
|
343
|
-
coinAddressNameDict =
|
|
330
|
+
coinAddressNameDict = _f.sent();
|
|
344
331
|
coinAddressNameDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 'ETH';
|
|
345
332
|
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS_LOWER_CASE)];
|
|
346
333
|
case 8:
|
|
347
|
-
coinAddressDecimalsDict =
|
|
334
|
+
coinAddressDecimalsDict = _f.sent();
|
|
348
335
|
coinAddressDecimalsDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 18;
|
|
349
336
|
CRYPTO_FACTORY_POOLS_DATA = {};
|
|
350
|
-
for (i = 0; i <
|
|
351
|
-
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],
|
|
352
342
|
reference_asset: "CRYPTO",
|
|
353
343
|
N_COINS: coinAddresses[i].length,
|
|
354
344
|
is_crypto: true,
|
|
@@ -363,7 +353,7 @@ function getCryptoFactoryPoolData() {
|
|
|
363
353
|
gauge_address: gaugeAddresses[i],
|
|
364
354
|
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
365
355
|
coin_addresses: coinAddresses[i],
|
|
366
|
-
swap_abi: factory_crypto_pool_2_json_1.default
|
|
356
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
367
357
|
gauge_abi: gauge_factory_json_1.default,
|
|
368
358
|
is_factory: true,
|
|
369
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,
|
|
@@ -177,10 +177,16 @@ var basePoolAddressZapDictPolygon = {
|
|
|
177
177
|
"0x445FE580eF8d70FF569aB36e80c647af338db351": "0x5ab5C56B9db92Ba45a0B46a207286cD83C15C939".toLowerCase(),
|
|
178
178
|
"0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": "0xE2e6DC1708337A6e59f227921db08F21e3394723".toLowerCase(), // ren
|
|
179
179
|
};
|
|
180
|
+
var blackListPolygon = [
|
|
181
|
+
"0x666dc3b4babfd063faf965bd020024af0dc51b64",
|
|
182
|
+
"0xe4199bc5c5c1f63dba47b56b6db7144c51cf0bf8",
|
|
183
|
+
"0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
|
|
184
|
+
];
|
|
185
|
+
var blackListEthereum = [];
|
|
180
186
|
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
181
|
-
function
|
|
187
|
+
function getFactoryIdsAndSwapAddresses() {
|
|
182
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i,
|
|
189
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses, blacklist;
|
|
184
190
|
return __generator(this, function (_e) {
|
|
185
191
|
switch (_e.label) {
|
|
186
192
|
case 0:
|
|
@@ -197,9 +203,11 @@ function getFactorySwapAddresses() {
|
|
|
197
203
|
}
|
|
198
204
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
199
205
|
case 2:
|
|
200
|
-
|
|
206
|
+
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-v2-".concat(i), address: addr.toLowerCase() }); });
|
|
201
207
|
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
202
|
-
|
|
208
|
+
blacklist = this.chainId === 137 ? blackListPolygon : blackListEthereum;
|
|
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; })]];
|
|
203
211
|
}
|
|
204
212
|
});
|
|
205
213
|
});
|
|
@@ -264,32 +272,27 @@ function setFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
264
272
|
};
|
|
265
273
|
});
|
|
266
274
|
}
|
|
267
|
-
function
|
|
275
|
+
function getFactorySymbolsAndNames(factorySwapAddresses) {
|
|
268
276
|
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
-
var calls, _i, factorySwapAddresses_3, addr,
|
|
277
|
+
var calls, _i, factorySwapAddresses_3, addr, res, symbols, names, i;
|
|
270
278
|
return __generator(this, function (_a) {
|
|
271
279
|
switch (_a.label) {
|
|
272
280
|
case 0:
|
|
273
281
|
calls = [];
|
|
274
282
|
for (_i = 0, factorySwapAddresses_3 = factorySwapAddresses; _i < factorySwapAddresses_3.length; _i++) {
|
|
275
283
|
addr = factorySwapAddresses_3[_i];
|
|
276
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
284
|
+
calls.push(this.contracts[addr].multicallContract.symbol(), this.contracts[addr].multicallContract.name());
|
|
277
285
|
}
|
|
278
286
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
279
287
|
case 1:
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
for (i = 0; i <
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
do {
|
|
287
|
-
n++;
|
|
288
|
-
} while (names.indexOf(names[i].slice(0, -2) + "-".concat(n) + "-f") !== -1 || existingNames.includes(names[i].slice(0, -2) + "-".concat(n) + "-f"));
|
|
289
|
-
names[i] = names[i].slice(0, -2) + "-".concat(n) + "-f";
|
|
290
|
-
}
|
|
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]);
|
|
291
294
|
}
|
|
292
|
-
return [2 /*return*/, names];
|
|
295
|
+
return [2 /*return*/, [symbols, names]];
|
|
293
296
|
}
|
|
294
297
|
});
|
|
295
298
|
});
|
|
@@ -502,46 +505,46 @@ function setFactoryZapContracts() {
|
|
|
502
505
|
}
|
|
503
506
|
function getFactoryPoolData() {
|
|
504
507
|
return __awaiter(this, void 0, void 0, function () {
|
|
505
|
-
var swapAddresses, swapABIs, gaugeAddresses, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, basePoolAddresses, basePoolAddressCoinsDict, basePoolAddressNameDict, basePoolAddressCoinAddressesDict, basePoolAddressDecimalsDict, basePoolAddressZapDict, FACTORY_POOLS_DATA, i;
|
|
506
|
-
var
|
|
507
|
-
return __generator(this, function (
|
|
508
|
-
switch (
|
|
509
|
-
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)];
|
|
510
513
|
case 1:
|
|
511
|
-
|
|
514
|
+
_a = _f.sent(), poolIds = _a[0], swapAddresses = _a[1];
|
|
512
515
|
return [4 /*yield*/, getFactorySwapABIs.call(this, swapAddresses)];
|
|
513
516
|
case 2:
|
|
514
|
-
swapABIs =
|
|
517
|
+
swapABIs = _f.sent();
|
|
515
518
|
setFactorySwapContracts.call(this, swapAddresses, swapABIs);
|
|
516
|
-
(
|
|
519
|
+
(_c = this.constants.LP_TOKENS).push.apply(_c, swapAddresses); // TODO move to another place
|
|
517
520
|
return [4 /*yield*/, getFactoryGaugeAddresses.call(this, swapAddresses)];
|
|
518
521
|
case 3:
|
|
519
|
-
gaugeAddresses =
|
|
522
|
+
gaugeAddresses = _f.sent();
|
|
520
523
|
setFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
521
|
-
(
|
|
522
|
-
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)];
|
|
523
526
|
case 4:
|
|
524
|
-
|
|
527
|
+
_b = _f.sent(), poolSymbols = _b[0], poolNames = _b[1];
|
|
525
528
|
return [4 /*yield*/, getFactoryReferenceAssets.call(this, swapAddresses)];
|
|
526
529
|
case 5:
|
|
527
|
-
referenceAssets =
|
|
530
|
+
referenceAssets = _f.sent();
|
|
528
531
|
return [4 /*yield*/, getFactoryCoinAddresses.call(this, swapAddresses)];
|
|
529
532
|
case 6:
|
|
530
|
-
coinAddresses =
|
|
533
|
+
coinAddresses = _f.sent();
|
|
531
534
|
setFactoryCoinsContracts.call(this, coinAddresses);
|
|
532
535
|
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
533
536
|
return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
|
|
534
537
|
case 7:
|
|
535
|
-
coinAddressNameDict =
|
|
538
|
+
coinAddressNameDict = _f.sent();
|
|
536
539
|
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS_LOWER_CASE)];
|
|
537
540
|
case 8:
|
|
538
|
-
coinAddressDecimalsDict =
|
|
541
|
+
coinAddressDecimalsDict = _f.sent();
|
|
539
542
|
return [4 /*yield*/, getFactoryIsMeta.call(this, swapAddresses)];
|
|
540
543
|
case 9:
|
|
541
|
-
isMeta =
|
|
544
|
+
isMeta = _f.sent();
|
|
542
545
|
return [4 /*yield*/, getFactoryBasePoolAddresses.call(this, swapAddresses)];
|
|
543
546
|
case 10:
|
|
544
|
-
basePoolAddresses =
|
|
547
|
+
basePoolAddresses = _f.sent();
|
|
545
548
|
setFactoryZapContracts.call(this);
|
|
546
549
|
basePoolAddressCoinsDict = this.chainId === 137 ? basePoolAddressCoinsDictPolygon : basePoolAddressCoinsDictEthereum;
|
|
547
550
|
basePoolAddressNameDict = this.chainId === 137 ? basePoolAddressNameDictPolygon : basePoolAddressNameDictEthereum;
|
|
@@ -549,9 +552,12 @@ function getFactoryPoolData() {
|
|
|
549
552
|
basePoolAddressDecimalsDict = this.chainId === 137 ? basePoolAddressDecimalsDictPolygon : basePoolAddressDecimalsDictEthereum;
|
|
550
553
|
basePoolAddressZapDict = this.chainId === 137 ? basePoolAddressZapDictPolygon : basePoolAddressZapDictEthereum;
|
|
551
554
|
FACTORY_POOLS_DATA = {};
|
|
552
|
-
for (i = 0; i <
|
|
555
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
553
556
|
if (!isMeta[i]) {
|
|
554
|
-
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],
|
|
555
561
|
reference_asset: referenceAssets[i],
|
|
556
562
|
N_COINS: coinAddresses[i].length,
|
|
557
563
|
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
@@ -572,7 +578,10 @@ function getFactoryPoolData() {
|
|
|
572
578
|
};
|
|
573
579
|
}
|
|
574
580
|
else {
|
|
575
|
-
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],
|
|
576
585
|
reference_asset: referenceAssets[i],
|
|
577
586
|
N_COINS: coinAddresses[i].length,
|
|
578
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;
|
|
@@ -56,6 +56,7 @@ declare const curve: {
|
|
|
56
56
|
crossAssetExchangeIsApproved: (inputCoin: string, amount: string) => Promise<boolean>;
|
|
57
57
|
crossAssetExchangeApprove: (inputCoin: string, amount: string) => Promise<string[]>;
|
|
58
58
|
crossAssetExchange: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<string>;
|
|
59
|
+
getUserPoolList: (address?: string | undefined) => Promise<string[]>;
|
|
59
60
|
estimateGas: {
|
|
60
61
|
ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<number>;
|
|
61
62
|
exchangeApprove: (inputCoin: string, outputCoin: string, amount: string) => Promise<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*/];
|
|
@@ -111,6 +113,7 @@ var curve = {
|
|
|
111
113
|
crossAssetExchangeIsApproved: pools_1.crossAssetExchangeIsApproved,
|
|
112
114
|
crossAssetExchangeApprove: pools_1.crossAssetExchangeApprove,
|
|
113
115
|
crossAssetExchange: pools_1.crossAssetExchange,
|
|
116
|
+
getUserPoolList: pools_1.getUserPoolList,
|
|
114
117
|
estimateGas: {
|
|
115
118
|
ensureAllowance: utils_1.ensureAllowanceEstimateGas,
|
|
116
119
|
exchangeApprove: pools_1.exchangeApproveEstimateGas,
|
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;
|
|
@@ -250,3 +253,4 @@ export declare const crossAssetExchangeApproveEstimateGas: (inputCoin: string, a
|
|
|
250
253
|
export declare const crossAssetExchangeApprove: (inputCoin: string, amount: string) => Promise<string[]>;
|
|
251
254
|
export declare const crossAssetExchangeEstimateGas: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<number>;
|
|
252
255
|
export declare const crossAssetExchange: (inputCoin: string, outputCoin: string, amount: string, maxSlippage?: number) => Promise<string>;
|
|
256
|
+
export declare const getUserPoolList: (address?: string | undefined) => Promise<string[]>;
|