Skip to content

Commit

Permalink
chore: adding base L1 to L2 deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kupermind committed Feb 22, 2024
1 parent f0073f5 commit a6ab295
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 2 deletions.
47 changes: 47 additions & 0 deletions scripts/deployment/bridges/base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Bridge-related deployment scripts
This process is the same as described in the original deployment procedure: [deployment](https://github.com/valory-xyz/autonolas-governance/blob/main/scripts/deployment).

## Steps to engage
The project has submodules to get the dependencies. Make sure you run `git clone --recursive` or init the submodules yourself.
The dependency list is managed by the `package.json` file, and the setup parameters are stored in the `hardhat.config.js` file.
Simply run the following command to install the project:
```
yarn install
```
command and compiled with the
```
npx hardhat compile
```

Create a `globals.json` file in the root folder, or copy it from the file with pre-defined parameters (i.e., `scripts/deployment/bridges/base/globals_base_sepolia.json` for the chiado testnet).

Parameters of the `globals.json` file:
- `contractVerification`: flag for verifying contracts in deployment scripts (`true`) or skipping it (`false`);
- `useLedger`: flag whether to use the hardware wallet (`true`) or proceed with the seed-phrase accounts (`false`);
- `derivationPath`: string with the derivation path;
- `gasPriceInGwei`: gas price in Gwei;
- `L2CrossDomainMessengerAddress`: (Base) CFM Contract Proxy address serving as a system processor of inbound calls across the bridge;
- `timelockAddress`: Timelock address on the root L1 network;

The script file name identifies the number of deployment steps taken up to the number in the file name.

Export network-related API keys defined in `hardhat.config.js` file that correspond to the required network.

To run the script, use the following command:
`npx hardhat run scripts/deployment/bridges/script_name --network network_type`,
where `script_number_and_name` is a script number and name, i.e. `deploy_01_home_mediator.js`, `network_type` is a network type corresponding to the `hardhat.config.js` network configuration.

## Validity checks and contract verification
Each script controls the obtained values by checking them against the expected ones. Also, each script has a contract verification procedure.
If a contract is deployed with arguments, these arguments are taken from the corresponding `verify_number_and_name` file, where `number_and_name` corresponds to the deployment script number and name.

## Data packing for cross-bridge transactions
In order to correctly pack the data and supply it to the Timelock such that it is correctly processed across the bridge,
use the following script: [cross-bridge data packing](https://github.com/valory-xyz/autonolas-governance/blob/main/scripts/deployment/bridges/pack-data.js).







59 changes: 59 additions & 0 deletions scripts/deployment/bridges/base/deploy_01_optimism_messenger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*global process*/

const { ethers } = require("hardhat");
const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const gasPriceInGwei = parsedData.gasPriceInGwei;

const networkURL = parsedData.networkURL;
const provider = new ethers.providers.JsonRpcProvider(networkURL);
const signers = await ethers.getSigners();

let EOA;
if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Transaction signing and execution
console.log("1. EOA to deploy home mediator contract");
const OptimismMessenger = await ethers.getContractFactory("OptimismMessenger");
console.log("You are signing the following transaction: OptimismMessenger.connect(EOA).deploy(L2CrossDomainMessengerAddress, timelockAddress)");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const optimismMessenger = await OptimismMessenger.connect(EOA).deploy(parsedData.L2CrossDomainMessengerAddress, parsedData.timelockAddress, { gasPrice });
const result = await optimismMessenger.deployed();

// Transaction details
console.log("Contract deployment: OptimismMessenger");
console.log("Contract address:", optimismMessenger.address);
console.log("Transaction:", result.deployTransaction.hash);

// Writing updated parameters back to the JSON file
parsedData.optimismMessengerAddress = optimismMessenger.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --constructor-args scripts/deployment/bridges/base/verify_01_home_mediator.js --network " + providerName + " " + optimismMessenger.address, { encoding: "utf-8" });
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
1 change: 1 addition & 0 deletions scripts/deployment/bridges/base/globals_base_mainnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contractVerification":true,"useLedger":true,"derivationPath":"m/44'/60'/2'/0/0","providerName":"base","gasPriceInGwei":"2","networkURL":"https://mainnet.base.org","L1CrossDomainMessengerProxyAddress":"0x866E82a600A1414e583f7F13623F1aC5d58b0Afa","timelockAddress":"0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE","optimismMessengerAddress":""}
1 change: 1 addition & 0 deletions scripts/deployment/bridges/base/globals_base_sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contractVerification":true,"useLedger":false,"derivationPath":"m/44'/60'/2'/0/0","providerName":"baseSepolia","gasPriceInGwei":"2","networkURL":"https://sepolia.base.org","L1CrossDomainMessengerProxyAddress":"0xC34855F4De64F1840e5686e64278da901e261f20","timelockAddress":"0x04A0afD079F14D539B17253Ea93563934A024165","L2CrossDomainMessengerAddress":"0x4200000000000000000000000000000000000007","optimismMessengerAddress":"0xeDd71796B90eaCc56B074C39BAC90ED2Ca6D93Ee"}
57 changes: 57 additions & 0 deletions scripts/deployment/bridges/base/test/deploy_00_mock_timelock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*global process*/

const { ethers } = require("hardhat");
const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = "sepolia";
const gasPriceInGwei = parsedData.gasPriceInGwei;

Check warning on line 14 in scripts/deployment/bridges/base/test/deploy_00_mock_timelock.js

View workflow job for this annotation

GitHub Actions / build

'gasPriceInGwei' is assigned a value but never used
let EOA;

const provider = await ethers.providers.getDefaultProvider(providerName);
const signers = await ethers.getSigners();

if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Transaction signing and execution
console.log("1. EOA to deploy mock timelock contract");
const Timelock = await ethers.getContractFactory("MockTimelock");
console.log("You are signing the following transaction: Timelock.connect(EOA).deploy(L1CrossDomainMessengerProxy)");
const timelock = await Timelock.connect(EOA).deploy(parsedData.L1CrossDomainMessengerProxyAddress);
const result = await timelock.deployed();

// Transaction details
console.log("Contract deployment: MockTimelock");
console.log("Contract address:", timelock.address);
console.log("Transaction:", result.deployTransaction.hash);

// Writing updated parameters back to the JSON file
parsedData.timelockAddress = timelock.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --constructor-args scripts/deployment/bridges/base/test/verify_00_mock_timelock.js --network " + providerName + " " + timelock.address, { encoding: "utf-8" });
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
63 changes: 63 additions & 0 deletions scripts/deployment/bridges/base/test/deploy_02_child_mock_erc20.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*global process*/

const { ethers } = require("hardhat");
const { LedgerSigner } = require("@anders-t/ethers-ledger");

async function main() {
const fs = require("fs");
const globalsFile = "globals.json";
const dataFromJSON = fs.readFileSync(globalsFile, "utf8");
let parsedData = JSON.parse(dataFromJSON);
const useLedger = parsedData.useLedger;
const derivationPath = parsedData.derivationPath;
const providerName = parsedData.providerName;
const gasPriceInGwei = parsedData.gasPriceInGwei;

const networkURL = parsedData.networkURL;
const provider = new ethers.providers.JsonRpcProvider(networkURL);
const signers = await ethers.getSigners();

let EOA;
if (useLedger) {
EOA = new LedgerSigner(provider, derivationPath);
} else {
EOA = signers[0];
}
// EOA address
const deployer = await EOA.getAddress();
console.log("EOA is:", deployer);

// Transaction signing and execution
console.log("2. EOA to deploy child mock ERC20 contract and change its owner to the FxGovernorTunnel");
const ChildMockERC20 = await ethers.getContractFactory("ChildMockERC20");
console.log("You are signing the following transaction: ChildMockERC20.connect(EOA).deploy()");
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei");
const childMockERC20 = await ChildMockERC20.connect(EOA).deploy({ gasPrice });
let result = await childMockERC20.deployed();

// Transaction details
console.log("Contract deployment: ChildMockERC20");
console.log("Contract address:", childMockERC20.address);
console.log("Transaction:", result.deployTransaction.hash);

// Writing updated parameters back to the JSON file
parsedData.childMockERC20Address = childMockERC20.address;
fs.writeFileSync(globalsFile, JSON.stringify(parsedData));

// Change the owner of the contract
result = await childMockERC20.changeOwner(parsedData.optimismMessengerAddress, { gasPrice });
console.log("Transaction:", result.hash);

// Contract verification
if (parsedData.contractVerification) {
const execSync = require("child_process").execSync;
execSync("npx hardhat verify --network " + providerName + " " + childMockERC20.address, { encoding: "utf-8" });
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
1 change: 1 addition & 0 deletions scripts/deployment/bridges/base/test/globals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contractVerification":true,"useLedger":false,"derivationPath":"m/44'/60'/2'/0/0","providerName":"baseSepolia","gasPriceInGwei":"2","networkURL":"https://sepolia.base.org","L1CrossDomainMessengerProxyAddress":"0xC34855F4De64F1840e5686e64278da901e261f20","timelockAddress":"0x04A0afD079F14D539B17253Ea93563934A024165","L2CrossDomainMessengerAddress":"0x4200000000000000000000000000000000000007","optimismMessengerAddress":"0xeDd71796B90eaCc56B074C39BAC90ED2Ca6D93Ee","childMockERC20Address":"0x17806E2a12d5E0F48C9803cd397DB3F044DA3b77"}
Loading

0 comments on commit a6ab295

Please sign in to comment.