@curvefi/api 1.15.1 → 1.17.1
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 +61 -0
- package/lib/constants/abis/abis-ethereum.js +95 -0
- package/lib/constants/abis/json/deposit_and_stake.json +51 -0
- package/lib/constants/aliases.d.ts +2 -0
- package/lib/constants/aliases.js +2 -0
- package/lib/constants/coins-ethereum.js +7 -3
- package/lib/curve.d.ts +1 -0
- package/lib/curve.js +10 -0
- package/lib/pools.d.ts +23 -0
- package/lib/pools.js +560 -76
- package/package.json +1 -1
package/lib/pools.js
CHANGED
|
@@ -81,7 +81,7 @@ 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"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
84
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
85
85
|
return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
|
|
86
86
|
case 1:
|
|
87
87
|
_expected = _a.sent(); // Lending pools
|
|
@@ -192,7 +192,7 @@ var Pool = /** @class */ (function () {
|
|
|
192
192
|
_poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
|
|
193
193
|
return [3 /*break*/, 6];
|
|
194
194
|
case 3:
|
|
195
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
195
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
196
196
|
return [4 /*yield*/, this._getRates()];
|
|
197
197
|
case 4:
|
|
198
198
|
_rates_1 = _a.sent();
|
|
@@ -382,49 +382,52 @@ var Pool = /** @class */ (function () {
|
|
|
382
382
|
});
|
|
383
383
|
}); };
|
|
384
384
|
this.addLiquiditySlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
385
|
-
var totalAmount, expected,
|
|
386
|
-
return __generator(this, function (
|
|
387
|
-
switch (
|
|
385
|
+
var prices_1, totalAmountUSD, expected_1, _a, totalAmount, expected, _c;
|
|
386
|
+
return __generator(this, function (_d) {
|
|
387
|
+
switch (_d.label) {
|
|
388
388
|
case 0:
|
|
389
|
-
|
|
389
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
390
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
391
|
+
case 1:
|
|
392
|
+
prices_1 = _d.sent();
|
|
393
|
+
totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_1[i]); }, 0);
|
|
390
394
|
_a = Number;
|
|
391
395
|
return [4 /*yield*/, this.addLiquidityExpected(amounts)];
|
|
392
|
-
case
|
|
393
|
-
|
|
396
|
+
case 2:
|
|
397
|
+
expected_1 = _a.apply(void 0, [_d.sent()]);
|
|
398
|
+
return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_1)];
|
|
399
|
+
case 3: return [2 /*return*/, _d.sent()];
|
|
400
|
+
case 4:
|
|
401
|
+
totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
|
|
402
|
+
_c = Number;
|
|
403
|
+
return [4 /*yield*/, this.addLiquidityExpected(amounts)];
|
|
404
|
+
case 5:
|
|
405
|
+
expected = _c.apply(void 0, [_d.sent()]);
|
|
394
406
|
return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected)];
|
|
395
|
-
case
|
|
407
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
396
408
|
}
|
|
397
409
|
});
|
|
398
410
|
}); };
|
|
399
411
|
this.addLiquidityIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
400
|
-
var spender;
|
|
401
412
|
return __generator(this, function (_a) {
|
|
402
413
|
switch (_a.label) {
|
|
403
|
-
case 0:
|
|
404
|
-
spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
|
|
405
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, spender)];
|
|
414
|
+
case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
|
|
406
415
|
case 1: return [2 /*return*/, _a.sent()];
|
|
407
416
|
}
|
|
408
417
|
});
|
|
409
418
|
}); };
|
|
410
419
|
this.addLiquidityApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
411
|
-
var spender;
|
|
412
420
|
return __generator(this, function (_a) {
|
|
413
421
|
switch (_a.label) {
|
|
414
|
-
case 0:
|
|
415
|
-
spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
|
|
416
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, spender)];
|
|
422
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, this.zap || this.swap)];
|
|
417
423
|
case 1: return [2 /*return*/, _a.sent()];
|
|
418
424
|
}
|
|
419
425
|
});
|
|
420
426
|
}); };
|
|
421
427
|
this.addLiquidityApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
422
|
-
var spender;
|
|
423
428
|
return __generator(this, function (_a) {
|
|
424
429
|
switch (_a.label) {
|
|
425
|
-
case 0:
|
|
426
|
-
spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
|
|
427
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, spender)];
|
|
430
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, this.zap || this.swap)];
|
|
428
431
|
case 1: return [2 /*return*/, _a.sent()];
|
|
429
432
|
}
|
|
430
433
|
});
|
|
@@ -459,7 +462,7 @@ var Pool = /** @class */ (function () {
|
|
|
459
462
|
return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
|
|
460
463
|
case 3: return [2 /*return*/, _d.sent()];
|
|
461
464
|
case 4:
|
|
462
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
|
|
465
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
|
|
463
466
|
return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
|
|
464
467
|
case 5: return [2 /*return*/, _d.sent()];
|
|
465
468
|
case 6:
|
|
@@ -474,7 +477,7 @@ var Pool = /** @class */ (function () {
|
|
|
474
477
|
});
|
|
475
478
|
}); };
|
|
476
479
|
this.balancedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
477
|
-
var poolBalances, walletBalances, _a, _c;
|
|
480
|
+
var poolBalances, walletBalances, _a, _c, prices_2, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
|
|
478
481
|
return __generator(this, function (_d) {
|
|
479
482
|
switch (_d.label) {
|
|
480
483
|
case 0: return [4 /*yield*/, this.getPoolBalances()];
|
|
@@ -484,7 +487,15 @@ var Pool = /** @class */ (function () {
|
|
|
484
487
|
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
485
488
|
case 2:
|
|
486
489
|
walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
|
|
487
|
-
return [
|
|
490
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
491
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
492
|
+
case 3:
|
|
493
|
+
prices_2 = _d.sent();
|
|
494
|
+
poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_2[i]; });
|
|
495
|
+
walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_2[i]; });
|
|
496
|
+
balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.underlyingDecimals);
|
|
497
|
+
return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_2[i], poolBalances[i])); })];
|
|
498
|
+
case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
|
|
488
499
|
}
|
|
489
500
|
});
|
|
490
501
|
}); };
|
|
@@ -507,7 +518,7 @@ var Pool = /** @class */ (function () {
|
|
|
507
518
|
return [4 /*yield*/, this._addLiquidityZap(_amounts)];
|
|
508
519
|
case 2: return [2 /*return*/, _a.sent()];
|
|
509
520
|
case 3:
|
|
510
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
521
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
511
522
|
return [4 /*yield*/, this._addLiquidity(_amounts, true)];
|
|
512
523
|
case 4: return [2 /*return*/, _a.sent()];
|
|
513
524
|
case 5:
|
|
@@ -521,8 +532,197 @@ var Pool = /** @class */ (function () {
|
|
|
521
532
|
}
|
|
522
533
|
});
|
|
523
534
|
}); };
|
|
535
|
+
this.depositAndStakeExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
536
|
+
return __generator(this, function (_a) {
|
|
537
|
+
switch (_a.label) {
|
|
538
|
+
case 0: return [4 /*yield*/, this.addLiquidityExpected(amounts)];
|
|
539
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}); };
|
|
543
|
+
this.depositAndStakeSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
544
|
+
return __generator(this, function (_a) {
|
|
545
|
+
switch (_a.label) {
|
|
546
|
+
case 0: return [4 /*yield*/, this.addLiquiditySlippage(amounts)];
|
|
547
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}); };
|
|
551
|
+
this.depositAndStakeIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
552
|
+
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
553
|
+
return __generator(this, function (_a) {
|
|
554
|
+
switch (_a.label) {
|
|
555
|
+
case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
|
|
556
|
+
case 1:
|
|
557
|
+
coinsAllowance = _a.sent();
|
|
558
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
559
|
+
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
|
|
560
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
|
|
561
|
+
case 2:
|
|
562
|
+
gaugeAllowance = _a.sent();
|
|
563
|
+
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
564
|
+
case 3: return [2 /*return*/, coinsAllowance];
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
}); };
|
|
568
|
+
this.depositAndStakeApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
569
|
+
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
570
|
+
return __generator(this, function (_a) {
|
|
571
|
+
switch (_a.label) {
|
|
572
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
573
|
+
case 1:
|
|
574
|
+
approveCoinsGas = _a.sent();
|
|
575
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
576
|
+
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
|
|
577
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
|
|
578
|
+
case 2:
|
|
579
|
+
gaugeAllowance = _a.sent();
|
|
580
|
+
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
581
|
+
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
582
|
+
case 3:
|
|
583
|
+
approveGaugeGas = (_a.sent()).toNumber();
|
|
584
|
+
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
585
|
+
case 4: return [2 /*return*/, approveCoinsGas];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}); };
|
|
589
|
+
this.depositAndStakeApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
590
|
+
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
591
|
+
return __generator(this, function (_a) {
|
|
592
|
+
switch (_a.label) {
|
|
593
|
+
case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
594
|
+
case 1:
|
|
595
|
+
approveCoinsTx = _a.sent();
|
|
596
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
597
|
+
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
|
|
598
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
|
|
599
|
+
case 2:
|
|
600
|
+
gaugeAllowance = _a.sent();
|
|
601
|
+
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
602
|
+
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
603
|
+
case 3:
|
|
604
|
+
gasLimit = (_a.sent()).mul(130).div(100);
|
|
605
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
606
|
+
case 4:
|
|
607
|
+
approveGaugeTx = (_a.sent()).hash;
|
|
608
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
609
|
+
case 5: return [2 /*return*/, approveCoinsTx];
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}); };
|
|
613
|
+
this.depositAndStakeEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
614
|
+
return __generator(this, function (_a) {
|
|
615
|
+
switch (_a.label) {
|
|
616
|
+
case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
|
|
617
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}); };
|
|
621
|
+
this.depositAndStake = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
622
|
+
return __generator(this, function (_a) {
|
|
623
|
+
switch (_a.label) {
|
|
624
|
+
case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
|
|
625
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}); };
|
|
629
|
+
this._depositAndStake = function (amounts, isUnderlying, estimateGas) { return __awaiter(_this, void 0, void 0, function () {
|
|
630
|
+
var coinAddresses, coins, decimals, depositAddress, balances, _a, _c, _d, _e, _f, i, allowance, _h, _amounts, contract, useUnderlying, _minMintAmount, _j, _k, _l, _m, _o, ethIndex, value, i, _gas, gasLimit;
|
|
631
|
+
return __generator(this, function (_p) {
|
|
632
|
+
switch (_p.label) {
|
|
633
|
+
case 0:
|
|
634
|
+
coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.coinAddresses, true);
|
|
635
|
+
coins = isUnderlying ? this.underlyingCoins : this.coinAddresses;
|
|
636
|
+
decimals = isUnderlying ? this.underlyingDecimals : this.decimals;
|
|
637
|
+
depositAddress = isUnderlying ? this.zap || this.swap : this.swap;
|
|
638
|
+
if (amounts.length !== coinAddresses.length) {
|
|
639
|
+
throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
640
|
+
}
|
|
641
|
+
if (!isUnderlying) return [3 /*break*/, 2];
|
|
642
|
+
_d = (_c = Object).values;
|
|
643
|
+
return [4 /*yield*/, this.underlyingCoinBalances()];
|
|
644
|
+
case 1:
|
|
645
|
+
_a = _d.apply(_c, [_p.sent()]);
|
|
646
|
+
return [3 /*break*/, 4];
|
|
647
|
+
case 2:
|
|
648
|
+
_f = (_e = Object).values;
|
|
649
|
+
return [4 /*yield*/, this.coinBalances()];
|
|
650
|
+
case 3:
|
|
651
|
+
_a = _f.apply(_e, [_p.sent()]);
|
|
652
|
+
_p.label = 4;
|
|
653
|
+
case 4:
|
|
654
|
+
balances = _a;
|
|
655
|
+
for (i = 0; i < balances.length; i++) {
|
|
656
|
+
if (Number(balances[i]) < Number(amounts[i])) {
|
|
657
|
+
throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (!isUnderlying) return [3 /*break*/, 6];
|
|
661
|
+
return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
|
|
662
|
+
case 5:
|
|
663
|
+
_h = _p.sent();
|
|
664
|
+
return [3 /*break*/, 8];
|
|
665
|
+
case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
|
|
666
|
+
case 7:
|
|
667
|
+
_h = _p.sent();
|
|
668
|
+
_p.label = 8;
|
|
669
|
+
case 8:
|
|
670
|
+
allowance = _h;
|
|
671
|
+
if (estimateGas && !allowance) {
|
|
672
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
673
|
+
}
|
|
674
|
+
if (!!estimateGas) return [3 /*break*/, 12];
|
|
675
|
+
if (!isUnderlying) return [3 /*break*/, 10];
|
|
676
|
+
return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
|
|
677
|
+
case 9:
|
|
678
|
+
_p.sent();
|
|
679
|
+
return [3 /*break*/, 12];
|
|
680
|
+
case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
|
|
681
|
+
case 11:
|
|
682
|
+
_p.sent();
|
|
683
|
+
_p.label = 12;
|
|
684
|
+
case 12:
|
|
685
|
+
_amounts = amounts.map(function (amount, i) {
|
|
686
|
+
return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
|
|
687
|
+
});
|
|
688
|
+
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) || (curve_1.curve.chainId === 137 && this.name === 'ren'));
|
|
690
|
+
if (!isUnderlying) return [3 /*break*/, 14];
|
|
691
|
+
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
692
|
+
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
693
|
+
case 13:
|
|
694
|
+
_j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
|
|
695
|
+
return [3 /*break*/, 16];
|
|
696
|
+
case 14:
|
|
697
|
+
_o = (_m = ethers_1.ethers.utils).parseUnits;
|
|
698
|
+
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
699
|
+
case 15:
|
|
700
|
+
_j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
|
|
701
|
+
_p.label = 16;
|
|
702
|
+
case 16:
|
|
703
|
+
_minMintAmount = _j;
|
|
704
|
+
ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
|
|
705
|
+
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
706
|
+
for (i = 0; i < 5; i++) {
|
|
707
|
+
coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
|
|
708
|
+
_amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
|
|
709
|
+
}
|
|
710
|
+
return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
711
|
+
case 17:
|
|
712
|
+
_gas = (_p.sent());
|
|
713
|
+
if (estimateGas)
|
|
714
|
+
return [2 /*return*/, _gas.toNumber()];
|
|
715
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
716
|
+
case 18:
|
|
717
|
+
_p.sent();
|
|
718
|
+
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.isFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
|
|
720
|
+
case 19: return [2 /*return*/, (_p.sent()).hash];
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
}); };
|
|
524
724
|
this.balancedWrappedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
525
|
-
var poolBalances, walletBalances, _a, _c;
|
|
725
|
+
var poolBalances, walletBalances, _a, _c, prices_3, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
|
|
526
726
|
return __generator(this, function (_d) {
|
|
527
727
|
switch (_d.label) {
|
|
528
728
|
case 0:
|
|
@@ -536,7 +736,15 @@ var Pool = /** @class */ (function () {
|
|
|
536
736
|
return [4 /*yield*/, this.coinBalances()];
|
|
537
737
|
case 2:
|
|
538
738
|
walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
|
|
539
|
-
return [
|
|
739
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
740
|
+
return [4 /*yield*/, this._wrappedPrices()];
|
|
741
|
+
case 3:
|
|
742
|
+
prices_3 = _d.sent();
|
|
743
|
+
poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_3[i]; });
|
|
744
|
+
walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_3[i]; });
|
|
745
|
+
balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.decimals);
|
|
746
|
+
return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_3[i], poolBalances[i])); })];
|
|
747
|
+
case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
|
|
540
748
|
}
|
|
541
749
|
});
|
|
542
750
|
}); };
|
|
@@ -555,20 +763,32 @@ var Pool = /** @class */ (function () {
|
|
|
555
763
|
});
|
|
556
764
|
}); };
|
|
557
765
|
this.addLiquidityWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
558
|
-
var totalAmount, expected,
|
|
559
|
-
return __generator(this, function (
|
|
560
|
-
switch (
|
|
766
|
+
var prices_4, totalAmountUSD, expected_2, _a, totalAmount, expected, _c;
|
|
767
|
+
return __generator(this, function (_d) {
|
|
768
|
+
switch (_d.label) {
|
|
561
769
|
case 0:
|
|
562
770
|
if (this.isFake) {
|
|
563
771
|
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
564
772
|
}
|
|
565
|
-
|
|
773
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
774
|
+
return [4 /*yield*/, this._wrappedPrices()];
|
|
775
|
+
case 1:
|
|
776
|
+
prices_4 = _d.sent();
|
|
777
|
+
totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_4[i]); }, 0);
|
|
566
778
|
_a = Number;
|
|
567
779
|
return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
|
|
568
|
-
case
|
|
569
|
-
|
|
780
|
+
case 2:
|
|
781
|
+
expected_2 = _a.apply(void 0, [_d.sent()]);
|
|
782
|
+
return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_2, false)];
|
|
783
|
+
case 3: return [2 /*return*/, _d.sent()];
|
|
784
|
+
case 4:
|
|
785
|
+
totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
|
|
786
|
+
_c = Number;
|
|
787
|
+
return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
|
|
788
|
+
case 5:
|
|
789
|
+
expected = _c.apply(void 0, [_d.sent()]);
|
|
570
790
|
return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected, false)];
|
|
571
|
-
case
|
|
791
|
+
case 6: return [2 /*return*/, _d.sent()];
|
|
572
792
|
}
|
|
573
793
|
});
|
|
574
794
|
}); };
|
|
@@ -637,7 +857,7 @@ var Pool = /** @class */ (function () {
|
|
|
637
857
|
_amounts = amounts.map(function (amount, i) {
|
|
638
858
|
return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
|
|
639
859
|
});
|
|
640
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
860
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
|
|
641
861
|
return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
|
|
642
862
|
case 3: return [2 /*return*/, _d.sent()];
|
|
643
863
|
case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
|
|
@@ -665,7 +885,7 @@ var Pool = /** @class */ (function () {
|
|
|
665
885
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
666
886
|
case 1:
|
|
667
887
|
_a.sent();
|
|
668
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
888
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
669
889
|
return [4 /*yield*/, this._addLiquidity(_amounts, false)];
|
|
670
890
|
case 2: return [2 /*return*/, _a.sent()];
|
|
671
891
|
case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
|
|
@@ -675,6 +895,128 @@ var Pool = /** @class */ (function () {
|
|
|
675
895
|
}
|
|
676
896
|
});
|
|
677
897
|
}); };
|
|
898
|
+
this.depositAndStakeWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
899
|
+
return __generator(this, function (_a) {
|
|
900
|
+
switch (_a.label) {
|
|
901
|
+
case 0:
|
|
902
|
+
if (this.isFake) {
|
|
903
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
904
|
+
}
|
|
905
|
+
return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
|
|
906
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
}); };
|
|
910
|
+
this.depositAndStakeWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
911
|
+
return __generator(this, function (_a) {
|
|
912
|
+
switch (_a.label) {
|
|
913
|
+
case 0:
|
|
914
|
+
if (this.isFake) {
|
|
915
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
916
|
+
}
|
|
917
|
+
return [4 /*yield*/, this.addLiquidityWrappedSlippage(amounts)];
|
|
918
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
}); };
|
|
922
|
+
this.depositAndStakeWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
923
|
+
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
924
|
+
return __generator(this, function (_a) {
|
|
925
|
+
switch (_a.label) {
|
|
926
|
+
case 0:
|
|
927
|
+
if (this.isFake) {
|
|
928
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
929
|
+
}
|
|
930
|
+
return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
|
|
931
|
+
case 1:
|
|
932
|
+
coinsAllowance = _a.sent();
|
|
933
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
934
|
+
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
|
|
935
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
|
|
936
|
+
case 2:
|
|
937
|
+
gaugeAllowance = _a.sent();
|
|
938
|
+
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
939
|
+
case 3: return [2 /*return*/, coinsAllowance];
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}); };
|
|
943
|
+
this.depositAndStakeWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
944
|
+
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
|
|
945
|
+
return __generator(this, function (_a) {
|
|
946
|
+
switch (_a.label) {
|
|
947
|
+
case 0:
|
|
948
|
+
if (this.isFake) {
|
|
949
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
950
|
+
}
|
|
951
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
952
|
+
case 1:
|
|
953
|
+
approveCoinsGas = _a.sent();
|
|
954
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
955
|
+
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
|
|
956
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
|
|
957
|
+
case 2:
|
|
958
|
+
gaugeAllowance = _a.sent();
|
|
959
|
+
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
960
|
+
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
961
|
+
case 3:
|
|
962
|
+
approveGaugeGas = (_a.sent()).toNumber();
|
|
963
|
+
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
964
|
+
case 4: return [2 /*return*/, approveCoinsGas];
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}); };
|
|
968
|
+
this.depositAndStakeWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
969
|
+
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
|
|
970
|
+
return __generator(this, function (_a) {
|
|
971
|
+
switch (_a.label) {
|
|
972
|
+
case 0:
|
|
973
|
+
if (this.isFake) {
|
|
974
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
975
|
+
}
|
|
976
|
+
return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
|
|
977
|
+
case 1:
|
|
978
|
+
approveCoinsTx = _a.sent();
|
|
979
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].contract;
|
|
980
|
+
if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
|
|
981
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
|
|
982
|
+
case 2:
|
|
983
|
+
gaugeAllowance = _a.sent();
|
|
984
|
+
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
985
|
+
return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
|
|
986
|
+
case 3:
|
|
987
|
+
gasLimit = (_a.sent()).mul(130).div(100);
|
|
988
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
989
|
+
case 4:
|
|
990
|
+
approveGaugeTx = (_a.sent()).hash;
|
|
991
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
992
|
+
case 5: return [2 /*return*/, approveCoinsTx];
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
}); };
|
|
996
|
+
this.depositAndStakeWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
997
|
+
return __generator(this, function (_a) {
|
|
998
|
+
switch (_a.label) {
|
|
999
|
+
case 0:
|
|
1000
|
+
if (this.isFake) {
|
|
1001
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1002
|
+
}
|
|
1003
|
+
return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
|
|
1004
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}); };
|
|
1008
|
+
this.depositAndStakeWrapped = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
|
|
1009
|
+
return __generator(this, function (_a) {
|
|
1010
|
+
switch (_a.label) {
|
|
1011
|
+
case 0:
|
|
1012
|
+
if (this.isFake) {
|
|
1013
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1014
|
+
}
|
|
1015
|
+
return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
|
|
1016
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
}); };
|
|
678
1020
|
this.removeLiquidityExpected = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
679
1021
|
var _lpTokenAmount, _expected;
|
|
680
1022
|
var _this = this;
|
|
@@ -682,7 +1024,7 @@ var Pool = /** @class */ (function () {
|
|
|
682
1024
|
switch (_a.label) {
|
|
683
1025
|
case 0:
|
|
684
1026
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
685
|
-
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
1027
|
+
if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
|
|
686
1028
|
return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
|
|
687
1029
|
case 1:
|
|
688
1030
|
_expected = _a.sent(); // Lending pools
|
|
@@ -705,7 +1047,7 @@ var Pool = /** @class */ (function () {
|
|
|
705
1047
|
return __generator(this, function (_a) {
|
|
706
1048
|
switch (_a.label) {
|
|
707
1049
|
case 0:
|
|
708
|
-
if (!
|
|
1050
|
+
if (!this.zap)
|
|
709
1051
|
return [2 /*return*/, true];
|
|
710
1052
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
711
1053
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -716,7 +1058,7 @@ var Pool = /** @class */ (function () {
|
|
|
716
1058
|
return __generator(this, function (_a) {
|
|
717
1059
|
switch (_a.label) {
|
|
718
1060
|
case 0:
|
|
719
|
-
if (!
|
|
1061
|
+
if (!this.zap)
|
|
720
1062
|
return [2 /*return*/, 0];
|
|
721
1063
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
722
1064
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -727,7 +1069,7 @@ var Pool = /** @class */ (function () {
|
|
|
727
1069
|
return __generator(this, function (_a) {
|
|
728
1070
|
switch (_a.label) {
|
|
729
1071
|
case 0:
|
|
730
|
-
if (!
|
|
1072
|
+
if (!this.zap)
|
|
731
1073
|
return [2 /*return*/, []];
|
|
732
1074
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
733
1075
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -759,7 +1101,7 @@ var Pool = /** @class */ (function () {
|
|
|
759
1101
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
|
|
760
1102
|
case 4: return [2 /*return*/, _c.sent()];
|
|
761
1103
|
case 5:
|
|
762
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
1104
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
763
1105
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
|
|
764
1106
|
case 6: return [2 /*return*/, _c.sent()];
|
|
765
1107
|
case 7:
|
|
@@ -784,7 +1126,7 @@ var Pool = /** @class */ (function () {
|
|
|
784
1126
|
return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
|
|
785
1127
|
case 2: return [2 /*return*/, _a.sent()];
|
|
786
1128
|
case 3:
|
|
787
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
1129
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
788
1130
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
|
|
789
1131
|
case 4: return [2 /*return*/, _a.sent()];
|
|
790
1132
|
case 5:
|
|
@@ -828,7 +1170,7 @@ var Pool = /** @class */ (function () {
|
|
|
828
1170
|
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
829
1171
|
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
830
1172
|
}
|
|
831
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1173
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
832
1174
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
|
|
833
1175
|
case 2: return [2 /*return*/, _a.sent()];
|
|
834
1176
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
|
|
@@ -848,7 +1190,7 @@ var Pool = /** @class */ (function () {
|
|
|
848
1190
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
849
1191
|
case 1:
|
|
850
1192
|
_a.sent();
|
|
851
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1193
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
852
1194
|
return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
|
|
853
1195
|
case 2: return [2 /*return*/, _a.sent()];
|
|
854
1196
|
case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
|
|
@@ -1153,7 +1495,7 @@ var Pool = /** @class */ (function () {
|
|
|
1153
1495
|
});
|
|
1154
1496
|
}); };
|
|
1155
1497
|
this.removeLiquidityOneCoinSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
|
|
1156
|
-
var totalAmount, _a;
|
|
1498
|
+
var totalAmount, _a, coinPrice;
|
|
1157
1499
|
return __generator(this, function (_c) {
|
|
1158
1500
|
switch (_c.label) {
|
|
1159
1501
|
case 0:
|
|
@@ -1161,8 +1503,14 @@ var Pool = /** @class */ (function () {
|
|
|
1161
1503
|
return [4 /*yield*/, this.removeLiquidityOneCoinExpected(lpTokenAmount, coin)];
|
|
1162
1504
|
case 1:
|
|
1163
1505
|
totalAmount = _a.apply(void 0, [_c.sent()]);
|
|
1164
|
-
return [
|
|
1165
|
-
|
|
1506
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
1507
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
1508
|
+
case 2:
|
|
1509
|
+
coinPrice = (_c.sent())[this._getCoinIdx(coin)];
|
|
1510
|
+
return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
|
|
1511
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
1512
|
+
case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
|
|
1513
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
1166
1514
|
}
|
|
1167
1515
|
});
|
|
1168
1516
|
}); };
|
|
@@ -1170,7 +1518,7 @@ var Pool = /** @class */ (function () {
|
|
|
1170
1518
|
return __generator(this, function (_a) {
|
|
1171
1519
|
switch (_a.label) {
|
|
1172
1520
|
case 0:
|
|
1173
|
-
if (!
|
|
1521
|
+
if (!this.zap)
|
|
1174
1522
|
return [2 /*return*/, true];
|
|
1175
1523
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
|
|
1176
1524
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1181,7 +1529,7 @@ var Pool = /** @class */ (function () {
|
|
|
1181
1529
|
return __generator(this, function (_a) {
|
|
1182
1530
|
switch (_a.label) {
|
|
1183
1531
|
case 0:
|
|
1184
|
-
if (!
|
|
1532
|
+
if (!this.zap)
|
|
1185
1533
|
return [2 /*return*/, 0];
|
|
1186
1534
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
1187
1535
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1192,7 +1540,7 @@ var Pool = /** @class */ (function () {
|
|
|
1192
1540
|
return __generator(this, function (_a) {
|
|
1193
1541
|
switch (_a.label) {
|
|
1194
1542
|
case 0:
|
|
1195
|
-
if (!
|
|
1543
|
+
if (!this.zap)
|
|
1196
1544
|
return [2 /*return*/, []];
|
|
1197
1545
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
|
|
1198
1546
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1225,7 +1573,7 @@ var Pool = /** @class */ (function () {
|
|
|
1225
1573
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
|
|
1226
1574
|
case 4: return [2 /*return*/, _c.sent()];
|
|
1227
1575
|
case 5:
|
|
1228
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
1576
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
|
|
1229
1577
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
|
|
1230
1578
|
case 6: return [2 /*return*/, _c.sent()];
|
|
1231
1579
|
case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1249,7 +1597,7 @@ var Pool = /** @class */ (function () {
|
|
|
1249
1597
|
return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
|
|
1250
1598
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1251
1599
|
case 3:
|
|
1252
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
1600
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
|
|
1253
1601
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
|
|
1254
1602
|
case 4: return [2 /*return*/, _a.sent()];
|
|
1255
1603
|
case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1286,7 +1634,7 @@ var Pool = /** @class */ (function () {
|
|
|
1286
1634
|
});
|
|
1287
1635
|
}); };
|
|
1288
1636
|
this.removeLiquidityOneCoinWrappedSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
|
|
1289
|
-
var totalAmount, _a;
|
|
1637
|
+
var totalAmount, _a, coinPrice;
|
|
1290
1638
|
return __generator(this, function (_c) {
|
|
1291
1639
|
switch (_c.label) {
|
|
1292
1640
|
case 0:
|
|
@@ -1297,8 +1645,14 @@ var Pool = /** @class */ (function () {
|
|
|
1297
1645
|
return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
1298
1646
|
case 1:
|
|
1299
1647
|
totalAmount = _a.apply(void 0, [_c.sent()]);
|
|
1300
|
-
return [
|
|
1301
|
-
|
|
1648
|
+
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
1649
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
1650
|
+
case 2:
|
|
1651
|
+
coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
|
|
1652
|
+
return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
|
|
1653
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
1654
|
+
case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
|
|
1655
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
1302
1656
|
}
|
|
1303
1657
|
});
|
|
1304
1658
|
}); };
|
|
@@ -1321,7 +1675,7 @@ var Pool = /** @class */ (function () {
|
|
|
1321
1675
|
throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
|
|
1322
1676
|
}
|
|
1323
1677
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1324
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1678
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1325
1679
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
|
|
1326
1680
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1327
1681
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
|
|
@@ -1345,7 +1699,7 @@ var Pool = /** @class */ (function () {
|
|
|
1345
1699
|
case 1:
|
|
1346
1700
|
_a.sent();
|
|
1347
1701
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1348
|
-
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1702
|
+
if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
|
|
1349
1703
|
return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
|
|
1350
1704
|
case 2: return [2 /*return*/, _a.sent()];
|
|
1351
1705
|
case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
|
|
@@ -1383,13 +1737,13 @@ var Pool = /** @class */ (function () {
|
|
|
1383
1737
|
switch (_a.label) {
|
|
1384
1738
|
case 0:
|
|
1385
1739
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1386
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.
|
|
1740
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1387
1741
|
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
1388
1742
|
}
|
|
1389
1743
|
});
|
|
1390
1744
|
}); };
|
|
1391
1745
|
this.gaugeDeposit = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1392
|
-
var _lpTokenAmount;
|
|
1746
|
+
var _lpTokenAmount, gasLimit;
|
|
1393
1747
|
return __generator(this, function (_a) {
|
|
1394
1748
|
switch (_a.label) {
|
|
1395
1749
|
case 0:
|
|
@@ -1397,8 +1751,11 @@ var Pool = /** @class */ (function () {
|
|
|
1397
1751
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
|
|
1398
1752
|
case 1:
|
|
1399
1753
|
_a.sent();
|
|
1400
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, curve_1.curve.
|
|
1401
|
-
case 2:
|
|
1754
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1755
|
+
case 2:
|
|
1756
|
+
gasLimit = (_a.sent()).mul(150).div(100);
|
|
1757
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1758
|
+
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
1402
1759
|
}
|
|
1403
1760
|
});
|
|
1404
1761
|
}); };
|
|
@@ -1408,19 +1765,22 @@ var Pool = /** @class */ (function () {
|
|
|
1408
1765
|
switch (_a.label) {
|
|
1409
1766
|
case 0:
|
|
1410
1767
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1411
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.
|
|
1768
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1412
1769
|
case 1: return [2 /*return*/, (_a.sent()).toNumber()];
|
|
1413
1770
|
}
|
|
1414
1771
|
});
|
|
1415
1772
|
}); };
|
|
1416
1773
|
this.gaugeWithdraw = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
|
|
1417
|
-
var _lpTokenAmount;
|
|
1774
|
+
var _lpTokenAmount, gasLimit;
|
|
1418
1775
|
return __generator(this, function (_a) {
|
|
1419
1776
|
switch (_a.label) {
|
|
1420
1777
|
case 0:
|
|
1421
1778
|
_lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
|
|
1422
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, curve_1.curve.
|
|
1423
|
-
case 1:
|
|
1779
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1780
|
+
case 1:
|
|
1781
|
+
gasLimit = (_a.sent()).mul(180).div(100);
|
|
1782
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1783
|
+
case 2: return [2 /*return*/, (_a.sent()).hash];
|
|
1424
1784
|
}
|
|
1425
1785
|
});
|
|
1426
1786
|
}); };
|
|
@@ -1631,7 +1991,7 @@ var Pool = /** @class */ (function () {
|
|
|
1631
1991
|
return __generator(this, function (_a) {
|
|
1632
1992
|
switch (_a.label) {
|
|
1633
1993
|
case 0:
|
|
1634
|
-
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1994
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1635
1995
|
i = this._getCoinIdx(inputCoin);
|
|
1636
1996
|
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
|
|
1637
1997
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1643,7 +2003,7 @@ var Pool = /** @class */ (function () {
|
|
|
1643
2003
|
return __generator(this, function (_a) {
|
|
1644
2004
|
switch (_a.label) {
|
|
1645
2005
|
case 0:
|
|
1646
|
-
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2006
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1647
2007
|
i = this._getCoinIdx(inputCoin);
|
|
1648
2008
|
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
1649
2009
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1655,7 +2015,7 @@ var Pool = /** @class */ (function () {
|
|
|
1655
2015
|
return __generator(this, function (_a) {
|
|
1656
2016
|
switch (_a.label) {
|
|
1657
2017
|
case 0:
|
|
1658
|
-
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2018
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1659
2019
|
i = this._getCoinIdx(inputCoin);
|
|
1660
2020
|
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
1661
2021
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1669,7 +2029,7 @@ var Pool = /** @class */ (function () {
|
|
|
1669
2029
|
return __generator(this, function (_d) {
|
|
1670
2030
|
switch (_d.label) {
|
|
1671
2031
|
case 0:
|
|
1672
|
-
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2032
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1673
2033
|
i = this._getCoinIdx(inputCoin);
|
|
1674
2034
|
j = this._getCoinIdx(outputCoin);
|
|
1675
2035
|
_c = (_a = Object).values;
|
|
@@ -1710,7 +2070,7 @@ var Pool = /** @class */ (function () {
|
|
|
1710
2070
|
return __generator(this, function (_a) {
|
|
1711
2071
|
switch (_a.label) {
|
|
1712
2072
|
case 0:
|
|
1713
|
-
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2073
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
1714
2074
|
i = this._getCoinIdx(inputCoin);
|
|
1715
2075
|
j = this._getCoinIdx(outputCoin);
|
|
1716
2076
|
_amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
|
|
@@ -2115,6 +2475,90 @@ var Pool = /** @class */ (function () {
|
|
|
2115
2475
|
});
|
|
2116
2476
|
});
|
|
2117
2477
|
};
|
|
2478
|
+
this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2479
|
+
var promises, _i, _a, addr;
|
|
2480
|
+
return __generator(this, function (_c) {
|
|
2481
|
+
switch (_c.label) {
|
|
2482
|
+
case 0:
|
|
2483
|
+
promises = [];
|
|
2484
|
+
for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
|
|
2485
|
+
addr = _a[_i];
|
|
2486
|
+
promises.push((0, utils_1._getUsdRate)(addr));
|
|
2487
|
+
}
|
|
2488
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
2489
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2490
|
+
}
|
|
2491
|
+
});
|
|
2492
|
+
}); };
|
|
2493
|
+
// NOTE! It may crash!
|
|
2494
|
+
this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2495
|
+
var promises, _i, _a, addr;
|
|
2496
|
+
return __generator(this, function (_c) {
|
|
2497
|
+
switch (_c.label) {
|
|
2498
|
+
case 0:
|
|
2499
|
+
promises = [];
|
|
2500
|
+
for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
|
|
2501
|
+
addr = _a[_i];
|
|
2502
|
+
promises.push((0, utils_1._getUsdRate)(addr));
|
|
2503
|
+
}
|
|
2504
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
2505
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
}); };
|
|
2509
|
+
this._addLiquidityCryptoSlippage = function (totalAmountUSD, expected, useUnderlying) {
|
|
2510
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
2511
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
2512
|
+
var poolBalances, _a, prices, _c, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _d, _e, _f;
|
|
2513
|
+
return __generator(this, function (_h) {
|
|
2514
|
+
switch (_h.label) {
|
|
2515
|
+
case 0:
|
|
2516
|
+
if (!useUnderlying) return [3 /*break*/, 2];
|
|
2517
|
+
return [4 /*yield*/, this.getPoolBalances()];
|
|
2518
|
+
case 1:
|
|
2519
|
+
_a = (_h.sent()).map(Number);
|
|
2520
|
+
return [3 /*break*/, 4];
|
|
2521
|
+
case 2: return [4 /*yield*/, this.getPoolWrappedBalances()];
|
|
2522
|
+
case 3:
|
|
2523
|
+
_a = (_h.sent()).map(Number);
|
|
2524
|
+
_h.label = 4;
|
|
2525
|
+
case 4:
|
|
2526
|
+
poolBalances = _a;
|
|
2527
|
+
if (!useUnderlying) return [3 /*break*/, 6];
|
|
2528
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2529
|
+
case 5:
|
|
2530
|
+
_c = _h.sent();
|
|
2531
|
+
return [3 /*break*/, 8];
|
|
2532
|
+
case 6: return [4 /*yield*/, this._wrappedPrices()];
|
|
2533
|
+
case 7:
|
|
2534
|
+
_c = _h.sent();
|
|
2535
|
+
_h.label = 8;
|
|
2536
|
+
case 8:
|
|
2537
|
+
prices = _c;
|
|
2538
|
+
poolBalancesUSD = poolBalances.map(function (b, i) { return Number(b) * prices[i]; });
|
|
2539
|
+
poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
|
|
2540
|
+
poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
|
|
2541
|
+
balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
|
|
2542
|
+
balancedAmounts = balancedAmountsUSD.map(function (a, i) { return String(a / prices[i]); });
|
|
2543
|
+
if (!useUnderlying) return [3 /*break*/, 10];
|
|
2544
|
+
_e = Number;
|
|
2545
|
+
return [4 /*yield*/, this.addLiquidityExpected(balancedAmounts)];
|
|
2546
|
+
case 9:
|
|
2547
|
+
_d = _e.apply(void 0, [_h.sent()]);
|
|
2548
|
+
return [3 /*break*/, 12];
|
|
2549
|
+
case 10:
|
|
2550
|
+
_f = Number;
|
|
2551
|
+
return [4 /*yield*/, this.addLiquidityWrappedExpected(balancedAmounts)];
|
|
2552
|
+
case 11:
|
|
2553
|
+
_d = _f.apply(void 0, [_h.sent()]);
|
|
2554
|
+
_h.label = 12;
|
|
2555
|
+
case 12:
|
|
2556
|
+
balancedExpected = _d;
|
|
2557
|
+
return [2 /*return*/, String((balancedExpected - expected) / balancedExpected)];
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
});
|
|
2561
|
+
};
|
|
2118
2562
|
this._addLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
|
|
2119
2563
|
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
2120
2564
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2155,6 +2599,41 @@ var Pool = /** @class */ (function () {
|
|
|
2155
2599
|
});
|
|
2156
2600
|
});
|
|
2157
2601
|
};
|
|
2602
|
+
this._removeLiquidityCryptoSlippage = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
|
|
2603
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
2604
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
2605
|
+
var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
|
|
2606
|
+
return __generator(this, function (_d) {
|
|
2607
|
+
switch (_d.label) {
|
|
2608
|
+
case 0:
|
|
2609
|
+
if (!useUnderlying) return [3 /*break*/, 2];
|
|
2610
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2611
|
+
case 1:
|
|
2612
|
+
_a = _d.sent();
|
|
2613
|
+
return [3 /*break*/, 4];
|
|
2614
|
+
case 2: return [4 /*yield*/, this._wrappedPrices()];
|
|
2615
|
+
case 3:
|
|
2616
|
+
_a = _d.sent();
|
|
2617
|
+
_d.label = 4;
|
|
2618
|
+
case 4:
|
|
2619
|
+
prices = _a;
|
|
2620
|
+
if (!useUnderlying) return [3 /*break*/, 6];
|
|
2621
|
+
return [4 /*yield*/, this.removeLiquidityExpected(String(lpTokenAmount))];
|
|
2622
|
+
case 5:
|
|
2623
|
+
_c = _d.sent();
|
|
2624
|
+
return [3 /*break*/, 8];
|
|
2625
|
+
case 6: return [4 /*yield*/, this.removeLiquidityWrappedExpected(String(lpTokenAmount))];
|
|
2626
|
+
case 7:
|
|
2627
|
+
_c = _d.sent();
|
|
2628
|
+
_d.label = 8;
|
|
2629
|
+
case 8:
|
|
2630
|
+
balancedAmounts = _c;
|
|
2631
|
+
balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
|
|
2632
|
+
return [2 /*return*/, String((balancedTotalAmountsUSD - totalAmountUSD) / balancedTotalAmountsUSD)];
|
|
2633
|
+
}
|
|
2634
|
+
});
|
|
2635
|
+
});
|
|
2636
|
+
};
|
|
2158
2637
|
this._removeLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
|
|
2159
2638
|
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
2160
2639
|
return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -2196,7 +2675,8 @@ var Pool = /** @class */ (function () {
|
|
|
2196
2675
|
});
|
|
2197
2676
|
};
|
|
2198
2677
|
this._balancedAmounts = function (poolBalances, walletBalances, decimals) {
|
|
2199
|
-
var
|
|
2678
|
+
var poolTotalLiquidity = poolBalances.reduce(function (a, b) { return a + b; });
|
|
2679
|
+
var poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalLiquidity; });
|
|
2200
2680
|
// Cross factors for each wallet balance used as reference to see the
|
|
2201
2681
|
// max that can be used according to the lowest relative wallet balance
|
|
2202
2682
|
var balancedAmountsForEachScenario = walletBalances.map(function (_, i) { return (walletBalances.map(function (_, j) { return (poolBalancesRatios[j] * walletBalances[i] / poolBalancesRatios[i]); })); });
|
|
@@ -2215,7 +2695,7 @@ var Pool = /** @class */ (function () {
|
|
|
2215
2695
|
switch (_a.label) {
|
|
2216
2696
|
case 0:
|
|
2217
2697
|
contract = curve_1.curve.contracts[this.swap].contract;
|
|
2218
|
-
if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
|
|
2698
|
+
if (!["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name)) return [3 /*break*/, 2];
|
|
2219
2699
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
2220
2700
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2221
2701
|
case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
@@ -2236,7 +2716,7 @@ var Pool = /** @class */ (function () {
|
|
|
2236
2716
|
return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
2237
2717
|
case 1: return [2 /*return*/, _a.sent()];
|
|
2238
2718
|
case 2:
|
|
2239
|
-
if (!(this.name
|
|
2719
|
+
if (!["eurtusd", "xautusd"].includes(this.name)) return [3 /*break*/, 4];
|
|
2240
2720
|
return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
|
|
2241
2721
|
case 3: return [2 /*return*/, _a.sent()];
|
|
2242
2722
|
case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
|
|
@@ -2896,7 +3376,7 @@ var Pool = /** @class */ (function () {
|
|
|
2896
3376
|
return __generator(this, function (_a) {
|
|
2897
3377
|
switch (_a.label) {
|
|
2898
3378
|
case 0:
|
|
2899
|
-
contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
3379
|
+
contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
|
|
2900
3380
|
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
2901
3381
|
if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
|
|
2902
3382
|
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
|
|
@@ -2938,8 +3418,12 @@ var Pool = /** @class */ (function () {
|
|
|
2938
3418
|
this.estimateGas = {
|
|
2939
3419
|
addLiquidityApprove: this.addLiquidityApproveEstimateGas,
|
|
2940
3420
|
addLiquidity: this.addLiquidityEstimateGas,
|
|
3421
|
+
depositAndStakeApprove: this.depositAndStakeApproveEstimateGas,
|
|
3422
|
+
depositAndStake: this.depositAndStakeEstimateGas,
|
|
2941
3423
|
addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
|
|
2942
3424
|
addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
|
|
3425
|
+
depositAndStakeWrappedApprove: this.depositAndStakeWrappedApproveEstimateGas,
|
|
3426
|
+
depositAndStakeWrapped: this.depositAndStakeWrappedEstimateGas,
|
|
2943
3427
|
gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
|
|
2944
3428
|
gaugeDeposit: this.gaugeDepositEstimateGas,
|
|
2945
3429
|
gaugeWithdraw: this.gaugeWithdrawEstimateGas,
|
|
@@ -3047,10 +3531,10 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
3047
3531
|
else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
|
|
3048
3532
|
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3049
3533
|
}
|
|
3050
|
-
else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0]
|
|
3534
|
+
else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
|
|
3051
3535
|
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3052
3536
|
}
|
|
3053
|
-
else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0]
|
|
3537
|
+
else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
|
|
3054
3538
|
return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
|
|
3055
3539
|
}
|
|
3056
3540
|
else {
|