Skip to content
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 alpha governance tests #116

Merged
merged 13 commits into from
Oct 24, 2023
Merged
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: yarn test

integration-test-isolated-pools:
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
needs: unit-test
steps:
- name: Checkout
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
docker system prune -f -a --volumes

integration-test-governance:
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
needs: unit-test
steps:
- name: Checkout
Expand All @@ -107,7 +107,7 @@ jobs:
- name: Run Governance integration integration tests
run: |
docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run test:integration --bail

- name: Stop containers
if: always()
run: |
Expand Down
1 change: 1 addition & 0 deletions copy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
Expand Down
14 changes: 8 additions & 6 deletions deploy/017-vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,25 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
autoMine: true,
});

const xvsVault = await ethers.getContract('XVSVault');
let xvsVault = await ethers.getContract('XVSVault');
const xvsStore = await ethers.getContract('XVSStore');
const xvsVaultProxy = await ethers.getContract('XVSVaultProxy');
const accessControlManager = await ethers.getContract('AccessControlManager');

// Become Implementation of XVSVaultProxy
await xvsVaultProxy._setPendingImplementation(xvsVaultAddress);
await xvsVault._become(xvsVaultProxyAddress);

xvsVault = await ethers.getContractAt('XVSVault', xvsVaultProxyAddress);

let txn = await xvsVault.setXvsStore(xvsAddress, xvsStore.address);
await txn.wait(1);

txn = await xvsVault.setAccessControl(accessControlManager.address);
await txn.wait(1);

// Become Implementation of XVSVaultProxy
await xvsVaultProxy._setPendingImplementation(xvsVaultAddress);
await xvsVault._become(xvsVaultProxyAddress);

// Set new owner to xvs store
await xvsStore.setNewOwner(xvsVaultAddress);
await xvsStore.setNewOwner(xvsVaultProxyAddress);
};

func.tags = ['XVS vault'];
Expand Down
120 changes: 87 additions & 33 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');
const xvsVault = await ethers.getContract('XVSVaultProxy');

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
3 changes: 2 additions & 1 deletion deploy/019-configure-vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await getNamedAccounts();

const accessControlManager = await ethers.getContract('AccessControlManager');
const xvsVault = await ethers.getContract('XVSVault');
const xvsVaultProxy = await ethers.getContract('XVSVaultProxy');
const xvsVault = await ethers.getContractAt('XVSVault', xvsVaultProxy.address);
const xvs = await ethers.getContract('XVS');

const tx = await accessControlManager.giveCallPermission(
Expand Down
7 changes: 1 addition & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ services:
condition: service_started
postgres:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://graph-node:8000"]
interval: 30s
timeout: 12s
retries: 10
environment:
postgres_host: postgres
postgres_user: graph-node
Expand All @@ -38,7 +33,7 @@ services:
- sh
- -c
- |
yarn &&PACKAGE=isolated-pools yarn workspace isolated-pools-subgraph run hardhat node --hostname 0.0.0.0
yarn && PACKAGE=isolated-pools yarn run node:integration
# Installing again to link workspaces
ports:
- 8545:8545
Expand Down
3 changes: 3 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const config: HardhatUserConfig = {
'@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegator.sol',
],
},
mocha: {
timeout: 100000000
},
// Hardhat deploy
namedAccounts: {
deployer: 0, // here this will by default take the first account as deployer
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lint:fix": "yarn lint --fix",
"pretty": "prettier '**/*.ts' --write",
"test": "yarn workspaces foreach run test",
"node:integration": "PACKAGE=isolated-pools hardhat node --hostname 0.0.0.0",
"test:integration": "yarn workspaces foreach run test:integration",
"postinstall": "patch-package && ./copy_contracts.sh"
},
Expand Down
Loading
Loading