forked from ava-labs/subnet-evm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reward Manager precompile (ava-labs#260)
* add initial precompile configs and handle them * add verify to precompile configs * add unit tests for initial configs and verify * add a nil check for initial fee config verification * conditionally verify allowlist * Update precompile/stateful_precompile_config.go Co-authored-by: aaronbuchwald <[email protected]> * add config test to precompile package * add 0 test case for gas limit * add comments for allowlist storage keys * move allow list role to different file * Update precompile/allow_list.go Co-authored-by: aaronbuchwald <[email protected]> * rename test * Update precompile/allow_list.go Co-authored-by: Darioush Jalali <[email protected]> * rename test & use func to create config * Remove unnecessary role checks * use config constructor for precompile tests * Update accounts/abi/bind/precompile_template.go Co-authored-by: Darioush Jalali <[email protected]> * Update precompile/contract_native_minter.go Co-authored-by: Darioush Jalali <[email protected]> * Update precompile/contract_deployer_allow_list.go Co-authored-by: Darioush Jalali <[email protected]> * Update precompile/allow_list.go Co-authored-by: Darioush Jalali <[email protected]> * add equals methods * initialize reward manager precompile by precompilegen * add reward upgrade to block verification * handle empty case in configure * use single field to decide allow fee recipieints * add coinbase verification * configure miner with coinbase in state accordingly * Remove abis * use header coinbase for verification * remove hashToBool util methods * use require and remove unneccessary address field from test * add unit tests * cleanups * Update consensus/dummy/consensus.go Co-authored-by: Darioush Jalali <[email protected]> * Update contract-examples/contracts/IAllowList.sol Co-authored-by: Darioush Jalali <[email protected]> * Update core/stateful_precompile_test.go Co-authored-by: Darioush Jalali <[email protected]> * Update core/stateful_precompile_test.go Co-authored-by: Darioush Jalali <[email protected]> * Update core/stateful_precompile_test.go Co-authored-by: Darioush Jalali <[email protected]> * Update precompile/reward_manager.go Co-authored-by: Darioush Jalali <[email protected]> * Update precompile/reward_manager.go Co-authored-by: Darioush Jalali <[email protected]> * Update precompile/reward_manager.go Co-authored-by: Darioush Jalali <[email protected]> * review fixes * add e2e tests and example contract * add initial config to test * Update contract-examples/tasks.ts Co-authored-by: Darioush Jalali <[email protected]> * Update contract-examples/test/ExampleRewardDistributor.ts Co-authored-by: Darioush Jalali <[email protected]> * Update contract-examples/test/ExampleRewardDistributor.ts Co-authored-by: Darioush Jalali <[email protected]> * review fixes * Update consensus/dummy/consensus.go Co-authored-by: aaronbuchwald <[email protected]> * Update params/config.go Co-authored-by: aaronbuchwald <[email protected]> * Update params/config.go Co-authored-by: aaronbuchwald <[email protected]> * fixs after review * add string method to reward manager * revert coinbase syntactic verification * review fixes * review fixes * add disabled precompile test cases * use hash value instead of address * config cleanup * Update contract-examples/tasks.ts Co-authored-by: Darioush Jalali <[email protected]> * Update contract-examples/tasks.ts Co-authored-by: Darioush Jalali <[email protected]> * more nit fixes * fix conflict * add disabled test case
- Loading branch information
Showing
28 changed files
with
1,838 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./IRewardManager.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
// ExampleRewardManager is a sample wrapper contract for RewardManager precompile. | ||
contract ExampleRewardManager is Ownable { | ||
address constant REWARD_MANAGER_ADDRESS = 0x0200000000000000000000000000000000000004; | ||
IRewardManager rewardManager = IRewardManager(REWARD_MANAGER_ADDRESS); | ||
|
||
constructor() Ownable() {} | ||
|
||
function currentRewardAddress() public view returns (address) { | ||
return rewardManager.currentRewardAddress(); | ||
} | ||
|
||
function setRewardAddress(address addr) public onlyOwner { | ||
rewardManager.setRewardAddress(addr); | ||
} | ||
|
||
function allowFeeRecipients() public onlyOwner { | ||
rewardManager.allowFeeRecipients(); | ||
} | ||
|
||
function disableRewards() public onlyOwner { | ||
rewardManager.disableRewards(); | ||
} | ||
|
||
function areFeeRecipientsAllowed() public view returns (bool) { | ||
return rewardManager.areFeeRecipientsAllowed(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
import "./IAllowList.sol"; | ||
|
||
interface IRewardManager is IAllowList { | ||
// setRewardAddress sets the reward address to the given address | ||
function setRewardAddress(address addr) external; | ||
|
||
// allowFeeRecipients allows block builders to claim fees | ||
function allowFeeRecipients() external; | ||
|
||
// disableRewards disables block rewards and starts burning fees | ||
function disableRewards() external; | ||
|
||
// currentRewardAddress returns the current reward address | ||
function currentRewardAddress() external view returns (address rewardAddress); | ||
|
||
// areFeeRecipientsAllowed returns true if fee recipients are allowed | ||
function areFeeRecipientsAllowed() external view returns (bool isAllowed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
Contract, | ||
ContractFactory | ||
} from "ethers" | ||
import { ethers } from "hardhat" | ||
|
||
|
||
const main = async (): Promise<any> => { | ||
const Contract: ContractFactory = await ethers.getContractFactory("ExampleRewardDistributor") | ||
const contract: Contract = await Contract.deploy() | ||
|
||
await contract.deployed() | ||
console.log(`Contract deployed to: ${contract.address}`) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
Oops, something went wrong.