@curvefi/api 2.4.1 → 2.5.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 (33) hide show
  1. package/lib/constants/abis/factory-v2/DepositZapFantom.json +164 -0
  2. package/lib/constants/abis/factory-v2/DepositZapMetaUsd2Fantom.json +197 -0
  3. package/lib/constants/abis/factory-v2/MetaUSDGeist.json +932 -0
  4. package/lib/constants/abis/fusdt/swap.json +1221 -0
  5. package/lib/constants/abis/fusdt/zap.json +215 -0
  6. package/lib/constants/abis/gauge_child.json +0 -100
  7. package/lib/constants/abis/gauge_rewards_only.json +649 -0
  8. package/lib/constants/abis/ren-fantom/swap.json +868 -0
  9. package/lib/constants/abis/tricrypto/swapNoZap.json +1250 -0
  10. package/lib/constants/aliases.d.ts +1 -0
  11. package/lib/constants/aliases.js +14 -2
  12. package/lib/constants/coins/fantom.d.ts +7 -0
  13. package/lib/constants/coins/fantom.js +36 -0
  14. package/lib/constants/pools/fantom.d.ts +4 -0
  15. package/lib/constants/pools/fantom.js +191 -0
  16. package/lib/constants/pools/index.d.ts +2 -1
  17. package/lib/constants/pools/index.js +3 -1
  18. package/lib/curve.js +31 -10
  19. package/lib/factory/common.js +19 -0
  20. package/lib/factory/constants.d.ts +11 -2
  21. package/lib/factory/constants.js +58 -3
  22. package/lib/factory/factory-api.js +4 -3
  23. package/lib/factory/factory-crypto.js +14 -10
  24. package/lib/factory/factory.js +3 -0
  25. package/lib/pools/PoolTemplate.d.ts +1 -2
  26. package/lib/pools/PoolTemplate.js +44 -166
  27. package/lib/pools/mixins/depositBonusMixins.js +52 -26
  28. package/lib/pools/mixins/withdrawBonusMixins.d.ts +7 -0
  29. package/lib/pools/mixins/withdrawBonusMixins.js +216 -0
  30. package/lib/pools/poolConstructor.js +20 -2
  31. package/lib/router.js +6 -6
  32. package/lib/utils.js +3 -0
  33. package/package.json +1 -1
@@ -197,8 +197,9 @@ function setCryptoFactoryCoinsContracts(coinAddresses) {
197
197
  }
198
198
  function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
199
199
  return __awaiter(this, void 0, void 0, function () {
200
+ var _this = this;
200
201
  return __generator(this, function (_a) {
201
- return [2 /*return*/, coinAddresses.map(function (coins) { return coins.map(function (c) { return c === constants_1.WETH_ADDRESS ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : c; }); })];
202
+ return [2 /*return*/, coinAddresses.map(function (coins) { return coins.map(function (c) { return c === constants_1.NATIVE_TOKENS[_this.chainId].wrappedAddress ? constants_1.NATIVE_TOKEN_ADDRESS : c; }); })];
202
203
  });
203
204
  });
204
205
  }
@@ -221,11 +222,13 @@ function getExistingCoinAddressNameDict() {
221
222
  _loop_1(poolData);
222
223
  }
223
224
  if (this.chainId === 1)
224
- dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "ETH";
225
+ dict[constants_1.NATIVE_TOKEN_ADDRESS] = "ETH";
225
226
  if (this.chainId === 137)
226
- dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "MATIC";
227
+ dict[constants_1.NATIVE_TOKEN_ADDRESS] = "MATIC";
228
+ if (this.chainId === 250)
229
+ dict[constants_1.NATIVE_TOKEN_ADDRESS] = "FTM";
227
230
  if (this.chainId === 43114)
228
- dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "AVAX";
231
+ dict[constants_1.NATIVE_TOKEN_ADDRESS] = "AVAX";
229
232
  return dict;
230
233
  }
231
234
  function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
@@ -259,6 +262,7 @@ function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
259
262
  newCoinAddresses.forEach(function (addr, i) {
260
263
  coinAddrNamesDict[addr] = names[i];
261
264
  });
265
+ coinAddrNamesDict[constants_1.NATIVE_TOKEN_ADDRESS] = constants_1.NATIVE_TOKENS[this.chainId].symbol;
262
266
  return [2 /*return*/, coinAddrNamesDict];
263
267
  }
264
268
  });
@@ -266,18 +270,18 @@ function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
266
270
  }
267
271
  function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDict) {
268
272
  return __awaiter(this, void 0, void 0, function () {
269
- var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, _i, flattenedCoinAddresses_3, addr, calls, decimals;
273
+ var flattenedCoinAddresses, newCoinAddresses, coinAddressDecimalsDict, _i, flattenedCoinAddresses_3, addr, calls, decimals;
270
274
  var _this = this;
271
275
  return __generator(this, function (_a) {
272
276
  switch (_a.label) {
273
277
  case 0:
274
278
  flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
275
279
  newCoinAddresses = [];
276
- coinAddrNamesDict = {};
280
+ coinAddressDecimalsDict = {};
277
281
  for (_i = 0, flattenedCoinAddresses_3 = flattenedCoinAddresses; _i < flattenedCoinAddresses_3.length; _i++) {
278
282
  addr = flattenedCoinAddresses_3[_i];
279
283
  if (addr in existingCoinAddressDecimalsDict) {
280
- coinAddrNamesDict[addr] = existingCoinAddressDecimalsDict[addr];
284
+ coinAddressDecimalsDict[addr] = existingCoinAddressDecimalsDict[addr];
281
285
  }
282
286
  else {
283
287
  newCoinAddresses.push(addr);
@@ -290,10 +294,10 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
290
294
  case 1:
291
295
  decimals = (_a.sent()).map(function (_d) { return Number(ethers_1.ethers.utils.formatUnits(_d, 0)); });
292
296
  newCoinAddresses.forEach(function (addr, i) {
293
- coinAddrNamesDict[addr] = decimals[i];
297
+ coinAddressDecimalsDict[addr] = decimals[i];
294
298
  });
295
- coinAddrNamesDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 18;
296
- return [2 /*return*/, coinAddrNamesDict];
299
+ coinAddressDecimalsDict[constants_1.NATIVE_TOKEN_ADDRESS] = 18;
300
+ return [2 /*return*/, coinAddressDecimalsDict];
297
301
  }
298
302
  });
299
303
  });
@@ -63,6 +63,7 @@ var BLACK_LIST = {
63
63
  "0xe4199bc5c5c1f63dba47b56b6db7144c51cf0bf8",
64
64
  "0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
65
65
  ],
66
+ 250: [],
66
67
  43114: [],
67
68
  };
68
69
  var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
@@ -255,6 +256,8 @@ function getExistingCoinAddressNameDict() {
255
256
  dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "ETH";
256
257
  if (this.chainId === 137)
257
258
  dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "MATIC";
259
+ if (this.chainId === 250)
260
+ dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "FTM";
258
261
  if (this.chainId === 43114)
259
262
  dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "AVAX";
260
263
  return dict;
@@ -86,6 +86,7 @@ export declare class PoolTemplate {
86
86
  allCoinBalances: (...addresses: string[] | string[][]) => Promise<IDict<IDict<string>> | IDict<string>>;
87
87
  };
88
88
  constructor(id: string);
89
+ rewardsOnly(): boolean;
89
90
  private statsParameters;
90
91
  private statsWrappedBalances;
91
92
  private statsUnderlyingBalances;
@@ -238,6 +239,4 @@ export declare class PoolTemplate {
238
239
  private _balances;
239
240
  private _underlyingPrices;
240
241
  private _wrappedPrices;
241
- private _withdrawCryptoBonus;
242
- private _withdrawBonus;
243
242
  }
@@ -203,8 +203,8 @@ var PoolTemplate = /** @class */ (function () {
203
203
  return __generator(this, function (_e) {
204
204
  switch (_e.label) {
205
205
  case 0:
206
- if (this.gauge === ethers_1.ethers.constants.AddressZero)
207
- throw Error("".concat(this.name, " doesn't have gauge"));
206
+ if (this.rewardsOnly())
207
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use getRewardsApy instead"));
208
208
  return [4 /*yield*/, this.statsTotalLiquidity()];
209
209
  case 1:
210
210
  totalLiquidityUSD = _e.sent();
@@ -255,12 +255,14 @@ var PoolTemplate = /** @class */ (function () {
255
255
  });
256
256
  }); };
257
257
  this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
258
- var apy, rewardTokens, _i, rewardTokens_1, rewardToken, gaugeContract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _a, mainPoolsRewards, allTypesExtendedPoolData, rewards, _c, _d, extendedPoolData, _e, _f, pool;
258
+ var apy, rewardTokens, _i, rewardTokens_1, rewardToken, contract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _a, mainPoolsRewards, allTypesExtendedPoolData, rewards, _c, _d, extendedPoolData, _e, _f, pool;
259
259
  var _g;
260
260
  return __generator(this, function (_h) {
261
261
  switch (_h.label) {
262
262
  case 0:
263
- if (![137, 43114].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
263
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
264
+ return [2 /*return*/, []];
265
+ if (![137, 250, 43114].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
264
266
  apy = [];
265
267
  return [4 /*yield*/, this.rewardTokens()];
266
268
  case 1:
@@ -270,14 +272,14 @@ var PoolTemplate = /** @class */ (function () {
270
272
  case 2:
271
273
  if (!(_i < rewardTokens_1.length)) return [3 /*break*/, 7];
272
274
  rewardToken = rewardTokens_1[_i];
273
- gaugeContract = curve_1.curve.contracts[this.gauge].contract;
275
+ contract = curve_1.curve.contracts[this.sRewardContract || this.gauge].contract;
274
276
  return [4 /*yield*/, this.statsTotalLiquidity()];
275
277
  case 3:
276
278
  totalLiquidityUSD = _h.sent();
277
279
  return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
278
280
  case 4:
279
281
  rewardRate = _h.sent();
280
- return [4 /*yield*/, gaugeContract.reward_data(rewardToken.token, curve_1.curve.constantOptions)];
282
+ return [4 /*yield*/, contract.reward_data(rewardToken.token, curve_1.curve.constantOptions)];
281
283
  case 5:
282
284
  rewardData = _h.sent();
283
285
  periodFinish = Number(ethers_1.ethers.utils.formatUnits(rewardData.period_finish, 0)) * 1000;
@@ -329,8 +331,8 @@ var PoolTemplate = /** @class */ (function () {
329
331
  return __generator(this, function (_e) {
330
332
  switch (_e.label) {
331
333
  case 0:
332
- if (this.gauge === ethers_1.ethers.constants.AddressZero)
333
- throw Error("".concat(this.name, " doesn't have gauge"));
334
+ if (this.rewardsOnly())
335
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use rewardsProfit instead"));
334
336
  address = address || curve_1.curve.signerAddress;
335
337
  if (!address)
336
338
  throw Error("Need to connect wallet or pass address into args");
@@ -842,6 +844,7 @@ var PoolTemplate = /** @class */ (function () {
842
844
  });
843
845
  });
844
846
  };
847
+ // Used by mixin. Don't delete it!!!
845
848
  this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
846
849
  var promises, _i, _a, addr;
847
850
  return __generator(this, function (_c) {
@@ -857,6 +860,7 @@ var PoolTemplate = /** @class */ (function () {
857
860
  }
858
861
  });
859
862
  }); };
863
+ // Used by mixin. Don't delete it!!!
860
864
  // NOTE! It may crash!
861
865
  this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
862
866
  var promises, _i, _a, addr;
@@ -873,82 +877,6 @@ var PoolTemplate = /** @class */ (function () {
873
877
  }
874
878
  });
875
879
  }); };
876
- this._withdrawCryptoBonus = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
877
- if (useUnderlying === void 0) { useUnderlying = true; }
878
- return __awaiter(_this, void 0, void 0, function () {
879
- var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
880
- return __generator(this, function (_d) {
881
- switch (_d.label) {
882
- case 0:
883
- if (!useUnderlying) return [3 /*break*/, 2];
884
- return [4 /*yield*/, this._underlyingPrices()];
885
- case 1:
886
- _a = _d.sent();
887
- return [3 /*break*/, 4];
888
- case 2: return [4 /*yield*/, this._wrappedPrices()];
889
- case 3:
890
- _a = _d.sent();
891
- _d.label = 4;
892
- case 4:
893
- prices = _a;
894
- if (!useUnderlying) return [3 /*break*/, 6];
895
- return [4 /*yield*/, this.withdrawExpected(String(lpTokenAmount))];
896
- case 5:
897
- _c = _d.sent();
898
- return [3 /*break*/, 8];
899
- case 6: return [4 /*yield*/, this.withdrawWrappedExpected(String(lpTokenAmount))];
900
- case 7:
901
- _c = _d.sent();
902
- _d.label = 8;
903
- case 8:
904
- balancedAmounts = _c;
905
- balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
906
- return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / totalAmountUSD * 100)];
907
- }
908
- });
909
- });
910
- };
911
- // TODO make the same as _withdrawCryptoBonus
912
- this._withdrawBonus = function (totalAmount, expected, useUnderlying) {
913
- if (useUnderlying === void 0) { useUnderlying = true; }
914
- return __awaiter(_this, void 0, void 0, function () {
915
- var poolBalances, _a, poolTotalBalance, poolBalancesRatios, balancedAmounts, balancedExpected, _c, _d, _e;
916
- return __generator(this, function (_f) {
917
- switch (_f.label) {
918
- case 0:
919
- if (!useUnderlying) return [3 /*break*/, 2];
920
- return [4 /*yield*/, this.stats.underlyingBalances()];
921
- case 1:
922
- _a = (_f.sent()).map(Number);
923
- return [3 /*break*/, 4];
924
- case 2: return [4 /*yield*/, this.stats.wrappedBalances()];
925
- case 3:
926
- _a = (_f.sent()).map(Number);
927
- _f.label = 4;
928
- case 4:
929
- poolBalances = _a;
930
- poolTotalBalance = poolBalances.reduce(function (a, b) { return a + b; });
931
- poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalBalance; });
932
- balancedAmounts = poolBalancesRatios.map(function (r) { return String(r * totalAmount); });
933
- if (!useUnderlying) return [3 /*break*/, 6];
934
- _d = Number;
935
- return [4 /*yield*/, this.withdrawImbalanceExpected(balancedAmounts)];
936
- case 5:
937
- _c = _d.apply(void 0, [_f.sent()]);
938
- return [3 /*break*/, 8];
939
- case 6:
940
- _e = Number;
941
- return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(balancedAmounts)];
942
- case 7:
943
- _c = _e.apply(void 0, [_f.sent()]);
944
- _f.label = 8;
945
- case 8:
946
- balancedExpected = _c;
947
- return [2 /*return*/, String((balancedExpected - expected) / balancedExpected * 100)];
948
- }
949
- });
950
- });
951
- };
952
880
  var poolData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA)[id];
953
881
  this.id = id;
954
882
  this.name = poolData.name;
@@ -1022,6 +950,12 @@ var PoolTemplate = /** @class */ (function () {
1022
950
  allCoinBalances: this.walletAllCoinBalances.bind(this),
1023
951
  };
1024
952
  }
953
+ PoolTemplate.prototype.rewardsOnly = function () {
954
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
955
+ throw Error("".concat(this.name, " doesn't have gauge"));
956
+ var gaugeContract = curve_1.curve.contracts[this.gauge].contract;
957
+ return !('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
958
+ };
1025
959
  PoolTemplate.prototype.statsWrappedBalances = function () {
1026
960
  return __awaiter(this, void 0, void 0, function () {
1027
961
  var swapContract, contractCalls, _wrappedBalances;
@@ -1410,9 +1344,8 @@ var PoolTemplate = /** @class */ (function () {
1410
1344
  return __generator(this, function (_d) {
1411
1345
  switch (_d.label) {
1412
1346
  case 0:
1413
- if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1414
- throw Error("claimableCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1415
- }
1347
+ if (this.rewardsOnly())
1348
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimableRewards instead"));
1416
1349
  address = address || curve_1.curve.signerAddress;
1417
1350
  if (!address)
1418
1351
  throw Error("Need to connect wallet or pass address into args");
@@ -1428,9 +1361,8 @@ var PoolTemplate = /** @class */ (function () {
1428
1361
  return __generator(this, function (_a) {
1429
1362
  switch (_a.label) {
1430
1363
  case 0:
1431
- if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1432
- throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1433
- }
1364
+ if (this.rewardsOnly())
1365
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
1434
1366
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1435
1367
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1436
1368
  }
@@ -1443,9 +1375,8 @@ var PoolTemplate = /** @class */ (function () {
1443
1375
  return __generator(this, function (_a) {
1444
1376
  switch (_a.label) {
1445
1377
  case 0:
1446
- if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1447
- throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1448
- }
1378
+ if (this.rewardsOnly())
1379
+ throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
1449
1380
  contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract;
1450
1381
  return [4 /*yield*/, contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1451
1382
  case 1:
@@ -1699,7 +1630,7 @@ var PoolTemplate = /** @class */ (function () {
1699
1630
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1700
1631
  throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1701
1632
  }
1702
- if (this.isFake)
1633
+ if (this.isPlain || this.isFake)
1703
1634
  throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1704
1635
  return [4 /*yield*/, this.depositWrappedExpected(amounts)];
1705
1636
  case 1: return [2 /*return*/, _a.sent()];
@@ -1715,7 +1646,7 @@ var PoolTemplate = /** @class */ (function () {
1715
1646
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1716
1647
  throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1717
1648
  }
1718
- if (this.isFake)
1649
+ if (this.isPlain || this.isFake)
1719
1650
  throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1720
1651
  return [4 /*yield*/, this.depositWrappedBonus(amounts)];
1721
1652
  case 1: return [2 /*return*/, _a.sent()];
@@ -1732,7 +1663,7 @@ var PoolTemplate = /** @class */ (function () {
1732
1663
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1733
1664
  throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1734
1665
  }
1735
- if (this.isFake)
1666
+ if (this.isPlain || this.isFake)
1736
1667
  throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1737
1668
  return [4 /*yield*/, (0, utils_1.hasAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1738
1669
  case 1:
@@ -1757,7 +1688,7 @@ var PoolTemplate = /** @class */ (function () {
1757
1688
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1758
1689
  throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1759
1690
  }
1760
- if (this.isFake)
1691
+ if (this.isPlain || this.isFake)
1761
1692
  throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1762
1693
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1763
1694
  case 1:
@@ -1786,7 +1717,7 @@ var PoolTemplate = /** @class */ (function () {
1786
1717
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1787
1718
  throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1788
1719
  }
1789
- if (this.isFake)
1720
+ if (this.isPlain || this.isFake)
1790
1721
  throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1791
1722
  return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.wrappedCoinAddresses, amounts, curve_1.curve.constants.ALIASES.deposit_and_stake)];
1792
1723
  case 1:
@@ -1817,7 +1748,7 @@ var PoolTemplate = /** @class */ (function () {
1817
1748
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1818
1749
  throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1819
1750
  }
1820
- if (this.isFake)
1751
+ if (this.isPlain || this.isFake)
1821
1752
  throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1822
1753
  return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
1823
1754
  case 1: return [2 /*return*/, _a.sent()];
@@ -1833,7 +1764,7 @@ var PoolTemplate = /** @class */ (function () {
1833
1764
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1834
1765
  throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1835
1766
  }
1836
- if (this.isFake)
1767
+ if (this.isPlain || this.isFake)
1837
1768
  throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1838
1769
  return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
1839
1770
  case 1: return [2 /*return*/, _a.sent()];
@@ -2041,22 +1972,11 @@ var PoolTemplate = /** @class */ (function () {
2041
1972
  });
2042
1973
  });
2043
1974
  };
1975
+ // OVERRIDE
2044
1976
  PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
2045
1977
  return __awaiter(this, void 0, void 0, function () {
2046
- var totalAmount, expected, _a;
2047
- return __generator(this, function (_c) {
2048
- switch (_c.label) {
2049
- case 0:
2050
- if (this.isCrypto)
2051
- throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2052
- totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
2053
- _a = Number;
2054
- return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
2055
- case 1:
2056
- expected = _a.apply(void 0, [_c.sent()]);
2057
- return [4 /*yield*/, this._withdrawBonus(totalAmount, expected)];
2058
- case 2: return [2 /*return*/, _c.sent()];
2059
- }
1978
+ return __generator(this, function (_a) {
1979
+ throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2060
1980
  });
2061
1981
  });
2062
1982
  };
@@ -2154,22 +2074,11 @@ var PoolTemplate = /** @class */ (function () {
2154
2074
  });
2155
2075
  });
2156
2076
  };
2077
+ // OVERRIDE
2157
2078
  PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
2158
2079
  return __awaiter(this, void 0, void 0, function () {
2159
- var totalAmount, expected, _a;
2160
- return __generator(this, function (_c) {
2161
- switch (_c.label) {
2162
- case 0:
2163
- if (this.isCrypto)
2164
- throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2165
- totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
2166
- _a = Number;
2167
- return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
2168
- case 1:
2169
- expected = _a.apply(void 0, [_c.sent()]);
2170
- return [4 /*yield*/, this._withdrawBonus(totalAmount, expected, false)];
2171
- case 2: return [2 /*return*/, _c.sent()];
2172
- }
2080
+ return __generator(this, function (_a) {
2081
+ throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2173
2082
  });
2174
2083
  });
2175
2084
  };
@@ -2215,25 +2124,11 @@ var PoolTemplate = /** @class */ (function () {
2215
2124
  });
2216
2125
  });
2217
2126
  };
2127
+ // OVERRIDE
2218
2128
  PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
2219
2129
  return __awaiter(this, void 0, void 0, function () {
2220
- var totalAmount, _a, coinPrice;
2221
- return __generator(this, function (_c) {
2222
- switch (_c.label) {
2223
- case 0:
2224
- _a = Number;
2225
- return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
2226
- case 1:
2227
- totalAmount = _a.apply(void 0, [_c.sent()]);
2228
- if (!this.isCrypto) return [3 /*break*/, 4];
2229
- return [4 /*yield*/, this._underlyingPrices()];
2230
- case 2:
2231
- coinPrice = (_c.sent())[this._getCoinIdx(coin)];
2232
- return [4 /*yield*/, this._withdrawCryptoBonus(totalAmount * coinPrice, Number(lpTokenAmount))];
2233
- case 3: return [2 /*return*/, _c.sent()];
2234
- case 4: return [4 /*yield*/, this._withdrawBonus(totalAmount, Number(lpTokenAmount))];
2235
- case 5: return [2 /*return*/, _c.sent()];
2236
- }
2130
+ return __generator(this, function (_a) {
2131
+ throw Error("withdrawOneCoinBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2237
2132
  });
2238
2133
  });
2239
2134
  };
@@ -2318,28 +2213,11 @@ var PoolTemplate = /** @class */ (function () {
2318
2213
  });
2319
2214
  });
2320
2215
  };
2216
+ // OVERRIDE
2321
2217
  PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
2322
2218
  return __awaiter(this, void 0, void 0, function () {
2323
- var totalAmount, _a, coinPrice;
2324
- return __generator(this, function (_c) {
2325
- switch (_c.label) {
2326
- case 0:
2327
- if (this.isFake || this.isPlain) {
2328
- throw Error("".concat(this.name, " pool doesn't have this method"));
2329
- }
2330
- _a = Number;
2331
- return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
2332
- case 1:
2333
- totalAmount = _a.apply(void 0, [_c.sent()]);
2334
- if (!this.isCrypto) return [3 /*break*/, 4];
2335
- return [4 /*yield*/, this._underlyingPrices()];
2336
- case 2:
2337
- coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
2338
- return [4 /*yield*/, this._withdrawCryptoBonus(totalAmount * coinPrice, Number(lpTokenAmount))];
2339
- case 3: return [2 /*return*/, _c.sent()];
2340
- case 4: return [4 /*yield*/, this._withdrawBonus(totalAmount, Number(lpTokenAmount), false)];
2341
- case 5: return [2 /*return*/, _c.sent()];
2342
- }
2219
+ return __generator(this, function (_a) {
2220
+ throw Error("withdrawOneCoinWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2343
2221
  });
2344
2222
  });
2345
2223
  };
@@ -2663,7 +2541,7 @@ var PoolTemplate = /** @class */ (function () {
2663
2541
  });
2664
2542
  };
2665
2543
  PoolTemplate.prototype._swapContractAddress = function () {
2666
- return (this.isCrypto && this.isMeta) || ([137, 43114].includes(curve_1.curve.chainId) && this.isMetaFactory) ? this.zap : this.address;
2544
+ return (this.isCrypto && this.isMeta) || (this.isMetaFactory && (new PoolTemplate(this.basePool).isLending)) ? this.zap : this.address;
2667
2545
  };
2668
2546
  PoolTemplate.prototype.swapIsApproved = function (inputCoin, amount) {
2669
2547
  return __awaiter(this, void 0, void 0, function () {
@@ -37,6 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.depositWrappedBonusCryptoMixin = exports.depositBonusCryptoMixin = exports.depositWrappedBonusMixin = exports.depositBonusMixin = void 0;
40
+ var ethers_1 = require("ethers");
41
+ var curve_1 = require("../../curve");
40
42
  var utils_1 = require("../../utils");
41
43
  // @ts-ignore
42
44
  exports.depositBonusMixin = {
@@ -71,25 +73,38 @@ exports.depositBonusMixin = {
71
73
  exports.depositWrappedBonusMixin = {
72
74
  depositWrappedBonus: function (amounts) {
73
75
  return __awaiter(this, void 0, void 0, function () {
74
- var totalAmount, expected, _a, poolBalances, poolTotalBalance, poolBalancesRatios, balancedAmounts, balancedExpected, _b;
75
- return __generator(this, function (_c) {
76
- switch (_c.label) {
76
+ var vp, basePoolAddress, _a, _b, _c, prices, totalValue, expected, _d, poolBalances, poolValues, poolTotalValue, poolRatios, balancedValues, balancedAmounts, balancedExpected, _e;
77
+ return __generator(this, function (_f) {
78
+ switch (_f.label) {
77
79
  case 0:
78
- totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
80
+ vp = 1;
81
+ if (!this.isMeta) return [3 /*break*/, 2];
82
+ basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
79
83
  _a = Number;
80
- return [4 /*yield*/, this.depositWrappedExpected(amounts)];
84
+ _c = (_b = ethers_1.ethers.utils).formatUnits;
85
+ return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
81
86
  case 1:
82
- expected = _a.apply(void 0, [_c.sent()]);
83
- return [4 /*yield*/, this.stats.wrappedBalances()];
87
+ vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
88
+ _f.label = 2;
84
89
  case 2:
85
- poolBalances = (_c.sent()).map(Number);
86
- poolTotalBalance = poolBalances.reduce(function (a, b) { return a + b; });
87
- poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalBalance; });
88
- balancedAmounts = poolBalancesRatios.map(function (r) { return r * totalAmount; });
89
- _b = Number;
90
- return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
90
+ prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
91
+ totalValue = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
92
+ _d = Number;
93
+ return [4 /*yield*/, this.depositWrappedExpected(amounts)];
91
94
  case 3:
92
- balancedExpected = _b.apply(void 0, [_c.sent()]);
95
+ expected = _d.apply(void 0, [_f.sent()]);
96
+ return [4 /*yield*/, this.stats.wrappedBalances()];
97
+ case 4:
98
+ poolBalances = (_f.sent()).map(Number);
99
+ poolValues = poolBalances.map(function (b, i) { return b * prices[i]; });
100
+ poolTotalValue = poolValues.reduce(function (a, b) { return a + b; });
101
+ poolRatios = poolValues.map(function (b) { return b / poolTotalValue; });
102
+ balancedValues = poolRatios.map(function (r) { return r * totalValue; });
103
+ balancedAmounts = balancedValues.map(function (a, i) { return a / prices[i]; });
104
+ _e = Number;
105
+ return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
106
+ case 5:
107
+ balancedExpected = _e.apply(void 0, [_f.sent()]);
93
108
  return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
94
109
  }
95
110
  });
@@ -133,29 +148,40 @@ exports.depositBonusCryptoMixin = {
133
148
  exports.depositWrappedBonusCryptoMixin = {
134
149
  depositWrappedBonus: function (amounts) {
135
150
  return __awaiter(this, void 0, void 0, function () {
136
- var prices, totalAmountUSD, expected, _a, poolBalances, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _b;
137
- return __generator(this, function (_c) {
138
- switch (_c.label) {
151
+ var prices, vp, basePoolAddress, _a, _b, _c, totalAmountUSD, expected, _d, poolBalances, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _e;
152
+ return __generator(this, function (_f) {
153
+ switch (_f.label) {
139
154
  case 0: return [4 /*yield*/, this._wrappedPrices()];
140
155
  case 1:
141
- prices = _c.sent();
142
- totalAmountUSD = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
156
+ prices = _f.sent();
157
+ vp = 1;
158
+ if (!this.isMeta) return [3 /*break*/, 3];
159
+ basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
143
160
  _a = Number;
144
- return [4 /*yield*/, this.depositWrappedExpected(amounts)];
161
+ _c = (_b = ethers_1.ethers.utils).formatUnits;
162
+ return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
145
163
  case 2:
146
- expected = _a.apply(void 0, [_c.sent()]);
147
- return [4 /*yield*/, this.stats.wrappedBalances()];
164
+ vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
165
+ _f.label = 3;
148
166
  case 3:
149
- poolBalances = (_c.sent()).map(Number);
167
+ prices = prices.map(function (p, i) { return i === prices.length - 1 ? p * vp : p; });
168
+ totalAmountUSD = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
169
+ _d = Number;
170
+ return [4 /*yield*/, this.depositWrappedExpected(amounts)];
171
+ case 4:
172
+ expected = _d.apply(void 0, [_f.sent()]);
173
+ return [4 /*yield*/, this.stats.wrappedBalances()];
174
+ case 5:
175
+ poolBalances = (_f.sent()).map(Number);
150
176
  poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices[i]; });
151
177
  poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
152
178
  poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
153
179
  balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
154
180
  balancedAmounts = balancedAmountsUSD.map(function (a, i) { return a / prices[i]; });
155
- _b = Number;
181
+ _e = Number;
156
182
  return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
157
- case 4:
158
- balancedExpected = _b.apply(void 0, [_c.sent()]);
183
+ case 6:
184
+ balancedExpected = _e.apply(void 0, [_f.sent()]);
159
185
  return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
160
186
  }
161
187
  });
@@ -0,0 +1,7 @@
1
+ import { PoolTemplate } from "../PoolTemplate";
2
+ export declare const withdrawImbalanceBonusMixin: PoolTemplate;
3
+ export declare const withdrawImbalanceWrappedBonusMixin: PoolTemplate;
4
+ export declare const withdrawOneCoinBonusMixin: PoolTemplate;
5
+ export declare const withdrawOneCoinWrappedBonusMixin: PoolTemplate;
6
+ export declare const withdrawOneCoinCryptoBonusMixin: PoolTemplate;
7
+ export declare const withdrawOneCoinWrappedCryptoBonusMixin: PoolTemplate;