The dashboard calculates how many rewards are going to be received when a staker pushes the "Claim" button.
Currently, this calculation is made by checking the last updated Merkle Distribution file (rewards.json) and subtracting the number of rewards that have been claimed already.
To get the rewards already claimed, the dashboard checks the claimed events emitted by the contract to the Ethereum network.
But checking these past events is not a reliable way to check this, since:
It is quite inefficient and it is getting more inefficient over time: as new blocks are generated in the blockchain, the earlier events are left behind.
Some providers can restrict the oldest events: maybe the provider returns only the events that happened in the last x Ethereum blocks.
The fix
Instead of querying for events, the claimed rewards of a stake can be queried directly to CumulativeClaimed in the Merkle distribution contract:
The issue
The dashboard calculates how many rewards are going to be received when a staker pushes the "Claim" button.
Currently, this calculation is made by checking the last updated Merkle Distribution file (rewards.json) and subtracting the number of rewards that have been claimed already.
To get the rewards already claimed, the dashboard checks the
claimed
events emitted by the contract to the Ethereum network.https://github.com/threshold-network/token-dashboard/blob/fccb16fa5caf44d7b4729ea04fe215752114e526/src/hooks/useFetchStakingRewards.ts#L38
But checking these past events is not a reliable way to check this, since:
The fix
Instead of querying for events, the claimed rewards of a stake can be queried directly to
CumulativeClaimed
in the Merkle distribution contract:https://github.com/threshold-network/merkle-distribution/blob/252dabcbf6a252104218512ffd62d5e2272cb777/contracts/CumulativeMerkleDrop.sol#L20