Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staking rewards to be claim are calculated in a inefficient way #765

Open
manumonti opened this issue Jun 17, 2024 · 0 comments
Open

Staking rewards to be claim are calculated in a inefficient way #765

manumonti opened this issue Jun 17, 2024 · 0 comments
Assignees

Comments

@manumonti
Copy link
Member

manumonti commented Jun 17, 2024

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.

const claimedEvents = await getContractPastEvents(merkleDropContract, {

But checking these past events is not a reliable way to check this, since:

  1. 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.
  2. 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:

https://github.com/threshold-network/merkle-distribution/blob/252dabcbf6a252104218512ffd62d5e2272cb777/contracts/CumulativeMerkleDrop.sol#L20

@theref theref self-assigned this Sep 24, 2024
theref added a commit that referenced this issue Sep 24, 2024
Rewards are cumulative, so anything that has already been claimed needs
to be subtracted to get the current available amount. This commit gets
the claimed amount by calling `cumulativeClaimed` on the merkle
contract. This is more reliable than scanning for claimed events.

Fixes #765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants