@curvefi/api 1.17.2 → 1.20.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 +57 -0
- package/lib/constants/abis/abis-ethereum.js +6 -6
- package/lib/constants/abis/json/factory-crypto/factory-crypto-pool-2.json +1112 -0
- package/lib/constants/abis/json/factory-crypto.json +635 -0
- package/lib/constants/abis/json/factory-v2/DepositZapMetaBtcPolygon.json +197 -0
- package/lib/constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json +197 -0
- package/lib/constants/abis/json/factory-v2/MetaBTC.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCBalances.json +932 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCBalancesRen.json +932 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCRen.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaUSD.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaUSDBalances.json +932 -0
- package/lib/constants/abis/json/factory-v2/Plain2Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2Optimized.json +844 -0
- package/lib/constants/abis/json/factory-v2/Plain3Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3Optimized.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Optimized.json +845 -0
- package/lib/constants/abis/json/factory.json +1063 -0
- package/lib/constants/abis/json/registry_exchange.json +207 -84
- package/lib/constants/aliases.d.ts +4 -0
- package/lib/constants/aliases.js +4 -0
- package/lib/constants/coins-polygon.js +3 -2
- package/lib/curve.d.ts +5 -0
- package/lib/curve.js +62 -0
- package/lib/factory-crypto.d.ts +32 -0
- package/lib/factory-crypto.js +377 -0
- package/lib/factory.d.ts +32 -0
- package/lib/factory.js +607 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +28 -0
- package/lib/interfaces.d.ts +28 -1
- package/lib/pools.d.ts +5 -0
- package/lib/pools.js +359 -159
- package/lib/utils.d.ts +8 -1
- package/lib/utils.js +111 -8
- package/package.json +4 -2
package/lib/pools.js
CHANGED
|
@@ -81,7 +81,9 @@ var Pool = /** @class */ (function () {
|
|
|
81
81
|
_amounts = amounts.map(function (amount, i) {
|
|
82
82
|
return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
|
|
83
83
|
});
|
|
84
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
84
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
85
|
+
this.isCryptoFactory ||
|
|
86
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
85
87
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
|
|
86
88
|
case 1:
|
|
87
89
|
_expected = _a.sent(); // Lending pools
|
|
@@ -192,7 +194,9 @@ var Pool = /** @class */ (function () {
|
|
|
192
194
|
_poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
|
|
193
195
|
return [3 /*break*/, 6];
|
|
194
196
|
case 3:
|
|
195
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
197
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
198
|
+
this.isCryptoFactory ||
|
|
199
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
196
200
|
return [4 /*yield*/, this._getRates()];
|
|
197
201
|
case 4:
|
|
198
202
|
_rates_1 = _a.sent();
|
|
@@ -236,21 +240,37 @@ var Pool = /** @class */ (function () {
|
|
|
236
240
|
case 2:
|
|
237
241
|
prices = _c.sent();
|
|
238
242
|
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
239
|
-
return [2 /*return*/,
|
|
243
|
+
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}); };
|
|
247
|
+
this._getPoolStats = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
248
|
+
var statsUrl, name, key;
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
switch (_a.label) {
|
|
251
|
+
case 0:
|
|
252
|
+
statsUrl = this.isFactory ? (0, utils_1._getFactoryStatsUrl)() : (0, utils_1._getStatsUrl)(this.isCrypto);
|
|
253
|
+
name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
|
|
254
|
+
key = this.isFactory ? this.swap.toLowerCase() : name;
|
|
255
|
+
if (!this.isFactory) return [3 /*break*/, 4];
|
|
256
|
+
if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 2];
|
|
257
|
+
return [4 /*yield*/, (0, utils_1._getFactoryStatsPolygon)(statsUrl)];
|
|
258
|
+
case 1: return [2 /*return*/, (_a.sent())[key]];
|
|
259
|
+
case 2: return [4 /*yield*/, (0, utils_1._getFactoryStatsEthereum)(statsUrl)];
|
|
260
|
+
case 3: return [2 /*return*/, (_a.sent())[key]];
|
|
261
|
+
case 4: return [4 /*yield*/, (0, utils_1._getStats)(statsUrl)];
|
|
262
|
+
case 5: return [2 /*return*/, (_a.sent())[key]];
|
|
240
263
|
}
|
|
241
264
|
});
|
|
242
265
|
}); };
|
|
243
266
|
this.getVolume = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
244
|
-
var
|
|
267
|
+
var volume, usdRate, _a;
|
|
245
268
|
return __generator(this, function (_c) {
|
|
246
269
|
switch (_c.label) {
|
|
247
|
-
case 0:
|
|
248
|
-
name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
|
|
249
|
-
statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
|
|
250
|
-
return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
270
|
+
case 0: return [4 /*yield*/, this._getPoolStats()];
|
|
251
271
|
case 1:
|
|
252
|
-
volume = (_c.sent()).
|
|
253
|
-
if (!this.isCrypto) return [3 /*break*/, 2];
|
|
272
|
+
volume = (_c.sent()).volume;
|
|
273
|
+
if (!(this.isCrypto || (curve_1.curve.chainId === 1 && this.isFactory))) return [3 /*break*/, 2];
|
|
254
274
|
_a = 1;
|
|
255
275
|
return [3 /*break*/, 4];
|
|
256
276
|
case 2: return [4 /*yield*/, (0, utils_1._getUsdRate)(this.referenceAsset)];
|
|
@@ -264,16 +284,14 @@ var Pool = /** @class */ (function () {
|
|
|
264
284
|
});
|
|
265
285
|
}); };
|
|
266
286
|
this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
267
|
-
var
|
|
287
|
+
var apy, multiplier, formattedApy;
|
|
268
288
|
return __generator(this, function (_a) {
|
|
269
289
|
switch (_a.label) {
|
|
270
|
-
case 0:
|
|
271
|
-
name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
|
|
272
|
-
statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
|
|
273
|
-
return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
290
|
+
case 0: return [4 /*yield*/, this._getPoolStats()];
|
|
274
291
|
case 1:
|
|
275
|
-
apy = (_a.sent()).
|
|
276
|
-
|
|
292
|
+
apy = (_a.sent()).apy;
|
|
293
|
+
multiplier = this.isFactory ? 1 : 100;
|
|
294
|
+
formattedApy = [apy.day, apy.week, apy.month, apy.total].map(function (x) { return (x * multiplier).toFixed(4); });
|
|
277
295
|
return [2 /*return*/, {
|
|
278
296
|
day: formattedApy[0],
|
|
279
297
|
week: formattedApy[1],
|
|
@@ -288,6 +306,8 @@ var Pool = /** @class */ (function () {
|
|
|
288
306
|
return __generator(this, function (_c) {
|
|
289
307
|
switch (_c.label) {
|
|
290
308
|
case 0:
|
|
309
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
310
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
291
311
|
if (curve_1.curve.chainId === 137)
|
|
292
312
|
throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
|
|
293
313
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
@@ -296,6 +316,8 @@ var Pool = /** @class */ (function () {
|
|
|
296
316
|
return [4 /*yield*/, this.getTotalLiquidity()];
|
|
297
317
|
case 1:
|
|
298
318
|
totalLiquidityUSD = _c.sent();
|
|
319
|
+
if (Number(totalLiquidityUSD) === 0)
|
|
320
|
+
return [2 /*return*/, ["0", "0"]];
|
|
299
321
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
300
322
|
gaugeContract.inflation_rate(),
|
|
301
323
|
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
@@ -304,6 +326,8 @@ var Pool = /** @class */ (function () {
|
|
|
304
326
|
])];
|
|
305
327
|
case 2:
|
|
306
328
|
_a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
|
|
329
|
+
if (Number(workingSupply) === 0)
|
|
330
|
+
return [2 /*return*/, ["0", "0"]];
|
|
307
331
|
rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
|
|
308
332
|
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
|
|
309
333
|
case 3:
|
|
@@ -462,7 +486,9 @@ var Pool = /** @class */ (function () {
|
|
|
462
486
|
return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
|
|
463
487
|
case 3: return [2 /*return*/, _d.sent()];
|
|
464
488
|
case 4:
|
|
465
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
489
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
490
|
+
this.isCryptoFactory ||
|
|
491
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
|
|
466
492
|
return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
|
|
467
493
|
case 5: return [2 /*return*/, _d.sent()];
|
|
468
494
|
case 6:
|
|
@@ -518,7 +544,9 @@ var Pool = /** @class */ (function () {
|
|
|
518
544
|
return [4 /*yield*/, this._addLiquidityZap(_amounts)];
|
|
519
545
|
case 2: return [2 /*return*/, _a.sent()];
|
|
520
546
|
case 3:
|
|
521
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
547
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
548
|
+
this.isCryptoFactory ||
|
|
549
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
522
550
|
return [4 /*yield*/, this._addLiquidity(_amounts, true)];
|
|
523
551
|
case 4: return [2 /*return*/, _a.sent()];
|
|
524
552
|
case 5:
|
|
@@ -552,7 +580,10 @@ var Pool = /** @class */ (function () {
|
|
|
552
580
|
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
553
581
|
return __generator(this, function (_a) {
|
|
554
582
|
switch (_a.label) {
|
|
555
|
-
case 0:
|
|
583
|
+
case 0:
|
|
584
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
585
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
586
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
|
|
556
587
|
case 1:
|
|
557
588
|
coinsAllowance = _a.sent();
|
|
558
589
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
@@ -569,7 +600,10 @@ var Pool = /** @class */ (function () {
|
|
|
569
600
|
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
570
601
|
return __generator(this, function (_a) {
|
|
571
602
|
switch (_a.label) {
|
|
572
|
-
case 0:
|
|
603
|
+
case 0:
|
|
604
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
605
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
606
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
573
607
|
case 1:
|
|
574
608
|
approveCoinsGas = _a.sent();
|
|
575
609
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
@@ -590,7 +624,10 @@ var Pool = /** @class */ (function () {
|
|
|
590
624
|
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
591
625
|
return __generator(this, function (_a) {
|
|
592
626
|
switch (_a.label) {
|
|
593
|
-
case 0:
|
|
627
|
+
case 0:
|
|
628
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
629
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
630
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
594
631
|
case 1:
|
|
595
632
|
approveCoinsTx = _a.sent();
|
|
596
633
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
@@ -631,6 +668,8 @@ var Pool = /** @class */ (function () {
|
|
|
631
668
|
return __generator(this, function (_p) {
|
|
632
669
|
switch (_p.label) {
|
|
633
670
|
case 0:
|
|
671
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
672
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
634
673
|
coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.coinAddresses, true);
|
|
635
674
|
coins = isUnderlying ? this.underlyingCoins : this.coinAddresses;
|
|
636
675
|
decimals = isUnderlying ? this.underlyingDecimals : this.decimals;
|
|
@@ -686,7 +725,9 @@ var Pool = /** @class */ (function () {
|
|
|
686
725
|
return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
|
|
687
726
|
});
|
|
688
727
|
contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
|
|
689
|
-
useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
728
|
+
useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
729
|
+
this.isCryptoFactory ||
|
|
730
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'));
|
|
690
731
|
if (!isUnderlying) return [3 /*break*/, 14];
|
|
691
732
|
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
692
733
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
@@ -707,7 +748,7 @@ var Pool = /** @class */ (function () {
|
|
|
707
748
|
coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
|
|
708
749
|
_amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
|
|
709
750
|
}
|
|
710
|
-
return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.
|
|
751
|
+
return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
711
752
|
case 17:
|
|
712
753
|
_gas = (_p.sent());
|
|
713
754
|
if (estimateGas)
|
|
@@ -716,7 +757,7 @@ var Pool = /** @class */ (function () {
|
|
|
716
757
|
case 18:
|
|
717
758
|
_p.sent();
|
|
718
759
|
gasLimit = _gas.mul(200).div(100);
|
|
719
|
-
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.
|
|
760
|
+
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
|
|
720
761
|
case 19: return [2 /*return*/, (_p.sent()).hash];
|
|
721
762
|
}
|
|
722
763
|
});
|
|
@@ -857,7 +898,9 @@ var Pool = /** @class */ (function () {
|
|
|
857
898
|
_amounts = amounts.map(function (amount, i) {
|
|
858
899
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
859
900
|
});
|
|
860
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
901
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
902
|
+
this.isCryptoFactory ||
|
|
903
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
861
904
|
return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
|
|
862
905
|
case 3: return [2 /*return*/, _d.sent()];
|
|
863
906
|
case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
@@ -885,7 +928,9 @@ var Pool = /** @class */ (function () {
|
|
|
885
928
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
886
929
|
case 1:
|
|
887
930
|
_a.sent();
|
|
888
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
931
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
932
|
+
this.isCryptoFactory ||
|
|
933
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
889
934
|
return [4 /*yield*/, this._addLiquidity(_amounts, false)];
|
|
890
935
|
case 2: return [2 /*return*/, _a.sent()];
|
|
891
936
|
case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
|
|
@@ -924,9 +969,10 @@ var Pool = /** @class */ (function () {
|
|
|
924
969
|
return __generator(this, function (_a) {
|
|
925
970
|
switch (_a.label) {
|
|
926
971
|
case 0:
|
|
927
|
-
if (this.
|
|
972
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
973
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
974
|
+
if (this.isFake)
|
|
928
975
|
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
929
|
-
}
|
|
930
976
|
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
|
|
931
977
|
case 1:
|
|
932
978
|
coinsAllowance = _a.sent();
|
|
@@ -945,9 +991,10 @@ var Pool = /** @class */ (function () {
|
|
|
945
991
|
return __generator(this, function (_a) {
|
|
946
992
|
switch (_a.label) {
|
|
947
993
|
case 0:
|
|
948
|
-
if (this.
|
|
994
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
995
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
996
|
+
if (this.isFake)
|
|
949
997
|
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
950
|
-
}
|
|
951
998
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
952
999
|
case 1:
|
|
953
1000
|
approveCoinsGas = _a.sent();
|
|
@@ -970,9 +1017,10 @@ var Pool = /** @class */ (function () {
|
|
|
970
1017
|
return __generator(this, function (_a) {
|
|
971
1018
|
switch (_a.label) {
|
|
972
1019
|
case 0:
|
|
973
|
-
if (this.
|
|
1020
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1021
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1022
|
+
if (this.isFake)
|
|
974
1023
|
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
975
|
-
}
|
|
976
1024
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
977
1025
|
case 1:
|
|
978
1026
|
approveCoinsTx = _a.sent();
|
|
@@ -1024,7 +1072,9 @@ var Pool = /** @class */ (function () {
|
|
|
1024
1072
|
switch (_a.label) {
|
|
1025
1073
|
case 0:
|
|
1026
1074
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1027
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1075
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1076
|
+
this.isCryptoFactory ||
|
|
1077
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
1028
1078
|
return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
|
|
1029
1079
|
case 1:
|
|
1030
1080
|
_expected = _a.sent(); // Lending pools
|
|
@@ -1101,7 +1151,9 @@ var Pool = /** @class */ (function () {
|
|
|
1101
1151
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
|
|
1102
1152
|
case 4: return [2 /*return*/, _c.sent()];
|
|
1103
1153
|
case 5:
|
|
1104
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1154
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1155
|
+
this.isCryptoFactory ||
|
|
1156
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
1105
1157
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
|
|
1106
1158
|
case 6: return [2 /*return*/, _c.sent()];
|
|
1107
1159
|
case 7:
|
|
@@ -1126,7 +1178,9 @@ var Pool = /** @class */ (function () {
|
|
|
1126
1178
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
|
|
1127
1179
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1128
1180
|
case 3:
|
|
1129
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1181
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1182
|
+
this.isCryptoFactory ||
|
|
1183
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
1130
1184
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
|
|
1131
1185
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1132
1186
|
case 5:
|
|
@@ -1170,7 +1224,9 @@ var Pool = /** @class */ (function () {
|
|
|
1170
1224
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
1171
1225
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
1172
1226
|
}
|
|
1173
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1227
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1228
|
+
this.isCryptoFactory ||
|
|
1229
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1174
1230
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
|
|
1175
1231
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1176
1232
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
@@ -1190,7 +1246,9 @@ var Pool = /** @class */ (function () {
|
|
|
1190
1246
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1191
1247
|
case 1:
|
|
1192
1248
|
_a.sent();
|
|
1193
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1249
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1250
|
+
this.isCryptoFactory ||
|
|
1251
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1194
1252
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
|
|
1195
1253
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1196
1254
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
|
|
@@ -1573,7 +1631,9 @@ var Pool = /** @class */ (function () {
|
|
|
1573
1631
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
|
|
1574
1632
|
case 4: return [2 /*return*/, _c.sent()];
|
|
1575
1633
|
case 5:
|
|
1576
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1634
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1635
|
+
this.isCryptoFactory ||
|
|
1636
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
1577
1637
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
|
|
1578
1638
|
case 6: return [2 /*return*/, _c.sent()];
|
|
1579
1639
|
case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1597,7 +1657,9 @@ var Pool = /** @class */ (function () {
|
|
|
1597
1657
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
|
|
1598
1658
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1599
1659
|
case 3:
|
|
1600
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1660
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1661
|
+
this.isCryptoFactory ||
|
|
1662
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
1601
1663
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
|
|
1602
1664
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1603
1665
|
case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1675,7 +1737,9 @@ var Pool = /** @class */ (function () {
|
|
|
1675
1737
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1676
1738
|
}
|
|
1677
1739
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1678
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1740
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1741
|
+
this.isCryptoFactory ||
|
|
1742
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1679
1743
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
|
|
1680
1744
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1681
1745
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1699,7 +1763,9 @@ var Pool = /** @class */ (function () {
|
|
|
1699
1763
|
case 1:
|
|
1700
1764
|
_a.sent();
|
|
1701
1765
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1702
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1766
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
|
|
1767
|
+
this.isCryptoFactory ||
|
|
1768
|
+
(curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1703
1769
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
|
|
1704
1770
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1705
1771
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1710,7 +1776,10 @@ var Pool = /** @class */ (function () {
|
|
|
1710
1776
|
this.gaugeDepositIsApproved = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1711
1777
|
return __generator(this, function (_a) {
|
|
1712
1778
|
switch (_a.label) {
|
|
1713
|
-
case 0:
|
|
1779
|
+
case 0:
|
|
1780
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1781
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1782
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
|
|
1714
1783
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1715
1784
|
}
|
|
1716
1785
|
});
|
|
@@ -1718,7 +1787,10 @@ var Pool = /** @class */ (function () {
|
|
|
1718
1787
|
this.gaugeDepositApproveEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1719
1788
|
return __generator(this, function (_a) {
|
|
1720
1789
|
switch (_a.label) {
|
|
1721
|
-
case 0:
|
|
1790
|
+
case 0:
|
|
1791
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1792
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1793
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1722
1794
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1723
1795
|
}
|
|
1724
1796
|
});
|
|
@@ -1726,7 +1798,10 @@ var Pool = /** @class */ (function () {
|
|
|
1726
1798
|
this.gaugeDepositApprove = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1727
1799
|
return __generator(this, function (_a) {
|
|
1728
1800
|
switch (_a.label) {
|
|
1729
|
-
case 0:
|
|
1801
|
+
case 0:
|
|
1802
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1803
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1804
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1730
1805
|
case 1: return [2 /*return*/, _a.sent()];
|
|
1731
1806
|
}
|
|
1732
1807
|
});
|
|
@@ -1736,6 +1811,8 @@ var Pool = /** @class */ (function () {
|
|
|
1736
1811
|
return __generator(this, function (_a) {
|
|
1737
1812
|
switch (_a.label) {
|
|
1738
1813
|
case 0:
|
|
1814
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1815
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1739
1816
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1740
1817
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1741
1818
|
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
@@ -1747,6 +1824,8 @@ var Pool = /** @class */ (function () {
|
|
|
1747
1824
|
return __generator(this, function (_a) {
|
|
1748
1825
|
switch (_a.label) {
|
|
1749
1826
|
case 0:
|
|
1827
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1828
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1750
1829
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1751
1830
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
|
|
1752
1831
|
case 1:
|
|
@@ -1764,6 +1843,8 @@ var Pool = /** @class */ (function () {
|
|
|
1764
1843
|
return __generator(this, function (_a) {
|
|
1765
1844
|
switch (_a.label) {
|
|
1766
1845
|
case 0:
|
|
1846
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1847
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1767
1848
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1768
1849
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1769
1850
|
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
@@ -1775,10 +1856,12 @@ var Pool = /** @class */ (function () {
|
|
|
1775
1856
|
return __generator(this, function (_a) {
|
|
1776
1857
|
switch (_a.label) {
|
|
1777
1858
|
case 0:
|
|
1859
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1860
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1778
1861
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1779
1862
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1780
1863
|
case 1:
|
|
1781
|
-
gasLimit = (_a.sent()).mul(
|
|
1864
|
+
gasLimit = (_a.sent()).mul(200).div(100);
|
|
1782
1865
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1783
1866
|
case 2: return [2 /*return*/, (_a.sent()).hash];
|
|
1784
1867
|
}
|
|
@@ -1791,6 +1874,8 @@ var Pool = /** @class */ (function () {
|
|
|
1791
1874
|
return __generator(this, function (_d) {
|
|
1792
1875
|
switch (_d.label) {
|
|
1793
1876
|
case 0:
|
|
1877
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1878
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1794
1879
|
if (curve_1.curve.chainId !== 1)
|
|
1795
1880
|
throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimableRewards instead"));
|
|
1796
1881
|
address = address || curve_1.curve.signerAddress;
|
|
@@ -1808,6 +1893,8 @@ var Pool = /** @class */ (function () {
|
|
|
1808
1893
|
return __generator(this, function (_a) {
|
|
1809
1894
|
switch (_a.label) {
|
|
1810
1895
|
case 0:
|
|
1896
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1897
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1811
1898
|
if (curve_1.curve.chainId !== 1)
|
|
1812
1899
|
throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimRewards instead"));
|
|
1813
1900
|
return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
|
|
@@ -1827,6 +1914,8 @@ var Pool = /** @class */ (function () {
|
|
|
1827
1914
|
return __generator(this, function (_h) {
|
|
1828
1915
|
switch (_h.label) {
|
|
1829
1916
|
case 0:
|
|
1917
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1918
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1830
1919
|
address = address || curve_1.curve.signerAddress;
|
|
1831
1920
|
if (!address)
|
|
1832
1921
|
throw Error("Need to connect wallet or pass address into args");
|
|
@@ -1890,6 +1979,8 @@ var Pool = /** @class */ (function () {
|
|
|
1890
1979
|
return __generator(this, function (_a) {
|
|
1891
1980
|
switch (_a.label) {
|
|
1892
1981
|
case 0:
|
|
1982
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1983
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1893
1984
|
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
1894
1985
|
if (!("claim_rewards()" in gaugeContract))
|
|
1895
1986
|
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
@@ -1909,8 +2000,12 @@ var Pool = /** @class */ (function () {
|
|
|
1909
2000
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1910
2001
|
return __generator(this, function (_a) {
|
|
1911
2002
|
switch (_a.label) {
|
|
1912
|
-
case 0:
|
|
2003
|
+
case 0:
|
|
2004
|
+
if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
|
|
2005
|
+
return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
|
|
1913
2006
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2007
|
+
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
|
|
2008
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
1914
2009
|
}
|
|
1915
2010
|
});
|
|
1916
2011
|
});
|
|
@@ -1923,8 +2018,12 @@ var Pool = /** @class */ (function () {
|
|
|
1923
2018
|
return __awaiter(_this, void 0, void 0, function () {
|
|
1924
2019
|
return __generator(this, function (_a) {
|
|
1925
2020
|
switch (_a.label) {
|
|
1926
|
-
case 0:
|
|
2021
|
+
case 0:
|
|
2022
|
+
if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
|
|
2023
|
+
return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken'], [this.lpToken]], addresses, false))];
|
|
1927
2024
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2025
|
+
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
|
|
2026
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
1928
2027
|
}
|
|
1929
2028
|
});
|
|
1930
2029
|
});
|
|
@@ -1991,7 +2090,8 @@ var Pool = /** @class */ (function () {
|
|
|
1991
2090
|
return __generator(this, function (_a) {
|
|
1992
2091
|
switch (_a.label) {
|
|
1993
2092
|
case 0:
|
|
1994
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name)
|
|
2093
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
|
|
2094
|
+
(curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
|
|
1995
2095
|
i = this._getCoinIdx(inputCoin);
|
|
1996
2096
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
1997
2097
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2003,7 +2103,8 @@ var Pool = /** @class */ (function () {
|
|
|
2003
2103
|
return __generator(this, function (_a) {
|
|
2004
2104
|
switch (_a.label) {
|
|
2005
2105
|
case 0:
|
|
2006
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name)
|
|
2106
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
|
|
2107
|
+
(curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
|
|
2007
2108
|
i = this._getCoinIdx(inputCoin);
|
|
2008
2109
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2009
2110
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2015,7 +2116,8 @@ var Pool = /** @class */ (function () {
|
|
|
2015
2116
|
return __generator(this, function (_a) {
|
|
2016
2117
|
switch (_a.label) {
|
|
2017
2118
|
case 0:
|
|
2018
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name)
|
|
2119
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
|
|
2120
|
+
(curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
|
|
2019
2121
|
i = this._getCoinIdx(inputCoin);
|
|
2020
2122
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2021
2123
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -2029,7 +2131,8 @@ var Pool = /** @class */ (function () {
|
|
|
2029
2131
|
return __generator(this, function (_d) {
|
|
2030
2132
|
switch (_d.label) {
|
|
2031
2133
|
case 0:
|
|
2032
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name)
|
|
2134
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
|
|
2135
|
+
(curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
|
|
2033
2136
|
i = this._getCoinIdx(inputCoin);
|
|
2034
2137
|
j = this._getCoinIdx(outputCoin);
|
|
2035
2138
|
_c = (_a = Object).values;
|
|
@@ -2057,8 +2160,12 @@ var Pool = /** @class */ (function () {
|
|
|
2057
2160
|
if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
|
|
2058
2161
|
return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2059
2162
|
case 4: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
2060
|
-
case 5:
|
|
2163
|
+
case 5:
|
|
2164
|
+
if (!(curve_1.curve.chainId === 137 && this.isFactory)) return [3 /*break*/, 7];
|
|
2165
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2061
2166
|
case 6: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
2167
|
+
case 7: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2168
|
+
case 8: return [2 /*return*/, (_d.sent()).toNumber()];
|
|
2062
2169
|
}
|
|
2063
2170
|
});
|
|
2064
2171
|
});
|
|
@@ -2066,11 +2173,12 @@ var Pool = /** @class */ (function () {
|
|
|
2066
2173
|
this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2067
2174
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
2068
2175
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2069
|
-
var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, estimatedGas, gasLimit;
|
|
2176
|
+
var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, gasLimit_2, estimatedGas, gasLimit;
|
|
2070
2177
|
return __generator(this, function (_a) {
|
|
2071
2178
|
switch (_a.label) {
|
|
2072
2179
|
case 0:
|
|
2073
|
-
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name)
|
|
2180
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
|
|
2181
|
+
(curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
|
|
2074
2182
|
i = this._getCoinIdx(inputCoin);
|
|
2075
2183
|
j = this._getCoinIdx(outputCoin);
|
|
2076
2184
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
@@ -2095,14 +2203,21 @@ var Pool = /** @class */ (function () {
|
|
|
2095
2203
|
gasLimit_1 = (_a.sent()).mul(130).div(100);
|
|
2096
2204
|
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_1 }))];
|
|
2097
2205
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
2098
|
-
case 6:
|
|
2206
|
+
case 6:
|
|
2207
|
+
if (!(curve_1.curve.chainId === 137 && this.isFactory)) return [3 /*break*/, 9];
|
|
2208
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2099
2209
|
case 7:
|
|
2210
|
+
gasLimit_2 = (_a.sent()).mul(140).div(100);
|
|
2211
|
+
return [4 /*yield*/, contract[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_2 }))];
|
|
2212
|
+
case 8: return [2 /*return*/, (_a.sent()).hash];
|
|
2213
|
+
case 9: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2214
|
+
case 10:
|
|
2100
2215
|
estimatedGas = _a.sent();
|
|
2101
2216
|
gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
|
|
2102
2217
|
estimatedGas.mul(160).div(100) :
|
|
2103
2218
|
estimatedGas.mul(130).div(100);
|
|
2104
2219
|
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
2105
|
-
case
|
|
2220
|
+
case 11: return [2 /*return*/, (_a.sent()).hash];
|
|
2106
2221
|
}
|
|
2107
2222
|
});
|
|
2108
2223
|
});
|
|
@@ -2212,7 +2327,7 @@ var Pool = /** @class */ (function () {
|
|
|
2212
2327
|
this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
2213
2328
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
2214
2329
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2215
|
-
var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value,
|
|
2330
|
+
var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_3, estimatedGas, gasLimit;
|
|
2216
2331
|
return __generator(this, function (_a) {
|
|
2217
2332
|
switch (_a.label) {
|
|
2218
2333
|
case 0:
|
|
@@ -2239,8 +2354,8 @@ var Pool = /** @class */ (function () {
|
|
|
2239
2354
|
if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
|
|
2240
2355
|
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2241
2356
|
case 4:
|
|
2242
|
-
|
|
2243
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit:
|
|
2357
|
+
gasLimit_3 = (_a.sent()).mul(130).div(100);
|
|
2358
|
+
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_3 }))];
|
|
2244
2359
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
2245
2360
|
case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2246
2361
|
case 7:
|
|
@@ -2264,6 +2379,8 @@ var Pool = /** @class */ (function () {
|
|
|
2264
2379
|
return __generator(this, function (_e) {
|
|
2265
2380
|
switch (_e.label) {
|
|
2266
2381
|
case 0:
|
|
2382
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
2383
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
2267
2384
|
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
2268
2385
|
addresses = addresses[0];
|
|
2269
2386
|
votingEscrowContract = curve_1.curve.contracts[curve_1.ALIASES.voting_escrow].multicallContract;
|
|
@@ -2301,6 +2418,8 @@ var Pool = /** @class */ (function () {
|
|
|
2301
2418
|
return __generator(this, function (_j) {
|
|
2302
2419
|
switch (_j.label) {
|
|
2303
2420
|
case 0:
|
|
2421
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
2422
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
2304
2423
|
if (accounts.length == 1 && Array.isArray(accounts[0]))
|
|
2305
2424
|
accounts = accounts[0];
|
|
2306
2425
|
votingEscrowContract = curve_1.curve.contracts[curve_1.ALIASES.voting_escrow].multicallContract;
|
|
@@ -2361,6 +2480,8 @@ var Pool = /** @class */ (function () {
|
|
|
2361
2480
|
return __generator(this, function (_c) {
|
|
2362
2481
|
switch (_c.label) {
|
|
2363
2482
|
case 0:
|
|
2483
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
2484
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
2364
2485
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
2365
2486
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
2366
2487
|
gaugeContract.working_balances(address),
|
|
@@ -2695,7 +2816,7 @@ var Pool = /** @class */ (function () {
|
|
|
2695
2816
|
switch (_a.label) {
|
|
2696
2817
|
case 0:
|
|
2697
2818
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
2698
|
-
if (!["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name)) return [3 /*break*/, 2];
|
|
2819
|
+
if (!(["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name) || this.isCryptoFactory)) return [3 /*break*/, 2];
|
|
2699
2820
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
2700
2821
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2701
2822
|
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
@@ -2712,7 +2833,7 @@ var Pool = /** @class */ (function () {
|
|
|
2712
2833
|
switch (_a.label) {
|
|
2713
2834
|
case 0:
|
|
2714
2835
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
2715
|
-
if (!this.
|
|
2836
|
+
if (!this.isMetaFactory) return [3 /*break*/, 2];
|
|
2716
2837
|
return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
2717
2838
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2718
2839
|
case 2:
|
|
@@ -2808,7 +2929,7 @@ var Pool = /** @class */ (function () {
|
|
|
2808
2929
|
this._addLiquidityMetaZap = function (_amounts, estimateGas) {
|
|
2809
2930
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
2810
2931
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2811
|
-
var _minMintAmount, ethIndex, value, contract, gas_1,
|
|
2932
|
+
var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_4, gas, gasLimit;
|
|
2812
2933
|
return __generator(this, function (_a) {
|
|
2813
2934
|
switch (_a.label) {
|
|
2814
2935
|
case 0:
|
|
@@ -2823,15 +2944,15 @@ var Pool = /** @class */ (function () {
|
|
|
2823
2944
|
ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
|
|
2824
2945
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
2825
2946
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
2826
|
-
if (!this.
|
|
2947
|
+
if (!this.isMetaFactory) return [3 /*break*/, 6];
|
|
2827
2948
|
return [4 /*yield*/, contract.estimateGas.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2828
2949
|
case 4:
|
|
2829
2950
|
gas_1 = _a.sent();
|
|
2830
2951
|
if (estimateGas) {
|
|
2831
2952
|
return [2 /*return*/, gas_1.toNumber()];
|
|
2832
2953
|
}
|
|
2833
|
-
|
|
2834
|
-
return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
2954
|
+
gasLimit_4 = gas_1.mul(130).div(100);
|
|
2955
|
+
return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4, value: value }))];
|
|
2835
2956
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
2836
2957
|
case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2837
2958
|
case 7:
|
|
@@ -3034,7 +3155,7 @@ var Pool = /** @class */ (function () {
|
|
|
3034
3155
|
this._removeLiquidityMetaZap = function (_lpTokenAmount, estimateGas) {
|
|
3035
3156
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
3036
3157
|
return __awaiter(_this, void 0, void 0, function () {
|
|
3037
|
-
var _minAmounts, contract, gas_2,
|
|
3158
|
+
var _minAmounts, contract, gas_2, gasLimit_5, gas, gasLimit;
|
|
3038
3159
|
return __generator(this, function (_a) {
|
|
3039
3160
|
switch (_a.label) {
|
|
3040
3161
|
case 0:
|
|
@@ -3047,15 +3168,15 @@ var Pool = /** @class */ (function () {
|
|
|
3047
3168
|
case 3:
|
|
3048
3169
|
_minAmounts = _a.sent();
|
|
3049
3170
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
3050
|
-
if (!this.
|
|
3171
|
+
if (!this.isMetaFactory) return [3 /*break*/, 6];
|
|
3051
3172
|
return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
3052
3173
|
case 4:
|
|
3053
3174
|
gas_2 = _a.sent();
|
|
3054
3175
|
if (estimateGas) {
|
|
3055
3176
|
return [2 /*return*/, gas_2.toNumber()];
|
|
3056
3177
|
}
|
|
3057
|
-
|
|
3058
|
-
return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
3178
|
+
gasLimit_5 = gas_2.mul(130).div(100);
|
|
3179
|
+
return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_5 }))];
|
|
3059
3180
|
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
3060
3181
|
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
3061
3182
|
case 7:
|
|
@@ -3158,7 +3279,7 @@ var Pool = /** @class */ (function () {
|
|
|
3158
3279
|
this._removeLiquidityImbalanceMetaZap = function (_amounts, estimateGas) {
|
|
3159
3280
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
3160
3281
|
return __awaiter(_this, void 0, void 0, function () {
|
|
3161
|
-
var _maxBurnAmount, contract, gas_3,
|
|
3282
|
+
var _maxBurnAmount, contract, gas_3, gasLimit_6, gas, gasLimit;
|
|
3162
3283
|
return __generator(this, function (_a) {
|
|
3163
3284
|
switch (_a.label) {
|
|
3164
3285
|
case 0: return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
|
|
@@ -3171,15 +3292,15 @@ var Pool = /** @class */ (function () {
|
|
|
3171
3292
|
_a.label = 3;
|
|
3172
3293
|
case 3:
|
|
3173
3294
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
3174
|
-
if (!this.
|
|
3295
|
+
if (!this.isMetaFactory) return [3 /*break*/, 6];
|
|
3175
3296
|
return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
3176
3297
|
case 4:
|
|
3177
3298
|
gas_3 = _a.sent();
|
|
3178
3299
|
if (estimateGas) {
|
|
3179
3300
|
return [2 /*return*/, gas_3.toNumber()];
|
|
3180
3301
|
}
|
|
3181
|
-
|
|
3182
|
-
return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
3302
|
+
gasLimit_6 = gas_3.mul(130).div(100);
|
|
3303
|
+
return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_6 }))];
|
|
3183
3304
|
case 5: return [2 /*return*/, (_a.sent())];
|
|
3184
3305
|
case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
|
|
3185
3306
|
case 7:
|
|
@@ -3244,7 +3365,7 @@ var Pool = /** @class */ (function () {
|
|
|
3244
3365
|
switch (_a.label) {
|
|
3245
3366
|
case 0:
|
|
3246
3367
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
3247
|
-
if (!this.
|
|
3368
|
+
if (!this.isMetaFactory) return [3 /*break*/, 2];
|
|
3248
3369
|
return [4 /*yield*/, contract.calc_withdraw_one_coin(this.swap, _lpTokenAmount, i, curve_1.curve.constantOptions)];
|
|
3249
3370
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
3250
3371
|
case 2: return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
|
|
@@ -3289,7 +3410,7 @@ var Pool = /** @class */ (function () {
|
|
|
3289
3410
|
this._removeLiquidityOneCoinZap = function (_lpTokenAmount, i, estimateGas) {
|
|
3290
3411
|
if (estimateGas === void 0) { estimateGas = false; }
|
|
3291
3412
|
return __awaiter(_this, void 0, void 0, function () {
|
|
3292
|
-
var _minAmount, _a, contract, gas_4,
|
|
3413
|
+
var _minAmount, _a, contract, gas_4, gasLimit_7, gas, gasLimit;
|
|
3293
3414
|
return __generator(this, function (_c) {
|
|
3294
3415
|
switch (_c.label) {
|
|
3295
3416
|
case 0:
|
|
@@ -3312,15 +3433,15 @@ var Pool = /** @class */ (function () {
|
|
|
3312
3433
|
_minAmount = _a;
|
|
3313
3434
|
_minAmount = _minAmount.mul(99).div(100);
|
|
3314
3435
|
contract = curve_1.curve.contracts[this.zap].contract;
|
|
3315
|
-
if (!this.
|
|
3436
|
+
if (!this.isMetaFactory) return [3 /*break*/, 9];
|
|
3316
3437
|
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
3317
3438
|
case 7:
|
|
3318
3439
|
gas_4 = _c.sent();
|
|
3319
3440
|
if (estimateGas) {
|
|
3320
3441
|
return [2 /*return*/, gas_4.toNumber()];
|
|
3321
3442
|
}
|
|
3322
|
-
|
|
3323
|
-
return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit:
|
|
3443
|
+
gasLimit_7 = gas_4.mul(130).div(100);
|
|
3444
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_7 }))];
|
|
3324
3445
|
case 8: return [2 /*return*/, (_c.sent()).hash];
|
|
3325
3446
|
case 9: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
|
|
3326
3447
|
case 10:
|
|
@@ -3394,7 +3515,7 @@ var Pool = /** @class */ (function () {
|
|
|
3394
3515
|
}
|
|
3395
3516
|
});
|
|
3396
3517
|
}); };
|
|
3397
|
-
var poolData = curve_1.POOLS_DATA[name];
|
|
3518
|
+
var poolData = __assign(__assign(__assign({}, curve_1.POOLS_DATA), (curve_1.curve.constants.FACTORY_POOLS_DATA || {})), (curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA || {}))[name];
|
|
3398
3519
|
this.name = name;
|
|
3399
3520
|
this.referenceAsset = poolData.reference_asset;
|
|
3400
3521
|
this.swap = poolData.swap_address;
|
|
@@ -3413,6 +3534,9 @@ var Pool = /** @class */ (function () {
|
|
|
3413
3534
|
this.isFake = poolData.is_fake || false;
|
|
3414
3535
|
this.isCrypto = poolData.is_crypto || false;
|
|
3415
3536
|
this.isFactory = poolData.is_factory || false;
|
|
3537
|
+
this.isMetaFactory = poolData.is_meta_factory || false;
|
|
3538
|
+
this.isPlainFactory = poolData.is_plain_factory || false;
|
|
3539
|
+
this.isCryptoFactory = poolData.is_crypto_factory || false;
|
|
3416
3540
|
this.basePool = poolData.base_pool || '';
|
|
3417
3541
|
this.rewardTokens = poolData.reward_tokens || [];
|
|
3418
3542
|
this.estimateGas = {
|
|
@@ -3463,8 +3587,8 @@ var Pool = /** @class */ (function () {
|
|
|
3463
3587
|
exports.Pool = Pool;
|
|
3464
3588
|
// --------- Exchange Using All Pools ---------
|
|
3465
3589
|
var _estimatedGasForPoolsCache = {};
|
|
3466
|
-
var _estimateGasForPools = function (
|
|
3467
|
-
var registryExchangeContract, sortedCoins, gasPromises, _i,
|
|
3590
|
+
var _estimateGasForPools = function (pools, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3591
|
+
var registryExchangeContract, sortedCoins, gasPromises, _i, pools_1, pool, key, gasPromise, _route, _swapParams, _pools, _gasAmounts_1, err_1;
|
|
3468
3592
|
var _a;
|
|
3469
3593
|
return __generator(this, function (_c) {
|
|
3470
3594
|
switch (_c.label) {
|
|
@@ -3472,12 +3596,15 @@ var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoin
|
|
|
3472
3596
|
registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
|
|
3473
3597
|
sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
|
|
3474
3598
|
gasPromises = [];
|
|
3475
|
-
for (_i = 0,
|
|
3476
|
-
|
|
3477
|
-
key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
|
|
3599
|
+
for (_i = 0, pools_1 = pools; _i < pools_1.length; _i++) {
|
|
3600
|
+
pool = pools_1[_i];
|
|
3601
|
+
key = "".concat(pool.poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
|
|
3478
3602
|
gasPromise = void 0;
|
|
3603
|
+
_route = [inputCoinAddress, pool.poolAddress, outputCoinAddress].concat(Array(6).fill(ethers_1.ethers.constants.AddressZero));
|
|
3604
|
+
_swapParams = [[pool.i, pool.j, pool.swapType]].concat(Array(3).fill([0, 0, 0]));
|
|
3605
|
+
_pools = [pool.swapAddress].concat(Array(3).fill(ethers_1.ethers.constants.AddressZero));
|
|
3479
3606
|
if ((((_a = _estimatedGasForPoolsCache[key]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 3600000 < Date.now()) {
|
|
3480
|
-
gasPromise = registryExchangeContract.estimateGas.
|
|
3607
|
+
gasPromise = registryExchangeContract.estimateGas.exchange_multiple(_route, _swapParams, _amount, 0, _pools, curve_1.curve.constantOptions);
|
|
3481
3608
|
}
|
|
3482
3609
|
else {
|
|
3483
3610
|
gasPromise = Promise.resolve(_estimatedGasForPoolsCache[key].gas);
|
|
@@ -3490,101 +3617,168 @@ var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoin
|
|
|
3490
3617
|
return [4 /*yield*/, Promise.all(gasPromises)];
|
|
3491
3618
|
case 2:
|
|
3492
3619
|
_gasAmounts_1 = _c.sent();
|
|
3493
|
-
|
|
3494
|
-
var key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
|
|
3620
|
+
pools.forEach(function (pool, i) {
|
|
3621
|
+
var key = "".concat(pool.poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
|
|
3495
3622
|
_estimatedGasForPoolsCache[key] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
|
|
3496
3623
|
});
|
|
3497
3624
|
return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(ethers_1.ethers.utils.formatUnits(_g, 0)); })];
|
|
3498
3625
|
case 3:
|
|
3499
3626
|
err_1 = _c.sent();
|
|
3500
|
-
return [2 /*return*/,
|
|
3627
|
+
return [2 /*return*/, pools.map(function () { return 0; })];
|
|
3501
3628
|
case 4: return [2 /*return*/];
|
|
3502
3629
|
}
|
|
3503
3630
|
});
|
|
3504
3631
|
}); };
|
|
3632
|
+
var _getAvailablePools = function (inputCoinAddress, outputCoinAddress) {
|
|
3633
|
+
return Object.entries(__assign(__assign(__assign({}, curve_1.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA)).map(function (_a) {
|
|
3634
|
+
var _c;
|
|
3635
|
+
var poolName = _a[0], poolData = _a[1];
|
|
3636
|
+
var coin_addresses = poolData.coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
3637
|
+
var underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
3638
|
+
var meta_coin_addresses = ((_c = poolData.meta_coin_addresses) === null || _c === void 0 ? void 0 : _c.map(function (a) { return a.toLowerCase(); })) || [];
|
|
3639
|
+
var inputCoinIndexes = {
|
|
3640
|
+
coin: coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
|
|
3641
|
+
underlying_coin: underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
|
|
3642
|
+
meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
|
|
3643
|
+
};
|
|
3644
|
+
var outputCoinIndexes = {
|
|
3645
|
+
coin: coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
3646
|
+
underlying_coin: underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
3647
|
+
meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
|
|
3648
|
+
};
|
|
3649
|
+
// Only for underlying swaps
|
|
3650
|
+
var poolAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(poolName) ||
|
|
3651
|
+
(curve_1.curve.chainId === 137 && poolData.is_factory) ? poolData.deposit_address : poolData.swap_address;
|
|
3652
|
+
if (inputCoinIndexes.coin >= 0 && outputCoinIndexes.coin >= 0 && poolName !== "atricrypto3") {
|
|
3653
|
+
var swapType = poolData.is_crypto ? 3 : 1;
|
|
3654
|
+
return {
|
|
3655
|
+
poolName: poolName,
|
|
3656
|
+
poolAddress: poolData.swap_address,
|
|
3657
|
+
i: inputCoinIndexes.coin,
|
|
3658
|
+
j: outputCoinIndexes.coin,
|
|
3659
|
+
swapType: swapType,
|
|
3660
|
+
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
else if (inputCoinIndexes.underlying_coin >= 0 &&
|
|
3664
|
+
outputCoinIndexes.underlying_coin >= 0 &&
|
|
3665
|
+
!(poolName === "atricrypto3" && (inputCoinIndexes.meta_coin >= 0 && outputCoinIndexes.meta_coin >= 0))) {
|
|
3666
|
+
var swapType = poolData.is_crypto && (poolData.is_fake || poolData.is_meta) ? 4 : poolData.is_crypto ? 3 : 2;
|
|
3667
|
+
return {
|
|
3668
|
+
poolName: poolName,
|
|
3669
|
+
poolAddress: poolAddress,
|
|
3670
|
+
i: inputCoinIndexes.underlying_coin,
|
|
3671
|
+
j: outputCoinIndexes.underlying_coin,
|
|
3672
|
+
swapType: swapType,
|
|
3673
|
+
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
3674
|
+
};
|
|
3675
|
+
}
|
|
3676
|
+
else if (inputCoinIndexes.coin === 0 && outputCoinIndexes.meta_coin >= 0 && poolName !== "atricrypto3") {
|
|
3677
|
+
var swapType = (curve_1.curve.chainId === 137 && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
|
|
3678
|
+
return {
|
|
3679
|
+
poolName: poolName,
|
|
3680
|
+
poolAddress: poolAddress,
|
|
3681
|
+
i: inputCoinIndexes.coin,
|
|
3682
|
+
j: outputCoinIndexes.meta_coin + 1,
|
|
3683
|
+
swapType: swapType,
|
|
3684
|
+
swapAddress: swapType === 5 ? poolData.swap_address : ethers_1.ethers.constants.AddressZero,
|
|
3685
|
+
};
|
|
3686
|
+
}
|
|
3687
|
+
else if (inputCoinIndexes.meta_coin >= 0 && outputCoinIndexes.coin === 0 && poolName !== "atricrypto3") {
|
|
3688
|
+
var swapType = (curve_1.curve.chainId === 137 && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
|
|
3689
|
+
return {
|
|
3690
|
+
poolName: poolName,
|
|
3691
|
+
poolAddress: poolAddress,
|
|
3692
|
+
i: inputCoinIndexes.meta_coin + 1,
|
|
3693
|
+
j: outputCoinIndexes.coin,
|
|
3694
|
+
swapType: swapType,
|
|
3695
|
+
swapAddress: swapType === 5 ? poolData.swap_address : ethers_1.ethers.constants.AddressZero,
|
|
3696
|
+
};
|
|
3697
|
+
}
|
|
3698
|
+
else {
|
|
3699
|
+
return null;
|
|
3700
|
+
}
|
|
3701
|
+
}).filter(function (pool) { return pool !== null; });
|
|
3702
|
+
};
|
|
3505
3703
|
var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3506
|
-
var
|
|
3507
|
-
return __generator(this, function (
|
|
3508
|
-
switch (
|
|
3704
|
+
var _a, inputCoinDecimals, outputCoinDecimals, _amount, availablePoolsRaw, availablePools, _i, availablePoolsRaw_1, pool, poolName, poolAddress, i, j, swapType, swapAddress, contract, _c, _d, err_2, _e, poolName, poolAddress, i, j, swapType, _output, swapAddress, _f, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd;
|
|
3705
|
+
return __generator(this, function (_h) {
|
|
3706
|
+
switch (_h.label) {
|
|
3509
3707
|
case 0:
|
|
3510
|
-
availablePools = Object.entries(curve_1.POOLS_DATA).map(function (pool) {
|
|
3511
|
-
var _a;
|
|
3512
|
-
var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
3513
|
-
var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
3514
|
-
var meta_coin_addresses = (_a = pool[1].meta_coin_addresses) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a.toLowerCase(); });
|
|
3515
|
-
var inputCoinIndexes = [
|
|
3516
|
-
coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
|
|
3517
|
-
underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
|
|
3518
|
-
meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
|
|
3519
|
-
];
|
|
3520
|
-
var outputCoinIndexes = [
|
|
3521
|
-
coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
3522
|
-
underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
|
|
3523
|
-
meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
|
|
3524
|
-
];
|
|
3525
|
-
if (pool[0] === 'atricrypto3') {
|
|
3526
|
-
return null;
|
|
3527
|
-
}
|
|
3528
|
-
if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
|
|
3529
|
-
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3530
|
-
}
|
|
3531
|
-
else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
|
|
3532
|
-
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3533
|
-
}
|
|
3534
|
-
else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
|
|
3535
|
-
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3536
|
-
}
|
|
3537
|
-
else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
|
|
3538
|
-
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3539
|
-
}
|
|
3540
|
-
else {
|
|
3541
|
-
return null;
|
|
3542
|
-
}
|
|
3543
|
-
}).filter(function (pool) { return pool !== null; });
|
|
3544
3708
|
_a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
|
|
3545
3709
|
_amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
poolAddress = availablePools[0].poolAddress;
|
|
3551
|
-
registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
|
|
3552
|
-
return [4 /*yield*/, registryExchangeContract.get_exchange_amount(poolAddress, inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
|
|
3710
|
+
availablePoolsRaw = _getAvailablePools(inputCoinAddress, outputCoinAddress).map(function (data) { return (__assign(__assign({}, data), { _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 })); });
|
|
3711
|
+
availablePools = [];
|
|
3712
|
+
_i = 0, availablePoolsRaw_1 = availablePoolsRaw;
|
|
3713
|
+
_h.label = 1;
|
|
3553
3714
|
case 1:
|
|
3554
|
-
|
|
3555
|
-
|
|
3715
|
+
if (!(_i < availablePoolsRaw_1.length)) return [3 /*break*/, 9];
|
|
3716
|
+
pool = availablePoolsRaw_1[_i];
|
|
3717
|
+
poolName = pool.poolName, poolAddress = pool.poolAddress, i = pool.i, j = pool.j, swapType = pool.swapType, swapAddress = pool.swapAddress;
|
|
3718
|
+
contract = curve_1.curve.contracts[swapAddress === ethers_1.ethers.constants.AddressZero ? poolAddress : swapAddress].contract;
|
|
3719
|
+
_h.label = 2;
|
|
3556
3720
|
case 2:
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3721
|
+
_h.trys.push([2, 7, , 8]);
|
|
3722
|
+
_c = pool;
|
|
3723
|
+
if (![2, 4, 5].includes(swapType)) return [3 /*break*/, 4];
|
|
3724
|
+
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
3725
|
+
case 3:
|
|
3726
|
+
_d = _h.sent();
|
|
3727
|
+
return [3 /*break*/, 6];
|
|
3728
|
+
case 4: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
|
|
3729
|
+
case 5:
|
|
3730
|
+
_d = _h.sent();
|
|
3731
|
+
_h.label = 6;
|
|
3732
|
+
case 6:
|
|
3733
|
+
_c._output = _d;
|
|
3734
|
+
availablePools.push(pool);
|
|
3735
|
+
return [3 /*break*/, 8];
|
|
3736
|
+
case 7:
|
|
3737
|
+
err_2 = _h.sent();
|
|
3738
|
+
console.log("Pool ".concat(poolName, " is empty or very imbalanced"));
|
|
3739
|
+
return [3 /*break*/, 8];
|
|
3740
|
+
case 8:
|
|
3741
|
+
_i++;
|
|
3742
|
+
return [3 /*break*/, 1];
|
|
3743
|
+
case 9:
|
|
3744
|
+
if (availablePools.length === 0) {
|
|
3745
|
+
return [2 /*return*/, {
|
|
3746
|
+
poolName: "",
|
|
3747
|
+
poolAddress: ethers_1.ethers.constants.AddressZero,
|
|
3748
|
+
i: 0,
|
|
3749
|
+
j: 0,
|
|
3750
|
+
swapType: 1,
|
|
3751
|
+
swapAddress: ethers_1.ethers.constants.AddressZero,
|
|
3752
|
+
_output: ethers_1.ethers.BigNumber.from(0),
|
|
3753
|
+
}];
|
|
3754
|
+
}
|
|
3755
|
+
if (availablePools.length === 1) {
|
|
3756
|
+
_e = availablePools[0], poolName = _e.poolName, poolAddress = _e.poolAddress, i = _e.i, j = _e.j, swapType = _e.swapType, _output = _e._output, swapAddress = _e.swapAddress;
|
|
3757
|
+
return [2 /*return*/, { poolName: poolName, poolAddress: poolAddress, i: i, j: j, swapType: swapType, _output: _output, swapAddress: swapAddress }];
|
|
3562
3758
|
}
|
|
3563
3759
|
return [4 /*yield*/, Promise.all([
|
|
3564
|
-
|
|
3565
|
-
_estimateGasForPools(availablePools
|
|
3760
|
+
// curve.multicallProvider.all(calls),
|
|
3761
|
+
_estimateGasForPools(availablePools, inputCoinAddress, outputCoinAddress, _amount),
|
|
3566
3762
|
(0, utils_1._getUsdRate)(outputCoinAddress),
|
|
3567
3763
|
axios_1.default.get("https://api.curve.fi/api/getGas"),
|
|
3568
|
-
(0, utils_1._getUsdRate)(curve_1.COINS.eth),
|
|
3764
|
+
(0, utils_1._getUsdRate)(curve_1.curve.chainId === 137 ? curve_1.COINS.matic : curve_1.COINS.eth),
|
|
3569
3765
|
])];
|
|
3570
|
-
case
|
|
3571
|
-
|
|
3766
|
+
case 10:
|
|
3767
|
+
_f = _h.sent(), gasAmounts = _f[0], outputCoinUsdRate = _f[1], gasData = _f[2], ethUsdRate = _f[3];
|
|
3572
3768
|
gasPrice = gasData.data.data.gas.standard;
|
|
3573
|
-
expectedAmounts =
|
|
3769
|
+
expectedAmounts = (availablePools).map(function (swapData) { return Number(ethers_1.ethers.utils.formatUnits(swapData._output, outputCoinDecimals)); });
|
|
3574
3770
|
expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
|
|
3575
3771
|
txCostsUsd = gasAmounts.map(function (a) { return ethUsdRate * a * gasPrice / 1e18; });
|
|
3576
3772
|
availablePools.forEach(function (pool, i) {
|
|
3577
|
-
pool._output = _expectedAmounts[i];
|
|
3578
3773
|
pool.outputUsd = expectedAmountsUsd[i];
|
|
3579
3774
|
pool.txCostUsd = txCostsUsd[i];
|
|
3580
3775
|
});
|
|
3581
|
-
|
|
3582
|
-
return [2 /*return*/, { poolAddress: bestPool.poolAddress, _output: bestPool._output }];
|
|
3776
|
+
return [2 /*return*/, availablePools.reduce(function (pool1, pool2) { return (pool1.outputUsd - pool1.txCostUsd) - (pool2.outputUsd - pool2.txCostUsd) >= 0 ? pool1 : pool2; })];
|
|
3583
3777
|
}
|
|
3584
3778
|
});
|
|
3585
3779
|
}); };
|
|
3586
3780
|
var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3587
|
-
var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolAddress, _output;
|
|
3781
|
+
var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolName, poolAddress, _output;
|
|
3588
3782
|
return __generator(this, function (_d) {
|
|
3589
3783
|
switch (_d.label) {
|
|
3590
3784
|
case 0:
|
|
@@ -3592,8 +3786,8 @@ var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __a
|
|
|
3592
3786
|
outputCoinDecimals = (0, utils_1._getCoinDecimals)(outputCoinAddress)[0];
|
|
3593
3787
|
return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
|
|
3594
3788
|
case 1:
|
|
3595
|
-
_c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
|
|
3596
|
-
return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
|
|
3789
|
+
_c = _d.sent(), poolName = _c.poolName, poolAddress = _c.poolAddress, _output = _c._output;
|
|
3790
|
+
return [2 /*return*/, { poolName: poolName, poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
|
|
3597
3791
|
}
|
|
3598
3792
|
});
|
|
3599
3793
|
}); };
|
|
@@ -3637,7 +3831,7 @@ exports.exchangeApprove = exchangeApprove;
|
|
|
3637
3831
|
var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
3638
3832
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
3639
3833
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
3640
|
-
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
|
|
3834
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, i, j, swapType, swapAddress, _output, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
|
|
3641
3835
|
return __generator(this, function (_e) {
|
|
3642
3836
|
switch (_e.label) {
|
|
3643
3837
|
case 0:
|
|
@@ -3645,10 +3839,13 @@ var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage)
|
|
|
3645
3839
|
_c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
3646
3840
|
return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
|
|
3647
3841
|
case 1:
|
|
3648
|
-
_d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
|
|
3842
|
+
_d = _e.sent(), poolAddress = _d.poolAddress, i = _d.i, j = _d.j, swapType = _d.swapType, swapAddress = _d.swapAddress, _output = _d._output;
|
|
3649
3843
|
if (poolAddress === "0x0000000000000000000000000000000000000000") {
|
|
3650
3844
|
throw new Error("This pair can't be exchanged");
|
|
3651
3845
|
}
|
|
3846
|
+
_route = [inputCoinAddress, poolAddress, outputCoinAddress].concat(Array(6).fill(ethers_1.ethers.constants.AddressZero));
|
|
3847
|
+
_swapParams = [[i, j, swapType]].concat(Array(3).fill([0, 0, 0]));
|
|
3848
|
+
_pools = [swapAddress].concat(Array(3).fill(ethers_1.ethers.constants.AddressZero));
|
|
3652
3849
|
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
3653
3850
|
minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
|
|
3654
3851
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
@@ -3657,7 +3854,7 @@ var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage)
|
|
|
3657
3854
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
3658
3855
|
case 2:
|
|
3659
3856
|
_e.sent();
|
|
3660
|
-
return [4 /*yield*/, contract.estimateGas.
|
|
3857
|
+
return [4 /*yield*/, contract.estimateGas.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
3661
3858
|
case 3: return [2 /*return*/, (_e.sent()).toNumber()];
|
|
3662
3859
|
}
|
|
3663
3860
|
});
|
|
@@ -3667,7 +3864,7 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
|
|
|
3667
3864
|
var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
3668
3865
|
if (maxSlippage === void 0) { maxSlippage = 0.01; }
|
|
3669
3866
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
3670
|
-
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
|
|
3867
|
+
var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, i, j, swapType, swapAddress, _output, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
|
|
3671
3868
|
return __generator(this, function (_e) {
|
|
3672
3869
|
switch (_e.label) {
|
|
3673
3870
|
case 0:
|
|
@@ -3678,10 +3875,13 @@ var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
|
3678
3875
|
_e.sent();
|
|
3679
3876
|
return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
|
|
3680
3877
|
case 2:
|
|
3681
|
-
_d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
|
|
3878
|
+
_d = _e.sent(), poolAddress = _d.poolAddress, i = _d.i, j = _d.j, swapType = _d.swapType, swapAddress = _d.swapAddress, _output = _d._output;
|
|
3682
3879
|
if (poolAddress === "0x0000000000000000000000000000000000000000") {
|
|
3683
3880
|
throw new Error("This pair can't be exchanged");
|
|
3684
3881
|
}
|
|
3882
|
+
_route = [inputCoinAddress, poolAddress, outputCoinAddress].concat(Array(6).fill(ethers_1.ethers.constants.AddressZero));
|
|
3883
|
+
_swapParams = [[i, j, swapType]].concat(Array(3).fill([0, 0, 0]));
|
|
3884
|
+
_pools = [swapAddress].concat(Array(3).fill(ethers_1.ethers.constants.AddressZero));
|
|
3685
3885
|
_amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
|
|
3686
3886
|
minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
|
|
3687
3887
|
_minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
|
|
@@ -3690,10 +3890,10 @@ var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
|
|
|
3690
3890
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
3691
3891
|
case 3:
|
|
3692
3892
|
_e.sent();
|
|
3693
|
-
return [4 /*yield*/, contract.estimateGas.
|
|
3893
|
+
return [4 /*yield*/, contract.estimateGas.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
3694
3894
|
case 4:
|
|
3695
3895
|
gasLimit = (_e.sent()).mul(130).div(100);
|
|
3696
|
-
return [4 /*yield*/, contract.
|
|
3896
|
+
return [4 /*yield*/, contract.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
3697
3897
|
case 5: return [2 /*return*/, (_e.sent()).hash];
|
|
3698
3898
|
}
|
|
3699
3899
|
});
|