@curvefi/api 1.14.0 → 1.16.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 (36) hide show
  1. package/README.md +77 -18
  2. package/lib/constants/abis/abis-ethereum.js +173 -16
  3. package/lib/constants/abis/abis-polygon.js +13 -5
  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/crveth/swap.json +61 -61
  8. package/lib/constants/abis/json/eurt/swap.json +29 -29
  9. package/lib/constants/abis/json/eurtusd/deposit.json +13 -13
  10. package/lib/constants/abis/json/eurtusd/swap.json +59 -59
  11. package/lib/constants/abis/json/gauge.json +1 -1
  12. package/lib/constants/abis/json/gauge_factory.json +879 -0
  13. package/lib/constants/abis/json/gauge_rewards_only.json +649 -0
  14. package/lib/constants/abis/json/gauge_synthetix.json +590 -0
  15. package/lib/constants/abis/json/gauge_v2.json +942 -0
  16. package/lib/constants/abis/json/gauge_v3.json +954 -0
  17. package/lib/constants/abis/json/gauge_v4.json +913 -0
  18. package/lib/constants/abis/json/minter.json +165 -0
  19. package/lib/constants/abis/json/ren-polygon/swap.json +46 -46
  20. package/lib/constants/abis/json/reth/swap.json +38 -38
  21. package/lib/constants/abis/json/tricrypto2/deposit.json +3 -3
  22. package/lib/constants/abis/json/tricrypto2/swap.json +60 -60
  23. package/lib/constants/aliases.d.ts +2 -0
  24. package/lib/constants/aliases.js +2 -0
  25. package/lib/constants/coins-ethereum.js +7 -3
  26. package/lib/constants/coins-polygon.js +3 -2
  27. package/lib/curve.d.ts +1 -0
  28. package/lib/curve.js +43 -23
  29. package/lib/index.d.ts +1 -0
  30. package/lib/index.js +1 -0
  31. package/lib/interfaces.d.ts +7 -1
  32. package/lib/pools.d.ts +23 -3
  33. package/lib/pools.js +458 -97
  34. package/lib/utils.d.ts +1 -0
  35. package/lib/utils.js +5 -3
  36. 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', "cvxeth"].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", "spelleth", "teth"].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
@@ -127,21 +127,26 @@ var Pool = /** @class */ (function () {
127
127
  });
128
128
  };
129
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) {
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
133
  case 0:
134
+ multicallContract = curve_1.curve.contracts[this.swap].multicallContract;
134
135
  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(),
136
+ multicallContract.get_virtual_price(),
137
+ multicallContract.fee(),
138
+ multicallContract.admin_fee(),
139
+ multicallContract.A(),
139
140
  ];
140
141
  if (this.isCrypto)
141
- calls.push(curve_1.curve.contracts[this.swap].multicallContract.gamma());
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
+ }
142
147
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
143
148
  case 1:
144
- _a = _d.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
149
+ _a = _f.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
145
150
  _c = [
146
151
  ethers_1.ethers.utils.formatUnits(_virtualPrice),
147
152
  ethers_1.ethers.utils.formatUnits(_fee, 8),
@@ -149,7 +154,17 @@ var Pool = /** @class */ (function () {
149
154
  ethers_1.ethers.utils.formatUnits(_A, 0),
150
155
  _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
151
156
  ], 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 }];
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 }];
153
168
  }
154
169
  });
155
170
  }); };
@@ -177,7 +192,7 @@ var Pool = /** @class */ (function () {
177
192
  _poolUnderlyingBalances = this.name !== 'atricrypto3' ? __spreadArray(__spreadArray([], _poolUnderlyingBalance, true), _basePoolExpectedAmounts, true) : __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolUnderlyingBalance, true);
178
193
  return [3 /*break*/, 6];
179
194
  case 3:
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];
195
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
181
196
  return [4 /*yield*/, this._getRates()];
182
197
  case 4:
183
198
  _rates_1 = _a.sent();
@@ -209,11 +224,11 @@ var Pool = /** @class */ (function () {
209
224
  var balances, promises, _i, _a, addr, prices, totalLiquidity;
210
225
  return __generator(this, function (_c) {
211
226
  switch (_c.label) {
212
- case 0: return [4 /*yield*/, this.getPoolWrappedBalances()];
227
+ case 0: return [4 /*yield*/, this.getPoolBalances()];
213
228
  case 1:
214
229
  balances = _c.sent();
215
230
  promises = [];
216
- for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
231
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
217
232
  addr = _a[_i];
218
233
  promises.push((0, utils_1._getUsdRate)(addr));
219
234
  }
@@ -249,7 +264,7 @@ var Pool = /** @class */ (function () {
249
264
  });
250
265
  }); };
251
266
  this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
252
- var name, statsUrl, apy;
267
+ var name, statsUrl, apy, formattedApy;
253
268
  return __generator(this, function (_a) {
254
269
  switch (_a.label) {
255
270
  case 0:
@@ -258,54 +273,103 @@ var Pool = /** @class */ (function () {
258
273
  return [4 /*yield*/, axios_1.default.get(statsUrl)];
259
274
  case 1:
260
275
  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); })];
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
+ }];
262
283
  }
263
284
  });
264
285
  }); };
265
286
  this.getTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
266
- var rewardContract, totalLiquidityUSD, crvRate, inflation, _a, baseApy, gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _c, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
267
- return __generator(this, function (_d) {
268
- switch (_d.label) {
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) {
269
290
  case 0:
270
- if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 4];
271
- rewardContract = curve_1.curve.contracts[this.crvRewardContract].contract;
272
- return [4 /*yield*/, this.getTotalLiquidity()];
273
- case 1:
274
- totalLiquidityUSD = _d.sent();
275
- return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
276
- case 2:
277
- crvRate = _d.sent();
278
- _a = utils_1.toBN;
279
- return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
280
- case 3:
281
- inflation = _a.apply(void 0, [(_d.sent()).rate]);
282
- baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
283
- return [2 /*return*/, [baseApy.times(100).toFixed(4), ""]];
284
- case 4:
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"));
285
293
  gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
286
294
  lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
287
295
  gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
288
296
  return [4 /*yield*/, this.getTotalLiquidity()];
289
- case 5:
290
- totalLiquidityUSD = _d.sent();
297
+ case 1:
298
+ totalLiquidityUSD = _c.sent();
291
299
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
292
300
  gaugeContract.inflation_rate(),
293
301
  gaugeControllerContract.gauge_relative_weight(this.gauge),
294
302
  gaugeContract.working_supply(),
295
303
  lpTokenContract.totalSupply(),
296
304
  ])];
297
- case 6:
298
- _c = (_d.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _c[0], weight = _c[1], workingSupply = _c[2], totalSupply = _c[3];
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];
299
307
  rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
300
308
  return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
301
- case 7:
302
- crvRate = _d.sent();
309
+ case 3:
310
+ crvRate = _c.sent();
303
311
  baseApy = rate.times(crvRate);
304
312
  boostedApy = baseApy.times(2.5);
305
313
  return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
306
314
  }
307
315
  });
308
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
+ }); };
309
373
  this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
310
374
  var _this = this;
311
375
  return __generator(this, function (_a) {
@@ -318,17 +382,29 @@ var Pool = /** @class */ (function () {
318
382
  });
319
383
  }); };
320
384
  this.addLiquiditySlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
321
- var totalAmount, expected, _a;
322
- return __generator(this, function (_c) {
323
- switch (_c.label) {
385
+ var prices_1, totalAmountUSD, expected_1, _a, totalAmount, expected, _c;
386
+ return __generator(this, function (_d) {
387
+ switch (_d.label) {
324
388
  case 0:
325
- totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
389
+ if (!this.isCrypto) return [3 /*break*/, 4];
390
+ return [4 /*yield*/, this._underlyingPrices()];
391
+ case 1:
392
+ prices_1 = _d.sent();
393
+ totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_1[i]); }, 0);
326
394
  _a = Number;
327
395
  return [4 /*yield*/, this.addLiquidityExpected(amounts)];
328
- case 1:
329
- expected = _a.apply(void 0, [_c.sent()]);
396
+ case 2:
397
+ expected_1 = _a.apply(void 0, [_d.sent()]);
398
+ return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_1)];
399
+ case 3: return [2 /*return*/, _d.sent()];
400
+ case 4:
401
+ totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
402
+ _c = Number;
403
+ return [4 /*yield*/, this.addLiquidityExpected(amounts)];
404
+ case 5:
405
+ expected = _c.apply(void 0, [_d.sent()]);
330
406
  return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected)];
331
- case 2: return [2 /*return*/, _c.sent()];
407
+ case 6: return [2 /*return*/, _d.sent()];
332
408
  }
333
409
  });
334
410
  }); };
@@ -395,7 +471,7 @@ var Pool = /** @class */ (function () {
395
471
  return [4 /*yield*/, this._addLiquidityZap(_amounts, true)];
396
472
  case 3: return [2 /*return*/, _d.sent()];
397
473
  case 4:
398
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
474
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 6];
399
475
  return [4 /*yield*/, this._addLiquidity(_amounts, true, true)];
400
476
  case 5: return [2 /*return*/, _d.sent()];
401
477
  case 6:
@@ -410,7 +486,7 @@ var Pool = /** @class */ (function () {
410
486
  });
411
487
  }); };
412
488
  this.balancedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
413
- var poolBalances, walletBalances, _a, _c;
489
+ var poolBalances, walletBalances, _a, _c, prices_2, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
414
490
  return __generator(this, function (_d) {
415
491
  switch (_d.label) {
416
492
  case 0: return [4 /*yield*/, this.getPoolBalances()];
@@ -420,7 +496,15 @@ var Pool = /** @class */ (function () {
420
496
  return [4 /*yield*/, this.underlyingCoinBalances()];
421
497
  case 2:
422
498
  walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
423
- return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
499
+ if (!this.isCrypto) return [3 /*break*/, 4];
500
+ return [4 /*yield*/, this._underlyingPrices()];
501
+ case 3:
502
+ prices_2 = _d.sent();
503
+ poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_2[i]; });
504
+ walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_2[i]; });
505
+ balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.underlyingDecimals);
506
+ return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_2[i], poolBalances[i])); })];
507
+ case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
424
508
  }
425
509
  });
426
510
  }); };
@@ -443,7 +527,7 @@ var Pool = /** @class */ (function () {
443
527
  return [4 /*yield*/, this._addLiquidityZap(_amounts)];
444
528
  case 2: return [2 /*return*/, _a.sent()];
445
529
  case 3:
446
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
530
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
447
531
  return [4 /*yield*/, this._addLiquidity(_amounts, true)];
448
532
  case 4: return [2 /*return*/, _a.sent()];
449
533
  case 5:
@@ -458,7 +542,7 @@ var Pool = /** @class */ (function () {
458
542
  });
459
543
  }); };
460
544
  this.balancedWrappedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
461
- var poolBalances, walletBalances, _a, _c;
545
+ var poolBalances, walletBalances, _a, _c, prices_3, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
462
546
  return __generator(this, function (_d) {
463
547
  switch (_d.label) {
464
548
  case 0:
@@ -472,7 +556,15 @@ var Pool = /** @class */ (function () {
472
556
  return [4 /*yield*/, this.coinBalances()];
473
557
  case 2:
474
558
  walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
475
- return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
559
+ if (!this.isCrypto) return [3 /*break*/, 4];
560
+ return [4 /*yield*/, this._wrappedPrices()];
561
+ case 3:
562
+ prices_3 = _d.sent();
563
+ poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_3[i]; });
564
+ walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_3[i]; });
565
+ balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.decimals);
566
+ return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_3[i], poolBalances[i])); })];
567
+ case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
476
568
  }
477
569
  });
478
570
  }); };
@@ -491,20 +583,32 @@ var Pool = /** @class */ (function () {
491
583
  });
492
584
  }); };
493
585
  this.addLiquidityWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
494
- var totalAmount, expected, _a;
495
- return __generator(this, function (_c) {
496
- switch (_c.label) {
586
+ var prices_4, totalAmountUSD, expected_2, _a, totalAmount, expected, _c;
587
+ return __generator(this, function (_d) {
588
+ switch (_d.label) {
497
589
  case 0:
498
590
  if (this.isFake) {
499
591
  throw Error("".concat(this.name, " pool doesn't have this method"));
500
592
  }
501
- totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
593
+ if (!this.isCrypto) return [3 /*break*/, 4];
594
+ return [4 /*yield*/, this._wrappedPrices()];
595
+ case 1:
596
+ prices_4 = _d.sent();
597
+ totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_4[i]); }, 0);
502
598
  _a = Number;
503
599
  return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
504
- case 1:
505
- expected = _a.apply(void 0, [_c.sent()]);
600
+ case 2:
601
+ expected_2 = _a.apply(void 0, [_d.sent()]);
602
+ return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_2, false)];
603
+ case 3: return [2 /*return*/, _d.sent()];
604
+ case 4:
605
+ totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
606
+ _c = Number;
607
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
608
+ case 5:
609
+ expected = _c.apply(void 0, [_d.sent()]);
506
610
  return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected, false)];
507
- case 2: return [2 /*return*/, _c.sent()];
611
+ case 6: return [2 /*return*/, _d.sent()];
508
612
  }
509
613
  });
510
614
  }); };
@@ -573,7 +677,7 @@ var Pool = /** @class */ (function () {
573
677
  _amounts = amounts.map(function (amount, i) {
574
678
  return ethers_1.ethers.utils.parseUnits(amount, _this.decimals[i]);
575
679
  });
576
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
680
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 4];
577
681
  return [4 /*yield*/, this._addLiquidity(_amounts, false, true)];
578
682
  case 3: return [2 /*return*/, _d.sent()];
579
683
  case 4: return [4 /*yield*/, this._addLiquiditySwap(_amounts, true)];
@@ -601,7 +705,7 @@ var Pool = /** @class */ (function () {
601
705
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
602
706
  case 1:
603
707
  _a.sent();
604
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
708
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
605
709
  return [4 /*yield*/, this._addLiquidity(_amounts, false)];
606
710
  case 2: return [2 /*return*/, _a.sent()];
607
711
  case 3: return [4 /*yield*/, this._addLiquiditySwap(_amounts)];
@@ -618,7 +722,7 @@ var Pool = /** @class */ (function () {
618
722
  switch (_a.label) {
619
723
  case 0:
620
724
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
621
- 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];
725
+ if (!(['compound', 'usdt', 'y', 'busd', 'pax', 'aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 2];
622
726
  return [4 /*yield*/, this._calcExpectedUnderlyingAmounts(_lpTokenAmount)];
623
727
  case 1:
624
728
  _expected = _a.sent(); // Lending pools
@@ -695,7 +799,7 @@ var Pool = /** @class */ (function () {
695
799
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount, true)];
696
800
  case 4: return [2 /*return*/, _c.sent()];
697
801
  case 5:
698
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
802
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
699
803
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true, true)];
700
804
  case 6: return [2 /*return*/, _c.sent()];
701
805
  case 7:
@@ -720,7 +824,7 @@ var Pool = /** @class */ (function () {
720
824
  return [4 /*yield*/, this._removeLiquidityZap(_lpTokenAmount)];
721
825
  case 2: return [2 /*return*/, _a.sent()];
722
826
  case 3:
723
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
827
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
724
828
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, true)];
725
829
  case 4: return [2 /*return*/, _a.sent()];
726
830
  case 5:
@@ -764,7 +868,7 @@ var Pool = /** @class */ (function () {
764
868
  if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
765
869
  throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
766
870
  }
767
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
871
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
768
872
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false, true)];
769
873
  case 2: return [2 /*return*/, _a.sent()];
770
874
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount, true)];
@@ -784,7 +888,7 @@ var Pool = /** @class */ (function () {
784
888
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
785
889
  case 1:
786
890
  _a.sent();
787
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
891
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
788
892
  return [4 /*yield*/, this._removeLiquidity(_lpTokenAmount, false)];
789
893
  case 2: return [2 /*return*/, _a.sent()];
790
894
  case 3: return [4 /*yield*/, this._removeLiquiditySwap(_lpTokenAmount)];
@@ -1089,7 +1193,7 @@ var Pool = /** @class */ (function () {
1089
1193
  });
1090
1194
  }); };
1091
1195
  this.removeLiquidityOneCoinSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
1092
- var totalAmount, _a;
1196
+ var totalAmount, _a, coinPrice;
1093
1197
  return __generator(this, function (_c) {
1094
1198
  switch (_c.label) {
1095
1199
  case 0:
@@ -1097,8 +1201,14 @@ var Pool = /** @class */ (function () {
1097
1201
  return [4 /*yield*/, this.removeLiquidityOneCoinExpected(lpTokenAmount, coin)];
1098
1202
  case 1:
1099
1203
  totalAmount = _a.apply(void 0, [_c.sent()]);
1100
- return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
1101
- case 2: return [2 /*return*/, _c.sent()];
1204
+ if (!this.isCrypto) return [3 /*break*/, 4];
1205
+ return [4 /*yield*/, this._underlyingPrices()];
1206
+ case 2:
1207
+ coinPrice = (_c.sent())[this._getCoinIdx(coin)];
1208
+ return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
1209
+ case 3: return [2 /*return*/, _c.sent()];
1210
+ case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
1211
+ case 5: return [2 /*return*/, _c.sent()];
1102
1212
  }
1103
1213
  });
1104
1214
  }); };
@@ -1161,7 +1271,7 @@ var Pool = /** @class */ (function () {
1161
1271
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i, true)];
1162
1272
  case 4: return [2 /*return*/, _c.sent()];
1163
1273
  case 5:
1164
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1274
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 7];
1165
1275
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true, true)];
1166
1276
  case 6: return [2 /*return*/, _c.sent()];
1167
1277
  case 7: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1185,7 +1295,7 @@ var Pool = /** @class */ (function () {
1185
1295
  return [4 /*yield*/, this._removeLiquidityOneCoinZap(_lpTokenAmount, i)];
1186
1296
  case 2: return [2 /*return*/, _a.sent()];
1187
1297
  case 3:
1188
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1298
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 5];
1189
1299
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, true)];
1190
1300
  case 4: return [2 /*return*/, _a.sent()];
1191
1301
  case 5: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1222,7 +1332,7 @@ var Pool = /** @class */ (function () {
1222
1332
  });
1223
1333
  }); };
1224
1334
  this.removeLiquidityOneCoinWrappedSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
1225
- var totalAmount, _a;
1335
+ var totalAmount, _a, coinPrice;
1226
1336
  return __generator(this, function (_c) {
1227
1337
  switch (_c.label) {
1228
1338
  case 0:
@@ -1233,8 +1343,14 @@ var Pool = /** @class */ (function () {
1233
1343
  return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
1234
1344
  case 1:
1235
1345
  totalAmount = _a.apply(void 0, [_c.sent()]);
1236
- return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
1237
- case 2: return [2 /*return*/, _c.sent()];
1346
+ if (!this.isCrypto) return [3 /*break*/, 4];
1347
+ return [4 /*yield*/, this._underlyingPrices()];
1348
+ case 2:
1349
+ coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
1350
+ return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
1351
+ case 3: return [2 /*return*/, _c.sent()];
1352
+ case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
1353
+ case 5: return [2 /*return*/, _c.sent()];
1238
1354
  }
1239
1355
  });
1240
1356
  }); };
@@ -1257,7 +1373,7 @@ var Pool = /** @class */ (function () {
1257
1373
  throw Error("".concat(this.name, " pool doesn't have remove_liquidity_one_coin method for wrapped tokens"));
1258
1374
  }
1259
1375
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1260
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1376
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1261
1377
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false, true)];
1262
1378
  case 2: return [2 /*return*/, _a.sent()];
1263
1379
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i, true)];
@@ -1281,7 +1397,7 @@ var Pool = /** @class */ (function () {
1281
1397
  case 1:
1282
1398
  _a.sent();
1283
1399
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1284
- if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1400
+ if (!(['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'))) return [3 /*break*/, 3];
1285
1401
  return [4 /*yield*/, this._removeLiquidityOneCoin(_lpTokenAmount, i, false)];
1286
1402
  case 2: return [2 /*return*/, _a.sent()];
1287
1403
  case 3: return [4 /*yield*/, this._removeLiquidityOneCoinSwap(_lpTokenAmount, i)];
@@ -1319,13 +1435,13 @@ var Pool = /** @class */ (function () {
1319
1435
  switch (_a.label) {
1320
1436
  case 0:
1321
1437
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1322
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.options)];
1438
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1323
1439
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1324
1440
  }
1325
1441
  });
1326
1442
  }); };
1327
1443
  this.gaugeDeposit = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1328
- var _lpTokenAmount;
1444
+ var _lpTokenAmount, gasLimit;
1329
1445
  return __generator(this, function (_a) {
1330
1446
  switch (_a.label) {
1331
1447
  case 0:
@@ -1333,8 +1449,11 @@ var Pool = /** @class */ (function () {
1333
1449
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
1334
1450
  case 1:
1335
1451
  _a.sent();
1336
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, curve_1.curve.options)];
1337
- case 2: return [2 /*return*/, (_a.sent()).hash];
1452
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
1453
+ case 2:
1454
+ gasLimit = (_a.sent()).mul(150).div(100);
1455
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1456
+ case 3: return [2 /*return*/, (_a.sent()).hash];
1338
1457
  }
1339
1458
  });
1340
1459
  }); };
@@ -1344,19 +1463,139 @@ var Pool = /** @class */ (function () {
1344
1463
  switch (_a.label) {
1345
1464
  case 0:
1346
1465
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1347
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.options)];
1466
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1348
1467
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1349
1468
  }
1350
1469
  });
1351
1470
  }); };
1352
1471
  this.gaugeWithdraw = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
1353
- var _lpTokenAmount;
1472
+ var _lpTokenAmount, gasLimit;
1354
1473
  return __generator(this, function (_a) {
1355
1474
  switch (_a.label) {
1356
1475
  case 0:
1357
1476
  _lpTokenAmount = ethers_1.ethers.utils.parseUnits(lpTokenAmount);
1358
- return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, curve_1.curve.options)];
1359
- case 1: return [2 /*return*/, (_a.sent()).hash];
1477
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
1478
+ case 1:
1479
+ gasLimit = (_a.sent()).mul(180).div(100);
1480
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1481
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1482
+ }
1483
+ });
1484
+ }); };
1485
+ this.gaugeClaimableTokens = function (address) {
1486
+ if (address === void 0) { address = ""; }
1487
+ return __awaiter(_this, void 0, void 0, function () {
1488
+ var _a, _c;
1489
+ return __generator(this, function (_d) {
1490
+ switch (_d.label) {
1491
+ case 0:
1492
+ if (curve_1.curve.chainId !== 1)
1493
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimableRewards instead"));
1494
+ address = address || curve_1.curve.signerAddress;
1495
+ if (!address)
1496
+ throw Error("Need to connect wallet or pass address into args");
1497
+ _c = (_a = ethers_1.ethers.utils).formatUnits;
1498
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
1499
+ case 1: return [2 /*return*/, _c.apply(_a, [_d.sent()])];
1500
+ }
1501
+ });
1502
+ });
1503
+ };
1504
+ this.gaugeClaimTokens = function () { return __awaiter(_this, void 0, void 0, function () {
1505
+ var gasLimit;
1506
+ return __generator(this, function (_a) {
1507
+ switch (_a.label) {
1508
+ case 0:
1509
+ if (curve_1.curve.chainId !== 1)
1510
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimRewards instead"));
1511
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1512
+ case 1:
1513
+ gasLimit = (_a.sent()).mul(130).div(100);
1514
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1515
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1516
+ }
1517
+ });
1518
+ }); };
1519
+ // TODO 1. Fix aave and saave error
1520
+ // TODO 2. Figure out Synthetix cumulative results
1521
+ this.gaugeClaimableRewards = function (address) {
1522
+ if (address === void 0) { address = ""; }
1523
+ return __awaiter(_this, void 0, void 0, function () {
1524
+ var gaugeContract, rewards, _i, _a, rewardToken, rewardTokenContract, symbol, decimals, method, amount, _c, _d, rewardToken, rewardTokenContract, symbol, decimals, amount, _e, _f;
1525
+ return __generator(this, function (_h) {
1526
+ switch (_h.label) {
1527
+ case 0:
1528
+ address = address || curve_1.curve.signerAddress;
1529
+ if (!address)
1530
+ throw Error("Need to connect wallet or pass address into args");
1531
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1532
+ rewards = [];
1533
+ if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
1534
+ _i = 0, _a = this.rewardTokens;
1535
+ _h.label = 1;
1536
+ case 1:
1537
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
1538
+ rewardToken = _a[_i];
1539
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1540
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1541
+ case 2:
1542
+ symbol = _h.sent();
1543
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1544
+ case 3:
1545
+ decimals = _h.sent();
1546
+ method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
1547
+ _d = (_c = ethers_1.ethers.utils).formatUnits;
1548
+ return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
1549
+ case 4:
1550
+ amount = _d.apply(_c, [_h.sent(), decimals]);
1551
+ rewards.push({
1552
+ token: rewardToken,
1553
+ symbol: symbol,
1554
+ amount: amount,
1555
+ });
1556
+ _h.label = 5;
1557
+ case 5:
1558
+ _i++;
1559
+ return [3 /*break*/, 1];
1560
+ case 6: return [3 /*break*/, 11];
1561
+ case 7:
1562
+ if (!('claimable_reward(address)' in gaugeContract && this.rewardTokens.length > 0)) return [3 /*break*/, 11];
1563
+ rewardToken = this.rewardTokens[0];
1564
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1565
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1566
+ case 8:
1567
+ symbol = _h.sent();
1568
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1569
+ case 9:
1570
+ decimals = _h.sent();
1571
+ _f = (_e = ethers_1.ethers.utils).formatUnits;
1572
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1573
+ case 10:
1574
+ amount = _f.apply(_e, [_h.sent(), decimals]);
1575
+ rewards.push({
1576
+ token: rewardToken,
1577
+ symbol: symbol,
1578
+ amount: amount,
1579
+ });
1580
+ _h.label = 11;
1581
+ case 11: return [2 /*return*/, rewards];
1582
+ }
1583
+ });
1584
+ });
1585
+ };
1586
+ this.gaugeClaimRewards = function () { return __awaiter(_this, void 0, void 0, function () {
1587
+ var gaugeContract, gasLimit;
1588
+ return __generator(this, function (_a) {
1589
+ switch (_a.label) {
1590
+ case 0:
1591
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1592
+ if (!("claim_rewards()" in gaugeContract))
1593
+ throw Error("".concat(this.name, " pool doesn't have such method"));
1594
+ return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
1595
+ case 1:
1596
+ gasLimit = (_a.sent()).mul(130).div(100);
1597
+ return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1598
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1360
1599
  }
1361
1600
  });
1362
1601
  }); };
@@ -1450,7 +1689,7 @@ var Pool = /** @class */ (function () {
1450
1689
  return __generator(this, function (_a) {
1451
1690
  switch (_a.label) {
1452
1691
  case 0:
1453
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1692
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1454
1693
  i = this._getCoinIdx(inputCoin);
1455
1694
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.underlyingCoinAddresses[i]], [amount], curve_1.curve.signerAddress, contractAddress)];
1456
1695
  case 1: return [2 /*return*/, _a.sent()];
@@ -1462,7 +1701,7 @@ var Pool = /** @class */ (function () {
1462
1701
  return __generator(this, function (_a) {
1463
1702
  switch (_a.label) {
1464
1703
  case 0:
1465
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1704
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1466
1705
  i = this._getCoinIdx(inputCoin);
1467
1706
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1468
1707
  case 1: return [2 /*return*/, _a.sent()];
@@ -1474,7 +1713,7 @@ var Pool = /** @class */ (function () {
1474
1713
  return __generator(this, function (_a) {
1475
1714
  switch (_a.label) {
1476
1715
  case 0:
1477
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1716
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1478
1717
  i = this._getCoinIdx(inputCoin);
1479
1718
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
1480
1719
  case 1: return [2 /*return*/, _a.sent()];
@@ -1488,7 +1727,7 @@ var Pool = /** @class */ (function () {
1488
1727
  return __generator(this, function (_d) {
1489
1728
  switch (_d.label) {
1490
1729
  case 0:
1491
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1730
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1492
1731
  i = this._getCoinIdx(inputCoin);
1493
1732
  j = this._getCoinIdx(outputCoin);
1494
1733
  _c = (_a = Object).values;
@@ -1529,7 +1768,7 @@ var Pool = /** @class */ (function () {
1529
1768
  return __generator(this, function (_a) {
1530
1769
  switch (_a.label) {
1531
1770
  case 0:
1532
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1771
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
1533
1772
  i = this._getCoinIdx(inputCoin);
1534
1773
  j = this._getCoinIdx(outputCoin);
1535
1774
  _amount = ethers_1.ethers.utils.parseUnits(amount, this.underlyingDecimals[i]);
@@ -1934,6 +2173,90 @@ var Pool = /** @class */ (function () {
1934
2173
  });
1935
2174
  });
1936
2175
  };
2176
+ this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
2177
+ var promises, _i, _a, addr;
2178
+ return __generator(this, function (_c) {
2179
+ switch (_c.label) {
2180
+ case 0:
2181
+ promises = [];
2182
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
2183
+ addr = _a[_i];
2184
+ promises.push((0, utils_1._getUsdRate)(addr));
2185
+ }
2186
+ return [4 /*yield*/, Promise.all(promises)];
2187
+ case 1: return [2 /*return*/, _c.sent()];
2188
+ }
2189
+ });
2190
+ }); };
2191
+ // NOTE! It may crash!
2192
+ this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
2193
+ var promises, _i, _a, addr;
2194
+ return __generator(this, function (_c) {
2195
+ switch (_c.label) {
2196
+ case 0:
2197
+ promises = [];
2198
+ for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
2199
+ addr = _a[_i];
2200
+ promises.push((0, utils_1._getUsdRate)(addr));
2201
+ }
2202
+ return [4 /*yield*/, Promise.all(promises)];
2203
+ case 1: return [2 /*return*/, _c.sent()];
2204
+ }
2205
+ });
2206
+ }); };
2207
+ this._addLiquidityCryptoSlippage = function (totalAmountUSD, expected, useUnderlying) {
2208
+ if (useUnderlying === void 0) { useUnderlying = true; }
2209
+ return __awaiter(_this, void 0, void 0, function () {
2210
+ var poolBalances, _a, prices, _c, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _d, _e, _f;
2211
+ return __generator(this, function (_h) {
2212
+ switch (_h.label) {
2213
+ case 0:
2214
+ if (!useUnderlying) return [3 /*break*/, 2];
2215
+ return [4 /*yield*/, this.getPoolBalances()];
2216
+ case 1:
2217
+ _a = (_h.sent()).map(Number);
2218
+ return [3 /*break*/, 4];
2219
+ case 2: return [4 /*yield*/, this.getPoolWrappedBalances()];
2220
+ case 3:
2221
+ _a = (_h.sent()).map(Number);
2222
+ _h.label = 4;
2223
+ case 4:
2224
+ poolBalances = _a;
2225
+ if (!useUnderlying) return [3 /*break*/, 6];
2226
+ return [4 /*yield*/, this._underlyingPrices()];
2227
+ case 5:
2228
+ _c = _h.sent();
2229
+ return [3 /*break*/, 8];
2230
+ case 6: return [4 /*yield*/, this._wrappedPrices()];
2231
+ case 7:
2232
+ _c = _h.sent();
2233
+ _h.label = 8;
2234
+ case 8:
2235
+ prices = _c;
2236
+ poolBalancesUSD = poolBalances.map(function (b, i) { return Number(b) * prices[i]; });
2237
+ poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
2238
+ poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
2239
+ balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
2240
+ balancedAmounts = balancedAmountsUSD.map(function (a, i) { return String(a / prices[i]); });
2241
+ if (!useUnderlying) return [3 /*break*/, 10];
2242
+ _e = Number;
2243
+ return [4 /*yield*/, this.addLiquidityExpected(balancedAmounts)];
2244
+ case 9:
2245
+ _d = _e.apply(void 0, [_h.sent()]);
2246
+ return [3 /*break*/, 12];
2247
+ case 10:
2248
+ _f = Number;
2249
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(balancedAmounts)];
2250
+ case 11:
2251
+ _d = _f.apply(void 0, [_h.sent()]);
2252
+ _h.label = 12;
2253
+ case 12:
2254
+ balancedExpected = _d;
2255
+ return [2 /*return*/, String((balancedExpected - expected) / balancedExpected)];
2256
+ }
2257
+ });
2258
+ });
2259
+ };
1937
2260
  this._addLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
1938
2261
  if (useUnderlying === void 0) { useUnderlying = true; }
1939
2262
  return __awaiter(_this, void 0, void 0, function () {
@@ -1974,6 +2297,41 @@ var Pool = /** @class */ (function () {
1974
2297
  });
1975
2298
  });
1976
2299
  };
2300
+ this._removeLiquidityCryptoSlippage = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
2301
+ if (useUnderlying === void 0) { useUnderlying = true; }
2302
+ return __awaiter(_this, void 0, void 0, function () {
2303
+ var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
2304
+ return __generator(this, function (_d) {
2305
+ switch (_d.label) {
2306
+ case 0:
2307
+ if (!useUnderlying) return [3 /*break*/, 2];
2308
+ return [4 /*yield*/, this._underlyingPrices()];
2309
+ case 1:
2310
+ _a = _d.sent();
2311
+ return [3 /*break*/, 4];
2312
+ case 2: return [4 /*yield*/, this._wrappedPrices()];
2313
+ case 3:
2314
+ _a = _d.sent();
2315
+ _d.label = 4;
2316
+ case 4:
2317
+ prices = _a;
2318
+ if (!useUnderlying) return [3 /*break*/, 6];
2319
+ return [4 /*yield*/, this.removeLiquidityExpected(String(lpTokenAmount))];
2320
+ case 5:
2321
+ _c = _d.sent();
2322
+ return [3 /*break*/, 8];
2323
+ case 6: return [4 /*yield*/, this.removeLiquidityWrappedExpected(String(lpTokenAmount))];
2324
+ case 7:
2325
+ _c = _d.sent();
2326
+ _d.label = 8;
2327
+ case 8:
2328
+ balancedAmounts = _c;
2329
+ balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
2330
+ return [2 /*return*/, String((balancedTotalAmountsUSD - totalAmountUSD) / balancedTotalAmountsUSD)];
2331
+ }
2332
+ });
2333
+ });
2334
+ };
1977
2335
  this._removeLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
1978
2336
  if (useUnderlying === void 0) { useUnderlying = true; }
1979
2337
  return __awaiter(_this, void 0, void 0, function () {
@@ -2015,7 +2373,8 @@ var Pool = /** @class */ (function () {
2015
2373
  });
2016
2374
  };
2017
2375
  this._balancedAmounts = function (poolBalances, walletBalances, decimals) {
2018
- var poolBalancesRatios = poolBalances.map(function (b) { return b / poolBalances.reduce(function (a, b) { return a + b; }); });
2376
+ var poolTotalLiquidity = poolBalances.reduce(function (a, b) { return a + b; });
2377
+ var poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalLiquidity; });
2019
2378
  // Cross factors for each wallet balance used as reference to see the
2020
2379
  // max that can be used according to the lowest relative wallet balance
2021
2380
  var balancedAmountsForEachScenario = walletBalances.map(function (_, i) { return (walletBalances.map(function (_, j) { return (poolBalancesRatios[j] * walletBalances[i] / poolBalancesRatios[i]); })); });
@@ -2034,7 +2393,7 @@ var Pool = /** @class */ (function () {
2034
2393
  switch (_a.label) {
2035
2394
  case 0:
2036
2395
  contract = curve_1.curve.contracts[this.swap].contract;
2037
- if (!["eurtusd", "crveth", "cvxeth"].includes(this.name)) return [3 /*break*/, 2];
2396
+ if (!["eurtusd", "xautusd", "crveth", "cvxeth", "spelleth", "teth"].includes(this.name)) return [3 /*break*/, 2];
2038
2397
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
2039
2398
  case 1: return [2 /*return*/, _a.sent()];
2040
2399
  case 2: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -2055,7 +2414,7 @@ var Pool = /** @class */ (function () {
2055
2414
  return [4 /*yield*/, contract.calc_token_amount(this.swap, _amounts, isDeposit, curve_1.curve.constantOptions)];
2056
2415
  case 1: return [2 /*return*/, _a.sent()];
2057
2416
  case 2:
2058
- if (!(this.name === "eurtusd")) return [3 /*break*/, 4];
2417
+ if (!["eurtusd", "xautusd"].includes(this.name)) return [3 /*break*/, 4];
2059
2418
  return [4 /*yield*/, contract.calc_token_amount(_amounts, curve_1.curve.constantOptions)];
2060
2419
  case 3: return [2 /*return*/, _a.sent()];
2061
2420
  case 4: return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve_1.curve.constantOptions)];
@@ -2715,7 +3074,7 @@ var Pool = /** @class */ (function () {
2715
3074
  return __generator(this, function (_a) {
2716
3075
  switch (_a.label) {
2717
3076
  case 0:
2718
- contractAddress = ["eurtusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
3077
+ contractAddress = ["eurtusd", "xautusd", "atricrypto3"].includes(this.name) ? this.zap : this.swap;
2719
3078
  contract = curve_1.curve.contracts[contractAddress].contract;
2720
3079
  if (!Object.prototype.hasOwnProperty.call(contract, 'get_dy_underlying')) return [3 /*break*/, 2];
2721
3080
  return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve_1.curve.constantOptions)];
@@ -2740,7 +3099,7 @@ var Pool = /** @class */ (function () {
2740
3099
  this.zap = poolData.deposit_address || null;
2741
3100
  this.lpToken = poolData.token_address;
2742
3101
  this.gauge = poolData.gauge_address;
2743
- this.crvRewardContract = poolData.crv_reward_contract || null;
3102
+ this.rewardContract = poolData.reward_contract || null;
2744
3103
  this.underlyingCoins = poolData.underlying_coins;
2745
3104
  this.coins = poolData.coins;
2746
3105
  this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
@@ -2753,6 +3112,7 @@ var Pool = /** @class */ (function () {
2753
3112
  this.isCrypto = poolData.is_crypto || false;
2754
3113
  this.isFactory = poolData.is_factory || false;
2755
3114
  this.basePool = poolData.base_pool || '';
3115
+ this.rewardTokens = poolData.reward_tokens || [];
2756
3116
  this.estimateGas = {
2757
3117
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2758
3118
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2783,6 +3143,7 @@ var Pool = /** @class */ (function () {
2783
3143
  getVolume: this.getVolume,
2784
3144
  getBaseApy: this.getBaseApy,
2785
3145
  getTokenApy: this.getTokenApy,
3146
+ getRewardsApy: this.getRewardsApy,
2786
3147
  };
2787
3148
  if (this.isMeta && !this.isFake) {
2788
3149
  var metaCoins = poolData.meta_coin_addresses;
@@ -2864,10 +3225,10 @@ var _getBestPoolAndOutput = function (inputCoinAddress, outputCoinAddress, amoun
2864
3225
  else if (inputCoinIndexes[1] >= 0 && outputCoinIndexes[1] >= 0) {
2865
3226
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2866
3227
  }
2867
- else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && pool[0] !== 'eurtusd') {
3228
+ else if (inputCoinIndexes[0] === 0 && outputCoinIndexes[2] >= 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
2868
3229
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2869
3230
  }
2870
- else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && pool[0] !== 'eurtusd') {
3231
+ else if (inputCoinIndexes[2] >= 0 && outputCoinIndexes[0] === 0 && !['eurtusd', "xautusd"].includes(pool[0])) {
2871
3232
  return { poolAddress: pool[1].swap_address, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 };
2872
3233
  }
2873
3234
  else {