Skip to content

Commit

Permalink
feat: add cross-chain deployment for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Nov 30, 2023
1 parent ffa9489 commit 5588dd8
Show file tree
Hide file tree
Showing 12 changed files with 1,497 additions and 1,507 deletions.
14 changes: 14 additions & 0 deletions copy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,24 @@ rm -rf contracts/protocol/contracts/test

mkdir -p ./contracts/governance/contracts/Governance
mkdir -p ./contracts/governance/contracts/legacy
mkdir -p ./contracts/governance/contracts/test
cp -rf ./node_modules/@venusprotocol/governance-contracts/contracts/legacy ./contracts/governance/contracts
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoInterfaces.sol ./contracts/governance/contracts/Governance/GovernorBravoInterfaces.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol ./contracts/governance/contracts/Governance/AccessControlledV8.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol ./contracts/governance/contracts/Governance/IAccessControlManagerV8.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/TimelockV8.sol ./contracts/governance/contracts/Governance/TimelockV8.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegate.sol ./contracts/governance/contracts/Governance/GovernorBravoDelegate.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegator.sol ./contracts/governance/contracts/Governance/GovernorBravoDelegator.sol
cp ./node_modules/@venusprotocol/governance-contracts/contracts/test/TestTimelockV8.sol ./contracts/governance/contracts/test/TestTimelockV8.sol

rm -rf contracts/protocol/contracts/Lens/VenusLens.sol

# Copy cross-chain contracts
mkdir -p ./contracts/governance/contracts/Cross-chain
cp -rf ./node_modules/@venusprotocol/cross-chain-governance-contracts/contracts/Cross-chain ./contracts/governance/contracts/

mkdir -p ./contracts/mocks
cp -rf ./mocks/ ./contracts/mocks/contracts

mkdir -p ./contracts/utilities
cp -rf ./node_modules/@venusprotocol/solidity-utilities/contracts ./contracts/utilities
17 changes: 4 additions & 13 deletions deploy/000-governance-access-control.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import accessControl from '@venusprotocol/governance-contracts/dist/deploy/001-access-control';
import timelockDeploy from '@venusprotocol/governance-contracts/dist/deploy/001-timelock';
import accessControlDeploy from '@venusprotocol/governance-contracts/dist/deploy/002-access-control';
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();

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

await accessControl(hre);
await timelockDeploy(hre);
await accessControlDeploy(hre);
};

export default func;
18 changes: 5 additions & 13 deletions deploy/018-governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await getNamedAccounts();
const signers = await ethers.getSigners();

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

await deploy('GovernorAlphaTimelock', {
contract: 'Timelock',
contract: 'TimelockV8',
from: deployer,
args: [deployer, 3600],
log: true,
Expand Down Expand Up @@ -48,7 +48,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await governorAlpha.__acceptAdmin();

await deploy('GovernorAlpha2Timelock', {
contract: 'Timelock',
contract: 'TimelockV8',
from: deployer,
args: [deployer, 3600],
log: true,
Expand Down Expand Up @@ -96,8 +96,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
});

await deploy('GovernorBravoDelegateV2', {
contract:
'@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegate.sol:GovernorBravoDelegate',
contract: 'GovernorBravoDelegate',
from: deployer,
args: [],
log: true,
Expand All @@ -110,7 +109,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const minVotingPeriod = await governorBravoDelegate.MIN_VOTING_PERIOD();
const minProposalThreshold = await governorBravoDelegate.MIN_PROPOSAL_THRESHOLD();

await deploy('GovernorBravoDelegatorV1', {
await deploy('GovernorBravoDelegator', {
from: deployer,
args: [
timelock.address,
Expand All @@ -125,13 +124,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
autoMine: true,
});

await deploy('GovernorBravoDelegate', {
from: deployer,
args: [],
log: true,
autoMine: true,
});
};

func.tags = ['Governance'];
Expand Down
198 changes: 195 additions & 3 deletions deploy/020-omnichain-local.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,197 @@
import omnichainLocal from '@venusprotocol/cross-chain-governance-contracts/dist/deploy/002-omnichain-local.ts';
import { BigNumberish } from 'ethers';
import { ethers } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

omnichainLocal.skip = () => false;
import { LZ_ENDPOINTS } from '../subgraphs/cross-chain-governance/src/constants';
import { OmnichainProposalSender } from '../typechain';

export default omnichainLocal;
export const OmnichainProposalSenderMethods: string[] = [
'setTrustedRemote(uint16,bytes)',
'setTrustedRemoteAddress(uint16,bytes)',
'updateValidChainId(uint16,bool)',
'setMaxDailyLimit(uint16,uint256)',
'execute(uint16,bytes,bytes)',
'pause()',
'unpause()',
'setSendVersion(uint16)',
'setConfig(uint16,uint16,uint256,bytes)',
];

export const OmnichainGovernanceExecutorMethods: string[] = [
'setSendVersion(uint16)',
'setReceiveVersion(uint16)',
'forceResumeReceive(uint16,bytes)',
'setOracle(address)',
'setMaxDailyReceiveLimit(uint16,uint256)',
'pause()',
'unpause()',
'setTrustedRemote(uint16,bytes)',
'setTrustedRemoteAddress(uint16,bytes)',
'setPrecrime(address)',
'setMinDstGas(uint16,uint16,uint256)',
'setPayloadSizeLimit(uint16,uint256)',
'setConfig(uint16,uint16,uint256,bytes)',
'addTimelocks(ITimelock[])',
];

export const bridgeConfig = {
bsctestnet: {
methods: [
{ method: 'setMaxDailyLimit(uint16,uint256)', args: [10161, 100] },
{ method: 'updateValidChainId(uint16,bool)', args: [10161, true] },
],
},
bscmainnet: {
methods: [
{ method: 'setMaxDailyLimit(uint16,uint256)', args: [101, 100] },
{ method: 'updateValidChainId(uint16,bool)', args: [101, true] },
],
},
sepolia: {
methods: [
{ method: 'setMinDstGas(uint16,uint16,uint256)', args: [10102, 0, 200000] },
{ method: 'setMaxDailyReceiveLimit(uint16,uint256)', args: [10102, 100] },
],
},
hardhat: {
methods: [
{ method: 'setMinDstGas(uint16,uint16,uint256)', args: [10102, 0, 200000] },
{ method: 'setMaxDailyReceiveLimit(uint16,uint256)', args: [10102, 100] },
],
},
};

export const getArgTypesFromSignature = (methodSignature: string): string[] => {
const [, argumentString] = methodSignature.split('(')[1].split(')');
return argumentString.split(',').map(arg => arg.trim());
};

interface GovernanceCommand {
contract: string;
signature: string;
argTypes: string[];
parameters: any[];

Check warning on line 74 in deploy/020-omnichain-local.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
value: BigNumberish;
}

const configureBridgeCommands = async (
target: string,
hre: HardhatRuntimeEnvironment,
): Promise<GovernanceCommand[]> => {
const commands = await Promise.all(
bridgeConfig[hre.network.name].methods.map(async (entry: { method: string; args: any[] }) => {

Check warning on line 83 in deploy/020-omnichain-local.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const { method, args } = entry;
return {
contract: target,
signature: method,
argTypes: getArgTypesFromSignature(method),
parameters: args,
value: 0,
};
}),
);
return commands.flat();
};

const configureAccessControls = async (
methods: string[],
accessControlManagerAddress: string,
caller: string,
target: string,
): Promise<GovernanceCommand[]> => {
const commands = await Promise.all(
methods.map(async method => {
const callerAddress = caller;
const targetAddress = target;
return [
{
contract: accessControlManagerAddress,
signature: 'giveCallPermission(address,string,address)',
argTypes: ['address', 'string', 'address'],
parameters: [targetAddress, method, callerAddress],
value: 0,
},
];
}),
);
return commands.flat();
};

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

const acmAddress = (await ethers.getContract('AccessControlManager')).address;
const normalTimelockAddress = (await ethers.getContract('NormalTimelock')).address;
const fastTrackTimelockAddress = (await ethers.getContract('FastTrackTimelock')).address;
const criticalTimelockAddress = (await ethers.getContract('CriticalTimelock')).address;
const governorBravoDelegatorAddress = (await ethers.getContract('GovernorBravoDelegator'))
.address;

const OmnichainProposalSender = await deploy('OmnichainProposalSender', {
from: deployer,
args: [
LZ_ENDPOINTS[hre.network.name as keyof typeof LZ_ENDPOINTS],
acmAddress,
governorBravoDelegatorAddress,
],
log: true,
autoMine: true,
});

const bridge = await ethers.getContractAt<OmnichainProposalSender>(
'OmnichainProposalSender',
OmnichainProposalSender.address,
ethers.provider.getSigner(deployer),
);

if ((await bridge.owner()) === deployer) {
const tx = await bridge.transferOwnership(normalTimelockAddress);
await tx.wait();
console.log(`Bridge owner ${deployer} successfully changed to ${normalTimelockAddress}.`);
}
const commands = [
...(await configureAccessControls(
OmnichainProposalSenderMethods,
acmAddress,
normalTimelockAddress,
OmnichainProposalSender.address,
)),
...(await configureAccessControls(
OmnichainProposalSenderMethods,
acmAddress,
fastTrackTimelockAddress,
OmnichainProposalSender.address,
)),
...(await configureAccessControls(
OmnichainProposalSenderMethods,
acmAddress,
criticalTimelockAddress,
OmnichainProposalSender.address,
)),
...(await configureBridgeCommands(OmnichainProposalSender.address, hre)),

{
contract: OmnichainProposalSender.address,
signature: 'setTrustedRemote(uint16,bytes)',
parameters: ['dstChainId', '0xDestAddressSrcAddress'],
value: 0,
},
];
console.log('Please propose a VIP with the following commands:');
console.log(
JSON.stringify(
commands.map(c => ({
target: c.contract,
signature: c.signature,
params: c.parameters,
value: c.value,
})),
),
);
};
func.tags = ['OmnichainProposalSender', 'omnichainlocal'];

export default func;
Loading

0 comments on commit 5588dd8

Please sign in to comment.