@curvefi/api 2.66.12 → 2.66.13
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/pools/utils.js +11 -1
- package/package.json +1 -1
package/lib/pools/utils.js
CHANGED
|
@@ -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 = 100;
|
|
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(); };
|
|
@@ -26,7 +36,7 @@ const _getUserLpBalances = (pools, address, useCache) => __awaiter(void 0, void
|
|
|
26
36
|
if (pool.gauge.address !== curve.constants.ZERO_ADDRESS)
|
|
27
37
|
calls.push(curve.contracts[pool.gauge.address].multicallContract.balanceOf(address));
|
|
28
38
|
}
|
|
29
|
-
const _rawBalances = yield
|
|
39
|
+
const _rawBalances = yield batchedMulticall(calls);
|
|
30
40
|
for (const poolId of poolsToFetch) {
|
|
31
41
|
const pool = getPool(poolId);
|
|
32
42
|
let _balance = _rawBalances.shift();
|