-
Notifications
You must be signed in to change notification settings - Fork 7
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
New Threshold rewards distribution contract #149
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments. A lot to unfold here!
contracts/RewardsAggregator.sol
Outdated
/** | ||
* @title Rewards Aggregator | ||
* @notice RewardsAggregator is the contract responsible for the distribution | ||
* of the Threshold Network staking rewards. The rewards are generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* of the Threshold Network staking rewards. The rewards are generated | |
* of Threshold Network staking rewards, which are generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ addressed on 28df6ba
contracts/RewardsAggregator.sol
Outdated
@@ -0,0 +1,262 @@ | |||
// SPDX-License-Identifier: MIT | |||
pragma solidity ^0.8.9; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vzotova Do you think we should increase the version here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question, I'd use same as in threshold staking (which is 0.8.9
not ^0.8.9
) or latest available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ addressed on 6aa0a8e
package.json
Outdated
"prettier": "2.7.1", | ||
"typescript": "^4.8.4" | ||
}, | ||
"dependencies": { | ||
"@octokit/core": "^5.0.2", | ||
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#4985bcf", | ||
"@threshold-network/solidity-contracts": "github:threshold-network/solidity-contracts#19afdea", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use an NPM dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Addressed on 747b3fa
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the open zeppelin contract dependency in package.json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ addressed on dd53240
contracts/RewardsAggregator.sol
Outdated
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@threshold-network/solidity-contracts/contracts/staking/IApplication.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the only thing we're using from this repo, I'd suggest we just copy the interface here and remove the dependency, so we don't pollute ours with their subdependencies. In fact, that would allow us to use OZ v5, otherwise we'd be stuck with v4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Addressed on 747b3fa
Note that we are using v4 of OpenZeppelin contracts because v5 is not compatible with CumulativeMerkleDrop
contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some outstanding RFCs from @cygnusv . Once addressed, I'm happy to approve.
aa6f9b0
to
a906b84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎸 - nice work! One minor question/comment.
contracts/RewardsAggregator.sol
Outdated
oldCumulativeMerkleDrop = _oldCumulativeMerkleDrop; | ||
} | ||
|
||
function setMerkleRoot(bytes32 merkleRoot_) external override onlyOwner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to keep the _
prefix consistent here, and in the function below as well i.e. _merkleRoot
, and _rewardsHolder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Done in a390c28 ✅
Since I'm the original pr author I can't do it explicitly, but approved! Let's test it out on testnet 💪 |
A new Rewards distribution contract is developed as part of the effort to develop an automatic reward mechanism.
The previous contract
CumulativeMerkleDrop
contract (aka Merkle Distribution contract) has proven to be useful since the release of the first Threshold Network rewards distribution in July 2022. Since then, every month a reward calculation script has been executed, generating a Merkle tree with the rewards earned by each stake. The Merkle root of this tree is updated on the contract every time a new Merkle tree is generated, so then, stakers can claim their rewards by calling the appropriate method on the contract.Although useful, this process is pretty manual and error-prone, so a new mechanism to distribute the rewards is being developed.
The new contract:
RewardsAggregator
Note that in the Threshold Network, each application (TACo and tBTC/RandomBeacon) implements its own reward distribution mechanism. The first application to implement automatic distribution is TACo.
So, this new rewards distribution contract has the ability to allow the stakers to claim the rewards from two different sources:
Work done:
RewardsAggregator.sol
.Running the tests
npm install npx hardhat compile npx hardhat test