@curvefi/api 2.2.0 → 2.3.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.
@@ -62,9 +62,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
62
62
  exports.PoolTemplate = void 0;
63
63
  var ethers_1 = require("ethers");
64
64
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
65
+ var memoizee_1 = __importDefault(require("memoizee"));
65
66
  var external_api_1 = require("../external-api");
66
67
  var utils_1 = require("../utils");
67
68
  var curve_1 = require("../curve");
69
+ var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
68
70
  var PoolTemplate = /** @class */ (function () {
69
71
  function PoolTemplate(id) {
70
72
  var _this = this;
@@ -190,36 +192,55 @@ var PoolTemplate = /** @class */ (function () {
190
192
  });
191
193
  }); };
192
194
  this.statsTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
193
- var gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _a, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
194
- return __generator(this, function (_c) {
195
- switch (_c.label) {
195
+ var totalLiquidityUSD, gaugeContract_1, crvContract, week, currentWeek, inflationRateBN, _a, _c, crvRate_1, apy, gaugeContract, lpTokenContract, gaugeControllerContract, _d, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
196
+ return __generator(this, function (_e) {
197
+ switch (_e.label) {
196
198
  case 0:
197
199
  if (this.gauge === ethers_1.ethers.constants.AddressZero)
198
200
  throw Error("".concat(this.name, " doesn't have gauge"));
199
- if (curve_1.curve.chainId !== 1)
200
- throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
201
- gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
202
- lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
203
- gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
204
201
  return [4 /*yield*/, this.statsTotalLiquidity()];
205
202
  case 1:
206
- totalLiquidityUSD = _c.sent();
203
+ totalLiquidityUSD = _e.sent();
207
204
  if (Number(totalLiquidityUSD) === 0)
208
205
  return [2 /*return*/, ["0", "0"]];
206
+ if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 6];
207
+ gaugeContract_1 = curve_1.curve.contracts[this.gauge].contract;
208
+ crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
209
+ week = 7 * 86400;
210
+ currentWeek = Math.floor(Date.now() / 1000 / week);
211
+ _a = utils_1.toBN;
212
+ return [4 /*yield*/, gaugeContract_1.inflation_rate(currentWeek, curve_1.curve.constantOptions)];
213
+ case 2:
214
+ inflationRateBN = _a.apply(void 0, [_e.sent()]);
215
+ if (!inflationRateBN.eq(0)) return [3 /*break*/, 4];
216
+ _c = utils_1.toBN;
217
+ return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
218
+ case 3:
219
+ inflationRateBN = _c.apply(void 0, [_e.sent()]).div(week);
220
+ _e.label = 4;
221
+ case 4: return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
222
+ case 5:
223
+ crvRate_1 = _e.sent();
224
+ apy = inflationRateBN.times(31536000).times(crvRate_1).div(Number(totalLiquidityUSD));
225
+ return [2 /*return*/, [apy.times(100).toFixed(4), apy.times(100).toFixed(4)]];
226
+ case 6:
227
+ gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
228
+ lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
229
+ gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
209
230
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
210
231
  gaugeContract.inflation_rate(),
211
232
  gaugeControllerContract.gauge_relative_weight(this.gauge),
212
233
  gaugeContract.working_supply(),
213
234
  lpTokenContract.totalSupply(),
214
235
  ])];
215
- case 2:
216
- _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
236
+ case 7:
237
+ _d = (_e.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _d[0], weight = _d[1], workingSupply = _d[2], totalSupply = _d[3];
217
238
  if (Number(workingSupply) === 0)
218
239
  return [2 /*return*/, ["0", "0"]];
219
240
  rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
220
241
  return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
221
- case 3:
222
- crvRate = _c.sent();
242
+ case 8:
243
+ crvRate = _e.sent();
223
244
  baseApy = rate.times(crvRate);
224
245
  boostedApy = baseApy.times(2.5);
225
246
  return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
@@ -227,44 +248,44 @@ var PoolTemplate = /** @class */ (function () {
227
248
  });
228
249
  }); };
229
250
  this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
230
- var apy, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, network, promises, _d, mainPoolsRewards, allTypesExtendedPoolData, rewards, _e, _f, extendedPoolData, _g, _h, pool;
231
- var _j;
232
- return __generator(this, function (_k) {
233
- switch (_k.label) {
251
+ var apy, rewardTokens, _i, rewardTokens_1, rewardToken, gaugeContract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _a, mainPoolsRewards, allTypesExtendedPoolData, rewards, _c, _d, extendedPoolData, _e, _f, pool;
252
+ var _g;
253
+ return __generator(this, function (_h) {
254
+ switch (_h.label) {
234
255
  case 0:
235
- if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 8];
256
+ if (![137, 43114].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
236
257
  apy = [];
237
- _i = 0, _a = this.rewardTokens;
238
- _k.label = 1;
258
+ return [4 /*yield*/, this.rewardTokens()];
239
259
  case 1:
240
- if (!(_i < _a.length)) return [3 /*break*/, 7];
241
- rewardToken = _a[_i];
242
- rewardContract = curve_1.curve.contracts[this.rewardContract].contract;
243
- return [4 /*yield*/, this.statsTotalLiquidity()];
260
+ rewardTokens = _h.sent();
261
+ _i = 0, rewardTokens_1 = rewardTokens;
262
+ _h.label = 2;
244
263
  case 2:
245
- totalLiquidityUSD = _k.sent();
246
- return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken)];
264
+ if (!(_i < rewardTokens_1.length)) return [3 /*break*/, 7];
265
+ rewardToken = rewardTokens_1[_i];
266
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
267
+ return [4 /*yield*/, this.statsTotalLiquidity()];
247
268
  case 3:
248
- crvRate = _k.sent();
249
- _c = utils_1.toBN;
250
- return [4 /*yield*/, rewardContract.reward_data(curve_1.curve.constants.ALIASES.crv, curve_1.curve.constantOptions)];
269
+ totalLiquidityUSD = _h.sent();
270
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
251
271
  case 4:
252
- inflation = _c.apply(void 0, [(_k.sent()).rate]);
253
- baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
254
- rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
255
- return [4 /*yield*/, rewardTokenContract.symbol()];
272
+ rewardRate = _h.sent();
273
+ return [4 /*yield*/, gaugeContract.reward_data(rewardToken.token, curve_1.curve.constantOptions)];
256
274
  case 5:
257
- symbol = _k.sent();
275
+ rewardData = _h.sent();
276
+ periodFinish = Number(ethers_1.ethers.utils.formatUnits(rewardData.period_finish, 0)) * 1000;
277
+ inflation = (0, utils_1.toBN)(rewardData.rate, rewardToken.decimals);
278
+ baseApy = periodFinish > Date.now() ? inflation.times(31536000).times(rewardRate).div(Number(totalLiquidityUSD)) : (0, utils_1.BN)(0);
258
279
  apy.push({
259
280
  gaugeAddress: this.gauge.toLowerCase(),
260
- tokenAddress: rewardToken,
261
- symbol: symbol,
281
+ tokenAddress: rewardToken.token,
282
+ symbol: rewardToken.symbol,
262
283
  apy: Number(baseApy.times(100).toFixed(4)),
263
284
  });
264
- _k.label = 6;
285
+ _h.label = 6;
265
286
  case 6:
266
287
  _i++;
267
- return [3 /*break*/, 1];
288
+ return [3 /*break*/, 2];
268
289
  case 7: return [2 /*return*/, apy];
269
290
  case 8:
270
291
  network = curve_1.curve.constants.NETWORK_NAME;
@@ -277,21 +298,87 @@ var PoolTemplate = /** @class */ (function () {
277
298
  ];
278
299
  return [4 /*yield*/, Promise.all(promises)];
279
300
  case 9:
280
- _d = _k.sent(), mainPoolsRewards = _d[0], allTypesExtendedPoolData = _d.slice(1);
301
+ _a = _h.sent(), mainPoolsRewards = _a[0], allTypesExtendedPoolData = _a.slice(1);
281
302
  rewards = mainPoolsRewards;
282
- for (_e = 0, _f = allTypesExtendedPoolData; _e < _f.length; _e++) {
283
- extendedPoolData = _f[_e];
284
- for (_g = 0, _h = extendedPoolData.poolData; _g < _h.length; _g++) {
285
- pool = _h[_g];
303
+ for (_c = 0, _d = allTypesExtendedPoolData; _c < _d.length; _c++) {
304
+ extendedPoolData = _d[_c];
305
+ for (_e = 0, _f = extendedPoolData.poolData; _e < _f.length; _e++) {
306
+ pool = _f[_e];
286
307
  if (pool.gaugeAddress && pool.gaugeRewards) {
287
308
  rewards[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
288
309
  }
289
310
  }
290
311
  }
291
- return [2 /*return*/, (_j = rewards[this.gauge.toLowerCase()]) !== null && _j !== void 0 ? _j : []];
312
+ return [2 /*return*/, (_g = rewards[this.gauge.toLowerCase()]) !== null && _g !== void 0 ? _g : []];
292
313
  }
293
314
  });
294
315
  }); };
316
+ this.rewardTokens = (0, memoizee_1.default)(function () { return __awaiter(_this, void 0, void 0, function () {
317
+ var gaugeContract, gaugeMulticallContract, rewardCount, _a, _c, _d, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, _e, symbol, decimals;
318
+ return __generator(this, function (_f) {
319
+ switch (_f.label) {
320
+ case 0:
321
+ if (this.gauge === ethers_1.ethers.constants.AddressZero)
322
+ return [2 /*return*/, []];
323
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
324
+ gaugeMulticallContract = curve_1.curve.contracts[this.gauge].multicallContract;
325
+ if (!("reward_tokens(uint256)" in gaugeContract)) return [3 /*break*/, 5];
326
+ rewardCount = 8;
327
+ if (!("reward_count()" in gaugeContract)) return [3 /*break*/, 2];
328
+ _a = Number;
329
+ _d = (_c = ethers_1.ethers.utils).formatUnits;
330
+ return [4 /*yield*/, gaugeContract.reward_count(curve_1.curve.constantOptions)];
331
+ case 1:
332
+ rewardCount = _a.apply(void 0, [_d.apply(_c, [_f.sent(), 0])]);
333
+ _f.label = 2;
334
+ case 2:
335
+ tokenCalls = [];
336
+ for (i = 0; i < rewardCount; i++) {
337
+ tokenCalls.push(gaugeMulticallContract.reward_tokens(i));
338
+ }
339
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenCalls)];
340
+ case 3:
341
+ tokens = (_f.sent())
342
+ .filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
343
+ .map(function (addr) { return addr.toLowerCase(); });
344
+ tokenInfoCalls = [];
345
+ for (_i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
346
+ token = tokens_1[_i];
347
+ (0, utils_1._setContracts)(token, ERC20_json_1.default);
348
+ tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
349
+ tokenInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
350
+ }
351
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenInfoCalls)];
352
+ case 4:
353
+ tokenInfo_1 = _f.sent();
354
+ for (i = 0; i < tokens.length; i++) {
355
+ curve_1.curve.constants.DECIMALS[tokens[i]] = tokenInfo_1[(i * 2) + 1];
356
+ }
357
+ return [2 /*return*/, tokens.map(function (token, i) { return ({ token: token, symbol: tokenInfo_1[i * 2], decimals: tokenInfo_1[(i * 2) + 1] }); })];
358
+ case 5:
359
+ if (!('claimable_reward(address)' in gaugeContract)) return [3 /*break*/, 8];
360
+ rewardContract = curve_1.curve.contracts[this.sRewardContract].contract;
361
+ method = "snx()" in rewardContract ? "snx" : "rewardsToken" // susd, tbtc : dusd, musd, rsv, sbtc
362
+ ;
363
+ return [4 /*yield*/, rewardContract[method](curve_1.curve.constantOptions)];
364
+ case 6:
365
+ token = (_f.sent()).toLowerCase();
366
+ (0, utils_1._setContracts)(token, ERC20_json_1.default);
367
+ tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
368
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all([
369
+ tokenMulticallContract.symbol(),
370
+ tokenMulticallContract.decimals(),
371
+ ])];
372
+ case 7:
373
+ _e = _f.sent(), symbol = _e[0], decimals = _e[1];
374
+ return [2 /*return*/, [{ token: token, symbol: symbol, decimals: decimals }]];
375
+ case 8: return [2 /*return*/, []]; // gauge
376
+ }
377
+ });
378
+ }); }, {
379
+ promise: true,
380
+ maxAge: 30 * 60 * 1000, // 30m
381
+ });
295
382
  // ---------------- ... ----------------
296
383
  this.gaugeMaxBoostedDeposit = function () {
297
384
  var addresses = [];
@@ -637,6 +724,7 @@ var PoolTemplate = /** @class */ (function () {
637
724
  this.lpToken = poolData.token_address;
638
725
  this.gauge = poolData.gauge_address;
639
726
  this.zap = poolData.deposit_address || null;
727
+ this.sRewardContract = poolData.sCurveRewards_address || null;
640
728
  this.rewardContract = poolData.reward_contract || null;
641
729
  this.isPlain = poolData.is_plain || false;
642
730
  this.isLending = poolData.is_lending || false;
@@ -653,7 +741,6 @@ var PoolTemplate = /** @class */ (function () {
653
741
  this.underlyingDecimals = poolData.underlying_decimals;
654
742
  this.wrappedDecimals = poolData.wrapped_decimals;
655
743
  this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(function () { return false; });
656
- this.rewardTokens = poolData.reward_tokens || [];
657
744
  this.estimateGas = {
658
745
  depositApprove: this.depositApproveEstimateGas.bind(this),
659
746
  deposit: this.depositEstimateGas.bind(this),
@@ -1091,8 +1178,6 @@ var PoolTemplate = /** @class */ (function () {
1091
1178
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1092
1179
  throw Error("claimableCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1093
1180
  }
1094
- if (curve_1.curve.chainId !== 1)
1095
- throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimableRewards instead"));
1096
1181
  address = address || curve_1.curve.signerAddress;
1097
1182
  if (!address)
1098
1183
  throw Error("Need to connect wallet or pass address into args");
@@ -1111,8 +1196,6 @@ var PoolTemplate = /** @class */ (function () {
1111
1196
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1112
1197
  throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1113
1198
  }
1114
- if (curve_1.curve.chainId !== 1)
1115
- throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimRewards instead"));
1116
1199
  return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1117
1200
  case 1: return [2 /*return*/, (_a.sent()).toNumber()];
1118
1201
  }
@@ -1121,32 +1204,30 @@ var PoolTemplate = /** @class */ (function () {
1121
1204
  };
1122
1205
  PoolTemplate.prototype.claimCrv = function () {
1123
1206
  return __awaiter(this, void 0, void 0, function () {
1124
- var gasLimit;
1207
+ var contract, gasLimit;
1125
1208
  return __generator(this, function (_a) {
1126
1209
  switch (_a.label) {
1127
1210
  case 0:
1128
1211
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1129
1212
  throw Error("claimCrv method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
1130
1213
  }
1131
- if (curve_1.curve.chainId !== 1)
1132
- throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use claimRewards instead"));
1133
- return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1214
+ contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract;
1215
+ return [4 /*yield*/, contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1134
1216
  case 1:
1135
1217
  gasLimit = (_a.sent()).mul(130).div(100);
1136
- return [4 /*yield*/, curve_1.curve.contracts[curve_1.curve.constants.ALIASES.minter].contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1218
+ return [4 /*yield*/, contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1137
1219
  case 2: return [2 /*return*/, (_a.sent()).hash];
1138
1220
  }
1139
1221
  });
1140
1222
  });
1141
1223
  };
1142
1224
  // TODO 1. Fix aave and saave error
1143
- // TODO 2. Figure out Synthetix cumulative results
1144
1225
  PoolTemplate.prototype.claimableRewards = function (address) {
1145
1226
  if (address === void 0) { address = ""; }
1146
1227
  return __awaiter(this, void 0, void 0, function () {
1147
- var gaugeContract, rewards, _i, _a, rewardToken, rewardTokenContract, symbol, decimals, method, amount, _c, _d, rewardToken, rewardTokenContract, symbol, decimals, amount, _e, _f;
1148
- return __generator(this, function (_g) {
1149
- switch (_g.label) {
1228
+ var gaugeContract, rewardTokens, rewards, _i, rewardTokens_2, rewardToken, amount, _a, _c, rewardToken, _totalAmount, _claimedAmount;
1229
+ return __generator(this, function (_d) {
1230
+ switch (_d.label) {
1150
1231
  case 0:
1151
1232
  if (this.gauge === ethers_1.ethers.constants.AddressZero) {
1152
1233
  throw Error("claimableRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
@@ -1155,56 +1236,46 @@ var PoolTemplate = /** @class */ (function () {
1155
1236
  if (!address)
1156
1237
  throw Error("Need to connect wallet or pass address into args");
1157
1238
  gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1158
- rewards = [];
1159
- if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
1160
- _i = 0, _a = this.rewardTokens;
1161
- _g.label = 1;
1239
+ return [4 /*yield*/, this.rewardTokens()];
1162
1240
  case 1:
1163
- if (!(_i < _a.length)) return [3 /*break*/, 6];
1164
- rewardToken = _a[_i];
1165
- rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1166
- return [4 /*yield*/, rewardTokenContract.symbol()];
1241
+ rewardTokens = _d.sent();
1242
+ rewards = [];
1243
+ if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 6];
1244
+ _i = 0, rewardTokens_2 = rewardTokens;
1245
+ _d.label = 2;
1167
1246
  case 2:
1168
- symbol = _g.sent();
1169
- return [4 /*yield*/, rewardTokenContract.decimals()];
1247
+ if (!(_i < rewardTokens_2.length)) return [3 /*break*/, 5];
1248
+ rewardToken = rewardTokens_2[_i];
1249
+ _c = (_a = ethers_1.ethers.utils).formatUnits;
1250
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, rewardToken, curve_1.curve.constantOptions)];
1170
1251
  case 3:
1171
- decimals = _g.sent();
1172
- method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
1173
- _d = (_c = ethers_1.ethers.utils).formatUnits;
1174
- return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
1175
- case 4:
1176
- amount = _d.apply(_c, [_g.sent(), decimals]);
1252
+ amount = _c.apply(_a, [_d.sent(), rewardToken.decimals]);
1177
1253
  rewards.push({
1178
- token: rewardToken,
1179
- symbol: symbol,
1254
+ token: rewardToken.token,
1255
+ symbol: rewardToken.symbol,
1180
1256
  amount: amount,
1181
1257
  });
1182
- _g.label = 5;
1183
- case 5:
1258
+ _d.label = 4;
1259
+ case 4:
1184
1260
  _i++;
1185
- return [3 /*break*/, 1];
1186
- case 6: return [3 /*break*/, 11];
1261
+ return [3 /*break*/, 2];
1262
+ case 5: return [3 /*break*/, 9];
1263
+ case 6:
1264
+ if (!('claimable_reward(address)' in gaugeContract && rewardTokens.length > 0)) return [3 /*break*/, 9];
1265
+ rewardToken = rewardTokens[0];
1266
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1187
1267
  case 7:
1188
- if (!('claimable_reward(address)' in gaugeContract && this.rewardTokens.length > 0)) return [3 /*break*/, 11];
1189
- rewardToken = this.rewardTokens[0];
1190
- rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1191
- return [4 /*yield*/, rewardTokenContract.symbol()];
1268
+ _totalAmount = _d.sent();
1269
+ return [4 /*yield*/, gaugeContract.claimed_rewards_for(address, curve_1.curve.constantOptions)];
1192
1270
  case 8:
1193
- symbol = _g.sent();
1194
- return [4 /*yield*/, rewardTokenContract.decimals()];
1195
- case 9:
1196
- decimals = _g.sent();
1197
- _f = (_e = ethers_1.ethers.utils).formatUnits;
1198
- return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1199
- case 10:
1200
- amount = _f.apply(_e, [_g.sent(), decimals]);
1271
+ _claimedAmount = _d.sent();
1201
1272
  rewards.push({
1202
- token: rewardToken,
1203
- symbol: symbol,
1204
- amount: amount,
1273
+ token: rewardToken.token,
1274
+ symbol: rewardToken.symbol,
1275
+ amount: ethers_1.ethers.utils.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
1205
1276
  });
1206
- _g.label = 11;
1207
- case 11: return [2 /*return*/, rewards];
1277
+ _d.label = 9;
1278
+ case 9: return [2 /*return*/, rewards];
1208
1279
  }
1209
1280
  });
1210
1281
  });
package/lib/utils.d.ts CHANGED
@@ -29,3 +29,4 @@ export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
29
29
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
30
30
  export declare const getUsdRate: (coin: string) => Promise<number>;
31
31
  export declare const getTVL: (chainId?: number) => Promise<number>;
32
+ export declare const _setContracts: (address: string, abi: any) => void;
package/lib/utils.js CHANGED
@@ -59,12 +59,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
59
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
60
  };
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
62
+ exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var ethers_1 = require("ethers");
65
65
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
66
66
  var curve_1 = require("./curve");
67
67
  var external_api_1 = require("./external-api");
68
+ var ethcall_1 = require("ethcall");
68
69
  exports.ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
69
70
  exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
70
71
  // bignumber.js
@@ -470,12 +471,16 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
470
471
  }[assetId] || assetId;
471
472
  assetId = (0, exports.isEth)(assetId) ? nativeTokenName : assetId.toLowerCase();
472
473
  // No EURT on Coingecko Polygon
473
- if (assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt.toLowerCase()) {
474
+ if (curve_1.curve.chainId === 137 && assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt) {
474
475
  chainName = 'ethereum';
475
476
  assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
476
477
  }
478
+ // CRV
479
+ if (assetId.toLowerCase() === curve_1.curve.constants.ALIASES.crv) {
480
+ assetId = 'curve-dao-token';
481
+ }
477
482
  if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 3];
478
- url = [nativeTokenName, 'bitcoin', 'link'].includes(assetId.toLowerCase()) ?
483
+ url = [nativeTokenName, 'bitcoin', 'link', 'curve-dao-token'].includes(assetId.toLowerCase()) ?
479
484
  "https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
480
485
  "https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
481
486
  return [4 /*yield*/, axios_1.default.get(url)];
@@ -533,3 +538,10 @@ var getTVL = function (chainId) {
533
538
  });
534
539
  };
535
540
  exports.getTVL = getTVL;
541
+ var _setContracts = function (address, abi) {
542
+ curve_1.curve.contracts[address] = {
543
+ contract: new ethers_1.Contract(address, abi, curve_1.curve.signer || curve_1.curve.provider),
544
+ multicallContract: new ethcall_1.Contract(address, abi),
545
+ };
546
+ };
547
+ exports._setContracts = _setContracts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",