@curvefi/api 2.54.2 → 2.54.3

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.
@@ -2463,27 +2463,38 @@ var PoolTemplate = /** @class */ (function () {
2463
2463
  };
2464
2464
  PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
2465
2465
  return __awaiter(this, void 0, void 0, function () {
2466
- var prices, _c, value, lpTokenAmount, balancedAmounts, balancedValue;
2467
- return __generator(this, function (_d) {
2468
- switch (_d.label) {
2466
+ var prices, isUseStoredRates, result, value, lpTokenAmount, balancedAmounts, balancedValue;
2467
+ var _this = this;
2468
+ return __generator(this, function (_c) {
2469
+ switch (_c.label) {
2469
2470
  case 0:
2471
+ prices = [];
2472
+ isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
2470
2473
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
2471
2474
  return [4 /*yield*/, this._underlyingPrices()];
2472
2475
  case 1:
2473
- _c = _d.sent();
2474
- return [3 /*break*/, 3];
2476
+ prices = _c.sent();
2477
+ return [3 /*break*/, 5];
2475
2478
  case 2:
2476
- _c = this.underlyingCoins.map(function () { return 1; });
2477
- _d.label = 3;
2479
+ if (!isUseStoredRates) return [3 /*break*/, 4];
2480
+ return [4 /*yield*/, this._stored_rates()];
2478
2481
  case 3:
2479
- prices = _c;
2482
+ result = _c.sent();
2483
+ result.forEach(function (item, index) {
2484
+ prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
2485
+ });
2486
+ return [3 /*break*/, 5];
2487
+ case 4:
2488
+ prices = this.underlyingCoins.map(function () { return 1; });
2489
+ _c.label = 5;
2490
+ case 5:
2480
2491
  value = amounts.map(checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2481
2492
  return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
2482
- case 4:
2483
- lpTokenAmount = _d.sent();
2493
+ case 6:
2494
+ lpTokenAmount = _c.sent();
2484
2495
  return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2485
- case 5:
2486
- balancedAmounts = _d.sent();
2496
+ case 7:
2497
+ balancedAmounts = _c.sent();
2487
2498
  balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2488
2499
  return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2489
2500
  }
@@ -2650,29 +2661,40 @@ var PoolTemplate = /** @class */ (function () {
2650
2661
  };
2651
2662
  PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
2652
2663
  return __awaiter(this, void 0, void 0, function () {
2653
- var prices, _c, coinPrice, amount, _d, value, balancedAmounts, balancedValue;
2654
- return __generator(this, function (_e) {
2655
- switch (_e.label) {
2664
+ var prices, isUseStoredRates, result, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
2665
+ var _this = this;
2666
+ return __generator(this, function (_d) {
2667
+ switch (_d.label) {
2656
2668
  case 0:
2669
+ prices = [];
2670
+ isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
2657
2671
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
2658
2672
  return [4 /*yield*/, this._underlyingPrices()];
2659
2673
  case 1:
2660
- _c = _e.sent();
2661
- return [3 /*break*/, 3];
2674
+ prices = _d.sent();
2675
+ return [3 /*break*/, 5];
2662
2676
  case 2:
2663
- _c = this.underlyingCoins.map(function () { return 1; });
2664
- _e.label = 3;
2677
+ if (!isUseStoredRates) return [3 /*break*/, 4];
2678
+ return [4 /*yield*/, this._stored_rates()];
2665
2679
  case 3:
2666
- prices = _c;
2680
+ result = _d.sent();
2681
+ result.forEach(function (item, index) {
2682
+ prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
2683
+ });
2684
+ return [3 /*break*/, 5];
2685
+ case 4:
2686
+ prices = this.underlyingCoins.map(function () { return 1; });
2687
+ _d.label = 5;
2688
+ case 5:
2667
2689
  coinPrice = prices[this._getCoinIdx(coin)];
2668
- _d = Number;
2690
+ _c = Number;
2669
2691
  return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
2670
- case 4:
2671
- amount = _d.apply(void 0, [_e.sent()]);
2692
+ case 6:
2693
+ amount = _c.apply(void 0, [_d.sent()]);
2672
2694
  value = amount * coinPrice;
2673
2695
  return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2674
- case 5:
2675
- balancedAmounts = _e.sent();
2696
+ case 7:
2697
+ balancedAmounts = _d.sent();
2676
2698
  balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2677
2699
  return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2678
2700
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.54.2",
3
+ "version": "2.54.3",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",