Skip to content

Commit

Permalink
refactor: update governance deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Oct 18, 2023
1 parent 7f40eb2 commit 6510461
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 49 deletions.
3 changes: 3 additions & 0 deletions copy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ mkdir -p ./contracts/governance/contracts/Governance
mkdir -p ./contracts/governance/contracts/legacy
cp ./node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorBravoDelegateV1.sol ./contracts/governance/contracts/legacy/GovernorBravoDelegateV1.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorBravoInterfaces.sol ./contracts/governance/contracts/legacy/GovernorBravoInterfaces.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorBravoDelegator.sol ./contracts/governance/contracts/legacy/GovernorBravoDelegator.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoInterfaces.sol ./contracts/governance/contracts/Governance/GovernorBravoInterfaces.sol

rm contracts/protocol/contracts/Governance/GovernorBravoDelegate.sol
rm contracts/protocol/contracts/Governance/GovernorBravoDelegator.sol
rm contracts/protocol/contracts/Governance/GovernorAlpha.sol
rm contracts/protocol/contracts/Governance/GovernorAlpha2.sol
rm contracts/protocol/contracts/Governance/Timelock.sol
rm -rf contracts/protocol/contracts/Lens/VenusLens.sol

Expand Down
118 changes: 86 additions & 32 deletions deploy/018-governance.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,125 @@
import { ethers } from 'hardhat';
import { ethers, network } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const signers = await ethers.getSigners();

const timelock = await ethers.getContract('Timelock');
const xvsVault = await ethers.getContract('XVSVault');

await deploy('GovernorAlphaTimelock', {
contract: 'Timelock',
from: deployer,
args: [deployer, 3600],
log: true,
autoMine: true,
});

const governorAlphaTimelock = await ethers.getContract('GovernorAlphaTimelock');
await deploy('GovernorAlpha', {
from: deployer,
args: [timelock.address, xvsVault.address, deployer],
args: [governorAlphaTimelock.address, xvsVault.address, deployer],
log: true,
autoMine: true,
});
const governorAlpha = await ethers.getContract('GovernorAlpha');

await signers[0].sendTransaction({
to: governorAlphaTimelock.address,
value: ethers.utils.parseEther('1.0'),
});

await network.provider.request({
method: 'hardhat_impersonateAccount',
params: [governorAlphaTimelock.address],
});
const signer = await ethers.getSigner(governorAlphaTimelock.address);

await governorAlphaTimelock.connect(signer).setPendingAdmin(governorAlpha.address);
await network.provider.request({
method: 'hardhat_stopImpersonatingAccount',
params: [governorAlphaTimelock.address],
});

await governorAlpha.__acceptAdmin();

await deploy('GovernorAlpha2Timelock', {
contract: 'Timelock',
from: deployer,
args: [deployer, 3600],
log: true,
autoMine: true,
});

const governorAlpha2Timelock = await ethers.getContract('GovernorAlpha2Timelock');

await deploy('GovernorAlpha2', {
from: deployer,
args: [timelock.address, xvsVault.address, deployer, 20],
args: [governorAlpha2Timelock.address, xvsVault.address, deployer, 20],
log: true,
autoMine: true,
});

const governorBravoDelegateDeployment = await deploy('GovernorBravoDelegate', {
const governorAlpha2 = await ethers.getContract('GovernorAlpha2');

await signers[0].sendTransaction({
to: governorAlpha2Timelock.address,
value: ethers.utils.parseEther('1.0'),
});

await network.provider.request({
method: 'hardhat_impersonateAccount',
params: [governorAlpha2Timelock.address],
});
const governorAlpha2Signer = await ethers.getSigner(governorAlpha2Timelock.address);

await governorAlpha2Timelock
.connect(governorAlpha2Signer)
.setPendingAdmin(governorAlpha2.address);

await network.provider.request({
method: 'hardhat_stopImpersonatingAccount',
params: [governorAlpha2Timelock.address],
});

await governorAlpha2.__acceptAdmin();

const governorBravoDelegateV1Deployment = await deploy('GovernorBravoDelegateV1', {
from: deployer,
args: [],
log: true,
autoMine: true,
});

const governorBravoDelegate = await ethers.getContractAt(
'GovernorBravoDelegate',
governorBravoDelegateDeployment.address,
);
await deploy('GovernorBravoDelegateV2', {
contract:
'@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegate.sol:GovernorBravoDelegate',
from: deployer,
args: [],
log: true,
autoMine: true,
});

const governorBravoDelegate = await ethers.getContract('GovernorBravoDelegateV2');

const minVotingDelay = await governorBravoDelegate.MIN_VOTING_DELAY();
const minVotingPeriod = await governorBravoDelegate.MIN_VOTING_PERIOD();
const minProposalThreshold = await governorBravoDelegate.MIN_PROPOSAL_THRESHOLD();
const proposalConfigs = [
{
votingDelay: minVotingDelay.add(3),
votingPeriod: minVotingPeriod.add(3),
proposalThreshold: minProposalThreshold.add(3),
},
{
votingDelay: minVotingDelay.add(2),
votingPeriod: minVotingPeriod.add(2),
proposalThreshold: minProposalThreshold.add(2),
},
{
votingDelay: minVotingDelay.add(1),
votingPeriod: minVotingPeriod.add(1),
proposalThreshold: minProposalThreshold.add(1),
},
];

const timelocks = [timelock.address, timelock.address, timelock.address];

await deploy('GovernorBravoDelegator', {

await deploy('GovernorBravoDelegatorV1', {
from: deployer,
args: [
timelock.address,
xvsVault.address,
deployer,
governorBravoDelegate.address,
proposalConfigs,
timelocks,
governorBravoDelegateV1Deployment.address,
minVotingPeriod.toString(),
minVotingDelay.toString(),
minProposalThreshold.toString(),
deployer,
],
log: true,
Expand Down
133 changes: 133 additions & 0 deletions patches/@venusprotocol+governance-contracts+1.3.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
diff --git a/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha.sol b/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha.sol
index fca5350..4713034 100644
--- a/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha.sol
+++ b/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha.sol
@@ -27,8 +27,8 @@ contract GovernorAlpha {

/// @notice The duration of voting on a proposal, in blocks
function votingPeriod() public pure returns (uint) {
- return (60 * 60 * 24 * 3) / 3;
- } // ~3 days in blocks (assuming 3s blocks)
+ return 100;
+ } // A reasonable amount of block suitable for testing

/// @notice The address of the Venus Protocol Timelock
TimelockInterface public timelock;
diff --git a/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha2.sol b/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha2.sol
index c009718..0e8e8ec 100644
--- a/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha2.sol
+++ b/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorAlpha2.sol
@@ -27,8 +27,8 @@ contract GovernorAlpha2 {

/// @notice The duration of voting on a proposal, in blocks
function votingPeriod() public pure returns (uint) {
- return (60 * 60 * 24 * 3) / 3;
- } // ~3 days in blocks (assuming 3s blocks)
+ return 100;
+ } // A reasonable amount of block suitable for testing

/// @notice The address of the Venus Protocol Timelock
TimelockInterface public timelock;
diff --git a/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorBravoDelegator.sol b/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorBravoDelegator.sol
new file mode 100644
index 0000000..4323517
--- /dev/null
+++ b/node_modules/@venusprotocol/governance-contracts/contracts/legacy/GovernorBravoDelegator.sol
@@ -0,0 +1,97 @@
+pragma solidity ^0.5.16;
+pragma experimental ABIEncoderV2;
+
+import "./GovernorBravoInterfaces.sol";
+
+/**
+ * @title GovernorBravoDelegator
+ * @author Venus
+ * @notice The `GovernorBravoDelegator` contract.
+ */
+contract GovernorBravoDelegatorV1 is GovernorBravoDelegatorStorage, GovernorBravoEventsV1 {
+ constructor(
+ address timelock_,
+ address xvsVault_,
+ address admin_,
+ address implementation_,
+ uint votingPeriod_,
+ uint votingDelay_,
+ uint proposalThreshold_,
+ address guardian_
+ ) public {
+ // Admin set to msg.sender for initialization
+ admin = msg.sender;
+
+ delegateTo(
+ implementation_,
+ abi.encodeWithSignature(
+ "initialize(address,address,uint256,uint256,uint256,address)",
+ timelock_,
+ xvsVault_,
+ votingPeriod_,
+ votingDelay_,
+ proposalThreshold_,
+ guardian_
+ )
+ );
+
+ _setImplementation(implementation_);
+
+ admin = admin_;
+ }
+
+ /**
+ * @notice Called by the admin to update the implementation of the delegator
+ * @param implementation_ The address of the new implementation for delegation
+ */
+ function _setImplementation(address implementation_) public {
+ require(msg.sender == admin, "GovernorBravoDelegator::_setImplementation: admin only");
+ require(
+ implementation_ != address(0),
+ "GovernorBravoDelegator::_setImplementation: invalid implementation address"
+ );
+
+ address oldImplementation = implementation;
+ implementation = implementation_;
+
+ emit NewImplementation(oldImplementation, implementation);
+ }
+
+ /**
+ * @notice Internal method to delegate execution to another contract
+ * @dev It returns to the external caller whatever the implementation returns or forwards reverts
+ * @param callee The contract to delegatecall
+ * @param data The raw data to delegatecall
+ */
+ function delegateTo(address callee, bytes memory data) internal {
+ (bool success, bytes memory returnData) = callee.delegatecall(data);
+ assembly {
+ if eq(success, 0) {
+ revert(add(returnData, 0x20), returndatasize)
+ }
+ }
+ }
+
+ /**
+ * @dev Delegates execution to an implementation contract.
+ * It returns to the external caller whatever the implementation returns
+ * or forwards reverts.
+ */
+ function() external payable {
+ // delegate all other functions to current implementation
+ (bool success, ) = implementation.delegatecall(msg.data);
+
+ assembly {
+ let free_mem_ptr := mload(0x40)
+ returndatacopy(free_mem_ptr, 0, returndatasize)
+
+ switch success
+ case 0 {
+ revert(free_mem_ptr, returndatasize)
+ }
+ default {
+ return(free_mem_ptr, returndatasize)
+ }
+ }
+ }
+}
4 changes: 2 additions & 2 deletions subgraphs/venus-governance/config/bsc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"governorAlphaStartBlock": "2474351",
"governorAlpha2Address": "0x388313BfEFEE8ddfeAD55b585F62812293Cf3A60",
"governorAlpha2StartBlock": "11934064",
"governorBravoDelegateAddress": "0x2d56dC077072B53571b8252008C60e945108c75a",
"governorBravoDelegateStartBlock": "13729317",
"governorBravoDelegatorAddress": "0x2d56dC077072B53571b8252008C60e945108c75a",
"governorBravoDelegatorStartBlock": "13729317",
"xvsVaultAddress": "0x6eF49b4e0772Fe78128F981d42D54172b55eCF9F",
"xvsVaultStartBlock": "13018718",
"xvsVaultPid": "0"
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/venus-governance/config/chapel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"governorAlphaStartBlock": "8205736",
"governorAlpha2Address": "0x7116894ed34FC4B27D5b84f46B70Af48397a6C24",
"governorAlpha2StartBlock": "13584539",
"governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2",
"governorBravoDelegateStartBlock": "16002994",
"governorBravoDelegatorAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2",
"governorBravoDelegatorStartBlock": "16002994",
"xvsVaultAddress": "0xa4Fd54cACdA379FB7CaA783B83Cc846f8ac0Faa6",
"xvsVaultStartBlock": "13937802",
"xvsVaultPid": "1"
Expand Down
10 changes: 5 additions & 5 deletions subgraphs/venus-governance/config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"network": "hardhat",
"accessControlManagerAddress": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
"accessControlManagerStartBlock": "0",
"governorAlphaAddress": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A",
"governorAlphaAddress": "0x0fe4223AD99dF788A6Dcad148eB4086E6389cEB6",
"governorAlphaStartBlock": "0",
"governorAlpha2Address": "0x0fe4223AD99dF788A6Dcad148eB4086E6389cEB6",
"governorAlpha2Address": "0x193521c8934bcf3473453af4321911e7a89e0e12",
"governorAlpha2StartBlock": "0",
"governorBravoDelegateAddress": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A",
"governorBravoDelegateStartBlock": "0",
"xvsVaultAddress": "0x967AB65ef14c58bD4DcfFeaAA1ADb40a022140E5",
"governorBravoDelegatorAddress": "0x22a9b82a6c3d2bfb68f324b2e8367f346dd6f32a",
"governorBravoDelegatorStartBlock": "0",
"xvsVaultAddress": "0xe1708FA6bb2844D5384613ef0846F9Bc1e8eC55E",
"xvsVaultStartBlock": "0",
"xvsVaultPid": "0"
}
6 changes: 4 additions & 2 deletions subgraphs/venus-governance/src/constants/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Address } from '@graphprotocol/graph-ts';

import { governorBravoDelegateAddress as governorBravoDelegateAddressString } from './config';
import { governorBravoDelegatorAddress as governorBravoDelegatorAddressString } from './config';

export const governorBravoDelegateAddress = Address.fromString(governorBravoDelegateAddressString);
export const governorBravoDelegatorAddress = Address.fromString(
governorBravoDelegatorAddressString,
);

export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000');
2 changes: 1 addition & 1 deletion subgraphs/venus-governance/src/constants/config-template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Use yarn prepare commands to generate config typescript file per env

export const governorBravoDelegateAddress = '{{ governorBravoDelegateAddress }}';
export const governorBravoDelegatorAddress = '{{ governorBravoDelegatorAddress }}';

export const xvsVaultPid = '{{ xvsVaultPid }}';

8 changes: 4 additions & 4 deletions subgraphs/venus-governance/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ dataSources:
name: GovernorBravoDelegate
network: {{ network }}
source:
address: "{{ governorBravoDelegateAddress }}"
address: "{{ governorBravoDelegatorAddress }}"
abi: GovernorBravoDelegate
startBlock: {{ governorBravoDelegateStartBlock }}
startBlock: {{ governorBravoDelegatorStartBlock }}
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down Expand Up @@ -117,9 +117,9 @@ dataSources:
name: GovernorBravoDelegate2
network: {{ network }}
source:
address: "{{ governorBravoDelegateAddress }}"
address: "{{ governorBravoDelegatorAddress }}"
abi: GovernorBravoDelegate2
startBlock: {{ governorBravoDelegateStartBlock }}
startBlock: {{ governorBravoDelegatorStartBlock }}
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand Down
Loading

0 comments on commit 6510461

Please sign in to comment.