@curvefi/api 1.16.1 → 1.18.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.
Files changed (39) hide show
  1. package/README.md +98 -0
  2. package/lib/constants/abis/abis-ethereum.js +6 -6
  3. package/lib/constants/abis/json/deposit_and_stake.json +51 -0
  4. package/lib/constants/abis/json/factory-v2/DepositZapMetaBtcPolygon.json +197 -0
  5. package/lib/constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json +197 -0
  6. package/lib/constants/abis/json/factory-v2/MetaBTC.json +919 -0
  7. package/lib/constants/abis/json/factory-v2/MetaBTCBalances.json +932 -0
  8. package/lib/constants/abis/json/factory-v2/MetaBTCBalancesRen.json +932 -0
  9. package/lib/constants/abis/json/factory-v2/MetaBTCRen.json +919 -0
  10. package/lib/constants/abis/json/factory-v2/MetaUSD.json +919 -0
  11. package/lib/constants/abis/json/factory-v2/MetaUSDBalances.json +932 -0
  12. package/lib/constants/abis/json/factory-v2/Plain2Balances.json +845 -0
  13. package/lib/constants/abis/json/factory-v2/Plain2Basic.json +845 -0
  14. package/lib/constants/abis/json/factory-v2/Plain2ETH.json +845 -0
  15. package/lib/constants/abis/json/factory-v2/Plain2Optimized.json +844 -0
  16. package/lib/constants/abis/json/factory-v2/Plain3Balances.json +845 -0
  17. package/lib/constants/abis/json/factory-v2/Plain3Basic.json +845 -0
  18. package/lib/constants/abis/json/factory-v2/Plain3ETH.json +845 -0
  19. package/lib/constants/abis/json/factory-v2/Plain3Optimized.json +845 -0
  20. package/lib/constants/abis/json/factory-v2/Plain4Balances.json +845 -0
  21. package/lib/constants/abis/json/factory-v2/Plain4Basic.json +845 -0
  22. package/lib/constants/abis/json/factory-v2/Plain4ETH.json +845 -0
  23. package/lib/constants/abis/json/factory-v2/Plain4Optimized.json +845 -0
  24. package/lib/constants/abis/json/factory.json +1063 -0
  25. package/lib/constants/aliases.d.ts +4 -0
  26. package/lib/constants/aliases.js +4 -0
  27. package/lib/constants/coins-polygon.js +3 -2
  28. package/lib/curve.d.ts +4 -0
  29. package/lib/curve.js +44 -0
  30. package/lib/factory.d.ts +32 -0
  31. package/lib/factory.js +607 -0
  32. package/lib/index.d.ts +4 -0
  33. package/lib/index.js +15 -0
  34. package/lib/interfaces.d.ts +15 -1
  35. package/lib/pools.d.ts +22 -0
  36. package/lib/pools.js +462 -69
  37. package/lib/utils.d.ts +8 -1
  38. package/lib/utils.js +121 -8
  39. package/package.json +4 -2
package/lib/pools.js CHANGED
@@ -240,17 +240,33 @@ var Pool = /** @class */ (function () {
240
240
  }
241
241
  });
242
242
  }); };
243
+ this._getPoolStats = function () { return __awaiter(_this, void 0, void 0, function () {
244
+ var statsUrl, name, key;
245
+ return __generator(this, function (_a) {
246
+ switch (_a.label) {
247
+ case 0:
248
+ statsUrl = this.isFactory ? (0, utils_1._getFactoryStatsUrl)() : (0, utils_1._getStatsUrl)(this.isCrypto);
249
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
250
+ key = this.isFactory ? this.swap.toLowerCase() : name;
251
+ if (!this.isFactory) return [3 /*break*/, 4];
252
+ if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 2];
253
+ return [4 /*yield*/, (0, utils_1._getFactoryStatsPolygon)(statsUrl)];
254
+ case 1: return [2 /*return*/, (_a.sent())[key]];
255
+ case 2: return [4 /*yield*/, (0, utils_1._getFactoryStatsEthereum)(statsUrl)];
256
+ case 3: return [2 /*return*/, (_a.sent())[key]];
257
+ case 4: return [4 /*yield*/, (0, utils_1._getStats)(statsUrl)];
258
+ case 5: return [2 /*return*/, (_a.sent())[key]];
259
+ }
260
+ });
261
+ }); };
243
262
  this.getVolume = function () { return __awaiter(_this, void 0, void 0, function () {
244
- var name, statsUrl, volume, usdRate, _a;
263
+ var volume, usdRate, _a;
245
264
  return __generator(this, function (_c) {
246
265
  switch (_c.label) {
247
- case 0:
248
- name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
249
- statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
250
- return [4 /*yield*/, axios_1.default.get(statsUrl)];
266
+ case 0: return [4 /*yield*/, this._getPoolStats()];
251
267
  case 1:
252
- volume = (_c.sent()).data.volume[name] || 0;
253
- if (!this.isCrypto) return [3 /*break*/, 2];
268
+ volume = (_c.sent()).volume;
269
+ if (!(this.isCrypto || (curve_1.curve.chainId === 1 && this.isFactory))) return [3 /*break*/, 2];
254
270
  _a = 1;
255
271
  return [3 /*break*/, 4];
256
272
  case 2: return [4 /*yield*/, (0, utils_1._getUsdRate)(this.referenceAsset)];
@@ -264,16 +280,14 @@ var Pool = /** @class */ (function () {
264
280
  });
265
281
  }); };
266
282
  this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
267
- var name, statsUrl, apy, formattedApy;
283
+ var apy, multiplier, formattedApy;
268
284
  return __generator(this, function (_a) {
269
285
  switch (_a.label) {
270
- case 0:
271
- name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
272
- statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
273
- return [4 /*yield*/, axios_1.default.get(statsUrl)];
286
+ case 0: return [4 /*yield*/, this._getPoolStats()];
274
287
  case 1:
275
- apy = (_a.sent()).data.apy;
276
- formattedApy = [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); });
288
+ apy = (_a.sent()).apy;
289
+ multiplier = this.isFactory ? 1 : 100;
290
+ formattedApy = [apy.day, apy.week, apy.month, apy.total].map(function (x) { return (x * multiplier).toFixed(4); });
277
291
  return [2 /*return*/, {
278
292
  day: formattedApy[0],
279
293
  week: formattedApy[1],
@@ -288,6 +302,8 @@ var Pool = /** @class */ (function () {
288
302
  return __generator(this, function (_c) {
289
303
  switch (_c.label) {
290
304
  case 0:
305
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
306
+ throw Error("".concat(this.name, " doesn't have gauge"));
291
307
  if (curve_1.curve.chainId === 137)
292
308
  throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
293
309
  gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
@@ -409,34 +425,25 @@ var Pool = /** @class */ (function () {
409
425
  });
410
426
  }); };
411
427
  this.addLiquidityIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
412
- var spender;
413
428
  return __generator(this, function (_a) {
414
429
  switch (_a.label) {
415
- case 0:
416
- spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
417
- return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, spender)];
430
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
418
431
  case 1: return [2 /*return*/, _a.sent()];
419
432
  }
420
433
  });
421
434
  }); };
422
435
  this.addLiquidityApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
423
- var spender;
424
436
  return __generator(this, function (_a) {
425
437
  switch (_a.label) {
426
- case 0:
427
- spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
428
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, spender)];
438
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, this.zap || this.swap)];
429
439
  case 1: return [2 /*return*/, _a.sent()];
430
440
  }
431
441
  });
432
442
  }); };
433
443
  this.addLiquidityApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
434
- var spender;
435
444
  return __generator(this, function (_a) {
436
445
  switch (_a.label) {
437
- case 0:
438
- spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
439
- return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, spender)];
446
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, this.zap || this.swap)];
440
447
  case 1: return [2 /*return*/, _a.sent()];
441
448
  }
442
449
  });
@@ -541,6 +548,206 @@ var Pool = /** @class */ (function () {
541
548
  }
542
549
  });
543
550
  }); };
551
+ this.depositAndStakeExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
552
+ return __generator(this, function (_a) {
553
+ switch (_a.label) {
554
+ case 0: return [4 /*yield*/, this.addLiquidityExpected(amounts)];
555
+ case 1: return [2 /*return*/, _a.sent()];
556
+ }
557
+ });
558
+ }); };
559
+ this.depositAndStakeSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
560
+ return __generator(this, function (_a) {
561
+ switch (_a.label) {
562
+ case 0: return [4 /*yield*/, this.addLiquiditySlippage(amounts)];
563
+ case 1: return [2 /*return*/, _a.sent()];
564
+ }
565
+ });
566
+ }); };
567
+ this.depositAndStakeIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
568
+ var coinsAllowance, gaugeContract, gaugeAllowance;
569
+ return __generator(this, function (_a) {
570
+ switch (_a.label) {
571
+ case 0:
572
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
573
+ throw Error("".concat(this.name, " doesn't have gauge"));
574
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
575
+ case 1:
576
+ coinsAllowance = _a.sent();
577
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
578
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
579
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
580
+ case 2:
581
+ gaugeAllowance = _a.sent();
582
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
583
+ case 3: return [2 /*return*/, coinsAllowance];
584
+ }
585
+ });
586
+ }); };
587
+ this.depositAndStakeApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
588
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
589
+ return __generator(this, function (_a) {
590
+ switch (_a.label) {
591
+ case 0:
592
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
593
+ throw Error("".concat(this.name, " doesn't have gauge"));
594
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
595
+ case 1:
596
+ approveCoinsGas = _a.sent();
597
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
598
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
599
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
600
+ case 2:
601
+ gaugeAllowance = _a.sent();
602
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
603
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
604
+ case 3:
605
+ approveGaugeGas = (_a.sent()).toNumber();
606
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
607
+ case 4: return [2 /*return*/, approveCoinsGas];
608
+ }
609
+ });
610
+ }); };
611
+ this.depositAndStakeApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
612
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
613
+ return __generator(this, function (_a) {
614
+ switch (_a.label) {
615
+ case 0:
616
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
617
+ throw Error("".concat(this.name, " doesn't have gauge"));
618
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
619
+ case 1:
620
+ approveCoinsTx = _a.sent();
621
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
622
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
623
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
624
+ case 2:
625
+ gaugeAllowance = _a.sent();
626
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
627
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
628
+ case 3:
629
+ gasLimit = (_a.sent()).mul(130).div(100);
630
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
631
+ case 4:
632
+ approveGaugeTx = (_a.sent()).hash;
633
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
634
+ case 5: return [2 /*return*/, approveCoinsTx];
635
+ }
636
+ });
637
+ }); };
638
+ this.depositAndStakeEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
639
+ return __generator(this, function (_a) {
640
+ switch (_a.label) {
641
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
642
+ case 1: return [2 /*return*/, _a.sent()];
643
+ }
644
+ });
645
+ }); };
646
+ this.depositAndStake = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
647
+ return __generator(this, function (_a) {
648
+ switch (_a.label) {
649
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
650
+ case 1: return [2 /*return*/, _a.sent()];
651
+ }
652
+ });
653
+ }); };
654
+ this._depositAndStake = function (amounts, isUnderlying, estimateGas) { return __awaiter(_this, void 0, void 0, function () {
655
+ var coinAddresses, coins, decimals, depositAddress, balances, _a, _c, _d, _e, _f, i, allowance, _h, _amounts, contract, useUnderlying, _minMintAmount, _j, _k, _l, _m, _o, ethIndex, value, i, _gas, gasLimit;
656
+ return __generator(this, function (_p) {
657
+ switch (_p.label) {
658
+ case 0:
659
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
660
+ throw Error("".concat(this.name, " doesn't have gauge"));
661
+ coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.coinAddresses, true);
662
+ coins = isUnderlying ? this.underlyingCoins : this.coinAddresses;
663
+ decimals = isUnderlying ? this.underlyingDecimals : this.decimals;
664
+ depositAddress = isUnderlying ? this.zap || this.swap : this.swap;
665
+ if (amounts.length !== coinAddresses.length) {
666
+ throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
667
+ }
668
+ if (!isUnderlying) return [3 /*break*/, 2];
669
+ _d = (_c = Object).values;
670
+ return [4 /*yield*/, this.underlyingCoinBalances()];
671
+ case 1:
672
+ _a = _d.apply(_c, [_p.sent()]);
673
+ return [3 /*break*/, 4];
674
+ case 2:
675
+ _f = (_e = Object).values;
676
+ return [4 /*yield*/, this.coinBalances()];
677
+ case 3:
678
+ _a = _f.apply(_e, [_p.sent()]);
679
+ _p.label = 4;
680
+ case 4:
681
+ balances = _a;
682
+ for (i = 0; i < balances.length; i++) {
683
+ if (Number(balances[i]) < Number(amounts[i])) {
684
+ throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
685
+ }
686
+ }
687
+ if (!isUnderlying) return [3 /*break*/, 6];
688
+ return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
689
+ case 5:
690
+ _h = _p.sent();
691
+ return [3 /*break*/, 8];
692
+ case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
693
+ case 7:
694
+ _h = _p.sent();
695
+ _p.label = 8;
696
+ case 8:
697
+ allowance = _h;
698
+ if (estimateGas && !allowance) {
699
+ throw Error("Token allowance is needed to estimate gas");
700
+ }
701
+ if (!!estimateGas) return [3 /*break*/, 12];
702
+ if (!isUnderlying) return [3 /*break*/, 10];
703
+ return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
704
+ case 9:
705
+ _p.sent();
706
+ return [3 /*break*/, 12];
707
+ case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
708
+ case 11:
709
+ _p.sent();
710
+ _p.label = 12;
711
+ case 12:
712
+ _amounts = amounts.map(function (amount, i) {
713
+ return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
714
+ });
715
+ contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
716
+ useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'));
717
+ if (!isUnderlying) return [3 /*break*/, 14];
718
+ _l = (_k = ethers_1.ethers.utils).parseUnits;
719
+ return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
720
+ case 13:
721
+ _j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
722
+ return [3 /*break*/, 16];
723
+ case 14:
724
+ _o = (_m = ethers_1.ethers.utils).parseUnits;
725
+ return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
726
+ case 15:
727
+ _j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
728
+ _p.label = 16;
729
+ case 16:
730
+ _minMintAmount = _j;
731
+ ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
732
+ value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
733
+ for (i = 0; i < 5; i++) {
734
+ coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
735
+ _amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
736
+ }
737
+ return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
738
+ case 17:
739
+ _gas = (_p.sent());
740
+ if (estimateGas)
741
+ return [2 /*return*/, _gas.toNumber()];
742
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
743
+ case 18:
744
+ _p.sent();
745
+ gasLimit = _gas.mul(200).div(100);
746
+ return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
747
+ case 19: return [2 /*return*/, (_p.sent()).hash];
748
+ }
749
+ });
750
+ }); };
544
751
  this.balancedWrappedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
545
752
  var poolBalances, walletBalances, _a, _c, prices_3, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
546
753
  return __generator(this, function (_d) {
@@ -715,6 +922,131 @@ var Pool = /** @class */ (function () {
715
922
  }
716
923
  });
717
924
  }); };
925
+ this.depositAndStakeWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
926
+ return __generator(this, function (_a) {
927
+ switch (_a.label) {
928
+ case 0:
929
+ if (this.isFake) {
930
+ throw Error("".concat(this.name, " pool doesn't have this method"));
931
+ }
932
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
933
+ case 1: return [2 /*return*/, _a.sent()];
934
+ }
935
+ });
936
+ }); };
937
+ this.depositAndStakeWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
938
+ return __generator(this, function (_a) {
939
+ switch (_a.label) {
940
+ case 0:
941
+ if (this.isFake) {
942
+ throw Error("".concat(this.name, " pool doesn't have this method"));
943
+ }
944
+ return [4 /*yield*/, this.addLiquidityWrappedSlippage(amounts)];
945
+ case 1: return [2 /*return*/, _a.sent()];
946
+ }
947
+ });
948
+ }); };
949
+ this.depositAndStakeWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
950
+ var coinsAllowance, gaugeContract, gaugeAllowance;
951
+ return __generator(this, function (_a) {
952
+ switch (_a.label) {
953
+ case 0:
954
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
955
+ throw Error("".concat(this.name, " doesn't have gauge"));
956
+ if (this.isFake)
957
+ throw Error("".concat(this.name, " pool doesn't have this method"));
958
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
959
+ case 1:
960
+ coinsAllowance = _a.sent();
961
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
962
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
963
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
964
+ case 2:
965
+ gaugeAllowance = _a.sent();
966
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
967
+ case 3: return [2 /*return*/, coinsAllowance];
968
+ }
969
+ });
970
+ }); };
971
+ this.depositAndStakeWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
972
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
973
+ return __generator(this, function (_a) {
974
+ switch (_a.label) {
975
+ case 0:
976
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
977
+ throw Error("".concat(this.name, " doesn't have gauge"));
978
+ if (this.isFake)
979
+ throw Error("".concat(this.name, " pool doesn't have this method"));
980
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
981
+ case 1:
982
+ approveCoinsGas = _a.sent();
983
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
984
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
985
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
986
+ case 2:
987
+ gaugeAllowance = _a.sent();
988
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
989
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
990
+ case 3:
991
+ approveGaugeGas = (_a.sent()).toNumber();
992
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
993
+ case 4: return [2 /*return*/, approveCoinsGas];
994
+ }
995
+ });
996
+ }); };
997
+ this.depositAndStakeWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
998
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
999
+ return __generator(this, function (_a) {
1000
+ switch (_a.label) {
1001
+ case 0:
1002
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1003
+ throw Error("".concat(this.name, " doesn't have gauge"));
1004
+ if (this.isFake)
1005
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1006
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
1007
+ case 1:
1008
+ approveCoinsTx = _a.sent();
1009
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1010
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
1011
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
1012
+ case 2:
1013
+ gaugeAllowance = _a.sent();
1014
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
1015
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
1016
+ case 3:
1017
+ gasLimit = (_a.sent()).mul(130).div(100);
1018
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1019
+ case 4:
1020
+ approveGaugeTx = (_a.sent()).hash;
1021
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
1022
+ case 5: return [2 /*return*/, approveCoinsTx];
1023
+ }
1024
+ });
1025
+ }); };
1026
+ this.depositAndStakeWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1027
+ return __generator(this, function (_a) {
1028
+ switch (_a.label) {
1029
+ case 0:
1030
+ if (this.isFake) {
1031
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1032
+ }
1033
+ return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
1034
+ case 1: return [2 /*return*/, _a.sent()];
1035
+ }
1036
+ });
1037
+ }); };
1038
+ this.depositAndStakeWrapped = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1039
+ return __generator(this, function (_a) {
1040
+ switch (_a.label) {
1041
+ case 0:
1042
+ if (this.isFake) {
1043
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1044
+ }
1045
+ return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
1046
+ case 1: return [2 /*return*/, _a.sent()];
1047
+ }
1048
+ });
1049
+ }); };
718
1050
  this.removeLiquidityExpected = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
719
1051
  var _lpTokenAmount, _expected;
720
1052
  var _this = this;
@@ -745,7 +1077,7 @@ var Pool = /** @class */ (function () {
745
1077
  return __generator(this, function (_a) {
746
1078
  switch (_a.label) {
747
1079
  case 0:
748
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
1080
+ if (!this.zap)
749
1081
  return [2 /*return*/, true];
750
1082
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
751
1083
  case 1: return [2 /*return*/, _a.sent()];
@@ -756,7 +1088,7 @@ var Pool = /** @class */ (function () {
756
1088
  return __generator(this, function (_a) {
757
1089
  switch (_a.label) {
758
1090
  case 0:
759
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
1091
+ if (!this.zap)
760
1092
  return [2 /*return*/, 0];
761
1093
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
762
1094
  case 1: return [2 /*return*/, _a.sent()];
@@ -767,7 +1099,7 @@ var Pool = /** @class */ (function () {
767
1099
  return __generator(this, function (_a) {
768
1100
  switch (_a.label) {
769
1101
  case 0:
770
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
1102
+ if (!this.zap)
771
1103
  return [2 /*return*/, []];
772
1104
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
773
1105
  case 1: return [2 /*return*/, _a.sent()];
@@ -1216,7 +1548,7 @@ var Pool = /** @class */ (function () {
1216
1548
  return __generator(this, function (_a) {
1217
1549
  switch (_a.label) {
1218
1550
  case 0:
1219
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
1551
+ if (!this.zap)
1220
1552
  return [2 /*return*/, true];
1221
1553
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
1222
1554
  case 1: return [2 /*return*/, _a.sent()];
@@ -1227,7 +1559,7 @@ var Pool = /** @class */ (function () {
1227
1559
  return __generator(this, function (_a) {
1228
1560
  switch (_a.label) {
1229
1561
  case 0:
1230
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
1562
+ if (!this.zap)
1231
1563
  return [2 /*return*/, 0];
1232
1564
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
1233
1565
  case 1: return [2 /*return*/, _a.sent()];
@@ -1238,7 +1570,7 @@ var Pool = /** @class */ (function () {
1238
1570
  return __generator(this, function (_a) {
1239
1571
  switch (_a.label) {
1240
1572
  case 0:
1241
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
1573
+ if (!this.zap)
1242
1574
  return [2 /*return*/, []];
1243
1575
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
1244
1576
  case 1: return [2 /*return*/, _a.sent()];
@@ -1408,7 +1740,10 @@ var Pool = /** @class */ (function () {
1408
1740
  this.gaugeDepositIsApproved = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1409
1741
  return __generator(this, function (_a) {
1410
1742
  switch (_a.label) {
1411
- case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
1743
+ case 0:
1744
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1745
+ throw Error("".concat(this.name, " doesn't have gauge"));
1746
+ return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.gauge)];
1412
1747
  case 1: return [2 /*return*/, _a.sent()];
1413
1748
  }
1414
1749
  });
@@ -1416,7 +1751,10 @@ var Pool = /** @class */ (function () {
1416
1751
  this.gaugeDepositApproveEstimateGas = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1417
1752
  return __generator(this, function (_a) {
1418
1753
  switch (_a.label) {
1419
- case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
1754
+ case 0:
1755
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1756
+ throw Error("".concat(this.name, " doesn't have gauge"));
1757
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.gauge)];
1420
1758
  case 1: return [2 /*return*/, _a.sent()];
1421
1759
  }
1422
1760
  });
@@ -1424,7 +1762,10 @@ var Pool = /** @class */ (function () {
1424
1762
  this.gaugeDepositApprove = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1425
1763
  return __generator(this, function (_a) {
1426
1764
  switch (_a.label) {
1427
- case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
1765
+ case 0:
1766
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1767
+ throw Error("".concat(this.name, " doesn't have gauge"));
1768
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.gauge)];
1428
1769
  case 1: return [2 /*return*/, _a.sent()];
1429
1770
  }
1430
1771
  });
@@ -1434,6 +1775,8 @@ var Pool = /** @class */ (function () {
1434
1775
  return __generator(this, function (_a) {
1435
1776
  switch (_a.label) {
1436
1777
  case 0:
1778
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1779
+ throw Error("".concat(this.name, " doesn't have gauge"));
1437
1780
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1438
1781
  return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1439
1782
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
@@ -1445,6 +1788,8 @@ var Pool = /** @class */ (function () {
1445
1788
  return __generator(this, function (_a) {
1446
1789
  switch (_a.label) {
1447
1790
  case 0:
1791
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1792
+ throw Error("".concat(this.name, " doesn't have gauge"));
1448
1793
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1449
1794
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
1450
1795
  case 1:
@@ -1462,6 +1807,8 @@ var Pool = /** @class */ (function () {
1462
1807
  return __generator(this, function (_a) {
1463
1808
  switch (_a.label) {
1464
1809
  case 0:
1810
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1811
+ throw Error("".concat(this.name, " doesn't have gauge"));
1465
1812
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1466
1813
  return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1467
1814
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
@@ -1473,10 +1820,12 @@ var Pool = /** @class */ (function () {
1473
1820
  return __generator(this, function (_a) {
1474
1821
  switch (_a.label) {
1475
1822
  case 0:
1823
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1824
+ throw Error("".concat(this.name, " doesn't have gauge"));
1476
1825
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1477
1826
  return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1478
1827
  case 1:
1479
- gasLimit = (_a.sent()).mul(180).div(100);
1828
+ gasLimit = (_a.sent()).mul(200).div(100);
1480
1829
  return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1481
1830
  case 2: return [2 /*return*/, (_a.sent()).hash];
1482
1831
  }
@@ -1489,6 +1838,8 @@ var Pool = /** @class */ (function () {
1489
1838
  return __generator(this, function (_d) {
1490
1839
  switch (_d.label) {
1491
1840
  case 0:
1841
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1842
+ throw Error("".concat(this.name, " doesn't have gauge"));
1492
1843
  if (curve_1.curve.chainId !== 1)
1493
1844
  throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimableRewards instead"));
1494
1845
  address = address || curve_1.curve.signerAddress;
@@ -1506,6 +1857,8 @@ var Pool = /** @class */ (function () {
1506
1857
  return __generator(this, function (_a) {
1507
1858
  switch (_a.label) {
1508
1859
  case 0:
1860
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1861
+ throw Error("".concat(this.name, " doesn't have gauge"));
1509
1862
  if (curve_1.curve.chainId !== 1)
1510
1863
  throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimRewards instead"));
1511
1864
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
@@ -1525,6 +1878,8 @@ var Pool = /** @class */ (function () {
1525
1878
  return __generator(this, function (_h) {
1526
1879
  switch (_h.label) {
1527
1880
  case 0:
1881
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1882
+ throw Error("".concat(this.name, " doesn't have gauge"));
1528
1883
  address = address || curve_1.curve.signerAddress;
1529
1884
  if (!address)
1530
1885
  throw Error("Need to connect wallet or pass address into args");
@@ -1588,6 +1943,8 @@ var Pool = /** @class */ (function () {
1588
1943
  return __generator(this, function (_a) {
1589
1944
  switch (_a.label) {
1590
1945
  case 0:
1946
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
1947
+ throw Error("".concat(this.name, " doesn't have gauge"));
1591
1948
  gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1592
1949
  if (!("claim_rewards()" in gaugeContract))
1593
1950
  throw Error("".concat(this.name, " pool doesn't have such method"));
@@ -1607,8 +1964,12 @@ var Pool = /** @class */ (function () {
1607
1964
  return __awaiter(_this, void 0, void 0, function () {
1608
1965
  return __generator(this, function (_a) {
1609
1966
  switch (_a.label) {
1610
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
1967
+ case 0:
1968
+ if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
1969
+ return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
1611
1970
  case 1: return [2 /*return*/, _a.sent()];
1971
+ case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoins, true), this.coins, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.coinAddresses, true)], addresses, false))];
1972
+ case 3: return [2 /*return*/, _a.sent()];
1612
1973
  }
1613
1974
  });
1614
1975
  });
@@ -1621,8 +1982,12 @@ var Pool = /** @class */ (function () {
1621
1982
  return __awaiter(_this, void 0, void 0, function () {
1622
1983
  return __generator(this, function (_a) {
1623
1984
  switch (_a.label) {
1624
- case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
1985
+ case 0:
1986
+ if (!(this.gauge === ethers_1.ethers.constants.AddressZero)) return [3 /*break*/, 2];
1987
+ return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken'], [this.lpToken]], addresses, false))];
1625
1988
  case 1: return [2 /*return*/, _a.sent()];
1989
+ case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
1990
+ case 3: return [2 /*return*/, _a.sent()];
1626
1991
  }
1627
1992
  });
1628
1993
  });
@@ -1689,7 +2054,8 @@ var Pool = /** @class */ (function () {
1689
2054
  return __generator(this, function (_a) {
1690
2055
  switch (_a.label) {
1691
2056
  case 0:
1692
- contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2057
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
2058
+ (curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
1693
2059
  i = this._getCoinIdx(inputCoin);
1694
2060
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1695
2061
  case 1: return [2 /*return*/, _a.sent()];
@@ -1701,7 +2067,8 @@ var Pool = /** @class */ (function () {
1701
2067
  return __generator(this, function (_a) {
1702
2068
  switch (_a.label) {
1703
2069
  case 0:
1704
- contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2070
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
2071
+ (curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
1705
2072
  i = this._getCoinIdx(inputCoin);
1706
2073
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1707
2074
  case 1: return [2 /*return*/, _a.sent()];
@@ -1713,7 +2080,8 @@ var Pool = /** @class */ (function () {
1713
2080
  return __generator(this, function (_a) {
1714
2081
  switch (_a.label) {
1715
2082
  case 0:
1716
- contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2083
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
2084
+ (curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
1717
2085
  i = this._getCoinIdx(inputCoin);
1718
2086
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1719
2087
  case 1: return [2 /*return*/, _a.sent()];
@@ -1727,7 +2095,8 @@ var Pool = /** @class */ (function () {
1727
2095
  return __generator(this, function (_d) {
1728
2096
  switch (_d.label) {
1729
2097
  case 0:
1730
- contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2098
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
2099
+ (curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
1731
2100
  i = this._getCoinIdx(inputCoin);
1732
2101
  j = this._getCoinIdx(outputCoin);
1733
2102
  _c = (_a = Object).values;
@@ -1755,8 +2124,12 @@ var Pool = /** @class */ (function () {
1755
2124
  if (!(this.name === "tricrypto2")) return [3 /*break*/, 5];
1756
2125
  return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1757
2126
  case 4: return [2 /*return*/, (_d.sent()).toNumber()];
1758
- case 5: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2127
+ case 5:
2128
+ if (!(curve_1.curve.chainId === 137 && this.isFactory)) return [3 /*break*/, 7];
2129
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1759
2130
  case 6: return [2 /*return*/, (_d.sent()).toNumber()];
2131
+ case 7: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2132
+ case 8: return [2 /*return*/, (_d.sent()).toNumber()];
1760
2133
  }
1761
2134
  });
1762
2135
  });
@@ -1764,11 +2137,12 @@ var Pool = /** @class */ (function () {
1764
2137
  this.exchange = function (inputCoin, outputCoin, amount, maxSlippage) {
1765
2138
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1766
2139
  return __awaiter(_this, void 0, void 0, function () {
1767
- var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, estimatedGas, gasLimit;
2140
+ var contractAddress, i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, exchangeMethod, value, gasLimit_1, gasLimit_2, estimatedGas, gasLimit;
1768
2141
  return __generator(this, function (_a) {
1769
2142
  switch (_a.label) {
1770
2143
  case 0:
1771
- contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2144
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ||
2145
+ (curve_1.curve.chainId === 137 && this.isFactory) ? this.zap : this.swap;
1772
2146
  i = this._getCoinIdx(inputCoin);
1773
2147
  j = this._getCoinIdx(outputCoin);
1774
2148
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
@@ -1793,14 +2167,21 @@ var Pool = /** @class */ (function () {
1793
2167
  gasLimit_1 = (_a.sent()).mul(130).div(100);
1794
2168
  return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_1 }))];
1795
2169
  case 5: return [2 /*return*/, (_a.sent()).hash];
1796
- case 6: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2170
+ case 6:
2171
+ if (!(curve_1.curve.chainId === 137 && this.isFactory)) return [3 /*break*/, 9];
2172
+ return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1797
2173
  case 7:
2174
+ gasLimit_2 = (_a.sent()).mul(140).div(100);
2175
+ return [4 /*yield*/, contract[exchangeMethod](this.swap, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_2 }))];
2176
+ case 8: return [2 /*return*/, (_a.sent()).hash];
2177
+ case 9: return [4 /*yield*/, contract.estimateGas[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2178
+ case 10:
1798
2179
  estimatedGas = _a.sent();
1799
2180
  gasLimit = curve_1.curve.chainId === 137 && this.name === 'ren' ?
1800
2181
  estimatedGas.mul(160).div(100) :
1801
2182
  estimatedGas.mul(130).div(100);
1802
2183
  return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
1803
- case 8: return [2 /*return*/, (_a.sent()).hash];
2184
+ case 11: return [2 /*return*/, (_a.sent()).hash];
1804
2185
  }
1805
2186
  });
1806
2187
  });
@@ -1910,7 +2291,7 @@ var Pool = /** @class */ (function () {
1910
2291
  this.exchangeWrapped = function (inputCoin, outputCoin, amount, maxSlippage) {
1911
2292
  if (maxSlippage === void 0) { maxSlippage = 0.01; }
1912
2293
  return __awaiter(_this, void 0, void 0, function () {
1913
- var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_2, estimatedGas, gasLimit;
2294
+ var i, j, _amount, _expected, outputCoinDecimals, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit_3, estimatedGas, gasLimit;
1914
2295
  return __generator(this, function (_a) {
1915
2296
  switch (_a.label) {
1916
2297
  case 0:
@@ -1937,8 +2318,8 @@ var Pool = /** @class */ (function () {
1937
2318
  if (!(this.name === 'tricrypto2')) return [3 /*break*/, 6];
1938
2319
  return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1939
2320
  case 4:
1940
- gasLimit_2 = (_a.sent()).mul(130).div(100);
1941
- return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_2 }))];
2321
+ gasLimit_3 = (_a.sent()).mul(130).div(100);
2322
+ return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit_3 }))];
1942
2323
  case 5: return [2 /*return*/, (_a.sent()).hash];
1943
2324
  case 6: return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
1944
2325
  case 7:
@@ -1962,6 +2343,8 @@ var Pool = /** @class */ (function () {
1962
2343
  return __generator(this, function (_e) {
1963
2344
  switch (_e.label) {
1964
2345
  case 0:
2346
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
2347
+ throw Error("".concat(this.name, " doesn't have gauge"));
1965
2348
  if (addresses.length == 1 && Array.isArray(addresses[0]))
1966
2349
  addresses = addresses[0];
1967
2350
  votingEscrowContract = curve_1.curve.contracts[curve_1.ALIASES.voting_escrow].multicallContract;
@@ -1999,6 +2382,8 @@ var Pool = /** @class */ (function () {
1999
2382
  return __generator(this, function (_j) {
2000
2383
  switch (_j.label) {
2001
2384
  case 0:
2385
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
2386
+ throw Error("".concat(this.name, " doesn't have gauge"));
2002
2387
  if (accounts.length == 1 && Array.isArray(accounts[0]))
2003
2388
  accounts = accounts[0];
2004
2389
  votingEscrowContract = curve_1.curve.contracts[curve_1.ALIASES.voting_escrow].multicallContract;
@@ -2059,6 +2444,8 @@ var Pool = /** @class */ (function () {
2059
2444
  return __generator(this, function (_c) {
2060
2445
  switch (_c.label) {
2061
2446
  case 0:
2447
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
2448
+ throw Error("".concat(this.name, " doesn't have gauge"));
2062
2449
  gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
2063
2450
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
2064
2451
  gaugeContract.working_balances(address),
@@ -2410,7 +2797,7 @@ var Pool = /** @class */ (function () {
2410
2797
  switch (_a.label) {
2411
2798
  case 0:
2412
2799
  contract = curve_1.curve.contracts[this.zap].contract;
2413
- if (!this.isFactory) return [3 /*break*/, 2];
2800
+ if (!this.isMetaFactory) return [3 /*break*/, 2];
2414
2801
  return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
2415
2802
  case 1: return [2 /*return*/, _a.sent()];
2416
2803
  case 2:
@@ -2506,7 +2893,7 @@ var Pool = /** @class */ (function () {
2506
2893
  this._addLiquidityMetaZap = function (_amounts, estimateGas) {
2507
2894
  if (estimateGas === void 0) { estimateGas = false; }
2508
2895
  return __awaiter(_this, void 0, void 0, function () {
2509
- var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_3, gas, gasLimit;
2896
+ var _minMintAmount, ethIndex, value, contract, gas_1, gasLimit_4, gas, gasLimit;
2510
2897
  return __generator(this, function (_a) {
2511
2898
  switch (_a.label) {
2512
2899
  case 0:
@@ -2521,15 +2908,15 @@ var Pool = /** @class */ (function () {
2521
2908
  ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
2522
2909
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
2523
2910
  contract = curve_1.curve.contracts[this.zap].contract;
2524
- if (!this.isFactory) return [3 /*break*/, 6];
2911
+ if (!this.isMetaFactory) return [3 /*break*/, 6];
2525
2912
  return [4 /*yield*/, contract.estimateGas.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2526
2913
  case 4:
2527
2914
  gas_1 = _a.sent();
2528
2915
  if (estimateGas) {
2529
2916
  return [2 /*return*/, gas_1.toNumber()];
2530
2917
  }
2531
- gasLimit_3 = gas_1.mul(130).div(100);
2532
- return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_3, value: value }))];
2918
+ gasLimit_4 = gas_1.mul(130).div(100);
2919
+ return [4 /*yield*/, contract.add_liquidity(this.swap, _amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4, value: value }))];
2533
2920
  case 5: return [2 /*return*/, (_a.sent()).hash];
2534
2921
  case 6: return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2535
2922
  case 7:
@@ -2732,7 +3119,7 @@ var Pool = /** @class */ (function () {
2732
3119
  this._removeLiquidityMetaZap = function (_lpTokenAmount, estimateGas) {
2733
3120
  if (estimateGas === void 0) { estimateGas = false; }
2734
3121
  return __awaiter(_this, void 0, void 0, function () {
2735
- var _minAmounts, contract, gas_2, gasLimit_4, gas, gasLimit;
3122
+ var _minAmounts, contract, gas_2, gasLimit_5, gas, gasLimit;
2736
3123
  return __generator(this, function (_a) {
2737
3124
  switch (_a.label) {
2738
3125
  case 0:
@@ -2745,15 +3132,15 @@ var Pool = /** @class */ (function () {
2745
3132
  case 3:
2746
3133
  _minAmounts = _a.sent();
2747
3134
  contract = curve_1.curve.contracts[this.zap].contract;
2748
- if (!this.isFactory) return [3 /*break*/, 6];
3135
+ if (!this.isMetaFactory) return [3 /*break*/, 6];
2749
3136
  return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
2750
3137
  case 4:
2751
3138
  gas_2 = _a.sent();
2752
3139
  if (estimateGas) {
2753
3140
  return [2 /*return*/, gas_2.toNumber()];
2754
3141
  }
2755
- gasLimit_4 = gas_2.mul(130).div(100);
2756
- return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_4 }))];
3142
+ gasLimit_5 = gas_2.mul(130).div(100);
3143
+ return [4 /*yield*/, contract.remove_liquidity(this.swap, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_5 }))];
2757
3144
  case 5: return [2 /*return*/, (_a.sent()).hash];
2758
3145
  case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
2759
3146
  case 7:
@@ -2856,7 +3243,7 @@ var Pool = /** @class */ (function () {
2856
3243
  this._removeLiquidityImbalanceMetaZap = function (_amounts, estimateGas) {
2857
3244
  if (estimateGas === void 0) { estimateGas = false; }
2858
3245
  return __awaiter(_this, void 0, void 0, function () {
2859
- var _maxBurnAmount, contract, gas_3, gasLimit_5, gas, gasLimit;
3246
+ var _maxBurnAmount, contract, gas_3, gasLimit_6, gas, gasLimit;
2860
3247
  return __generator(this, function (_a) {
2861
3248
  switch (_a.label) {
2862
3249
  case 0: return [4 /*yield*/, this._calcLpTokenAmountZap(_amounts, false)];
@@ -2869,15 +3256,15 @@ var Pool = /** @class */ (function () {
2869
3256
  _a.label = 3;
2870
3257
  case 3:
2871
3258
  contract = curve_1.curve.contracts[this.zap].contract;
2872
- if (!this.isFactory) return [3 /*break*/, 6];
3259
+ if (!this.isMetaFactory) return [3 /*break*/, 6];
2873
3260
  return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
2874
3261
  case 4:
2875
3262
  gas_3 = _a.sent();
2876
3263
  if (estimateGas) {
2877
3264
  return [2 /*return*/, gas_3.toNumber()];
2878
3265
  }
2879
- gasLimit_5 = gas_3.mul(130).div(100);
2880
- return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_5 }))];
3266
+ gasLimit_6 = gas_3.mul(130).div(100);
3267
+ return [4 /*yield*/, contract.remove_liquidity_imbalance(this.swap, _amounts, _maxBurnAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_6 }))];
2881
3268
  case 5: return [2 /*return*/, (_a.sent())];
2882
3269
  case 6: return [4 /*yield*/, contract.estimateGas.remove_liquidity_imbalance(_amounts, _maxBurnAmount, curve_1.curve.constantOptions)];
2883
3270
  case 7:
@@ -2942,7 +3329,7 @@ var Pool = /** @class */ (function () {
2942
3329
  switch (_a.label) {
2943
3330
  case 0:
2944
3331
  contract = curve_1.curve.contracts[this.zap].contract;
2945
- if (!this.isFactory) return [3 /*break*/, 2];
3332
+ if (!this.isMetaFactory) return [3 /*break*/, 2];
2946
3333
  return [4 /*yield*/, contract.calc_withdraw_one_coin(this.swap, _lpTokenAmount, i, curve_1.curve.constantOptions)];
2947
3334
  case 1: return [2 /*return*/, (_a.sent())];
2948
3335
  case 2: return [4 /*yield*/, contract.calc_withdraw_one_coin(_lpTokenAmount, i, curve_1.curve.constantOptions)];
@@ -2987,7 +3374,7 @@ var Pool = /** @class */ (function () {
2987
3374
  this._removeLiquidityOneCoinZap = function (_lpTokenAmount, i, estimateGas) {
2988
3375
  if (estimateGas === void 0) { estimateGas = false; }
2989
3376
  return __awaiter(_this, void 0, void 0, function () {
2990
- var _minAmount, _a, contract, gas_4, gasLimit_6, gas, gasLimit;
3377
+ var _minAmount, _a, contract, gas_4, gasLimit_7, gas, gasLimit;
2991
3378
  return __generator(this, function (_c) {
2992
3379
  switch (_c.label) {
2993
3380
  case 0:
@@ -3010,15 +3397,15 @@ var Pool = /** @class */ (function () {
3010
3397
  _minAmount = _a;
3011
3398
  _minAmount = _minAmount.mul(99).div(100);
3012
3399
  contract = curve_1.curve.contracts[this.zap].contract;
3013
- if (!this.isFactory) return [3 /*break*/, 9];
3400
+ if (!this.isMetaFactory) return [3 /*break*/, 9];
3014
3401
  return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
3015
3402
  case 7:
3016
3403
  gas_4 = _c.sent();
3017
3404
  if (estimateGas) {
3018
3405
  return [2 /*return*/, gas_4.toNumber()];
3019
3406
  }
3020
- gasLimit_6 = gas_4.mul(130).div(100);
3021
- return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_6 }))];
3407
+ gasLimit_7 = gas_4.mul(130).div(100);
3408
+ return [4 /*yield*/, contract.remove_liquidity_one_coin(this.swap, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_7 }))];
3022
3409
  case 8: return [2 /*return*/, (_c.sent()).hash];
3023
3410
  case 9: return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
3024
3411
  case 10:
@@ -3092,7 +3479,7 @@ var Pool = /** @class */ (function () {
3092
3479
  }
3093
3480
  });
3094
3481
  }); };
3095
- var poolData = curve_1.POOLS_DATA[name];
3482
+ var poolData = __assign(__assign({}, curve_1.POOLS_DATA), (curve_1.curve.constants.FACTORY_POOLS_DATA || {}))[name];
3096
3483
  this.name = name;
3097
3484
  this.referenceAsset = poolData.reference_asset;
3098
3485
  this.swap = poolData.swap_address;
@@ -3111,13 +3498,19 @@ var Pool = /** @class */ (function () {
3111
3498
  this.isFake = poolData.is_fake || false;
3112
3499
  this.isCrypto = poolData.is_crypto || false;
3113
3500
  this.isFactory = poolData.is_factory || false;
3501
+ this.isMetaFactory = poolData.is_meta_factory || false;
3502
+ this.isPlainFactory = poolData.is_plain_factory || false;
3114
3503
  this.basePool = poolData.base_pool || '';
3115
3504
  this.rewardTokens = poolData.reward_tokens || [];
3116
3505
  this.estimateGas = {
3117
3506
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
3118
3507
  addLiquidity: this.addLiquidityEstimateGas,
3508
+ depositAndStakeApprove: this.depositAndStakeApproveEstimateGas,
3509
+ depositAndStake: this.depositAndStakeEstimateGas,
3119
3510
  addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
3120
3511
  addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
3512
+ depositAndStakeWrappedApprove: this.depositAndStakeWrappedApproveEstimateGas,
3513
+ depositAndStakeWrapped: this.depositAndStakeWrappedEstimateGas,
3121
3514
  gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
3122
3515
  gaugeDeposit: this.gaugeDepositEstimateGas,
3123
3516
  gaugeWithdraw: this.gaugeWithdrawEstimateGas,