@curvefi/api 2.8.3 → 2.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants/abis/atricrypto3/base_pool_zap.json +216 -0
- package/lib/constants/abis/gauge_v5.json +1 -1
- package/lib/curve.js +30 -29
- package/lib/factory/common.d.ts +1 -0
- package/lib/factory/common.js +12 -1
- package/lib/factory/constants.js +5 -0
- package/lib/factory/factory-api.js +101 -30
- package/lib/factory/factory-crypto.js +75 -22
- package/lib/factory/factory.js +31 -12
- package/lib/pools/PoolTemplate.js +35 -21
- package/lib/pools/mixins/common.d.ts +1 -0
- package/lib/pools/mixins/common.js +30 -1
- package/lib/pools/mixins/poolBalancesMixin.js +14 -6
- package/lib/pools/mixins/withdrawExpectedMixins.js +17 -15
- package/lib/pools/poolConstructor.js +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +15 -7
- package/package.json +1 -1
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
49
|
};
|
|
@@ -45,7 +54,10 @@ var ethcall_1 = require("ethcall");
|
|
|
45
54
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
46
55
|
var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
|
|
47
56
|
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
57
|
+
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
58
|
+
var base_pool_zap_json_1 = __importDefault(require("../constants/abis/atricrypto3/base_pool_zap.json"));
|
|
48
59
|
var constants_1 = require("./constants");
|
|
60
|
+
var common_1 = require("./common");
|
|
49
61
|
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
50
62
|
function getCryptoFactoryIdsAndSwapAddresses() {
|
|
51
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -134,8 +146,8 @@ function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
134
146
|
var _this = this;
|
|
135
147
|
factoryGaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; }).forEach(function (addr, i) {
|
|
136
148
|
_this.contracts[addr] = {
|
|
137
|
-
contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
|
|
138
|
-
multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
|
|
149
|
+
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
|
|
150
|
+
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
|
|
139
151
|
};
|
|
140
152
|
});
|
|
141
153
|
}
|
|
@@ -308,9 +320,10 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
308
320
|
});
|
|
309
321
|
});
|
|
310
322
|
}
|
|
323
|
+
var atricrypto3Lp = "0xdAD97F7713Ae9437fa9249920eC8507e5FbB23d3".toLowerCase();
|
|
311
324
|
function getCryptoFactoryPoolData() {
|
|
312
325
|
return __awaiter(this, void 0, void 0, function () {
|
|
313
|
-
var _a, poolIds, swapAddresses, tokenAddresses, gaugeAddresses, _b, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i;
|
|
326
|
+
var _a, poolIds, swapAddresses, tokenAddresses, gaugeAddresses, _b, poolSymbols, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i, isMeta, basePoolId, basePoolCoinNames, basePoolCoinAddresses, basePoolDecimals, basePoolZap;
|
|
314
327
|
return __generator(this, function (_c) {
|
|
315
328
|
switch (_c.label) {
|
|
316
329
|
case 0: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this)];
|
|
@@ -342,27 +355,67 @@ function getCryptoFactoryPoolData() {
|
|
|
342
355
|
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS)];
|
|
343
356
|
case 8:
|
|
344
357
|
coinAddressDecimalsDict = _c.sent();
|
|
358
|
+
common_1.setCryptoFactoryZapContracts.call(this);
|
|
345
359
|
CRYPTO_FACTORY_POOLS_DATA = {};
|
|
346
360
|
for (i = 0; i < poolIds.length; i++) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
361
|
+
isMeta = this.chainId === 137 && coinAddresses[i][1].toLowerCase() === atricrypto3Lp;
|
|
362
|
+
if (isMeta) {
|
|
363
|
+
basePoolId = "atricrypto3";
|
|
364
|
+
basePoolCoinNames = ['DAI', 'USDC', 'USDT', 'WBTC', 'WETH'];
|
|
365
|
+
basePoolCoinAddresses = [
|
|
366
|
+
'0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
|
|
367
|
+
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
|
|
368
|
+
'0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
|
|
369
|
+
'0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6',
|
|
370
|
+
'0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', // WETH
|
|
371
|
+
];
|
|
372
|
+
basePoolDecimals = [18, 6, 6, 8, 18];
|
|
373
|
+
basePoolZap = "0x3d8EADb739D1Ef95dd53D718e4810721837c69c1";
|
|
374
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
375
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
376
|
+
full_name: poolNames[i],
|
|
377
|
+
symbol: poolSymbols[i],
|
|
378
|
+
reference_asset: "CRYPTO",
|
|
379
|
+
swap_address: swapAddresses[i],
|
|
380
|
+
token_address: tokenAddresses[i],
|
|
381
|
+
gauge_address: gaugeAddresses[i],
|
|
382
|
+
deposit_address: basePoolZap,
|
|
383
|
+
is_meta: true,
|
|
384
|
+
is_crypto: true,
|
|
385
|
+
is_factory: true,
|
|
386
|
+
base_pool: basePoolId,
|
|
387
|
+
underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolCoinNames, true),
|
|
388
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
389
|
+
underlying_coin_addresses: __spreadArray([coinAddresses[i][0]], basePoolCoinAddresses, true),
|
|
390
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
391
|
+
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolDecimals, true),
|
|
392
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
393
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
394
|
+
gauge_abi: this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
395
|
+
deposit_abi: base_pool_zap_json_1.default,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
400
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
401
|
+
full_name: poolNames[i],
|
|
402
|
+
symbol: poolSymbols[i],
|
|
403
|
+
reference_asset: "CRYPTO",
|
|
404
|
+
swap_address: swapAddresses[i],
|
|
405
|
+
token_address: tokenAddresses[i],
|
|
406
|
+
gauge_address: gaugeAddresses[i],
|
|
407
|
+
is_crypto: true,
|
|
408
|
+
is_factory: true,
|
|
409
|
+
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
410
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
411
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
412
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
413
|
+
underlying_decimals: underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
414
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
415
|
+
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
416
|
+
gauge_abi: this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
366
419
|
}
|
|
367
420
|
return [2 /*return*/, CRYPTO_FACTORY_POOLS_DATA];
|
|
368
421
|
}
|
package/lib/factory/factory.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -54,6 +65,7 @@ var ethcall_1 = require("ethcall");
|
|
|
54
65
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
55
66
|
var deposit_json_1 = __importDefault(require("../constants/abis/factoryPools/deposit.json"));
|
|
56
67
|
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
68
|
+
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
57
69
|
var common_1 = require("./common");
|
|
58
70
|
var constants_1 = require("./constants");
|
|
59
71
|
var BLACK_LIST = {
|
|
@@ -149,8 +161,8 @@ function setFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
|
149
161
|
var _this = this;
|
|
150
162
|
factoryGaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; }).forEach(function (addr, i) {
|
|
151
163
|
_this.contracts[addr] = {
|
|
152
|
-
contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
|
|
153
|
-
multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
|
|
164
|
+
contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
|
|
165
|
+
multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
|
|
154
166
|
};
|
|
155
167
|
});
|
|
156
168
|
}
|
|
@@ -311,7 +323,7 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
311
323
|
return __generator(this, function (_a) {
|
|
312
324
|
switch (_a.label) {
|
|
313
325
|
case 0:
|
|
314
|
-
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
326
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses))).filter(function (addr) { return addr !== constants_1.NATIVE_TOKEN_ADDRESS; });
|
|
315
327
|
newCoinAddresses = [];
|
|
316
328
|
coinAddrNamesDict = {};
|
|
317
329
|
for (_i = 0, flattenedCoinAddresses_3 = flattenedCoinAddresses; _i < flattenedCoinAddresses_3.length; _i++) {
|
|
@@ -359,8 +371,7 @@ function getFactoryIsMeta(factorySwapAddresses) {
|
|
|
359
371
|
}
|
|
360
372
|
function getFactoryPoolData() {
|
|
361
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
-
var _a, poolIds, swapAddresses, implementations, implementationABIDict, swapABIs, gaugeAddresses, _b, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, implementationBasePoolIdDict, basePoolIds,
|
|
363
|
-
var _this = this;
|
|
374
|
+
var _a, poolIds, swapAddresses, implementations, implementationABIDict, swapABIs, gaugeAddresses, _b, poolSymbols, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, implementationBasePoolIdDict, basePoolIds, FACTORY_POOLS_DATA, _loop_2, this_1, i;
|
|
364
375
|
return __generator(this, function (_c) {
|
|
365
376
|
switch (_c.label) {
|
|
366
377
|
case 0: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this)];
|
|
@@ -399,12 +410,8 @@ function getFactoryPoolData() {
|
|
|
399
410
|
implementationBasePoolIdDict = constants_1.FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
|
|
400
411
|
basePoolIds = implementations.map(function (addr) { return implementationBasePoolIdDict[addr]; });
|
|
401
412
|
common_1.setFactoryZapContracts.call(this);
|
|
402
|
-
basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId, _this.constants.POOLS_DATA[poolId].underlying_coins]; }));
|
|
403
|
-
basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId, _this.constants.POOLS_DATA[poolId].underlying_coin_addresses]; }));
|
|
404
|
-
basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { return [poolId, _this.constants.POOLS_DATA[poolId].underlying_decimals]; }));
|
|
405
|
-
basePoolIdZapDict = constants_1.FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
|
|
406
413
|
FACTORY_POOLS_DATA = {};
|
|
407
|
-
|
|
414
|
+
_loop_2 = function (i) {
|
|
408
415
|
if (!isMeta[i]) {
|
|
409
416
|
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
410
417
|
name: poolNames[i].split(": ")[1].trim(),
|
|
@@ -423,10 +430,18 @@ function getFactoryPoolData() {
|
|
|
423
430
|
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
424
431
|
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
425
432
|
swap_abi: swapABIs[i],
|
|
426
|
-
gauge_abi: gauge_factory_json_1.default,
|
|
433
|
+
gauge_abi: this_1.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
427
434
|
};
|
|
428
435
|
}
|
|
429
436
|
else {
|
|
437
|
+
var allPoolsData_1 = __assign(__assign({}, this_1.constants.POOLS_DATA), FACTORY_POOLS_DATA);
|
|
438
|
+
// @ts-ignore
|
|
439
|
+
var basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coins]; }));
|
|
440
|
+
// @ts-ignore
|
|
441
|
+
var basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coin_addresses]; }));
|
|
442
|
+
// @ts-ignore
|
|
443
|
+
var basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_decimals]; }));
|
|
444
|
+
var basePoolIdZapDict = constants_1.FACTORY_CONSTANTS[this_1.chainId].basePoolIdZapDict;
|
|
430
445
|
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
431
446
|
name: poolNames[i].split(": ")[1].trim(),
|
|
432
447
|
full_name: poolNames[i],
|
|
@@ -446,10 +461,14 @@ function getFactoryPoolData() {
|
|
|
446
461
|
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolIdDecimalsDict[basePoolIds[i]], true),
|
|
447
462
|
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
448
463
|
swap_abi: swapABIs[i],
|
|
449
|
-
gauge_abi: gauge_factory_json_1.default,
|
|
464
|
+
gauge_abi: this_1.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
450
465
|
deposit_abi: deposit_json_1.default,
|
|
451
466
|
};
|
|
452
467
|
}
|
|
468
|
+
};
|
|
469
|
+
this_1 = this;
|
|
470
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
471
|
+
_loop_2(i);
|
|
453
472
|
}
|
|
454
473
|
return [2 /*return*/, FACTORY_POOLS_DATA];
|
|
455
474
|
}
|
|
@@ -390,7 +390,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
390
390
|
}, {
|
|
391
391
|
primitive: true,
|
|
392
392
|
promise: true,
|
|
393
|
-
maxAge:
|
|
393
|
+
maxAge: 60 * 1000, // 1m
|
|
394
394
|
});
|
|
395
395
|
// ---------------- CRV PROFIT, CLAIM, BOOSTING ----------------
|
|
396
396
|
this.crvProfit = function (address) {
|
|
@@ -569,9 +569,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
569
569
|
};
|
|
570
570
|
// ---------------- REWARDS PROFIT, CLAIM ----------------
|
|
571
571
|
this.rewardTokens = (0, memoizee_1.default)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
572
|
-
var gaugeContract, gaugeMulticallContract, rewardCount, _c, _d, _e, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract,
|
|
573
|
-
return __generator(this, function (
|
|
574
|
-
switch (
|
|
572
|
+
var gaugeContract, gaugeMulticallContract, rewardCount, _c, _d, _e, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, res, symbol, decimals;
|
|
573
|
+
return __generator(this, function (_f) {
|
|
574
|
+
switch (_f.label) {
|
|
575
575
|
case 0:
|
|
576
576
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
577
577
|
return [2 /*return*/, []];
|
|
@@ -584,8 +584,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
584
584
|
_e = (_d = ethers_1.ethers.utils).formatUnits;
|
|
585
585
|
return [4 /*yield*/, gaugeContract.reward_count(curve_1.curve.constantOptions)];
|
|
586
586
|
case 1:
|
|
587
|
-
rewardCount = _c.apply(void 0, [_e.apply(_d, [
|
|
588
|
-
|
|
587
|
+
rewardCount = _c.apply(void 0, [_e.apply(_d, [_f.sent(), 0])]);
|
|
588
|
+
_f.label = 2;
|
|
589
589
|
case 2:
|
|
590
590
|
tokenCalls = [];
|
|
591
591
|
for (i = 0; i < rewardCount; i++) {
|
|
@@ -593,7 +593,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
593
593
|
}
|
|
594
594
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenCalls)];
|
|
595
595
|
case 3:
|
|
596
|
-
tokens = (
|
|
596
|
+
tokens = (_f.sent())
|
|
597
597
|
.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
|
|
598
598
|
.map(function (addr) { return addr.toLowerCase(); });
|
|
599
599
|
tokenInfoCalls = [];
|
|
@@ -605,7 +605,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
605
605
|
}
|
|
606
606
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenInfoCalls)];
|
|
607
607
|
case 4:
|
|
608
|
-
tokenInfo_1 =
|
|
608
|
+
tokenInfo_1 = _f.sent();
|
|
609
609
|
for (i = 0; i < tokens.length; i++) {
|
|
610
610
|
curve_1.curve.constants.DECIMALS[tokens[i]] = tokenInfo_1[(i * 2) + 1];
|
|
611
611
|
}
|
|
@@ -617,7 +617,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
617
617
|
;
|
|
618
618
|
return [4 /*yield*/, rewardContract[method](curve_1.curve.constantOptions)];
|
|
619
619
|
case 6:
|
|
620
|
-
token = (
|
|
620
|
+
token = (_f.sent()).toLowerCase();
|
|
621
621
|
(0, utils_1._setContracts)(token, ERC20_json_1.default);
|
|
622
622
|
tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
|
|
623
623
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
@@ -625,7 +625,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
625
625
|
tokenMulticallContract.decimals(),
|
|
626
626
|
])];
|
|
627
627
|
case 7:
|
|
628
|
-
|
|
628
|
+
res = _f.sent();
|
|
629
|
+
symbol = res[0];
|
|
630
|
+
decimals = res[0].toNumber();
|
|
629
631
|
return [2 /*return*/, [{ token: token, symbol: symbol, decimals: decimals }]];
|
|
630
632
|
case 8: return [2 /*return*/, []]; // gauge
|
|
631
633
|
}
|
|
@@ -699,7 +701,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
699
701
|
])];
|
|
700
702
|
case 8:
|
|
701
703
|
_d = _f.sent(), _inflationRate = _d[0], _periodFinish = _d[1], _balance = _d[2], _totalSupply = _d[3];
|
|
702
|
-
periodFinish =
|
|
704
|
+
periodFinish = _periodFinish.toNumber() * 1000;
|
|
703
705
|
inflationRateBN = periodFinish > Date.now() ? (0, utils_1.toBN)(_inflationRate, rewardToken.decimals) : (0, utils_1.BN)(0);
|
|
704
706
|
balanceBN = (0, utils_1.toBN)(_balance);
|
|
705
707
|
totalSupplyBN = (0, utils_1.toBN)(_totalSupply);
|
|
@@ -1065,15 +1067,18 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1065
1067
|
calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
1066
1068
|
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
1067
1069
|
contract = curve_1.curve.contracts[calcContractAddress].contract;
|
|
1068
|
-
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/,
|
|
1070
|
+
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 4];
|
|
1071
|
+
if (!contract["calc_token_amount(address,uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 2];
|
|
1069
1072
|
return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1070
1073
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1071
|
-
case 2:
|
|
1072
|
-
if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 4];
|
|
1073
|
-
return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1074
|
+
case 2: return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, curve_1.curve.constantOptions)];
|
|
1074
1075
|
case 3: return [2 /*return*/, _c.sent()];
|
|
1075
|
-
case 4:
|
|
1076
|
+
case 4:
|
|
1077
|
+
if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 6];
|
|
1078
|
+
return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
1076
1079
|
case 5: return [2 /*return*/, _c.sent()];
|
|
1080
|
+
case 6: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
1081
|
+
case 7: return [2 /*return*/, _c.sent()];
|
|
1077
1082
|
}
|
|
1078
1083
|
});
|
|
1079
1084
|
});
|
|
@@ -2391,7 +2396,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2391
2396
|
lpTotalBalanceBN = (0, utils_1.BN)(lpBalances.lpToken);
|
|
2392
2397
|
if ('gauge' in lpBalances)
|
|
2393
2398
|
lpTotalBalanceBN = lpTotalBalanceBN.plus((0, utils_1.BN)(lpBalances.gauge));
|
|
2394
|
-
return [2 /*return*/, lpTotalBalanceBN
|
|
2399
|
+
return [2 /*return*/, lpTotalBalanceBN];
|
|
2395
2400
|
}
|
|
2396
2401
|
});
|
|
2397
2402
|
});
|
|
@@ -2409,7 +2414,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2409
2414
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2410
2415
|
case 1:
|
|
2411
2416
|
lpTotalBalanceBN = _c.sent();
|
|
2412
|
-
|
|
2417
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2418
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2419
|
+
return [4 /*yield*/, this.withdrawExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2413
2420
|
case 2: return [2 /*return*/, _c.sent()];
|
|
2414
2421
|
}
|
|
2415
2422
|
});
|
|
@@ -2428,7 +2435,9 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2428
2435
|
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2429
2436
|
case 1:
|
|
2430
2437
|
lpTotalBalanceBN = _c.sent();
|
|
2431
|
-
|
|
2438
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2439
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2440
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2432
2441
|
case 2: return [2 /*return*/, _c.sent()];
|
|
2433
2442
|
}
|
|
2434
2443
|
});
|
|
@@ -2543,8 +2552,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2543
2552
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2544
2553
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2545
2554
|
case 1: return [2 /*return*/, _c.sent()];
|
|
2546
|
-
case 2:
|
|
2547
|
-
|
|
2555
|
+
case 2:
|
|
2556
|
+
if (!('get_dy(address,uint256,uint256,uint256)' in contract)) return [3 /*break*/, 4];
|
|
2557
|
+
return [4 /*yield*/, contract.get_dy(this.address, i, j, _amount, curve_1.curve.constantOptions)];
|
|
2558
|
+
case 3: // atricrypto3 based metapools
|
|
2559
|
+
return [2 /*return*/, _c.sent()];
|
|
2560
|
+
case 4: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
2561
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
2548
2562
|
}
|
|
2549
2563
|
});
|
|
2550
2564
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { PoolTemplate } from "../PoolTemplate";
|
|
3
3
|
export declare function _calcExpectedAmounts(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
|
|
4
|
+
export declare function _atricrypto3CalcExpectedAmounts(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
|
|
@@ -35,8 +35,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports._calcExpectedAmounts = void 0;
|
|
48
|
+
exports._atricrypto3CalcExpectedAmounts = exports._calcExpectedAmounts = void 0;
|
|
49
|
+
var PoolTemplate_1 = require("../PoolTemplate");
|
|
40
50
|
var curve_1 = require("../../curve");
|
|
41
51
|
var utils_1 = require("../../utils");
|
|
42
52
|
function _calcExpectedAmounts(_lpTokenAmount) {
|
|
@@ -75,3 +85,22 @@ function _calcExpectedAmounts(_lpTokenAmount) {
|
|
|
75
85
|
});
|
|
76
86
|
}
|
|
77
87
|
exports._calcExpectedAmounts = _calcExpectedAmounts;
|
|
88
|
+
function _atricrypto3CalcExpectedAmounts(_lpTokenAmount) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
+
var _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0: return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
94
|
+
case 1:
|
|
95
|
+
_expectedWrappedAmounts = _a.sent();
|
|
96
|
+
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
97
|
+
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
98
|
+
return [4 /*yield*/, _calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
99
|
+
case 2:
|
|
100
|
+
_basePoolExpectedAmounts = _a.sent();
|
|
101
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports._atricrypto3CalcExpectedAmounts = _atricrypto3CalcExpectedAmounts;
|
|
@@ -80,22 +80,30 @@ exports.poolBalancesAtricrypto3Mixin = {
|
|
|
80
80
|
exports.poolBalancesMetaMixin = {
|
|
81
81
|
statsUnderlyingBalances: function () {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalance, basePool, _basePoolExpectedAmounts, _poolUnderlyingBalances;
|
|
83
|
+
var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalance, basePool, _basePoolExpectedAmounts, _a, _poolUnderlyingBalances;
|
|
84
84
|
var _this = this;
|
|
85
|
-
return __generator(this, function (
|
|
86
|
-
switch (
|
|
85
|
+
return __generator(this, function (_c) {
|
|
86
|
+
switch (_c.label) {
|
|
87
87
|
case 0:
|
|
88
88
|
swapContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
89
89
|
contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
|
|
90
90
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
91
91
|
case 1:
|
|
92
|
-
_poolWrappedBalances =
|
|
92
|
+
_poolWrappedBalances = _c.sent();
|
|
93
93
|
_poolWrappedBalances.unshift(_poolWrappedBalances.pop());
|
|
94
94
|
_poolMetaCoinBalance = _poolWrappedBalances[0], _poolNonMetaBalance = _poolWrappedBalances.slice(1);
|
|
95
95
|
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
96
|
-
return [
|
|
96
|
+
if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
|
|
97
|
+
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
|
|
97
98
|
case 2:
|
|
98
|
-
|
|
99
|
+
_a = _c.sent();
|
|
100
|
+
return [3 /*break*/, 5];
|
|
101
|
+
case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
|
|
102
|
+
case 4:
|
|
103
|
+
_a = _c.sent();
|
|
104
|
+
_c.label = 5;
|
|
105
|
+
case 5:
|
|
106
|
+
_basePoolExpectedAmounts = _a;
|
|
99
107
|
_poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolNonMetaBalance, true), _basePoolExpectedAmounts, true);
|
|
100
108
|
return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
|
|
101
109
|
}
|
|
@@ -96,21 +96,29 @@ exports.withdrawExpectedLendingOrCryptoMixin = {
|
|
|
96
96
|
exports.withdrawExpectedMetaMixin = {
|
|
97
97
|
withdrawExpected: function (lpTokenAmount) {
|
|
98
98
|
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _expected;
|
|
99
|
+
var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _a, _expected;
|
|
100
100
|
var _this = this;
|
|
101
|
-
return __generator(this, function (
|
|
102
|
-
switch (
|
|
101
|
+
return __generator(this, function (_b) {
|
|
102
|
+
switch (_b.label) {
|
|
103
103
|
case 0:
|
|
104
104
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
105
105
|
return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
106
106
|
case 1:
|
|
107
|
-
_expectedWrappedAmounts =
|
|
107
|
+
_expectedWrappedAmounts = _b.sent();
|
|
108
108
|
_expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
|
|
109
109
|
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
110
110
|
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
111
|
-
return [
|
|
111
|
+
if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
|
|
112
|
+
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
112
113
|
case 2:
|
|
113
|
-
|
|
114
|
+
_a = _b.sent();
|
|
115
|
+
return [3 /*break*/, 5];
|
|
116
|
+
case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
117
|
+
case 4:
|
|
118
|
+
_a = _b.sent();
|
|
119
|
+
_b.label = 5;
|
|
120
|
+
case 5:
|
|
121
|
+
_basePoolExpectedAmounts = _a;
|
|
114
122
|
_expected = __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true);
|
|
115
123
|
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
116
124
|
}
|
|
@@ -122,21 +130,15 @@ exports.withdrawExpectedMetaMixin = {
|
|
|
122
130
|
exports.withdrawExpectedAtricrypto3Mixin = {
|
|
123
131
|
withdrawExpected: function (lpTokenAmount) {
|
|
124
132
|
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var _lpTokenAmount,
|
|
133
|
+
var _lpTokenAmount, _expected;
|
|
126
134
|
var _this = this;
|
|
127
135
|
return __generator(this, function (_a) {
|
|
128
136
|
switch (_a.label) {
|
|
129
137
|
case 0:
|
|
130
138
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
131
|
-
return [4 /*yield*/, common_1.
|
|
139
|
+
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
132
140
|
case 1:
|
|
133
|
-
|
|
134
|
-
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
135
|
-
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
136
|
-
return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
137
|
-
case 2:
|
|
138
|
-
_basePoolExpectedAmounts = _a.sent();
|
|
139
|
-
_expected = __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true);
|
|
141
|
+
_expected = _a.sent();
|
|
140
142
|
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
141
143
|
}
|
|
142
144
|
});
|
|
@@ -230,7 +230,7 @@ var getPool = function (poolId) {
|
|
|
230
230
|
if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve_1.curve.contracts[poolDummy.address].contract) { // tricrypto2 (eth), tricrypto (arbitrum)
|
|
231
231
|
Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
|
|
232
232
|
}
|
|
233
|
-
else if (poolDummy.isMetaFactory && (0, exports.getPool)(poolDummy.basePool).isLending) {
|
|
233
|
+
else if (poolDummy.isMetaFactory && ((0, exports.getPool)(poolDummy.basePool).isLending || (0, exports.getPool)(poolDummy.basePool).isFake)) {
|
|
234
234
|
Object.assign(Pool.prototype, swapMixins_1.swapMetaFactoryMixin);
|
|
235
235
|
}
|
|
236
236
|
else {
|
package/lib/utils.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const formatNumber: (n: number | string, decimals?: number) => st
|
|
|
13
13
|
export declare const parseUnits: (n: number | string, decimals?: number) => ethers.BigNumber;
|
|
14
14
|
export declare const isEth: (address: string) => boolean;
|
|
15
15
|
export declare const getEthIndex: (addresses: string[]) => number;
|
|
16
|
+
export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
|
|
16
17
|
export declare const _getCoinAddresses: (...coins: string[] | string[][]) => string[];
|
|
17
18
|
export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
|
|
18
19
|
export declare const _getBalances: (coins: string[], addresses: string[]) => Promise<IDict<string[]>>;
|
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._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = 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.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
62
|
+
exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = 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.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = 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 bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -116,7 +116,7 @@ exports.isEth = isEth;
|
|
|
116
116
|
var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(exports.ETH_ADDRESS.toLowerCase()); };
|
|
117
117
|
exports.getEthIndex = getEthIndex;
|
|
118
118
|
// coins can be either addresses or symbols
|
|
119
|
-
var
|
|
119
|
+
var _getCoinAddressesNoCheck = function () {
|
|
120
120
|
var coins = [];
|
|
121
121
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
122
122
|
coins[_i] = arguments[_i];
|
|
@@ -124,7 +124,15 @@ var _getCoinAddresses = function () {
|
|
|
124
124
|
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
125
125
|
coins = coins[0];
|
|
126
126
|
coins = coins;
|
|
127
|
-
|
|
127
|
+
return coins.map(function (c) { return c.toLowerCase(); }).map(function (c) { return curve_1.curve.constants.COINS[c] || c; });
|
|
128
|
+
};
|
|
129
|
+
exports._getCoinAddressesNoCheck = _getCoinAddressesNoCheck;
|
|
130
|
+
var _getCoinAddresses = function () {
|
|
131
|
+
var coins = [];
|
|
132
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
133
|
+
coins[_i] = arguments[_i];
|
|
134
|
+
}
|
|
135
|
+
var coinAddresses = exports._getCoinAddressesNoCheck.apply(void 0, coins);
|
|
128
136
|
var availableAddresses = __spreadArray(__spreadArray([], Object.keys(curve_1.curve.constants.DECIMALS), true), curve_1.curve.constants.GAUGES, true);
|
|
129
137
|
for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
|
|
130
138
|
var coinAddr = coinAddresses_1[_a];
|
|
@@ -473,11 +481,11 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
473
481
|
}
|
|
474
482
|
assetId = {
|
|
475
483
|
'CRV': 'curve-dao-token',
|
|
476
|
-
'EUR':
|
|
484
|
+
'EUR': 'stasis-eurs',
|
|
477
485
|
'BTC': 'bitcoin',
|
|
478
486
|
'ETH': 'ethereum',
|
|
479
487
|
'LINK': 'link',
|
|
480
|
-
}[assetId] || assetId;
|
|
488
|
+
}[assetId.toUpperCase()] || assetId;
|
|
481
489
|
assetId = (0, exports.isEth)(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
482
490
|
// No EURT on Coingecko Polygon
|
|
483
491
|
if (curve_1.curve.chainId === 137 && assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt) {
|
|
@@ -489,7 +497,7 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
489
497
|
assetId = 'curve-dao-token';
|
|
490
498
|
}
|
|
491
499
|
if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 3];
|
|
492
|
-
url = [nativeTokenName, 'bitcoin', 'link', 'curve-dao-token'].includes(assetId.toLowerCase()) ?
|
|
500
|
+
url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
493
501
|
"https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
|
|
494
502
|
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
495
503
|
return [4 /*yield*/, axios_1.default.get(url)];
|
|
@@ -512,7 +520,7 @@ var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, func
|
|
|
512
520
|
return __generator(this, function (_a) {
|
|
513
521
|
switch (_a.label) {
|
|
514
522
|
case 0:
|
|
515
|
-
coinAddress = (0, exports.
|
|
523
|
+
coinAddress = (0, exports._getCoinAddressesNoCheck)(coin)[0];
|
|
516
524
|
return [4 /*yield*/, (0, exports._getUsdRate)(coinAddress)];
|
|
517
525
|
case 1: return [2 /*return*/, _a.sent()];
|
|
518
526
|
}
|