@curvefi/api 1.12.0 → 1.15.1

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 (53) hide show
  1. package/README.md +98 -1
  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 +1 -0
  45. package/lib/curve.js +47 -16
  46. package/lib/index.d.ts +1 -0
  47. package/lib/index.js +1 -0
  48. package/lib/interfaces.d.ts +8 -0
  49. package/lib/pools.d.ts +41 -5
  50. package/lib/pools.js +334 -52
  51. package/lib/utils.d.ts +2 -1
  52. package/lib/utils.js +42 -29
  53. 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,45 @@ 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 multicallContract, calls, additionalCalls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
131
+ return __generator(this, function (_f) {
132
+ switch (_f.label) {
133
+ case 0:
134
+ multicallContract = curve_1.curve.contracts[this.swap].multicallContract;
135
+ calls = [
136
+ multicallContract.get_virtual_price(),
137
+ multicallContract.fee(),
138
+ multicallContract.admin_fee(),
139
+ multicallContract.A(),
140
+ ];
141
+ if (this.isCrypto)
142
+ calls.push(multicallContract.gamma());
143
+ additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
144
+ if ('initial_A' in multicallContract) {
145
+ additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
146
+ }
147
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
134
148
  case 1:
135
- _virtualPrice = _a.sent();
136
- return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_virtualPrice)];
149
+ _a = _f.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
150
+ _c = [
151
+ ethers_1.ethers.utils.formatUnits(_virtualPrice),
152
+ ethers_1.ethers.utils.formatUnits(_fee, 8),
153
+ ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
154
+ ethers_1.ethers.utils.formatUnits(_A, 0),
155
+ _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
156
+ ], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
157
+ A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.name) ? 1 : 100;
158
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
159
+ case 2:
160
+ _d = _f.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
161
+ _e = [
162
+ _future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
163
+ _initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
164
+ _future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
165
+ _initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
166
+ ], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
167
+ return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
137
168
  }
138
169
  });
139
170
  }); };
@@ -161,7 +192,7 @@ var Pool = /** @class */ (function () {
161
192
  _poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
162
193
  return [3 /*break*/, 6];
163
194
  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];
195
+ 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
196
  return [4 /*yield*/, this._getRates()];
166
197
  case 4:
167
198
  _rates_1 = _a.sent();
@@ -180,9 +211,6 @@ var Pool = /** @class */ (function () {
180
211
  return __generator(this, function (_a) {
181
212
  switch (_a.label) {
182
213
  case 0:
183
- if (this.isFake) {
184
- throw Error("".concat(this.name, " pool doesn't have this method"));
185
- }
186
214
  swapContract = curve_1.curve.contracts[this.swap].multicallContract;
187
215
  contractCalls = this.coins.map(function (_, i) { return swapContract.balances(i); });
188
216
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
@@ -192,6 +220,156 @@ var Pool = /** @class */ (function () {
192
220
  }
193
221
  });
194
222
  }); };
223
+ this.getTotalLiquidity = function () { return __awaiter(_this, void 0, void 0, function () {
224
+ var balances, promises, _i, _a, addr, prices, totalLiquidity;
225
+ return __generator(this, function (_c) {
226
+ switch (_c.label) {
227
+ case 0: return [4 /*yield*/, this.getPoolBalances()];
228
+ case 1:
229
+ balances = _c.sent();
230
+ promises = [];
231
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
232
+ addr = _a[_i];
233
+ promises.push((0, utils_1._getUsdRate)(addr));
234
+ }
235
+ return [4 /*yield*/, Promise.all(promises)];
236
+ case 2:
237
+ prices = _c.sent();
238
+ totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
239
+ return [2 /*return*/, String(totalLiquidity)];
240
+ }
241
+ });
242
+ }); };
243
+ this.getVolume = function () { return __awaiter(_this, void 0, void 0, function () {
244
+ var name, statsUrl, volume, usdRate, _a;
245
+ return __generator(this, function (_c) {
246
+ switch (_c.label) {
247
+ case 0:
248
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
249
+ statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
250
+ return [4 /*yield*/, axios_1.default.get(statsUrl)];
251
+ case 1:
252
+ volume = (_c.sent()).data.volume[name] || 0;
253
+ if (!this.isCrypto) return [3 /*break*/, 2];
254
+ _a = 1;
255
+ return [3 /*break*/, 4];
256
+ case 2: return [4 /*yield*/, (0, utils_1._getUsdRate)(this.referenceAsset)];
257
+ case 3:
258
+ _a = _c.sent();
259
+ _c.label = 4;
260
+ case 4:
261
+ usdRate = _a;
262
+ return [2 /*return*/, String(volume * usdRate)];
263
+ }
264
+ });
265
+ }); };
266
+ this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
267
+ var name, statsUrl, apy, formattedApy;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ name = (this.name === 'ren' && curve_1.curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name;
272
+ statsUrl = (0, utils_1._getStatsUrl)(this.isCrypto);
273
+ return [4 /*yield*/, axios_1.default.get(statsUrl)];
274
+ case 1:
275
+ apy = (_a.sent()).data.apy;
276
+ formattedApy = [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); });
277
+ return [2 /*return*/, {
278
+ day: formattedApy[0],
279
+ week: formattedApy[1],
280
+ month: formattedApy[2],
281
+ total: formattedApy[3],
282
+ }];
283
+ }
284
+ });
285
+ }); };
286
+ this.getTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
287
+ var gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _a, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
288
+ return __generator(this, function (_c) {
289
+ switch (_c.label) {
290
+ case 0:
291
+ if (curve_1.curve.chainId === 137)
292
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
293
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
294
+ lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
295
+ gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
296
+ return [4 /*yield*/, this.getTotalLiquidity()];
297
+ case 1:
298
+ totalLiquidityUSD = _c.sent();
299
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all([
300
+ gaugeContract.inflation_rate(),
301
+ gaugeControllerContract.gauge_relative_weight(this.gauge),
302
+ gaugeContract.working_supply(),
303
+ lpTokenContract.totalSupply(),
304
+ ])];
305
+ case 2:
306
+ _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
307
+ rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
308
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
309
+ case 3:
310
+ crvRate = _c.sent();
311
+ baseApy = rate.times(crvRate);
312
+ boostedApy = baseApy.times(2.5);
313
+ return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
314
+ }
315
+ });
316
+ }); };
317
+ this.getRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
318
+ var apy_1, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, mainPoolsGaugeRewards, mainPoolsGaugeRewardsLowerCase, apyData, apy, _d, apyData_1, data;
319
+ return __generator(this, function (_e) {
320
+ switch (_e.label) {
321
+ case 0:
322
+ if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 8];
323
+ apy_1 = [];
324
+ _i = 0, _a = this.rewardTokens;
325
+ _e.label = 1;
326
+ case 1:
327
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
328
+ rewardToken = _a[_i];
329
+ rewardContract = curve_1.curve.contracts[this.rewardContract].contract;
330
+ return [4 /*yield*/, this.getTotalLiquidity()];
331
+ case 2:
332
+ totalLiquidityUSD = _e.sent();
333
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken)];
334
+ case 3:
335
+ crvRate = _e.sent();
336
+ _c = utils_1.toBN;
337
+ return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
338
+ case 4:
339
+ inflation = _c.apply(void 0, [(_e.sent()).rate]);
340
+ baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
341
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
342
+ return [4 /*yield*/, rewardTokenContract.symbol()];
343
+ case 5:
344
+ symbol = _e.sent();
345
+ apy_1.push({
346
+ token: rewardToken,
347
+ symbol: symbol,
348
+ apy: baseApy.times(100).toFixed(4),
349
+ });
350
+ _e.label = 6;
351
+ case 6:
352
+ _i++;
353
+ return [3 /*break*/, 1];
354
+ case 7: return [2 /*return*/, apy_1];
355
+ case 8: return [4 /*yield*/, axios_1.default.get("https://api.curve.fi/api/getMainPoolsGaugeRewards")];
356
+ case 9:
357
+ mainPoolsGaugeRewards = (_e.sent()).data.data.mainPoolsGaugeRewards;
358
+ mainPoolsGaugeRewardsLowerCase = Object.fromEntries(Object.entries(mainPoolsGaugeRewards).map(function (entry) { return [entry[0].toLowerCase(), entry[1]]; }));
359
+ apyData = mainPoolsGaugeRewardsLowerCase[this.gauge.toLowerCase()] || [];
360
+ apy = [];
361
+ for (_d = 0, apyData_1 = apyData; _d < apyData_1.length; _d++) {
362
+ data = apyData_1[_d];
363
+ apy.push({
364
+ token: data.tokenAddress,
365
+ symbol: data.symbol,
366
+ apy: String(data.apy),
367
+ });
368
+ }
369
+ return [2 /*return*/, apy];
370
+ }
371
+ });
372
+ }); };
195
373
  this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
196
374
  var _this = this;
197
375
  return __generator(this, function (_a) {
@@ -281,7 +459,7 @@ var Pool = /** @class */ (function () {
281
459
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
282
460
  case 3: return [2 /*return*/, _d.sent()];
283
461
  case 4:
284
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
462
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
285
463
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
286
464
  case 5: return [2 /*return*/, _d.sent()];
287
465
  case 6:
@@ -329,7 +507,7 @@ var Pool = /** @class */ (function () {
329
507
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
330
508
  case 2: return [2 /*return*/, _a.sent()];
331
509
  case 3:
332
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
510
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
333
511
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
334
512
  case 4: return [2 /*return*/, _a.sent()];
335
513
  case 5:
@@ -459,7 +637,7 @@ var Pool = /** @class */ (function () {
459
637
  _amounts = amounts.map(function (amount, i) {
460
638
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
461
639
  });
462
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
640
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
463
641
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
464
642
  case 3: return [2 /*return*/, _d.sent()];
465
643
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -487,7 +665,7 @@ var Pool = /** @class */ (function () {
487
665
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
488
666
  case 1:
489
667
  _a.sent();
490
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
668
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
491
669
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
492
670
  case 2: return [2 /*return*/, _a.sent()];
493
671
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -504,7 +682,7 @@ var Pool = /** @class */ (function () {
504
682
  switch (_a.label) {
505
683
  case 0:
506
684
  _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];
685
+ 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
686
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
509
687
  case 1:
510
688
  _expected = _a.sent(); // Lending pools
@@ -581,7 +759,7 @@ var Pool = /** @class */ (function () {
581
759
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
582
760
  case 4: return [2 /*return*/, _c.sent()];
583
761
  case 5:
584
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
762
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
585
763
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
586
764
  case 6: return [2 /*return*/, _c.sent()];
587
765
  case 7:
@@ -606,7 +784,7 @@ var Pool = /** @class */ (function () {
606
784
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
607
785
  case 2: return [2 /*return*/, _a.sent()];
608
786
  case 3:
609
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
787
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
610
788
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
611
789
  case 4: return [2 /*return*/, _a.sent()];
612
790
  case 5:
@@ -650,7 +828,7 @@ var Pool = /** @class */ (function () {
650
828
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
651
829
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
652
830
  }
653
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
831
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
654
832
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
655
833
  case 2: return [2 /*return*/, _a.sent()];
656
834
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -670,7 +848,7 @@ var Pool = /** @class */ (function () {
670
848
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
671
849
  case 1:
672
850
  _a.sent();
673
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
851
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
674
852
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
675
853
  case 2: return [2 /*return*/, _a.sent()];
676
854
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -1047,7 +1225,7 @@ var Pool = /** @class */ (function () {
1047
1225
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1048
1226
  case 4: return [2 /*return*/, _c.sent()];
1049
1227
  case 5:
1050
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1228
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1051
1229
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1052
1230
  case 6: return [2 /*return*/, _c.sent()];
1053
1231
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1071,7 +1249,7 @@ var Pool = /** @class */ (function () {
1071
1249
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1072
1250
  case 2: return [2 /*return*/, _a.sent()];
1073
1251
  case 3:
1074
- if (!(['aave', 'saave', 'ib', 'crveth'].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1252
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1075
1253
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1076
1254
  case 4: return [2 /*return*/, _a.sent()];
1077
1255
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1143,7 +1321,7 @@ var Pool = /** @class */ (function () {
1143
1321
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1144
1322
  }
1145
1323
  _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];
1324
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1147
1325
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1148
1326
  case 2: return [2 /*return*/, _a.sent()];
1149
1327
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1167,7 +1345,7 @@ var Pool = /** @class */ (function () {
1167
1345
  case 1:
1168
1346
  _a.sent();
1169
1347
  _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];
1348
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1171
1349
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1172
1350
  case 2: return [2 /*return*/, _a.sent()];
1173
1351
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1246,6 +1424,123 @@ var Pool = /** @class */ (function () {
1246
1424
  }
1247
1425
  });
1248
1426
  }); };
1427
+ this.gaugeClaimableTokens = function (address) {
1428
+ if (address === void 0) { address = ""; }
1429
+ return __awaiter(_this, void 0, void 0, function () {
1430
+ var _a, _c;
1431
+ return __generator(this, function (_d) {
1432
+ switch (_d.label) {
1433
+ case 0:
1434
+ if (curve_1.curve.chainId !== 1)
1435
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimableRewards instead"));
1436
+ address = address || curve_1.curve.signerAddress;
1437
+ if (!address)
1438
+ throw Error("Need to connect wallet or pass address into args");
1439
+ _c = (_a = ethers_1.ethers.utils).formatUnits;
1440
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
1441
+ case 1: return [2 /*return*/, _c.apply(_a, [_d.sent()])];
1442
+ }
1443
+ });
1444
+ });
1445
+ };
1446
+ this.gaugeClaimTokens = function () { return __awaiter(_this, void 0, void 0, function () {
1447
+ var gasLimit;
1448
+ return __generator(this, function (_a) {
1449
+ switch (_a.label) {
1450
+ case 0:
1451
+ if (curve_1.curve.chainId !== 1)
1452
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimRewards instead"));
1453
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1454
+ case 1:
1455
+ gasLimit = (_a.sent()).mul(130).div(100);
1456
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1457
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1458
+ }
1459
+ });
1460
+ }); };
1461
+ // TODO 1. Fix aave and saave error
1462
+ // TODO 2. Figure out Synthetix cumulative results
1463
+ this.gaugeClaimableRewards = function (address) {
1464
+ if (address === void 0) { address = ""; }
1465
+ return __awaiter(_this, void 0, void 0, function () {
1466
+ var gaugeContract, rewards, _i, _a, rewardToken, rewardTokenContract, symbol, decimals, method, amount, _c, _d, rewardToken, rewardTokenContract, symbol, decimals, amount, _e, _f;
1467
+ return __generator(this, function (_h) {
1468
+ switch (_h.label) {
1469
+ case 0:
1470
+ address = address || curve_1.curve.signerAddress;
1471
+ if (!address)
1472
+ throw Error("Need to connect wallet or pass address into args");
1473
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1474
+ rewards = [];
1475
+ if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
1476
+ _i = 0, _a = this.rewardTokens;
1477
+ _h.label = 1;
1478
+ case 1:
1479
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
1480
+ rewardToken = _a[_i];
1481
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1482
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1483
+ case 2:
1484
+ symbol = _h.sent();
1485
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1486
+ case 3:
1487
+ decimals = _h.sent();
1488
+ method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
1489
+ _d = (_c = ethers_1.ethers.utils).formatUnits;
1490
+ return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
1491
+ case 4:
1492
+ amount = _d.apply(_c, [_h.sent(), decimals]);
1493
+ rewards.push({
1494
+ token: rewardToken,
1495
+ symbol: symbol,
1496
+ amount: amount,
1497
+ });
1498
+ _h.label = 5;
1499
+ case 5:
1500
+ _i++;
1501
+ return [3 /*break*/, 1];
1502
+ case 6: return [3 /*break*/, 11];
1503
+ case 7:
1504
+ if (!('claimable_reward(address)' in gaugeContract && this.rewardTokens.length > 0)) return [3 /*break*/, 11];
1505
+ rewardToken = this.rewardTokens[0];
1506
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1507
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1508
+ case 8:
1509
+ symbol = _h.sent();
1510
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1511
+ case 9:
1512
+ decimals = _h.sent();
1513
+ _f = (_e = ethers_1.ethers.utils).formatUnits;
1514
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1515
+ case 10:
1516
+ amount = _f.apply(_e, [_h.sent(), decimals]);
1517
+ rewards.push({
1518
+ token: rewardToken,
1519
+ symbol: symbol,
1520
+ amount: amount,
1521
+ });
1522
+ _h.label = 11;
1523
+ case 11: return [2 /*return*/, rewards];
1524
+ }
1525
+ });
1526
+ });
1527
+ };
1528
+ this.gaugeClaimRewards = function () { return __awaiter(_this, void 0, void 0, function () {
1529
+ var gaugeContract, gasLimit;
1530
+ return __generator(this, function (_a) {
1531
+ switch (_a.label) {
1532
+ case 0:
1533
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1534
+ if (!("claim_rewards()" in gaugeContract))
1535
+ throw Error("".concat(this.name, " pool doesn't have such method"));
1536
+ return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
1537
+ case 1:
1538
+ gasLimit = (_a.sent()).mul(130).div(100);
1539
+ return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1540
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1541
+ }
1542
+ });
1543
+ }); };
1249
1544
  this.balances = function () {
1250
1545
  var addresses = [];
1251
1546
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -1718,32 +2013,6 @@ var Pool = /** @class */ (function () {
1718
2013
  }
1719
2014
  });
1720
2015
  }); };
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
2016
  this._getCoinIdx = function (coin, useUnderlying) {
1748
2017
  if (useUnderlying === void 0) { useUnderlying = true; }
1749
2018
  if (typeof coin === 'number') {
@@ -1946,7 +2215,7 @@ var Pool = /** @class */ (function () {
1946
2215
  switch (_a.label) {
1947
2216
  case 0:
1948
2217
  contract = curve_1.curve.contracts[this.swap].contract;
1949
- if (!["eurtusd", "crveth"].includes(this.name)) return [3 /*break*/, 2];
2218
+ if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
1950
2219
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
1951
2220
  case 1: return [2 /*return*/, _a.sent()];
1952
2221
  case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -2647,10 +2916,12 @@ var Pool = /** @class */ (function () {
2647
2916
  }); };
2648
2917
  var poolData = curve_1.POOLS_DATA[name];
2649
2918
  this.name = name;
2919
+ this.referenceAsset = poolData.reference_asset;
2650
2920
  this.swap = poolData.swap_address;
2651
2921
  this.zap = poolData.deposit_address || null;
2652
2922
  this.lpToken = poolData.token_address;
2653
2923
  this.gauge = poolData.gauge_address;
2924
+ this.rewardContract = poolData.reward_contract || null;
2654
2925
  this.underlyingCoins = poolData.underlying_coins;
2655
2926
  this.coins = poolData.coins;
2656
2927
  this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
@@ -2663,6 +2934,7 @@ var Pool = /** @class */ (function () {
2663
2934
  this.isCrypto = poolData.is_crypto || false;
2664
2935
  this.isFactory = poolData.is_factory || false;
2665
2936
  this.basePool = poolData.base_pool || '';
2937
+ this.rewardTokens = poolData.reward_tokens || [];
2666
2938
  this.estimateGas = {
2667
2939
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2668
2940
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2685,6 +2957,16 @@ var Pool = /** @class */ (function () {
2685
2957
  exchangeWrappedApprove: this.exchangeWrappedApproveEstimateGas,
2686
2958
  exchangeWrapped: this.exchangeWrappedEstimateGas,
2687
2959
  };
2960
+ this.stats = {
2961
+ getParameters: this.getParameters,
2962
+ getPoolBalances: this.getPoolBalances,
2963
+ getPoolWrappedBalances: this.getPoolWrappedBalances,
2964
+ getTotalLiquidity: this.getTotalLiquidity,
2965
+ getVolume: this.getVolume,
2966
+ getBaseApy: this.getBaseApy,
2967
+ getTokenApy: this.getTokenApy,
2968
+ getRewardsApy: this.getRewardsApy,
2969
+ };
2688
2970
  if (this.isMeta && !this.isFake) {
2689
2971
  var metaCoins = poolData.meta_coin_addresses;
2690
2972
  var metaCoinDecimals = poolData.meta_coin_decimals;
package/lib/utils.d.ts CHANGED
@@ -20,5 +20,6 @@ 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;
25
+ export declare const getPoolList: () => string[];