@curvefi/api 1.8.2 → 1.10.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
@@ -59,14 +59,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
59
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
60
  };
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.crossAssetExchange = exports.crossAssetExchangeEstimateGas = exports.crossAssetExchangeApprove = exports.crossAssetExchangeApproveEstimateGas = exports.crossAssetExchangeIsApproved = exports.crossAssetExchangeExpected = exports.crossAssetExchangeOutputAndSlippage = exports._crossAssetExchangeInfo = exports._getSmallAmountForCoin = exports.crossAssetExchangeAvailable = exports.exchange = exports.exchangeEstimateGas = exports.exchangeApprove = exports.exchangeApproveEstimateGas = exports.exchangeIsApproved = exports.exchangeExpected = exports.getBestPoolAndOutput = exports._getBestPoolAndOutput = exports.Pool = void 0;
62
+ exports.crossAssetExchange = exports.crossAssetExchangeEstimateGas = exports.crossAssetExchangeApprove = exports.crossAssetExchangeApproveEstimateGas = exports.crossAssetExchangeIsApproved = exports.crossAssetExchangeExpected = exports.crossAssetExchangeOutputAndSlippage = exports._crossAssetExchangeInfo = exports._getSmallAmountForCoin = exports.crossAssetExchangeAvailable = exports.exchange = exports.exchangeEstimateGas = exports.exchangeApprove = exports.exchangeApproveEstimateGas = exports.exchangeIsApproved = exports.exchangeExpected = exports.getBestPoolAndOutput = exports.Pool = void 0;
63
63
  var ethers_1 = require("ethers");
64
64
  var utils_1 = require("./utils");
65
- var registry_exchange_json_1 = __importDefault(require("./constants/abis/json/registry_exchange.json"));
66
- var registry_json_1 = __importDefault(require("./constants/abis/json/registry.json"));
67
65
  var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
68
66
  var curve_1 = require("./curve");
69
67
  var coins_1 = require("./constants/coins");
68
+ var axios_1 = __importDefault(require("axios"));
70
69
  var Pool = /** @class */ (function () {
71
70
  function Pool(name) {
72
71
  var _this = this;
@@ -79,12 +78,12 @@ var Pool = /** @class */ (function () {
79
78
  switch (_a.label) {
80
79
  case 0:
81
80
  if (amounts.length !== this.underlyingCoinAddresses.length) {
82
- throw Error(this.name + " pool has " + this.underlyingCoinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
81
+ throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
83
82
  }
84
83
  _amounts = amounts.map(function (amount, i) {
85
84
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
86
85
  });
87
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
86
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 2];
88
87
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
89
88
  case 1:
90
89
  _expected = _a.sent(); // Lending pools
@@ -113,7 +112,7 @@ var Pool = /** @class */ (function () {
113
112
  switch (_a.label) {
114
113
  case 0:
115
114
  if (amounts.length !== this.coinAddresses.length) {
116
- throw Error(this.name + " pool has " + this.coinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
115
+ throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
117
116
  }
118
117
  _amounts = amounts.map(function (amount, i) {
119
118
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
@@ -159,7 +158,7 @@ var Pool = /** @class */ (function () {
159
158
  _poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true);
160
159
  return [3 /*break*/, 6];
161
160
  case 3:
162
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
161
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
163
162
  return [4 /*yield*/, this._getRates()];
164
163
  case 4:
165
164
  _rates_1 = _a.sent();
@@ -251,7 +250,7 @@ var Pool = /** @class */ (function () {
251
250
  switch (_d.label) {
252
251
  case 0:
253
252
  if (amounts.length !== this.underlyingCoinAddresses.length) {
254
- throw Error(this.name + " pool has " + this.underlyingCoinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
253
+ throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
255
254
  }
256
255
  _c = (_a = Object).values;
257
256
  return [4 /*yield*/, this.underlyingCoinBalances()];
@@ -259,7 +258,7 @@ var Pool = /** @class */ (function () {
259
258
  balances = _c.apply(_a, [_d.sent()]);
260
259
  for (i = 0; i < balances.length; i++) {
261
260
  if (Number(balances[i]) < Number(amounts[i])) {
262
- throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + balances[i] + ", required: " + amounts[i]);
261
+ throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
263
262
  }
264
263
  }
265
264
  return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
@@ -274,7 +273,7 @@ var Pool = /** @class */ (function () {
274
273
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
275
274
  case 3: return [2 /*return*/, _d.sent()];
276
275
  case 4:
277
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 6];
276
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 6];
278
277
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
279
278
  case 5: return [2 /*return*/, _d.sent()];
280
279
  case 6:
@@ -310,7 +309,7 @@ var Pool = /** @class */ (function () {
310
309
  switch (_a.label) {
311
310
  case 0:
312
311
  if (amounts.length !== this.underlyingCoinAddresses.length) {
313
- throw Error(this.name + " pool has " + this.underlyingCoinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
312
+ throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
314
313
  }
315
314
  _amounts = amounts.map(function (amount, i) {
316
315
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
@@ -318,11 +317,11 @@ var Pool = /** @class */ (function () {
318
317
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
319
318
  case 1:
320
319
  _a.sent();
321
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
320
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name)) return [3 /*break*/, 3];
322
321
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
323
322
  case 2: return [2 /*return*/, _a.sent()];
324
323
  case 3:
325
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
324
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
326
325
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
327
326
  case 4: return [2 /*return*/, _a.sent()];
328
327
  case 5:
@@ -408,7 +407,7 @@ var Pool = /** @class */ (function () {
408
407
  switch (_d.label) {
409
408
  case 0:
410
409
  if (amounts.length !== this.coinAddresses.length) {
411
- throw Error(this.name + " pool has " + this.coinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
410
+ throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
412
411
  }
413
412
  _c = (_a = Object).values;
414
413
  return [4 /*yield*/, this.coinBalances()];
@@ -416,7 +415,7 @@ var Pool = /** @class */ (function () {
416
415
  balances = _c.apply(_a, [_d.sent()]);
417
416
  for (i = 0; i < balances.length; i++) {
418
417
  if (Number(balances[i]) < Number(amounts[i])) {
419
- throw Error("Not enough " + this.coins[i] + ". Actual: " + balances[i] + ", required: " + amounts[i]);
418
+ throw Error("Not enough ".concat(this.coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
420
419
  }
421
420
  }
422
421
  return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
@@ -427,7 +426,7 @@ var Pool = /** @class */ (function () {
427
426
  _amounts = amounts.map(function (amount, i) {
428
427
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
429
428
  });
430
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
429
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 4];
431
430
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
432
431
  case 3: return [2 /*return*/, _d.sent()];
433
432
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -444,7 +443,7 @@ var Pool = /** @class */ (function () {
444
443
  switch (_a.label) {
445
444
  case 0:
446
445
  if (amounts.length !== this.coinAddresses.length) {
447
- throw Error(this.name + " pool has " + this.coinAddresses.length + " coins (amounts provided for " + amounts.length + ")");
446
+ throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
448
447
  }
449
448
  _amounts = amounts.map(function (amount, i) {
450
449
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
@@ -452,7 +451,7 @@ var Pool = /** @class */ (function () {
452
451
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
453
452
  case 1:
454
453
  _a.sent();
455
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
454
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
456
455
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
457
456
  case 2: return [2 /*return*/, _a.sent()];
458
457
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -469,7 +468,7 @@ var Pool = /** @class */ (function () {
469
468
  switch (_a.label) {
470
469
  case 0:
471
470
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
472
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
471
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 2];
473
472
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
474
473
  case 1:
475
474
  _expected = _a.sent(); // Lending pools
@@ -492,7 +491,7 @@ var Pool = /** @class */ (function () {
492
491
  return __generator(this, function (_a) {
493
492
  switch (_a.label) {
494
493
  case 0:
495
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
494
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
496
495
  return [2 /*return*/, true];
497
496
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
498
497
  case 1: return [2 /*return*/, _a.sent()];
@@ -503,7 +502,7 @@ var Pool = /** @class */ (function () {
503
502
  return __generator(this, function (_a) {
504
503
  switch (_a.label) {
505
504
  case 0:
506
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
505
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
507
506
  return [2 /*return*/, 0];
508
507
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
509
508
  case 1: return [2 /*return*/, _a.sent()];
@@ -514,7 +513,7 @@ var Pool = /** @class */ (function () {
514
513
  return __generator(this, function (_a) {
515
514
  switch (_a.label) {
516
515
  case 0:
517
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !this.isMeta)
516
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
518
517
  return [2 /*return*/, []];
519
518
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
520
519
  case 1: return [2 /*return*/, _a.sent()];
@@ -529,7 +528,7 @@ var Pool = /** @class */ (function () {
529
528
  case 1:
530
529
  lpTokenBalance = (_c.sent())['lpToken'];
531
530
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
532
- throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
531
+ throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
533
532
  }
534
533
  _a = this.zap;
535
534
  if (!_a) return [3 /*break*/, 3];
@@ -542,11 +541,11 @@ var Pool = /** @class */ (function () {
542
541
  throw Error("Token allowance is needed to estimate gas");
543
542
  }
544
543
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
545
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 5];
544
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name)) return [3 /*break*/, 5];
546
545
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
547
546
  case 4: return [2 /*return*/, _c.sent()];
548
547
  case 5:
549
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
548
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 7];
550
549
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
551
550
  case 6: return [2 /*return*/, _c.sent()];
552
551
  case 7:
@@ -567,11 +566,11 @@ var Pool = /** @class */ (function () {
567
566
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
568
567
  case 1:
569
568
  _a.sent();
570
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
569
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name)) return [3 /*break*/, 3];
571
570
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
572
571
  case 2: return [2 /*return*/, _a.sent()];
573
572
  case 3:
574
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
573
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
575
574
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
576
575
  case 4: return [2 /*return*/, _a.sent()];
577
576
  case 5:
@@ -607,9 +606,9 @@ var Pool = /** @class */ (function () {
607
606
  case 1:
608
607
  lpTokenBalance = (_a.sent())['lpToken'];
609
608
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
610
- throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
609
+ throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
611
610
  }
612
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
611
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
613
612
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
614
613
  case 2: return [2 /*return*/, _a.sent()];
615
614
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -626,7 +625,7 @@ var Pool = /** @class */ (function () {
626
625
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
627
626
  case 1:
628
627
  _a.sent();
629
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
628
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
630
629
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
631
630
  case 2: return [2 /*return*/, _a.sent()];
632
631
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -639,6 +638,9 @@ var Pool = /** @class */ (function () {
639
638
  return __generator(this, function (_a) {
640
639
  switch (_a.label) {
641
640
  case 0:
641
+ if (this.isCrypto) {
642
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
643
+ }
642
644
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
643
645
  return [4 /*yield*/, this.calcLpTokenAmount(amounts, false)];
644
646
  case 1: return [2 /*return*/, _a.sent()];
@@ -650,6 +652,9 @@ var Pool = /** @class */ (function () {
650
652
  return __generator(this, function (_c) {
651
653
  switch (_c.label) {
652
654
  case 0:
655
+ if (this.isCrypto) {
656
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
657
+ }
653
658
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
654
659
  _a = Number;
655
660
  return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
@@ -666,6 +671,9 @@ var Pool = /** @class */ (function () {
666
671
  return __generator(this, function (_a) {
667
672
  switch (_a.label) {
668
673
  case 0:
674
+ if (this.isCrypto) {
675
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
676
+ }
669
677
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
670
678
  if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
671
679
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
@@ -690,6 +698,9 @@ var Pool = /** @class */ (function () {
690
698
  return __generator(this, function (_a) {
691
699
  switch (_a.label) {
692
700
  case 0:
701
+ if (this.isCrypto) {
702
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
703
+ }
693
704
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
694
705
  if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
695
706
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
@@ -714,6 +725,9 @@ var Pool = /** @class */ (function () {
714
725
  return __generator(this, function (_a) {
715
726
  switch (_a.label) {
716
727
  case 0:
728
+ if (this.isCrypto) {
729
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
730
+ }
717
731
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
718
732
  if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) return [3 /*break*/, 3];
719
733
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, false)];
@@ -737,14 +751,18 @@ var Pool = /** @class */ (function () {
737
751
  var _this = this;
738
752
  return __generator(this, function (_c) {
739
753
  switch (_c.label) {
740
- case 0: return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
754
+ case 0:
755
+ if (this.isCrypto) {
756
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
757
+ }
758
+ return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
741
759
  case 1:
742
760
  lpTokenAmount = _c.sent();
743
761
  return [4 /*yield*/, this.lpTokenBalances()];
744
762
  case 2:
745
763
  lpTokenBalance = (_c.sent())['lpToken'];
746
764
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
747
- throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
765
+ throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
748
766
  }
749
767
  _a = this.zap;
750
768
  if (!_a) return [3 /*break*/, 4];
@@ -779,6 +797,9 @@ var Pool = /** @class */ (function () {
779
797
  return __generator(this, function (_a) {
780
798
  switch (_a.label) {
781
799
  case 0:
800
+ if (this.isCrypto) {
801
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
802
+ }
782
803
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
783
804
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
784
805
  case 1:
@@ -804,6 +825,9 @@ var Pool = /** @class */ (function () {
804
825
  return __generator(this, function (_a) {
805
826
  switch (_a.label) {
806
827
  case 0:
828
+ if (this.isCrypto) {
829
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
830
+ }
807
831
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
808
832
  return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
809
833
  case 1: return [2 /*return*/, _a.sent()];
@@ -815,6 +839,9 @@ var Pool = /** @class */ (function () {
815
839
  return __generator(this, function (_c) {
816
840
  switch (_c.label) {
817
841
  case 0:
842
+ if (this.isCrypto) {
843
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
844
+ }
818
845
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
819
846
  _a = Number;
820
847
  return [4 /*yield*/, this.removeLiquidityImbalanceWrappedExpected(amounts)];
@@ -830,14 +857,18 @@ var Pool = /** @class */ (function () {
830
857
  var _this = this;
831
858
  return __generator(this, function (_a) {
832
859
  switch (_a.label) {
833
- case 0: return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
860
+ case 0:
861
+ if (this.isCrypto) {
862
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
863
+ }
864
+ return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
834
865
  case 1:
835
866
  lpTokenAmount = _a.sent();
836
867
  return [4 /*yield*/, this.lpTokenBalances()];
837
868
  case 2:
838
869
  lpTokenBalance = (_a.sent())['lpToken'];
839
870
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
840
- throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
871
+ throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
841
872
  }
842
873
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
843
874
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
@@ -856,6 +887,9 @@ var Pool = /** @class */ (function () {
856
887
  return __generator(this, function (_a) {
857
888
  switch (_a.label) {
858
889
  case 0:
890
+ if (this.isCrypto) {
891
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
892
+ }
859
893
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
860
894
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
861
895
  case 1:
@@ -913,7 +947,7 @@ var Pool = /** @class */ (function () {
913
947
  return __generator(this, function (_a) {
914
948
  switch (_a.label) {
915
949
  case 0:
916
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
950
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
917
951
  return [2 /*return*/, true];
918
952
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
919
953
  case 1: return [2 /*return*/, _a.sent()];
@@ -924,7 +958,7 @@ var Pool = /** @class */ (function () {
924
958
  return __generator(this, function (_a) {
925
959
  switch (_a.label) {
926
960
  case 0:
927
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
961
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
928
962
  return [2 /*return*/, 0];
929
963
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
930
964
  case 1: return [2 /*return*/, _a.sent()];
@@ -935,7 +969,7 @@ var Pool = /** @class */ (function () {
935
969
  return __generator(this, function (_a) {
936
970
  switch (_a.label) {
937
971
  case 0:
938
- if (!['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
972
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
939
973
  return [2 /*return*/, []];
940
974
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
941
975
  case 1: return [2 /*return*/, _a.sent()];
@@ -950,7 +984,7 @@ var Pool = /** @class */ (function () {
950
984
  case 1:
951
985
  lpTokenBalance = (_c.sent())['lpToken'];
952
986
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
953
- throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
987
+ throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
954
988
  }
955
989
  _a = this.zap;
956
990
  if (!_a) return [3 /*break*/, 3];
@@ -964,11 +998,11 @@ var Pool = /** @class */ (function () {
964
998
  }
965
999
  i = this._getCoinIdx(coin);
966
1000
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
967
- if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 5];
1001
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 5];
968
1002
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
969
1003
  case 4: return [2 /*return*/, _c.sent()];
970
1004
  case 5:
971
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
1005
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 7];
972
1006
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
973
1007
  case 6: return [2 /*return*/, _c.sent()];
974
1008
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -988,11 +1022,11 @@ var Pool = /** @class */ (function () {
988
1022
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
989
1023
  case 1:
990
1024
  _a.sent();
991
- if (!(['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 3];
1025
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) || this.name === 'susd' || this.isMeta)) return [3 /*break*/, 3];
992
1026
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
993
1027
  case 2: return [2 /*return*/, _a.sent()];
994
1028
  case 3:
995
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
1029
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
996
1030
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
997
1031
  case 4: return [2 /*return*/, _a.sent()];
998
1032
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1008,7 +1042,7 @@ var Pool = /** @class */ (function () {
1008
1042
  switch (_a.label) {
1009
1043
  case 0:
1010
1044
  if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
1011
- throw Error(this.name + " pool doesn't have remove_liquidity_one_coin method for wrapped tokens");
1045
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1012
1046
  }
1013
1047
  i = this._getCoinIdx(coin, false);
1014
1048
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
@@ -1047,14 +1081,14 @@ var Pool = /** @class */ (function () {
1047
1081
  case 1:
1048
1082
  lpTokenBalance = (_a.sent())['lpToken'];
1049
1083
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
1050
- throw Error("Not enough LP tokens. Actual: " + lpTokenBalance + ", required: " + lpTokenAmount);
1084
+ throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
1051
1085
  }
1052
1086
  i = this._getCoinIdx(coin, false);
1053
1087
  if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
1054
- throw Error(this.name + " pool doesn't have remove_liquidity_one_coin method for wrapped tokens");
1088
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1055
1089
  }
1056
1090
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1057
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1091
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
1058
1092
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1059
1093
  case 2: return [2 /*return*/, _a.sent()];
1060
1094
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1069,13 +1103,13 @@ var Pool = /** @class */ (function () {
1069
1103
  case 0:
1070
1104
  i = this._getCoinIdx(coin, false);
1071
1105
  if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
1072
- throw Error(this.name + " pool doesn't have remove_liquidity_one_coin method for wrapped tokens");
1106
+ throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1073
1107
  }
1074
1108
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
1075
1109
  case 1:
1076
1110
  _a.sent();
1077
1111
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1078
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1112
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
1079
1113
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1080
1114
  case 2: return [2 /*return*/, _a.sent()];
1081
1115
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1156,70 +1190,70 @@ var Pool = /** @class */ (function () {
1156
1190
  }); };
1157
1191
  this.balances = function () {
1158
1192
  var addresses = [];
1159
- for (var _a = 0; _a < arguments.length; _a++) {
1160
- addresses[_a] = arguments[_a];
1193
+ for (var _i = 0; _i < arguments.length; _i++) {
1194
+ addresses[_i] = arguments[_i];
1161
1195
  }
1162
1196
  return __awaiter(_this, void 0, void 0, function () {
1163
- return __generator(this, function (_c) {
1164
- switch (_c.label) {
1197
+ return __generator(this, function (_a) {
1198
+ switch (_a.label) {
1165
1199
  case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
1166
- case 1: return [2 /*return*/, _c.sent()];
1200
+ case 1: return [2 /*return*/, _a.sent()];
1167
1201
  }
1168
1202
  });
1169
1203
  });
1170
1204
  };
1171
1205
  this.lpTokenBalances = function () {
1172
1206
  var addresses = [];
1173
- for (var _a = 0; _a < arguments.length; _a++) {
1174
- addresses[_a] = arguments[_a];
1207
+ for (var _i = 0; _i < arguments.length; _i++) {
1208
+ addresses[_i] = arguments[_i];
1175
1209
  }
1176
1210
  return __awaiter(_this, void 0, void 0, function () {
1177
- return __generator(this, function (_c) {
1178
- switch (_c.label) {
1211
+ return __generator(this, function (_a) {
1212
+ switch (_a.label) {
1179
1213
  case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
1180
- case 1: return [2 /*return*/, _c.sent()];
1214
+ case 1: return [2 /*return*/, _a.sent()];
1181
1215
  }
1182
1216
  });
1183
1217
  });
1184
1218
  };
1185
1219
  this.underlyingCoinBalances = function () {
1186
1220
  var addresses = [];
1187
- for (var _a = 0; _a < arguments.length; _a++) {
1188
- addresses[_a] = arguments[_a];
1221
+ for (var _i = 0; _i < arguments.length; _i++) {
1222
+ addresses[_i] = arguments[_i];
1189
1223
  }
1190
1224
  return __awaiter(_this, void 0, void 0, function () {
1191
- return __generator(this, function (_c) {
1192
- switch (_c.label) {
1225
+ return __generator(this, function (_a) {
1226
+ switch (_a.label) {
1193
1227
  case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoins, this.underlyingCoinAddresses], addresses, false))];
1194
- case 1: return [2 /*return*/, _c.sent()];
1228
+ case 1: return [2 /*return*/, _a.sent()];
1195
1229
  }
1196
1230
  });
1197
1231
  });
1198
1232
  };
1199
1233
  this.coinBalances = function () {
1200
1234
  var addresses = [];
1201
- for (var _a = 0; _a < arguments.length; _a++) {
1202
- addresses[_a] = arguments[_a];
1235
+ for (var _i = 0; _i < arguments.length; _i++) {
1236
+ addresses[_i] = arguments[_i];
1203
1237
  }
1204
1238
  return __awaiter(_this, void 0, void 0, function () {
1205
- return __generator(this, function (_c) {
1206
- switch (_c.label) {
1239
+ return __generator(this, function (_a) {
1240
+ switch (_a.label) {
1207
1241
  case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.coins, this.coinAddresses], addresses, false))];
1208
- case 1: return [2 /*return*/, _c.sent()];
1242
+ case 1: return [2 /*return*/, _a.sent()];
1209
1243
  }
1210
1244
  });
1211
1245
  });
1212
1246
  };
1213
1247
  this.allCoinBalances = function () {
1214
1248
  var addresses = [];
1215
- for (var _a = 0; _a < arguments.length; _a++) {
1216
- addresses[_a] = arguments[_a];
1249
+ for (var _i = 0; _i < arguments.length; _i++) {
1250
+ addresses[_i] = arguments[_i];
1217
1251
  }
1218
1252
  return __awaiter(_this, void 0, void 0, function () {
1219
- return __generator(this, function (_c) {
1220
- switch (_c.label) {
1253
+ return __generator(this, function (_a) {
1254
+ switch (_a.label) {
1221
1255
  case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
1222
- case 1: return [2 /*return*/, _c.sent()];
1256
+ case 1: return [2 /*return*/, _a.sent()];
1223
1257
  }
1224
1258
  });
1225
1259
  });
@@ -1240,34 +1274,37 @@ var Pool = /** @class */ (function () {
1240
1274
  });
1241
1275
  }); };
1242
1276
  this.exchangeIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1243
- var i;
1277
+ var contractAddress, i;
1244
1278
  return __generator(this, function (_a) {
1245
1279
  switch (_a.label) {
1246
1280
  case 0:
1281
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1247
1282
  i = this._getCoinIdx(inputCoin);
1248
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1283
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1249
1284
  case 1: return [2 /*return*/, _a.sent()];
1250
1285
  }
1251
1286
  });
1252
1287
  }); };
1253
1288
  this.exchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1254
- var i;
1289
+ var contractAddress, i;
1255
1290
  return __generator(this, function (_a) {
1256
1291
  switch (_a.label) {
1257
1292
  case 0:
1293
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1258
1294
  i = this._getCoinIdx(inputCoin);
1259
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1295
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1260
1296
  case 1: return [2 /*return*/, _a.sent()];
1261
1297
  }
1262
1298
  });
1263
1299
  }); };
1264
1300
  this.exchangeApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1265
- var i;
1301
+ var contractAddress, i;
1266
1302
  return __generator(this, function (_a) {
1267
1303
  switch (_a.label) {
1268
1304
  case 0:
1305
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1269
1306
  i = this._getCoinIdx(inputCoin);
1270
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1307
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1271
1308
  case 1: return [2 /*return*/, _a.sent()];
1272
1309
  }
1273
1310
  });
@@ -1275,13 +1312,10 @@ var Pool = /** @class */ (function () {
1275
1312
  this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
1276
1313
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1277
1314
  return __awaiter(_this, void 0, void 0, function () {
1278
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
1315
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contractAddress, contract, exchangeMethod, value;
1279
1316
  return __generator(this, function (_d) {
1280
1317
  switch (_d.label) {
1281
1318
  case 0:
1282
- if (this.name === 'tricrypto2') {
1283
- throw Error("Use exchangeTricryptoEstimateGas method for tricrypto2 pool instead");
1284
- }
1285
1319
  i = this._getCoinIdx(inputCoin);
1286
1320
  j = this._getCoinIdx(outputCoin);
1287
1321
  _c = (_a = Object).values;
@@ -1289,7 +1323,7 @@ var Pool = /** @class */ (function () {
1289
1323
  case 1:
1290
1324
  inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
1291
1325
  if (Number(inputCoinBalance) < Number(amount)) {
1292
- throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
1326
+ throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
1293
1327
  }
1294
1328
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1295
1329
  case 2:
@@ -1300,12 +1334,18 @@ var Pool = /** @class */ (function () {
1300
1334
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1301
1335
  case 3:
1302
1336
  _expected = _d.sent();
1303
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1304
- contract = curve_1.curve.contracts[this.swap].contract;
1337
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
1338
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1339
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1340
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1341
+ contract = curve_1.curve.contracts[contractAddress].contract;
1305
1342
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1306
1343
  value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1307
- return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1344
+ if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
1345
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1308
1346
  case 4: return [2 /*return*/, (_d.sent()).toNumber()];
1347
+ case 5: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1348
+ case 6: return [2 /*return*/, (_d.sent()).toNumber()];
1309
1349
  }
1310
1350
  });
1311
1351
  });
@@ -1313,158 +1353,40 @@ var Pool = /** @class */ (function () {
1313
1353
  this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
1314
1354
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1315
1355
  return __awaiter(_this, void 0, void 0, function () {
1316
- var i, j, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value, gasLimit;
1356
+ var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contractAddress, contract, exchangeMethod, value, gasLimit_1, gasLimit;
1317
1357
  return __generator(this, function (_a) {
1318
1358
  switch (_a.label) {
1319
1359
  case 0:
1320
- if (this.name === 'tricrypto2') {
1321
- throw Error("Use exchangeTricrypto method for tricrypto2 pool instead");
1322
- }
1323
1360
  i = this._getCoinIdx(inputCoin);
1324
1361
  j = this._getCoinIdx(outputCoin);
1325
1362
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
1326
1363
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1327
1364
  case 1:
1328
1365
  _expected = _a.sent();
1329
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1366
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
1367
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1368
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1330
1369
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
1331
1370
  case 2:
1332
1371
  _a.sent();
1333
- contract = curve_1.curve.contracts[this.swap].contract;
1372
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1373
+ contract = curve_1.curve.contracts[contractAddress].contract;
1334
1374
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1335
1375
  value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1336
1376
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
1337
1377
  case 3:
1338
1378
  _a.sent();
1339
- return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1379
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
1380
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1340
1381
  case 4:
1341
- gasLimit = (_a.sent()).mul(130).div(100);
1342
- return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1382
+ gasLimit_1 = (_a.sent()).mul(130).div(100);
1383
+ return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_1 }))];
1343
1384
  case 5: return [2 /*return*/, (_a.sent()).hash];
1344
- }
1345
- });
1346
- });
1347
- };
1348
- this.exchangeTricryptoIsApproved = function (inputCoin, amount, useEth) {
1349
- if (useEth === void 0) { useEth = false; }
1350
- return __awaiter(_this, void 0, void 0, function () {
1351
- var i;
1352
- return __generator(this, function (_a) {
1353
- switch (_a.label) {
1354
- case 0:
1355
- i = this._getCoinIdx(inputCoin);
1356
- if (i === 2 && useEth)
1357
- return [2 /*return*/, true];
1358
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1359
- case 1: return [2 /*return*/, _a.sent()];
1360
- }
1361
- });
1362
- });
1363
- };
1364
- this.exchangeTricryptoApproveEstimateGas = function (inputCoin, amount, useEth) {
1365
- if (useEth === void 0) { useEth = false; }
1366
- return __awaiter(_this, void 0, void 0, function () {
1367
- var i;
1368
- return __generator(this, function (_a) {
1369
- switch (_a.label) {
1370
- case 0:
1371
- i = this._getCoinIdx(inputCoin);
1372
- if (i === 2 && useEth)
1373
- return [2 /*return*/, 0];
1374
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1375
- case 1: return [2 /*return*/, _a.sent()];
1376
- }
1377
- });
1378
- });
1379
- };
1380
- this.exchangeTricryptoApprove = function (inputCoin, amount, useEth) {
1381
- if (useEth === void 0) { useEth = false; }
1382
- return __awaiter(_this, void 0, void 0, function () {
1383
- var i;
1384
- return __generator(this, function (_a) {
1385
- switch (_a.label) {
1386
- case 0:
1387
- i = this._getCoinIdx(inputCoin);
1388
- if (i === 2 && useEth)
1389
- return [2 /*return*/, []];
1390
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1391
- case 1: return [2 /*return*/, _a.sent()];
1392
- }
1393
- });
1394
- });
1395
- };
1396
- this.exchangeTricryptoEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage, useEth) {
1397
- if (maxSlippage === void 0) { maxSlippage = 0.01; }
1398
- if (useEth === void 0) { useEth = false; }
1399
- return __awaiter(_this, void 0, void 0, function () {
1400
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
1401
- return __generator(this, function (_d) {
1402
- switch (_d.label) {
1403
- case 0:
1404
- if (this.name !== 'tricrypto2') {
1405
- throw Error("This method is for only tricrypto2 pool");
1406
- }
1407
- i = this._getCoinIdx(inputCoin);
1408
- j = this._getCoinIdx(outputCoin);
1409
- _c = (_a = Object).values;
1410
- return [4 /*yield*/, this.underlyingCoinBalances()];
1411
- case 1:
1412
- inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
1413
- if (Number(inputCoinBalance) < Number(amount)) {
1414
- throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
1415
- }
1416
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1417
- case 2:
1418
- if (!(_d.sent())) {
1419
- throw Error("Token allowance is needed to estimate gas");
1420
- }
1421
- _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
1422
- return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1423
- case 3:
1424
- _expected = _d.sent();
1425
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1426
- contract = curve_1.curve.contracts[this.swap].contract;
1427
- value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
1428
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1429
- case 4: return [2 /*return*/, (_d.sent()).toNumber()];
1430
- }
1431
- });
1432
- });
1433
- };
1434
- this.exchangeTricrypto = function (inputCoin, outputCoin, amount, maxSlippage, useEth) {
1435
- if (maxSlippage === void 0) { maxSlippage = 0.01; }
1436
- if (useEth === void 0) { useEth = false; }
1437
- return __awaiter(_this, void 0, void 0, function () {
1438
- var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit;
1439
- return __generator(this, function (_a) {
1440
- switch (_a.label) {
1441
- case 0:
1442
- if (this.name !== 'tricrypto2') {
1443
- throw Error("This method is for only tricrypto2 pool");
1444
- }
1445
- i = this._getCoinIdx(inputCoin);
1446
- j = this._getCoinIdx(outputCoin);
1447
- _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
1448
- return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1449
- case 1:
1450
- _expected = _a.sent();
1451
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1452
- if (!(i !== 2 || !useEth)) return [3 /*break*/, 3];
1453
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
1454
- case 2:
1455
- _a.sent();
1456
- _a.label = 3;
1457
- case 3:
1458
- contract = curve_1.curve.contracts[this.swap].contract;
1459
- value = useEth && i == 2 ? _amount : ethers_1.ethers.BigNumber.from(0);
1460
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
1461
- case 4:
1462
- _a.sent();
1463
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1464
- case 5:
1385
+ case 6: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1386
+ case 7:
1465
1387
  gasLimit = (_a.sent()).mul(130).div(100);
1466
- return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, useEth, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1467
- case 6: return [2 /*return*/, (_a.sent()).hash];
1388
+ return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1389
+ case 8: return [2 /*return*/, (_a.sent()).hash];
1468
1390
  }
1469
1391
  });
1470
1392
  });
@@ -1520,7 +1442,7 @@ var Pool = /** @class */ (function () {
1520
1442
  this.exchangeWrappedEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
1521
1443
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1522
1444
  return __awaiter(_this, void 0, void 0, function () {
1523
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
1445
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value;
1524
1446
  return __generator(this, function (_d) {
1525
1447
  switch (_d.label) {
1526
1448
  case 0:
@@ -1531,7 +1453,7 @@ var Pool = /** @class */ (function () {
1531
1453
  case 1:
1532
1454
  inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
1533
1455
  if (Number(inputCoinBalance) < Number(amount)) {
1534
- throw Error("Not enough " + this.coins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
1456
+ throw Error("Not enough ".concat(this.coins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
1535
1457
  }
1536
1458
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1537
1459
  case 2:
@@ -1542,11 +1464,16 @@ var Pool = /** @class */ (function () {
1542
1464
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
1543
1465
  case 3:
1544
1466
  _expected = _d.sent();
1545
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1467
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
1468
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1469
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1546
1470
  contract = curve_1.curve.contracts[this.swap].contract;
1547
1471
  value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1548
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1472
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 5];
1473
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1549
1474
  case 4: return [2 /*return*/, (_d.sent()).toNumber()];
1475
+ case 5: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1476
+ case 6: return [2 /*return*/, (_d.sent()).toNumber()];
1550
1477
  }
1551
1478
  });
1552
1479
  });
@@ -1554,7 +1481,7 @@ var Pool = /** @class */ (function () {
1554
1481
  this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
1555
1482
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1556
1483
  return __awaiter(_this, void 0, void 0, function () {
1557
- var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit;
1484
+ var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, gasLimit;
1558
1485
  return __generator(this, function (_a) {
1559
1486
  switch (_a.label) {
1560
1487
  case 0:
@@ -1564,7 +1491,9 @@ var Pool = /** @class */ (function () {
1564
1491
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
1565
1492
  case 1:
1566
1493
  _expected = _a.sent();
1567
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1494
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
1495
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1496
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1568
1497
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.coinAddresses[i]], [_amount], this.swap)];
1569
1498
  case 2:
1570
1499
  _a.sent();
@@ -1573,24 +1502,30 @@ var Pool = /** @class */ (function () {
1573
1502
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
1574
1503
  case 3:
1575
1504
  _a.sent();
1576
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1505
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
1506
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1577
1507
  case 4:
1508
+ gasLimit_2 = (_a.sent()).mul(130).div(100);
1509
+ return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_2 }))];
1510
+ case 5: return [2 /*return*/, (_a.sent()).hash];
1511
+ case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1512
+ case 7:
1578
1513
  gasLimit = (_a.sent()).mul(130).div(100);
1579
1514
  return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1580
- case 5: return [2 /*return*/, (_a.sent()).hash];
1515
+ case 8: return [2 /*return*/, (_a.sent()).hash];
1581
1516
  }
1582
1517
  });
1583
1518
  });
1584
1519
  };
1585
1520
  this.gaugeMaxBoostedDeposit = function () {
1586
1521
  var addresses = [];
1587
- for (var _a = 0; _a < arguments.length; _a++) {
1588
- addresses[_a] = arguments[_a];
1522
+ for (var _i = 0; _i < arguments.length; _i++) {
1523
+ addresses[_i] = arguments[_i];
1589
1524
  }
1590
1525
  return __awaiter(_this, void 0, void 0, function () {
1591
- var votingEscrowContract, gaugeContract, contractCalls, response, _c, veTotalSupply, gaugeTotalSupply, resultBN, result, _d, _e, entry;
1592
- return __generator(this, function (_f) {
1593
- switch (_f.label) {
1526
+ var votingEscrowContract, gaugeContract, contractCalls, response, _a, veTotalSupply, gaugeTotalSupply, resultBN, result, _c, _d, entry;
1527
+ return __generator(this, function (_e) {
1528
+ switch (_e.label) {
1594
1529
  case 0:
1595
1530
  if (addresses.length == 1 && Array.isArray(addresses[0]))
1596
1531
  addresses = addresses[0];
@@ -1602,15 +1537,15 @@ var Pool = /** @class */ (function () {
1602
1537
  });
1603
1538
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1604
1539
  case 1:
1605
- response = (_f.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1606
- _c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
1540
+ response = (_e.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1541
+ _a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
1607
1542
  resultBN = {};
1608
1543
  addresses.forEach(function (acct, i) {
1609
1544
  resultBN[acct] = response[i].div(veTotalSupply).times(gaugeTotalSupply);
1610
1545
  });
1611
1546
  result = {};
1612
- for (_d = 0, _e = Object.entries(resultBN); _d < _e.length; _d++) {
1613
- entry = _e[_d];
1547
+ for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
1548
+ entry = _d[_c];
1614
1549
  result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
1615
1550
  }
1616
1551
  return [2 /*return*/, result];
@@ -1620,13 +1555,13 @@ var Pool = /** @class */ (function () {
1620
1555
  };
1621
1556
  this.gaugeOptimalDeposits = function () {
1622
1557
  var accounts = [];
1623
- for (var _a = 0; _a < arguments.length; _a++) {
1624
- accounts[_a] = arguments[_a];
1558
+ for (var _i = 0; _i < arguments.length; _i++) {
1559
+ accounts[_i] = arguments[_i];
1625
1560
  }
1626
1561
  return __awaiter(_this, void 0, void 0, function () {
1627
- var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, response, _c, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _d, accounts_1, acct, totalPower, optimalBN, _e, accounts_2, acct, amount, _f, accounts_3, acct, optimal, _g, _h, entry;
1628
- return __generator(this, function (_k) {
1629
- switch (_k.label) {
1562
+ var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, response, _a, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _c, accounts_1, acct, totalPower, optimalBN, _d, accounts_2, acct, amount, _e, accounts_3, acct, optimal, _f, _h, entry;
1563
+ return __generator(this, function (_j) {
1564
+ switch (_j.label) {
1630
1565
  case 0:
1631
1566
  if (accounts.length == 1 && Array.isArray(accounts[0]))
1632
1567
  accounts = accounts[0];
@@ -1639,12 +1574,12 @@ var Pool = /** @class */ (function () {
1639
1574
  });
1640
1575
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1641
1576
  case 1:
1642
- response = (_k.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1643
- _c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
1577
+ response = (_j.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1578
+ _a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
1644
1579
  votingPower = {};
1645
1580
  totalBalance = (0, utils_1.BN)(0);
1646
- for (_d = 0, accounts_1 = accounts; _d < accounts_1.length; _d++) {
1647
- acct = accounts_1[_d];
1581
+ for (_c = 0, accounts_1 = accounts; _c < accounts_1.length; _c++) {
1582
+ acct = accounts_1[_c];
1648
1583
  votingPower[acct] = response[0];
1649
1584
  totalBalance = totalBalance.plus(response[1]).plus(response[2]);
1650
1585
  response.splice(0, 3);
@@ -1652,8 +1587,8 @@ var Pool = /** @class */ (function () {
1652
1587
  totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
1653
1588
  optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
1654
1589
  if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
1655
- for (_e = 0, accounts_2 = accounts; _e < accounts_2.length; _e++) {
1656
- acct = accounts_2[_e];
1590
+ for (_d = 0, accounts_2 = accounts; _d < accounts_2.length; _d++) {
1591
+ acct = accounts_2[_d];
1657
1592
  amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
1658
1593
  gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
1659
1594
  optimalBN[acct] = amount;
@@ -1665,16 +1600,16 @@ var Pool = /** @class */ (function () {
1665
1600
  }
1666
1601
  else {
1667
1602
  if (totalPower.lt(0)) {
1668
- for (_f = 0, accounts_3 = accounts; _f < accounts_3.length; _f++) {
1669
- acct = accounts_3[_f];
1603
+ for (_e = 0, accounts_3 = accounts; _e < accounts_3.length; _e++) {
1604
+ acct = accounts_3[_e];
1670
1605
  optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
1671
1606
  }
1672
1607
  }
1673
1608
  optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
1674
1609
  }
1675
1610
  optimal = {};
1676
- for (_g = 0, _h = Object.entries(optimalBN); _g < _h.length; _g++) {
1677
- entry = _h[_g];
1611
+ for (_f = 0, _h = Object.entries(optimalBN); _f < _h.length; _f++) {
1612
+ entry = _h[_f];
1678
1613
  optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
1679
1614
  }
1680
1615
  return [2 /*return*/, optimal];
@@ -1737,7 +1672,7 @@ var Pool = /** @class */ (function () {
1737
1672
  throw Error('Index must be >= 0');
1738
1673
  }
1739
1674
  if (idx_1 > coins_N - 1) {
1740
- throw Error("Index must be < " + coins_N);
1675
+ throw Error("Index must be < ".concat(coins_N));
1741
1676
  }
1742
1677
  return idx_1;
1743
1678
  }
@@ -1747,7 +1682,7 @@ var Pool = /** @class */ (function () {
1747
1682
  _this.coinAddresses.map(function (c) { return c.toLowerCase(); });
1748
1683
  var idx = lowerCaseCoinAddresses.indexOf(coinAddress.toLowerCase());
1749
1684
  if (idx === -1) {
1750
- throw Error("There is no " + coin + " in " + _this.name + " pool");
1685
+ throw Error("There is no ".concat(coin, " in ").concat(_this.name, " pool"));
1751
1686
  }
1752
1687
  return idx;
1753
1688
  };
@@ -1792,13 +1727,13 @@ var Pool = /** @class */ (function () {
1792
1727
  }); };
1793
1728
  this._balances = function (rawCoinNames, rawCoinAddresses) {
1794
1729
  var addresses = [];
1795
- for (var _a = 2; _a < arguments.length; _a++) {
1796
- addresses[_a - 2] = arguments[_a];
1730
+ for (var _i = 2; _i < arguments.length; _i++) {
1731
+ addresses[_i - 2] = arguments[_i];
1797
1732
  }
1798
1733
  return __awaiter(_this, void 0, void 0, function () {
1799
- var coinNames, coinAddresses, i, rawBalances, balances, _c, addresses_1, address, _d, coinNames_1, coinName;
1800
- return __generator(this, function (_e) {
1801
- switch (_e.label) {
1734
+ var coinNames, coinAddresses, i, rawBalances, balances, _a, addresses_1, address, _c, coinNames_1, coinName;
1735
+ return __generator(this, function (_d) {
1736
+ switch (_d.label) {
1802
1737
  case 0:
1803
1738
  coinNames = [];
1804
1739
  coinAddresses = [];
@@ -1809,20 +1744,16 @@ var Pool = /** @class */ (function () {
1809
1744
  coinAddresses.push(rawCoinAddresses[i]);
1810
1745
  }
1811
1746
  }
1812
- if (this.name === 'tricrypto2') {
1813
- coinNames.push('ETH');
1814
- coinAddresses.push('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE');
1815
- }
1816
1747
  addresses = (0, utils_1._prepareAddresses)(addresses);
1817
1748
  return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
1818
1749
  case 1:
1819
- rawBalances = _e.sent();
1750
+ rawBalances = _d.sent();
1820
1751
  balances = {};
1821
- for (_c = 0, addresses_1 = addresses; _c < addresses_1.length; _c++) {
1822
- address = addresses_1[_c];
1752
+ for (_a = 0, addresses_1 = addresses; _a < addresses_1.length; _a++) {
1753
+ address = addresses_1[_a];
1823
1754
  balances[address] = {};
1824
- for (_d = 0, coinNames_1 = coinNames; _d < coinNames_1.length; _d++) {
1825
- coinName = coinNames_1[_d];
1755
+ for (_c = 0, coinNames_1 = coinNames; _c < coinNames_1.length; _c++) {
1756
+ coinName = coinNames_1[_c];
1826
1757
  balances[address][coinName] = rawBalances[address].shift();
1827
1758
  }
1828
1759
  }
@@ -1926,10 +1857,16 @@ var Pool = /** @class */ (function () {
1926
1857
  this._calcLpTokenAmount = function (_amounts, isDeposit) {
1927
1858
  if (isDeposit === void 0) { isDeposit = true; }
1928
1859
  return __awaiter(_this, void 0, void 0, function () {
1860
+ var contract;
1929
1861
  return __generator(this, function (_a) {
1930
1862
  switch (_a.label) {
1931
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1863
+ case 0:
1864
+ contract = curve_1.curve.contracts[this.swap].contract;
1865
+ if (!["eurtusd", "crveth"].includes(this.name)) return [3 /*break*/, 2];
1866
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1932
1867
  case 1: return [2 /*return*/, _a.sent()];
1868
+ case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1869
+ case 3: return [2 /*return*/, _a.sent()];
1933
1870
  }
1934
1871
  });
1935
1872
  });
@@ -1945,8 +1882,12 @@ var Pool = /** @class */ (function () {
1945
1882
  if (!this.isFactory) return [3 /*break*/, 2];
1946
1883
  return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
1947
1884
  case 1: return [2 /*return*/, _a.sent()];
1948
- case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1885
+ case 2:
1886
+ if (!(this.name === "eurtusd")) return [3 /*break*/, 4];
1887
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1949
1888
  case 3: return [2 /*return*/, _a.sent()];
1889
+ case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1890
+ case 5: return [2 /*return*/, _a.sent()];
1950
1891
  }
1951
1892
  });
1952
1893
  });
@@ -1963,7 +1904,7 @@ var Pool = /** @class */ (function () {
1963
1904
  _wrapped_amounts = _underlying_amounts.map(function (amount, i) {
1964
1905
  return amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates[i]);
1965
1906
  });
1966
- return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.constantOptions)];
1907
+ return [4 /*yield*/, this._calcLpTokenAmount(_wrapped_amounts, isDeposit)];
1967
1908
  case 2: return [2 /*return*/, _a.sent()];
1968
1909
  }
1969
1910
  });
@@ -2034,7 +1975,7 @@ var Pool = /** @class */ (function () {
2034
1975
  this._addLiquidityMetaZap = function (_amounts, estimateGas) {
2035
1976
  if (estimateGas === void 0) { estimateGas = false; }
2036
1977
  return __awaiter(_this, void 0, void 0, function () {
2037
- var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_1, gas, gasLimit;
1978
+ var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_3, gas, gasLimit;
2038
1979
  return __generator(this, function (_a) {
2039
1980
  switch (_a.label) {
2040
1981
  case 0:
@@ -2056,8 +1997,8 @@ var Pool = /** @class */ (function () {
2056
1997
  if (estimateGas) {
2057
1998
  return [2 /*return*/, gas_1.toNumber()];
2058
1999
  }
2059
- gasLimit_1 = gas_1.mul(130).div(100);
2060
- return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1, value: value }))];
2000
+ gasLimit_3 = gas_1.mul(130).div(100);
2001
+ return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3, value: value }))];
2061
2002
  case 5: return [2 /*return*/, (_a.sent()).hash];
2062
2003
  case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2063
2004
  case 7:
@@ -2100,7 +2041,7 @@ var Pool = /** @class */ (function () {
2100
2041
  _minMintAmount = _a;
2101
2042
  _minMintAmount = _minMintAmount.mul(99).div(100);
2102
2043
  contract = curve_1.curve.contracts[this.swap].contract;
2103
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
2044
+ ethIndex = (0, utils_1.getEthIndex)(useUnderlying ? this.underlyingCoinAddresses : this.coinAddresses);
2104
2045
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
2105
2046
  return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2106
2047
  case 7:
@@ -2116,21 +2057,21 @@ var Pool = /** @class */ (function () {
2116
2057
  });
2117
2058
  };
2118
2059
  this._calcExpectedAmounts = function (_lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
2119
- var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _c, coinBalancesBN_1, coinBalance;
2060
+ var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _i, coinBalancesBN_1, coinBalance;
2120
2061
  var _this = this;
2121
- return __generator(this, function (_d) {
2122
- switch (_d.label) {
2062
+ return __generator(this, function (_c) {
2063
+ switch (_c.label) {
2123
2064
  case 0:
2124
2065
  coinBalancesBN = [];
2125
2066
  i = 0;
2126
- _d.label = 1;
2067
+ _c.label = 1;
2127
2068
  case 1:
2128
2069
  if (!(i < this.coinAddresses.length)) return [3 /*break*/, 4];
2129
2070
  return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.constantOptions)];
2130
2071
  case 2:
2131
- _balance = _d.sent();
2072
+ _balance = _c.sent();
2132
2073
  coinBalancesBN.push((0, utils_1.toBN)(_balance, this.decimals[i]));
2133
- _d.label = 3;
2074
+ _c.label = 3;
2134
2075
  case 3:
2135
2076
  i++;
2136
2077
  return [3 /*break*/, 1];
@@ -2138,10 +2079,10 @@ var Pool = /** @class */ (function () {
2138
2079
  _a = utils_1.toBN;
2139
2080
  return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
2140
2081
  case 5:
2141
- totalSupplyBN = _a.apply(void 0, [_d.sent()]);
2082
+ totalSupplyBN = _a.apply(void 0, [_c.sent()]);
2142
2083
  expectedAmountsBN = [];
2143
- for (_c = 0, coinBalancesBN_1 = coinBalancesBN; _c < coinBalancesBN_1.length; _c++) {
2144
- coinBalance = coinBalancesBN_1[_c];
2084
+ for (_i = 0, coinBalancesBN_1 = coinBalancesBN; _i < coinBalancesBN_1.length; _i++) {
2085
+ coinBalance = coinBalancesBN_1[_i];
2145
2086
  expectedAmountsBN.push(coinBalance.times((0, utils_1.toBN)(_lpTokenAmount)).div(totalSupplyBN));
2146
2087
  }
2147
2088
  return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return (0, utils_1.fromBN)(amount, _this.decimals[i]); })];
@@ -2258,7 +2199,7 @@ var Pool = /** @class */ (function () {
2258
2199
  this._removeLiquidityMetaZap = function (_lpTokenAmount, estimateGas) {
2259
2200
  if (estimateGas === void 0) { estimateGas = false; }
2260
2201
  return __awaiter(_this, void 0, void 0, function () {
2261
- var _minAmounts, contract, gas_2, gasLimit_2, gas, gasLimit;
2202
+ var _minAmounts, contract, gas_2, gasLimit_4, gas, gasLimit;
2262
2203
  return __generator(this, function (_a) {
2263
2204
  switch (_a.label) {
2264
2205
  case 0:
@@ -2278,8 +2219,8 @@ var Pool = /** @class */ (function () {
2278
2219
  if (estimateGas) {
2279
2220
  return [2 /*return*/, gas_2.toNumber()];
2280
2221
  }
2281
- gasLimit_2 = gas_2.mul(130).div(100);
2282
- return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_2 }))];
2222
+ gasLimit_4 = gas_2.mul(130).div(100);
2223
+ return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
2283
2224
  case 5: return [2 /*return*/, (_a.sent()).hash];
2284
2225
  case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
2285
2226
  case 7:
@@ -2382,7 +2323,7 @@ var Pool = /** @class */ (function () {
2382
2323
  this._removeLiquidityImbalanceMetaZap = function (_amounts, estimateGas) {
2383
2324
  if (estimateGas === void 0) { estimateGas = false; }
2384
2325
  return __awaiter(_this, void 0, void 0, function () {
2385
- var _maxBurnAmount, contract, gas_3, gasLimit_3, gas, gasLimit;
2326
+ var _maxBurnAmount, contract, gas_3, gasLimit_5, gas, gasLimit;
2386
2327
  return __generator(this, function (_a) {
2387
2328
  switch (_a.label) {
2388
2329
  case 0: return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
@@ -2402,8 +2343,8 @@ var Pool = /** @class */ (function () {
2402
2343
  if (estimateGas) {
2403
2344
  return [2 /*return*/, gas_3.toNumber()];
2404
2345
  }
2405
- gasLimit_3 = gas_3.mul(130).div(100);
2406
- return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3 }))];
2346
+ gasLimit_5 = gas_3.mul(130).div(100);
2347
+ return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_5 }))];
2407
2348
  case 5: return [2 /*return*/, (_a.sent())];
2408
2349
  case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
2409
2350
  case 7:
@@ -2511,38 +2452,48 @@ var Pool = /** @class */ (function () {
2511
2452
  this._removeLiquidityOneCoinZap = function (_lpTokenAmount, i, estimateGas) {
2512
2453
  if (estimateGas === void 0) { estimateGas = false; }
2513
2454
  return __awaiter(_this, void 0, void 0, function () {
2514
- var _minAmount, contract, gas_4, gasLimit_4, gas, gasLimit;
2515
- return __generator(this, function (_a) {
2516
- switch (_a.label) {
2455
+ var _minAmount, _a, contract, gas_4, gasLimit_6, gas, gasLimit;
2456
+ return __generator(this, function (_c) {
2457
+ switch (_c.label) {
2517
2458
  case 0:
2518
2459
  if (!!estimateGas) return [3 /*break*/, 2];
2519
2460
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
2520
2461
  case 1:
2521
- _a.sent();
2522
- _a.label = 2;
2523
- case 2: return [4 /*yield*/, this._calcWithdrawOneCoinZap(_lpTokenAmount, i)];
2462
+ _c.sent();
2463
+ _c.label = 2;
2464
+ case 2:
2465
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 4];
2466
+ return [4 /*yield*/, this._calcWithdrawOneCoinSwap(_lpTokenAmount, i)];
2524
2467
  case 3:
2525
- _minAmount = (_a.sent()).mul(99).div(100);
2468
+ _a = _c.sent();
2469
+ return [3 /*break*/, 6];
2470
+ case 4: return [4 /*yield*/, this._calcWithdrawOneCoinZap(_lpTokenAmount, i)];
2471
+ case 5:
2472
+ _a = _c.sent();
2473
+ _c.label = 6;
2474
+ case 6:
2475
+ _minAmount = _a;
2476
+ _minAmount = _minAmount.mul(99).div(100);
2526
2477
  contract = curve_1.curve.contracts[this.zap].contract;
2527
- if (!this.isFactory) return [3 /*break*/, 6];
2478
+ if (!this.isFactory) return [3 /*break*/, 9];
2528
2479
  return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
2529
- case 4:
2530
- gas_4 = _a.sent();
2480
+ case 7:
2481
+ gas_4 = _c.sent();
2531
2482
  if (estimateGas) {
2532
2483
  return [2 /*return*/, gas_4.toNumber()];
2533
2484
  }
2534
- gasLimit_4 = gas_4.mul(130).div(100);
2535
- return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
2536
- case 5: return [2 /*return*/, (_a.sent()).hash];
2537
- case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
2538
- case 7:
2539
- gas = _a.sent();
2485
+ gasLimit_6 = gas_4.mul(130).div(100);
2486
+ return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_6 }))];
2487
+ case 8: return [2 /*return*/, (_c.sent()).hash];
2488
+ case 9: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
2489
+ case 10:
2490
+ gas = _c.sent();
2540
2491
  if (estimateGas) {
2541
2492
  return [2 /*return*/, gas.toNumber()];
2542
2493
  }
2543
2494
  gasLimit = gas.mul(130).div(100);
2544
2495
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
2545
- case 8: return [2 /*return*/, (_a.sent()).hash];
2496
+ case 11: return [2 /*return*/, (_c.sent()).hash];
2546
2497
  }
2547
2498
  });
2548
2499
  });
@@ -2582,11 +2533,12 @@ var Pool = /** @class */ (function () {
2582
2533
  });
2583
2534
  };
2584
2535
  this._getExchangeOutput = function (i, j, _amount) { return __awaiter(_this, void 0, void 0, function () {
2585
- var contract;
2536
+ var contractAddress, contract;
2586
2537
  return __generator(this, function (_a) {
2587
2538
  switch (_a.label) {
2588
2539
  case 0:
2589
- contract = curve_1.curve.contracts[this.swap].contract;
2540
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
2541
+ contract = curve_1.curve.contracts[contractAddress].contract;
2590
2542
  if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
2591
2543
  return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
2592
2544
  case 1: return [2 /*return*/, _a.sent()];
@@ -2617,8 +2569,9 @@ var Pool = /** @class */ (function () {
2617
2569
  this.decimals = poolData.decimals;
2618
2570
  this.useLending = poolData.use_lending;
2619
2571
  this.isMeta = poolData.is_meta || false;
2620
- this.basePool = poolData.base_pool || '';
2572
+ this.isCrypto = poolData.is_crypto || false;
2621
2573
  this.isFactory = poolData.is_factory || false;
2574
+ this.basePool = poolData.base_pool || '';
2622
2575
  this.estimateGas = {
2623
2576
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2624
2577
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2638,8 +2591,6 @@ var Pool = /** @class */ (function () {
2638
2591
  removeLiquidityOneCoinWrapped: this.removeLiquidityOneCoinWrappedEstimateGas,
2639
2592
  exchangeApprove: this.exchangeApproveEstimateGas,
2640
2593
  exchange: this.exchangeEstimateGas,
2641
- exchangeTricryptoApprove: this.exchangeTricryptoApproveEstimateGas,
2642
- exchangeTricrypto: this.exchangeTricryptoEstimateGas,
2643
2594
  exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
2644
2595
  exchangeWrapped: this.exchangeWrappedEstimateGas,
2645
2596
  };
@@ -2654,71 +2605,135 @@ var Pool = /** @class */ (function () {
2654
2605
  }());
2655
2606
  exports.Pool = Pool;
2656
2607
  // --------- Exchange Using All Pools ---------
2657
- var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
2658
- var tricryptoCoins, tricrypto2, output, _a, inputCoinDecimals, outputCoinDecimals, addressProviderContract, registryExchangeAddress, registryExchangeContract, _amount, _c, poolAddress, _output;
2659
- return __generator(this, function (_d) {
2660
- switch (_d.label) {
2608
+ var _estimatedGasForPoolsCache = {};
2609
+ var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
2610
+ var registryExchangeContract, sortedCoins, gasPromises, _i, poolAddresses_1, poolAddress, key, gasPromise, _gasAmounts_1, err_1;
2611
+ var _a;
2612
+ return __generator(this, function (_c) {
2613
+ switch (_c.label) {
2661
2614
  case 0:
2662
- tricryptoCoins = [coins_1.COINS.usdt.toLowerCase(), coins_1.COINS.wbtc.toLowerCase(), coins_1.COINS.weth.toLowerCase()];
2663
- if (!(tricryptoCoins.includes(inputCoinAddress.toLowerCase()) && tricryptoCoins.includes(outputCoinAddress.toLowerCase()))) return [3 /*break*/, 2];
2664
- tricrypto2 = new Pool("tricrypto2");
2665
- return [4 /*yield*/, tricrypto2.exchangeExpected(inputCoinAddress, outputCoinAddress, amount)];
2615
+ registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2616
+ sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
2617
+ gasPromises = [];
2618
+ for (_i = 0, poolAddresses_1 = poolAddresses; _i < poolAddresses_1.length; _i++) {
2619
+ poolAddress = poolAddresses_1[_i];
2620
+ key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
2621
+ gasPromise = void 0;
2622
+ if ((((_a = _estimatedGasForPoolsCache[key]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 3600000 < Date.now()) {
2623
+ gasPromise = registryExchangeContract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, 0, curve_1.curve.constantOptions);
2624
+ }
2625
+ else {
2626
+ gasPromise = Promise.resolve(_estimatedGasForPoolsCache[key].gas);
2627
+ }
2628
+ gasPromises.push(gasPromise);
2629
+ }
2630
+ _c.label = 1;
2666
2631
  case 1:
2667
- output = _d.sent();
2668
- return [2 /*return*/, { poolAddress: tricrypto2.swap, output: output }];
2632
+ _c.trys.push([1, 3, , 4]);
2633
+ return [4 /*yield*/, Promise.all(gasPromises)];
2669
2634
  case 2:
2670
- _a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
2671
- addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
2672
- return [4 /*yield*/, addressProviderContract.get_address(2, curve_1.curve.constantOptions)];
2635
+ _gasAmounts_1 = _c.sent();
2636
+ poolAddresses.forEach(function (poolAddress, i) {
2637
+ var key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
2638
+ _estimatedGasForPoolsCache[key] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
2639
+ });
2640
+ return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(ethers_1.ethers.utils.formatUnits(_g, 0)); })];
2673
2641
  case 3:
2674
- registryExchangeAddress = _d.sent();
2675
- registryExchangeContract = new ethers_1.ethers.Contract(registryExchangeAddress, registry_exchange_json_1.default, curve_1.curve.signer || curve_1.curve.provider);
2676
- _amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
2677
- return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
2678
- case 4:
2679
- _c = _d.sent(), poolAddress = _c[0], _output = _c[1];
2680
- return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
2642
+ err_1 = _c.sent();
2643
+ return [2 /*return*/, poolAddresses.map(function () { return 0; })];
2644
+ case 4: return [2 /*return*/];
2681
2645
  }
2682
2646
  });
2683
2647
  }); };
2684
- exports._getBestPoolAndOutput = _getBestPoolAndOutput;
2685
- var _getExchangeData = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2686
- var _a, inputCoinAddress, outputCoinAddress, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, isUnderlying, i, j;
2648
+ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
2649
+ var availablePools, _a, inputCoinDecimals, outputCoinDecimals, _amount, poolAddress, registryExchangeContract, _output, registryExchangeMulticall, calls, _i, availablePools_1, pool, _c, _expectedAmounts, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd, bestPool;
2687
2650
  return __generator(this, function (_d) {
2688
2651
  switch (_d.label) {
2689
2652
  case 0:
2690
- _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2691
- addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
2692
- return [4 /*yield*/, addressProviderContract.get_registry()];
2653
+ availablePools = Object.entries(abis_ethereum_1.poolsData).map(function (pool) {
2654
+ var _a;
2655
+ var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
2656
+ var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
2657
+ var meta_coin_addresses = (_a = pool[1].meta_coin_addresses) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a.toLowerCase(); });
2658
+ var inputCoinIndexes = [
2659
+ coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
2660
+ underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
2661
+ meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
2662
+ ];
2663
+ var outputCoinIndexes = [
2664
+ coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
2665
+ underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
2666
+ meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
2667
+ ];
2668
+ if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
2669
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2670
+ }
2671
+ else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
2672
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2673
+ }
2674
+ else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0] !== 'eurtusd') {
2675
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2676
+ }
2677
+ else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0] !== 'eurtusd') {
2678
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2679
+ }
2680
+ else {
2681
+ return null;
2682
+ }
2683
+ }).filter(function (pool) { return pool !== null; });
2684
+ _a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
2685
+ _amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
2686
+ if (availablePools.length === 0) {
2687
+ return [2 /*return*/, { poolAddress: "0x0000000000000000000000000000000000000000", _output: ethers_1.ethers.BigNumber.from(0) }];
2688
+ }
2689
+ if (!(availablePools.length === 1)) return [3 /*break*/, 2];
2690
+ poolAddress = availablePools[0].poolAddress;
2691
+ registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2692
+ return [4 /*yield*/, registryExchangeContract.get_exchange_amount(poolAddress, inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
2693
2693
  case 1:
2694
- registryAddress = _d.sent();
2695
- registryContract = new ethers_1.ethers.Contract(registryAddress, registry_json_1.default, curve_1.curve.signer);
2696
- return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, amount)];
2694
+ _output = _d.sent();
2695
+ return [2 /*return*/, { poolAddress: poolAddress, _output: _output }];
2697
2696
  case 2:
2698
- poolAddress = (_d.sent()).poolAddress;
2699
- if (poolAddress === "0x0000000000000000000000000000000000000000") {
2700
- throw new Error("This pair can't be exchanged");
2701
- }
2702
- poolName = (0, utils_1.getPoolNameBySwapAddress)(poolAddress);
2703
- return [4 /*yield*/, registryContract.get_coin_indices(poolAddress, inputCoinAddress, outputCoinAddress)];
2697
+ registryExchangeMulticall = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].multicallContract;
2698
+ calls = [];
2699
+ for (_i = 0, availablePools_1 = availablePools; _i < availablePools_1.length; _i++) {
2700
+ pool = availablePools_1[_i];
2701
+ calls.push(registryExchangeMulticall.get_exchange_amount(pool.poolAddress, inputCoinAddress, outputCoinAddress, _amount));
2702
+ }
2703
+ return [4 /*yield*/, Promise.all([
2704
+ curve_1.curve.multicallProvider.all(calls),
2705
+ _estimateGasForPools(availablePools.map(function (pool) { return pool.poolAddress; }), inputCoinAddress, outputCoinAddress, _amount),
2706
+ (0, utils_1._getUsdRate)(outputCoinAddress),
2707
+ axios_1.default.get("https://api.curve.fi/api/getGas"),
2708
+ (0, utils_1._getUsdRate)(coins_1.COINS.eth),
2709
+ ])];
2704
2710
  case 3:
2705
- _c = _d.sent(), _i = _c[0], _j = _c[1], isUnderlying = _c[2];
2706
- i = Number(_i.toString());
2707
- j = Number(_j.toString());
2708
- return [2 /*return*/, [poolName, i, j, isUnderlying]];
2711
+ _c = _d.sent(), _expectedAmounts = _c[0], gasAmounts = _c[1], outputCoinUsdRate = _c[2], gasData = _c[3], ethUsdRate = _c[4];
2712
+ gasPrice = gasData.data.data.gas.standard;
2713
+ expectedAmounts = _expectedAmounts.map(function (_amount) { return Number(ethers_1.ethers.utils.formatUnits(_amount, outputCoinDecimals)); });
2714
+ expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
2715
+ txCostsUsd = gasAmounts.map(function (a) { return ethUsdRate * a * gasPrice / 1e18; });
2716
+ availablePools.forEach(function (pool, i) {
2717
+ pool._output = _expectedAmounts[i];
2718
+ pool.outputUsd = expectedAmountsUsd[i];
2719
+ pool.txCostUsd = txCostsUsd[i];
2720
+ });
2721
+ bestPool = availablePools.reduce(function (pool1, pool2) { return (pool1.outputUsd - pool1.txCostUsd) - (pool2.outputUsd - pool2.txCostUsd) >= 0 ? pool1 : pool2; });
2722
+ return [2 /*return*/, { poolAddress: bestPool.poolAddress, _output: bestPool._output }];
2709
2723
  }
2710
2724
  });
2711
2725
  }); };
2712
2726
  var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2713
- var _a, inputCoinAddress, outputCoinAddress, _c, poolAddress, output;
2727
+ var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolAddress, _output;
2714
2728
  return __generator(this, function (_d) {
2715
2729
  switch (_d.label) {
2716
2730
  case 0:
2717
2731
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2718
- return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, amount)];
2732
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(outputCoinAddress)[0];
2733
+ return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2719
2734
  case 1:
2720
- _c = _d.sent(), poolAddress = _c.poolAddress, output = _c.output;
2721
- return [2 /*return*/, { poolAddress: poolAddress, output: output }];
2735
+ _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2736
+ return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
2722
2737
  }
2723
2738
  });
2724
2739
  }); };
@@ -2733,40 +2748,28 @@ var exchangeExpected = function (inputCoin, outputCoin, amount) { return __await
2733
2748
  }); };
2734
2749
  exports.exchangeExpected = exchangeExpected;
2735
2750
  var exchangeIsApproved = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2736
- var poolAddress;
2737
2751
  return __generator(this, function (_a) {
2738
2752
  switch (_a.label) {
2739
- case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2740
- case 1:
2741
- poolAddress = (_a.sent()).poolAddress;
2742
- return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, poolAddress)];
2743
- case 2: return [2 /*return*/, _a.sent()];
2753
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.registry_exchange)];
2754
+ case 1: return [2 /*return*/, _a.sent()];
2744
2755
  }
2745
2756
  });
2746
2757
  }); };
2747
2758
  exports.exchangeIsApproved = exchangeIsApproved;
2748
2759
  var exchangeApproveEstimateGas = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2749
- var poolAddress;
2750
2760
  return __generator(this, function (_a) {
2751
2761
  switch (_a.label) {
2752
- case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2753
- case 1:
2754
- poolAddress = (_a.sent()).poolAddress;
2755
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], poolAddress)];
2756
- case 2: return [2 /*return*/, _a.sent()];
2762
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2763
+ case 1: return [2 /*return*/, _a.sent()];
2757
2764
  }
2758
2765
  });
2759
2766
  }); };
2760
2767
  exports.exchangeApproveEstimateGas = exchangeApproveEstimateGas;
2761
2768
  var exchangeApprove = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2762
- var poolAddress;
2763
2769
  return __generator(this, function (_a) {
2764
2770
  switch (_a.label) {
2765
- case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2766
- case 1:
2767
- poolAddress = (_a.sent()).poolAddress;
2768
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], poolAddress)];
2769
- case 2: return [2 /*return*/, _a.sent()];
2771
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2772
+ case 1: return [2 /*return*/, _a.sent()];
2770
2773
  }
2771
2774
  });
2772
2775
  }); };
@@ -2774,22 +2777,28 @@ exports.exchangeApprove = exchangeApprove;
2774
2777
  var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
2775
2778
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2776
2779
  return __awaiter(void 0, void 0, void 0, function () {
2777
- var _a, poolName, i, j, isUnderlying, pool;
2778
- return __generator(this, function (_c) {
2779
- switch (_c.label) {
2780
- case 0: return [4 /*yield*/, _getExchangeData(inputCoin, outputCoin, amount)];
2780
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
2781
+ return __generator(this, function (_e) {
2782
+ switch (_e.label) {
2783
+ case 0:
2784
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2785
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2786
+ return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2781
2787
  case 1:
2782
- _a = _c.sent(), poolName = _a[0], i = _a[1], j = _a[2], isUnderlying = _a[3];
2783
- pool = new Pool(poolName);
2784
- if (!(poolName === "tricrypto2")) return [3 /*break*/, 3];
2785
- return [4 /*yield*/, pool.estimateGas.exchangeTricrypto(i, j, amount, maxSlippage)];
2786
- case 2: return [2 /*return*/, _c.sent()];
2787
- case 3:
2788
- if (!isUnderlying) return [3 /*break*/, 5];
2789
- return [4 /*yield*/, pool.estimateGas.exchange(i, j, amount, maxSlippage)];
2790
- case 4: return [2 /*return*/, _c.sent()];
2791
- case 5: return [4 /*yield*/, pool.estimateGas.exchangeWrapped(i, j, amount, maxSlippage)];
2792
- case 6: return [2 /*return*/, _c.sent()];
2788
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
2789
+ if (poolAddress === "0x0000000000000000000000000000000000000000") {
2790
+ throw new Error("This pair can't be exchanged");
2791
+ }
2792
+ _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2793
+ minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
2794
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2795
+ contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2796
+ value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2797
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
2798
+ case 2:
2799
+ _e.sent();
2800
+ return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2801
+ case 3: return [2 /*return*/, (_e.sent()).toNumber()];
2793
2802
  }
2794
2803
  });
2795
2804
  });
@@ -2798,22 +2807,34 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
2798
2807
  var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2799
2808
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2800
2809
  return __awaiter(void 0, void 0, void 0, function () {
2801
- var _a, poolName, i, j, isUnderlying, pool;
2802
- return __generator(this, function (_c) {
2803
- switch (_c.label) {
2804
- case 0: return [4 /*yield*/, _getExchangeData(inputCoin, outputCoin, amount)];
2810
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
2811
+ return __generator(this, function (_e) {
2812
+ switch (_e.label) {
2813
+ case 0:
2814
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2815
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2816
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2805
2817
  case 1:
2806
- _a = _c.sent(), poolName = _a[0], i = _a[1], j = _a[2], isUnderlying = _a[3];
2807
- pool = new Pool(poolName);
2808
- if (!(poolName === "tricrypto2")) return [3 /*break*/, 3];
2809
- return [4 /*yield*/, pool.exchangeTricrypto(i, j, amount, maxSlippage)];
2810
- case 2: return [2 /*return*/, _c.sent()];
2818
+ _e.sent();
2819
+ return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2820
+ case 2:
2821
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
2822
+ if (poolAddress === "0x0000000000000000000000000000000000000000") {
2823
+ throw new Error("This pair can't be exchanged");
2824
+ }
2825
+ _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2826
+ minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
2827
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2828
+ contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2829
+ value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2830
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
2811
2831
  case 3:
2812
- if (!isUnderlying) return [3 /*break*/, 5];
2813
- return [4 /*yield*/, pool.exchange(i, j, amount, maxSlippage)];
2814
- case 4: return [2 /*return*/, _c.sent()];
2815
- case 5: return [4 /*yield*/, pool.exchangeWrapped(i, j, amount, maxSlippage)];
2816
- case 6: return [2 /*return*/, _c.sent()];
2832
+ _e.sent();
2833
+ return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2834
+ case 4:
2835
+ gasLimit = (_e.sent()).mul(130).div(100);
2836
+ return [4 /*yield*/, contract.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
2837
+ case 5: return [2 /*return*/, (_e.sent()).hash];
2817
2838
  }
2818
2839
  });
2819
2840
  });
@@ -2827,7 +2848,7 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
2827
2848
  case 0:
2828
2849
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2829
2850
  // TODO remove it when fixed
2830
- if (inputCoinAddress === coins_1.COINS.weth || outputCoinAddress === coins_1.COINS.weth)
2851
+ if (inputCoinAddress.toLowerCase() === coins_1.COINS.weth.toLowerCase() || outputCoinAddress.toLowerCase() === coins_1.COINS.weth.toLowerCase())
2831
2852
  return [2 /*return*/, false];
2832
2853
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2833
2854
  case 1:
@@ -2952,7 +2973,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
2952
2973
  case 2:
2953
2974
  inputCoinBalance = (_e.sent())[curve_1.curve.signerAddress];
2954
2975
  if (Number(inputCoinBalance) < Number(amount)) {
2955
- throw Error("Not enough " + inputCoin + ". Actual: " + inputCoinBalance + ", required: " + amount);
2976
+ throw Error("Not enough ".concat(inputCoin, ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
2956
2977
  }
2957
2978
  return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoinAddress], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
2958
2979
  case 3:
@@ -2964,7 +2985,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
2964
2985
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2965
2986
  case 4:
2966
2987
  _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2967
- minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
2988
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
2968
2989
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2969
2990
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2970
2991
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
@@ -2993,7 +3014,7 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2993
3014
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2994
3015
  case 2:
2995
3016
  _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2996
- minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
3017
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
2997
3018
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2998
3019
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2999
3020
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];