@curvefi/api 2.61.14 → 2.62.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/README.md CHANGED
@@ -1607,7 +1607,9 @@ import curve from "@curvefi/api";
1607
1607
  // factory-v2-221
1608
1608
  const pool = curve.getPool(poolId);
1609
1609
 
1610
- await pool.depositAndStake([10, 10, 10]); // Initial amounts for stable pool must be equal
1610
+ const amounts = await pool.getSeedAmounts(10);
1611
+ // [ '10.0', '10.0', '10.0' ]
1612
+ await pool.depositAndStake(amounts);
1611
1613
  const balances = await pool.stats.underlyingBalances();
1612
1614
  // [ '10.0', '10.0', '10.0' ]
1613
1615
  })()
@@ -1748,17 +1750,19 @@ import curve from "@curvefi/api";
1748
1750
  const pool = curve.getPool(poolId);
1749
1751
 
1750
1752
  // Deposit & Stake Wrapped
1751
-
1752
- await pool.depositAndStakeWrapped([10, 10]); // Initial wrapped amounts for stable metapool must be equal
1753
+
1754
+ const amounts = await pool.getSeedAmounts(10);
1755
+ // [ '10', '9.666800376685890985' ]
1756
+ await pool.depositAndStakeWrapped(amounts);
1753
1757
  const balances = await pool.stats.wrappedBalances();
1754
- // [ '10.0', '10.0' ]
1758
+ // [ '10', '9.666800376685890985' ]
1755
1759
 
1756
1760
  // Or deposit & Stake Underlying
1757
1761
 
1758
- // const amounts = pool.metaUnderlyingSeedAmounts(30);
1759
- // [ '30', '10.000000000000000000', '10.000000', '10.000000' ]
1762
+ // const amounts = pool.getSeedAmounts(10, true); // useUnderlying = true
1763
+ // [ '10', '3.690404151768511181', '3.713621', '2.595975' ]
1760
1764
  // await pool.depositAndStake(amounts);
1761
- // [ '30.0', '9.272021785560442569', '8.927595', '11.800485' ]
1765
+ // [ '10', '3.690404151768511181', '3.713621', '2.595975' ]
1762
1766
  })()
1763
1767
  ```
1764
1768
 
@@ -1891,7 +1895,7 @@ import curve from "@curvefi/api";
1891
1895
  // factory-crypto-155
1892
1896
  const pool = curve.getPool(poolId);
1893
1897
 
1894
- const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1898
+ const amounts = await pool.getSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1895
1899
  // [ '30', '0.02' ]
1896
1900
  await pool.depositAndStake(amounts);
1897
1901
  const underlyingBalances = await pool.stats.underlyingBalances();
@@ -1943,7 +1947,7 @@ import curve from "@curvefi/api";
1943
1947
  // factory-twocrypto-155
1944
1948
  const pool = curve.getPool(poolId);
1945
1949
 
1946
- const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1950
+ const amounts = await pool.getSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1947
1951
  // [ '30', '0.02' ]
1948
1952
  await pool.depositAndStake(amounts);
1949
1953
  const underlyingBalances = await pool.stats.underlyingBalances();
@@ -2030,7 +2034,7 @@ import curve from "@curvefi/api";
2030
2034
  // factory-tricrypto-2
2031
2035
  const pool = curve.getPool(poolId);
2032
2036
 
2033
- const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
2037
+ const amounts = await pool.getSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
2034
2038
  // [ '30', '0.017647058823529412', '0.00111111' ]
2035
2039
  await pool.depositAndStake(amounts);
2036
2040
  const underlyingBalances = await pool.stats.underlyingBalances();
@@ -112,8 +112,7 @@ export declare class PoolTemplate {
112
112
  private _calcLpTokenAmount;
113
113
  private calcLpTokenAmount;
114
114
  private calcLpTokenAmountWrapped;
115
- metaUnderlyingSeedAmounts(amount1: number | string): string[];
116
- cryptoSeedAmounts(amount1: number | string): Promise<string[]>;
115
+ getSeedAmounts(amount1: number | string, useUnderlying?: boolean): Promise<string[]>;
117
116
  depositBalancedAmounts(): Promise<string[]>;
118
117
  depositExpected(amounts: (number | string)[]): Promise<string>;
119
118
  private _balancedAmountsWithSameValue;
@@ -260,7 +259,7 @@ export declare class PoolTemplate {
260
259
  private _getCoinIdx;
261
260
  private _getRates;
262
261
  private _balances;
263
- private _stored_rates;
262
+ private _storedRatesBN;
264
263
  private _underlyingPrices;
265
264
  private _wrappedPrices;
266
265
  private getGaugeStatus;
@@ -412,7 +412,7 @@ var PoolTemplate = /** @class */ (function () {
412
412
  if (isDeposit === void 0) { isDeposit = true; }
413
413
  if (useUnderlying === void 0) { useUnderlying = true; }
414
414
  return __awaiter(_this, void 0, void 0, function () {
415
- var e_2, lpContract, _lpTotalSupply, decimals_1, amounts, seedAmounts_1, contract, basePool, e_3, lpContract, _lpTotalSupply, decimals_2, amounts_1, seedAmounts_2, _amounts18Decimals;
415
+ var e_2, lpContract, _lpTotalSupply, decimals_1, amounts, seedAmounts_1, contract, basePool, e_3, lpContract, _lpTotalSupply, decimals_2, amounts, seedAmounts_2, _amounts18Decimals;
416
416
  return __generator(this, function (_c) {
417
417
  switch (_c.label) {
418
418
  case 0:
@@ -434,7 +434,7 @@ var PoolTemplate = /** @class */ (function () {
434
434
  throw Error("Initial deposit for crypto meta pools must be in wrapped coins");
435
435
  decimals_1 = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
436
436
  amounts = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_1[i]); });
437
- return [4 /*yield*/, this.cryptoSeedAmounts(amounts[0])];
437
+ return [4 /*yield*/, this.getSeedAmounts(amounts[0])];
438
438
  case 5:
439
439
  seedAmounts_1 = _c.sent();
440
440
  amounts.forEach(function (a, i) {
@@ -443,7 +443,7 @@ var PoolTemplate = /** @class */ (function () {
443
443
  });
444
444
  return [2 /*return*/, parseUnits(Math.pow(amounts.map(Number).reduce(function (a, b) { return a * b; }), 1 / amounts.length))];
445
445
  case 6:
446
- _c.trys.push([6, 13, , 15]);
446
+ _c.trys.push([6, 13, , 16]);
447
447
  contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
448
448
  if (!(curve.constants.ALIASES.stable_calc === curve.constants.ZERO_ADDRESS || this.id.startsWith("factory-stable-ng"))) return [3 /*break*/, 8];
449
449
  return [4 /*yield*/, this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying)];
@@ -455,7 +455,7 @@ var PoolTemplate = /** @class */ (function () {
455
455
  case 9: return [2 /*return*/, _c.sent()];
456
456
  case 10: return [4 /*yield*/, contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending)];
457
457
  case 11: return [2 /*return*/, _c.sent()];
458
- case 12: return [3 /*break*/, 15];
458
+ case 12: return [3 /*break*/, 16];
459
459
  case 13:
460
460
  e_3 = _c.sent();
461
461
  if (!isDeposit)
@@ -467,25 +467,17 @@ var PoolTemplate = /** @class */ (function () {
467
467
  if (_lpTotalSupply > curve.parseUnits("0"))
468
468
  throw e_3; // Already seeded
469
469
  decimals_2 = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
470
- amounts_1 = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_2[i]); });
471
- if (this.isMeta && useUnderlying) {
472
- seedAmounts_2 = this.metaUnderlyingSeedAmounts(amounts_1[0]);
473
- amounts_1.forEach(function (a, i) {
474
- if (!BN(a).eq(BN(seedAmounts_2[i])))
475
- throw Error("Amounts must be = ".concat(seedAmounts_2));
476
- });
477
- }
478
- else {
479
- if (_amounts[0] <= curve.parseUnits("0"))
480
- throw Error("Initial deposit amounts must be > 0");
481
- amounts_1.forEach(function (a) {
482
- if (a !== amounts_1[0])
483
- throw Error("Initial deposit amounts must be equal");
484
- });
485
- }
486
- _amounts18Decimals = amounts_1.map(function (a) { return parseUnits(a); });
470
+ amounts = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_2[i]); });
471
+ return [4 /*yield*/, this.getSeedAmounts(amounts[0])];
472
+ case 15:
473
+ seedAmounts_2 = _c.sent();
474
+ amounts.forEach(function (a, i) {
475
+ if (!BN(a).eq(BN(seedAmounts_2[i])))
476
+ throw Error("Amounts must be = ".concat(seedAmounts_2));
477
+ });
478
+ _amounts18Decimals = amounts.map(function (a) { return parseUnits(a); });
487
479
  return [2 /*return*/, _amounts18Decimals.reduce(function (_a, _b) { return _a + _b; })];
488
- case 15: return [2 /*return*/];
480
+ case 16: return [2 /*return*/];
489
481
  }
490
482
  });
491
483
  });
@@ -1110,11 +1102,27 @@ var PoolTemplate = /** @class */ (function () {
1110
1102
  });
1111
1103
  });
1112
1104
  };
1113
- this._stored_rates = function () { return __awaiter(_this, void 0, void 0, function () {
1105
+ this._storedRatesBN = function (useUnderlying) { return __awaiter(_this, void 0, void 0, function () {
1106
+ var _vp, isUseStoredRates, _stored_rates;
1107
+ var _this = this;
1114
1108
  return __generator(this, function (_c) {
1115
1109
  switch (_c.label) {
1116
- case 0: return [4 /*yield*/, curve.contracts[this.address].contract.stored_rates()];
1117
- case 1: return [2 /*return*/, _c.sent()];
1110
+ case 0:
1111
+ if (!this.isMeta) return [3 /*break*/, 2];
1112
+ if (useUnderlying)
1113
+ return [2 /*return*/, this.underlyingCoins.map(function () { return BN(1); })];
1114
+ return [4 /*yield*/, curve.contracts[curve.getPoolsData()[this.basePool].swap_address].contract.get_virtual_price()];
1115
+ case 1:
1116
+ _vp = _c.sent();
1117
+ return [2 /*return*/, [BN(1), toBN(_vp)]];
1118
+ case 2:
1119
+ isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
1120
+ if (!isUseStoredRates) return [3 /*break*/, 4];
1121
+ return [4 /*yield*/, curve.contracts[this.address].contract.stored_rates()];
1122
+ case 3:
1123
+ _stored_rates = _c.sent();
1124
+ return [2 /*return*/, _stored_rates.map(function (_r, i) { return toBN(_r, 36 - _this.wrappedDecimals[i]); })];
1125
+ case 4: return [2 /*return*/, this.wrappedCoins.map(function () { return BN(1); })];
1118
1126
  }
1119
1127
  });
1120
1128
  }); };
@@ -1374,32 +1382,18 @@ var PoolTemplate = /** @class */ (function () {
1374
1382
  });
1375
1383
  };
1376
1384
  // ---------------- DEPOSIT ----------------
1377
- PoolTemplate.prototype.metaUnderlyingSeedAmounts = function (amount1) {
1378
- if (this.isCrypto)
1379
- throw Error("Use cryptoSeedAmounts method for ".concat(this.name, " pool"));
1380
- if (!this.isMeta)
1381
- throw Error("metaUnderlyingSeedAmounts method exists only for meta stable pools");
1382
- var amount1BN = BN(amount1);
1383
- if (amount1BN.lte(0))
1384
- throw Error("Initial deposit amounts must be > 0");
1385
- var amounts = [_cutZeros(amount1BN.toFixed(this.underlyingDecimals[0]))];
1386
- for (var i = 1; i < this.underlyingDecimals.length; i++) {
1387
- amounts.push(amount1BN.div(this.underlyingDecimals.length - 1).toFixed(this.underlyingDecimals[i]));
1388
- }
1389
- return amounts;
1390
- };
1391
- PoolTemplate.prototype.cryptoSeedAmounts = function (amount1) {
1385
+ PoolTemplate.prototype.getSeedAmounts = function (amount1, useUnderlying) {
1386
+ if (useUnderlying === void 0) { useUnderlying = false; }
1392
1387
  return __awaiter(this, void 0, void 0, function () {
1393
- var decimals, amount1BN, priceScaleBN, _c, priceScaleBN;
1388
+ var amount1BN, decimals, priceScaleBN, _c, priceScaleBN, amounts, basePool, basePoolBalancesBN, totalBN, i, storedRatesBN, i;
1394
1389
  return __generator(this, function (_d) {
1395
1390
  switch (_d.label) {
1396
1391
  case 0:
1397
- if (!this.isCrypto)
1398
- throw Error("cryptoSeedAmounts method doesn't exist for stable pools");
1399
- decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
1400
1392
  amount1BN = BN(amount1);
1401
1393
  if (amount1BN.lte(0))
1402
1394
  throw Error("Initial deposit amounts must be > 0");
1395
+ if (!this.isCrypto) return [3 /*break*/, 5];
1396
+ decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
1403
1397
  if (!(decimals.length === 2)) return [3 /*break*/, 2];
1404
1398
  _c = toBN;
1405
1399
  return [4 /*yield*/, curve.contracts[this.address].contract.price_scale(curve.constantOptions)];
@@ -1419,7 +1413,26 @@ var PoolTemplate = /** @class */ (function () {
1419
1413
  _cutZeros(amount1BN.div(priceScaleBN[0]).toFixed(decimals[1])),
1420
1414
  _cutZeros(amount1BN.div(priceScaleBN[1]).toFixed(decimals[2])),
1421
1415
  ]];
1422
- case 4: throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 3");
1416
+ case 4: throw Error("getSeedAmounts method doesn't exist for crypto pools with N coins > 3");
1417
+ case 5:
1418
+ amounts = [_cutZeros(amount1BN.toFixed(this.wrappedDecimals[0]))];
1419
+ if (!(this.isMeta && useUnderlying)) return [3 /*break*/, 7];
1420
+ basePool = new PoolTemplate(this.basePool);
1421
+ return [4 /*yield*/, basePool.stats.underlyingBalances()];
1422
+ case 6:
1423
+ basePoolBalancesBN = (_d.sent()).map(BN);
1424
+ totalBN = basePoolBalancesBN.reduce(function (a, b) { return a.plus(b); });
1425
+ for (i = 1; i < this.underlyingDecimals.length; i++) {
1426
+ amounts.push(amount1BN.times(basePoolBalancesBN[i - 1]).div(totalBN).toFixed(this.underlyingDecimals[i]));
1427
+ }
1428
+ return [2 /*return*/, amounts.map(_cutZeros)];
1429
+ case 7: return [4 /*yield*/, this._storedRatesBN(false)];
1430
+ case 8:
1431
+ storedRatesBN = _d.sent();
1432
+ for (i = 1; i < this.wrappedDecimals.length; i++) {
1433
+ amounts.push(amount1BN.times(storedRatesBN[0]).div(storedRatesBN[i]).toFixed(this.wrappedDecimals[i]));
1434
+ }
1435
+ return [2 /*return*/, amounts.map(_cutZeros)];
1423
1436
  }
1424
1437
  });
1425
1438
  });
@@ -1470,46 +1483,34 @@ var PoolTemplate = /** @class */ (function () {
1470
1483
  };
1471
1484
  PoolTemplate.prototype.depositBonus = function (amounts) {
1472
1485
  return __awaiter(this, void 0, void 0, function () {
1473
- var amountsBN, prices, isUseStoredRates, result, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1474
- var _this = this;
1486
+ var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1475
1487
  return __generator(this, function (_e) {
1476
1488
  switch (_e.label) {
1477
1489
  case 0:
1478
1490
  amountsBN = amounts.map(BN);
1479
- prices = [];
1480
- isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
1491
+ pricesBN = [];
1481
1492
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
1482
1493
  return [4 /*yield*/, this._underlyingPrices()];
1483
1494
  case 1:
1484
- prices = _e.sent();
1485
- return [3 /*break*/, 5];
1486
- case 2:
1487
- if (!isUseStoredRates) return [3 /*break*/, 4];
1488
- return [4 /*yield*/, this._stored_rates()];
1495
+ pricesBN = (_e.sent()).map(BN);
1496
+ return [3 /*break*/, 4];
1497
+ case 2: return [4 /*yield*/, this._storedRatesBN(true)];
1489
1498
  case 3:
1490
- result = _e.sent();
1491
- result.forEach(function (item, index) {
1492
- prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
1493
- });
1494
- return [3 /*break*/, 5];
1495
- case 4:
1496
- prices = this.underlyingCoins.map(function () { return 1; });
1497
- _e.label = 5;
1499
+ pricesBN = _e.sent();
1500
+ _e.label = 4;
1501
+ case 4: return [4 /*yield*/, this.stats.underlyingBalances()];
1498
1502
  case 5:
1499
- pricesBN = prices.map(BN);
1500
- return [4 /*yield*/, this.stats.underlyingBalances()];
1501
- case 6:
1502
1503
  balancesBN = (_e.sent()).map(BN);
1503
1504
  balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
1504
1505
  _c = BN;
1505
1506
  return [4 /*yield*/, this.depositExpected(amounts)];
1506
- case 7:
1507
+ case 6:
1507
1508
  expectedBN = _c.apply(void 0, [_e.sent()]);
1508
1509
  _d = BN;
1509
1510
  return [4 /*yield*/, this.depositExpected(balancedAmounts)];
1510
- case 8:
1511
+ case 7:
1511
1512
  balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
1512
- return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
1513
+ return [2 /*return*/, expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100).toString()];
1513
1514
  }
1514
1515
  });
1515
1516
  });
@@ -2468,40 +2469,30 @@ var PoolTemplate = /** @class */ (function () {
2468
2469
  };
2469
2470
  PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
2470
2471
  return __awaiter(this, void 0, void 0, function () {
2471
- var prices, isUseStoredRates, result, value, lpTokenAmount, balancedAmounts, balancedValue;
2472
- var _this = this;
2472
+ var pricesBN, valueBN, lpTokenAmount, balancedAmounts, balancedValueBN;
2473
2473
  return __generator(this, function (_c) {
2474
2474
  switch (_c.label) {
2475
2475
  case 0:
2476
- prices = [];
2477
- isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
2476
+ pricesBN = [];
2478
2477
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
2479
2478
  return [4 /*yield*/, this._underlyingPrices()];
2480
2479
  case 1:
2481
- prices = _c.sent();
2482
- return [3 /*break*/, 5];
2483
- case 2:
2484
- if (!isUseStoredRates) return [3 /*break*/, 4];
2485
- return [4 /*yield*/, this._stored_rates()];
2480
+ pricesBN = (_c.sent()).map(BN);
2481
+ return [3 /*break*/, 4];
2482
+ case 2: return [4 /*yield*/, this._storedRatesBN(true)];
2486
2483
  case 3:
2487
- result = _c.sent();
2488
- result.forEach(function (item, index) {
2489
- prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
2490
- });
2491
- return [3 /*break*/, 5];
2484
+ pricesBN = _c.sent();
2485
+ _c.label = 4;
2492
2486
  case 4:
2493
- prices = this.underlyingCoins.map(function () { return 1; });
2494
- _c.label = 5;
2495
- case 5:
2496
- value = amounts.map(checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2487
+ valueBN = amounts.map(BN).reduce(function (sBN, aBN, i) { return pricesBN[i].times(aBN).plus(sBN); }, BN(0));
2497
2488
  return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
2498
- case 6:
2489
+ case 5:
2499
2490
  lpTokenAmount = _c.sent();
2500
2491
  return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2501
- case 7:
2492
+ case 6:
2502
2493
  balancedAmounts = _c.sent();
2503
- balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2504
- return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2494
+ balancedValueBN = balancedAmounts.map(BN).reduce(function (sBN, aBN, i) { return pricesBN[i].times(aBN).plus(sBN); }, BN(0));
2495
+ return [2 /*return*/, valueBN.minus(balancedValueBN).div(balancedValueBN).times(100).toString()];
2505
2496
  }
2506
2497
  });
2507
2498
  });
@@ -2666,42 +2657,32 @@ var PoolTemplate = /** @class */ (function () {
2666
2657
  };
2667
2658
  PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
2668
2659
  return __awaiter(this, void 0, void 0, function () {
2669
- var prices, isUseStoredRates, result, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
2670
- var _this = this;
2660
+ var pricesBN, coinPriceBN, amountBN, _c, valueBN, balancedAmounts, balancedValueBN;
2671
2661
  return __generator(this, function (_d) {
2672
2662
  switch (_d.label) {
2673
2663
  case 0:
2674
- prices = [];
2675
- isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
2664
+ pricesBN = [];
2676
2665
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
2677
2666
  return [4 /*yield*/, this._underlyingPrices()];
2678
2667
  case 1:
2679
- prices = _d.sent();
2680
- return [3 /*break*/, 5];
2681
- case 2:
2682
- if (!isUseStoredRates) return [3 /*break*/, 4];
2683
- return [4 /*yield*/, this._stored_rates()];
2668
+ pricesBN = (_d.sent()).map(BN);
2669
+ return [3 /*break*/, 4];
2670
+ case 2: return [4 /*yield*/, this._storedRatesBN(true)];
2684
2671
  case 3:
2685
- result = _d.sent();
2686
- result.forEach(function (item, index) {
2687
- prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
2688
- });
2689
- return [3 /*break*/, 5];
2672
+ pricesBN = _d.sent();
2673
+ _d.label = 4;
2690
2674
  case 4:
2691
- prices = this.underlyingCoins.map(function () { return 1; });
2692
- _d.label = 5;
2693
- case 5:
2694
- coinPrice = prices[this._getCoinIdx(coin)];
2695
- _c = Number;
2675
+ coinPriceBN = pricesBN[this._getCoinIdx(coin)];
2676
+ _c = BN;
2696
2677
  return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
2697
- case 6:
2698
- amount = _c.apply(void 0, [_d.sent()]);
2699
- value = amount * coinPrice;
2678
+ case 5:
2679
+ amountBN = _c.apply(void 0, [_d.sent()]);
2680
+ valueBN = amountBN.times(coinPriceBN);
2700
2681
  return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2701
- case 7:
2682
+ case 6:
2702
2683
  balancedAmounts = _d.sent();
2703
- balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2704
- return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2684
+ balancedValueBN = balancedAmounts.map(BN).reduce(function (sBN, aBN, i) { return pricesBN[i].times(aBN).plus(sBN); }, BN(0));
2685
+ return [2 /*return*/, valueBN.minus(balancedValueBN).div(balancedValueBN).times(100).toString()];
2705
2686
  }
2706
2687
  });
2707
2688
  });
package/lib/utils.js CHANGED
@@ -69,7 +69,7 @@ export var ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
69
69
  export var MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
70
70
  // Formatting numbers
71
71
  export var _cutZeros = function (strn) {
72
- return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
72
+ return strn.replace(/(\.\d*[1-9])0+$/gi, '$1').replace(/\.0+$/gi, '');
73
73
  };
74
74
  export var checkNumber = function (n) {
75
75
  if (Number(n) !== Number(n))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.61.14",
3
+ "version": "2.62.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",