@curvefi/api 1.11.0 → 1.15.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 (52) hide show
  1. package/README.md +68 -0
  2. package/lib/constants/abis/abis-ethereum.js +144 -16
  3. package/lib/constants/abis/abis-polygon.js +17 -1
  4. package/lib/constants/abis/json/aave/rewards.json +107 -0
  5. package/lib/constants/abis/json/atricrypto3/swap.json +63 -63
  6. package/lib/constants/abis/json/atricrypto3/zap.json +8 -8
  7. package/lib/constants/abis/json/busd/deposit.json +5 -10
  8. package/lib/constants/abis/json/busd/swap.json +18 -36
  9. package/lib/constants/abis/json/compound/deposit.json +5 -10
  10. package/lib/constants/abis/json/compound/migration.json +1 -2
  11. package/lib/constants/abis/json/compound/oldSwap.json +16 -32
  12. package/lib/constants/abis/json/compound/swap.json +18 -36
  13. package/lib/constants/abis/json/crveth/swap.json +61 -61
  14. package/lib/constants/abis/json/eurt/swap.json +29 -29
  15. package/lib/constants/abis/json/eurtusd/deposit.json +13 -13
  16. package/lib/constants/abis/json/eurtusd/swap.json +59 -59
  17. package/lib/constants/abis/json/gauge.json +1 -1
  18. package/lib/constants/abis/json/gauge_factory.json +879 -0
  19. package/lib/constants/abis/json/gauge_rewards_only.json +649 -0
  20. package/lib/constants/abis/json/gauge_synthetix.json +590 -0
  21. package/lib/constants/abis/json/gauge_v2.json +942 -0
  22. package/lib/constants/abis/json/gauge_v3.json +954 -0
  23. package/lib/constants/abis/json/gauge_v4.json +913 -0
  24. package/lib/constants/abis/json/iearn/deposit.json +5 -10
  25. package/lib/constants/abis/json/iearn/swap.json +18 -36
  26. package/lib/constants/abis/json/minter.json +165 -0
  27. package/lib/constants/abis/json/pax/deposit.json +5 -10
  28. package/lib/constants/abis/json/pax/swap.json +19 -38
  29. package/lib/constants/abis/json/ren/swap.json +19 -38
  30. package/lib/constants/abis/json/ren-polygon/swap.json +46 -46
  31. package/lib/constants/abis/json/reth/swap.json +38 -38
  32. package/lib/constants/abis/json/sbtc/swap.json +19 -38
  33. package/lib/constants/abis/json/streamer.json +257 -0
  34. package/lib/constants/abis/json/susdv2/deposit.json +5 -10
  35. package/lib/constants/abis/json/susdv2/swap.json +16 -32
  36. package/lib/constants/abis/json/tricrypto2/deposit.json +3 -3
  37. package/lib/constants/abis/json/tricrypto2/swap.json +60 -60
  38. package/lib/constants/abis/json/usdt/deposit.json +5 -10
  39. package/lib/constants/abis/json/usdt/swap.json +19 -37
  40. package/lib/constants/aliases.d.ts +2 -0
  41. package/lib/constants/aliases.js +3 -1
  42. package/lib/constants/coins-ethereum.js +4 -2
  43. package/lib/constants/coins-polygon.js +3 -2
  44. package/lib/curve.d.ts +2 -1
  45. package/lib/curve.js +73 -30
  46. package/lib/index.d.ts +1 -1
  47. package/lib/interfaces.d.ts +8 -0
  48. package/lib/pools.d.ts +36 -5
  49. package/lib/pools.js +313 -52
  50. package/lib/utils.d.ts +1 -1
  51. package/lib/utils.js +40 -29
  52. package/package.json +1 -1
package/lib/pools.js CHANGED
@@ -81,7 +81,7 @@ var Pool = /** @class */ (function () {
81
81
  _amounts = amounts.map(function (amount, i) {
82
82
  return ethers_1.ethers.utils.parseUnits(amount, _this.underlyingDecimals[i]);
83
83
  });
84
- if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
84
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
85
85
  return [4 /*yield*/, this._calcLpTokenAmountWithUnderlying(_amounts, isDeposit)];
86
86
  case 1:
87
87
  _expected = _a.sent(); // Lending pools
@@ -126,14 +126,30 @@ var Pool = /** @class */ (function () {
126
126
  });
127
127
  });
128
128
  };
129
- this.getVirtualPrice = function () { return __awaiter(_this, void 0, void 0, function () {
130
- var _virtualPrice;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0: return [4 /*yield*/, curve_1.curve.contracts[this.swap].contract.get_virtual_price(curve_1.curve.constantOptions)];
129
+ this.getParameters = function () { return __awaiter(_this, void 0, void 0, function () {
130
+ var calls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma;
131
+ return __generator(this, function (_d) {
132
+ switch (_d.label) {
133
+ case 0:
134
+ calls = [
135
+ curve_1.curve.contracts[this.swap].multicallContract.get_virtual_price(),
136
+ curve_1.curve.contracts[this.swap].multicallContract.fee(),
137
+ curve_1.curve.contracts[this.swap].multicallContract.admin_fee(),
138
+ curve_1.curve.contracts[this.swap].multicallContract.A(),
139
+ ];
140
+ if (this.isCrypto)
141
+ calls.push(curve_1.curve.contracts[this.swap].multicallContract.gamma());
142
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
134
143
  case 1:
135
- _virtualPrice = _a.sent();
136
- return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_virtualPrice)];
144
+ _a = _d.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
145
+ _c = [
146
+ ethers_1.ethers.utils.formatUnits(_virtualPrice),
147
+ ethers_1.ethers.utils.formatUnits(_fee, 8),
148
+ ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
149
+ ethers_1.ethers.utils.formatUnits(_A, 0),
150
+ _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
151
+ ], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
152
+ return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, gamma: gamma }];
137
153
  }
138
154
  });
139
155
  }); };
@@ -161,7 +177,7 @@ var Pool = /** @class */ (function () {
161
177
  _poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
162
178
  return [3 /*break*/, 6];
163
179
  case 3:
164
- if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
180
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
165
181
  return [4 /*yield*/, this._getRates()];
166
182
  case 4:
167
183
  _rates_1 = _a.sent();
@@ -180,9 +196,6 @@ var Pool = /** @class */ (function () {
180
196
  return __generator(this, function (_a) {
181
197
  switch (_a.label) {
182
198
  case 0:
183
- if (this.isFake) {
184
- throw Error("".concat(this.name, " pool doesn't have this method"));
185
- }
186
199
  swapContract = curve_1.curve.contracts[this.swap].multicallContract;
187
200
  contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
188
201
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
@@ -192,6 +205,150 @@ var Pool = /** @class */ (function () {
192
205
  }
193
206
  });
194
207
  }); };
208
+ this.getTotalLiquidity = function () { return __awaiter(_this, void 0, void 0, function () {
209
+ var balances, promises, _i, _a, addr, prices, totalLiquidity;
210
+ return __generator(this, function (_c) {
211
+ switch (_c.label) {
212
+ case 0: return [4 /*yield*/, this.getPoolWrappedBalances()];
213
+ case 1:
214
+ balances = _c.sent();
215
+ promises = [];
216
+ for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
217
+ addr = _a[_i];
218
+ promises.push((0, utils_1._getUsdRate)(addr));
219
+ }
220
+ return [4 /*yield*/, Promise.all(promises)];
221
+ case 2:
222
+ prices = _c.sent();
223
+ totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
224
+ return [2 /*return*/, String(totalLiquidity)];
225
+ }
226
+ });
227
+ }); };
228
+ this.getVolume = function () { return __awaiter(_this, void 0, void 0, function () {
229
+ var name, statsUrl, volume, usdRate, _a;
230
+ return __generator(this, function (_c) {
231
+ switch (_c.label) {
232
+ case 0:
233
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
234
+ statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
235
+ return [4 /*yield*/, axios_1.default.get(statsUrl)];
236
+ case 1:
237
+ volume = (_c.sent()).data.volume[name] || 0;
238
+ if (!this.isCrypto) return [3 /*break*/, 2];
239
+ _a = 1;
240
+ return [3 /*break*/, 4];
241
+ case 2: return [4 /*yield*/, (0, utils_1._getUsdRate)(this.referenceAsset)];
242
+ case 3:
243
+ _a = _c.sent();
244
+ _c.label = 4;
245
+ case 4:
246
+ usdRate = _a;
247
+ return [2 /*return*/, String(volume * usdRate)];
248
+ }
249
+ });
250
+ }); };
251
+ this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
252
+ var name, statsUrl, apy;
253
+ return __generator(this, function (_a) {
254
+ switch (_a.label) {
255
+ case 0:
256
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
257
+ statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
258
+ return [4 /*yield*/, axios_1.default.get(statsUrl)];
259
+ case 1:
260
+ apy = (_a.sent()).data.apy;
261
+ return [2 /*return*/, [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); })];
262
+ }
263
+ });
264
+ }); };
265
+ this.getTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
266
+ var gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _a, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
267
+ return __generator(this, function (_c) {
268
+ switch (_c.label) {
269
+ case 0:
270
+ if (curve_1.curve.chainId === 137)
271
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
272
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
273
+ lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
274
+ gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
275
+ return [4 /*yield*/, this.getTotalLiquidity()];
276
+ case 1:
277
+ totalLiquidityUSD = _c.sent();
278
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all([
279
+ gaugeContract.inflation_rate(),
280
+ gaugeControllerContract.gauge_relative_weight(this.gauge),
281
+ gaugeContract.working_supply(),
282
+ lpTokenContract.totalSupply(),
283
+ ])];
284
+ case 2:
285
+ _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
286
+ rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
287
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
288
+ case 3:
289
+ crvRate = _c.sent();
290
+ baseApy = rate.times(crvRate);
291
+ boostedApy = baseApy.times(2.5);
292
+ return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
293
+ }
294
+ });
295
+ }); };
296
+ this.getRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
297
+ var apy_1, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, mainPoolsGaugeRewards, mainPoolsGaugeRewardsLowerCase, apyData, apy, _d, apyData_1, data;
298
+ return __generator(this, function (_e) {
299
+ switch (_e.label) {
300
+ case 0:
301
+ if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 8];
302
+ apy_1 = [];
303
+ _i = 0, _a = this.rewardTokens;
304
+ _e.label = 1;
305
+ case 1:
306
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
307
+ rewardToken = _a[_i];
308
+ rewardContract = curve_1.curve.contracts[this.rewardContract].contract;
309
+ return [4 /*yield*/, this.getTotalLiquidity()];
310
+ case 2:
311
+ totalLiquidityUSD = _e.sent();
312
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken)];
313
+ case 3:
314
+ crvRate = _e.sent();
315
+ _c = utils_1.toBN;
316
+ return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
317
+ case 4:
318
+ inflation = _c.apply(void 0, [(_e.sent()).rate]);
319
+ baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
320
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
321
+ return [4 /*yield*/, rewardTokenContract.symbol()];
322
+ case 5:
323
+ symbol = _e.sent();
324
+ apy_1.push({
325
+ token: rewardToken,
326
+ symbol: symbol,
327
+ apy: baseApy.times(100).toFixed(4),
328
+ });
329
+ _e.label = 6;
330
+ case 6:
331
+ _i++;
332
+ return [3 /*break*/, 1];
333
+ case 7: return [2 /*return*/, apy_1];
334
+ case 8: return [4 /*yield*/, axios_1.default.get("https://api.curve.fi/api/getMainPoolsGaugeRewards")];
335
+ case 9:
336
+ mainPoolsGaugeRewards = (_e.sent()).data.data.mainPoolsGaugeRewards;
337
+ mainPoolsGaugeRewardsLowerCase = Object.fromEntries(Object.entries(mainPoolsGaugeRewards).map(function (entry) { return [entry[0].toLowerCase(), entry[1]]; }));
338
+ apyData = mainPoolsGaugeRewardsLowerCase[this.gauge.toLowerCase()] || [];
339
+ apy = [];
340
+ for (_d = 0, apyData_1 = apyData; _d < apyData_1.length; _d++) {
341
+ data = apyData_1[_d];
342
+ apy.push({
343
+ token: data.tokenAddress,
344
+ symbol: data.symbol,
345
+ apy: String(data.apy),
346
+ });
347
+ }
348
+ return [2 /*return*/, apy];
349
+ }
350
+ });
351
+ }); };
195
352
  this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
196
353
  var _this = this;
197
354
  return __generator(this, function (_a) {
@@ -281,7 +438,7 @@ var Pool = /** @class */ (function () {
281
438
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
282
439
  case 3: return [2 /*return*/, _d.sent()];
283
440
  case 4:
284
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
441
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
285
442
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
286
443
  case 5: return [2 /*return*/, _d.sent()];
287
444
  case 6:
@@ -329,7 +486,7 @@ var Pool = /** @class */ (function () {
329
486
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
330
487
  case 2: return [2 /*return*/, _a.sent()];
331
488
  case 3:
332
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
489
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
333
490
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
334
491
  case 4: return [2 /*return*/, _a.sent()];
335
492
  case 5:
@@ -459,7 +616,7 @@ var Pool = /** @class */ (function () {
459
616
  _amounts = amounts.map(function (amount, i) {
460
617
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
461
618
  });
462
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
619
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
463
620
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
464
621
  case 3: return [2 /*return*/, _d.sent()];
465
622
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -487,7 +644,7 @@ var Pool = /** @class */ (function () {
487
644
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
488
645
  case 1:
489
646
  _a.sent();
490
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
647
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
491
648
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
492
649
  case 2: return [2 /*return*/, _a.sent()];
493
650
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -504,7 +661,7 @@ var Pool = /** @class */ (function () {
504
661
  switch (_a.label) {
505
662
  case 0:
506
663
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
507
- if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
664
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
508
665
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
509
666
  case 1:
510
667
  _expected = _a.sent(); // Lending pools
@@ -581,7 +738,7 @@ var Pool = /** @class */ (function () {
581
738
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
582
739
  case 4: return [2 /*return*/, _c.sent()];
583
740
  case 5:
584
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
741
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
585
742
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
586
743
  case 6: return [2 /*return*/, _c.sent()];
587
744
  case 7:
@@ -606,7 +763,7 @@ var Pool = /** @class */ (function () {
606
763
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
607
764
  case 2: return [2 /*return*/, _a.sent()];
608
765
  case 3:
609
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
766
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
610
767
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
611
768
  case 4: return [2 /*return*/, _a.sent()];
612
769
  case 5:
@@ -650,7 +807,7 @@ var Pool = /** @class */ (function () {
650
807
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
651
808
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
652
809
  }
653
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
810
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
654
811
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
655
812
  case 2: return [2 /*return*/, _a.sent()];
656
813
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -670,7 +827,7 @@ var Pool = /** @class */ (function () {
670
827
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
671
828
  case 1:
672
829
  _a.sent();
673
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
830
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
674
831
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
675
832
  case 2: return [2 /*return*/, _a.sent()];
676
833
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -1047,7 +1204,7 @@ var Pool = /** @class */ (function () {
1047
1204
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1048
1205
  case 4: return [2 /*return*/, _c.sent()];
1049
1206
  case 5:
1050
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1207
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1051
1208
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1052
1209
  case 6: return [2 /*return*/, _c.sent()];
1053
1210
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1071,7 +1228,7 @@ var Pool = /** @class */ (function () {
1071
1228
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1072
1229
  case 2: return [2 /*return*/, _a.sent()];
1073
1230
  case 3:
1074
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1231
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1075
1232
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1076
1233
  case 4: return [2 /*return*/, _a.sent()];
1077
1234
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1143,7 +1300,7 @@ var Pool = /** @class */ (function () {
1143
1300
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1144
1301
  }
1145
1302
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1146
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1303
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1147
1304
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1148
1305
  case 2: return [2 /*return*/, _a.sent()];
1149
1306
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1167,7 +1324,7 @@ var Pool = /** @class */ (function () {
1167
1324
  case 1:
1168
1325
  _a.sent();
1169
1326
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1170
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1327
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1171
1328
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1172
1329
  case 2: return [2 /*return*/, _a.sent()];
1173
1330
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1246,6 +1403,123 @@ var Pool = /** @class */ (function () {
1246
1403
  }
1247
1404
  });
1248
1405
  }); };
1406
+ this.gaugeClaimableTokens = function (address) {
1407
+ if (address === void 0) { address = ""; }
1408
+ return __awaiter(_this, void 0, void 0, function () {
1409
+ var _a, _c;
1410
+ return __generator(this, function (_d) {
1411
+ switch (_d.label) {
1412
+ case 0:
1413
+ if (curve_1.curve.chainId !== 1)
1414
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimableRewards instead"));
1415
+ address = address || curve_1.curve.signerAddress;
1416
+ if (!address)
1417
+ throw Error("Need to connect wallet or pass address into args");
1418
+ _c = (_a = ethers_1.ethers.utils).formatUnits;
1419
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
1420
+ case 1: return [2 /*return*/, _c.apply(_a, [_d.sent()])];
1421
+ }
1422
+ });
1423
+ });
1424
+ };
1425
+ this.gaugeClaimTokens = function () { return __awaiter(_this, void 0, void 0, function () {
1426
+ var gasLimit;
1427
+ return __generator(this, function (_a) {
1428
+ switch (_a.label) {
1429
+ case 0:
1430
+ if (curve_1.curve.chainId !== 1)
1431
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimRewards instead"));
1432
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1433
+ case 1:
1434
+ gasLimit = (_a.sent()).mul(130).div(100);
1435
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1436
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1437
+ }
1438
+ });
1439
+ }); };
1440
+ // TODO 1. Fix aave and saave error
1441
+ // TODO 2. Figure out Synthetix cumulative results
1442
+ this.gaugeClaimableRewards = function (address) {
1443
+ if (address === void 0) { address = ""; }
1444
+ return __awaiter(_this, void 0, void 0, function () {
1445
+ var gaugeContract, rewards, _i, _a, rewardToken, rewardTokenContract, symbol, decimals, method, amount, _c, _d, rewardToken, rewardTokenContract, symbol, decimals, amount, _e, _f;
1446
+ return __generator(this, function (_h) {
1447
+ switch (_h.label) {
1448
+ case 0:
1449
+ address = address || curve_1.curve.signerAddress;
1450
+ if (!address)
1451
+ throw Error("Need to connect wallet or pass address into args");
1452
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1453
+ rewards = [];
1454
+ if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
1455
+ _i = 0, _a = this.rewardTokens;
1456
+ _h.label = 1;
1457
+ case 1:
1458
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
1459
+ rewardToken = _a[_i];
1460
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1461
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1462
+ case 2:
1463
+ symbol = _h.sent();
1464
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1465
+ case 3:
1466
+ decimals = _h.sent();
1467
+ method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
1468
+ _d = (_c = ethers_1.ethers.utils).formatUnits;
1469
+ return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
1470
+ case 4:
1471
+ amount = _d.apply(_c, [_h.sent(), decimals]);
1472
+ rewards.push({
1473
+ token: rewardToken,
1474
+ symbol: symbol,
1475
+ amount: amount,
1476
+ });
1477
+ _h.label = 5;
1478
+ case 5:
1479
+ _i++;
1480
+ return [3 /*break*/, 1];
1481
+ case 6: return [3 /*break*/, 11];
1482
+ case 7:
1483
+ if (!('claimable_reward(address)' in gaugeContract && this.rewardTokens.length > 0)) return [3 /*break*/, 11];
1484
+ rewardToken = this.rewardTokens[0];
1485
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1486
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1487
+ case 8:
1488
+ symbol = _h.sent();
1489
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1490
+ case 9:
1491
+ decimals = _h.sent();
1492
+ _f = (_e = ethers_1.ethers.utils).formatUnits;
1493
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1494
+ case 10:
1495
+ amount = _f.apply(_e, [_h.sent(), decimals]);
1496
+ rewards.push({
1497
+ token: rewardToken,
1498
+ symbol: symbol,
1499
+ amount: amount,
1500
+ });
1501
+ _h.label = 11;
1502
+ case 11: return [2 /*return*/, rewards];
1503
+ }
1504
+ });
1505
+ });
1506
+ };
1507
+ this.gaugeClaimRewards = function () { return __awaiter(_this, void 0, void 0, function () {
1508
+ var gaugeContract, gasLimit;
1509
+ return __generator(this, function (_a) {
1510
+ switch (_a.label) {
1511
+ case 0:
1512
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1513
+ if (!("claim_rewards()" in gaugeContract))
1514
+ throw Error("".concat(this.name, " pool doesn't have such method"));
1515
+ return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
1516
+ case 1:
1517
+ gasLimit = (_a.sent()).mul(130).div(100);
1518
+ return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1519
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1520
+ }
1521
+ });
1522
+ }); };
1249
1523
  this.balances = function () {
1250
1524
  var addresses = [];
1251
1525
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1718,32 +1992,6 @@ var Pool = /** @class */ (function () {
1718
1992
  }
1719
1993
  });
1720
1994
  }); };
1721
- this.getApy = function () { return __awaiter(_this, void 0, void 0, function () {
1722
- var swapContract, gaugeContract, gaugeControllerContract, _a, inflation, weight, workingSupply, virtualPrice, rate, crvRate, baseApy, boostedApy;
1723
- return __generator(this, function (_c) {
1724
- switch (_c.label) {
1725
- case 0:
1726
- swapContract = curve_1.curve.contracts[this.swap].multicallContract;
1727
- gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
1728
- gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
1729
- return [4 /*yield*/, curve_1.curve.multicallProvider.all([
1730
- gaugeContract.inflation_rate(),
1731
- gaugeControllerContract.gauge_relative_weight(this.gauge),
1732
- gaugeContract.working_supply(),
1733
- swapContract.get_virtual_price(),
1734
- ])];
1735
- case 1:
1736
- _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], virtualPrice = _a[3];
1737
- rate = inflation.times(weight).times(31536000).div(workingSupply).times(0.4).div(virtualPrice);
1738
- return [4 /*yield*/, (0, utils_1.getCrvRate)()];
1739
- case 2:
1740
- crvRate = _c.sent();
1741
- baseApy = rate.times(crvRate);
1742
- boostedApy = baseApy.times(2.5);
1743
- return [2 /*return*/, [baseApy.toFixed(4), boostedApy.toFixed(4)]];
1744
- }
1745
- });
1746
- }); };
1747
1995
  this._getCoinIdx = function (coin, useUnderlying) {
1748
1996
  if (useUnderlying === void 0) { useUnderlying = true; }
1749
1997
  if (typeof coin === 'number') {
@@ -1946,7 +2194,7 @@ var Pool = /** @class */ (function () {
1946
2194
  switch (_a.label) {
1947
2195
  case 0:
1948
2196
  contract = curve_1.curve.contracts[this.swap].contract;
1949
- if (!["eurtusd", "crveth"].includes(this.name)) return [3 /*break*/, 2];
2197
+ if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
1950
2198
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1951
2199
  case 1: return [2 /*return*/, _a.sent()];
1952
2200
  case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -2647,10 +2895,12 @@ var Pool = /** @class */ (function () {
2647
2895
  }); };
2648
2896
  var poolData = curve_1.POOLS_DATA[name];
2649
2897
  this.name = name;
2898
+ this.referenceAsset = poolData.reference_asset;
2650
2899
  this.swap = poolData.swap_address;
2651
2900
  this.zap = poolData.deposit_address || null;
2652
2901
  this.lpToken = poolData.token_address;
2653
2902
  this.gauge = poolData.gauge_address;
2903
+ this.rewardContract = poolData.reward_contract || null;
2654
2904
  this.underlyingCoins = poolData.underlying_coins;
2655
2905
  this.coins = poolData.coins;
2656
2906
  this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
@@ -2663,6 +2913,7 @@ var Pool = /** @class */ (function () {
2663
2913
  this.isCrypto = poolData.is_crypto || false;
2664
2914
  this.isFactory = poolData.is_factory || false;
2665
2915
  this.basePool = poolData.base_pool || '';
2916
+ this.rewardTokens = poolData.reward_tokens || [];
2666
2917
  this.estimateGas = {
2667
2918
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2668
2919
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2685,6 +2936,16 @@ var Pool = /** @class */ (function () {
2685
2936
  exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
2686
2937
  exchangeWrapped: this.exchangeWrappedEstimateGas,
2687
2938
  };
2939
+ this.stats = {
2940
+ getParameters: this.getParameters,
2941
+ getPoolBalances: this.getPoolBalances,
2942
+ getPoolWrappedBalances: this.getPoolWrappedBalances,
2943
+ getTotalLiquidity: this.getTotalLiquidity,
2944
+ getVolume: this.getVolume,
2945
+ getBaseApy: this.getBaseApy,
2946
+ getTokenApy: this.getTokenApy,
2947
+ getRewardsApy: this.getRewardsApy,
2948
+ };
2688
2949
  if (this.isMeta && !this.isFake) {
2689
2950
  var metaCoins = poolData.meta_coin_addresses;
2690
2951
  var metaCoinDecimals = poolData.meta_coin_decimals;
package/lib/utils.d.ts CHANGED
@@ -20,5 +20,5 @@ export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumb
20
20
  export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: string[], spender: string) => Promise<number>;
21
21
  export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
22
22
  export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
23
- export declare const getCrvRate: () => Promise<number>;
24
23
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
24
+ export declare const _getStatsUrl: (isCrypto?: boolean) => string;