@curvefi/api 2.8.2 → 2.8.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.
@@ -95,6 +95,7 @@ export declare class PoolTemplate {
95
95
  private statsBaseApy;
96
96
  private statsTokenApy;
97
97
  private statsRewardsApy;
98
+ private _pureCalcLpTokenAmount;
98
99
  private _calcLpTokenAmount;
99
100
  private calcLpTokenAmount;
100
101
  private calcLpTokenAmountWrapped;
@@ -322,6 +322,76 @@ var PoolTemplate = /** @class */ (function () {
322
322
  }
323
323
  });
324
324
  }); };
325
+ this._calcLpTokenAmount = (0, memoizee_1.default)(function (_amounts, isDeposit, useUnderlying) {
326
+ if (isDeposit === void 0) { isDeposit = true; }
327
+ if (useUnderlying === void 0) { useUnderlying = true; }
328
+ return __awaiter(_this, void 0, void 0, function () {
329
+ var _rates_1, N_coins, decimals, calcContractAddress, calcContract, poolContract, lpContract, calls, res, _c, _totalSupply, _fee, _lpTokenAmount, balances, _d, totalSupplyBN, feeBN, lpTokenAmountBN, balancesBN, amountsBN, feesBN, i, _fees, _lpTokenFee;
330
+ return __generator(this, function (_e) {
331
+ switch (_e.label) {
332
+ case 0:
333
+ if (!(!this.isMeta && useUnderlying)) return [3 /*break*/, 2];
334
+ return [4 /*yield*/, this._getRates()];
335
+ case 1:
336
+ _rates_1 = _e.sent();
337
+ _amounts = _amounts.map(function (_amount, i) {
338
+ return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
339
+ });
340
+ _e.label = 2;
341
+ case 2:
342
+ if (!this.isCrypto) return [3 /*break*/, 4];
343
+ return [4 /*yield*/, this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying)];
344
+ case 3: return [2 /*return*/, _e.sent()];
345
+ case 4:
346
+ N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
347
+ decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
348
+ calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
349
+ calcContract = curve_1.curve.contracts[calcContractAddress].multicallContract;
350
+ poolContract = curve_1.curve.contracts[this.address].multicallContract;
351
+ lpContract = curve_1.curve.contracts[this.lpToken].multicallContract;
352
+ calls = [lpContract.totalSupply(), poolContract.fee()];
353
+ // lpAmount before fees
354
+ if (this.isMetaFactory && useUnderlying) {
355
+ calls.push(calcContract.calc_token_amount(this.address, _amounts, isDeposit));
356
+ }
357
+ else if (calcContract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) {
358
+ calls.push(calcContract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions));
359
+ }
360
+ else {
361
+ calls.push(calcContract.calc_token_amount(_amounts, curve_1.curve.constantOptions));
362
+ }
363
+ return [4 /*yield*/, Promise.all([
364
+ curve_1.curve.multicallProvider.all(calls),
365
+ useUnderlying ? this.stats.underlyingBalances() : this.stats.wrappedBalances(),
366
+ ])];
367
+ case 5:
368
+ res = _e.sent();
369
+ _c = res[0], _totalSupply = _c[0], _fee = _c[1], _lpTokenAmount = _c[2];
370
+ balances = res[1];
371
+ _d = [(0, utils_1.toBN)(_totalSupply), (0, utils_1.toBN)(_fee, 10).times(N_coins).div(4 * (N_coins - 1)), (0, utils_1.toBN)(_lpTokenAmount)], totalSupplyBN = _d[0], feeBN = _d[1], lpTokenAmountBN = _d[2];
372
+ balancesBN = balances.map(function (b) { return (0, utils_1.BN)(b); });
373
+ amountsBN = _amounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, decimals[i]); });
374
+ feesBN = [];
375
+ for (i = 0; i < N_coins; i++) {
376
+ feesBN[i] = balancesBN[i].times(lpTokenAmountBN).div(totalSupplyBN).minus(amountsBN[i]).times(feeBN);
377
+ if (feesBN[i].lt(0))
378
+ feesBN[i] = feesBN[i].times(-1);
379
+ }
380
+ _fees = feesBN.map(function (fBN, i) { return (0, utils_1.fromBN)(fBN, decimals[i]); });
381
+ return [4 /*yield*/, this._pureCalcLpTokenAmount(_fees, !isDeposit, useUnderlying)];
382
+ case 6:
383
+ _lpTokenFee = _e.sent();
384
+ if (isDeposit)
385
+ _lpTokenFee = _lpTokenFee.mul(-1);
386
+ return [2 /*return*/, _lpTokenAmount.add(_lpTokenFee)];
387
+ }
388
+ });
389
+ });
390
+ }, {
391
+ primitive: true,
392
+ promise: true,
393
+ maxAge: 1 * 60 * 1000, // 1m
394
+ });
325
395
  // ---------------- CRV PROFIT, CLAIM, BOOSTING ----------------
326
396
  this.crvProfit = function (address) {
327
397
  if (address === void 0) { address = ""; }
@@ -984,68 +1054,26 @@ var PoolTemplate = /** @class */ (function () {
984
1054
  });
985
1055
  });
986
1056
  };
987
- PoolTemplate.prototype._calcLpTokenAmount = function (_amounts, isDeposit, useUnderlying) {
1057
+ PoolTemplate.prototype._pureCalcLpTokenAmount = function (_amounts, isDeposit, useUnderlying) {
988
1058
  if (isDeposit === void 0) { isDeposit = true; }
989
1059
  if (useUnderlying === void 0) { useUnderlying = true; }
990
1060
  return __awaiter(this, void 0, void 0, function () {
991
- var _rates_1, N_coins, decimals, calcContractAddress, calcContract, poolContract, lpContract, calls, res, _c, _totalSupply, _fee, _expected1, balances, _d, totalSupplyBN, feeBN, expected1BN, balancesBN, amountsBN, feesBN, i, _newAmounts, contract;
992
- return __generator(this, function (_e) {
993
- switch (_e.label) {
1061
+ var calcContractAddress, N_coins, contract;
1062
+ return __generator(this, function (_c) {
1063
+ switch (_c.label) {
994
1064
  case 0:
995
- if (!(!this.isMeta && useUnderlying)) return [3 /*break*/, 2];
996
- return [4 /*yield*/, this._getRates()];
997
- case 1:
998
- _rates_1 = _e.sent();
999
- _amounts = _amounts.map(function (_amount, i) {
1000
- return _amount.mul(ethers_1.ethers.BigNumber.from(10).pow(18)).div(_rates_1[i]);
1001
- });
1002
- _e.label = 2;
1003
- case 2:
1004
- N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
1005
- decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
1006
1065
  calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
1007
- calcContract = curve_1.curve.contracts[calcContractAddress].multicallContract;
1008
- poolContract = curve_1.curve.contracts[this.address].multicallContract;
1009
- lpContract = curve_1.curve.contracts[this.lpToken].multicallContract;
1010
- calls = [lpContract.totalSupply(), poolContract.fee()];
1011
- // lpAmount before fees
1012
- if (this.isMetaFactory && useUnderlying) {
1013
- calls.push(calcContract.calc_token_amount(this.address, _amounts, isDeposit));
1014
- }
1015
- else if (calcContract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) {
1016
- calls.push(calcContract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions));
1017
- }
1018
- else {
1019
- calls.push(calcContract.calc_token_amount(_amounts, curve_1.curve.constantOptions));
1020
- }
1021
- return [4 /*yield*/, Promise.all([
1022
- curve_1.curve.multicallProvider.all(calls),
1023
- useUnderlying ? this.stats.underlyingBalances() : this.stats.wrappedBalances(),
1024
- ])];
1025
- case 3:
1026
- res = _e.sent();
1027
- _c = res[0], _totalSupply = _c[0], _fee = _c[1], _expected1 = _c[2];
1028
- balances = res[1];
1029
- _d = [(0, utils_1.toBN)(_totalSupply), (0, utils_1.toBN)(_fee, 10).times(N_coins).div(4 * (N_coins - 1)), (0, utils_1.toBN)(_expected1)], totalSupplyBN = _d[0], feeBN = _d[1], expected1BN = _d[2];
1030
- balancesBN = balances.map(function (b) { return (0, utils_1.BN)(b); });
1031
- amountsBN = _amounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, decimals[i]); });
1032
- feesBN = [];
1033
- for (i = 0; i < N_coins; i++) {
1034
- feesBN[i] = balancesBN[i].times(expected1BN).div(totalSupplyBN).minus(amountsBN[i]).times(feeBN);
1035
- if (feesBN[i].lt(0))
1036
- feesBN[i] = feesBN[i].times(-1);
1037
- }
1038
- _newAmounts = amountsBN.map(function (aBN, i) { return (0, utils_1.fromBN)(isDeposit ? aBN.minus(feesBN[i]) : aBN.plus(feesBN[i]), decimals[i]); });
1066
+ N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
1039
1067
  contract = curve_1.curve.contracts[calcContractAddress].contract;
1040
- if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 5];
1041
- return [4 /*yield*/, contract.calc_token_amount(this.address, _newAmounts, isDeposit, curve_1.curve.constantOptions)];
1042
- case 4: return [2 /*return*/, _e.sent()];
1043
- case 5:
1044
- if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 7];
1045
- return [4 /*yield*/, contract.calc_token_amount(_newAmounts, isDeposit, curve_1.curve.constantOptions)];
1046
- case 6: return [2 /*return*/, _e.sent()];
1047
- case 7: return [4 /*yield*/, contract.calc_token_amount(_newAmounts, curve_1.curve.constantOptions)];
1048
- case 8: return [2 /*return*/, _e.sent()];
1068
+ if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 2];
1069
+ return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve_1.curve.constantOptions)];
1070
+ case 1: return [2 /*return*/, _c.sent()];
1071
+ case 2:
1072
+ if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 4];
1073
+ return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
1074
+ case 3: return [2 /*return*/, _c.sent()];
1075
+ case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1076
+ case 5: return [2 /*return*/, _c.sent()];
1049
1077
  }
1050
1078
  });
1051
1079
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.8.2",
3
+ "version": "2.8.3",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",