Skip to content

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

@manumonti

Description

@manumonti

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions