Skip to content

Commit 848d010

Browse files
author
Leonid Beder
committed
Update snapshot generation to a more precise method
1 parent 649a0f8 commit 848d010

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

utils/staking-rewards/snapshot.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { solidityKeccak256, keccak256 } = utils;
1010

1111
const ETHEREUM_PROVIDER_URL = 'ws://localhost:8545';
1212
const START_BLOCK = 11039642;
13-
const END_BLOCK = 14745043;
13+
const END_BLOCK = 14741802;
1414
const BATCH_SIZE = 1000;
1515

1616
const LIQUIDITY_PROTECTION_STORE_ADDRESS = '0xf5fab5dbd2f3bf675de4cb76517d4767013cfb55';
@@ -25,15 +25,17 @@ const init = () => {
2525
};
2626

2727
const getProviders = async () => {
28-
console.log(`Getting all historic providers from ${START_BLOCK} to ${END_BLOCK}...`);
28+
const currentBlock = await provider.getBlockNumber();
29+
30+
console.log(`Getting all historic providers from ${START_BLOCK} to ${currentBlock}...`);
2931
console.log();
3032

3133
const store = LiquidityProtectionStore.connect(LIQUIDITY_PROTECTION_STORE_ADDRESS, provider);
3234

3335
const providers = new Set<string>();
3436

35-
for (let i = START_BLOCK; i < END_BLOCK; i += BATCH_SIZE) {
36-
const endBlock = Math.min(i + BATCH_SIZE - 1, END_BLOCK);
37+
for (let i = START_BLOCK; i < currentBlock; i += BATCH_SIZE) {
38+
const endBlock = Math.min(i + BATCH_SIZE - 1, currentBlock);
3739

3840
console.log(`Querying all ProtectionAdded and ProtectionUpdated events from ${i} to ${endBlock}...`);
3941

@@ -67,8 +69,16 @@ const filterProvidersWithRewards = async (providers: Set<string>) => {
6769
const stakingRewards = StakingRewards.connect(STAKING_REWARDS_ADDRESS, provider);
6870

6971
for (const provider of providers) {
70-
const claimable = await stakingRewards.pendingRewards(provider, { blockTag: END_BLOCK });
71-
const totalClaimed = await stakingRewards.totalClaimedRewards(provider, { blockTag: END_BLOCK });
72+
let claimable = await stakingRewards.pendingRewards(provider, { blockTag: END_BLOCK });
73+
let totalClaimed = await stakingRewards.totalClaimedRewards(provider, { blockTag: END_BLOCK });
74+
const actualTotalClaimed = await stakingRewards.totalClaimedRewards(provider);
75+
76+
if (!actualTotalClaimed.eq(totalClaimed)) {
77+
const claimDiff = actualTotalClaimed.sub(totalClaimed);
78+
claimable = claimDiff.lte(claimable) ? claimable.sub(claimDiff) : BigNumber.from(0);
79+
totalClaimed = actualTotalClaimed;
80+
}
81+
7282
if (claimable.gt(0) || totalClaimed.gt(0)) {
7383
providersWithRewards[provider] = { claimable, totalClaimed };
7484
}

0 commit comments

Comments
 (0)