From e5c1155bdcbfc4b99761d59dd483e8329f3a59c4 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 5 Jul 2024 09:52:24 +0800 Subject: [PATCH] 1.add accept from old distribution interface 2. make quorum variable 3. deploy on koi --- Makefile | 4 +- README.md | 4 ++ script/Deploy.s.sol | 6 +- script/DeployKoi.s.sol | 61 +++++++++++++++++++ src/governance/KtonDAO.sol | 11 ++-- src/staking/KtonDAOVault.sol | 4 ++ src/staking/interfaces/IOldStakingRewards.sol | 2 + 7 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 script/DeployKoi.s.sol diff --git a/Makefile b/Makefile index a62e238..5a639f3 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ clean :; @forge clean test :; @forge test fmt :; @forge fmt -dry-run:; @forge script script/Deploy.s.sol:DeployScript --rpc-url "https://koi-rpc.darwinia.network" -deploy :; @forge script script/Deploy.s.sol:DeployScript --rpc-url "https://koi-rpc.darwinia.network" --broadcast +dry-run:; @forge script script/DeployKoi.s.sol:DeployKoiScript --rpc-url "https://crab-rpc.darwinia.network" +deploy :; @forge script script/DeployKoi.s.sol:DeployKoiScript --rpc-url "https://koi-rpc.darwinia.network" --broadcast .PHONY: all flat clean test salt deploy diff --git a/README.md b/README.md index ba83926..42b08d2 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ Staking pool for KTON. | KTONStakingRewards | 0x000000000419683a1a03AbC21FC9da25fd2B4dD7 | | RewardsDistribution | 0x000000000Ae5DB7BDAf8D071e680452e33d91Dd5 | | modlda/trsry | 0x6d6f646c64612f74727372790000000000000000 | +| gKTON | 0x01840055063E8d56C957b79C964D7fc50a825752 | +| KtonDAO | 0x34D4519c574047c9D7F9E79b2bc718aef159129B | +| Timelock | 0xCA435c493Ee55AB27e8C8b1b1a89706c5a2761b5 | +| KtonDAOVault | 0x0DBFbb1Ab6e42F89661B4f98d5d0acdBE21d1ffC | ### API diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index 4f9f08b..cfbee03 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -28,13 +28,17 @@ contract DeployScript is Script { safeconsole.log("gKTON: ", gKTON_PROXY); safeconsole.log("gKTON_Logic: ", Upgrades.getImplementationAddress(gKTON_PROXY)); + Options memory opts; + uint256 quorum = 3_000e18; + opts.constructorData = abi.encode(quorum); address ktonDAO_PROXY = Upgrades.deployTransparentProxy( "KtonDAO.sol:KtonDAO", timelock, abi.encodeCall( KtonDAO.initialize, (IVotes(gKTON), TimelockControllerUpgradeable(payable(timelock)), 1 days, 30 days, 20e18, "KtonDAO") - ) + ), + opts ); safeconsole.log("KtonDAO: ", ktonDAO_PROXY); safeconsole.log("KtonDAO_Logic: ", Upgrades.getImplementationAddress(ktonDAO_PROXY)); diff --git a/script/DeployKoi.s.sol b/script/DeployKoi.s.sol new file mode 100644 index 0000000..e2f1ff5 --- /dev/null +++ b/script/DeployKoi.s.sol @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {Script} from "forge-std/Script.sol"; +import {safeconsole} from "forge-std/safeconsole.sol"; +import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; +import {Options} from "openzeppelin-foundry-upgrades/Options.sol"; + +import {GovernanceKton} from "../src/governance/GovernanceKton.sol"; +import {KtonDAO, IVotes, TimelockControllerUpgradeable} from "../src/governance/KtonDAO.sol"; +import {KtonTimelockController} from "../src/governance/KtonTimelockController.sol"; +import {KtonDAOVault} from "../src/staking/KtonDAOVault.sol"; + +contract DeployKoiScript is Script { + address gKTON = 0x01840055063E8d56C957b79C964D7fc50a825752; + address ktonDAO = 0x34D4519c574047c9D7F9E79b2bc718aef159129B; + address timelock = 0xCA435c493Ee55AB27e8C8b1b1a89706c5a2761b5; + address vault = 0x0DBFbb1Ab6e42F89661B4f98d5d0acdBE21d1ffC; + + function setUp() public {} + + function run() public { + vm.startBroadcast(); + + address gKTON_PROXY = Upgrades.deployTransparentProxy( + "GovernanceKton.sol:GovernanceKton", timelock, abi.encodeCall(GovernanceKton.initialize, (vault)) + ); + safeconsole.log("gKTON: ", gKTON_PROXY); + safeconsole.log("gKTON_Logic: ", Upgrades.getImplementationAddress(gKTON_PROXY)); + + Options memory opts; + uint256 quorum = 3e16; + opts.constructorData = abi.encode(quorum); + address ktonDAO_PROXY = Upgrades.deployTransparentProxy( + "KtonDAO.sol:KtonDAO", + timelock, + abi.encodeCall( + KtonDAO.initialize, + (IVotes(gKTON), TimelockControllerUpgradeable(payable(timelock)), 0, 1 hours, 1e16, "KtonDAO") + ), + opts + ); + safeconsole.log("KtonDAO: ", ktonDAO_PROXY); + safeconsole.log("KtonDAO_Logic: ", Upgrades.getImplementationAddress(ktonDAO_PROXY)); + + uint256 minDelay = 0; + address[] memory proposers = new address[](1); + proposers[0] = ktonDAO; + KtonTimelockController timelockController = + new KtonTimelockController(minDelay, proposers, new address[](0), address(0)); + safeconsole.log("Timelock: ", address(timelockController)); + + address KtonDAOVault_PROXY = Upgrades.deployTransparentProxy( + "KtonDAOVault.sol:KtonDAOVault", timelock, abi.encodeCall(KtonDAOVault.initialize, (timelock, gKTON)) + ); + safeconsole.log("KtonDAOVault: ", KtonDAOVault_PROXY); + safeconsole.log("KtonDAOVault_Logic: ", Upgrades.getImplementationAddress(KtonDAOVault_PROXY)); + + vm.stopBroadcast(); + } +} diff --git a/src/governance/KtonDAO.sol b/src/governance/KtonDAO.sol index 39563c5..0015f57 100644 --- a/src/governance/KtonDAO.sol +++ b/src/governance/KtonDAO.sol @@ -16,9 +16,12 @@ contract KtonDAO is GovernorVotesUpgradeable, GovernorTimelockControlUpgradeable { + /// @custom:oz-upgrades-unsafe-allow state-variable-immutable + uint256 public immutable QUORUM; + /// @custom:oz-upgrades-unsafe-allow constructor - constructor() { - _disableInitializers(); + constructor(uint256 quorum_) { + QUORUM = quorum_; } function initialize( @@ -36,8 +39,8 @@ contract KtonDAO is __GovernorTimelockControl_init(_timelock); } - function quorum(uint256) public pure override returns (uint256) { - return 3_000e18; + function quorum(uint256) public view override returns (uint256) { + return QUORUM; } // The following functions are overrides required by Solidity. diff --git a/src/staking/KtonDAOVault.sol b/src/staking/KtonDAOVault.sol index 9170bd3..9e767b8 100644 --- a/src/staking/KtonDAOVault.sol +++ b/src/staking/KtonDAOVault.sol @@ -33,6 +33,10 @@ contract KtonDAOVault is Initializable, Ownable2StepUpgradeable { receive() external payable {} + function acceptOwnershipFromOldDistribution() external onlySystem { + IOldStakingRewards(OLD_KTON_REWARDS_DISTRIBUTION).acceptOwnership(); + } + /// Runtime migration Step: /// 1. Migrate OLD_KTON_REWARDS_DISTRIBUTION's owner to this contracts address. /// 2. distributeRewards to this contract address. diff --git a/src/staking/interfaces/IOldStakingRewards.sol b/src/staking/interfaces/IOldStakingRewards.sol index 8d85dd1..99a723d 100644 --- a/src/staking/interfaces/IOldStakingRewards.sol +++ b/src/staking/interfaces/IOldStakingRewards.sol @@ -24,4 +24,6 @@ interface IOldStakingRewards { function getReward() external; function exit() external; + + function acceptOwnership() external; }