Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Keep rewards distributor #627

Merged
merged 45 commits into from Dec 4, 2020
Merged

Keep rewards distributor #627

merged 45 commits into from Dec 4, 2020

Conversation

dimpar
Copy link
Contributor

@dimpar dimpar commented Nov 26, 2020

Refs: #602

This PR will add a functionality to claim KEEP rewards by the stakers. Rewards distribution is verified using a merkle tree structure. Merkle tree is generated for each interval (ex. every week) and the next step is allocating KEEP rewards where merkle root is the key for that given interval. The end result of a merkle tree generation .json will consist of:

  • merkle root which is "assigned" to a specific interval
  • list of rewarded accounts with their reward amount, proofs and index in the merkle tree structure

Merkle tree is generated thanks to the Uniswap merkle-distributor source

Generation of merkle root & proofs:

  • ./rewards-merkle-generator.sh --input path/to/file
  • ./rewards-merkle-generator.sh if no path was provided, default path is used (now it is an example file)

solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
@pdyraga
Copy link
Member

pdyraga commented Nov 27, 2020

I am fine with having the contract code in /solidity/contracts but just a heads up that when we'll be working on the part generating merkle root and scripts automating the process, we should place this code in /staker-rewards directory where the code for generating reward distribution numbers lives (see #625).

@dimpar dimpar marked this pull request as ready for review November 30, 2020 11:26
.gitmodules Outdated Show resolved Hide resolved
rewards-merkle-generator.sh Outdated Show resolved Hide resolved
rewards-merkle-generator.sh Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
Allocate amount of KEEP for the given merkle root. Calling
receiveApproval with the onlyOwner modifier results in error because
caller is msg.sender which is the KEEP Token. But what we need is the
caller (owner) who is the owner of Distributor contract as well.
We need to replace it with a seperate function where the owner can be
set explicitly.
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
solidity/contracts/ECDSARewardsDistributor.sol Outdated Show resolved Hide resolved
@pdyraga pdyraga added this to the solidity/v1.4.0 milestone Dec 3, 2020
It is better to have a fork of the Uniswap/merkle-distributor project in
case anything bad happens with the original project (ex. deleted). We
remove this dependency which is going to be replace with a local copy.
- test descriptions to better reflect what they do
- names of the test data
- allocated -> receipt
@pdyraga
Copy link
Member

pdyraga commented Dec 3, 2020

Tested locally, works as advertised. Four outstanding comments and I am good to merge.

@pdyraga pdyraga merged commit 4fcb922 into master Dec 4, 2020
@pdyraga pdyraga deleted the keep-rewards-distributor branch December 4, 2020 11:11
nkuba added a commit that referenced this pull request Dec 10, 2020
…neficiary

Keep rewards distributor beneficiary

Introducing a new token holder contract allowing the contract owner to allocate rewards to `ECDSARewardsDistributor` in phases. Each phase corresponds to a new reward interval allocated with its own Merkle root used by stakers to withdraw their rewards. The contract can receive funds from any other `PhasedEscrow` with `ECDSARewardsEscrowBeneficiary`.

ECDSA staker rewards have been withdrawn from `ECDSARewards` contract to a `PhasedEscrow` (https://etherscan.io/address/0x973005c57872bd7bffb2157e88a6408d428a0f0a). The team initiated the upgrade in interval 2 and finalized it after interval 2 ended to implement [updates to the rewards mechanism](https://blog.keep.network/a-new-rewards-mechanism-deef3412c3e1). `ECDSARewardsDistributor` introduced in #627 will be allocated each interval with an allocation and Merkle root corresponding to that interval's rewards. The missing building block is `ECDSARewardsDistributorEscrow` introduced in this PR.

`ECDSARewardsDistributorEscrow` should receive all funds from `PhasedEscrow` contract that holds now ECDSA staker KEEP rewards. Then, for each new reward interval, the contract owner will call `allocateInterval(bytes32 merkleRoot, uint256 amount)` function to allocate a new reward interval on `ECDSARewardsDistributor` from the tokens held by the contract.

To withdraw funds from `PhasedEscrow` to `ECDSARewardsDistributorEscrow`, it is enough to deploy `ECDSARewardsEscrowBeneficiary` pointing to `ECDSARewardsDistributorEscrow` and set it as a beneficiary of `PhasedEscrow`. This scenario is exercised in `"funding"` describe in unit tests.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants