@curvefi/api 1.18.0 → 1.20.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
@@ -81,7 +81,9 @@ var Pool = /** @class */ (function () {
81
81
  _amounts = amounts.map(function (amount, i) {
82
82
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
83
83
  });
84
- if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
84
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
85
+ this.isCryptoFactory ||
86
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
85
87
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
86
88
  case 1:
87
89
  _expected = _a.sent(); // Lending pools
@@ -192,7 +194,9 @@ var Pool = /** @class */ (function () {
192
194
  _poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
193
195
  return [3 /*break*/, 6];
194
196
  case 3:
195
- if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
197
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
198
+ this.isCryptoFactory ||
199
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
196
200
  return [4 /*yield*/, this._getRates()];
197
201
  case 4:
198
202
  _rates_1 = _a.sent();
@@ -236,7 +240,7 @@ var Pool = /** @class */ (function () {
236
240
  case 2:
237
241
  prices = _c.sent();
238
242
  totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
239
- return [2 /*return*/, String(totalLiquidity)];
243
+ return [2 /*return*/, totalLiquidity.toFixed(8)];
240
244
  }
241
245
  });
242
246
  }); };
@@ -312,6 +316,8 @@ var Pool = /** @class */ (function () {
312
316
  return [4 /*yield*/, this.getTotalLiquidity()];
313
317
  case 1:
314
318
  totalLiquidityUSD = _c.sent();
319
+ if (Number(totalLiquidityUSD) === 0)
320
+ return [2 /*return*/, ["0", "0"]];
315
321
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
316
322
  gaugeContract.inflation_rate(),
317
323
  gaugeControllerContract.gauge_relative_weight(this.gauge),
@@ -320,6 +326,8 @@ var Pool = /** @class */ (function () {
320
326
  ])];
321
327
  case 2:
322
328
  _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
329
+ if (Number(workingSupply) === 0)
330
+ return [2 /*return*/, ["0", "0"]];
323
331
  rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
324
332
  return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
325
333
  case 3:
@@ -478,7 +486,9 @@ var Pool = /** @class */ (function () {
478
486
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
479
487
  case 3: return [2 /*return*/, _d.sent()];
480
488
  case 4:
481
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
489
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
490
+ this.isCryptoFactory ||
491
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
482
492
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
483
493
  case 5: return [2 /*return*/, _d.sent()];
484
494
  case 6:
@@ -534,7 +544,9 @@ var Pool = /** @class */ (function () {
534
544
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
535
545
  case 2: return [2 /*return*/, _a.sent()];
536
546
  case 3:
537
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
547
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
548
+ this.isCryptoFactory ||
549
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
538
550
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
539
551
  case 4: return [2 /*return*/, _a.sent()];
540
552
  case 5:
@@ -713,7 +725,9 @@ var Pool = /** @class */ (function () {
713
725
  return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
714
726
  });
715
727
  contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
716
- useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'));
728
+ useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
729
+ this.isCryptoFactory ||
730
+ (curve_1.curve.chainId === 137 && this.name === 'ren'));
717
731
  if (!isUnderlying) return [3 /*break*/, 14];
718
732
  _l = (_k = ethers_1.ethers.utils).parseUnits;
719
733
  return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
@@ -884,7 +898,9 @@ var Pool = /** @class */ (function () {
884
898
  _amounts = amounts.map(function (amount, i) {
885
899
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
886
900
  });
887
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
901
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
902
+ this.isCryptoFactory ||
903
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
888
904
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
889
905
  case 3: return [2 /*return*/, _d.sent()];
890
906
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -912,7 +928,9 @@ var Pool = /** @class */ (function () {
912
928
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
913
929
  case 1:
914
930
  _a.sent();
915
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
931
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
932
+ this.isCryptoFactory ||
933
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
916
934
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
917
935
  case 2: return [2 /*return*/, _a.sent()];
918
936
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -1054,7 +1072,9 @@ var Pool = /** @class */ (function () {
1054
1072
  switch (_a.label) {
1055
1073
  case 0:
1056
1074
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1057
- if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
1075
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1076
+ this.isCryptoFactory ||
1077
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
1058
1078
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
1059
1079
  case 1:
1060
1080
  _expected = _a.sent(); // Lending pools
@@ -1131,7 +1151,9 @@ var Pool = /** @class */ (function () {
1131
1151
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
1132
1152
  case 4: return [2 /*return*/, _c.sent()];
1133
1153
  case 5:
1134
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1154
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1155
+ this.isCryptoFactory ||
1156
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1135
1157
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
1136
1158
  case 6: return [2 /*return*/, _c.sent()];
1137
1159
  case 7:
@@ -1156,7 +1178,9 @@ var Pool = /** @class */ (function () {
1156
1178
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
1157
1179
  case 2: return [2 /*return*/, _a.sent()];
1158
1180
  case 3:
1159
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1181
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1182
+ this.isCryptoFactory ||
1183
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1160
1184
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
1161
1185
  case 4: return [2 /*return*/, _a.sent()];
1162
1186
  case 5:
@@ -1200,7 +1224,9 @@ var Pool = /** @class */ (function () {
1200
1224
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
1201
1225
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
1202
1226
  }
1203
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1227
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1228
+ this.isCryptoFactory ||
1229
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1204
1230
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
1205
1231
  case 2: return [2 /*return*/, _a.sent()];
1206
1232
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -1220,7 +1246,9 @@ var Pool = /** @class */ (function () {
1220
1246
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
1221
1247
  case 1:
1222
1248
  _a.sent();
1223
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1249
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1250
+ this.isCryptoFactory ||
1251
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1224
1252
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
1225
1253
  case 2: return [2 /*return*/, _a.sent()];
1226
1254
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -1603,7 +1631,9 @@ var Pool = /** @class */ (function () {
1603
1631
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1604
1632
  case 4: return [2 /*return*/, _c.sent()];
1605
1633
  case 5:
1606
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1634
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1635
+ this.isCryptoFactory ||
1636
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1607
1637
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1608
1638
  case 6: return [2 /*return*/, _c.sent()];
1609
1639
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1627,7 +1657,9 @@ var Pool = /** @class */ (function () {
1627
1657
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1628
1658
  case 2: return [2 /*return*/, _a.sent()];
1629
1659
  case 3:
1630
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1660
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1661
+ this.isCryptoFactory ||
1662
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1631
1663
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1632
1664
  case 4: return [2 /*return*/, _a.sent()];
1633
1665
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1705,7 +1737,9 @@ var Pool = /** @class */ (function () {
1705
1737
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1706
1738
  }
1707
1739
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1708
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1740
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1741
+ this.isCryptoFactory ||
1742
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1709
1743
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1710
1744
  case 2: return [2 /*return*/, _a.sent()];
1711
1745
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1729,7 +1763,9 @@ var Pool = /** @class */ (function () {
1729
1763
  case 1:
1730
1764
  _a.sent();
1731
1765
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1732
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1766
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) ||
1767
+ this.isCryptoFactory ||
1768
+ (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1733
1769
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1734
1770
  case 2: return [2 /*return*/, _a.sent()];
1735
1771
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -2780,7 +2816,7 @@ var Pool = /** @class */ (function () {
2780
2816
  switch (_a.label) {
2781
2817
  case 0:
2782
2818
  contract = curve_1.curve.contracts[this.swap].contract;
2783
- if (!["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name)) return [3 /*break*/, 2];
2819
+ if (!(["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name) || this.isCryptoFactory)) return [3 /*break*/, 2];
2784
2820
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
2785
2821
  case 1: return [2 /*return*/, _a.sent()];
2786
2822
  case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -3479,7 +3515,7 @@ var Pool = /** @class */ (function () {
3479
3515
  }
3480
3516
  });
3481
3517
  }); };
3482
- var poolData = __assign(__assign({}, curve_1.POOLS_DATA), (curve_1.curve.constants.FACTORY_POOLS_DATA || {}))[name];
3518
+ var poolData = __assign(__assign(__assign({}, curve_1.POOLS_DATA), (curve_1.curve.constants.FACTORY_POOLS_DATA || {})), (curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA || {}))[name];
3483
3519
  this.name = name;
3484
3520
  this.referenceAsset = poolData.reference_asset;
3485
3521
  this.swap = poolData.swap_address;
@@ -3500,6 +3536,7 @@ var Pool = /** @class */ (function () {
3500
3536
  this.isFactory = poolData.is_factory || false;
3501
3537
  this.isMetaFactory = poolData.is_meta_factory || false;
3502
3538
  this.isPlainFactory = poolData.is_plain_factory || false;
3539
+ this.isCryptoFactory = poolData.is_crypto_factory || false;
3503
3540
  this.basePool = poolData.base_pool || '';
3504
3541
  this.rewardTokens = poolData.reward_tokens || [];
3505
3542
  this.estimateGas = {
@@ -3550,8 +3587,8 @@ var Pool = /** @class */ (function () {
3550
3587
  exports.Pool = Pool;
3551
3588
  // --------- Exchange Using All Pools ---------
3552
3589
  var _estimatedGasForPoolsCache = {};
3553
- var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
3554
- var registryExchangeContract, sortedCoins, gasPromises, _i, poolAddresses_1, poolAddress, key, gasPromise, _gasAmounts_1, err_1;
3590
+ var _estimateGasForPools = function (pools, inputCoinAddress, outputCoinAddress, _amount) { return __awaiter(void 0, void 0, void 0, function () {
3591
+ var registryExchangeContract, sortedCoins, gasPromises, _i, pools_1, pool, key, gasPromise, _route, _swapParams, _pools, _gasAmounts_1, err_1;
3555
3592
  var _a;
3556
3593
  return __generator(this, function (_c) {
3557
3594
  switch (_c.label) {
@@ -3559,12 +3596,15 @@ var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoin
3559
3596
  registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
3560
3597
  sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
3561
3598
  gasPromises = [];
3562
- for (_i = 0, poolAddresses_1 = poolAddresses; _i < poolAddresses_1.length; _i++) {
3563
- poolAddress = poolAddresses_1[_i];
3564
- key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
3599
+ for (_i = 0, pools_1 = pools; _i < pools_1.length; _i++) {
3600
+ pool = pools_1[_i];
3601
+ key = "".concat(pool.poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
3565
3602
  gasPromise = void 0;
3603
+ _route = [inputCoinAddress, pool.poolAddress, outputCoinAddress].concat(Array(6).fill(ethers_1.ethers.constants.AddressZero));
3604
+ _swapParams = [[pool.i, pool.j, pool.swapType]].concat(Array(3).fill([0, 0, 0]));
3605
+ _pools = [pool.swapAddress].concat(Array(3).fill(ethers_1.ethers.constants.AddressZero));
3566
3606
  if ((((_a = _estimatedGasForPoolsCache[key]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 3600000 < Date.now()) {
3567
- gasPromise = registryExchangeContract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, 0, curve_1.curve.constantOptions);
3607
+ gasPromise = registryExchangeContract.estimateGas.exchange_multiple(_route, _swapParams, _amount, 0, _pools, curve_1.curve.constantOptions);
3568
3608
  }
3569
3609
  else {
3570
3610
  gasPromise = Promise.resolve(_estimatedGasForPoolsCache[key].gas);
@@ -3577,101 +3617,168 @@ var _estimateGasForPools = function (poolAddresses, inputCoinAddress, outputCoin
3577
3617
  return [4 /*yield*/, Promise.all(gasPromises)];
3578
3618
  case 2:
3579
3619
  _gasAmounts_1 = _c.sent();
3580
- poolAddresses.forEach(function (poolAddress, i) {
3581
- var key = "".concat(poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
3620
+ pools.forEach(function (pool, i) {
3621
+ var key = "".concat(pool.poolAddress, "-").concat(sortedCoins[0], "-").concat(sortedCoins[1]);
3582
3622
  _estimatedGasForPoolsCache[key] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
3583
3623
  });
3584
3624
  return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(ethers_1.ethers.utils.formatUnits(_g, 0)); })];
3585
3625
  case 3:
3586
3626
  err_1 = _c.sent();
3587
- return [2 /*return*/, poolAddresses.map(function () { return 0; })];
3627
+ return [2 /*return*/, pools.map(function () { return 0; })];
3588
3628
  case 4: return [2 /*return*/];
3589
3629
  }
3590
3630
  });
3591
3631
  }); };
3632
+ var _getAvailablePools = function (inputCoinAddress, outputCoinAddress) {
3633
+ return Object.entries(__assign(__assign(__assign({}, curve_1.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA)).map(function (_a) {
3634
+ var _c;
3635
+ var poolName = _a[0], poolData = _a[1];
3636
+ var coin_addresses = poolData.coin_addresses.map(function (a) { return a.toLowerCase(); });
3637
+ var underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
3638
+ var meta_coin_addresses = ((_c = poolData.meta_coin_addresses) === null || _c === void 0 ? void 0 : _c.map(function (a) { return a.toLowerCase(); })) || [];
3639
+ var inputCoinIndexes = {
3640
+ coin: coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
3641
+ underlying_coin: underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
3642
+ meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
3643
+ };
3644
+ var outputCoinIndexes = {
3645
+ coin: coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
3646
+ underlying_coin: underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
3647
+ meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
3648
+ };
3649
+ // Only for underlying swaps
3650
+ var poolAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(poolName) ||
3651
+ (curve_1.curve.chainId === 137 && poolData.is_factory) ? poolData.deposit_address : poolData.swap_address;
3652
+ if (inputCoinIndexes.coin >= 0 && outputCoinIndexes.coin >= 0 && poolName !== "atricrypto3") {
3653
+ var swapType = poolData.is_crypto ? 3 : 1;
3654
+ return {
3655
+ poolName: poolName,
3656
+ poolAddress: poolData.swap_address,
3657
+ i: inputCoinIndexes.coin,
3658
+ j: outputCoinIndexes.coin,
3659
+ swapType: swapType,
3660
+ swapAddress: ethers_1.ethers.constants.AddressZero,
3661
+ };
3662
+ }
3663
+ else if (inputCoinIndexes.underlying_coin >= 0 &&
3664
+ outputCoinIndexes.underlying_coin >= 0 &&
3665
+ !(poolName === "atricrypto3" && (inputCoinIndexes.meta_coin >= 0 && outputCoinIndexes.meta_coin >= 0))) {
3666
+ var swapType = poolData.is_crypto && (poolData.is_fake || poolData.is_meta) ? 4 : poolData.is_crypto ? 3 : 2;
3667
+ return {
3668
+ poolName: poolName,
3669
+ poolAddress: poolAddress,
3670
+ i: inputCoinIndexes.underlying_coin,
3671
+ j: outputCoinIndexes.underlying_coin,
3672
+ swapType: swapType,
3673
+ swapAddress: ethers_1.ethers.constants.AddressZero,
3674
+ };
3675
+ }
3676
+ else if (inputCoinIndexes.coin === 0 && outputCoinIndexes.meta_coin >= 0 && poolName !== "atricrypto3") {
3677
+ var swapType = (curve_1.curve.chainId === 137 && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
3678
+ return {
3679
+ poolName: poolName,
3680
+ poolAddress: poolAddress,
3681
+ i: inputCoinIndexes.coin,
3682
+ j: outputCoinIndexes.meta_coin + 1,
3683
+ swapType: swapType,
3684
+ swapAddress: swapType === 5 ? poolData.swap_address : ethers_1.ethers.constants.AddressZero,
3685
+ };
3686
+ }
3687
+ else if (inputCoinIndexes.meta_coin >= 0 && outputCoinIndexes.coin === 0 && poolName !== "atricrypto3") {
3688
+ var swapType = (curve_1.curve.chainId === 137 && poolData.is_factory) ? 5 : poolData.is_crypto ? 4 : 2;
3689
+ return {
3690
+ poolName: poolName,
3691
+ poolAddress: poolAddress,
3692
+ i: inputCoinIndexes.meta_coin + 1,
3693
+ j: outputCoinIndexes.coin,
3694
+ swapType: swapType,
3695
+ swapAddress: swapType === 5 ? poolData.swap_address : ethers_1.ethers.constants.AddressZero,
3696
+ };
3697
+ }
3698
+ else {
3699
+ return null;
3700
+ }
3701
+ }).filter(function (pool) { return pool !== null; });
3702
+ };
3592
3703
  var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
3593
- 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;
3594
- return __generator(this, function (_d) {
3595
- switch (_d.label) {
3704
+ var _a, inputCoinDecimals, outputCoinDecimals, _amount, availablePoolsRaw, availablePools, _i, availablePoolsRaw_1, pool, poolName, poolAddress, i, j, swapType, swapAddress, contract, _c, _d, err_2, _e, poolName, poolAddress, i, j, swapType, _output, swapAddress, _f, gasAmounts, outputCoinUsdRate, gasData, ethUsdRate, gasPrice, expectedAmounts, expectedAmountsUsd, txCostsUsd;
3705
+ return __generator(this, function (_h) {
3706
+ switch (_h.label) {
3596
3707
  case 0:
3597
- availablePools = Object.entries(curve_1.POOLS_DATA).map(function (pool) {
3598
- var _a;
3599
- var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
3600
- var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
3601
- var meta_coin_addresses = (_a = pool[1].meta_coin_addresses) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a.toLowerCase(); });
3602
- var inputCoinIndexes = [
3603
- coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
3604
- underlying_coin_addresses.indexOf(inputCoinAddress.toLowerCase()),
3605
- meta_coin_addresses ? meta_coin_addresses.indexOf(inputCoinAddress.toLowerCase()) : -1,
3606
- ];
3607
- var outputCoinIndexes = [
3608
- coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
3609
- underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
3610
- meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
3611
- ];
3612
- if (pool[0] === 'atricrypto3') {
3613
- return null;
3614
- }
3615
- if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
3616
- return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3617
- }
3618
- else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
3619
- return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3620
- }
3621
- else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
3622
- return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3623
- }
3624
- else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
3625
- return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
3626
- }
3627
- else {
3628
- return null;
3629
- }
3630
- }).filter(function (pool) { return pool !== null; });
3631
3708
  _a = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _a[0], outputCoinDecimals = _a[1];
3632
3709
  _amount = ethers_1.ethers.utils.parseUnits(amount.toString(), inputCoinDecimals);
3633
- if (availablePools.length === 0) {
3634
- return [2 /*return*/, { poolAddress: "0x0000000000000000000000000000000000000000", _output: ethers_1.ethers.BigNumber.from(0) }];
3635
- }
3636
- if (!(availablePools.length === 1)) return [3 /*break*/, 2];
3637
- poolAddress = availablePools[0].poolAddress;
3638
- registryExchangeContract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
3639
- return [4 /*yield*/, registryExchangeContract.get_exchange_amount(poolAddress, inputCoinAddress, outputCoinAddress, _amount, curve_1.curve.constantOptions)];
3710
+ availablePoolsRaw = _getAvailablePools(inputCoinAddress, outputCoinAddress).map(function (data) { return (__assign(__assign({}, data), { _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 })); });
3711
+ availablePools = [];
3712
+ _i = 0, availablePoolsRaw_1 = availablePoolsRaw;
3713
+ _h.label = 1;
3640
3714
  case 1:
3641
- _output = _d.sent();
3642
- return [2 /*return*/, { poolAddress: poolAddress, _output: _output }];
3715
+ if (!(_i < availablePoolsRaw_1.length)) return [3 /*break*/, 9];
3716
+ pool = availablePoolsRaw_1[_i];
3717
+ poolName = pool.poolName, poolAddress = pool.poolAddress, i = pool.i, j = pool.j, swapType = pool.swapType, swapAddress = pool.swapAddress;
3718
+ contract = curve_1.curve.contracts[swapAddress === ethers_1.ethers.constants.AddressZero ? poolAddress : swapAddress].contract;
3719
+ _h.label = 2;
3643
3720
  case 2:
3644
- registryExchangeMulticall = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].multicallContract;
3645
- calls = [];
3646
- for (_i = 0, availablePools_1 = availablePools; _i < availablePools_1.length; _i++) {
3647
- pool = availablePools_1[_i];
3648
- calls.push(registryExchangeMulticall.get_exchange_amount(pool.poolAddress, inputCoinAddress, outputCoinAddress, _amount));
3721
+ _h.trys.push([2, 7, , 8]);
3722
+ _c = pool;
3723
+ if (![2, 4, 5].includes(swapType)) return [3 /*break*/, 4];
3724
+ return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
3725
+ case 3:
3726
+ _d = _h.sent();
3727
+ return [3 /*break*/, 6];
3728
+ case 4: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve_1.curve.constantOptions)];
3729
+ case 5:
3730
+ _d = _h.sent();
3731
+ _h.label = 6;
3732
+ case 6:
3733
+ _c._output = _d;
3734
+ availablePools.push(pool);
3735
+ return [3 /*break*/, 8];
3736
+ case 7:
3737
+ err_2 = _h.sent();
3738
+ console.log("Pool ".concat(poolName, " is empty or very imbalanced"));
3739
+ return [3 /*break*/, 8];
3740
+ case 8:
3741
+ _i++;
3742
+ return [3 /*break*/, 1];
3743
+ case 9:
3744
+ if (availablePools.length === 0) {
3745
+ return [2 /*return*/, {
3746
+ poolName: "",
3747
+ poolAddress: ethers_1.ethers.constants.AddressZero,
3748
+ i: 0,
3749
+ j: 0,
3750
+ swapType: 1,
3751
+ swapAddress: ethers_1.ethers.constants.AddressZero,
3752
+ _output: ethers_1.ethers.BigNumber.from(0),
3753
+ }];
3754
+ }
3755
+ if (availablePools.length === 1) {
3756
+ _e = availablePools[0], poolName = _e.poolName, poolAddress = _e.poolAddress, i = _e.i, j = _e.j, swapType = _e.swapType, _output = _e._output, swapAddress = _e.swapAddress;
3757
+ return [2 /*return*/, { poolName: poolName, poolAddress: poolAddress, i: i, j: j, swapType: swapType, _output: _output, swapAddress: swapAddress }];
3649
3758
  }
3650
3759
  return [4 /*yield*/, Promise.all([
3651
- curve_1.curve.multicallProvider.all(calls),
3652
- _estimateGasForPools(availablePools.map(function (pool) { return pool.poolAddress; }), inputCoinAddress, outputCoinAddress, _amount),
3760
+ // curve.multicallProvider.all(calls),
3761
+ _estimateGasForPools(availablePools, inputCoinAddress, outputCoinAddress, _amount),
3653
3762
  (0, utils_1._getUsdRate)(outputCoinAddress),
3654
3763
  axios_1.default.get("https://api.curve.fi/api/getGas"),
3655
- (0, utils_1._getUsdRate)(curve_1.COINS.eth),
3764
+ (0, utils_1._getUsdRate)(curve_1.curve.chainId === 137 ? curve_1.COINS.matic : curve_1.COINS.eth),
3656
3765
  ])];
3657
- case 3:
3658
- _c = _d.sent(), _expectedAmounts = _c[0], gasAmounts = _c[1], outputCoinUsdRate = _c[2], gasData = _c[3], ethUsdRate = _c[4];
3766
+ case 10:
3767
+ _f = _h.sent(), gasAmounts = _f[0], outputCoinUsdRate = _f[1], gasData = _f[2], ethUsdRate = _f[3];
3659
3768
  gasPrice = gasData.data.data.gas.standard;
3660
- expectedAmounts = _expectedAmounts.map(function (_amount) { return Number(ethers_1.ethers.utils.formatUnits(_amount, outputCoinDecimals)); });
3769
+ expectedAmounts = (availablePools).map(function (swapData) { return Number(ethers_1.ethers.utils.formatUnits(swapData._output, outputCoinDecimals)); });
3661
3770
  expectedAmountsUsd = expectedAmounts.map(function (a) { return a * outputCoinUsdRate; });
3662
3771
  txCostsUsd = gasAmounts.map(function (a) { return ethUsdRate * a * gasPrice / 1e18; });
3663
3772
  availablePools.forEach(function (pool, i) {
3664
- pool._output = _expectedAmounts[i];
3665
3773
  pool.outputUsd = expectedAmountsUsd[i];
3666
3774
  pool.txCostUsd = txCostsUsd[i];
3667
3775
  });
3668
- bestPool = availablePools.reduce(function (pool1, pool2) { return (pool1.outputUsd - pool1.txCostUsd) - (pool2.outputUsd - pool2.txCostUsd) >= 0 ? pool1 : pool2; });
3669
- return [2 /*return*/, { poolAddress: bestPool.poolAddress, _output: bestPool._output }];
3776
+ return [2 /*return*/, availablePools.reduce(function (pool1, pool2) { return (pool1.outputUsd - pool1.txCostUsd) - (pool2.outputUsd - pool2.txCostUsd) >= 0 ? pool1 : pool2; })];
3670
3777
  }
3671
3778
  });
3672
3779
  }); };
3673
3780
  var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
3674
- var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolAddress, _output;
3781
+ var _a, inputCoinAddress, outputCoinAddress, outputCoinDecimals, _c, poolName, poolAddress, _output;
3675
3782
  return __generator(this, function (_d) {
3676
3783
  switch (_d.label) {
3677
3784
  case 0:
@@ -3679,8 +3786,8 @@ var getBestPoolAndOutput = function (inputCoin, outputCoin, amount) { return __a
3679
3786
  outputCoinDecimals = (0, utils_1._getCoinDecimals)(outputCoinAddress)[0];
3680
3787
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
3681
3788
  case 1:
3682
- _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
3683
- return [2 /*return*/, { poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
3789
+ _c = _d.sent(), poolName = _c.poolName, poolAddress = _c.poolAddress, _output = _c._output;
3790
+ return [2 /*return*/, { poolName: poolName, poolAddress: poolAddress, output: ethers_1.ethers.utils.formatUnits(_output, outputCoinDecimals) }];
3684
3791
  }
3685
3792
  });
3686
3793
  }); };
@@ -3724,7 +3831,7 @@ exports.exchangeApprove = exchangeApprove;
3724
3831
  var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
3725
3832
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
3726
3833
  return __awaiter(void 0, void 0, void 0, function () {
3727
- var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
3834
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, i, j, swapType, swapAddress, _output, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
3728
3835
  return __generator(this, function (_e) {
3729
3836
  switch (_e.label) {
3730
3837
  case 0:
@@ -3732,10 +3839,13 @@ var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage)
3732
3839
  _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
3733
3840
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
3734
3841
  case 1:
3735
- _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
3842
+ _d = _e.sent(), poolAddress = _d.poolAddress, i = _d.i, j = _d.j, swapType = _d.swapType, swapAddress = _d.swapAddress, _output = _d._output;
3736
3843
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
3737
3844
  throw new Error("This pair can't be exchanged");
3738
3845
  }
3846
+ _route = [inputCoinAddress, poolAddress, outputCoinAddress].concat(Array(6).fill(ethers_1.ethers.constants.AddressZero));
3847
+ _swapParams = [[i, j, swapType]].concat(Array(3).fill([0, 0, 0]));
3848
+ _pools = [swapAddress].concat(Array(3).fill(ethers_1.ethers.constants.AddressZero));
3739
3849
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
3740
3850
  minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
3741
3851
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
@@ -3744,7 +3854,7 @@ var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage)
3744
3854
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
3745
3855
  case 2:
3746
3856
  _e.sent();
3747
- return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
3857
+ return [4 /*yield*/, contract.estimateGas.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
3748
3858
  case 3: return [2 /*return*/, (_e.sent()).toNumber()];
3749
3859
  }
3750
3860
  });
@@ -3754,7 +3864,7 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
3754
3864
  var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
3755
3865
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
3756
3866
  return __awaiter(void 0, void 0, void 0, function () {
3757
- var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
3867
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, i, j, swapType, swapAddress, _output, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
3758
3868
  return __generator(this, function (_e) {
3759
3869
  switch (_e.label) {
3760
3870
  case 0:
@@ -3765,10 +3875,13 @@ var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
3765
3875
  _e.sent();
3766
3876
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
3767
3877
  case 2:
3768
- _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
3878
+ _d = _e.sent(), poolAddress = _d.poolAddress, i = _d.i, j = _d.j, swapType = _d.swapType, swapAddress = _d.swapAddress, _output = _d._output;
3769
3879
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
3770
3880
  throw new Error("This pair can't be exchanged");
3771
3881
  }
3882
+ _route = [inputCoinAddress, poolAddress, outputCoinAddress].concat(Array(6).fill(ethers_1.ethers.constants.AddressZero));
3883
+ _swapParams = [[i, j, swapType]].concat(Array(3).fill([0, 0, 0]));
3884
+ _pools = [swapAddress].concat(Array(3).fill(ethers_1.ethers.constants.AddressZero));
3772
3885
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
3773
3886
  minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
3774
3887
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
@@ -3777,10 +3890,10 @@ var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
3777
3890
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
3778
3891
  case 3:
3779
3892
  _e.sent();
3780
- return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
3893
+ return [4 /*yield*/, contract.estimateGas.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
3781
3894
  case 4:
3782
3895
  gasLimit = (_e.sent()).mul(130).div(100);
3783
- return [4 /*yield*/, contract.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
3896
+ return [4 /*yield*/, contract.exchange_multiple(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
3784
3897
  case 5: return [2 /*return*/, (_e.sent()).hash];
3785
3898
  }
3786
3899
  });
package/lib/utils.d.ts CHANGED
@@ -29,4 +29,5 @@ export declare const _getFactoryStatsEthereum: ((statsUrl: string) => Promise<IS
29
29
  export declare const _getFactoryStatsPolygon: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
30
30
  export declare const getPoolList: () => string[];
31
31
  export declare const getFactoryPoolList: () => string[];
32
+ export declare const getCryptoFactoryPoolList: () => string[];
32
33
  export declare const getUsdRate: (coin: string) => Promise<number>;
package/lib/utils.js CHANGED
@@ -59,7 +59,7 @@ 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.getUsdRate = exports.getFactoryPoolList = exports.getPoolList = exports._getFactoryStatsPolygon = exports._getFactoryStatsEthereum = exports._getStats = exports._getStatsUrl = exports._getFactoryStatsUrl = exports._getUsdRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
62
+ exports.getUsdRate = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = exports._getFactoryStatsPolygon = exports._getFactoryStatsEthereum = exports._getStats = exports._getStatsUrl = exports._getFactoryStatsUrl = exports._getUsdRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var memoizee_1 = __importDefault(require("memoizee"));
65
65
  var ethers_1 = require("ethers");
@@ -532,6 +532,8 @@ var getPoolList = function () { return Object.keys(curve_1.POOLS_DATA); };
532
532
  exports.getPoolList = getPoolList;
533
533
  var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
534
534
  exports.getFactoryPoolList = getFactoryPoolList;
535
+ var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
536
+ exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
535
537
  var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, function () {
536
538
  var coinAddress;
537
539
  return __generator(this, function (_a) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.18.0",
3
+ "version": "1.20.1",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {