@curvefi/api 1.9.1 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/pools.js CHANGED
@@ -62,9 +62,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
62
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 abis_ethereum_1 = require("./constants/abis/abis-ethereum");
66
65
  var curve_1 = require("./curve");
67
- var coins_1 = require("./constants/coins");
68
66
  var axios_1 = __importDefault(require("axios"));
69
67
  var Pool = /** @class */ (function () {
70
68
  function Pool(name) {
@@ -83,7 +81,7 @@ var Pool = /** @class */ (function () {
83
81
  _amounts = amounts.map(function (amount, i) {
84
82
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
85
83
  });
86
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
84
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
87
85
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
88
86
  case 1:
89
87
  _expected = _a.sent(); // Lending pools
@@ -111,6 +109,9 @@ var Pool = /** @class */ (function () {
111
109
  return __generator(this, function (_a) {
112
110
  switch (_a.label) {
113
111
  case 0:
112
+ if (this.isFake) {
113
+ throw Error("".concat(this.name, " pool doesn't have this method"));
114
+ }
114
115
  if (amounts.length !== this.coinAddresses.length) {
115
116
  throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
116
117
  }
@@ -146,19 +147,21 @@ var Pool = /** @class */ (function () {
146
147
  contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
147
148
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
148
149
  case 1:
149
- _poolWrappedBalances = (_a.sent());
150
+ _poolWrappedBalances = _a.sent();
150
151
  _poolUnderlyingBalances = [];
151
152
  if (!this.isMeta) return [3 /*break*/, 3];
152
- _poolWrappedBalances.unshift(_poolWrappedBalances.pop());
153
+ if (this.name !== 'atricrypto3') {
154
+ _poolWrappedBalances.unshift(_poolWrappedBalances.pop());
155
+ }
153
156
  _poolMetaCoinBalance = _poolWrappedBalances[0], _poolUnderlyingBalance = _poolWrappedBalances.slice(1);
154
157
  basePool = new Pool(this.basePool);
155
158
  return [4 /*yield*/, basePool._calcExpectedAmounts(_poolMetaCoinBalance)];
156
159
  case 2:
157
160
  _basePoolExpectedAmounts = _a.sent();
158
- _poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true);
161
+ _poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
159
162
  return [3 /*break*/, 6];
160
163
  case 3:
161
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
164
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
162
165
  return [4 /*yield*/, this._getRates()];
163
166
  case 4:
164
167
  _rates_1 = _a.sent();
@@ -172,15 +175,20 @@ var Pool = /** @class */ (function () {
172
175
  });
173
176
  }); };
174
177
  this.getPoolWrappedBalances = function () { return __awaiter(_this, void 0, void 0, function () {
175
- var swapContract, contractCalls;
178
+ var swapContract, contractCalls, _wrappedBalances;
176
179
  var _this = this;
177
180
  return __generator(this, function (_a) {
178
181
  switch (_a.label) {
179
182
  case 0:
183
+ if (this.isFake) {
184
+ throw Error("".concat(this.name, " pool doesn't have this method"));
185
+ }
180
186
  swapContract = curve_1.curve.contracts[this.swap].multicallContract;
181
187
  contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
182
188
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
183
- case 1: return [2 /*return*/, (_a.sent()).map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.decimals[i]); })];
189
+ case 1:
190
+ _wrappedBalances = _a.sent();
191
+ return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.decimals[i]); })];
184
192
  }
185
193
  });
186
194
  }); };
@@ -273,7 +281,7 @@ var Pool = /** @class */ (function () {
273
281
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
274
282
  case 3: return [2 /*return*/, _d.sent()];
275
283
  case 4:
276
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 6];
284
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
277
285
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
278
286
  case 5: return [2 /*return*/, _d.sent()];
279
287
  case 6:
@@ -321,7 +329,7 @@ var Pool = /** @class */ (function () {
321
329
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
322
330
  case 2: return [2 /*return*/, _a.sent()];
323
331
  case 3:
324
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
332
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
325
333
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
326
334
  case 4: return [2 /*return*/, _a.sent()];
327
335
  case 5:
@@ -339,7 +347,11 @@ var Pool = /** @class */ (function () {
339
347
  var poolBalances, walletBalances, _a, _c;
340
348
  return __generator(this, function (_d) {
341
349
  switch (_d.label) {
342
- case 0: return [4 /*yield*/, this.getPoolWrappedBalances()];
350
+ case 0:
351
+ if (this.isFake) {
352
+ throw Error("".concat(this.name, " pool doesn't have this method"));
353
+ }
354
+ return [4 /*yield*/, this.getPoolWrappedBalances()];
343
355
  case 1:
344
356
  poolBalances = (_d.sent()).map(Number);
345
357
  _c = (_a = Object).values;
@@ -355,6 +367,9 @@ var Pool = /** @class */ (function () {
355
367
  return __generator(this, function (_a) {
356
368
  switch (_a.label) {
357
369
  case 0:
370
+ if (this.isFake) {
371
+ throw Error("".concat(this.name, " pool doesn't have this method"));
372
+ }
358
373
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.decimals[i]); });
359
374
  return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
360
375
  case 1: return [2 /*return*/, _a.sent()];
@@ -366,6 +381,9 @@ var Pool = /** @class */ (function () {
366
381
  return __generator(this, function (_c) {
367
382
  switch (_c.label) {
368
383
  case 0:
384
+ if (this.isFake) {
385
+ throw Error("".concat(this.name, " pool doesn't have this method"));
386
+ }
369
387
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
370
388
  _a = Number;
371
389
  return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
@@ -379,7 +397,11 @@ var Pool = /** @class */ (function () {
379
397
  this.addLiquidityWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
380
398
  return __generator(this, function (_a) {
381
399
  switch (_a.label) {
382
- case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
400
+ case 0:
401
+ if (this.isFake) {
402
+ throw Error("".concat(this.name, " pool doesn't have this method"));
403
+ }
404
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, this.swap)];
383
405
  case 1: return [2 /*return*/, _a.sent()];
384
406
  }
385
407
  });
@@ -387,7 +409,11 @@ var Pool = /** @class */ (function () {
387
409
  this.addLiquidityWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
388
410
  return __generator(this, function (_a) {
389
411
  switch (_a.label) {
390
- case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, this.swap)];
412
+ case 0:
413
+ if (this.isFake) {
414
+ throw Error("".concat(this.name, " pool doesn't have this method"));
415
+ }
416
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, this.swap)];
391
417
  case 1: return [2 /*return*/, _a.sent()];
392
418
  }
393
419
  });
@@ -395,7 +421,11 @@ var Pool = /** @class */ (function () {
395
421
  this.addLiquidityWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
396
422
  return __generator(this, function (_a) {
397
423
  switch (_a.label) {
398
- case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, this.swap)];
424
+ case 0:
425
+ if (this.isFake) {
426
+ throw Error("".concat(this.name, " pool doesn't have this method"));
427
+ }
428
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, this.swap)];
399
429
  case 1: return [2 /*return*/, _a.sent()];
400
430
  }
401
431
  });
@@ -406,6 +436,9 @@ var Pool = /** @class */ (function () {
406
436
  return __generator(this, function (_d) {
407
437
  switch (_d.label) {
408
438
  case 0:
439
+ if (this.isFake) {
440
+ throw Error("".concat(this.name, " pool doesn't have this method"));
441
+ }
409
442
  if (amounts.length !== this.coinAddresses.length) {
410
443
  throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
411
444
  }
@@ -426,7 +459,7 @@ var Pool = /** @class */ (function () {
426
459
  _amounts = amounts.map(function (amount, i) {
427
460
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
428
461
  });
429
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
462
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
430
463
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
431
464
  case 3: return [2 /*return*/, _d.sent()];
432
465
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -442,6 +475,9 @@ var Pool = /** @class */ (function () {
442
475
  return __generator(this, function (_a) {
443
476
  switch (_a.label) {
444
477
  case 0:
478
+ if (this.isFake) {
479
+ throw Error("".concat(this.name, " pool doesn't have this method"));
480
+ }
445
481
  if (amounts.length !== this.coinAddresses.length) {
446
482
  throw Error("".concat(this.name, " pool has ").concat(this.coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
447
483
  }
@@ -451,7 +487,7 @@ var Pool = /** @class */ (function () {
451
487
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
452
488
  case 1:
453
489
  _a.sent();
454
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
490
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
455
491
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
456
492
  case 2: return [2 /*return*/, _a.sent()];
457
493
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -468,7 +504,7 @@ var Pool = /** @class */ (function () {
468
504
  switch (_a.label) {
469
505
  case 0:
470
506
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
471
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 2];
507
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
472
508
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
473
509
  case 1:
474
510
  _expected = _a.sent(); // Lending pools
@@ -545,7 +581,7 @@ var Pool = /** @class */ (function () {
545
581
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
546
582
  case 4: return [2 /*return*/, _c.sent()];
547
583
  case 5:
548
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
584
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
549
585
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
550
586
  case 6: return [2 /*return*/, _c.sent()];
551
587
  case 7:
@@ -570,7 +606,7 @@ var Pool = /** @class */ (function () {
570
606
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
571
607
  case 2: return [2 /*return*/, _a.sent()];
572
608
  case 3:
573
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
609
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
574
610
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
575
611
  case 4: return [2 /*return*/, _a.sent()];
576
612
  case 5:
@@ -588,6 +624,9 @@ var Pool = /** @class */ (function () {
588
624
  return __generator(this, function (_a) {
589
625
  switch (_a.label) {
590
626
  case 0:
627
+ if (this.isFake) {
628
+ throw Error("".concat(this.name, " pool doesn't have this method"));
629
+ }
591
630
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
592
631
  return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
593
632
  case 1:
@@ -601,6 +640,9 @@ var Pool = /** @class */ (function () {
601
640
  return __generator(this, function (_a) {
602
641
  switch (_a.label) {
603
642
  case 0:
643
+ if (this.isFake) {
644
+ throw Error("".concat(this.name, " pool doesn't have this method"));
645
+ }
604
646
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
605
647
  return [4 /*yield*/, this.lpTokenBalances()];
606
648
  case 1:
@@ -608,7 +650,7 @@ var Pool = /** @class */ (function () {
608
650
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
609
651
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
610
652
  }
611
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
653
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
612
654
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
613
655
  case 2: return [2 /*return*/, _a.sent()];
614
656
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -621,11 +663,14 @@ var Pool = /** @class */ (function () {
621
663
  return __generator(this, function (_a) {
622
664
  switch (_a.label) {
623
665
  case 0:
666
+ if (this.isFake) {
667
+ throw Error("".concat(this.name, " pool doesn't have this method"));
668
+ }
624
669
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
625
670
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
626
671
  case 1:
627
672
  _a.sent();
628
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
673
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
629
674
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
630
675
  case 2: return [2 /*return*/, _a.sent()];
631
676
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -638,7 +683,7 @@ var Pool = /** @class */ (function () {
638
683
  return __generator(this, function (_a) {
639
684
  switch (_a.label) {
640
685
  case 0:
641
- if (['tricrypto2'].includes(this.name)) {
686
+ if (this.isCrypto) {
642
687
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
643
688
  }
644
689
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
@@ -652,7 +697,7 @@ var Pool = /** @class */ (function () {
652
697
  return __generator(this, function (_c) {
653
698
  switch (_c.label) {
654
699
  case 0:
655
- if (['tricrypto2'].includes(this.name)) {
700
+ if (this.isCrypto) {
656
701
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
657
702
  }
658
703
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
@@ -671,7 +716,7 @@ var Pool = /** @class */ (function () {
671
716
  return __generator(this, function (_a) {
672
717
  switch (_a.label) {
673
718
  case 0:
674
- if (['tricrypto2'].includes(this.name)) {
719
+ if (this.isCrypto) {
675
720
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
676
721
  }
677
722
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -698,7 +743,7 @@ var Pool = /** @class */ (function () {
698
743
  return __generator(this, function (_a) {
699
744
  switch (_a.label) {
700
745
  case 0:
701
- if (['tricrypto2'].includes(this.name)) {
746
+ if (this.isCrypto) {
702
747
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
703
748
  }
704
749
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -725,7 +770,7 @@ var Pool = /** @class */ (function () {
725
770
  return __generator(this, function (_a) {
726
771
  switch (_a.label) {
727
772
  case 0:
728
- if (['tricrypto2'].includes(this.name)) {
773
+ if (this.isCrypto) {
729
774
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
730
775
  }
731
776
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -752,7 +797,7 @@ var Pool = /** @class */ (function () {
752
797
  return __generator(this, function (_c) {
753
798
  switch (_c.label) {
754
799
  case 0:
755
- if (['tricrypto2'].includes(this.name)) {
800
+ if (this.isCrypto) {
756
801
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
757
802
  }
758
803
  return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
@@ -779,7 +824,7 @@ var Pool = /** @class */ (function () {
779
824
  return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts, true)];
780
825
  case 5: return [2 /*return*/, _c.sent()];
781
826
  case 6:
782
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 8];
827
+ if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 8];
783
828
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true, true)];
784
829
  case 7: return [2 /*return*/, _c.sent()];
785
830
  case 8:
@@ -797,7 +842,7 @@ var Pool = /** @class */ (function () {
797
842
  return __generator(this, function (_a) {
798
843
  switch (_a.label) {
799
844
  case 0:
800
- if (['tricrypto2'].includes(this.name)) {
845
+ if (this.isCrypto) {
801
846
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
802
847
  }
803
848
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]); });
@@ -808,7 +853,7 @@ var Pool = /** @class */ (function () {
808
853
  return [4 /*yield*/, this._removeLiquidityImbalanceZap(_amounts)];
809
854
  case 2: return [2 /*return*/, _a.sent()];
810
855
  case 3:
811
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
856
+ if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
812
857
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, true)];
813
858
  case 4: return [2 /*return*/, _a.sent()];
814
859
  case 5:
@@ -825,7 +870,7 @@ var Pool = /** @class */ (function () {
825
870
  return __generator(this, function (_a) {
826
871
  switch (_a.label) {
827
872
  case 0:
828
- if (['tricrypto2'].includes(this.name)) {
873
+ if (this.isCrypto) {
829
874
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
830
875
  }
831
876
  amounts = amounts.map(function (a, i) { return Number(a).toFixed(_this.underlyingDecimals[i]); });
@@ -839,7 +884,7 @@ var Pool = /** @class */ (function () {
839
884
  return __generator(this, function (_c) {
840
885
  switch (_c.label) {
841
886
  case 0:
842
- if (['tricrypto2'].includes(this.name)) {
887
+ if (this.isCrypto) {
843
888
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
844
889
  }
845
890
  totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
@@ -858,7 +903,7 @@ var Pool = /** @class */ (function () {
858
903
  return __generator(this, function (_a) {
859
904
  switch (_a.label) {
860
905
  case 0:
861
- if (['tricrypto2'].includes(this.name)) {
906
+ if (this.isCrypto) {
862
907
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
863
908
  }
864
909
  return [4 /*yield*/, this.removeLiquidityImbalanceExpected(amounts)];
@@ -871,7 +916,7 @@ var Pool = /** @class */ (function () {
871
916
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
872
917
  }
873
918
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
874
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 4];
919
+ if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
875
920
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, true)];
876
921
  case 3: return [2 /*return*/, _a.sent()];
877
922
  case 4: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, true)];
@@ -887,14 +932,14 @@ var Pool = /** @class */ (function () {
887
932
  return __generator(this, function (_a) {
888
933
  switch (_a.label) {
889
934
  case 0:
890
- if (['tricrypto2'].includes(this.name)) {
935
+ if (this.isCrypto) {
891
936
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_imbalance method"));
892
937
  }
893
938
  _amounts = amounts.map(function (amount, i) { return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]); });
894
939
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
895
940
  case 1:
896
941
  _a.sent();
897
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
942
+ if (!(['aave', 'saave', 'ib'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
898
943
  return [4 /*yield*/, this._removeLiquidityImbalance(_amounts, false, estimateGas)];
899
944
  case 2: return [2 /*return*/, _a.sent()];
900
945
  case 3: return [4 /*yield*/, this._removeLiquidityImbalanceSwap(_amounts, estimateGas)];
@@ -1002,7 +1047,7 @@ var Pool = /** @class */ (function () {
1002
1047
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1003
1048
  case 4: return [2 /*return*/, _c.sent()];
1004
1049
  case 5:
1005
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 7];
1050
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1006
1051
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1007
1052
  case 6: return [2 /*return*/, _c.sent()];
1008
1053
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1026,7 +1071,7 @@ var Pool = /** @class */ (function () {
1026
1071
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1027
1072
  case 2: return [2 /*return*/, _a.sent()];
1028
1073
  case 3:
1029
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 5];
1074
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1030
1075
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1031
1076
  case 4: return [2 /*return*/, _a.sent()];
1032
1077
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1041,6 +1086,9 @@ var Pool = /** @class */ (function () {
1041
1086
  return __generator(this, function (_a) {
1042
1087
  switch (_a.label) {
1043
1088
  case 0:
1089
+ if (this.isFake) {
1090
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1091
+ }
1044
1092
  if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
1045
1093
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1046
1094
  }
@@ -1064,6 +1112,9 @@ var Pool = /** @class */ (function () {
1064
1112
  return __generator(this, function (_c) {
1065
1113
  switch (_c.label) {
1066
1114
  case 0:
1115
+ if (this.isFake) {
1116
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1117
+ }
1067
1118
  _a = Number;
1068
1119
  return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
1069
1120
  case 1:
@@ -1077,7 +1128,11 @@ var Pool = /** @class */ (function () {
1077
1128
  var lpTokenBalance, i, _lpTokenAmount;
1078
1129
  return __generator(this, function (_a) {
1079
1130
  switch (_a.label) {
1080
- case 0: return [4 /*yield*/, this.lpTokenBalances()];
1131
+ case 0:
1132
+ if (this.isFake) {
1133
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1134
+ }
1135
+ return [4 /*yield*/, this.lpTokenBalances()];
1081
1136
  case 1:
1082
1137
  lpTokenBalance = (_a.sent())['lpToken'];
1083
1138
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
@@ -1088,7 +1143,7 @@ var Pool = /** @class */ (function () {
1088
1143
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1089
1144
  }
1090
1145
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1091
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1146
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1092
1147
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1093
1148
  case 2: return [2 /*return*/, _a.sent()];
1094
1149
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1101,6 +1156,9 @@ var Pool = /** @class */ (function () {
1101
1156
  return __generator(this, function (_a) {
1102
1157
  switch (_a.label) {
1103
1158
  case 0:
1159
+ if (this.isFake) {
1160
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1161
+ }
1104
1162
  i = this._getCoinIdx(coin, false);
1105
1163
  if (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name)) {
1106
1164
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
@@ -1109,7 +1167,7 @@ var Pool = /** @class */ (function () {
1109
1167
  case 1:
1110
1168
  _a.sent();
1111
1169
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1112
- if (!['aave', 'saave', 'ib'].includes(this.name)) return [3 /*break*/, 3];
1170
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1113
1171
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1114
1172
  case 2: return [2 /*return*/, _a.sent()];
1115
1173
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1274,34 +1332,37 @@ var Pool = /** @class */ (function () {
1274
1332
  });
1275
1333
  }); };
1276
1334
  this.exchangeIsApproved = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1277
- var i;
1335
+ var contractAddress, i;
1278
1336
  return __generator(this, function (_a) {
1279
1337
  switch (_a.label) {
1280
1338
  case 0:
1339
+ contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1281
1340
  i = this._getCoinIdx(inputCoin);
1282
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1341
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1283
1342
  case 1: return [2 /*return*/, _a.sent()];
1284
1343
  }
1285
1344
  });
1286
1345
  }); };
1287
1346
  this.exchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1288
- var i;
1347
+ var contractAddress, i;
1289
1348
  return __generator(this, function (_a) {
1290
1349
  switch (_a.label) {
1291
1350
  case 0:
1351
+ contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1292
1352
  i = this._getCoinIdx(inputCoin);
1293
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1353
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1294
1354
  case 1: return [2 /*return*/, _a.sent()];
1295
1355
  }
1296
1356
  });
1297
1357
  }); };
1298
1358
  this.exchangeApprove = function (inputCoin, amount) { return __awaiter(_this, void 0, void 0, function () {
1299
- var i;
1359
+ var contractAddress, i;
1300
1360
  return __generator(this, function (_a) {
1301
1361
  switch (_a.label) {
1302
1362
  case 0:
1363
+ contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1303
1364
  i = this._getCoinIdx(inputCoin);
1304
- return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], this.swap)];
1365
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1305
1366
  case 1: return [2 /*return*/, _a.sent()];
1306
1367
  }
1307
1368
  });
@@ -1309,10 +1370,11 @@ var Pool = /** @class */ (function () {
1309
1370
  this.exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
1310
1371
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1311
1372
  return __awaiter(_this, void 0, void 0, function () {
1312
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value;
1373
+ var contractAddress, i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value;
1313
1374
  return __generator(this, function (_d) {
1314
1375
  switch (_d.label) {
1315
1376
  case 0:
1377
+ contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1316
1378
  i = this._getCoinIdx(inputCoin);
1317
1379
  j = this._getCoinIdx(outputCoin);
1318
1380
  _c = (_a = Object).values;
@@ -1322,7 +1384,7 @@ var Pool = /** @class */ (function () {
1322
1384
  if (Number(inputCoinBalance) < Number(amount)) {
1323
1385
  throw Error("Not enough ".concat(this.underlyingCoins[i], ". Actual: ").concat(inputCoinBalance, ", required: ").concat(amount));
1324
1386
  }
1325
- return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1387
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1326
1388
  case 2:
1327
1389
  if (!(_d.sent())) {
1328
1390
  throw Error("Token allowance is needed to estimate gas");
@@ -1331,8 +1393,10 @@ var Pool = /** @class */ (function () {
1331
1393
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1332
1394
  case 3:
1333
1395
  _expected = _d.sent();
1334
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1335
- contract = curve_1.curve.contracts[this.swap].contract;
1396
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
1397
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1398
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1399
+ contract = curve_1.curve.contracts[contractAddress].contract;
1336
1400
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1337
1401
  value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1338
1402
  if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
@@ -1347,21 +1411,24 @@ var Pool = /** @class */ (function () {
1347
1411
  this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
1348
1412
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1349
1413
  return __awaiter(_this, void 0, void 0, function () {
1350
- var i, j, _amount, _expected, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, gasLimit;
1414
+ var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, estimatedGas, gasLimit;
1351
1415
  return __generator(this, function (_a) {
1352
1416
  switch (_a.label) {
1353
1417
  case 0:
1418
+ contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1354
1419
  i = this._getCoinIdx(inputCoin);
1355
1420
  j = this._getCoinIdx(outputCoin);
1356
1421
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
1357
1422
  return [4 /*yield*/, this._getExchangeOutput(i, j, _amount)];
1358
1423
  case 1:
1359
1424
  _expected = _a.sent();
1360
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1361
- return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], this.swap)];
1425
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.underlyingCoinAddresses[j])[0];
1426
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1427
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1428
+ return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
1362
1429
  case 2:
1363
1430
  _a.sent();
1364
- contract = curve_1.curve.contracts[this.swap].contract;
1431
+ contract = curve_1.curve.contracts[contractAddress].contract;
1365
1432
  exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
1366
1433
  value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1367
1434
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
@@ -1375,7 +1442,10 @@ var Pool = /** @class */ (function () {
1375
1442
  case 5: return [2 /*return*/, (_a.sent()).hash];
1376
1443
  case 6: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1377
1444
  case 7:
1378
- gasLimit = (_a.sent()).mul(130).div(100);
1445
+ estimatedGas = _a.sent();
1446
+ gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
1447
+ estimatedGas.mul(160).div(100) :
1448
+ estimatedGas.mul(130).div(100);
1379
1449
  return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1380
1450
  case 8: return [2 /*return*/, (_a.sent()).hash];
1381
1451
  }
@@ -1387,6 +1457,9 @@ var Pool = /** @class */ (function () {
1387
1457
  return __generator(this, function (_a) {
1388
1458
  switch (_a.label) {
1389
1459
  case 0:
1460
+ if (this.isFake) {
1461
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1462
+ }
1390
1463
  i = this._getCoinIdx(inputCoin, false);
1391
1464
  j = this._getCoinIdx(outputCoin, false);
1392
1465
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
@@ -1402,6 +1475,9 @@ var Pool = /** @class */ (function () {
1402
1475
  return __generator(this, function (_a) {
1403
1476
  switch (_a.label) {
1404
1477
  case 0:
1478
+ if (this.isFake) {
1479
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1480
+ }
1405
1481
  i = this._getCoinIdx(inputCoin, false);
1406
1482
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.coinAddresses[i]], [amount], curve_1.curve.signerAddress, this.swap)];
1407
1483
  case 1: return [2 /*return*/, _a.sent()];
@@ -1413,6 +1489,9 @@ var Pool = /** @class */ (function () {
1413
1489
  return __generator(this, function (_a) {
1414
1490
  switch (_a.label) {
1415
1491
  case 0:
1492
+ if (this.isFake) {
1493
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1494
+ }
1416
1495
  i = this._getCoinIdx(inputCoin, false);
1417
1496
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.coinAddresses[i]], [amount], this.swap)];
1418
1497
  case 1: return [2 /*return*/, _a.sent()];
@@ -1424,6 +1503,9 @@ var Pool = /** @class */ (function () {
1424
1503
  return __generator(this, function (_a) {
1425
1504
  switch (_a.label) {
1426
1505
  case 0:
1506
+ if (this.isFake) {
1507
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1508
+ }
1427
1509
  i = this._getCoinIdx(inputCoin, false);
1428
1510
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.coinAddresses[i]], [amount], this.swap)];
1429
1511
  case 1: return [2 /*return*/, _a.sent()];
@@ -1433,10 +1515,13 @@ var Pool = /** @class */ (function () {
1433
1515
  this.exchangeWrappedEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
1434
1516
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1435
1517
  return __awaiter(_this, void 0, void 0, function () {
1436
- var i, j, inputCoinBalance, _a, _c, _amount, _expected, _minRecvAmount, contract, value;
1518
+ var i, j, inputCoinBalance, _a, _c, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value;
1437
1519
  return __generator(this, function (_d) {
1438
1520
  switch (_d.label) {
1439
1521
  case 0:
1522
+ if (this.isFake) {
1523
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1524
+ }
1440
1525
  i = this._getCoinIdx(inputCoin, false);
1441
1526
  j = this._getCoinIdx(outputCoin, false);
1442
1527
  _c = (_a = Object).values;
@@ -1455,7 +1540,9 @@ var Pool = /** @class */ (function () {
1455
1540
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
1456
1541
  case 3:
1457
1542
  _expected = _d.sent();
1458
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1543
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
1544
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1545
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1459
1546
  contract = curve_1.curve.contracts[this.swap].contract;
1460
1547
  value = (0, utils_1.isEth)(this.coinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
1461
1548
  if (!(this.name === 'tricrypto2')) return [3 /*break*/, 5];
@@ -1470,17 +1557,22 @@ var Pool = /** @class */ (function () {
1470
1557
  this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
1471
1558
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1472
1559
  return __awaiter(_this, void 0, void 0, function () {
1473
- var i, j, _amount, _expected, _minRecvAmount, contract, value, gasLimit_2, gasLimit;
1560
+ var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, estimatedGas, gasLimit;
1474
1561
  return __generator(this, function (_a) {
1475
1562
  switch (_a.label) {
1476
1563
  case 0:
1564
+ if (this.isFake) {
1565
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1566
+ }
1477
1567
  i = this._getCoinIdx(inputCoin, false);
1478
1568
  j = this._getCoinIdx(outputCoin, false);
1479
1569
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.decimals[i]);
1480
1570
  return [4 /*yield*/, this._getExchangeOutputWrapped(i, j, _amount)];
1481
1571
  case 1:
1482
1572
  _expected = _a.sent();
1483
- _minRecvAmount = _expected.mul((1 - maxSlippage) * 100).div(100);
1573
+ outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.coinAddresses[j])[0];
1574
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
1575
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
1484
1576
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.coinAddresses[i]], [_amount], this.swap)];
1485
1577
  case 2:
1486
1578
  _a.sent();
@@ -1497,7 +1589,10 @@ var Pool = /** @class */ (function () {
1497
1589
  case 5: return [2 /*return*/, (_a.sent()).hash];
1498
1590
  case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1499
1591
  case 7:
1500
- gasLimit = (_a.sent()).mul(130).div(100);
1592
+ estimatedGas = _a.sent();
1593
+ gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
1594
+ estimatedGas.mul(140).div(100) :
1595
+ estimatedGas.mul(130).div(100);
1501
1596
  return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1502
1597
  case 8: return [2 /*return*/, (_a.sent()).hash];
1503
1598
  }
@@ -1510,7 +1605,7 @@ var Pool = /** @class */ (function () {
1510
1605
  addresses[_i] = arguments[_i];
1511
1606
  }
1512
1607
  return __awaiter(_this, void 0, void 0, function () {
1513
- var votingEscrowContract, gaugeContract, contractCalls, response, _a, veTotalSupply, gaugeTotalSupply, resultBN, result, _c, _d, entry;
1608
+ var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _a, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _c, _d, entry;
1514
1609
  return __generator(this, function (_e) {
1515
1610
  switch (_e.label) {
1516
1611
  case 0:
@@ -1524,11 +1619,12 @@ var Pool = /** @class */ (function () {
1524
1619
  });
1525
1620
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1526
1621
  case 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];
1622
+ _response = _e.sent();
1623
+ responseBN = _response.map(function (value) { return (0, utils_1.toBN)(value); });
1624
+ _a = responseBN.splice(0, 2), veTotalSupplyBN = _a[0], gaugeTotalSupplyBN = _a[1];
1529
1625
  resultBN = {};
1530
1626
  addresses.forEach(function (acct, i) {
1531
- resultBN[acct] = response[i].div(veTotalSupply).times(gaugeTotalSupply);
1627
+ resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
1532
1628
  });
1533
1629
  result = {};
1534
1630
  for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
@@ -1546,7 +1642,7 @@ var Pool = /** @class */ (function () {
1546
1642
  accounts[_i] = arguments[_i];
1547
1643
  }
1548
1644
  return __awaiter(_this, void 0, void 0, function () {
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;
1645
+ var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, _response, 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
1646
  return __generator(this, function (_j) {
1551
1647
  switch (_j.label) {
1552
1648
  case 0:
@@ -1561,7 +1657,8 @@ var Pool = /** @class */ (function () {
1561
1657
  });
1562
1658
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
1563
1659
  case 1:
1564
- response = (_j.sent()).map(function (value) { return (0, utils_1.toBN)(value); });
1660
+ _response = _j.sent();
1661
+ response = _response.map(function (value) { return (0, utils_1.toBN)(value); });
1565
1662
  _a = response.splice(0, 2), veTotalSupply = _a[0], gaugeTotalSupply = _a[1];
1566
1663
  votingPower = {};
1567
1664
  totalBalance = (0, utils_1.BN)(0);
@@ -1844,10 +1941,16 @@ var Pool = /** @class */ (function () {
1844
1941
  this._calcLpTokenAmount = function (_amounts, isDeposit) {
1845
1942
  if (isDeposit === void 0) { isDeposit = true; }
1846
1943
  return __awaiter(_this, void 0, void 0, function () {
1944
+ var contract;
1847
1945
  return __generator(this, function (_a) {
1848
1946
  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)];
1947
+ case 0:
1948
+ contract = curve_1.curve.contracts[this.swap].contract;
1949
+ if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
1950
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1850
1951
  case 1: return [2 /*return*/, _a.sent()];
1952
+ case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1953
+ case 3: return [2 /*return*/, _a.sent()];
1851
1954
  }
1852
1955
  });
1853
1956
  });
@@ -1863,8 +1966,12 @@ var Pool = /** @class */ (function () {
1863
1966
  if (!this.isFactory) return [3 /*break*/, 2];
1864
1967
  return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
1865
1968
  case 1: return [2 /*return*/, _a.sent()];
1866
- case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1969
+ case 2:
1970
+ if (!(this.name === "eurtusd")) return [3 /*break*/, 4];
1971
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1867
1972
  case 3: return [2 /*return*/, _a.sent()];
1973
+ case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1974
+ case 5: return [2 /*return*/, _a.sent()];
1868
1975
  }
1869
1976
  });
1870
1977
  });
@@ -1881,7 +1988,7 @@ var Pool = /** @class */ (function () {
1881
1988
  _wrapped_amounts = _underlying_amounts.map(function (amount, i) {
1882
1989
  return amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates[i]);
1883
1990
  });
1884
- return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.calc_token_amount(_wrapped_amounts, isDeposit, curve_1.curve.constantOptions)];
1991
+ return [4 /*yield*/, this._calcLpTokenAmount(_wrapped_amounts, isDeposit)];
1885
1992
  case 2: return [2 /*return*/, _a.sent()];
1886
1993
  }
1887
1994
  });
@@ -2018,7 +2125,7 @@ var Pool = /** @class */ (function () {
2018
2125
  _minMintAmount = _a;
2019
2126
  _minMintAmount = _minMintAmount.mul(99).div(100);
2020
2127
  contract = curve_1.curve.contracts[this.swap].contract;
2021
- ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
2128
+ ethIndex = (0, utils_1.getEthIndex)(useUnderlying ? this.underlyingCoinAddresses : this.coinAddresses);
2022
2129
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
2023
2130
  return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, useUnderlying, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2024
2131
  case 7:
@@ -2103,13 +2210,15 @@ var Pool = /** @class */ (function () {
2103
2210
  case 0: return [4 /*yield*/, this._calcExpectedAmounts(_lpTokenAmount)];
2104
2211
  case 1:
2105
2212
  _expectedWrappedAmounts = _a.sent();
2106
- _expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
2213
+ if (this.name !== 'atricrypto3') {
2214
+ _expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
2215
+ }
2107
2216
  _expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
2108
2217
  basePool = new Pool(this.basePool);
2109
2218
  return [4 /*yield*/, basePool._calcExpectedAmounts(_expectedMetaCoinAmount)];
2110
2219
  case 2:
2111
2220
  _basePoolExpectedAmounts = _a.sent();
2112
- return [2 /*return*/, __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true)];
2221
+ return [2 /*return*/, this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
2113
2222
  }
2114
2223
  });
2115
2224
  }); };
@@ -2363,7 +2472,9 @@ var Pool = /** @class */ (function () {
2363
2472
  if (estimateGas) {
2364
2473
  return [2 /*return*/, gas.toNumber()];
2365
2474
  }
2366
- gasLimit = gas.mul(130).div(100);
2475
+ gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
2476
+ gas.mul(140).div(100) :
2477
+ gas.mul(130).div(100);
2367
2478
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
2368
2479
  case 6: return [2 /*return*/, (_c.sent()).hash];
2369
2480
  }
@@ -2502,7 +2613,9 @@ var Pool = /** @class */ (function () {
2502
2613
  if (estimateGas) {
2503
2614
  return [2 /*return*/, gas.toNumber()];
2504
2615
  }
2505
- gasLimit = gas.mul(130).div(100);
2616
+ gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
2617
+ gas.mul(160).div(100) :
2618
+ gas.mul(130).div(100);
2506
2619
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, useUnderlying, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
2507
2620
  case 6: return [2 /*return*/, (_c.sent()).hash];
2508
2621
  }
@@ -2510,11 +2623,12 @@ var Pool = /** @class */ (function () {
2510
2623
  });
2511
2624
  };
2512
2625
  this._getExchangeOutput = function (i, j, _amount) { return __awaiter(_this, void 0, void 0, function () {
2513
- var contract;
2626
+ var contractAddress, contract;
2514
2627
  return __generator(this, function (_a) {
2515
2628
  switch (_a.label) {
2516
2629
  case 0:
2517
- contract = curve_1.curve.contracts[this.swap].contract;
2630
+ contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2631
+ contract = curve_1.curve.contracts[contractAddress].contract;
2518
2632
  if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
2519
2633
  return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
2520
2634
  case 1: return [2 /*return*/, _a.sent()];
@@ -2531,7 +2645,7 @@ var Pool = /** @class */ (function () {
2531
2645
  }
2532
2646
  });
2533
2647
  }); };
2534
- var poolData = abis_ethereum_1.poolsData[name];
2648
+ var poolData = curve_1.POOLS_DATA[name];
2535
2649
  this.name = name;
2536
2650
  this.swap = poolData.swap_address;
2537
2651
  this.zap = poolData.deposit_address || null;
@@ -2545,8 +2659,10 @@ var Pool = /** @class */ (function () {
2545
2659
  this.decimals = poolData.decimals;
2546
2660
  this.useLending = poolData.use_lending;
2547
2661
  this.isMeta = poolData.is_meta || false;
2548
- this.basePool = poolData.base_pool || '';
2662
+ this.isFake = poolData.is_fake || false;
2663
+ this.isCrypto = poolData.is_crypto || false;
2549
2664
  this.isFactory = poolData.is_factory || false;
2665
+ this.basePool = poolData.base_pool || '';
2550
2666
  this.estimateGas = {
2551
2667
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2552
2668
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2569,7 +2685,7 @@ var Pool = /** @class */ (function () {
2569
2685
  exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
2570
2686
  exchangeWrapped: this.exchangeWrappedEstimateGas,
2571
2687
  };
2572
- if (this.isMeta) {
2688
+ if (this.isMeta && !this.isFake) {
2573
2689
  var metaCoins = poolData.meta_coin_addresses;
2574
2690
  var metaCoinDecimals = poolData.meta_coin_decimals;
2575
2691
  this.underlyingCoinAddresses = __spreadArray([this.underlyingCoinAddresses[0]], metaCoins, true);
@@ -2625,7 +2741,7 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
2625
2741
  return __generator(this, function (_d) {
2626
2742
  switch (_d.label) {
2627
2743
  case 0:
2628
- availablePools = Object.entries(abis_ethereum_1.poolsData).map(function (pool) {
2744
+ availablePools = Object.entries(curve_1.POOLS_DATA).map(function (pool) {
2629
2745
  var _a;
2630
2746
  var coin_addresses = pool[1].coin_addresses.map(function (a) { return a.toLowerCase(); });
2631
2747
  var underlying_coin_addresses = pool[1].underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
@@ -2640,16 +2756,19 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
2640
2756
  underlying_coin_addresses.indexOf(outputCoinAddress.toLowerCase()),
2641
2757
  meta_coin_addresses ? meta_coin_addresses.indexOf(outputCoinAddress.toLowerCase()) : -1,
2642
2758
  ];
2759
+ if (pool[0] === 'atricrypto3') {
2760
+ return null;
2761
+ }
2643
2762
  if (inputCoinIndexes[0] >= 0 && outputCoinIndexes[0] >= 0) {
2644
2763
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2645
2764
  }
2646
2765
  else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
2647
2766
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2648
2767
  }
2649
- else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0) {
2768
+ else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0] !== 'eurtusd') {
2650
2769
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2651
2770
  }
2652
- else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0) {
2771
+ else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0] !== 'eurtusd') {
2653
2772
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2654
2773
  }
2655
2774
  else {
@@ -2680,7 +2799,7 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
2680
2799
  _estimateGasForPools(availablePools.map(function (pool) { return pool.poolAddress; }), inputCoinAddress, outputCoinAddress, _amount),
2681
2800
  (0, utils_1._getUsdRate)(outputCoinAddress),
2682
2801
  axios_1.default.get("https://api.curve.fi/api/getGas"),
2683
- (0, utils_1._getUsdRate)(coins_1.COINS.eth),
2802
+ (0, utils_1._getUsdRate)(curve_1.COINS.eth),
2684
2803
  ])];
2685
2804
  case 3:
2686
2805
  _c = _d.sent(), _expectedAmounts = _c[0], gasAmounts = _c[1], outputCoinUsdRate = _c[2], gasData = _c[3], ethUsdRate = _c[4];
@@ -2752,27 +2871,28 @@ exports.exchangeApprove = exchangeApprove;
2752
2871
  var exchangeEstimateGas = function (inputCoin, outputCoin, amount, maxSlippage) {
2753
2872
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2754
2873
  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) {
2874
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value;
2875
+ return __generator(this, function (_e) {
2876
+ switch (_e.label) {
2758
2877
  case 0:
2759
2878
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2760
- inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2879
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2761
2880
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2762
2881
  case 1:
2763
- _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2882
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
2764
2883
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
2765
2884
  throw new Error("This pair can't be exchanged");
2766
2885
  }
2767
2886
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2768
- _minRecvAmount = _output.mul((1 - maxSlippage) * 100).div(100);
2887
+ minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
2888
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2769
2889
  contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2770
2890
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2771
2891
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
2772
2892
  case 2:
2773
- _d.sent();
2893
+ _e.sent();
2774
2894
  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()];
2895
+ case 3: return [2 /*return*/, (_e.sent()).toNumber()];
2776
2896
  }
2777
2897
  });
2778
2898
  });
@@ -2781,33 +2901,34 @@ exports.exchangeEstimateGas = exchangeEstimateGas;
2781
2901
  var exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2782
2902
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
2783
2903
  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) {
2904
+ var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _d, poolAddress, _output, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
2905
+ return __generator(this, function (_e) {
2906
+ switch (_e.label) {
2787
2907
  case 0:
2788
2908
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2789
- inputCoinDecimals = (0, utils_1._getCoinDecimals)(inputCoinAddress)[0];
2909
+ _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2790
2910
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.registry_exchange)];
2791
2911
  case 1:
2792
- _d.sent();
2912
+ _e.sent();
2793
2913
  return [4 /*yield*/, _getBestPoolAndOutput(inputCoinAddress, outputCoinAddress, amount)];
2794
2914
  case 2:
2795
- _c = _d.sent(), poolAddress = _c.poolAddress, _output = _c._output;
2915
+ _d = _e.sent(), poolAddress = _d.poolAddress, _output = _d._output;
2796
2916
  if (poolAddress === "0x0000000000000000000000000000000000000000") {
2797
2917
  throw new Error("This pair can't be exchanged");
2798
2918
  }
2799
2919
  _amount = ethers_1.ethers.utils.parseUnits(amount, inputCoinDecimals);
2800
- _minRecvAmount = _output.mul((1 - maxSlippage) * 100).div(100);
2920
+ minRecvAmountBN = (0, utils_1.toBN)(_output, outputCoinDecimals).times(1 - maxSlippage);
2921
+ _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2801
2922
  contract = curve_1.curve.contracts[curve_1.ALIASES.registry_exchange].contract;
2802
2923
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : ethers_1.ethers.BigNumber.from(0);
2803
2924
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
2804
2925
  case 3:
2805
- _d.sent();
2926
+ _e.sent();
2806
2927
  return [4 /*yield*/, contract.estimateGas.exchange(poolAddress, inputCoinAddress, outputCoinAddress, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2807
2928
  case 4:
2808
- gasLimit = (_d.sent()).mul(130).div(100);
2929
+ gasLimit = (_e.sent()).mul(130).div(100);
2809
2930
  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];
2931
+ case 5: return [2 /*return*/, (_e.sent()).hash];
2811
2932
  }
2812
2933
  });
2813
2934
  });
@@ -2819,9 +2940,12 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
2819
2940
  return __generator(this, function (_c) {
2820
2941
  switch (_c.label) {
2821
2942
  case 0:
2943
+ if (curve_1.curve.chainId !== 1) {
2944
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
2945
+ }
2822
2946
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2823
2947
  // TODO remove it when fixed
2824
- if (inputCoinAddress.toLowerCase() === coins_1.COINS.weth.toLowerCase() || outputCoinAddress.toLowerCase() === coins_1.COINS.weth.toLowerCase())
2948
+ if (inputCoinAddress.toLowerCase() === curve_1.COINS.weth.toLowerCase() || outputCoinAddress.toLowerCase() === curve_1.COINS.weth.toLowerCase())
2825
2949
  return [2 /*return*/, false];
2826
2950
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
2827
2951
  case 1:
@@ -2833,11 +2957,11 @@ var crossAssetExchangeAvailable = function (inputCoin, outputCoin) { return __aw
2833
2957
  exports.crossAssetExchangeAvailable = crossAssetExchangeAvailable;
2834
2958
  var _getSmallAmountForCoin = function (coinAddress) {
2835
2959
  var smallAmount = '10'; // $10 or €10
2836
- if (Object.values(coins_1.BTC_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
2960
+ if (Object.values(curve_1.BTC_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
2837
2961
  smallAmount = '0.00025'; // =10$ when BTC = $40k
2838
- else if (Object.values(coins_1.ETH_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
2962
+ else if (Object.values(curve_1.ETH_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
2839
2963
  smallAmount = '0.004'; // =10$ when ETH = $2.5k
2840
- else if (Object.values(coins_1.LINK_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
2964
+ else if (Object.values(curve_1.LINK_COINS_LOWER_CASE).includes(coinAddress.toLowerCase()))
2841
2965
  smallAmount = '0.5'; // =10$ when LINK = $20
2842
2966
  return smallAmount;
2843
2967
  };
@@ -2874,6 +2998,9 @@ var crossAssetExchangeOutputAndSlippage = function (inputCoin, outputCoin, amoun
2874
2998
  return __generator(this, function (_e) {
2875
2999
  switch (_e.label) {
2876
3000
  case 0:
3001
+ if (curve_1.curve.chainId !== 1) {
3002
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3003
+ }
2877
3004
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2878
3005
  _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2879
3006
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
@@ -2890,6 +3017,9 @@ var crossAssetExchangeExpected = function (inputCoin, outputCoin, amount) { retu
2890
3017
  return __generator(this, function (_e) {
2891
3018
  switch (_e.label) {
2892
3019
  case 0:
3020
+ if (curve_1.curve.chainId !== 1) {
3021
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3022
+ }
2893
3023
  _a = (0, utils_1._getCoinAddresses)(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
2894
3024
  _c = (0, utils_1._getCoinDecimals)(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
2895
3025
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
@@ -2907,7 +3037,11 @@ exports.crossAssetExchangeExpected = crossAssetExchangeExpected;
2907
3037
  var crossAssetExchangeIsApproved = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2908
3038
  return __generator(this, function (_a) {
2909
3039
  switch (_a.label) {
2910
- case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
3040
+ case 0:
3041
+ if (curve_1.curve.chainId !== 1) {
3042
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3043
+ }
3044
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([inputCoin], [amount], curve_1.curve.signerAddress, curve_1.ALIASES.router)];
2911
3045
  case 1: return [2 /*return*/, _a.sent()];
2912
3046
  }
2913
3047
  });
@@ -2916,7 +3050,11 @@ exports.crossAssetExchangeIsApproved = crossAssetExchangeIsApproved;
2916
3050
  var crossAssetExchangeApproveEstimateGas = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2917
3051
  return __generator(this, function (_a) {
2918
3052
  switch (_a.label) {
2919
- case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.router)];
3053
+ case 0:
3054
+ if (curve_1.curve.chainId !== 1) {
3055
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3056
+ }
3057
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([inputCoin], [amount], curve_1.ALIASES.router)];
2920
3058
  case 1: return [2 /*return*/, _a.sent()];
2921
3059
  }
2922
3060
  });
@@ -2925,7 +3063,11 @@ exports.crossAssetExchangeApproveEstimateGas = crossAssetExchangeApproveEstimate
2925
3063
  var crossAssetExchangeApprove = function (inputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
2926
3064
  return __generator(this, function (_a) {
2927
3065
  switch (_a.label) {
2928
- case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.router)];
3066
+ case 0:
3067
+ if (curve_1.curve.chainId !== 1) {
3068
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3069
+ }
3070
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([inputCoin], [amount], curve_1.ALIASES.router)];
2929
3071
  case 1: return [2 /*return*/, _a.sent()];
2930
3072
  }
2931
3073
  });
@@ -2937,7 +3079,11 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
2937
3079
  var _a, inputCoinAddress, outputCoinAddress, inputCoinBalance, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract;
2938
3080
  return __generator(this, function (_e) {
2939
3081
  switch (_e.label) {
2940
- case 0: return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
3082
+ case 0:
3083
+ if (curve_1.curve.chainId !== 1) {
3084
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3085
+ }
3086
+ return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
2941
3087
  case 1:
2942
3088
  if (!(_e.sent()))
2943
3089
  throw Error("Such exchange is not available");
@@ -2958,7 +3104,7 @@ var crossAssetExchangeEstimateGas = function (inputCoin, outputCoin, amount, max
2958
3104
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2959
3105
  case 4:
2960
3106
  _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2961
- minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
3107
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
2962
3108
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2963
3109
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2964
3110
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];
@@ -2977,7 +3123,11 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2977
3123
  var _a, inputCoinAddress, outputCoinAddress, _c, inputCoinDecimals, outputCoinDecimals, _amount, _d, route, indices, _expected, minRecvAmountBN, _minRecvAmount, value, routerContract, gasLimit;
2978
3124
  return __generator(this, function (_e) {
2979
3125
  switch (_e.label) {
2980
- case 0: return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
3126
+ case 0:
3127
+ if (curve_1.curve.chainId !== 1) {
3128
+ throw Error("Cross-asset swaps are not available on this network (id".concat(curve_1.curve.chainId, ")"));
3129
+ }
3130
+ return [4 /*yield*/, (0, exports.crossAssetExchangeAvailable)(inputCoin, outputCoin)];
2981
3131
  case 1:
2982
3132
  if (!(_e.sent()))
2983
3133
  throw Error("Such exchange is not available");
@@ -2987,7 +3137,7 @@ var crossAssetExchange = function (inputCoin, outputCoin, amount, maxSlippage) {
2987
3137
  return [4 /*yield*/, (0, exports._crossAssetExchangeInfo)(inputCoinAddress, outputCoinAddress, inputCoinDecimals, outputCoinDecimals, amount)];
2988
3138
  case 2:
2989
3139
  _d = _e.sent(), route = _d.route, indices = _d.indices, _expected = _d._expected;
2990
- minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times((1 - maxSlippage));
3140
+ minRecvAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(1 - maxSlippage);
2991
3141
  _minRecvAmount = (0, utils_1.fromBN)(minRecvAmountBN, outputCoinDecimals);
2992
3142
  value = (0, utils_1.isEth)(inputCoinAddress) ? _amount : 0;
2993
3143
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.router].contract];