-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add fork test tooling #419
Changes from 1 commit
df1e6f4
aaae7d6
d3f4806
28e29a7
cc01b28
516937b
383f2df
e5582e1
8526d1d
9728d78
5a7e530
efd24a5
14d1073
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,10 +90,6 @@ contract FixedRateRewardsSource is Governable, Initializable { | |
function previewRewards() public view returns (uint256 rewardAmount) { | ||
RewardConfig memory _config = rewardConfig; | ||
|
||
if (_config.lastCollect == 0) { | ||
return 0; | ||
} | ||
|
||
rewardAmount = (block.timestamp - _config.lastCollect) * _config.rewardsPerSecond; | ||
uint256 balance = IERC20(rewardToken).balanceOf(address(this)); | ||
if (rewardAmount > balance) { | ||
|
@@ -139,6 +135,11 @@ contract FixedRateRewardsSource is Governable, Initializable { | |
// Update storage | ||
RewardConfig storage _config = rewardConfig; | ||
emit RewardsPerSecondChanged(_rewardsPerSecond, _config.rewardsPerSecond); | ||
if (_config.rewardsPerSecond == 0) { | ||
// When changing rate from zero to non-zero, | ||
// Update lastCollect timestamp as well | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only have 1 more nitpick:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is done |
||
_config.lastCollect = uint64(block.timestamp); | ||
} | ||
_config.rewardsPerSecond = _rewardsPerSecond; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity 0.8.10; | ||
|
||
interface IMintableERC20 { | ||
function mint(address to, uint256 amount) external; | ||
function balanceOf(address owner) external view returns (uint256); | ||
function transfer(address to, uint256 amount) external returns (bool); | ||
function approve(address spender, uint256 allowance) external; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.10; | ||
|
||
import {Vm} from "forge-std/Vm.sol"; | ||
import {Addresses} from "contracts/utils/Addresses.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
import "OpenZeppelin/openzeppelin-contracts@4.6.0/contracts/utils/Strings.sol"; | ||
|
||
library GovFive { | ||
struct GovFiveAction { | ||
address receiver; | ||
string fullsig; | ||
bytes data; | ||
} | ||
|
||
struct GovFiveProposal { | ||
string name; | ||
string description; | ||
GovFiveAction[] actions; | ||
} | ||
|
||
function setName(GovFiveProposal storage prop, string memory name) internal { | ||
prop.name = name; | ||
} | ||
|
||
function setDescription(GovFiveProposal storage prop, string memory description) internal { | ||
prop.description = description; | ||
} | ||
|
||
function action(GovFiveProposal storage prop, address receiver, string memory fullsig, bytes memory data) | ||
internal | ||
{ | ||
prop.actions.push(GovFiveAction({receiver: receiver, fullsig: fullsig, data: data})); | ||
} | ||
|
||
function execute(GovFiveProposal storage prop) internal { | ||
address VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); | ||
Vm vm = Vm(VM_ADDRESS); | ||
for (uint256 i = 0; i < prop.actions.length; i++) { | ||
GovFiveAction memory propAction = prop.actions[i]; | ||
bytes memory sig = abi.encodePacked(bytes4(keccak256(bytes(propAction.fullsig)))); | ||
vm.prank(Addresses.TIMELOCK); | ||
(bool success, bytes memory data) = propAction.receiver.call(abi.encodePacked(sig, propAction.data)); | ||
if (!success) { | ||
console.log(propAction.fullsig); | ||
revert("Multisig action failed"); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,56 +18,21 @@ import {Migrator} from "contracts/Migrator.sol"; | |
import {Timelock} from "contracts/Timelock.sol"; | ||
import {Governance} from "contracts/Governance.sol"; | ||
|
||
import {GovFive} from "contracts/utils/GovFive.sol"; | ||
|
||
import "OpenZeppelin/openzeppelin-contracts@4.6.0/contracts/token/ERC20/extensions/ERC20Votes.sol"; | ||
import "OpenZeppelin/openzeppelin-contracts@4.6.0/contracts/governance/TimelockController.sol"; | ||
|
||
// To be extracted | ||
library GovFive { | ||
struct GovFiveAction { | ||
address receiver; | ||
string fullsig; | ||
bytes data; | ||
} | ||
|
||
struct GovFiveProposal { | ||
string name; | ||
string description; | ||
GovFiveAction[] actions; | ||
} | ||
|
||
function setName(GovFiveProposal storage prop, string memory name) internal { | ||
prop.name = name; | ||
} | ||
|
||
function setDescription(GovFiveProposal storage prop, string memory description) internal { | ||
prop.description = description; | ||
} | ||
|
||
function action(GovFiveProposal storage prop, address receiver, string memory fullsig, bytes memory data) | ||
internal | ||
{ | ||
prop.actions.push(GovFiveAction({receiver: receiver, fullsig: fullsig, data: data})); | ||
} | ||
|
||
function execute(GovFiveProposal storage prop) internal { | ||
address VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); | ||
Vm vm = Vm(VM_ADDRESS); | ||
for (uint256 i = 0; i < prop.actions.length; i++) { | ||
GovFiveAction memory action = prop.actions[i]; | ||
bytes memory sig = abi.encodePacked(bytes4(keccak256(bytes(action.fullsig)))); | ||
vm.prank(Addresses.TIMELOCK); | ||
action.receiver.call(abi.encodePacked(sig, action.data)); | ||
} | ||
} | ||
} | ||
|
||
contract XOGNGovernanceScript is BaseMainnetScript { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the real world this will be the multisig calling the timelock. However this is a lower priority. First we need to make sure that main switch over has enough tests on it. |
||
using GovFive for GovFive.GovFiveProposal; | ||
|
||
GovFive.GovFiveProposal govFive; | ||
|
||
string public constant override DEPLOY_NAME = "012_xOGNGovernance"; | ||
|
||
uint256 constant OGN_EPOCH = 1717041600; // May 30, 2024 GMT | ||
uint256 constant REWARDS_PER_SECOND = 300000 ether / uint256(24 * 60 * 60); // 300k per day | ||
|
||
constructor() {} | ||
|
||
function _execute() internal override { | ||
|
@@ -86,14 +51,24 @@ contract XOGNGovernanceScript is BaseMainnetScript { | |
|
||
address xognGov = deployedContracts["XOGN_GOV"]; | ||
|
||
govFive.setName("Enable OGN Governance"); | ||
// Todo: Fuller description | ||
govFive.setName("Enable OGN Governance & Begin Rewards"); | ||
|
||
govFive.setDescription("Grant roles on Timelock to OGN Governance"); | ||
|
||
govFive.action(Addresses.TIMELOCK, "grantRole(bytes32,address)", abi.encode(timelock.PROPOSER_ROLE(), xognGov)); | ||
govFive.action(Addresses.TIMELOCK, "grantRole(bytes32,address)", abi.encode(timelock.CANCELLER_ROLE(), xognGov)); | ||
govFive.action(Addresses.TIMELOCK, "grantRole(bytes32,address)", abi.encode(timelock.EXECUTOR_ROLE(), xognGov)); | ||
|
||
// Enable rewards | ||
govFive.action( | ||
deployedContracts["OGN_REWARDS_SOURCE"], | ||
"setRewardsPerSecond(uint192)", | ||
abi.encode(uint192(REWARDS_PER_SECOND)) | ||
); | ||
|
||
// Go to the start of everything | ||
vm.warp(OGN_EPOCH); | ||
|
||
govFive.execute(); // One day lives up a level, and this contract returns a generic governance struct with a function pointers | ||
} | ||
} |
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.
Currently deploy script 10 deploys the contract and deploy script 12 sets the rewards per second. I would leave this check in since it is a sanity check and not very gas expensive one at that.
With the current code of the contract, the contract needs to be deployed and funded in the correct order, or it will not function properly. Since one can:
I think the correct functioning of the contract should be assured even if the deploy is not configured perfectly as expected. For that reason I would:
_rewardsPerSecond
from the initialize function. Any deployment of this contract will suffer the same issues on initialisation of rewards source and start of emission.setRewardsPerSecond
isn't called with a non 0 value.setRewardsPerSecond
with a 0 value. This would in effect pause the contract and remove any rewards accrued since the last collect. Is that intentional? If not change the_setRewardsPerSecond
to: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.
As of now, The deploy script initializes the proxy and implementation in the same call. So, once the proxy is initialized, it'll always have a lastCollect set and will never be zero. That's the reason I removed that check as it seemed redundant.
If the
rewardsPerSecond
isn't changed, won't previewRewards just return zero (and 0 reward collected)? Why would it revert?Agree with this, will make this change
Yep. xOGN Governance (
rewardsTarget
) is only contract that can callcollectRewards
. Also, xOGN Governance doesn't account for any rewards sent to it directly (It does a balance check before and after collectRewards to figure out the diff and uses that as reward collected). So, collecting rewards internally won't be possible when changing the rateI'm not sure if we want the ability to pause rewards in future for any reason. Let me check with @DanielVF
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.
Thanks for correcting me on first 2 points; you're right they are not an issue.
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'm good with a change to rewards rate potentially changing how much users receive for the past, as well as the future. We'll probably usually couple it with a xOGN collect in most changes though.
Having a "pause" feature that stops rewards could be a useful thing.