Skip to content

feat(gateway): add deploy scripts #38

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

Merged
merged 4 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.10+commit.fc410830",
"mochaExplorer.files": "contracts/test/**/*.{j,t}s"
"mochaExplorer.files": "contracts/test/**/*.{j,t}s",
"cSpell.words": [
"arbitrum"
]
}
1 change: 1 addition & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1
INFURA_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
ARBISCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
REPORT_GAS=true
25 changes: 12 additions & 13 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Smart contracts for Kleros v2

## Deployed Addresses

### Contract 1
### Rinkeby

- Mainnet: ...
- Testnet: ...
- [FastBridgeReceiver](https://rinkeby.etherscan.io/address/0x300CbF0829762FeDc90287D08aeDf261EE6ED8eB)
- [ForeignGateway](https://rinkeby.etherscan.io/address/0x8F1a2B8F9b04320375856580Fc6B1669Cb12a9EE)

### Contract 2
### Arbitrum Rinkeby

...
- [FastBridgeSender](https://testnet.arbiscan.io/address/0x395014fddc3b12F9a78ED8E57DA162Fd77E12bE3)
- [HomeGateway](https://testnet.arbiscan.io/address/0x300CbF0829762FeDc90287D08aeDf261EE6ED8eB)
- [SafeBridgeArbitrum](https://testnet.arbiscan.io/address/0x014A442480DbAD767b7615E55E271799889FA1a7)

## Contributing

Expand Down Expand Up @@ -59,19 +61,20 @@ cp .env.example .env

The following env vars are required:

- `PRIVATE_KEY`: the private key of the deployer account used for xDAI, Sokol and Kovan.
- `PRIVATE_KEY`: the private key of the deployer account used for the testnets.
- `MAINNET_PRIVATE_KEY`: the private key of the deployer account used for Mainnet.
- `INFURA_API_KEY`: the API key for infura.

The ones below are optional:

- `ETHERSCAN_API_KEY`: used only if you wish to verify the source of the newly deployed contracts on Etherscan.
- `ETHERSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Etherscan**.
- `ARBISCAN_API_KEY`: to verify the source of the newly deployed contracts on **Arbitrum**.

#### 1. Update the Constructor Parameters (optional)

If some of the constructor parameters (such as the Meta Evidence) needs to change, you need to update the files in the `deploy/` directory.

#### 2. Deploy the Proxies
#### 2. Deploy to Public Testnets

```bash
yarn deploy:staging # to deploy to L1/L2 testnet
Expand All @@ -85,10 +88,6 @@ If you miss that, you can always go to the `deployments/<network>` directory and

This must be done for each network separately.

For `Mainnet` you can use the `etherscan-verify` command from `hardhat`:

```bash
yarn hardhat --network mainnet etherscan-verify
yarn hardhat --network <arbitrumRinkeby|arbitrum|rinkeby|mainnet> etherscan-verify
```

For `Arbitrum` the process currently must be done manually through [Arbiscan](https://arbiscan.io/verifyContract).
14 changes: 14 additions & 0 deletions contracts/deploy-helpers/getContractAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { BN, Address, toChecksumAddress } = require("ethereumjs-util");

/**
* Gets the address of a soon to be deployed contract.
* @param {string} deployer The address of the deployer account.
* @param {number|BN} nonce The current nonce for the deployer account.
* @return {string} The address of a contract if it is deployed in the next transaction sent by the deployer account.
*/
function getContractAddress(deployer, nonce) {
const deployAddress = Address.generate(Address.fromString(deployer), new BN(String(nonce)));
return toChecksumAddress(deployAddress.toString());
}

module.exports = getContractAddress;
65 changes: 65 additions & 0 deletions contracts/deploy/01-foreign-chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { parseEther } from "ethers/lib/utils";

import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

import getContractAddress from "../deploy-helpers/getContractAddress";

const FOREIGN_CHAIN_IDS = [1, 4];
const paramsByChainId = {
1: {
claimDeposit: parseEther("0.1"),
challengeDuration: 86400, // 1 day
homeChainId: 42161,
},
4: {
claimDeposit: parseEther("0.1"),
challengeDuration: 3600, // 1 hour
homeChainId: 421611,
},
};

const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
const { deploy } = deployments;
const { providers, constants } = ethers;
const { hexZeroPad } = hre.ethers.utils;

const { deployer } = await getNamedAccounts();
const chainId = await getChainId();

const homeNetworks = {
1: config.networks.arbitrum,
4: config.networks.arbitrumRinkeby,
};
const { url } = homeNetworks[chainId];
const homeChainProvider = new providers.JsonRpcProvider(url);
const nonce = await homeChainProvider.getTransactionCount(deployer);

const { claimDeposit, challengeDuration, homeChainId } = paramsByChainId[chainId];

// home Gateway deploy tx will the third tx after this on it's network,
// so we add two to the current nonce.
const homeGatewayAddress = getContractAddress(deployer, nonce + 2);

const homeChainIdAsBytes32 = hexZeroPad(homeChainId, 32);
console.log(nonce + 2);
console.log(homeGatewayAddress);

const fastBridgeReceiver = await deploy("FastBridgeReceiver", {
from: deployer,
args: [deployer, claimDeposit, challengeDuration],
log: true,
});

const foreignGateway = await deploy("ForeignGateway", {
from: deployer,
args: [deployer, fastBridgeReceiver.address, ["1000", "10000"], homeGatewayAddress, homeChainIdAsBytes32],
log: true,
});
};

deployForeignGateway.tags = ["ForeignChain"];
deployForeignGateway.skip = async ({ getChainId }) => !FOREIGN_CHAIN_IDS.includes(Number(await getChainId()));

export default deployForeignGateway;
60 changes: 60 additions & 0 deletions contracts/deploy/02-home-chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

import getContractAddress from "../deploy-helpers/getContractAddress";

const HOME_CHAIN_IDS = [42161, 421611];
const paramsByChainId = {
4: {
arbitrator: "0xab96e690f784b305942752a1fda42680e80f37a0", // SimplePermissionlessArbitrator
foreignChainId: 77,
},
42161: {
arbitrator: "0x18c8a7ec7897177E4529065a7E7B0878358B3BfF", // SimplePermissionlessArbitrator
foreignChainId: 1,
},
421611: {
arbitrator: "0x18c8a7ec7897177E4529065a7E7B0878358B3BfF", // SimplePermissionlessArbitrator
foreignChainId: 4,
},
};

const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
const { hexZeroPad } = hre.ethers.utils;

const { deployer } = await getNamedAccounts();
const chainId = await getChainId();

const { arbitrator, foreignChainId } = paramsByChainId[chainId];

const foreignGateway = await hre.companionNetworks.foreign.deployments.get("ForeignGateway");
const fastBridgeReceiver = await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiver");

const foreignChainIdAsBytes32 = hexZeroPad(foreignChainId, 32);

const safeBridge = await deploy("SafeBridgeArbitrum", {
from: deployer,
log: true,
});

const fastBridgeSender = await deploy("FastBridgeSender", {
from: deployer,
args: [safeBridge.address, fastBridgeReceiver.address],
log: true,
});

const homeGateway = await deploy("HomeGateway", {
from: deployer,
args: [arbitrator, fastBridgeSender.address, foreignGateway.address, foreignChainIdAsBytes32],
log: true,
});

await execute("FastBridgeSender", { from: deployer, log: true }, "setFastSender", homeGateway.address);
};

deployHomeGateway.tags = ["HomeChain"];
deployHomeGateway.skip = async ({ getChainId }) => !HOME_CHAIN_IDS.includes(Number(await getChainId()));

export default deployHomeGateway;
1 change: 1 addition & 0 deletions contracts/deployments/arbitrumRinkeby/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
421611
Loading