Skip to content

Commit 22e852e

Browse files
authored
Merge pull request #284 from lidofinance/fix/si-2493-get-votings-events
Get votings events issue
2 parents 592a6fa + 1ee9681 commit 22e852e

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

utils/get-confirmations.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,38 @@ export const getConfirmationsInfo = async <
5252
contract.read.getConfirmExpiry(),
5353
publicClient.getBlockNumber(),
5454
]);
55+
5556
const confirmExpireInBlocks = confirmExpiry / AVG_BLOCK_TIME_SEC;
5657
const fromBlock = currentBlock - confirmExpireInBlocks;
5758

59+
const safeBlockSize = 10_000n; // safe for rpc calls
60+
const ranges: Array<Record<'fromBlock' | 'toBlock', bigint>> = [];
61+
62+
for (let start = fromBlock; start <= currentBlock; start += safeBlockSize) {
63+
ranges.push({
64+
fromBlock: start,
65+
toBlock:
66+
start + safeBlockSize - 1n <= currentBlock
67+
? start + safeBlockSize - 1n
68+
: currentBlock,
69+
});
70+
}
71+
5872
// get all logs without filtering by role, because Operator Grid uses addresses instead of roles
59-
const logs = await publicClient.getContractEvents({
60-
address: contract.address,
61-
abi: contract.abi,
62-
eventName: 'RoleMemberConfirmed',
63-
fromBlock,
64-
strict: true,
65-
});
73+
const logs = (
74+
await Promise.all(
75+
ranges.map(({ fromBlock, toBlock }) =>
76+
publicClient.getContractEvents({
77+
address: contract.address,
78+
abi: contract.abi,
79+
eventName: 'RoleMemberConfirmed',
80+
strict: true,
81+
fromBlock,
82+
toBlock,
83+
}),
84+
),
85+
)
86+
).flat();
6687

6788
let confirmations = logs
6889
// filter out confirmations that are already expired

0 commit comments

Comments
 (0)