@curvefi/api 1.7.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,7 +78,7 @@ 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]);
@@ -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]);
@@ -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)];
@@ -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,7 +317,7 @@ 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:
@@ -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)];
@@ -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]);
@@ -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,7 +541,7 @@ 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:
@@ -567,7 +566,7 @@ 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:
@@ -607,7 +606,7 @@ 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
611
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
613
612
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
@@ -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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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 (['tricrypto2'].includes(this.name)) {
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,7 +998,7 @@ 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:
@@ -988,7 +1022,7 @@ 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:
@@ -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,11 +1081,11 @@ 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
1091
  if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
@@ -1069,7 +1103,7 @@ 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:
@@ -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
  });
@@ -1279,9 +1313,6 @@ var Pool = /** @class */ (function () {
1279
1313
  return __generator(this, function (_d) {
1280
1314
  switch (_d.label) {
1281
1315
  case 0:
1282
- if (this.name === 'tricrypto2') {
1283
- throw Error("Use exchangeTricryptoEstimateGas method for tricrypto2 pool instead");
1284
- }
1285
1316
  i = this._getCoinIdx(inputCoin);
1286
1317
  j = this._getCoinIdx(outputCoin);
1287
1318
  _c = (_a = Object).values;
@@ -1289,7 +1320,7 @@ var Pool = /** @class */ (function () {
1289
1320
  case 1:
1290
1321
  inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
1291
1322
  if (Number(inputCoinBalance) < Number(amount)) {
1292
- throw Error("Not enough " + this.underlyingCoins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
1323
+ throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
1293
1324
  }
1294
1325
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1295
1326
  case 2:
@@ -1304,8 +1335,11 @@ var Pool = /** @class */ (function () {
1304
1335
  contract = curve_1.curve.contracts[this.swap].contract;
1305
1336
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1306
1337
  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 }))];
1338
+ if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
1339
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1308
1340
  case 4: return [2 /*return*/, (_d.sent()).toNumber()];
1341
+ case 5: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1342
+ case 6: return [2 /*return*/, (_d.sent()).toNumber()];
1309
1343
  }
1310
1344
  });
1311
1345
  });
@@ -1313,13 +1347,10 @@ var Pool = /** @class */ (function () {
1313
1347
  this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
1314
1348
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1315
1349
  return __awaiter(_this, void 0, void 0, function () {
1316
- var i, j, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value, gasLimit;
1350
+ var i, j, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, gasLimit;
1317
1351
  return __generator(this, function (_a) {
1318
1352
  switch (_a.label) {
1319
1353
  case 0:
1320
- if (this.name === 'tricrypto2') {
1321
- throw Error("Use exchangeTricrypto method for tricrypto2 pool instead");
1322
- }
1323
1354
  i = this._getCoinIdx(inputCoin);
1324
1355
  j = this._getCoinIdx(outputCoin);
1325
1356
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
@@ -1336,135 +1367,17 @@ var Pool = /** @class */ (function () {
1336
1367
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
1337
1368
  case 3:
1338
1369
  _a.sent();
1339
- return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1370
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
1371
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1340
1372
  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 }))];
1373
+ gasLimit_1 = (_a.sent()).mul(130).div(100);
1374
+ return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_1 }))];
1343
1375
  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:
1376
+ case 6: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1377
+ case 7:
1465
1378
  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];
1379
+ return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1380
+ case 8: return [2 /*return*/, (_a.sent()).hash];
1468
1381
  }
1469
1382
  });
1470
1383
  });
@@ -1531,7 +1444,7 @@ var Pool = /** @class */ (function () {
1531
1444
  case 1:
1532
1445
  inputCoinBalance = _c.apply(_a, [_d.sent()])[i];
1533
1446
  if (Number(inputCoinBalance) < Number(amount)) {
1534
- throw Error("Not enough " + this.coins[i] + ". Actual: " + inputCoinBalance + ", required: " + amount);
1447
+ throw Error("Not enough ".concat(this.coins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
1535
1448
  }
1536
1449
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1537
1450
  case 2:
@@ -1545,8 +1458,11 @@ var Pool = /** @class */ (function () {
1545
1458
  _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1546
1459
  contract = curve_1.curve.contracts[this.swap].contract;
1547
1460
  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 }))];
1461
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 5];
1462
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1549
1463
  case 4: return [2 /*return*/, (_d.sent()).toNumber()];
1464
+ case 5: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1465
+ case 6: return [2 /*return*/, (_d.sent()).toNumber()];
1550
1466
  }
1551
1467
  });
1552
1468
  });
@@ -1554,7 +1470,7 @@ var Pool = /** @class */ (function () {
1554
1470
  this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
1555
1471
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1556
1472
  return __awaiter(_this, void 0, void 0, function () {
1557
- var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit;
1473
+ var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit_2, gasLimit;
1558
1474
  return __generator(this, function (_a) {
1559
1475
  switch (_a.label) {
1560
1476
  case 0:
@@ -1573,24 +1489,30 @@ var Pool = /** @class */ (function () {
1573
1489
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
1574
1490
  case 3:
1575
1491
  _a.sent();
1576
- return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1492
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
1493
+ return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1577
1494
  case 4:
1495
+ gasLimit_2 = (_a.sent()).mul(130).div(100);
1496
+ return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_2 }))];
1497
+ case 5: return [2 /*return*/, (_a.sent()).hash];
1498
+ case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1499
+ case 7:
1578
1500
  gasLimit = (_a.sent()).mul(130).div(100);
1579
1501
  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];
1502
+ case 8: return [2 /*return*/, (_a.sent()).hash];
1581
1503
  }
1582
1504
  });
1583
1505
  });
1584
1506
  };
1585
1507
  this.gaugeMaxBoostedDeposit = function () {
1586
1508
  var addresses = [];
1587
- for (var _a = 0; _a < arguments.length; _a++) {
1588
- addresses[_a] = arguments[_a];
1509
+ for (var _i = 0; _i < arguments.length; _i++) {
1510
+ addresses[_i] = arguments[_i];
1589
1511
  }
1590
1512
  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) {
1513
+ var votingEscrowContract, gaugeContract, contractCalls, response, _a, veTotalSupply, gaugeTotalSupply, resultBN, result, _c, _d, entry;
1514
+ return __generator(this, function (_e) {
1515
+ switch (_e.label) {
1594
1516
  case 0:
1595
1517
  if (addresses.length == 1 && Array.isArray(addresses[0]))
1596
1518
  addresses = addresses[0];
@@ -1602,15 +1524,15 @@ var Pool = /** @class */ (function () {
1602
1524
  });
1603
1525
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1604
1526
  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];
1527
+ response = (_e.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1528
+ _a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
1607
1529
  resultBN = {};
1608
1530
  addresses.forEach(function (acct, i) {
1609
1531
  resultBN[acct] = response[i].div(veTotalSupply).times(gaugeTotalSupply);
1610
1532
  });
1611
1533
  result = {};
1612
- for (_d = 0, _e = Object.entries(resultBN); _d < _e.length; _d++) {
1613
- entry = _e[_d];
1534
+ for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
1535
+ entry = _d[_c];
1614
1536
  result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
1615
1537
  }
1616
1538
  return [2 /*return*/, result];
@@ -1620,13 +1542,13 @@ var Pool = /** @class */ (function () {
1620
1542
  };
1621
1543
  this.gaugeOptimalDeposits = function () {
1622
1544
  var accounts = [];
1623
- for (var _a = 0; _a < arguments.length; _a++) {
1624
- accounts[_a] = arguments[_a];
1545
+ for (var _i = 0; _i < arguments.length; _i++) {
1546
+ accounts[_i] = arguments[_i];
1625
1547
  }
1626
1548
  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) {
1549
+ 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;
1550
+ return __generator(this, function (_j) {
1551
+ switch (_j.label) {
1630
1552
  case 0:
1631
1553
  if (accounts.length == 1 && Array.isArray(accounts[0]))
1632
1554
  accounts = accounts[0];
@@ -1639,12 +1561,12 @@ var Pool = /** @class */ (function () {
1639
1561
  });
1640
1562
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1641
1563
  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];
1564
+ response = (_j.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1565
+ _a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
1644
1566
  votingPower = {};
1645
1567
  totalBalance = (0, utils_1.BN)(0);
1646
- for (_d = 0, accounts_1 = accounts; _d < accounts_1.length; _d++) {
1647
- acct = accounts_1[_d];
1568
+ for (_c = 0, accounts_1 = accounts; _c < accounts_1.length; _c++) {
1569
+ acct = accounts_1[_c];
1648
1570
  votingPower[acct] = response[0];
1649
1571
  totalBalance = totalBalance.plus(response[1]).plus(response[2]);
1650
1572
  response.splice(0, 3);
@@ -1652,8 +1574,8 @@ var Pool = /** @class */ (function () {
1652
1574
  totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
1653
1575
  optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, (0, utils_1.BN)(0)]; }));
1654
1576
  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];
1577
+ for (_d = 0, accounts_2 = accounts; _d < accounts_2.length; _d++) {
1578
+ acct = accounts_2[_d];
1657
1579
  amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
1658
1580
  gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
1659
1581
  optimalBN[acct] = amount;
@@ -1665,16 +1587,16 @@ var Pool = /** @class */ (function () {
1665
1587
  }
1666
1588
  else {
1667
1589
  if (totalPower.lt(0)) {
1668
- for (_f = 0, accounts_3 = accounts; _f < accounts_3.length; _f++) {
1669
- acct = accounts_3[_f];
1590
+ for (_e = 0, accounts_3 = accounts; _e < accounts_3.length; _e++) {
1591
+ acct = accounts_3[_e];
1670
1592
  optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
1671
1593
  }
1672
1594
  }
1673
1595
  optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
1674
1596
  }
1675
1597
  optimal = {};
1676
- for (_g = 0, _h = Object.entries(optimalBN); _g < _h.length; _g++) {
1677
- entry = _h[_g];
1598
+ for (_f = 0, _h = Object.entries(optimalBN); _f < _h.length; _f++) {
1599
+ entry = _h[_f];
1678
1600
  optimal[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
1679
1601
  }
1680
1602
  return [2 /*return*/, optimal];
@@ -1737,7 +1659,7 @@ var Pool = /** @class */ (function () {
1737
1659
  throw Error('Index must be >= 0');
1738
1660
  }
1739
1661
  if (idx_1 > coins_N - 1) {
1740
- throw Error("Index must be < " + coins_N);
1662
+ throw Error("Index must be < ".concat(coins_N));
1741
1663
  }
1742
1664
  return idx_1;
1743
1665
  }
@@ -1747,7 +1669,7 @@ var Pool = /** @class */ (function () {
1747
1669
  _this.coinAddresses.map(function (c) { return c.toLowerCase(); });
1748
1670
  var idx = lowerCaseCoinAddresses.indexOf(coinAddress.toLowerCase());
1749
1671
  if (idx === -1) {
1750
- throw Error("There is no " + coin + " in " + _this.name + " pool");
1672
+ throw Error("There is no ".concat(coin, " in ").concat(_this.name, " pool"));
1751
1673
  }
1752
1674
  return idx;
1753
1675
  };
@@ -1792,13 +1714,13 @@ var Pool = /** @class */ (function () {
1792
1714
  }); };
1793
1715
  this._balances = function (rawCoinNames, rawCoinAddresses) {
1794
1716
  var addresses = [];
1795
- for (var _a = 2; _a < arguments.length; _a++) {
1796
- addresses[_a - 2] = arguments[_a];
1717
+ for (var _i = 2; _i < arguments.length; _i++) {
1718
+ addresses[_i - 2] = arguments[_i];
1797
1719
  }
1798
1720
  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) {
1721
+ var coinNames, coinAddresses, i, rawBalances, balances, _a, addresses_1, address, _c, coinNames_1, coinName;
1722
+ return __generator(this, function (_d) {
1723
+ switch (_d.label) {
1802
1724
  case 0:
1803
1725
  coinNames = [];
1804
1726
  coinAddresses = [];
@@ -1809,20 +1731,16 @@ var Pool = /** @class */ (function () {
1809
1731
  coinAddresses.push(rawCoinAddresses[i]);
1810
1732
  }
1811
1733
  }
1812
- if (this.name === 'tricrypto2') {
1813
- coinNames.push('ETH');
1814
- coinAddresses.push('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE');
1815
- }
1816
1734
  addresses = (0, utils_1._prepareAddresses)(addresses);
1817
1735
  return [4 /*yield*/, (0, utils_1._getBalances)(coinAddresses, addresses)];
1818
1736
  case 1:
1819
- rawBalances = _e.sent();
1737
+ rawBalances = _d.sent();
1820
1738
  balances = {};
1821
- for (_c = 0, addresses_1 = addresses; _c < addresses_1.length; _c++) {
1822
- address = addresses_1[_c];
1739
+ for (_a = 0, addresses_1 = addresses; _a < addresses_1.length; _a++) {
1740
+ address = addresses_1[_a];
1823
1741
  balances[address] = {};
1824
- for (_d = 0, coinNames_1 = coinNames; _d < coinNames_1.length; _d++) {
1825
- coinName = coinNames_1[_d];
1742
+ for (_c = 0, coinNames_1 = coinNames; _c < coinNames_1.length; _c++) {
1743
+ coinName = coinNames_1[_c];
1826
1744
  balances[address][coinName] = rawBalances[address].shift();
1827
1745
  }
1828
1746
  }
@@ -2034,7 +1952,7 @@ var Pool = /** @class */ (function () {
2034
1952
  this._addLiquidityMetaZap = function (_amounts, estimateGas) {
2035
1953
  if (estimateGas === void 0) { estimateGas = false; }
2036
1954
  return __awaiter(_this, void 0, void 0, function () {
2037
- var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_1, gas, gasLimit;
1955
+ var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_3, gas, gasLimit;
2038
1956
  return __generator(this, function (_a) {
2039
1957
  switch (_a.label) {
2040
1958
  case 0:
@@ -2056,8 +1974,8 @@ var Pool = /** @class */ (function () {
2056
1974
  if (estimateGas) {
2057
1975
  return [2 /*return*/, gas_1.toNumber()];
2058
1976
  }
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 }))];
1977
+ gasLimit_3 = gas_1.mul(130).div(100);
1978
+ return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3, value: value }))];
2061
1979
  case 5: return [2 /*return*/, (_a.sent()).hash];
2062
1980
  case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2063
1981
  case 7:
@@ -2116,21 +2034,21 @@ var Pool = /** @class */ (function () {
2116
2034
  });
2117
2035
  };
2118
2036
  this._calcExpectedAmounts = function (_lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
2119
- var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _c, coinBalancesBN_1, coinBalance;
2037
+ var coinBalancesBN, i, _balance, totalSupplyBN, _a, expectedAmountsBN, _i, coinBalancesBN_1, coinBalance;
2120
2038
  var _this = this;
2121
- return __generator(this, function (_d) {
2122
- switch (_d.label) {
2039
+ return __generator(this, function (_c) {
2040
+ switch (_c.label) {
2123
2041
  case 0:
2124
2042
  coinBalancesBN = [];
2125
2043
  i = 0;
2126
- _d.label = 1;
2044
+ _c.label = 1;
2127
2045
  case 1:
2128
2046
  if (!(i < this.coinAddresses.length)) return [3 /*break*/, 4];
2129
2047
  return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.balances(i, curve_1.curve.constantOptions)];
2130
2048
  case 2:
2131
- _balance = _d.sent();
2049
+ _balance = _c.sent();
2132
2050
  coinBalancesBN.push((0, utils_1.toBN)(_balance, this.decimals[i]));
2133
- _d.label = 3;
2051
+ _c.label = 3;
2134
2052
  case 3:
2135
2053
  i++;
2136
2054
  return [3 /*break*/, 1];
@@ -2138,10 +2056,10 @@ var Pool = /** @class */ (function () {
2138
2056
  _a = utils_1.toBN;
2139
2057
  return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
2140
2058
  case 5:
2141
- totalSupplyBN = _a.apply(void 0, [_d.sent()]);
2059
+ totalSupplyBN = _a.apply(void 0, [_c.sent()]);
2142
2060
  expectedAmountsBN = [];
2143
- for (_c = 0, coinBalancesBN_1 = coinBalancesBN; _c < coinBalancesBN_1.length; _c++) {
2144
- coinBalance = coinBalancesBN_1[_c];
2061
+ for (_i = 0, coinBalancesBN_1 = coinBalancesBN; _i < coinBalancesBN_1.length; _i++) {
2062
+ coinBalance = coinBalancesBN_1[_i];
2145
2063
  expectedAmountsBN.push(coinBalance.times((0, utils_1.toBN)(_lpTokenAmount)).div(totalSupplyBN));
2146
2064
  }
2147
2065
  return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return (0, utils_1.fromBN)(amount, _this.decimals[i]); })];
@@ -2258,7 +2176,7 @@ var Pool = /** @class */ (function () {
2258
2176
  this._removeLiquidityMetaZap = function (_lpTokenAmount, estimateGas) {
2259
2177
  if (estimateGas === void 0) { estimateGas = false; }
2260
2178
  return __awaiter(_this, void 0, void 0, function () {
2261
- var _minAmounts, contract, gas_2, gasLimit_2, gas, gasLimit;
2179
+ var _minAmounts, contract, gas_2, gasLimit_4, gas, gasLimit;
2262
2180
  return __generator(this, function (_a) {
2263
2181
  switch (_a.label) {
2264
2182
  case 0:
@@ -2278,8 +2196,8 @@ var Pool = /** @class */ (function () {
2278
2196
  if (estimateGas) {
2279
2197
  return [2 /*return*/, gas_2.toNumber()];
2280
2198
  }
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 }))];
2199
+ gasLimit_4 = gas_2.mul(130).div(100);
2200
+ return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
2283
2201
  case 5: return [2 /*return*/, (_a.sent()).hash];
2284
2202
  case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
2285
2203
  case 7:
@@ -2382,7 +2300,7 @@ var Pool = /** @class */ (function () {
2382
2300
  this._removeLiquidityImbalanceMetaZap = function (_amounts, estimateGas) {
2383
2301
  if (estimateGas === void 0) { estimateGas = false; }
2384
2302
  return __awaiter(_this, void 0, void 0, function () {
2385
- var _maxBurnAmount, contract, gas_3, gasLimit_3, gas, gasLimit;
2303
+ var _maxBurnAmount, contract, gas_3, gasLimit_5, gas, gasLimit;
2386
2304
  return __generator(this, function (_a) {
2387
2305
  switch (_a.label) {
2388
2306
  case 0: return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
@@ -2402,8 +2320,8 @@ var Pool = /** @class */ (function () {
2402
2320
  if (estimateGas) {
2403
2321
  return [2 /*return*/, gas_3.toNumber()];
2404
2322
  }
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 }))];
2323
+ gasLimit_5 = gas_3.mul(130).div(100);
2324
+ return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_5 }))];
2407
2325
  case 5: return [2 /*return*/, (_a.sent())];
2408
2326
  case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
2409
2327
  case 7:
@@ -2511,38 +2429,48 @@ var Pool = /** @class */ (function () {
2511
2429
  this._removeLiquidityOneCoinZap = function (_lpTokenAmount, i, estimateGas) {
2512
2430
  if (estimateGas === void 0) { estimateGas = false; }
2513
2431
  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) {
2432
+ var _minAmount, _a, contract, gas_4, gasLimit_6, gas, gasLimit;
2433
+ return __generator(this, function (_c) {
2434
+ switch (_c.label) {
2517
2435
  case 0:
2518
2436
  if (!!estimateGas) return [3 /*break*/, 2];
2519
2437
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
2520
2438
  case 1:
2521
- _a.sent();
2522
- _a.label = 2;
2523
- case 2: return [4 /*yield*/, this._calcWithdrawOneCoinZap(_lpTokenAmount, i)];
2439
+ _c.sent();
2440
+ _c.label = 2;
2441
+ case 2:
2442
+ if (!(this.name === 'tricrypto2')) return [3 /*break*/, 4];
2443
+ return [4 /*yield*/, this._calcWithdrawOneCoinSwap(_lpTokenAmount, i)];
2524
2444
  case 3:
2525
- _minAmount = (_a.sent()).mul(99).div(100);
2445
+ _a = _c.sent();
2446
+ return [3 /*break*/, 6];
2447
+ case 4: return [4 /*yield*/, this._calcWithdrawOneCoinZap(_lpTokenAmount, i)];
2448
+ case 5:
2449
+ _a = _c.sent();
2450
+ _c.label = 6;
2451
+ case 6:
2452
+ _minAmount = _a;
2453
+ _minAmount = _minAmount.mul(99).div(100);
2526
2454
  contract = curve_1.curve.contracts[this.zap].contract;
2527
- if (!this.isFactory) return [3 /*break*/, 6];
2455
+ if (!this.isFactory) return [3 /*break*/, 9];
2528
2456
  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();
2457
+ case 7:
2458
+ gas_4 = _c.sent();
2531
2459
  if (estimateGas) {
2532
2460
  return [2 /*return*/, gas_4.toNumber()];
2533
2461
  }
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();
2462
+ gasLimit_6 = gas_4.mul(130).div(100);
2463
+ return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_6 }))];
2464
+ case 8: return [2 /*return*/, (_c.sent()).hash];
2465
+ case 9: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
2466
+ case 10:
2467
+ gas = _c.sent();
2540
2468
  if (estimateGas) {
2541
2469
  return [2 /*return*/, gas.toNumber()];
2542
2470
  }
2543
2471
  gasLimit = gas.mul(130).div(100);
2544
2472
  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];
2473
+ case 11: return [2 /*return*/, (_c.sent()).hash];
2546
2474
  }
2547
2475
  });
2548
2476
  });
@@ -2638,8 +2566,6 @@ var Pool = /** @class */ (function () {
2638
2566
  removeLiquidityOneCoinWrapped: this.removeLiquidityOneCoinWrappedEstimateGas,
2639
2567
  exchangeApprove: this.exchangeApproveEstimateGas,
2640
2568
  exchange: this.exchangeEstimateGas,
2641
- exchangeTricryptoApprove: this.exchangeTricryptoApproveEstimateGas,
2642
- exchangeTricrypto: this.exchangeTricryptoEstimateGas,
2643
2569
  exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
2644
2570
  exchangeWrapped: this.exchangeWrappedEstimateGas,
2645
2571
  };
@@ -2654,69 +2580,135 @@ var Pool = /** @class */ (function () {
2654
2580
  }());
2655
2581
  exports.Pool = Pool;
2656
2582
  // --------- Exchange Using All Pools ---------
2657
- var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount) { return __awaiter(void 0, void 0, void 0, function () {
2658
- var tricryptoCoins, addressProviderContract, registryExchangeAddress, registryExchangeContract, _amount, _a, poolAddress, output;
2583
+ var _estimatedGasForPoolsCache = {};
2584
+ var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
2585
+ var registryExchangeContract, sortedCoins, gasPromises, _i, poolAddresses_1, poolAddress, key, gasPromise, _gasAmounts_1, err_1;
2586
+ var _a;
2659
2587
  return __generator(this, function (_c) {
2660
2588
  switch (_c.label) {
2661
2589
  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())) {
2664
- throw new Error("This pair can't be exchanged");
2590
+ registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2591
+ sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
2592
+ gasPromises = [];
2593
+ for (_i = 0, poolAddresses_1 = poolAddresses; _i < poolAddresses_1.length; _i++) {
2594
+ poolAddress = poolAddresses_1[_i];
2595
+ key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
2596
+ gasPromise = void 0;
2597
+ if ((((_a = _estimatedGasForPoolsCache[key]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 3600000 < Date.now()) {
2598
+ gasPromise = registryExchangeContract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, 0, curve_1.curve.constantOptions);
2599
+ }
2600
+ else {
2601
+ gasPromise = Promise.resolve(_estimatedGasForPoolsCache[key].gas);
2602
+ }
2603
+ gasPromises.push(gasPromise);
2665
2604
  }
2666
- addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
2667
- return [4 /*yield*/, addressProviderContract.get_address(2, curve_1.curve.constantOptions)];
2605
+ _c.label = 1;
2668
2606
  case 1:
2669
- registryExchangeAddress = _c.sent();
2670
- registryExchangeContract = new ethers_1.ethers.Contract(registryExchangeAddress, registry_exchange_json_1.default, curve_1.curve.signer || curve_1.curve.provider);
2671
- _amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
2672
- return [4 /*yield*/, registryExchangeContract.get_best_rate(inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
2607
+ _c.trys.push([1, 3, , 4]);
2608
+ return [4 /*yield*/, Promise.all(gasPromises)];
2673
2609
  case 2:
2674
- _a = _c.sent(), poolAddress = _a[0], output = _a[1];
2675
- return [2 /*return*/, { poolAddress: poolAddress, output: output }];
2610
+ _gasAmounts_1 = _c.sent();
2611
+ poolAddresses.forEach(function (poolAddress, i) {
2612
+ var key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
2613
+ _estimatedGasForPoolsCache[key] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
2614
+ });
2615
+ return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(ethers_1.ethers.utils.formatUnits(_g, 0)); })];
2616
+ case 3:
2617
+ err_1 = _c.sent();
2618
+ return [2 /*return*/, poolAddresses.map(function () { return 0; })];
2619
+ case 4: return [2 /*return*/];
2676
2620
  }
2677
2621
  });
2678
2622
  }); };
2679
- exports._getBestPoolAndOutput = _getBestPoolAndOutput;
2680
- var _getExchangeData = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2681
- var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, addressProviderContract, registryAddress, registryContract, poolAddress, poolName, _c, _i, _j, isUnderlying, i, j;
2623
+ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
2624
+ 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;
2682
2625
  return __generator(this, function (_d) {
2683
2626
  switch (_d.label) {
2684
2627
  case 0:
2685
- _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2686
- inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2687
- addressProviderContract = curve_1.curve.contracts[curve_1.ALIASES.address_provider].contract;
2688
- return [4 /*yield*/, addressProviderContract.get_registry()];
2628
+ availablePools = Object.entries(abis_ethereum_1.poolsData).map(function (pool) {
2629
+ var _a;
2630
+ var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
2631
+ var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
2632
+ var meta_coin_addresses = (_a = pool[1].meta_coin_addresses) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a.toLowerCase(); });
2633
+ var inputCoinIndexes = [
2634
+ coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
2635
+ underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
2636
+ meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
2637
+ ];
2638
+ var outputCoinIndexes = [
2639
+ coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
2640
+ underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
2641
+ meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
2642
+ ];
2643
+ if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
2644
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2645
+ }
2646
+ else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
2647
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2648
+ }
2649
+ else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0) {
2650
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2651
+ }
2652
+ else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0) {
2653
+ return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2654
+ }
2655
+ else {
2656
+ return null;
2657
+ }
2658
+ }).filter(function (pool) { return pool !== null; });
2659
+ _a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
2660
+ _amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
2661
+ if (availablePools.length === 0) {
2662
+ return [2 /*return*/, { poolAddress: "0x0000000000000000000000000000000000000000", _output: ethers_1.ethers.BigNumber.from(0) }];
2663
+ }
2664
+ if (!(availablePools.length === 1)) return [3 /*break*/, 2];
2665
+ poolAddress = availablePools[0].poolAddress;
2666
+ registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2667
+ return [4 /*yield*/, registryExchangeContract.get_exchange_amount(poolAddress, inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
2689
2668
  case 1:
2690
- registryAddress = _d.sent();
2691
- registryContract = new ethers_1.ethers.Contract(registryAddress, registry_json_1.default, curve_1.curve.signer);
2692
- return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2669
+ _output = _d.sent();
2670
+ return [2 /*return*/, { poolAddress: poolAddress, _output: _output }];
2693
2671
  case 2:
2694
- poolAddress = (_d.sent()).poolAddress;
2695
- if (poolAddress === "0x0000000000000000000000000000000000000000") {
2696
- throw new Error("This pair can't be exchanged");
2697
- }
2698
- poolName = (0, utils_1.getPoolNameBySwapAddress)(poolAddress);
2699
- return [4 /*yield*/, registryContract.get_coin_indices(poolAddress, inputCoinAddress, outputCoinAddress)];
2672
+ registryExchangeMulticall = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].multicallContract;
2673
+ calls = [];
2674
+ for (_i = 0, availablePools_1 = availablePools; _i < availablePools_1.length; _i++) {
2675
+ pool = availablePools_1[_i];
2676
+ calls.push(registryExchangeMulticall.get_exchange_amount(pool.poolAddress, inputCoinAddress, outputCoinAddress, _amount));
2677
+ }
2678
+ return [4 /*yield*/, Promise.all([
2679
+ curve_1.curve.multicallProvider.all(calls),
2680
+ _estimateGasForPools(availablePools.map(function (pool) { return pool.poolAddress; }), inputCoinAddress, outputCoinAddress, _amount),
2681
+ (0, utils_1._getUsdRate)(outputCoinAddress),
2682
+ axios_1.default.get("https://api.curve.fi/api/getGas"),
2683
+ (0, utils_1._getUsdRate)(coins_1.COINS.eth),
2684
+ ])];
2700
2685
  case 3:
2701
- _c = _d.sent(), _i = _c[0], _j = _c[1], isUnderlying = _c[2];
2702
- i = Number(_i.toString());
2703
- j = Number(_j.toString());
2704
- return [2 /*return*/, [poolName, i, j, isUnderlying]];
2686
+ _c = _d.sent(), _expectedAmounts = _c[0], gasAmounts = _c[1], outputCoinUsdRate = _c[2], gasData = _c[3], ethUsdRate = _c[4];
2687
+ gasPrice = gasData.data.data.gas.standard;
2688
+ expectedAmounts = _expectedAmounts.map(function (_amount) { return Number(ethers_1.ethers.utils.formatUnits(_amount, outputCoinDecimals)); });
2689
+ expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
2690
+ txCostsUsd = gasAmounts.map(function (a) { return ethUsdRate * a * gasPrice / 1e18; });
2691
+ availablePools.forEach(function (pool, i) {
2692
+ pool._output = _expectedAmounts[i];
2693
+ pool.outputUsd = expectedAmountsUsd[i];
2694
+ pool.txCostUsd = txCostsUsd[i];
2695
+ });
2696
+ bestPool = availablePools.reduce(function (pool1, pool2) { return (pool1.outputUsd - pool1.txCostUsd) - (pool2.outputUsd - pool2.txCostUsd) >= 0 ? pool1 : pool2; });
2697
+ return [2 /*return*/, { poolAddress: bestPool.poolAddress, _output: bestPool._output }];
2705
2698
  }
2706
2699
  });
2707
2700
  }); };
2708
2701
  var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2709
- var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, output;
2710
- return __generator(this, function (_e) {
2711
- switch (_e.label) {
2702
+ var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolAddress, _output;
2703
+ return __generator(this, function (_d) {
2704
+ switch (_d.label) {
2712
2705
  case 0:
2713
2706
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2714
- _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2715
- return [4 /*yield*/, (0, exports._getBestPoolAndOutput)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, amount)];
2707
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(outputCoinAddress)[0];
2708
+ return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2716
2709
  case 1:
2717
- _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d.output;
2718
- output = ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals);
2719
- return [2 /*return*/, { poolAddress: poolAddress, output: output }];
2710
+ _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2711
+ return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
2720
2712
  }
2721
2713
  });
2722
2714
  }); };
@@ -2731,40 +2723,28 @@ var exchangeExpected = function (inputCoin, outputCoin, amount) { return __await
2731
2723
  }); };
2732
2724
  exports.exchangeExpected = exchangeExpected;
2733
2725
  var exchangeIsApproved = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2734
- var poolAddress;
2735
2726
  return __generator(this, function (_a) {
2736
2727
  switch (_a.label) {
2737
- case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2738
- case 1:
2739
- poolAddress = (_a.sent()).poolAddress;
2740
- return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, poolAddress)];
2741
- case 2: return [2 /*return*/, _a.sent()];
2728
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.registry_exchange)];
2729
+ case 1: return [2 /*return*/, _a.sent()];
2742
2730
  }
2743
2731
  });
2744
2732
  }); };
2745
2733
  exports.exchangeIsApproved = exchangeIsApproved;
2746
2734
  var exchangeApproveEstimateGas = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2747
- var poolAddress;
2748
2735
  return __generator(this, function (_a) {
2749
2736
  switch (_a.label) {
2750
- case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2751
- case 1:
2752
- poolAddress = (_a.sent()).poolAddress;
2753
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], poolAddress)];
2754
- case 2: return [2 /*return*/, _a.sent()];
2737
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2738
+ case 1: return [2 /*return*/, _a.sent()];
2755
2739
  }
2756
2740
  });
2757
2741
  }); };
2758
2742
  exports.exchangeApproveEstimateGas = exchangeApproveEstimateGas;
2759
2743
  var exchangeApprove = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2760
- var poolAddress;
2761
2744
  return __generator(this, function (_a) {
2762
2745
  switch (_a.label) {
2763
- case 0: return [4 /*yield*/, (0, exports.getBestPoolAndOutput)(inputCoin, outputCoin, amount)];
2764
- case 1:
2765
- poolAddress = (_a.sent()).poolAddress;
2766
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], poolAddress)];
2767
- case 2: return [2 /*return*/, _a.sent()];
2746
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2747
+ case 1: return [2 /*return*/, _a.sent()];
2768
2748
  }
2769
2749
  });
2770
2750
  }); };
@@ -2772,18 +2752,27 @@ exports.exchangeApprove = exchangeApprove;
2772
2752
  var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
2773
2753
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2774
2754
  return __awaiter(void 0, void 0, void 0, function () {
2775
- var _a, poolName, i, j, isUnderlying, pool;
2776
- return __generator(this, function (_c) {
2777
- switch (_c.label) {
2778
- case 0: return [4 /*yield*/, _getExchangeData(inputCoin, outputCoin, amount)];
2755
+ var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, _c, poolAddress, _output, _amount, _minRecvAmount, contract, value;
2756
+ return __generator(this, function (_d) {
2757
+ switch (_d.label) {
2758
+ case 0:
2759
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2760
+ inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2761
+ return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2779
2762
  case 1:
2780
- _a = _c.sent(), poolName = _a[0], i = _a[1], j = _a[2], isUnderlying = _a[3];
2781
- pool = new Pool(poolName);
2782
- if (!isUnderlying) return [3 /*break*/, 3];
2783
- return [4 /*yield*/, pool.estimateGas.exchange(i, j, amount, maxSlippage)];
2784
- case 2: return [2 /*return*/, _c.sent()];
2785
- case 3: return [4 /*yield*/, pool.estimateGas.exchangeWrapped(i, j, amount, maxSlippage)];
2786
- case 4: return [2 /*return*/, _c.sent()];
2763
+ _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2764
+ if (poolAddress === "0x0000000000000000000000000000000000000000") {
2765
+ throw new Error("This pair can't be exchanged");
2766
+ }
2767
+ _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2768
+ _minRecvAmount = _output.mul((1 - maxSlippage) * 100).div(100);
2769
+ contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2770
+ value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2771
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
2772
+ case 2:
2773
+ _d.sent();
2774
+ return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2775
+ case 3: return [2 /*return*/, (_d.sent()).toNumber()];
2787
2776
  }
2788
2777
  });
2789
2778
  });
@@ -2792,18 +2781,33 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
2792
2781
  var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2793
2782
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2794
2783
  return __awaiter(void 0, void 0, void 0, function () {
2795
- var _a, poolName, i, j, isUnderlying, pool;
2796
- return __generator(this, function (_c) {
2797
- switch (_c.label) {
2798
- case 0: return [4 /*yield*/, _getExchangeData(inputCoin, outputCoin, amount)];
2784
+ var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, _c, poolAddress, _output, _amount, _minRecvAmount, contract, value, gasLimit;
2785
+ return __generator(this, function (_d) {
2786
+ switch (_d.label) {
2787
+ case 0:
2788
+ _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2789
+ inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2790
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2799
2791
  case 1:
2800
- _a = _c.sent(), poolName = _a[0], i = _a[1], j = _a[2], isUnderlying = _a[3];
2801
- pool = new Pool(poolName);
2802
- if (!isUnderlying) return [3 /*break*/, 3];
2803
- return [4 /*yield*/, pool.exchange(i, j, amount, maxSlippage)];
2804
- case 2: return [2 /*return*/, _c.sent()];
2805
- case 3: return [4 /*yield*/, pool.exchangeWrapped(i, j, amount, maxSlippage)];
2806
- case 4: return [2 /*return*/, _c.sent()];
2792
+ _d.sent();
2793
+ return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2794
+ case 2:
2795
+ _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2796
+ if (poolAddress === "0x0000000000000000000000000000000000000000") {
2797
+ throw new Error("This pair can't be exchanged");
2798
+ }
2799
+ _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2800
+ _minRecvAmount = _output.mul((1 - maxSlippage) * 100).div(100);
2801
+ contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2802
+ value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2803
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
2804
+ case 3:
2805
+ _d.sent();
2806
+ return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2807
+ case 4:
2808
+ gasLimit = (_d.sent()).mul(130).div(100);
2809
+ return [4 /*yield*/, contract.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
2810
+ case 5: return [2 /*return*/, (_d.sent()).hash];
2807
2811
  }
2808
2812
  });
2809
2813
  });
@@ -2816,6 +2820,9 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
2816
2820
  switch (_c.label) {
2817
2821
  case 0:
2818
2822
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2823
+ // TODO remove it when fixed
2824
+ if (inputCoinAddress.toLowerCase() === coins_1.COINS.weth.toLowerCase() || outputCoinAddress.toLowerCase() === coins_1.COINS.weth.toLowerCase())
2825
+ return [2 /*return*/, false];
2819
2826
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2820
2827
  case 1:
2821
2828
  routerContract = _c.sent();
@@ -2939,7 +2946,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
2939
2946
  case 2:
2940
2947
  inputCoinBalance = (_e.sent())[curve_1.curve.signerAddress];
2941
2948
  if (Number(inputCoinBalance) < Number(amount)) {
2942
- throw Error("Not enough " + inputCoin + ". Actual: " + inputCoinBalance + ", required: " + amount);
2949
+ throw Error("Not enough ".concat(inputCoin, ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
2943
2950
  }
2944
2951
  return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoinAddress], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
2945
2952
  case 3: