@curvefi/api 2.66.12 → 2.66.14

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 (2) hide show
  1. package/lib/pools/utils.js +15 -4
  2. package/package.json +1 -1
@@ -12,6 +12,16 @@ import { curve } from "../curve.js";
12
12
  import { _getRewardsFromApi, _getUsdRate, _setContracts, toBN } from "../utils.js";
13
13
  import { _getAllPoolsFromApi } from "../external-api.js";
14
14
  import ERC20Abi from "../constants/abis/ERC20.json" with { type: 'json' };
15
+ const BATCH_SIZE = 50;
16
+ const batchedMulticall = (calls) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const results = [];
18
+ for (let i = 0; i < calls.length; i += BATCH_SIZE) {
19
+ const batch = calls.slice(i, i + BATCH_SIZE);
20
+ const res = yield curve.multicallProvider.all(batch);
21
+ results.push(...res);
22
+ }
23
+ return results;
24
+ });
15
25
  // _userLpBalance: { address: { poolId: { _lpBalance: 0, time: 0 } } }
16
26
  const _userLpBalanceCache = {};
17
27
  const _isUserLpBalanceCacheExpired = (address, poolId) => { var _a, _b; return (((_b = (_a = _userLpBalanceCache[address]) === null || _a === void 0 ? void 0 : _a[poolId]) === null || _b === void 0 ? void 0 : _b.time) || 0) + 600000 < Date.now(); };
@@ -23,14 +33,15 @@ const _getUserLpBalances = (pools, address, useCache) => __awaiter(void 0, void
23
33
  for (const poolId of poolsToFetch) {
24
34
  const pool = getPool(poolId);
25
35
  calls.push(curve.contracts[pool.lpToken].multicallContract.balanceOf(address));
26
- if (pool.gauge.address !== curve.constants.ZERO_ADDRESS)
36
+ if (pool.gauge.address && pool.gauge.address !== curve.constants.ZERO_ADDRESS) {
27
37
  calls.push(curve.contracts[pool.gauge.address].multicallContract.balanceOf(address));
38
+ }
28
39
  }
29
- const _rawBalances = yield curve.multicallProvider.all(calls);
40
+ const _rawBalances = yield batchedMulticall(calls);
30
41
  for (const poolId of poolsToFetch) {
31
42
  const pool = getPool(poolId);
32
43
  let _balance = _rawBalances.shift();
33
- if (pool.gauge.address !== curve.constants.ZERO_ADDRESS)
44
+ if (pool.gauge.address && pool.gauge.address !== curve.constants.ZERO_ADDRESS)
34
45
  _balance = _balance + _rawBalances.shift();
35
46
  if (!_userLpBalanceCache[address])
36
47
  _userLpBalanceCache[address] = {};
@@ -243,7 +254,7 @@ const _getUserClaimableUseApi = (pools, address, useCache) => __awaiter(void 0,
243
254
  }
244
255
  }
245
256
  }
246
- const rawRewardInfo = yield curve.multicallProvider.all(rewardInfoCalls);
257
+ const rawRewardInfo = yield batchedMulticall(rewardInfoCalls);
247
258
  for (let i = 0; i < poolsToFetch.length; i++) {
248
259
  const poolId = poolsToFetch[i];
249
260
  const pool = getPool(poolId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.66.12",
3
+ "version": "2.66.14",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",