@curvefi/api 1.15.0 → 1.17.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/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
@@ -127,21 +127,26 @@ var Pool = /** @class */ (function () {
127
127
  });
128
128
  };
129
129
  this.getParameters = function () { return __awaiter(_this, void 0, void 0, function () {
130
- var calls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma;
131
- return __generator(this, function (_d) {
132
- switch (_d.label) {
130
+ var multicallContract, calls, additionalCalls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
131
+ return __generator(this, function (_f) {
132
+ switch (_f.label) {
133
133
  case 0:
134
+ multicallContract = curve_1.curve.contracts[this.swap].multicallContract;
134
135
  calls = [
135
- curve_1.curve.contracts[this.swap].multicallContract.get_virtual_price(),
136
- curve_1.curve.contracts[this.swap].multicallContract.fee(),
137
- curve_1.curve.contracts[this.swap].multicallContract.admin_fee(),
138
- curve_1.curve.contracts[this.swap].multicallContract.A(),
136
+ multicallContract.get_virtual_price(),
137
+ multicallContract.fee(),
138
+ multicallContract.admin_fee(),
139
+ multicallContract.A(),
139
140
  ];
140
141
  if (this.isCrypto)
141
- calls.push(curve_1.curve.contracts[this.swap].multicallContract.gamma());
142
+ calls.push(multicallContract.gamma());
143
+ additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
144
+ if ('initial_A' in multicallContract) {
145
+ additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
146
+ }
142
147
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
143
148
  case 1:
144
- _a = _d.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
149
+ _a = _f.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
145
150
  _c = [
146
151
  ethers_1.ethers.utils.formatUnits(_virtualPrice),
147
152
  ethers_1.ethers.utils.formatUnits(_fee, 8),
@@ -149,7 +154,17 @@ var Pool = /** @class */ (function () {
149
154
  ethers_1.ethers.utils.formatUnits(_A, 0),
150
155
  _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
151
156
  ], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
152
- return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, gamma: gamma }];
157
+ A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.name) ? 1 : 100;
158
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
159
+ case 2:
160
+ _d = _f.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
161
+ _e = [
162
+ _future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
163
+ _initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
164
+ _future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
165
+ _initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
166
+ ], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
167
+ return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
153
168
  }
154
169
  });
155
170
  }); };
@@ -177,7 +192,7 @@ var Pool = /** @class */ (function () {
177
192
  _poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
178
193
  return [3 /*break*/, 6];
179
194
  case 3:
180
- 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];
181
196
  return [4 /*yield*/, this._getRates()];
182
197
  case 4:
183
198
  _rates_1 = _a.sent();
@@ -209,11 +224,11 @@ var Pool = /** @class */ (function () {
209
224
  var balances, promises, _i, _a, addr, prices, totalLiquidity;
210
225
  return __generator(this, function (_c) {
211
226
  switch (_c.label) {
212
- case 0: return [4 /*yield*/, this.getPoolWrappedBalances()];
227
+ case 0: return [4 /*yield*/, this.getPoolBalances()];
213
228
  case 1:
214
229
  balances = _c.sent();
215
230
  promises = [];
216
- for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
231
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
217
232
  addr = _a[_i];
218
233
  promises.push((0, utils_1._getUsdRate)(addr));
219
234
  }
@@ -249,7 +264,7 @@ var Pool = /** @class */ (function () {
249
264
  });
250
265
  }); };
251
266
  this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
252
- var name, statsUrl, apy;
267
+ var name, statsUrl, apy, formattedApy;
253
268
  return __generator(this, function (_a) {
254
269
  switch (_a.label) {
255
270
  case 0:
@@ -258,7 +273,13 @@ var Pool = /** @class */ (function () {
258
273
  return [4 /*yield*/, axios_1.default.get(statsUrl)];
259
274
  case 1:
260
275
  apy = (_a.sent()).data.apy;
261
- return [2 /*return*/, [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); })];
276
+ formattedApy = [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); });
277
+ return [2 /*return*/, {
278
+ day: formattedApy[0],
279
+ week: formattedApy[1],
280
+ month: formattedApy[2],
281
+ total: formattedApy[3],
282
+ }];
262
283
  }
263
284
  });
264
285
  }); };
@@ -361,17 +382,29 @@ var Pool = /** @class */ (function () {
361
382
  });
362
383
  }); };
363
384
  this.addLiquiditySlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
364
- var totalAmount, expected, _a;
365
- return __generator(this, function (_c) {
366
- switch (_c.label) {
385
+ var prices_1, totalAmountUSD, expected_1, _a, totalAmount, expected, _c;
386
+ return __generator(this, function (_d) {
387
+ switch (_d.label) {
367
388
  case 0:
368
- totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
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);
369
394
  _a = Number;
370
395
  return [4 /*yield*/, this.addLiquidityExpected(amounts)];
371
- case 1:
372
- expected = _a.apply(void 0, [_c.sent()]);
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()]);
373
406
  return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected)];
374
- case 2: return [2 /*return*/, _c.sent()];
407
+ case 6: return [2 /*return*/, _d.sent()];
375
408
  }
376
409
  });
377
410
  }); };
@@ -438,7 +471,7 @@ var Pool = /** @class */ (function () {
438
471
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
439
472
  case 3: return [2 /*return*/, _d.sent()];
440
473
  case 4:
441
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
474
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
442
475
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
443
476
  case 5: return [2 /*return*/, _d.sent()];
444
477
  case 6:
@@ -453,7 +486,7 @@ var Pool = /** @class */ (function () {
453
486
  });
454
487
  }); };
455
488
  this.balancedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
456
- var poolBalances, walletBalances, _a, _c;
489
+ var poolBalances, walletBalances, _a, _c, prices_2, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
457
490
  return __generator(this, function (_d) {
458
491
  switch (_d.label) {
459
492
  case 0: return [4 /*yield*/, this.getPoolBalances()];
@@ -463,7 +496,15 @@ var Pool = /** @class */ (function () {
463
496
  return [4 /*yield*/, this.underlyingCoinBalances()];
464
497
  case 2:
465
498
  walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
466
- return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
499
+ if (!this.isCrypto) return [3 /*break*/, 4];
500
+ return [4 /*yield*/, this._underlyingPrices()];
501
+ case 3:
502
+ prices_2 = _d.sent();
503
+ poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_2[i]; });
504
+ walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_2[i]; });
505
+ balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.underlyingDecimals);
506
+ return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_2[i], poolBalances[i])); })];
507
+ case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
467
508
  }
468
509
  });
469
510
  }); };
@@ -486,7 +527,7 @@ var Pool = /** @class */ (function () {
486
527
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
487
528
  case 2: return [2 /*return*/, _a.sent()];
488
529
  case 3:
489
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
530
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
490
531
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
491
532
  case 4: return [2 /*return*/, _a.sent()];
492
533
  case 5:
@@ -500,8 +541,197 @@ var Pool = /** @class */ (function () {
500
541
  }
501
542
  });
502
543
  }); };
544
+ this.depositAndStakeExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
545
+ return __generator(this, function (_a) {
546
+ switch (_a.label) {
547
+ case 0: return [4 /*yield*/, this.addLiquidityExpected(amounts)];
548
+ case 1: return [2 /*return*/, _a.sent()];
549
+ }
550
+ });
551
+ }); };
552
+ this.depositAndStakeSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0: return [4 /*yield*/, this.addLiquiditySlippage(amounts)];
556
+ case 1: return [2 /*return*/, _a.sent()];
557
+ }
558
+ });
559
+ }); };
560
+ this.depositAndStakeIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
561
+ var coinsAllowance, gaugeContract, gaugeAllowance;
562
+ return __generator(this, function (_a) {
563
+ switch (_a.label) {
564
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
565
+ case 1:
566
+ coinsAllowance = _a.sent();
567
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
568
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
569
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
570
+ case 2:
571
+ gaugeAllowance = _a.sent();
572
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
573
+ case 3: return [2 /*return*/, coinsAllowance];
574
+ }
575
+ });
576
+ }); };
577
+ this.depositAndStakeApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
578
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
579
+ return __generator(this, function (_a) {
580
+ switch (_a.label) {
581
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
582
+ case 1:
583
+ approveCoinsGas = _a.sent();
584
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
585
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
586
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
587
+ case 2:
588
+ gaugeAllowance = _a.sent();
589
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
590
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
591
+ case 3:
592
+ approveGaugeGas = (_a.sent()).toNumber();
593
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
594
+ case 4: return [2 /*return*/, approveCoinsGas];
595
+ }
596
+ });
597
+ }); };
598
+ this.depositAndStakeApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
599
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
600
+ return __generator(this, function (_a) {
601
+ switch (_a.label) {
602
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
603
+ case 1:
604
+ approveCoinsTx = _a.sent();
605
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
606
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
607
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
608
+ case 2:
609
+ gaugeAllowance = _a.sent();
610
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
611
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
612
+ case 3:
613
+ gasLimit = (_a.sent()).mul(130).div(100);
614
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
615
+ case 4:
616
+ approveGaugeTx = (_a.sent()).hash;
617
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
618
+ case 5: return [2 /*return*/, approveCoinsTx];
619
+ }
620
+ });
621
+ }); };
622
+ this.depositAndStakeEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
623
+ return __generator(this, function (_a) {
624
+ switch (_a.label) {
625
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
626
+ case 1: return [2 /*return*/, _a.sent()];
627
+ }
628
+ });
629
+ }); };
630
+ this.depositAndStake = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
631
+ return __generator(this, function (_a) {
632
+ switch (_a.label) {
633
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
634
+ case 1: return [2 /*return*/, _a.sent()];
635
+ }
636
+ });
637
+ }); };
638
+ this._depositAndStake = function (amounts, isUnderlying, estimateGas) { return __awaiter(_this, void 0, void 0, function () {
639
+ 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;
640
+ return __generator(this, function (_p) {
641
+ switch (_p.label) {
642
+ case 0:
643
+ coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.coinAddresses, true);
644
+ coins = isUnderlying ? this.underlyingCoins : this.coinAddresses;
645
+ decimals = isUnderlying ? this.underlyingDecimals : this.decimals;
646
+ depositAddress = isUnderlying ? this.zap || this.swap : this.swap;
647
+ if (amounts.length !== coinAddresses.length) {
648
+ throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
649
+ }
650
+ if (!isUnderlying) return [3 /*break*/, 2];
651
+ _d = (_c = Object).values;
652
+ return [4 /*yield*/, this.underlyingCoinBalances()];
653
+ case 1:
654
+ _a = _d.apply(_c, [_p.sent()]);
655
+ return [3 /*break*/, 4];
656
+ case 2:
657
+ _f = (_e = Object).values;
658
+ return [4 /*yield*/, this.coinBalances()];
659
+ case 3:
660
+ _a = _f.apply(_e, [_p.sent()]);
661
+ _p.label = 4;
662
+ case 4:
663
+ balances = _a;
664
+ for (i = 0; i < balances.length; i++) {
665
+ if (Number(balances[i]) < Number(amounts[i])) {
666
+ throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
667
+ }
668
+ }
669
+ if (!isUnderlying) return [3 /*break*/, 6];
670
+ return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
671
+ case 5:
672
+ _h = _p.sent();
673
+ return [3 /*break*/, 8];
674
+ case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
675
+ case 7:
676
+ _h = _p.sent();
677
+ _p.label = 8;
678
+ case 8:
679
+ allowance = _h;
680
+ if (estimateGas && !allowance) {
681
+ throw Error("Token allowance is needed to estimate gas");
682
+ }
683
+ if (!!estimateGas) return [3 /*break*/, 12];
684
+ if (!isUnderlying) return [3 /*break*/, 10];
685
+ return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
686
+ case 9:
687
+ _p.sent();
688
+ return [3 /*break*/, 12];
689
+ case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
690
+ case 11:
691
+ _p.sent();
692
+ _p.label = 12;
693
+ case 12:
694
+ _amounts = amounts.map(function (amount, i) {
695
+ return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
696
+ });
697
+ contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
698
+ useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'));
699
+ if (!isUnderlying) return [3 /*break*/, 14];
700
+ _l = (_k = ethers_1.ethers.utils).parseUnits;
701
+ return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
702
+ case 13:
703
+ _j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
704
+ return [3 /*break*/, 16];
705
+ case 14:
706
+ _o = (_m = ethers_1.ethers.utils).parseUnits;
707
+ return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
708
+ case 15:
709
+ _j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
710
+ _p.label = 16;
711
+ case 16:
712
+ _minMintAmount = _j;
713
+ ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
714
+ value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
715
+ for (i = 0; i < 5; i++) {
716
+ coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
717
+ _amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
718
+ }
719
+ 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 }))];
720
+ case 17:
721
+ _gas = (_p.sent());
722
+ if (estimateGas)
723
+ return [2 /*return*/, _gas.toNumber()];
724
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
725
+ case 18:
726
+ _p.sent();
727
+ gasLimit = _gas.mul(200).div(100);
728
+ 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 }))];
729
+ case 19: return [2 /*return*/, (_p.sent()).hash];
730
+ }
731
+ });
732
+ }); };
503
733
  this.balancedWrappedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
504
- var poolBalances, walletBalances, _a, _c;
734
+ var poolBalances, walletBalances, _a, _c, prices_3, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
505
735
  return __generator(this, function (_d) {
506
736
  switch (_d.label) {
507
737
  case 0:
@@ -515,7 +745,15 @@ var Pool = /** @class */ (function () {
515
745
  return [4 /*yield*/, this.coinBalances()];
516
746
  case 2:
517
747
  walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
518
- return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
748
+ if (!this.isCrypto) return [3 /*break*/, 4];
749
+ return [4 /*yield*/, this._wrappedPrices()];
750
+ case 3:
751
+ prices_3 = _d.sent();
752
+ poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_3[i]; });
753
+ walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_3[i]; });
754
+ balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.decimals);
755
+ return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_3[i], poolBalances[i])); })];
756
+ case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
519
757
  }
520
758
  });
521
759
  }); };
@@ -534,20 +772,32 @@ var Pool = /** @class */ (function () {
534
772
  });
535
773
  }); };
536
774
  this.addLiquidityWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
537
- var totalAmount, expected, _a;
538
- return __generator(this, function (_c) {
539
- switch (_c.label) {
775
+ var prices_4, totalAmountUSD, expected_2, _a, totalAmount, expected, _c;
776
+ return __generator(this, function (_d) {
777
+ switch (_d.label) {
540
778
  case 0:
541
779
  if (this.isFake) {
542
780
  throw Error("".concat(this.name, " pool doesn't have this method"));
543
781
  }
544
- totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
782
+ if (!this.isCrypto) return [3 /*break*/, 4];
783
+ return [4 /*yield*/, this._wrappedPrices()];
784
+ case 1:
785
+ prices_4 = _d.sent();
786
+ totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_4[i]); }, 0);
545
787
  _a = Number;
546
788
  return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
547
- case 1:
548
- expected = _a.apply(void 0, [_c.sent()]);
789
+ case 2:
790
+ expected_2 = _a.apply(void 0, [_d.sent()]);
791
+ return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_2, false)];
792
+ case 3: return [2 /*return*/, _d.sent()];
793
+ case 4:
794
+ totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
795
+ _c = Number;
796
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
797
+ case 5:
798
+ expected = _c.apply(void 0, [_d.sent()]);
549
799
  return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected, false)];
550
- case 2: return [2 /*return*/, _c.sent()];
800
+ case 6: return [2 /*return*/, _d.sent()];
551
801
  }
552
802
  });
553
803
  }); };
@@ -616,7 +866,7 @@ var Pool = /** @class */ (function () {
616
866
  _amounts = amounts.map(function (amount, i) {
617
867
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
618
868
  });
619
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
869
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
620
870
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
621
871
  case 3: return [2 /*return*/, _d.sent()];
622
872
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -644,7 +894,7 @@ var Pool = /** @class */ (function () {
644
894
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
645
895
  case 1:
646
896
  _a.sent();
647
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
897
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
648
898
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
649
899
  case 2: return [2 /*return*/, _a.sent()];
650
900
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -654,6 +904,128 @@ var Pool = /** @class */ (function () {
654
904
  }
655
905
  });
656
906
  }); };
907
+ this.depositAndStakeWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
908
+ return __generator(this, function (_a) {
909
+ switch (_a.label) {
910
+ case 0:
911
+ if (this.isFake) {
912
+ throw Error("".concat(this.name, " pool doesn't have this method"));
913
+ }
914
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
915
+ case 1: return [2 /*return*/, _a.sent()];
916
+ }
917
+ });
918
+ }); };
919
+ this.depositAndStakeWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
920
+ return __generator(this, function (_a) {
921
+ switch (_a.label) {
922
+ case 0:
923
+ if (this.isFake) {
924
+ throw Error("".concat(this.name, " pool doesn't have this method"));
925
+ }
926
+ return [4 /*yield*/, this.addLiquidityWrappedSlippage(amounts)];
927
+ case 1: return [2 /*return*/, _a.sent()];
928
+ }
929
+ });
930
+ }); };
931
+ this.depositAndStakeWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
932
+ var coinsAllowance, gaugeContract, gaugeAllowance;
933
+ return __generator(this, function (_a) {
934
+ switch (_a.label) {
935
+ case 0:
936
+ if (this.isFake) {
937
+ throw Error("".concat(this.name, " pool doesn't have this method"));
938
+ }
939
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
940
+ case 1:
941
+ coinsAllowance = _a.sent();
942
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
943
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
944
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
945
+ case 2:
946
+ gaugeAllowance = _a.sent();
947
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
948
+ case 3: return [2 /*return*/, coinsAllowance];
949
+ }
950
+ });
951
+ }); };
952
+ this.depositAndStakeWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
953
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
954
+ return __generator(this, function (_a) {
955
+ switch (_a.label) {
956
+ case 0:
957
+ if (this.isFake) {
958
+ throw Error("".concat(this.name, " pool doesn't have this method"));
959
+ }
960
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
961
+ case 1:
962
+ approveCoinsGas = _a.sent();
963
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
964
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
965
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
966
+ case 2:
967
+ gaugeAllowance = _a.sent();
968
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
969
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
970
+ case 3:
971
+ approveGaugeGas = (_a.sent()).toNumber();
972
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
973
+ case 4: return [2 /*return*/, approveCoinsGas];
974
+ }
975
+ });
976
+ }); };
977
+ this.depositAndStakeWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
978
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
979
+ return __generator(this, function (_a) {
980
+ switch (_a.label) {
981
+ case 0:
982
+ if (this.isFake) {
983
+ throw Error("".concat(this.name, " pool doesn't have this method"));
984
+ }
985
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
986
+ case 1:
987
+ approveCoinsTx = _a.sent();
988
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
989
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
990
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
991
+ case 2:
992
+ gaugeAllowance = _a.sent();
993
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
994
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
995
+ case 3:
996
+ gasLimit = (_a.sent()).mul(130).div(100);
997
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
998
+ case 4:
999
+ approveGaugeTx = (_a.sent()).hash;
1000
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
1001
+ case 5: return [2 /*return*/, approveCoinsTx];
1002
+ }
1003
+ });
1004
+ }); };
1005
+ this.depositAndStakeWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1006
+ return __generator(this, function (_a) {
1007
+ switch (_a.label) {
1008
+ case 0:
1009
+ if (this.isFake) {
1010
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1011
+ }
1012
+ return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
1013
+ case 1: return [2 /*return*/, _a.sent()];
1014
+ }
1015
+ });
1016
+ }); };
1017
+ this.depositAndStakeWrapped = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1018
+ return __generator(this, function (_a) {
1019
+ switch (_a.label) {
1020
+ case 0:
1021
+ if (this.isFake) {
1022
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1023
+ }
1024
+ return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
1025
+ case 1: return [2 /*return*/, _a.sent()];
1026
+ }
1027
+ });
1028
+ }); };
657
1029
  this.removeLiquidityExpected = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
658
1030
  var _lpTokenAmount, _expected;
659
1031
  var _this = this;
@@ -661,7 +1033,7 @@ var Pool = /** @class */ (function () {
661
1033
  switch (_a.label) {
662
1034
  case 0:
663
1035
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
664
- 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];
1036
+ 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];
665
1037
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
666
1038
  case 1:
667
1039
  _expected = _a.sent(); // Lending pools
@@ -738,7 +1110,7 @@ var Pool = /** @class */ (function () {
738
1110
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
739
1111
  case 4: return [2 /*return*/, _c.sent()];
740
1112
  case 5:
741
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1113
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
742
1114
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
743
1115
  case 6: return [2 /*return*/, _c.sent()];
744
1116
  case 7:
@@ -763,7 +1135,7 @@ var Pool = /** @class */ (function () {
763
1135
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
764
1136
  case 2: return [2 /*return*/, _a.sent()];
765
1137
  case 3:
766
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1138
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
767
1139
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
768
1140
  case 4: return [2 /*return*/, _a.sent()];
769
1141
  case 5:
@@ -807,7 +1179,7 @@ var Pool = /** @class */ (function () {
807
1179
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
808
1180
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
809
1181
  }
810
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1182
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
811
1183
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
812
1184
  case 2: return [2 /*return*/, _a.sent()];
813
1185
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -827,7 +1199,7 @@ var Pool = /** @class */ (function () {
827
1199
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
828
1200
  case 1:
829
1201
  _a.sent();
830
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1202
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
831
1203
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
832
1204
  case 2: return [2 /*return*/, _a.sent()];
833
1205
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -1132,7 +1504,7 @@ var Pool = /** @class */ (function () {
1132
1504
  });
1133
1505
  }); };
1134
1506
  this.removeLiquidityOneCoinSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
1135
- var totalAmount, _a;
1507
+ var totalAmount, _a, coinPrice;
1136
1508
  return __generator(this, function (_c) {
1137
1509
  switch (_c.label) {
1138
1510
  case 0:
@@ -1140,8 +1512,14 @@ var Pool = /** @class */ (function () {
1140
1512
  return [4 /*yield*/, this.removeLiquidityOneCoinExpected(lpTokenAmount, coin)];
1141
1513
  case 1:
1142
1514
  totalAmount = _a.apply(void 0, [_c.sent()]);
1143
- return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
1144
- case 2: return [2 /*return*/, _c.sent()];
1515
+ if (!this.isCrypto) return [3 /*break*/, 4];
1516
+ return [4 /*yield*/, this._underlyingPrices()];
1517
+ case 2:
1518
+ coinPrice = (_c.sent())[this._getCoinIdx(coin)];
1519
+ return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
1520
+ case 3: return [2 /*return*/, _c.sent()];
1521
+ case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
1522
+ case 5: return [2 /*return*/, _c.sent()];
1145
1523
  }
1146
1524
  });
1147
1525
  }); };
@@ -1204,7 +1582,7 @@ var Pool = /** @class */ (function () {
1204
1582
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1205
1583
  case 4: return [2 /*return*/, _c.sent()];
1206
1584
  case 5:
1207
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1585
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1208
1586
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1209
1587
  case 6: return [2 /*return*/, _c.sent()];
1210
1588
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1228,7 +1606,7 @@ var Pool = /** @class */ (function () {
1228
1606
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1229
1607
  case 2: return [2 /*return*/, _a.sent()];
1230
1608
  case 3:
1231
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1609
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1232
1610
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1233
1611
  case 4: return [2 /*return*/, _a.sent()];
1234
1612
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1265,7 +1643,7 @@ var Pool = /** @class */ (function () {
1265
1643
  });
1266
1644
  }); };
1267
1645
  this.removeLiquidityOneCoinWrappedSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
1268
- var totalAmount, _a;
1646
+ var totalAmount, _a, coinPrice;
1269
1647
  return __generator(this, function (_c) {
1270
1648
  switch (_c.label) {
1271
1649
  case 0:
@@ -1276,8 +1654,14 @@ var Pool = /** @class */ (function () {
1276
1654
  return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
1277
1655
  case 1:
1278
1656
  totalAmount = _a.apply(void 0, [_c.sent()]);
1279
- return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
1280
- case 2: return [2 /*return*/, _c.sent()];
1657
+ if (!this.isCrypto) return [3 /*break*/, 4];
1658
+ return [4 /*yield*/, this._underlyingPrices()];
1659
+ case 2:
1660
+ coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
1661
+ return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
1662
+ case 3: return [2 /*return*/, _c.sent()];
1663
+ case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
1664
+ case 5: return [2 /*return*/, _c.sent()];
1281
1665
  }
1282
1666
  });
1283
1667
  }); };
@@ -1300,7 +1684,7 @@ var Pool = /** @class */ (function () {
1300
1684
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1301
1685
  }
1302
1686
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1303
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1687
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1304
1688
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1305
1689
  case 2: return [2 /*return*/, _a.sent()];
1306
1690
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1324,7 +1708,7 @@ var Pool = /** @class */ (function () {
1324
1708
  case 1:
1325
1709
  _a.sent();
1326
1710
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1327
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1711
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1328
1712
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1329
1713
  case 2: return [2 /*return*/, _a.sent()];
1330
1714
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1362,13 +1746,13 @@ var Pool = /** @class */ (function () {
1362
1746
  switch (_a.label) {
1363
1747
  case 0:
1364
1748
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1365
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.options)];
1749
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1366
1750
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1367
1751
  }
1368
1752
  });
1369
1753
  }); };
1370
1754
  this.gaugeDeposit = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1371
- var _lpTokenAmount;
1755
+ var _lpTokenAmount, gasLimit;
1372
1756
  return __generator(this, function (_a) {
1373
1757
  switch (_a.label) {
1374
1758
  case 0:
@@ -1376,8 +1760,11 @@ var Pool = /** @class */ (function () {
1376
1760
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
1377
1761
  case 1:
1378
1762
  _a.sent();
1379
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, curve_1.curve.options)];
1380
- case 2: return [2 /*return*/, (_a.sent()).hash];
1763
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1764
+ case 2:
1765
+ gasLimit = (_a.sent()).mul(150).div(100);
1766
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1767
+ case 3: return [2 /*return*/, (_a.sent()).hash];
1381
1768
  }
1382
1769
  });
1383
1770
  }); };
@@ -1387,19 +1774,22 @@ var Pool = /** @class */ (function () {
1387
1774
  switch (_a.label) {
1388
1775
  case 0:
1389
1776
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1390
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.options)];
1777
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1391
1778
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1392
1779
  }
1393
1780
  });
1394
1781
  }); };
1395
1782
  this.gaugeWithdraw = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1396
- var _lpTokenAmount;
1783
+ var _lpTokenAmount, gasLimit;
1397
1784
  return __generator(this, function (_a) {
1398
1785
  switch (_a.label) {
1399
1786
  case 0:
1400
1787
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1401
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, curve_1.curve.options)];
1402
- case 1: return [2 /*return*/, (_a.sent()).hash];
1788
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1789
+ case 1:
1790
+ gasLimit = (_a.sent()).mul(180).div(100);
1791
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1792
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1403
1793
  }
1404
1794
  });
1405
1795
  }); };
@@ -1610,7 +2000,7 @@ var Pool = /** @class */ (function () {
1610
2000
  return __generator(this, function (_a) {
1611
2001
  switch (_a.label) {
1612
2002
  case 0:
1613
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2003
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1614
2004
  i = this._getCoinIdx(inputCoin);
1615
2005
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1616
2006
  case 1: return [2 /*return*/, _a.sent()];
@@ -1622,7 +2012,7 @@ var Pool = /** @class */ (function () {
1622
2012
  return __generator(this, function (_a) {
1623
2013
  switch (_a.label) {
1624
2014
  case 0:
1625
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2015
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1626
2016
  i = this._getCoinIdx(inputCoin);
1627
2017
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1628
2018
  case 1: return [2 /*return*/, _a.sent()];
@@ -1634,7 +2024,7 @@ var Pool = /** @class */ (function () {
1634
2024
  return __generator(this, function (_a) {
1635
2025
  switch (_a.label) {
1636
2026
  case 0:
1637
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2027
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1638
2028
  i = this._getCoinIdx(inputCoin);
1639
2029
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1640
2030
  case 1: return [2 /*return*/, _a.sent()];
@@ -1648,7 +2038,7 @@ var Pool = /** @class */ (function () {
1648
2038
  return __generator(this, function (_d) {
1649
2039
  switch (_d.label) {
1650
2040
  case 0:
1651
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2041
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1652
2042
  i = this._getCoinIdx(inputCoin);
1653
2043
  j = this._getCoinIdx(outputCoin);
1654
2044
  _c = (_a = Object).values;
@@ -1689,7 +2079,7 @@ var Pool = /** @class */ (function () {
1689
2079
  return __generator(this, function (_a) {
1690
2080
  switch (_a.label) {
1691
2081
  case 0:
1692
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2082
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1693
2083
  i = this._getCoinIdx(inputCoin);
1694
2084
  j = this._getCoinIdx(outputCoin);
1695
2085
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
@@ -2094,6 +2484,90 @@ var Pool = /** @class */ (function () {
2094
2484
  });
2095
2485
  });
2096
2486
  };
2487
+ this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
2488
+ var promises, _i, _a, addr;
2489
+ return __generator(this, function (_c) {
2490
+ switch (_c.label) {
2491
+ case 0:
2492
+ promises = [];
2493
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
2494
+ addr = _a[_i];
2495
+ promises.push((0, utils_1._getUsdRate)(addr));
2496
+ }
2497
+ return [4 /*yield*/, Promise.all(promises)];
2498
+ case 1: return [2 /*return*/, _c.sent()];
2499
+ }
2500
+ });
2501
+ }); };
2502
+ // NOTE! It may crash!
2503
+ this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
2504
+ var promises, _i, _a, addr;
2505
+ return __generator(this, function (_c) {
2506
+ switch (_c.label) {
2507
+ case 0:
2508
+ promises = [];
2509
+ for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
2510
+ addr = _a[_i];
2511
+ promises.push((0, utils_1._getUsdRate)(addr));
2512
+ }
2513
+ return [4 /*yield*/, Promise.all(promises)];
2514
+ case 1: return [2 /*return*/, _c.sent()];
2515
+ }
2516
+ });
2517
+ }); };
2518
+ this._addLiquidityCryptoSlippage = function (totalAmountUSD, expected, useUnderlying) {
2519
+ if (useUnderlying === void 0) { useUnderlying = true; }
2520
+ return __awaiter(_this, void 0, void 0, function () {
2521
+ var poolBalances, _a, prices, _c, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _d, _e, _f;
2522
+ return __generator(this, function (_h) {
2523
+ switch (_h.label) {
2524
+ case 0:
2525
+ if (!useUnderlying) return [3 /*break*/, 2];
2526
+ return [4 /*yield*/, this.getPoolBalances()];
2527
+ case 1:
2528
+ _a = (_h.sent()).map(Number);
2529
+ return [3 /*break*/, 4];
2530
+ case 2: return [4 /*yield*/, this.getPoolWrappedBalances()];
2531
+ case 3:
2532
+ _a = (_h.sent()).map(Number);
2533
+ _h.label = 4;
2534
+ case 4:
2535
+ poolBalances = _a;
2536
+ if (!useUnderlying) return [3 /*break*/, 6];
2537
+ return [4 /*yield*/, this._underlyingPrices()];
2538
+ case 5:
2539
+ _c = _h.sent();
2540
+ return [3 /*break*/, 8];
2541
+ case 6: return [4 /*yield*/, this._wrappedPrices()];
2542
+ case 7:
2543
+ _c = _h.sent();
2544
+ _h.label = 8;
2545
+ case 8:
2546
+ prices = _c;
2547
+ poolBalancesUSD = poolBalances.map(function (b, i) { return Number(b) * prices[i]; });
2548
+ poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
2549
+ poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
2550
+ balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
2551
+ balancedAmounts = balancedAmountsUSD.map(function (a, i) { return String(a / prices[i]); });
2552
+ if (!useUnderlying) return [3 /*break*/, 10];
2553
+ _e = Number;
2554
+ return [4 /*yield*/, this.addLiquidityExpected(balancedAmounts)];
2555
+ case 9:
2556
+ _d = _e.apply(void 0, [_h.sent()]);
2557
+ return [3 /*break*/, 12];
2558
+ case 10:
2559
+ _f = Number;
2560
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(balancedAmounts)];
2561
+ case 11:
2562
+ _d = _f.apply(void 0, [_h.sent()]);
2563
+ _h.label = 12;
2564
+ case 12:
2565
+ balancedExpected = _d;
2566
+ return [2 /*return*/, String((balancedExpected - expected) / balancedExpected)];
2567
+ }
2568
+ });
2569
+ });
2570
+ };
2097
2571
  this._addLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
2098
2572
  if (useUnderlying === void 0) { useUnderlying = true; }
2099
2573
  return __awaiter(_this, void 0, void 0, function () {
@@ -2134,6 +2608,41 @@ var Pool = /** @class */ (function () {
2134
2608
  });
2135
2609
  });
2136
2610
  };
2611
+ this._removeLiquidityCryptoSlippage = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
2612
+ if (useUnderlying === void 0) { useUnderlying = true; }
2613
+ return __awaiter(_this, void 0, void 0, function () {
2614
+ var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
2615
+ return __generator(this, function (_d) {
2616
+ switch (_d.label) {
2617
+ case 0:
2618
+ if (!useUnderlying) return [3 /*break*/, 2];
2619
+ return [4 /*yield*/, this._underlyingPrices()];
2620
+ case 1:
2621
+ _a = _d.sent();
2622
+ return [3 /*break*/, 4];
2623
+ case 2: return [4 /*yield*/, this._wrappedPrices()];
2624
+ case 3:
2625
+ _a = _d.sent();
2626
+ _d.label = 4;
2627
+ case 4:
2628
+ prices = _a;
2629
+ if (!useUnderlying) return [3 /*break*/, 6];
2630
+ return [4 /*yield*/, this.removeLiquidityExpected(String(lpTokenAmount))];
2631
+ case 5:
2632
+ _c = _d.sent();
2633
+ return [3 /*break*/, 8];
2634
+ case 6: return [4 /*yield*/, this.removeLiquidityWrappedExpected(String(lpTokenAmount))];
2635
+ case 7:
2636
+ _c = _d.sent();
2637
+ _d.label = 8;
2638
+ case 8:
2639
+ balancedAmounts = _c;
2640
+ balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
2641
+ return [2 /*return*/, String((balancedTotalAmountsUSD - totalAmountUSD) / balancedTotalAmountsUSD)];
2642
+ }
2643
+ });
2644
+ });
2645
+ };
2137
2646
  this._removeLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
2138
2647
  if (useUnderlying === void 0) { useUnderlying = true; }
2139
2648
  return __awaiter(_this, void 0, void 0, function () {
@@ -2175,7 +2684,8 @@ var Pool = /** @class */ (function () {
2175
2684
  });
2176
2685
  };
2177
2686
  this._balancedAmounts = function (poolBalances, walletBalances, decimals) {
2178
- var poolBalancesRatios = poolBalances.map(function (b) { return b / poolBalances.reduce(function (a, b) { return a + b; }); });
2687
+ var poolTotalLiquidity = poolBalances.reduce(function (a, b) { return a + b; });
2688
+ var poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalLiquidity; });
2179
2689
  // Cross factors for each wallet balance used as reference to see the
2180
2690
  // max that can be used according to the lowest relative wallet balance
2181
2691
  var balancedAmountsForEachScenario = walletBalances.map(function (_, i) { return (walletBalances.map(function (_, j) { return (poolBalancesRatios[j] * walletBalances[i] / poolBalancesRatios[i]); })); });
@@ -2194,7 +2704,7 @@ var Pool = /** @class */ (function () {
2194
2704
  switch (_a.label) {
2195
2705
  case 0:
2196
2706
  contract = curve_1.curve.contracts[this.swap].contract;
2197
- if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
2707
+ if (!["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name)) return [3 /*break*/, 2];
2198
2708
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
2199
2709
  case 1: return [2 /*return*/, _a.sent()];
2200
2710
  case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -2215,7 +2725,7 @@ var Pool = /** @class */ (function () {
2215
2725
  return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
2216
2726
  case 1: return [2 /*return*/, _a.sent()];
2217
2727
  case 2:
2218
- if (!(this.name === "eurtusd")) return [3 /*break*/, 4];
2728
+ if (!["eurtusd", "xautusd"].includes(this.name)) return [3 /*break*/, 4];
2219
2729
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
2220
2730
  case 3: return [2 /*return*/, _a.sent()];
2221
2731
  case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -2875,7 +3385,7 @@ var Pool = /** @class */ (function () {
2875
3385
  return __generator(this, function (_a) {
2876
3386
  switch (_a.label) {
2877
3387
  case 0:
2878
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
3388
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2879
3389
  contract = curve_1.curve.contracts[contractAddress].contract;
2880
3390
  if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
2881
3391
  return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
@@ -2917,8 +3427,12 @@ var Pool = /** @class */ (function () {
2917
3427
  this.estimateGas = {
2918
3428
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2919
3429
  addLiquidity: this.addLiquidityEstimateGas,
3430
+ depositAndStakeApprove: this.depositAndStakeApproveEstimateGas,
3431
+ depositAndStake: this.depositAndStakeEstimateGas,
2920
3432
  addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
2921
3433
  addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
3434
+ depositAndStakeWrappedApprove: this.depositAndStakeWrappedApproveEstimateGas,
3435
+ depositAndStakeWrapped: this.depositAndStakeWrappedEstimateGas,
2922
3436
  gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
2923
3437
  gaugeDeposit: this.gaugeDepositEstimateGas,
2924
3438
  gaugeWithdraw: this.gaugeWithdrawEstimateGas,
@@ -3026,10 +3540,10 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
3026
3540
  else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
3027
3541
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3028
3542
  }
3029
- else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0] !== 'eurtusd') {
3543
+ else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
3030
3544
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3031
3545
  }
3032
- else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0] !== 'eurtusd') {
3546
+ else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
3033
3547
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3034
3548
  }
3035
3549
  else {