Skip to content

Commit c7e81a4

Browse files
authored
Fix Gate-io, update helper (DefiLlama#15191)
1 parent 60e9cdd commit c7e81a4

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

projects/gate-io/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,5 @@ unsupportedChains.forEach(chain => delete config[chain]);
16711671

16721672
module.exports = mergeExports([
16731673
cexExports(config),
1674-
{ ethereum: { tvl: getStakedEthTVL({ withdrawalAddress: '0x287a66c7d9cba7504e90fa638911d74c4dc6a147' }) } },
1675-
{ ethereum: { tvl: getStakedEthTVL({ withdrawalAddress: '0xbcf03ce48091e6b820a7c33e166e5d0109d8e712' }) } },
1676-
{ ethereum: { tvl: getStakedEthTVL({ withdrawalAddress: '0x7a3f9b7120386249528c93e5eb373b78e54d5ba9' }) } },
1674+
{ ethereum: { tvl: getStakedEthTVL({ withdrawalAddresses: ['0x287a66c7d9cba7504e90fa638911d74c4dc6a147', '0xbcf03ce48091e6b820a7c33e166e5d0109d8e712', '0x7a3f9b7120386249528c93e5eb373b78e54d5ba9'], sleepTime: 10000, size: 200 }) } },
16771675
]);

projects/helper/utils.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,30 @@ function once(func) {
320320
return wrapped
321321
}
322322

323+
function getStakedEthTVL({ withdrawalAddress, withdrawalAddresses, skipValidators = 0, size = 200, sleepTime = 10000 }) {
324+
return async (api) => {
325+
const addresses = withdrawalAddresses ?? [withdrawalAddress];
326+
327+
for (const addr of addresses) {
328+
let fetchedValidators = skipValidators;
329+
330+
api.sumTokens({ owner: addr, tokens: [nullAddress] });
331+
332+
do {
333+
const validators = (
334+
await http.get(
335+
`https://beaconcha.in/api/v1/validator/withdrawalCredentials/${addr}?limit=${size}&offset=${fetchedValidators}`
336+
)
337+
).data.map((i) => i.publickey);
338+
339+
fetchedValidators += validators.length;
340+
api.log(`Fetching balances for validators (${addr})`, validators.length);
341+
await addValidatorBalance(validators);
342+
if (sleepTime > 0) await sleep(sleepTime);
343+
} while (fetchedValidators % size === 0);
344+
}
323345

324-
function getStakedEthTVL({ withdrawalAddress, skipValidators = 0 }) {
325-
return async (api) => {
326-
let fetchedValidators = skipValidators;
327-
let size = 200;
328-
api.sumTokens({ owner: withdrawalAddress, tokens: [nullAddress] })
329-
do {
330-
const validators = (
331-
await http.get(
332-
`https://beaconcha.in/api/v1/validator/withdrawalCredentials/${withdrawalAddress}?limit=${size}&offset=${fetchedValidators}`
333-
)
334-
).data.map((i) => i.publickey);
335-
fetchedValidators += validators.length;
336-
api.log("Fetching balances for validators", validators.length);
337-
await addValidatorBalance(validators);
338-
await sleep(10000);
339-
} while (fetchedValidators % size === 0);
340-
341-
return api.getBalances()
342-
346+
return api.getBalances();
343347

344348
async function addValidatorBalance(validators) {
345349
if (validators.length > 100) {
@@ -352,10 +356,9 @@ function getStakedEthTVL({ withdrawalAddress, skipValidators = 0 }) {
352356
indicesOrPubkey: validators.join(","),
353357
});
354358

355-
356359
data.forEach((i) => api.addGasToken(i.balance * 1e9));
357360
}
358-
}
361+
};
359362
}
360363

361364

0 commit comments

Comments
 (0)