@curvefi/api 1.9.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,7 +43,8 @@ exports.LINK_COINS = {
43
43
  exports.LINK_COINS_LOWER_CASE = Object.fromEntries(Object.entries(exports.LINK_COINS).map(function (entry) { return [entry[0], entry[1].toLowerCase()]; }));
44
44
  exports.EUR_COINS = {
45
45
  eurs: "0xdB25f211AB05b1c97D595516F45794528a807ad8",
46
- seur: "0xD71eCFF9342A5Ced620049e616c5035F1dB98620", // sEUR
46
+ seur: "0xD71eCFF9342A5Ced620049e616c5035F1dB98620",
47
+ eurt: "0xC581b735A1688071A1746c968e0798D642EDE491", // EURT
47
48
  };
48
49
  exports.USD_COINS = {
49
50
  ycdai: "0x99d1Fa417f94dcD62BfE781a1213c092a47041Bc",
@@ -112,6 +113,7 @@ exports.DECIMALS = {
112
113
  "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": 18,
113
114
  "0xdB25f211AB05b1c97D595516F45794528a807ad8": 2,
114
115
  "0xD71eCFF9342A5Ced620049e616c5035F1dB98620": 18,
116
+ "0xC581b735A1688071A1746c968e0798D642EDE491": 6,
115
117
  "0x514910771AF9Ca656af840dff83E8264EcF986CA": 18,
116
118
  "0xbBC455cb4F1B9e4bFC4B73970d360c8f032EfEE6": 18,
117
119
  "0x028171bCA77440897B824Ca71D1c56caC55b68A3": 18,
@@ -26,6 +26,7 @@ export interface PoolDataInterface {
26
26
  deposit_abi?: any;
27
27
  old_swap_abi?: any;
28
28
  is_meta?: boolean;
29
+ is_crypto?: boolean;
29
30
  meta_N?: number;
30
31
  meta_decimals?: number[];
31
32
  meta_coin_decimals?: number[];
package/lib/pools.d.ts CHANGED
@@ -15,6 +15,7 @@ export declare class Pool {
15
15
  decimals: number[];
16
16
  useLending: boolean[];
17
17
  isMeta: boolean;
18
+ isCrypto: boolean;
18
19
  basePool: string;
19
20
  isFactory: boolean;
20
21
  estimateGas: {
package/lib/pools.js CHANGED
@@ -83,7 +83,7 @@ var Pool = /** @class */ (function () {
83
83
  _amounts = amounts.map(function (amount, i) {
84
84
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
85
85
  });
86
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
86
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 2];
87
87
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
88
88
  case 1:
89
89
  _expected = _a.sent(); // Lending pools
@@ -158,7 +158,7 @@ var Pool = /** @class */ (function () {
158
158
  _poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true);
159
159
  return [3 /*break*/, 6];
160
160
  case 3:
161
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
161
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
162
162
  return [4 /*yield*/, this._getRates()];
163
163
  case 4:
164
164
  _rates_1 = _a.sent();
@@ -273,7 +273,7 @@ var Pool = /** @class */ (function () {
273
273
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
274
274
  case 3: return [2 /*return*/, _d.sent()];
275
275
  case 4:
276
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 6];
276
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 6];
277
277
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
278
278
  case 5: return [2 /*return*/, _d.sent()];
279
279
  case 6:
@@ -321,7 +321,7 @@ var Pool = /** @class */ (function () {
321
321
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
322
322
  case 2: return [2 /*return*/, _a.sent()];
323
323
  case 3:
324
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
324
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
325
325
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
326
326
  case 4: return [2 /*return*/, _a.sent()];
327
327
  case 5:
@@ -426,7 +426,7 @@ var Pool = /** @class */ (function () {
426
426
  _amounts = amounts.map(function (amount, i) {
427
427
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
428
428
  });
429
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
429
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 4];
430
430
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
431
431
  case 3: return [2 /*return*/, _d.sent()];
432
432
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -451,7 +451,7 @@ var Pool = /** @class */ (function () {
451
451
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
452
452
  case 1:
453
453
  _a.sent();
454
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
454
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
455
455
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
456
456
  case 2: return [2 /*return*/, _a.sent()];
457
457
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -468,7 +468,7 @@ var Pool = /** @class */ (function () {
468
468
  switch (_a.label) {
469
469
  case 0:
470
470
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
471
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
471
+ if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 2];
472
472
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
473
473
  case 1:
474
474
  _expected = _a.sent(); // Lending pools
@@ -545,7 +545,7 @@ var Pool = /** @class */ (function () {
545
545
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
546
546
  case 4: return [2 /*return*/, _c.sent()];
547
547
  case 5:
548
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
548
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 7];
549
549
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
550
550
  case 6: return [2 /*return*/, _c.sent()];
551
551
  case 7:
@@ -570,7 +570,7 @@ var Pool = /** @class */ (function () {
570
570
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
571
571
  case 2: return [2 /*return*/, _a.sent()];
572
572
  case 3:
573
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
573
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
574
574
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
575
575
  case 4: return [2 /*return*/, _a.sent()];
576
576
  case 5:
@@ -608,7 +608,7 @@ var Pool = /** @class */ (function () {
608
608
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
609
609
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
610
610
  }
611
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
611
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
612
612
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
613
613
  case 2: return [2 /*return*/, _a.sent()];
614
614
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -625,7 +625,7 @@ var Pool = /** @class */ (function () {
625
625
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
626
626
  case 1:
627
627
  _a.sent();
628
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
628
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
629
629
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
630
630
  case 2: return [2 /*return*/, _a.sent()];
631
631
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -638,7 +638,7 @@ var Pool = /** @class */ (function () {
638
638
  return __generator(this, function (_a) {
639
639
  switch (_a.label) {
640
640
  case 0:
641
- if (['tricrypto2'].includes(this.name)) {
641
+ if (this.isCrypto) {
642
642
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
643
643
  }
644
644
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
@@ -652,7 +652,7 @@ var Pool = /** @class */ (function () {
652
652
  return __generator(this, function (_c) {
653
653
  switch (_c.label) {
654
654
  case 0:
655
- if (['tricrypto2'].includes(this.name)) {
655
+ if (this.isCrypto) {
656
656
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
657
657
  }
658
658
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
@@ -671,7 +671,7 @@ var Pool = /** @class */ (function () {
671
671
  return __generator(this, function (_a) {
672
672
  switch (_a.label) {
673
673
  case 0:
674
- if (['tricrypto2'].includes(this.name)) {
674
+ if (this.isCrypto) {
675
675
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
676
676
  }
677
677
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -698,7 +698,7 @@ var Pool = /** @class */ (function () {
698
698
  return __generator(this, function (_a) {
699
699
  switch (_a.label) {
700
700
  case 0:
701
- if (['tricrypto2'].includes(this.name)) {
701
+ if (this.isCrypto) {
702
702
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
703
703
  }
704
704
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -725,7 +725,7 @@ var Pool = /** @class */ (function () {
725
725
  return __generator(this, function (_a) {
726
726
  switch (_a.label) {
727
727
  case 0:
728
- if (['tricrypto2'].includes(this.name)) {
728
+ if (this.isCrypto) {
729
729
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
730
730
  }
731
731
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -752,7 +752,7 @@ var Pool = /** @class */ (function () {
752
752
  return __generator(this, function (_c) {
753
753
  switch (_c.label) {
754
754
  case 0:
755
- if (['tricrypto2'].includes(this.name)) {
755
+ if (this.isCrypto) {
756
756
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
757
757
  }
758
758
  return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
@@ -797,7 +797,7 @@ var Pool = /** @class */ (function () {
797
797
  return __generator(this, function (_a) {
798
798
  switch (_a.label) {
799
799
  case 0:
800
- if (['tricrypto2'].includes(this.name)) {
800
+ if (this.isCrypto) {
801
801
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
802
802
  }
803
803
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -825,7 +825,7 @@ var Pool = /** @class */ (function () {
825
825
  return __generator(this, function (_a) {
826
826
  switch (_a.label) {
827
827
  case 0:
828
- if (['tricrypto2'].includes(this.name)) {
828
+ if (this.isCrypto) {
829
829
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
830
830
  }
831
831
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
@@ -839,7 +839,7 @@ var Pool = /** @class */ (function () {
839
839
  return __generator(this, function (_c) {
840
840
  switch (_c.label) {
841
841
  case 0:
842
- if (['tricrypto2'].includes(this.name)) {
842
+ if (this.isCrypto) {
843
843
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
844
844
  }
845
845
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
@@ -858,7 +858,7 @@ var Pool = /** @class */ (function () {
858
858
  return __generator(this, function (_a) {
859
859
  switch (_a.label) {
860
860
  case 0:
861
- if (['tricrypto2'].includes(this.name)) {
861
+ if (this.isCrypto) {
862
862
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
863
863
  }
864
864
  return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
@@ -887,7 +887,7 @@ var Pool = /** @class */ (function () {
887
887
  return __generator(this, function (_a) {
888
888
  switch (_a.label) {
889
889
  case 0:
890
- if (['tricrypto2'].includes(this.name)) {
890
+ if (this.isCrypto) {
891
891
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
892
892
  }
893
893
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
@@ -1002,7 +1002,7 @@ var Pool = /** @class */ (function () {
1002
1002
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1003
1003
  case 4: return [2 /*return*/, _c.sent()];
1004
1004
  case 5:
1005
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
1005
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 7];
1006
1006
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1007
1007
  case 6: return [2 /*return*/, _c.sent()];
1008
1008
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1026,7 +1026,7 @@ var Pool = /** @class */ (function () {
1026
1026
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1027
1027
  case 2: return [2 /*return*/, _a.sent()];
1028
1028
  case 3:
1029
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
1029
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 5];
1030
1030
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1031
1031
  case 4: return [2 /*return*/, _a.sent()];
1032
1032
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1088,7 +1088,7 @@ var Pool = /** @class */ (function () {
1088
1088
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1089
1089
  }
1090
1090
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1091
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1091
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
1092
1092
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1093
1093
  case 2: return [2 /*return*/, _a.sent()];
1094
1094
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1109,7 +1109,7 @@ var Pool = /** @class */ (function () {
1109
1109
  case 1:
1110
1110
  _a.sent();
1111
1111
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1112
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1112
+ if (!['aave', 'saave', 'ib', 'crveth'].includes(this.name)) return [3 /*break*/, 3];
1113
1113
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1114
1114
  case 2: return [2 /*return*/, _a.sent()];
1115
1115
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1274,34 +1274,37 @@ var Pool = /** @class */ (function () {
1274
1274
  });
1275
1275
  }); };
1276
1276
  this.exchangeIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1277
- var i;
1277
+ var contractAddress, i;
1278
1278
  return __generator(this, function (_a) {
1279
1279
  switch (_a.label) {
1280
1280
  case 0:
1281
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1281
1282
  i = this._getCoinIdx(inputCoin);
1282
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1283
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1283
1284
  case 1: return [2 /*return*/, _a.sent()];
1284
1285
  }
1285
1286
  });
1286
1287
  }); };
1287
1288
  this.exchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1288
- var i;
1289
+ var contractAddress, i;
1289
1290
  return __generator(this, function (_a) {
1290
1291
  switch (_a.label) {
1291
1292
  case 0:
1293
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1292
1294
  i = this._getCoinIdx(inputCoin);
1293
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1295
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1294
1296
  case 1: return [2 /*return*/, _a.sent()];
1295
1297
  }
1296
1298
  });
1297
1299
  }); };
1298
1300
  this.exchangeApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1299
- var i;
1301
+ var contractAddress, i;
1300
1302
  return __generator(this, function (_a) {
1301
1303
  switch (_a.label) {
1302
1304
  case 0:
1305
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1303
1306
  i = this._getCoinIdx(inputCoin);
1304
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1307
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1305
1308
  case 1: return [2 /*return*/, _a.sent()];
1306
1309
  }
1307
1310
  });
@@ -1309,7 +1312,7 @@ var Pool = /** @class */ (function () {
1309
1312
  this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
1310
1313
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1311
1314
  return __awaiter(_this, void 0, void 0, function () {
1312
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
1315
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contractAddress, contract, exchangeMethod, value;
1313
1316
  return __generator(this, function (_d) {
1314
1317
  switch (_d.label) {
1315
1318
  case 0:
@@ -1331,8 +1334,11 @@ var Pool = /** @class */ (function () {
1331
1334
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1332
1335
  case 3:
1333
1336
  _expected = _d.sent();
1334
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1335
- contract = curve_1.curve.contracts[this.swap].contract;
1337
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
1338
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1339
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1340
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1341
+ contract = curve_1.curve.contracts[contractAddress].contract;
1336
1342
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1337
1343
  value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1338
1344
  if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
@@ -1347,7 +1353,7 @@ var Pool = /** @class */ (function () {
1347
1353
  this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
1348
1354
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1349
1355
  return __awaiter(_this, void 0, void 0, function () {
1350
- var i, j, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, gasLimit;
1356
+ var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contractAddress, contract, exchangeMethod, value, gasLimit_1, gasLimit;
1351
1357
  return __generator(this, function (_a) {
1352
1358
  switch (_a.label) {
1353
1359
  case 0:
@@ -1357,11 +1363,14 @@ var Pool = /** @class */ (function () {
1357
1363
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1358
1364
  case 1:
1359
1365
  _expected = _a.sent();
1360
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1366
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
1367
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1368
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1361
1369
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
1362
1370
  case 2:
1363
1371
  _a.sent();
1364
- contract = curve_1.curve.contracts[this.swap].contract;
1372
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
1373
+ contract = curve_1.curve.contracts[contractAddress].contract;
1365
1374
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1366
1375
  value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1367
1376
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
@@ -1433,7 +1442,7 @@ var Pool = /** @class */ (function () {
1433
1442
  this.exchangeWrappedEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
1434
1443
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1435
1444
  return __awaiter(_this, void 0, void 0, function () {
1436
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
1445
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value;
1437
1446
  return __generator(this, function (_d) {
1438
1447
  switch (_d.label) {
1439
1448
  case 0:
@@ -1455,7 +1464,9 @@ var Pool = /** @class */ (function () {
1455
1464
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
1456
1465
  case 3:
1457
1466
  _expected = _d.sent();
1458
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1467
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
1468
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1469
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1459
1470
  contract = curve_1.curve.contracts[this.swap].contract;
1460
1471
  value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1461
1472
  if (!(this.name === 'tricrypto2')) return [3 /*break*/, 5];
@@ -1470,7 +1481,7 @@ var Pool = /** @class */ (function () {
1470
1481
  this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
1471
1482
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1472
1483
  return __awaiter(_this, void 0, void 0, function () {
1473
- var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit_2, gasLimit;
1484
+ var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, gasLimit;
1474
1485
  return __generator(this, function (_a) {
1475
1486
  switch (_a.label) {
1476
1487
  case 0:
@@ -1480,7 +1491,9 @@ var Pool = /** @class */ (function () {
1480
1491
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
1481
1492
  case 1:
1482
1493
  _expected = _a.sent();
1483
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1494
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
1495
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1496
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1484
1497
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.coinAddresses[i]], [_amount], this.swap)];
1485
1498
  case 2:
1486
1499
  _a.sent();
@@ -1844,10 +1857,16 @@ var Pool = /** @class */ (function () {
1844
1857
  this._calcLpTokenAmount = function (_amounts, isDeposit) {
1845
1858
  if (isDeposit === void 0) { isDeposit = true; }
1846
1859
  return __awaiter(_this, void 0, void 0, function () {
1860
+ var contract;
1847
1861
  return __generator(this, function (_a) {
1848
1862
  switch (_a.label) {
1849
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1863
+ case 0:
1864
+ contract = curve_1.curve.contracts[this.swap].contract;
1865
+ if (!["eurtusd", "crveth"].includes(this.name)) return [3 /*break*/, 2];
1866
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1850
1867
  case 1: return [2 /*return*/, _a.sent()];
1868
+ case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1869
+ case 3: return [2 /*return*/, _a.sent()];
1851
1870
  }
1852
1871
  });
1853
1872
  });
@@ -1863,8 +1882,12 @@ var Pool = /** @class */ (function () {
1863
1882
  if (!this.isFactory) return [3 /*break*/, 2];
1864
1883
  return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
1865
1884
  case 1: return [2 /*return*/, _a.sent()];
1866
- case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1885
+ case 2:
1886
+ if (!(this.name === "eurtusd")) return [3 /*break*/, 4];
1887
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1867
1888
  case 3: return [2 /*return*/, _a.sent()];
1889
+ case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1890
+ case 5: return [2 /*return*/, _a.sent()];
1868
1891
  }
1869
1892
  });
1870
1893
  });
@@ -1881,7 +1904,7 @@ var Pool = /** @class */ (function () {
1881
1904
  _wrapped_amounts = _underlying_amounts.map(function (amount, i) {
1882
1905
  return amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates[i]);
1883
1906
  });
1884
- return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.constantOptions)];
1907
+ return [4 /*yield*/, this._calcLpTokenAmount(_wrapped_amounts, isDeposit)];
1885
1908
  case 2: return [2 /*return*/, _a.sent()];
1886
1909
  }
1887
1910
  });
@@ -2018,7 +2041,7 @@ var Pool = /** @class */ (function () {
2018
2041
  _minMintAmount = _a;
2019
2042
  _minMintAmount = _minMintAmount.mul(99).div(100);
2020
2043
  contract = curve_1.curve.contracts[this.swap].contract;
2021
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
2044
+ ethIndex = (0, utils_1.getEthIndex)(useUnderlying ? this.underlyingCoinAddresses : this.coinAddresses);
2022
2045
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
2023
2046
  return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2024
2047
  case 7:
@@ -2510,11 +2533,12 @@ var Pool = /** @class */ (function () {
2510
2533
  });
2511
2534
  };
2512
2535
  this._getExchangeOutput = function (i, j, _amount) { return __awaiter(_this, void 0, void 0, function () {
2513
- var contract;
2536
+ var contractAddress, contract;
2514
2537
  return __generator(this, function (_a) {
2515
2538
  switch (_a.label) {
2516
2539
  case 0:
2517
- contract = curve_1.curve.contracts[this.swap].contract;
2540
+ contractAddress = this.name === "eurtusd" ? this.zap : this.swap;
2541
+ contract = curve_1.curve.contracts[contractAddress].contract;
2518
2542
  if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
2519
2543
  return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
2520
2544
  case 1: return [2 /*return*/, _a.sent()];
@@ -2545,8 +2569,9 @@ var Pool = /** @class */ (function () {
2545
2569
  this.decimals = poolData.decimals;
2546
2570
  this.useLending = poolData.use_lending;
2547
2571
  this.isMeta = poolData.is_meta || false;
2548
- this.basePool = poolData.base_pool || '';
2572
+ this.isCrypto = poolData.is_crypto || false;
2549
2573
  this.isFactory = poolData.is_factory || false;
2574
+ this.basePool = poolData.base_pool || '';
2550
2575
  this.estimateGas = {
2551
2576
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2552
2577
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2646,10 +2671,10 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
2646
2671
  else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
2647
2672
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2648
2673
  }
2649
- else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0) {
2674
+ else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0] !== 'eurtusd') {
2650
2675
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2651
2676
  }
2652
- else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0) {
2677
+ else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0] !== 'eurtusd') {
2653
2678
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2654
2679
  }
2655
2680
  else {
@@ -2752,27 +2777,28 @@ exports.exchangeApprove = exchangeApprove;
2752
2777
  var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
2753
2778
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2754
2779
  return __awaiter(void 0, void 0, void 0, function () {
2755
- var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, _c, poolAddress, _output, _amount, _minRecvAmount, contract, value;
2756
- return __generator(this, function (_d) {
2757
- switch (_d.label) {
2780
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
2781
+ return __generator(this, function (_e) {
2782
+ switch (_e.label) {
2758
2783
  case 0:
2759
2784
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2760
- inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2785
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2761
2786
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2762
2787
  case 1:
2763
- _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2788
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
2764
2789
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
2765
2790
  throw new Error("This pair can't be exchanged");
2766
2791
  }
2767
2792
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2768
- _minRecvAmount = _output.mul((1 - maxSlippage) * 100).div(100);
2793
+ minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
2794
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2769
2795
  contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2770
2796
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2771
2797
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
2772
2798
  case 2:
2773
- _d.sent();
2799
+ _e.sent();
2774
2800
  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()];
2801
+ case 3: return [2 /*return*/, (_e.sent()).toNumber()];
2776
2802
  }
2777
2803
  });
2778
2804
  });
@@ -2781,33 +2807,34 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
2781
2807
  var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2782
2808
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2783
2809
  return __awaiter(void 0, void 0, void 0, function () {
2784
- var _a, inputCoinAddress, outputCoinAddress, inputCoinDecimals, _c, poolAddress, _output, _amount, _minRecvAmount, contract, value, gasLimit;
2785
- return __generator(this, function (_d) {
2786
- switch (_d.label) {
2810
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
2811
+ return __generator(this, function (_e) {
2812
+ switch (_e.label) {
2787
2813
  case 0:
2788
2814
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2789
- inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2815
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2790
2816
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2791
2817
  case 1:
2792
- _d.sent();
2818
+ _e.sent();
2793
2819
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2794
2820
  case 2:
2795
- _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2821
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
2796
2822
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
2797
2823
  throw new Error("This pair can't be exchanged");
2798
2824
  }
2799
2825
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2800
- _minRecvAmount = _output.mul((1 - maxSlippage) * 100).div(100);
2826
+ minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
2827
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2801
2828
  contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2802
2829
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2803
2830
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
2804
2831
  case 3:
2805
- _d.sent();
2832
+ _e.sent();
2806
2833
  return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2807
2834
  case 4:
2808
- gasLimit = (_d.sent()).mul(130).div(100);
2835
+ gasLimit = (_e.sent()).mul(130).div(100);
2809
2836
  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];
2837
+ case 5: return [2 /*return*/, (_e.sent()).hash];
2811
2838
  }
2812
2839
  });
2813
2840
  });
@@ -2958,7 +2985,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
2958
2985
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2959
2986
  case 4:
2960
2987
  _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2961
- minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
2988
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
2962
2989
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2963
2990
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2964
2991
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
@@ -2987,7 +3014,7 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2987
3014
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2988
3015
  case 2:
2989
3016
  _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2990
- minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
3017
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
2991
3018
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2992
3019
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2993
3020
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {