Skip to content

Commit 90487b3

Browse files
committed
feat: deploy script for arbitration
Also better support for local deployments of the home chain contracts.
1 parent bb0d788 commit 90487b3

File tree

10 files changed

+3278
-48
lines changed

10 files changed

+3278
-48
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"solidity.compileUsingRemoteVersion": "v0.8.10+commit.fc410830",
33
"mochaExplorer.files": "contracts/test/**/*.{j,t}s",
44
"cSpell.words": [
5-
"arbitrum"
5+
"arbitrum",
6+
"kleros"
67
]
78
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
4+
const HOME_CHAIN_IDS = [42161, 421611, 31337]; // ArbOne, ArbRinkeby, Hardhat
5+
6+
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
7+
const { deployments, getNamedAccounts } = hre;
8+
const { deploy, execute } = deployments;
9+
const { AddressZero } = hre.ethers.constants;
10+
11+
// fallback to hardhat node signers on local network
12+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
13+
console.log("deployer: %s", deployer);
14+
15+
const rng = await deploy("ConstantNG", {
16+
from: deployer,
17+
args: [42],
18+
log: true,
19+
});
20+
21+
const disputeKit = await deploy("DisputeKitClassic", {
22+
from: deployer,
23+
args: [deployer, AddressZero, rng.address],
24+
log: true,
25+
});
26+
27+
const sortitionSumTreeLibrary = await deploy("SortitionSumTreeFactory", {
28+
from: deployer,
29+
log: true,
30+
});
31+
32+
// TODO: deploy a PNK token if there isn't one already
33+
34+
const klerosCore = await deploy("KlerosCore", {
35+
from: deployer,
36+
libraries: {
37+
SortitionSumTreeFactory: sortitionSumTreeLibrary.address,
38+
},
39+
args: [deployer, AddressZero, AddressZero, disputeKit.address, false, 200, 10000, 100, 3, [0, 0, 0, 0], 3],
40+
log: true,
41+
});
42+
43+
await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address);
44+
};
45+
46+
deployArbitration.tags = ["HomeChain", "Arbitration"];
47+
deployArbitration.skip = async ({ getChainId }) => !HOME_CHAIN_IDS.includes(Number(await getChainId()));
48+
49+
export default deployArbitration;

contracts/deploy/01-foreign-chain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DeployFunction } from "hardhat-deploy/types";
55

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

8-
const FOREIGN_CHAIN_IDS = [1, 4];
8+
const FOREIGN_CHAIN_IDS = [1, 4, 31337]; // Mainnet, Rinkeby, Hardhat
99
const paramsByChainId = {
1010
1: {
1111
claimDeposit: parseEther("0.1"),

contracts/deploy/02-home-chain.ts

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,41 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33

4-
import getContractAddress from "../deploy-helpers/getContractAddress";
5-
6-
const HOME_CHAIN_IDS = [42161, 421611];
7-
const paramsByChainId = {
8-
4: {
9-
arbitrator: "0xab96e690f784b305942752a1fda42680e80f37a0", // SimplePermissionlessArbitrator
10-
foreignChainId: 77,
11-
},
12-
42161: {
13-
arbitrator: "0x18c8a7ec7897177E4529065a7E7B0878358B3BfF", // SimplePermissionlessArbitrator
14-
foreignChainId: 1,
15-
},
16-
421611: {
17-
arbitrator: "0x18c8a7ec7897177E4529065a7E7B0878358B3BfF", // SimplePermissionlessArbitrator
18-
foreignChainId: 4,
19-
},
20-
};
4+
const HOME_CHAIN_IDS = [42161, 421611, 31337]; // ArbOne, ArbRinkeby, Hardhat
215

226
const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
23-
const { deployments, getNamedAccounts, getChainId } = hre;
7+
const { deployments, getNamedAccounts } = hre;
248
const { deploy, execute } = deployments;
25-
const { hexZeroPad } = hre.ethers.utils;
26-
27-
const { deployer } = await getNamedAccounts();
28-
const chainId = await getChainId();
29-
30-
const { arbitrator, foreignChainId } = paramsByChainId[chainId];
31-
32-
const foreignGateway = await hre.companionNetworks.foreign.deployments.get("ForeignGateway");
33-
const fastBridgeReceiver = await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiver");
349

35-
const foreignChainIdAsBytes32 = hexZeroPad(foreignChainId, 32);
10+
// fallback to hardhat node signers on local network
11+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
12+
console.log("deployer: %s", deployer);
3613

3714
const safeBridge = await deploy("SafeBridgeArbitrum", {
3815
from: deployer,
3916
log: true,
4017
});
4118

19+
const fastBridgeReceiver = await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiver");
4220
const fastBridgeSender = await deploy("FastBridgeSender", {
4321
from: deployer,
4422
args: [safeBridge.address, fastBridgeReceiver.address],
4523
log: true,
4624
});
4725

26+
const klerosCore = await deployments.get("KlerosCore");
27+
const foreignGateway = await hre.companionNetworks.foreign.deployments.get("ForeignGateway");
28+
const foreignChainId = Number(await hre.companionNetworks.foreign.getChainId());
4829
const homeGateway = await deploy("HomeGateway", {
4930
from: deployer,
50-
args: [arbitrator, fastBridgeSender.address, foreignGateway.address, foreignChainIdAsBytes32],
31+
args: [klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
5132
log: true,
5233
});
5334

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

57-
deployHomeGateway.tags = ["HomeChain"];
38+
deployHomeGateway.tags = ["HomeChain", "HomeGateway"];
5839
deployHomeGateway.skip = async ({ getChainId }) => !HOME_CHAIN_IDS.includes(Number(await getChainId()));
5940

6041
export default deployHomeGateway;
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"address": "0x87142b7E9C7D026776499120D902AF8896C07894",
3+
"abi": [
4+
{
5+
"inputs": [
6+
{
7+
"internalType": "uint256",
8+
"name": "_number",
9+
"type": "uint256"
10+
}
11+
],
12+
"stateMutability": "nonpayable",
13+
"type": "constructor"
14+
},
15+
{
16+
"inputs": [
17+
{
18+
"internalType": "uint256",
19+
"name": "_block",
20+
"type": "uint256"
21+
}
22+
],
23+
"name": "contribute",
24+
"outputs": [],
25+
"stateMutability": "payable",
26+
"type": "function"
27+
},
28+
{
29+
"inputs": [
30+
{
31+
"internalType": "uint256",
32+
"name": "_block",
33+
"type": "uint256"
34+
}
35+
],
36+
"name": "getRN",
37+
"outputs": [
38+
{
39+
"internalType": "uint256",
40+
"name": "RN",
41+
"type": "uint256"
42+
}
43+
],
44+
"stateMutability": "view",
45+
"type": "function"
46+
},
47+
{
48+
"inputs": [
49+
{
50+
"internalType": "uint256",
51+
"name": "_block",
52+
"type": "uint256"
53+
}
54+
],
55+
"name": "getUncorrelatedRN",
56+
"outputs": [
57+
{
58+
"internalType": "uint256",
59+
"name": "RN",
60+
"type": "uint256"
61+
}
62+
],
63+
"stateMutability": "nonpayable",
64+
"type": "function"
65+
},
66+
{
67+
"inputs": [],
68+
"name": "number",
69+
"outputs": [
70+
{
71+
"internalType": "uint256",
72+
"name": "",
73+
"type": "uint256"
74+
}
75+
],
76+
"stateMutability": "view",
77+
"type": "function"
78+
},
79+
{
80+
"inputs": [
81+
{
82+
"internalType": "uint256",
83+
"name": "_block",
84+
"type": "uint256"
85+
}
86+
],
87+
"name": "requestRN",
88+
"outputs": [],
89+
"stateMutability": "payable",
90+
"type": "function"
91+
}
92+
],
93+
"transactionHash": "0x994e342622469b1e19becdf52b4614d4f57bac87185e7d7496d4815cdadd276c",
94+
"receipt": {
95+
"to": null,
96+
"from": "0xF50E77f2A2B6138D16c6c7511562E5C33c4B15A3",
97+
"contractAddress": "0x87142b7E9C7D026776499120D902AF8896C07894",
98+
"transactionIndex": 0,
99+
"gasUsed": "2027143",
100+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
101+
"blockHash": "0xf208ce071e86e58470ebbbd798aad9d927f53482ae74e57a209e827c46484265",
102+
"transactionHash": "0x994e342622469b1e19becdf52b4614d4f57bac87185e7d7496d4815cdadd276c",
103+
"logs": [],
104+
"blockNumber": 9358156,
105+
"cumulativeGasUsed": "762143",
106+
"status": 1,
107+
"byzantium": true
108+
},
109+
"args": [
110+
42
111+
],
112+
"numDeployments": 1,
113+
"solcInputHash": "9627b78546d73cee66a2022d221ca6c9",
114+
"metadata": "{\"compiler\":{\"version\":\"0.8.10+commit.fc410830\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_number\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_block\",\"type\":\"uint256\"}],\"name\":\"contribute\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_block\",\"type\":\"uint256\"}],\"name\":\"getRN\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"RN\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_block\",\"type\":\"uint256\"}],\"name\":\"getUncorrelatedRN\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"RN\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"number\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_block\",\"type\":\"uint256\"}],\"name\":\"requestRN\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"constructor\":{\"details\":\"Constructor.\",\"params\":{\"_number\":\"The number to always return.\"}},\"contribute(uint256)\":{\"details\":\"Contribute to the reward of a random number. All the ETH will be lost forever.\",\"params\":{\"_block\":\"Block the random number is linked to.\"}},\"getRN(uint256)\":{\"details\":\"Get the \\\"random number\\\" (which is always the same).\",\"params\":{\"_block\":\"Block the random number is linked to.\"},\"returns\":{\"RN\":\"Random Number. If the number is not ready or has not been required 0 instead.\"}},\"getUncorrelatedRN(uint256)\":{\"details\":\"Get a uncorrelated random number. Act like getRN but give a different number for each sender. This is to prevent users from getting correlated numbers.\",\"params\":{\"_block\":\"Block the random number is linked to.\"},\"returns\":{\"RN\":\"Random Number. If the number is not ready or has not been required 0 instead.\"}},\"requestRN(uint256)\":{\"details\":\"Request a random number.\",\"params\":{\"_block\":\"Block linked to the request.\"}}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/rng/ConstantNG.sol\":\"ConstantNG\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"src/rng/ConstantNG.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\n/**\\n * @title Constant Number Generator\\n * @author Cl\\u00e9ment Lesaege - <[email protected]>\\n * @dev A Random Number Generator which always return the same number. Usefull in order to make tests.\\n */\\n\\npragma solidity ^0.8;\\nimport \\\"./RNG.sol\\\";\\n\\ncontract ConstantNG is RNG {\\n uint256 public immutable number;\\n\\n /**\\n * @dev Constructor.\\n * @param _number The number to always return.\\n */\\n constructor(uint256 _number) {\\n number = _number;\\n }\\n\\n /**\\n * @dev Contribute to the reward of a random number. All the ETH will be lost forever.\\n * @param _block Block the random number is linked to.\\n */\\n function contribute(uint256 _block) public payable override {}\\n\\n /**\\n * @dev Get the \\\"random number\\\" (which is always the same).\\n * @param _block Block the random number is linked to.\\n * @return RN Random Number. If the number is not ready or has not been required 0 instead.\\n */\\n function getRN(uint256 _block) public view override returns (uint256 RN) {\\n return number;\\n }\\n}\\n\",\"keccak256\":\"0xa36e4dbc69128b01a005e4a9ce79a4c0f555be0963497e7cabdb76028f00e44c\",\"license\":\"MIT\"},\"src/rng/RNG.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\n/**\\n * @authors: [@clesaege]\\n * @reviewers: [@remedcu]\\n * @auditors: []\\n * @bounties: []\\n * @deployments: []\\n */\\n\\npragma solidity ^0.8;\\n\\n/**\\n * @title Random Number Generator Standard\\n * @author Cl\\u00e9ment Lesaege - <[email protected]>\\n * @dev This is an abstract contract\\n */\\nabstract contract RNG {\\n /**\\n * @dev Contribute to the reward of a random number.\\n * @param _block Block the random number is linked to.\\n */\\n function contribute(uint256 _block) public payable virtual;\\n\\n /**\\n * @dev Request a random number.\\n * @param _block Block linked to the request.\\n */\\n function requestRN(uint256 _block) public payable {\\n contribute(_block);\\n }\\n\\n /**\\n * @dev Get the random number.\\n * @param _block Block the random number is linked to.\\n * @return RN Random Number. If the number is not ready or has not been required 0 instead.\\n */\\n function getRN(uint256 _block) public virtual returns (uint256 RN);\\n\\n /**\\n * @dev Get a uncorrelated random number. Act like getRN but give a different number for each sender.\\n * This is to prevent users from getting correlated numbers.\\n * @param _block Block the random number is linked to.\\n * @return RN Random Number. If the number is not ready or has not been required 0 instead.\\n */\\n function getUncorrelatedRN(uint256 _block) public returns (uint256 RN) {\\n uint256 baseRN = getRN(_block);\\n if (baseRN == 0) return 0;\\n else return uint256(keccak256(abi.encode(msg.sender, baseRN)));\\n }\\n}\\n\",\"keccak256\":\"0x854bcb147fe44383cba7a5fdbcb69b3c0a9a71435c80eb73c172222da472a855\",\"license\":\"MIT\"}},\"version\":1}",
115+
"bytecode": "0x60a060405234801561001057600080fd5b5060405161024438038061024483398101604081905261002f91610037565b608052610050565b60006020828403121561004957600080fd5b5051919050565b6080516101cd6100776000396000818160a80152818160f9015261011f01526101cd6000f3fe60806040526004361061004a5760003560e01c80631c73601e1461004f5780637b9c34e0146100815780638381f58a14610096578063c1cbbca7146100ca578063ca4742f1146100db575b600080fd5b34801561005b57600080fd5b5061006f61006a36600461017e565b61011b565b60405190815260200160405180910390f35b61009461008f36600461017e565b6100d8565b005b3480156100a257600080fd5b5061006f7f000000000000000000000000000000000000000000000000000000000000000081565b6100946100d836600461017e565b50565b3480156100e757600080fd5b5061006f6100f636600461017e565b507f000000000000000000000000000000000000000000000000000000000000000090565b60007f00000000000000000000000000000000000000000000000000000000000000008061014c5750600092915050565b6040805133602082015290810182905260600160408051601f1981840301815291905280516020909101209392505050565b60006020828403121561019057600080fd5b503591905056fea2646970667358221220693d5cc66e09ccd6a6d6637ad435b22e4b44841e2e761be701bf91040945c1fc64736f6c634300080a0033",
116+
"deployedBytecode": "0x60806040526004361061004a5760003560e01c80631c73601e1461004f5780637b9c34e0146100815780638381f58a14610096578063c1cbbca7146100ca578063ca4742f1146100db575b600080fd5b34801561005b57600080fd5b5061006f61006a36600461017e565b61011b565b60405190815260200160405180910390f35b61009461008f36600461017e565b6100d8565b005b3480156100a257600080fd5b5061006f7f000000000000000000000000000000000000000000000000000000000000000081565b6100946100d836600461017e565b50565b3480156100e757600080fd5b5061006f6100f636600461017e565b507f000000000000000000000000000000000000000000000000000000000000000090565b60007f00000000000000000000000000000000000000000000000000000000000000008061014c5750600092915050565b6040805133602082015290810182905260600160408051601f1981840301815291905280516020909101209392505050565b60006020828403121561019057600080fd5b503591905056fea2646970667358221220693d5cc66e09ccd6a6d6637ad435b22e4b44841e2e761be701bf91040945c1fc64736f6c634300080a0033",
117+
"devdoc": {
118+
"kind": "dev",
119+
"methods": {
120+
"constructor": {
121+
"details": "Constructor.",
122+
"params": {
123+
"_number": "The number to always return."
124+
}
125+
},
126+
"contribute(uint256)": {
127+
"details": "Contribute to the reward of a random number. All the ETH will be lost forever.",
128+
"params": {
129+
"_block": "Block the random number is linked to."
130+
}
131+
},
132+
"getRN(uint256)": {
133+
"details": "Get the \"random number\" (which is always the same).",
134+
"params": {
135+
"_block": "Block the random number is linked to."
136+
},
137+
"returns": {
138+
"RN": "Random Number. If the number is not ready or has not been required 0 instead."
139+
}
140+
},
141+
"getUncorrelatedRN(uint256)": {
142+
"details": "Get a uncorrelated random number. Act like getRN but give a different number for each sender. This is to prevent users from getting correlated numbers.",
143+
"params": {
144+
"_block": "Block the random number is linked to."
145+
},
146+
"returns": {
147+
"RN": "Random Number. If the number is not ready or has not been required 0 instead."
148+
}
149+
},
150+
"requestRN(uint256)": {
151+
"details": "Request a random number.",
152+
"params": {
153+
"_block": "Block linked to the request."
154+
}
155+
}
156+
},
157+
"version": 1
158+
},
159+
"userdoc": {
160+
"kind": "user",
161+
"methods": {},
162+
"version": 1
163+
},
164+
"storageLayout": {
165+
"storage": [],
166+
"types": null
167+
}
168+
}

0 commit comments

Comments
 (0)