Skip to content

[WIP] Deployment to Chiado #560

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 9 commits into from
Feb 3, 2023
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
1 change: 1 addition & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ INFURA_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
# If ETHERSCAN_API_KEY is set, it overrides any hardhat configuration.
ETHERSCAN_API_KEY_FIX=ABC123ABC123ABC123ABC123ABC123ABC1
ARBISCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
GNOSISSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1

# Optionally for debugging
# TENDERLY_USERNAME=your_username
Expand Down
47 changes: 40 additions & 7 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments

### v2-prealpha-3

#### Chiado

- [ArbitrableExample](https://blockscout.com/gnosis/chiado/address/0x823D972BAcBa033BFca208738847cC7135573316)
- [ForeignGatewayOnGnosis](https://blockscout.com/gnosis/chiado/address/0x87142b7E9C7D026776499120D902AF8896C07894)
- [SortitionSumTreeFactory](https://blockscout.com/gnosis/chiado/address/0xc7e3BF90299f6BD9FA7c3703837A9CAbB5743636)
- [TokenBridge](https://blockscout.com/gnosis/chiado/address/0xbb3c86f9918C3C1d83668fA84e79E876d147fFf2)
- [WETH](https://blockscout.com/gnosis/chiado/address/0x014A442480DbAD767b7615E55E271799889FA1a7)
- [WETHFaucet](https://blockscout.com/gnosis/chiado/address/0x395014fddc3b12F9a78ED8E57DA162Fd77E12bE3)
- [WPNKFaucet](https://blockscout.com/gnosis/chiado/address/0xcFc0b84419583ff7b32fD5139B789cE858517d4C)
- [WrappedPinakion](https://blockscout.com/gnosis/chiado/address/0x04Fb43F2Ce076867b5ba38750Ecb2cc6BDe78D61)
- [xKlerosLiquidV2](https://blockscout.com/gnosis/chiado/address/0xf637A0a4415CCFB97407846486b6be663d3C33ef)

#### Goerli

- [PNK](https://goerli.etherscan.io/token/0xA3B02bA6E10F55fb177637917B1b472da0110CcC)
Expand All @@ -23,6 +35,7 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
- [DisputeResolver](https://goerli.arbiscan.io/address/0xDe3eCeB73C453E56F5661ad029a41341CF592b9A)
- [FastBridgeSender](https://goerli.arbiscan.io/address/0x4d18b9792e0D8F5aF696E71dBEDff8fcBEed6e8C)
- [HomeGatewayToEthereum](https://goerli.arbiscan.io/address/0xed12799915180a257985631fbD2ead261eD838cf)
- [HomeGatewayToGnosis](https://goerli.arbiscan.io/address/0x12613A66F1E5A2086374e103F66BF0eddA5d1478)
- [KlerosCore](https://goerli.arbiscan.io/address/0x3eED6aaCa43f4Bb98C591e4A0d2C4a124efF9C24)
- [PolicyRegistry](https://goerli.arbiscan.io/address/0xC5655728387Ce5E2aAA22138114E5777370aBDae)
- [RandomizerRNG](https://goerli.arbiscan.io/address/0xa2d1A3CDF0becEdb724e5A34De7022B6FF5e4787)
Expand Down Expand Up @@ -82,6 +95,7 @@ The ones below are optional:

- `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**.
- `GNOSISSCAN_API_KEY`: to verify the source of the newly deployed contracts on **Gnosis chain**.

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

Expand All @@ -100,20 +114,25 @@ yarn hardhat node --tags nothing
**Shell 2: the deploy script**

```bash
yarn deploy --network localhost --tags <Arbitration|VeaMock>
yarn deploy --network localhost --tags <Arbitration|VeaMock|ForeignGatewayOnEthereum|HomeGateway>
```

#### 3. Deploy to Public Testnets

```bash
# ArbitrumGoerli to Chiado
yarn deploy --network arbitrumGoerli --tags Arbitration
yarn deploy --network chiado --tags ForeignGatewayOnGnosis
yarn deploy --network chiado --tags KlerosLiquidOnGnosis
yarn deploy --network arbitrumGoerli --tags HomeGatewayToGnosis

# Goerli
yarn deploy --network arbitrumGoerli --tags Arbitration
yarn deploy --network goerli --tags ForeignGateway
yarn deploy --network arbitrumGoerli --tags HomeGateway
yarn deploy --network goerli --tags ForeignGatewayOnEthereum
yarn deploy --network arbitrumGoerli --tags HomeGatewayToEthereum
```

The deployed addresses should be output to the screen after the deployment is complete.
If you miss that, you can always go to the `deployments/<network>` directory and look for the respective file.
The deployed addresses should be displayed to the screen after the deployment is complete. If you missed them, you can always go to the `deployments/<network>` directory and look for the respective file.

#### Running Test Fixtures

Expand All @@ -134,7 +153,7 @@ yarn test --network localhost
This must be done for each network separately.

```bash
yarn etherscan-verify --network <arbitrumGoerli|arbitrumRinkeby|arbitrum|goerli|rinkeby|mainnet>
yarn etherscan-verify --network <arbitrumGoerli|arbitrum|chiado|gnosischain|goerli|mainnet>
```

## Ad-hoc procedures
Expand All @@ -153,7 +172,7 @@ done

#### 2/ Import the data to V2 - Local Network

:warning: This script populates only from `*.mainnet.json`, but not from `*.gnosischain.json` at this time.
:warning: By default this script populates from `*.mainnet.json`. To populate from `*.gnosischain.json`, set the variable `USE_GNOSIS` to true inside [scripts/populateCourts.ts](scripts/populateCourts.ts).

:warning: It is possible to switch to testnet-friendly court parameters by setting the variable `TESTING_PARAMETERS` to true inside [scripts/populateCourts.ts](scripts/populateCourts.ts).

Expand All @@ -177,6 +196,20 @@ yarn hardhat run scripts/populatePolicyRegistry.ts --network arbitrumGoerli
yarn hardhat run scripts/populateCourts.ts --network arbitrumGoerli
```

### Generate deployment artifacts for existing contracts

#### Usage

```bash
scripts/generateDeploymentArtifact.sh <network> <address>
```

#### Example: WETH on Gnosis chain

```bash
scripts/generateDeploymentArtifact.sh gnosischain 0xf8d1677c8a0c961938bf2f9adc3f3cfda759a9d9 > deployments/gnosischain/WETH.json
```

### Push the contracts to a Tenderly project

Ensure that your `$TENDERLY_PROJECT` and `$TENDERLY_USERNAME` is set correctly in `.env`.
Expand Down
7 changes: 4 additions & 3 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("deploying to %s with deployer %s", HomeChains[chainId], deployer);
console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer);

if (chainId === HomeChains.HARDHAT) {
pnkByChain.set(
Expand Down Expand Up @@ -79,6 +79,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const minStake = BigNumber.from(10).pow(20).mul(2);
const alpha = 10000;
const feeForJuror = BigNumber.from(10).pow(17);
const sortitionSumTreeK = 3;
const klerosCore = await deploy("KlerosCore", {
from: deployer,
libraries: {
Expand All @@ -93,7 +94,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
false,
[minStake, alpha, feeForJuror, 3], // minStake, alpha, feeForJuror, jurorsForCourtJump
[0, 0, 0, 0], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
3,
sortitionSumTreeK,
],
log: true,
});
Expand All @@ -111,7 +112,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
});
};

deployArbitration.tags = ["HomeChain", "Arbitration"];
deployArbitration.tags = ["Arbitration"];
deployArbitration.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !HomeChains[chainId];
Expand Down
4 changes: 2 additions & 2 deletions contracts/deploy/00-rng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("deploying to %s with deployer %s", HomeChains[chainId], deployer);
console.log("Deploying to %s with deployer %s", HomeChains[chainId], deployer);

if (chainId === HomeChains.HARDHAT) {
pnkByChain.set(
Expand Down Expand Up @@ -63,7 +63,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await disputeKit.changeRandomNumberGenerator(rng.address, RNG_LOOKAHEAD);
};

deployArbitration.tags = ["HomeChain", "RNG"];
deployArbitration.tags = ["RNG"];
deployArbitration.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !HomeChains[chainId];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { parseEther } from "ethers/lib/utils";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";
Expand All @@ -16,22 +15,23 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("deploying to chainId %s with deployer %s", chainId, deployer);
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);

const homeNetworks = {
1: config.networks.arbitrum,
5: config.networks.arbitrumGoerli,
ETHEREUM_MAINNET: config.networks.arbitrum,
ETHEREUM_GOERLI: config.networks.arbitrumGoerli,
HARDHAT: config.networks.localhost,
};

// Hack to predict the deployment address on the home chain.
// TODO: use deterministic deployments
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[chainId].url);
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[ForeignChains[chainId]].url);
let nonce = await homeChainProvider.getTransactionCount(deployer);
nonce += 2; // HomeGatewayToEthereum deploy tx will the third tx after this on its home network, so we add two to the current nonce.
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
const homeGatewayAddress = getContractAddress(deployer, nonce);
console.log("calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);

const veaReceiver = await deployments.get("FastBridgeReceiverOnEthereum");

Expand Down Expand Up @@ -60,7 +60,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
});
};

deployForeignGateway.tags = ["ForeignChain", "ForeignGateway"];
deployForeignGateway.tags = ["ForeignGatewayOnEthereum"];
deployForeignGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !ForeignChains[chainId];
Expand Down
93 changes: 93 additions & 0 deletions contracts/deploy/01-foreign-gateway-on-gnosis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { parseUnits } from "ethers/lib/utils";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";

enum ForeignChains {
GNOSIS_MAINNET = 100,
GNOSIS_CHIADO = 10200,
HARDHAT = 31337,
}

const wethByChain = new Map<ForeignChains, string>([
[ForeignChains.GNOSIS_MAINNET, "0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1"],
]);

const ONE_GWEI = parseUnits("1", "gwei");

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

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);

const homeNetworks = {
GNOSIS_MAINNET: config.networks.arbitrum,
GNOSIS_CHIADO: config.networks.arbitrumGoerli,
HARDHAT: config.networks.localhost,
};

// Hack to predict the deployment address on the home chain.
// TODO: use deterministic deployments
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[ForeignChains[chainId]].url);
const nonce = await homeChainProvider.getTransactionCount(deployer);
const homeGatewayAddress = getContractAddress(deployer, nonce); // HomeGateway deploy tx will be the next tx home network
console.log("Calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);

const veaReceiver = await deployments.get("FastBridgeReceiverOnGnosis");
console.log("Using FastBridgeReceiverOnGnosis at %s", veaReceiver.address);

if (!wethByChain.get(chainId)) {
const weth = await deploy("WETH", {
from: deployer,
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
});

wethByChain.set(ForeignChains[ForeignChains[chainId]], weth.address);

await deploy("WETHFaucet", {
from: deployer,
contract: "Faucet",
args: [weth.address],
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
});
}

const wethAddress = wethByChain.get(ForeignChains[ForeignChains[chainId]]);
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);

await deploy("ForeignGatewayOnGnosis", {
from: deployer,
contract: "ForeignGatewayOnGnosis",
args: [deployer, veaReceiver.address, homeGatewayAddress, homeChainIdAsBytes32, wethAddress],
log: true,
maxFeePerGas: ONE_GWEI,
maxPriorityFeePerGas: ONE_GWEI,
});

// TODO: disable the gateway until fully initialized with the correct fees OR allow disputeCreators to add funds again if necessary.
await execute(
"ForeignGatewayOnGnosis",
{ from: deployer, log: true },
"changeCourtJurorFee",
0,
ethers.utils.parseEther("0.00001")
);
};

deployForeignGateway.tags = ["ForeignGatewayOnGnosis"];
deployForeignGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !ForeignChains[chainId];
};

export default deployForeignGateway;
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("deploying to chainId %s with deployer %s", chainId, deployer);
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);

const veaSender = await deployments.get("FastBridgeSender");
const veaSender = await deployments.get("FastBridgeSenderToEthereum");
const klerosCore = await deployments.get("KlerosCore");

const foreignGateway = await hre.companionNetworks.foreign.deployments.get("ForeignGatewayOnEthereum");
const foreignChainId = Number(await hre.companionNetworks.foreign.getChainId());
const foreignGateway = await hre.companionNetworks.foreignGoerli.deployments.get("ForeignGatewayOnEthereum");
const foreignChainId = Number(await hre.companionNetworks.foreignGoerli.getChainId());
const foreignChainName = await hre.companionNetworks.foreignGoerli.deployments.getNetworkName();
console.log("Using ForeignGateway %s on chainId %s (%s)", foreignGateway.address, foreignChainId, foreignChainName);

await deploy("HomeGatewayToEthereum", {
from: deployer,
contract: "HomeGateway",
Expand All @@ -31,7 +34,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
}); // nonce+0
};

deployHomeGateway.tags = ["HomeChain", "HomeGateway"];
deployHomeGateway.tags = ["HomeGatewayToEthereum"];
deployHomeGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !HomeChains[chainId];
Expand Down
42 changes: 42 additions & 0 deletions contracts/deploy/02-home-gateway-to-gnosis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

enum HomeChains {
ARBITRUM_ONE = 42161,
ARBITRUM_GOERLI = 421613,
}

// TODO: use deterministic deployments

const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("Deploying to chainId %s with deployer %s", chainId, deployer);

const veaSender = await deployments.get("FastBridgeSenderToGnosis");
const klerosCore = await deployments.get("KlerosCore");

const foreignGateway = await hre.companionNetworks.foreignChiado.deployments.get("ForeignGatewayOnGnosis");
const foreignChainId = Number(await hre.companionNetworks.foreignChiado.getChainId());
const foreignChainName = await hre.companionNetworks.foreignChiado.deployments.getNetworkName();
console.log("Using ForeignGateway %s on chainId %s (%s)", foreignGateway.address, foreignChainId, foreignChainName);

await deploy("HomeGatewayToGnosis", {
from: deployer,
contract: "HomeGateway",
args: [deployer, klerosCore.address, veaSender.address, foreignGateway.address, foreignChainId],
log: true,
}); // nonce+0
};

deployHomeGateway.tags = ["HomeGatewayToGnosis"];
deployHomeGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !HomeChains[chainId];
};

export default deployHomeGateway;
Loading