@curvefi/api 2.26.3 → 2.26.4

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.
package/lib/index.d.ts CHANGED
@@ -36,7 +36,7 @@ declare const curve: {
36
36
  getCryptoFactoryPoolList: () => string[];
37
37
  getUserPoolListByLiquidity: (address?: string) => Promise<string[]>;
38
38
  getUserPoolListByClaimable: (address?: string) => Promise<string[]>;
39
- getUserPoolList: (address?: string) => Promise<string[]>;
39
+ getUserPoolList: (address?: string, useApi?: boolean) => Promise<string[]>;
40
40
  getUserLiquidityUSD: (pools: string[], address?: string) => Promise<string[]>;
41
41
  getUserClaimable: (pools: string[], address?: string) => Promise<{
42
42
  token: string;
@@ -737,6 +737,7 @@ var PoolTemplate = /** @class */ (function () {
737
737
  rewards = _f.sent();
738
738
  if (!rewards[this.gauge])
739
739
  return [2 /*return*/, []];
740
+ rewards[this.gauge].forEach(function (r) { return (0, utils_1._setContracts)(r.tokenAddress, ERC20_json_1.default); });
740
741
  return [2 /*return*/, rewards[this.gauge].map(function (r) { return ({ token: r.tokenAddress, symbol: r.symbol, decimals: r.decimals }); })];
741
742
  case 2:
742
743
  gaugeContract = curve_1.curve.contracts[this.gauge].contract;
@@ -11,5 +11,5 @@ export declare const getUserClaimable: (pools: string[], address?: string) => Pr
11
11
  amount: string;
12
12
  price: number;
13
13
  }[][]>;
14
- export declare const getUserPoolList: (address?: string) => Promise<string[]>;
14
+ export declare const getUserPoolList: (address?: string, useApi?: boolean) => Promise<string[]>;
15
15
  export declare const _getAmplificationCoefficientsFromApi: () => Promise<IDict<number>>;
@@ -236,6 +236,9 @@ var _getUserClaimable = function (pools, address, useCache) { return __awaiter(v
236
236
  rewardAddress = rawRewardTokens.shift();
237
237
  if (rewardAddress === ethers_1.ethers.constants.AddressZero)
238
238
  continue;
239
+ // REYIELD shitcoin which breaks things, because symbol() throws an error
240
+ if (rewardAddress === "0xf228ec3476318aCB4E719D2b290bb2ef8B34DFfA".toLowerCase())
241
+ continue;
239
242
  rewardTokens[poolsToFetch[i]].push(rewardAddress);
240
243
  }
241
244
  }
@@ -309,6 +312,106 @@ var _getUserClaimable = function (pools, address, useCache) { return __awaiter(v
309
312
  }
310
313
  });
311
314
  }); };
315
+ var _getUserClaimableUseApi = function (pools, address, useCache) { return __awaiter(void 0, void 0, void 0, function () {
316
+ var poolsToFetch, hasCrvReward, _i, poolsToFetch_5, poolId, pool, gaugeContract, rewardTokens, i, pool, rewards, rewardInfoCalls, i, poolId, pool, gaugeContract, gaugeMulticallContract, _a, _b, r, rawRewardInfo, i, poolId, pool, gaugeContract, token, symbol, decimals, _amount, amount, _c, _d, r, _amount, _claimedAmount, amount, _claimable, _e, pools_3, poolId;
317
+ var _f, _g;
318
+ return __generator(this, function (_h) {
319
+ switch (_h.label) {
320
+ case 0:
321
+ poolsToFetch = useCache ? pools.filter(function (poolId) { return _isUserClaimableCacheExpired(address, poolId); }) : pools;
322
+ if (!(poolsToFetch.length > 0)) return [3 /*break*/, 6];
323
+ hasCrvReward = [];
324
+ for (_i = 0, poolsToFetch_5 = poolsToFetch; _i < poolsToFetch_5.length; _i++) {
325
+ poolId = poolsToFetch_5[_i];
326
+ pool = (0, poolConstructor_1.getPool)(poolId);
327
+ if (curve_1.curve.chainId === 2222 || curve_1.curve.chainId === 42220 || pool.gauge === ethers_1.ethers.constants.AddressZero) { // TODO remove this for Kava and Celo
328
+ hasCrvReward.push(false);
329
+ continue;
330
+ }
331
+ gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
332
+ hasCrvReward.push('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
333
+ }
334
+ rewardTokens = {};
335
+ i = 0;
336
+ _h.label = 1;
337
+ case 1:
338
+ if (!(i < poolsToFetch.length)) return [3 /*break*/, 4];
339
+ pool = (0, poolConstructor_1.getPool)(poolsToFetch[i]);
340
+ return [4 /*yield*/, (0, utils_1._getRewardsFromApi)()];
341
+ case 2:
342
+ rewards = _h.sent();
343
+ rewardTokens[poolsToFetch[i]] = ((_f = rewards[pool.gauge]) !== null && _f !== void 0 ? _f : []).map(function (r) { return ({ token: r.tokenAddress, symbol: r.symbol, decimals: r.decimals }); });
344
+ _h.label = 3;
345
+ case 3:
346
+ i++;
347
+ return [3 /*break*/, 1];
348
+ case 4:
349
+ rewardInfoCalls = [];
350
+ for (i = 0; i < poolsToFetch.length; i++) {
351
+ poolId = poolsToFetch[i];
352
+ pool = (0, poolConstructor_1.getPool)(poolId);
353
+ if (pool.gauge === ethers_1.ethers.constants.AddressZero)
354
+ continue;
355
+ gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
356
+ gaugeMulticallContract = curve_1.curve.contracts[pool.gauge].multicallContract;
357
+ if (hasCrvReward[i]) {
358
+ rewardInfoCalls.push(gaugeMulticallContract.claimable_tokens(address));
359
+ }
360
+ for (_a = 0, _b = rewardTokens[poolId]; _a < _b.length; _a++) {
361
+ r = _b[_a];
362
+ (0, utils_1._setContracts)(r.token, ERC20_json_1.default);
363
+ if ('claimable_reward(address,address)' in gaugeContract) {
364
+ rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address, r.token));
365
+ }
366
+ else if ('claimable_reward(address)' in gaugeContract) { // Synthetix Gauge
367
+ rewardInfoCalls.push(gaugeMulticallContract.claimable_reward(address), gaugeMulticallContract.claimed_rewards_for(address));
368
+ }
369
+ }
370
+ }
371
+ return [4 /*yield*/, curve_1.curve.multicallProvider.all(rewardInfoCalls)];
372
+ case 5:
373
+ rawRewardInfo = _h.sent();
374
+ for (i = 0; i < poolsToFetch.length; i++) {
375
+ poolId = poolsToFetch[i];
376
+ pool = (0, poolConstructor_1.getPool)(poolId);
377
+ if (!_userClaimableCache[address])
378
+ _userClaimableCache[address] = {};
379
+ _userClaimableCache[address][poolId] = { rewards: [], time: Date.now() };
380
+ if (pool.gauge === ethers_1.ethers.constants.AddressZero)
381
+ continue;
382
+ gaugeContract = curve_1.curve.contracts[pool.gauge].contract;
383
+ if (hasCrvReward[i]) {
384
+ token = curve_1.curve.constants.ALIASES.crv;
385
+ symbol = 'CRV';
386
+ decimals = 18;
387
+ _amount = rawRewardInfo.shift();
388
+ amount = ethers_1.ethers.utils.formatUnits(_amount, decimals);
389
+ if (Number(amount) > 0)
390
+ _userClaimableCache[address][poolId].rewards.push({ token: token, symbol: symbol, amount: amount });
391
+ }
392
+ for (_c = 0, _d = rewardTokens[poolId]; _c < _d.length; _c++) {
393
+ r = _d[_c];
394
+ _amount = rawRewardInfo.shift();
395
+ if ('claimable_reward(address)' in gaugeContract) {
396
+ _claimedAmount = rawRewardInfo.shift();
397
+ _amount = _amount.sub(_claimedAmount);
398
+ }
399
+ amount = ethers_1.ethers.utils.formatUnits(_amount, r.decimals);
400
+ if (Number(amount) > 0)
401
+ _userClaimableCache[address][poolId].rewards.push({ token: r.token, symbol: r.symbol, amount: amount });
402
+ }
403
+ }
404
+ _h.label = 6;
405
+ case 6:
406
+ _claimable = [];
407
+ for (_e = 0, pools_3 = pools; _e < pools_3.length; _e++) {
408
+ poolId = pools_3[_e];
409
+ _claimable.push((_g = _userClaimableCache[address]) === null || _g === void 0 ? void 0 : _g[poolId].rewards);
410
+ }
411
+ return [2 /*return*/, _claimable];
412
+ }
413
+ });
414
+ }); };
312
415
  var getUserPoolListByClaimable = function (address) {
313
416
  if (address === void 0) { address = curve_1.curve.signerAddress; }
314
417
  return __awaiter(void 0, void 0, void 0, function () {
@@ -369,8 +472,9 @@ var getUserClaimable = function (pools, address) {
369
472
  });
370
473
  };
371
474
  exports.getUserClaimable = getUserClaimable;
372
- var getUserPoolList = function (address) {
475
+ var getUserPoolList = function (address, useApi) {
373
476
  if (address === void 0) { address = curve_1.curve.signerAddress; }
477
+ if (useApi === void 0) { useApi = true; }
374
478
  return __awaiter(void 0, void 0, void 0, function () {
375
479
  var pools, _a, _lpBalances, _claimable, userPoolList, i;
376
480
  return __generator(this, function (_b) {
@@ -379,7 +483,7 @@ var getUserPoolList = function (address) {
379
483
  pools = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
380
484
  return [4 /*yield*/, Promise.all([
381
485
  _getUserLpBalances(pools, address, false),
382
- _getUserClaimable(pools, address, false),
486
+ useApi ? _getUserClaimableUseApi(pools, address, false) : _getUserClaimable(pools, address, false),
383
487
  ])];
384
488
  case 1:
385
489
  _a = _b.sent(), _lpBalances = _a[0], _claimable = _a[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.26.3",
3
+ "version": "2.26.4",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",