@curvefi/api 2.52.5 → 2.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,8 +56,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
56
  };
57
57
  import memoize from "memoizee";
58
58
  import { _getPoolsFromApi, _getSubgraphData, _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes } from '../external-api.js';
59
- import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, } from '../utils.js';
60
- import { curve as _curve, curve } from "../curve.js";
59
+ import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, isMethodExist, } from '../utils.js';
60
+ import { curve } from "../curve.js";
61
61
  import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
62
62
  var DAY = 86400;
63
63
  var WEEK = 7 * DAY;
@@ -293,30 +293,19 @@ var PoolTemplate = /** @class */ (function () {
293
293
  }
294
294
  });
295
295
  }); };
296
- this.statsTokenApy = function (useApi) {
297
- if (useApi === void 0) { useApi = true; }
296
+ this._calcTokenApy = function (futureWorkingSupplyBN) {
297
+ if (futureWorkingSupplyBN === void 0) { futureWorkingSupplyBN = null; }
298
298
  return __awaiter(_this, void 0, void 0, function () {
299
- var isDisabledChain, crvAPYs, poolCrvApy, totalLiquidityUSD, inflationRateBN, workingSupplyBN, totalSupplyBN, gaugeContract, lpTokenContract, crvContract, currentWeek, _c, gaugeContract, lpTokenContract, gaugeControllerContract, weightBN, rateBN, crvPrice, baseApyBN, boostedApyBN;
299
+ var totalLiquidityUSD, inflationRateBN, workingSupplyBN, totalSupplyBN, gaugeContract, lpTokenContract, crvContract, currentWeek, _c, gaugeContract, lpTokenContract, gaugeControllerContract, weightBN, rateBN, crvPrice, baseApyBN, boostedApyBN;
300
300
  var _d, _e;
301
- var _f;
302
- return __generator(this, function (_g) {
303
- switch (_g.label) {
304
- case 0:
305
- if (this.rewardsOnly())
306
- throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
307
- isDisabledChain = [1313161554].includes(curve.chainId);
308
- if (!(useApi && !isDisabledChain)) return [3 /*break*/, 2];
309
- return [4 /*yield*/, _getCrvApyFromApi()];
301
+ return __generator(this, function (_f) {
302
+ switch (_f.label) {
303
+ case 0: return [4 /*yield*/, this.statsTotalLiquidity()];
310
304
  case 1:
311
- crvAPYs = _g.sent();
312
- poolCrvApy = (_f = crvAPYs[this.gauge]) !== null && _f !== void 0 ? _f : [0, 0];
313
- return [2 /*return*/, [poolCrvApy[0], poolCrvApy[1]]];
314
- case 2: return [4 /*yield*/, this.statsTotalLiquidity()];
315
- case 3:
316
- totalLiquidityUSD = _g.sent();
305
+ totalLiquidityUSD = _f.sent();
317
306
  if (Number(totalLiquidityUSD) === 0)
318
307
  return [2 /*return*/, [0, 0]];
319
- if (!(curve.chainId !== 1)) return [3 /*break*/, 7];
308
+ if (!(curve.chainId !== 1)) return [3 /*break*/, 5];
320
309
  gaugeContract = curve.contracts[this.gauge].multicallContract;
321
310
  lpTokenContract = curve.contracts[this.lpToken].multicallContract;
322
311
  crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
@@ -326,16 +315,16 @@ var PoolTemplate = /** @class */ (function () {
326
315
  gaugeContract.working_supply(),
327
316
  lpTokenContract.totalSupply(),
328
317
  ])];
329
- case 4:
330
- _d = (_g.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _d[0], workingSupplyBN = _d[1], totalSupplyBN = _d[2];
331
- if (!inflationRateBN.eq(0)) return [3 /*break*/, 6];
318
+ case 2:
319
+ _d = (_f.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _d[0], workingSupplyBN = _d[1], totalSupplyBN = _d[2];
320
+ if (!inflationRateBN.eq(0)) return [3 /*break*/, 4];
332
321
  _c = toBN;
333
322
  return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve.constantOptions)];
323
+ case 3:
324
+ inflationRateBN = _c.apply(void 0, [_f.sent()]).div(WEEK);
325
+ _f.label = 4;
326
+ case 4: return [3 /*break*/, 7];
334
327
  case 5:
335
- inflationRateBN = _c.apply(void 0, [_g.sent()]).div(WEEK);
336
- _g.label = 6;
337
- case 6: return [3 /*break*/, 9];
338
- case 7:
339
328
  gaugeContract = curve.contracts[this.gauge].multicallContract;
340
329
  lpTokenContract = curve.contracts[this.lpToken].multicallContract;
341
330
  gaugeControllerContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
@@ -346,17 +335,19 @@ var PoolTemplate = /** @class */ (function () {
346
335
  gaugeContract.working_supply(),
347
336
  lpTokenContract.totalSupply(),
348
337
  ])];
349
- case 8:
350
- _e = (_g.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingSupplyBN = _e[2], totalSupplyBN = _e[3];
338
+ case 6:
339
+ _e = (_f.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingSupplyBN = _e[2], totalSupplyBN = _e[3];
351
340
  inflationRateBN = inflationRateBN.times(weightBN);
352
- _g.label = 9;
353
- case 9:
341
+ _f.label = 7;
342
+ case 7:
354
343
  if (inflationRateBN.eq(0))
355
344
  return [2 /*return*/, [0, 0]];
356
- rateBN = inflationRateBN.times(31536000).times(0.4).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD));
345
+ if (futureWorkingSupplyBN !== null)
346
+ workingSupplyBN = futureWorkingSupplyBN;
347
+ rateBN = inflationRateBN.times(31536000).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)).times(0.4);
357
348
  return [4 /*yield*/, _getUsdRate(curve.constants.ALIASES.crv)];
358
- case 10:
359
- crvPrice = _g.sent();
349
+ case 8:
350
+ crvPrice = _f.sent();
360
351
  baseApyBN = rateBN.times(crvPrice);
361
352
  boostedApyBN = baseApyBN.times(2.5);
362
353
  return [2 /*return*/, [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()]];
@@ -364,6 +355,29 @@ var PoolTemplate = /** @class */ (function () {
364
355
  });
365
356
  });
366
357
  };
358
+ this.statsTokenApy = function (useApi) {
359
+ if (useApi === void 0) { useApi = true; }
360
+ return __awaiter(_this, void 0, void 0, function () {
361
+ var isDisabledChain, crvAPYs, poolCrvApy;
362
+ var _c;
363
+ return __generator(this, function (_d) {
364
+ switch (_d.label) {
365
+ case 0:
366
+ if (this.rewardsOnly())
367
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
368
+ isDisabledChain = [1313161554].includes(curve.chainId);
369
+ if (!(useApi && !isDisabledChain)) return [3 /*break*/, 2];
370
+ return [4 /*yield*/, _getCrvApyFromApi()];
371
+ case 1:
372
+ crvAPYs = _d.sent();
373
+ poolCrvApy = (_c = crvAPYs[this.gauge]) !== null && _c !== void 0 ? _c : [0, 0];
374
+ return [2 /*return*/, [poolCrvApy[0], poolCrvApy[1]]];
375
+ case 2: return [4 /*yield*/, this._calcTokenApy()];
376
+ case 3: return [2 /*return*/, _d.sent()];
377
+ }
378
+ });
379
+ });
380
+ };
367
381
  this.statsRewardsApy = function (useApi) {
368
382
  if (useApi === void 0) { useApi = true; }
369
383
  return __awaiter(_this, void 0, void 0, function () {
@@ -592,7 +606,7 @@ var PoolTemplate = /** @class */ (function () {
592
606
  });
593
607
  });
594
608
  };
595
- this.boost = function (address) {
609
+ this.userBoost = function (address) {
596
610
  if (address === void 0) { address = ""; }
597
611
  return __awaiter(_this, void 0, void 0, function () {
598
612
  var gaugeContract, _c, workingBalanceBN, balanceBN, boostBN;
@@ -601,9 +615,9 @@ var PoolTemplate = /** @class */ (function () {
601
615
  case 0:
602
616
  if (this.gauge === curve.constants.ZERO_ADDRESS)
603
617
  throw Error("".concat(this.name, " doesn't have gauge"));
604
- address = address || curve.signerAddress;
605
- if (!address)
606
- throw Error("Need to connect wallet or pass address into args");
618
+ if (this.rewardsOnly())
619
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
620
+ address = _getAddress(address);
607
621
  gaugeContract = curve.contracts[this.gauge].multicallContract;
608
622
  return [4 /*yield*/, curve.multicallProvider.all([
609
623
  gaugeContract.working_balances(address),
@@ -621,27 +635,106 @@ var PoolTemplate = /** @class */ (function () {
621
635
  });
622
636
  });
623
637
  };
638
+ this._userFutureBoostAndWorkingSupply = function (address) { return __awaiter(_this, void 0, void 0, function () {
639
+ var veContractMulticall, gaugeContractMulticall, calls, _c, _votingBalance, _votingTotal, _gaugeBalance, _gaugeTotal, _workingBalance, _workingSupply, _futureWorkingBalance, _futureWorkingSupply, futureWorkingBalanceBN, balanceBN, boostBN;
640
+ return __generator(this, function (_d) {
641
+ switch (_d.label) {
642
+ case 0:
643
+ veContractMulticall = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
644
+ gaugeContractMulticall = curve.contracts[this.gauge].multicallContract;
645
+ calls = [
646
+ veContractMulticall.balanceOf(address),
647
+ veContractMulticall.totalSupply(),
648
+ gaugeContractMulticall.balanceOf(address),
649
+ gaugeContractMulticall.totalSupply(),
650
+ gaugeContractMulticall.working_balances(address),
651
+ gaugeContractMulticall.working_supply(),
652
+ ];
653
+ return [4 /*yield*/, curve.multicallProvider.all(calls)];
654
+ case 1:
655
+ _c = _d.sent(), _votingBalance = _c[0], _votingTotal = _c[1], _gaugeBalance = _c[2], _gaugeTotal = _c[3], _workingBalance = _c[4], _workingSupply = _c[5];
656
+ _futureWorkingBalance = _gaugeBalance * BigInt(40) / BigInt(100);
657
+ if (_votingTotal > BigInt(0)) {
658
+ _futureWorkingBalance += _gaugeTotal * _votingBalance / _votingTotal * BigInt(60) / BigInt(100);
659
+ }
660
+ if (_futureWorkingBalance > _gaugeBalance)
661
+ _futureWorkingBalance = _gaugeBalance;
662
+ _futureWorkingSupply = _workingSupply - _workingBalance + _futureWorkingBalance;
663
+ futureWorkingBalanceBN = toBN(_futureWorkingBalance);
664
+ balanceBN = toBN(_gaugeBalance);
665
+ boostBN = futureWorkingBalanceBN.div(0.4).div(balanceBN);
666
+ return [2 /*return*/, [boostBN, toBN(_futureWorkingSupply)]];
667
+ }
668
+ });
669
+ }); };
670
+ this.userFutureBoost = function (address) {
671
+ if (address === void 0) { address = ""; }
672
+ return __awaiter(_this, void 0, void 0, function () {
673
+ var boostBN;
674
+ return __generator(this, function (_c) {
675
+ switch (_c.label) {
676
+ case 0:
677
+ if (this.rewardsOnly())
678
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
679
+ address = _getAddress(address);
680
+ return [4 /*yield*/, this._userFutureBoostAndWorkingSupply(address)];
681
+ case 1:
682
+ boostBN = (_c.sent())[0];
683
+ if (boostBN.lt(1))
684
+ return [2 /*return*/, '1.0'];
685
+ if (boostBN.gt(2.5))
686
+ return [2 /*return*/, '2.5'];
687
+ return [2 /*return*/, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
688
+ }
689
+ });
690
+ });
691
+ };
624
692
  this.userCrvApy = function (address) {
625
693
  if (address === void 0) { address = ""; }
626
694
  return __awaiter(_this, void 0, void 0, function () {
627
- var _c, baseApy, maxApy, boost;
695
+ var _c, minApy, maxApy, boost;
628
696
  return __generator(this, function (_d) {
629
697
  switch (_d.label) {
630
698
  case 0:
631
- address = address || curve.signerAddress;
632
- if (!address)
633
- throw Error("Need to connect wallet or pass address into args");
699
+ if (this.rewardsOnly())
700
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
701
+ address = _getAddress(address);
634
702
  return [4 /*yield*/, this.statsTokenApy()];
635
703
  case 1:
636
- _c = _d.sent(), baseApy = _c[0], maxApy = _c[1];
637
- return [4 /*yield*/, this.boost(address)];
704
+ _c = _d.sent(), minApy = _c[0], maxApy = _c[1];
705
+ return [4 /*yield*/, this.userBoost(address)];
638
706
  case 2:
639
707
  boost = _d.sent();
640
708
  if (boost == "2.5")
641
709
  return [2 /*return*/, maxApy];
642
710
  if (boost === "NaN")
643
711
  return [2 /*return*/, NaN];
644
- return [2 /*return*/, BN(baseApy).times(BN(boost)).toNumber()];
712
+ return [2 /*return*/, BN(minApy).times(BN(boost)).toNumber()];
713
+ }
714
+ });
715
+ });
716
+ };
717
+ this.userFutureCrvApy = function (address) {
718
+ if (address === void 0) { address = ""; }
719
+ return __awaiter(_this, void 0, void 0, function () {
720
+ var _c, boostBN, futureWorkingSupplyBN, _d, minApy, maxApy;
721
+ return __generator(this, function (_e) {
722
+ switch (_e.label) {
723
+ case 0:
724
+ if (this.rewardsOnly())
725
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
726
+ address = _getAddress(address);
727
+ return [4 /*yield*/, this._userFutureBoostAndWorkingSupply(address)];
728
+ case 1:
729
+ _c = _e.sent(), boostBN = _c[0], futureWorkingSupplyBN = _c[1];
730
+ return [4 /*yield*/, this._calcTokenApy(futureWorkingSupplyBN)];
731
+ case 2:
732
+ _d = _e.sent(), minApy = _d[0], maxApy = _d[1];
733
+ if (boostBN.lt(1))
734
+ return [2 /*return*/, minApy];
735
+ if (boostBN.gt(2.5))
736
+ return [2 /*return*/, maxApy];
737
+ return [2 /*return*/, BN(minApy).times(boostBN).toNumber()];
645
738
  }
646
739
  });
647
740
  });
@@ -825,7 +918,7 @@ var PoolTemplate = /** @class */ (function () {
825
918
  return [3 /*break*/, 3];
826
919
  case 6: return [3 /*break*/, 14];
827
920
  case 7:
828
- if (!(this.sRewardContract && "rewardRate()" in _curve.contracts[this.sRewardContract].contract && "periodFinish()" && rewardTokens.length === 1)) return [3 /*break*/, 10];
921
+ if (!(this.sRewardContract && "rewardRate()" in curve.contracts[this.sRewardContract].contract && "periodFinish()" && rewardTokens.length === 1)) return [3 /*break*/, 10];
829
922
  rewardToken = rewardTokens[0];
830
923
  sRewardContract = curve.contracts[this.sRewardContract].multicallContract;
831
924
  return [4 /*yield*/, curve.multicallProvider.all([
@@ -1052,6 +1145,14 @@ var PoolTemplate = /** @class */ (function () {
1052
1145
  });
1053
1146
  });
1054
1147
  };
1148
+ this._stored_rates = function () { return __awaiter(_this, void 0, void 0, function () {
1149
+ return __generator(this, function (_c) {
1150
+ switch (_c.label) {
1151
+ case 0: return [4 /*yield*/, curve.contracts[this.address].contract.stored_rates()];
1152
+ case 1: return [2 /*return*/, _c.sent()];
1153
+ }
1154
+ });
1155
+ }); };
1055
1156
  this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
1056
1157
  var promises, _i, _c, addr;
1057
1158
  return __generator(this, function (_d) {
@@ -1103,6 +1204,7 @@ var PoolTemplate = /** @class */ (function () {
1103
1204
  this.isFake = poolData.is_fake || false;
1104
1205
  this.isFactory = poolData.is_factory || false;
1105
1206
  this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
1207
+ this.isStableNg = poolData.is_stable_ng || false;
1106
1208
  this.isLlamma = poolData.is_llamma || false;
1107
1209
  this.basePool = poolData.base_pool || '';
1108
1210
  this.metaCoinIdx = this.isMeta ? (_c = poolData.meta_coin_idx) !== null && _c !== void 0 ? _c : poolData.wrapped_coins.length - 1 : -1;
@@ -1403,34 +1505,45 @@ var PoolTemplate = /** @class */ (function () {
1403
1505
  };
1404
1506
  PoolTemplate.prototype.depositBonus = function (amounts) {
1405
1507
  return __awaiter(this, void 0, void 0, function () {
1406
- var amountsBN, prices, _c, pricesBN, balancesBN, balancedAmounts, expectedBN, _d, balancedExpectedBN, _e;
1407
- return __generator(this, function (_f) {
1408
- switch (_f.label) {
1508
+ var amountsBN, prices, isUseStoredRates, result, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1509
+ var _this = this;
1510
+ return __generator(this, function (_e) {
1511
+ switch (_e.label) {
1409
1512
  case 0:
1410
1513
  amountsBN = amounts.map(BN);
1411
- if (!(this.isCrypto || this.id === 'wsteth' || this.id === 'factory-crvusd-24')) return [3 /*break*/, 2];
1514
+ prices = [];
1515
+ isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
1516
+ if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
1412
1517
  return [4 /*yield*/, this._underlyingPrices()];
1413
1518
  case 1:
1414
- _c = _f.sent();
1415
- return [3 /*break*/, 3];
1519
+ prices = _e.sent();
1520
+ return [3 /*break*/, 5];
1416
1521
  case 2:
1417
- _c = this.underlyingCoins.map(function () { return 1; });
1418
- _f.label = 3;
1522
+ if (!isUseStoredRates) return [3 /*break*/, 4];
1523
+ return [4 /*yield*/, this._stored_rates()];
1419
1524
  case 3:
1420
- prices = _c;
1525
+ result = _e.sent();
1526
+ result.forEach(function (item, index) {
1527
+ prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
1528
+ });
1529
+ return [3 /*break*/, 5];
1530
+ case 4:
1531
+ prices = this.underlyingCoins.map(function () { return 1; });
1532
+ _e.label = 5;
1533
+ case 5:
1421
1534
  pricesBN = prices.map(BN);
1422
1535
  return [4 /*yield*/, this.stats.underlyingBalances()];
1423
- case 4:
1424
- balancesBN = (_f.sent()).map(BN);
1536
+ case 6:
1537
+ balancesBN = (_e.sent()).map(BN);
1425
1538
  balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
1426
- _d = BN;
1539
+ _c = BN;
1427
1540
  return [4 /*yield*/, this.depositExpected(amounts)];
1428
- case 5:
1429
- expectedBN = _d.apply(void 0, [_f.sent()]);
1430
- _e = BN;
1541
+ case 7:
1542
+ expectedBN = _c.apply(void 0, [_e.sent()]);
1543
+ _d = BN;
1431
1544
  return [4 /*yield*/, this.depositExpected(balancedAmounts)];
1432
- case 6:
1433
- balancedExpectedBN = _e.apply(void 0, [_f.sent()]);
1545
+ case 8:
1546
+ balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
1434
1547
  return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
1435
1548
  }
1436
1549
  });
package/lib/utils.d.ts CHANGED
@@ -23,6 +23,7 @@ export declare const _getCoinAddresses: (...coins: string[] | string[][]) => str
23
23
  export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
24
24
  export declare const _getBalances: (coins: string[], addresses: string[]) => Promise<IDict<string[]>>;
25
25
  export declare const _prepareAddresses: (addresses: string[] | string[][]) => string[];
26
+ export declare const _getAddress: (address: string) => string;
26
27
  export declare const getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<IDict<string[]> | string[]>;
27
28
  export declare const _getAllowance: (coins: string[], address: string, spender: string) => Promise<bigint[]>;
28
29
  export declare const getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
@@ -56,5 +57,6 @@ export declare const getCoinsData: (...coins: string[] | string[][]) => Promise<
56
57
  export declare const hasDepositAndStake: () => boolean;
57
58
  export declare const hasRouter: () => boolean;
58
59
  export declare const getCountArgsOfMethodByContract: (contract: Contract, methodName: string) => number;
60
+ export declare const isMethodExist: (contract: Contract, methodName: string) => boolean;
59
61
  export declare const getPoolName: (name: string) => string;
60
62
  export declare const assetTypeNameHandler: (assetTypeName: string) => REFERENCE_ASSET;
package/lib/utils.js CHANGED
@@ -234,6 +234,12 @@ export var _prepareAddresses = function (addresses) {
234
234
  addresses = addresses;
235
235
  return addresses.filter(function (val, idx, arr) { return arr.indexOf(val) === idx; });
236
236
  };
237
+ export var _getAddress = function (address) {
238
+ address = address || curve.signerAddress;
239
+ if (!address)
240
+ throw Error("Need to connect wallet or pass address into args");
241
+ return address;
242
+ };
237
243
  export var getBalances = function (coins) {
238
244
  var addresses = [];
239
245
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -369,7 +375,7 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
369
375
  export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
370
376
  if (isMax === void 0) { isMax = true; }
371
377
  return __awaiter(void 0, void 0, void 0, function () {
372
- var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, currentGas_1, _a, currentGas, _b;
378
+ var coinAddresses, decimals, _amounts, address, _allowance, gas, i, contract, _approveAmount, currentGas, _a, currentGas, _b;
373
379
  return __generator(this, function (_c) {
374
380
  switch (_c.label) {
375
381
  case 0:
@@ -379,22 +385,29 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
379
385
  address = curve.signerAddress;
380
386
  return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
381
387
  case 1:
382
- allowance = _c.sent();
388
+ _allowance = _c.sent();
383
389
  gas = [0, 0];
384
390
  i = 0;
385
391
  _c.label = 2;
386
392
  case 2:
387
- if (!(i < allowance.length)) return [3 /*break*/, 7];
388
- if (!(allowance[i] < _amounts[i])) return [3 /*break*/, 6];
393
+ if (!(i < _allowance.length)) return [3 /*break*/, 7];
394
+ if (!(_allowance[i] < _amounts[i])) return [3 /*break*/, 6];
389
395
  contract = curve.contracts[coinAddresses[i]].contract;
390
396
  _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
391
- if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
397
+ if (!(_allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
392
398
  _a = smartNumber;
393
399
  return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
394
400
  case 3:
395
- currentGas_1 = _a.apply(void 0, [_c.sent()]);
396
- gas = gasSum(gas, currentGas_1);
397
- _c.label = 4;
401
+ currentGas = _a.apply(void 0, [_c.sent()]);
402
+ // For some coins (crv for example ) we can't estimate the second tx gas (approve: 0 --> amount), so we assume it will cost the same amount of gas
403
+ if (typeof currentGas === "number") {
404
+ currentGas = currentGas * 2;
405
+ }
406
+ else {
407
+ currentGas = currentGas.map(function (g) { return g * 2; });
408
+ }
409
+ gas = gasSum(gas, currentGas);
410
+ return [3 /*break*/, 6];
398
411
  case 4:
399
412
  _b = smartNumber;
400
413
  return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
@@ -429,10 +442,13 @@ export var ensureAllowance = function (coins, amounts, spender, isMax) {
429
442
  };
430
443
  export var getPoolIdBySwapAddress = function (swapAddress) {
431
444
  var poolsData = curve.getPoolsData();
432
- return Object.entries(poolsData).filter(function (_a) {
445
+ var poolIds = Object.entries(poolsData).filter(function (_a) {
433
446
  var _ = _a[0], poolData = _a[1];
434
447
  return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
435
- })[0][0];
448
+ });
449
+ if (poolIds.length === 0)
450
+ return "";
451
+ return poolIds[0][0];
436
452
  };
437
453
  var _getTokenAddressBySwapAddress = function (swapAddress) {
438
454
  var poolsData = curve.getPoolsData();
@@ -898,6 +914,15 @@ export var getCountArgsOfMethodByContract = function (contract, methodName) {
898
914
  return -1;
899
915
  }
900
916
  };
917
+ export var isMethodExist = function (contract, methodName) {
918
+ var func = contract.interface.fragments.find(function (item) { return item.name === methodName; });
919
+ if (func) {
920
+ return true;
921
+ }
922
+ else {
923
+ return false;
924
+ }
925
+ };
901
926
  export var getPoolName = function (name) {
902
927
  var separatedName = name.split(": ");
903
928
  if (separatedName.length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.52.5",
3
+ "version": "2.53.1",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",