threshold-network / merkle-distribution

Threshold Network rewards generation and distribution
https://threshold.network
1 stars 6 forks source link

Rewards should be keyed by StakingProvider #12

Closed theref closed 2 years ago

theref commented 2 years ago

Rewards should be keyed by stakingProvider:

r.c — Yesterday at 8:36 AM dnunez I noticed that if we generate the rewards per beneficiary we can't tell how many rewards a given stake has. Eg.

  • I have 2 stakes with the same beneficiary address,
  • the JSON file contains proofs for each beneficiary,
  • I can't display in the stake card how many tokens a stake 0x1 and stake 0x2 have because they have the same beneficiary.

dnunez — Yesterday at 10:30 AM Ah, good catch! We'd need to slightly change the format of the JSON file then. Instead of keyed by beneficiary, rewards should be keyed by staking provider then. That implies changes to the contract too

theref commented 2 years ago

We can include the beneficiary in the merkle tree which will avoid having to make a call to the staking contracts (which will cost a bunch of gas)

theref commented 2 years ago

@manumonti in the contract when we verify the merkle proof, that line will be changing to:

bytes32 leaf = keccak256(abi.encodePacked(stakingProvider, cumulativeAmount, beneficiary));
require(_verifyAsm(merkleProof, expectedMerkleRoot, leaf), "CMD: Invalid proof");

so the script to generate the json will need to be changed too