Skip to content

feat(deploy): referencing the PNK token for each chain #45

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 1 commit into from
Feb 16, 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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"mochaExplorer.files": "contracts/test/**/*.{j,t}s",
"cSpell.words": [
"arbitrum",
"IERC",
"kleros"
]
}
31 changes: 27 additions & 4 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
- [ConstantNG](https://testnet.arbiscan.io/address/0x4401A368dea8D5761AEEFfd3c4a674086dea0666)
- [DisputeKitClassic](https://testnet.arbiscan.io/address/0xD78DCddE2C5a2Bd4BB246Bc7dB6994b95f7c442C)
- [FastBridgeSender](https://testnet.arbiscan.io/address/0x34E520dc1d2Db660113b64724e14CEdCD01Ee879)
- [HomeGateway](https://testnet.arbiscan.io/address/0x40a78989317B953e427B3BD87C59eA003fcC2296)
- [KlerosCore](https://testnet.arbiscan.io/address/0xf2a59723c5d625D646668E0B615B5764c3F81540)
- [HomeGateway](https://testnet.arbiscan.io/address/0x4d18b9792e0D8F5aF696E71dBEDff8fcBEed6e8C)
- [KlerosCore](https://testnet.arbiscan.io/address/0x5A407DcbD0F83ECbc1894C4B4f8Fc5b699D4822F)
- [SafeBridgeArbitrum](https://testnet.arbiscan.io/address/0x68eE49dfD9d76f3386257a3D0e0A85c0A5519bBD)
- [SortitionSumTreeFactory](https://testnet.arbiscan.io/address/0xf02733d9e5CbfE67B54F165b0277E1995106D526)

Expand Down Expand Up @@ -80,11 +80,34 @@ The ones below are 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 to a Local Network

The complete deployment is multi-chain, so a deployment to the local network can only simulate either the Home chain or the Foreign chain.
Currently the scripts support only deploying the HomeChain contracts to the local network.

**Shell 1: the node**

```bash
yarn hardhat node --tags nothing
```

**Shell 2: the deploy script**

```bash
yarn hardhat deploy --network localhost --tags HomeChain
```

#### 2. Deploy to Public Testnets

```bash
yarn deploy:staging # to deploy to L1/L2 testnet
# yarn deploy:production # to deploy to L1/L2 mainnet
# To deploy on L2 only
yarn hardhat deploy --network arbitrumRinkeby --tags HomeChain

# To deploy on L1 only
yarn hardhat deploy --network rinkeby --tags ForeignChain

# To deploy both L1 and L2
yarn deploy:staging
```

The deployed addresses should be output to the screen after the deployment is complete.
Expand Down
42 changes: 35 additions & 7 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";

const HOME_CHAIN_IDS = [42161, 421611, 31337]; // ArbOne, ArbRinkeby, Hardhat
enum HomeChains {
ARBITRUM_ONE = 42161,
ARBITRUM_RINKEBY = 421611,
HARDHAT = 31337,
}

const pnkByChain = new Map<HomeChains, string>([
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
[HomeChains.ARBITRUM_RINKEBY, "0x364530164a2338cdba211f72c1438eb811b5c639"],
]);

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts } = hre;
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
const { AddressZero } = hre.ethers.constants;

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

const rng = await deploy("ConstantNG", {
from: deployer,
Expand All @@ -29,21 +39,39 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
log: true,
});

// TODO: deploy a PNK token if there isn't one already
if (chainId === HomeChains.HARDHAT) {
pnkByChain.set(
HomeChains.HARDHAT,
(
await deploy("PNK", {
from: deployer,
log: true,
})
).address
);
}
const pnk = pnkByChain.get(Number(await getChainId())) ?? AddressZero;

const klerosCore = await deploy("KlerosCore", {
from: deployer,
libraries: {
SortitionSumTreeFactory: sortitionSumTreeLibrary.address,
},
args: [deployer, AddressZero, AddressZero, disputeKit.address, false, 200, 10000, 100, 3, [0, 0, 0, 0], 3],
args: [deployer, pnk, AddressZero, disputeKit.address, false, 200, 10000, 100, 3, [0, 0, 0, 0], 3],
log: true,
});

await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address);
// execute DisputeKitClassic.changeCore() only if necessary
const currentCore = await hre.ethers.getContractAt("DisputeKitClassic", disputeKit.address).then((dk) => dk.core());
if (currentCore !== klerosCore.address) {
await execute("DisputeKitClassic", { from: deployer, log: true }, "changeCore", klerosCore.address);
}
};

deployArbitration.tags = ["HomeChain", "Arbitration"];
deployArbitration.skip = async ({ getChainId }) => !HOME_CHAIN_IDS.includes(Number(await getChainId()));
deployArbitration.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !HomeChains[chainId];
};

export default deployArbitration;
2 changes: 1 addition & 1 deletion contracts/deploy/01-foreign-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const paramsByChainId = {
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
const { deploy } = deployments;
const { providers, constants } = ethers;
const { providers } = ethers;
const { hexZeroPad } = hre.ethers.utils;

const { deployer } = await getNamedAccounts();
Expand Down
68 changes: 34 additions & 34 deletions contracts/deployments/arbitrumRinkeby/HomeGateway.json

Large diffs are not rendered by default.

166 changes: 83 additions & 83 deletions contracts/deployments/arbitrumRinkeby/KlerosCore.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "hardhat-deploy";
import "hardhat-deploy-ethers";
import "hardhat-watcher";
import "hardhat-docgen";
import "hardhat-contract-sizer";

dotenv.config();

Expand Down
1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"ethers": "^5.5.1",
"follow-redirects": "^1.14.7",
"hardhat": "^2.6.8",
"hardhat-contract-sizer": "^2.4.0",
"hardhat-deploy": "^0.10.5",
"hardhat-deploy-ethers": "^0.3.0-beta.11",
"hardhat-docgen": "^1.2.1",
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/arbitration/PNK.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract PNK is ERC20 {
constructor() ERC20("Pinakion", "PNK") {}
}
4 changes: 2 additions & 2 deletions contracts/test/arbitration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function deployContracts(deployer) {

const disputeKitFactory = await ethers.getContractFactory("DisputeKitClassic", deployer);
const disputeKit = await disputeKitFactory.deploy(
deployer.address,
deployer.address,
ethers.constants.AddressZero, // KlerosCore is set later once it is deployed
rng.address
);
Expand All @@ -57,7 +57,7 @@ async function deployContracts(deployer) {
},
});
const core = await klerosCoreFactory.deploy(
deployer.address,
deployer.address,
ethers.constants.AddressZero, // should be an ERC20
ethers.constants.AddressZero, // should be a Juror Prosecution module
disputeKit.address,
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ __metadata:
ethers: ^5.5.1
follow-redirects: ^1.14.7
hardhat: ^2.6.8
hardhat-contract-sizer: ^2.4.0
hardhat-deploy: ^0.10.5
hardhat-deploy-ethers: ^0.3.0-beta.11
hardhat-docgen: ^1.2.1
Expand Down Expand Up @@ -4233,6 +4234,19 @@ __metadata:
languageName: node
linkType: hard

"cli-table3@npm:^0.6.0":
version: 0.6.1
resolution: "cli-table3@npm:0.6.1"
dependencies:
colors: 1.4.0
string-width: ^4.2.0
dependenciesMeta:
colors:
optional: true
checksum: 956e175f8eb019c26465b9f1e51121c08d8978e2aab04be7f8520ea8a4e67906fcbd8516dfb77e386ae3730ef0281aa21a65613dffbfa3d62969263252bd25a9
languageName: node
linkType: hard

"cli-truncate@npm:2.1.0, cli-truncate@npm:^2.1.0":
version: 2.1.0
resolution: "cli-truncate@npm:2.1.0"
Expand Down Expand Up @@ -8023,6 +8037,18 @@ __metadata:
languageName: node
linkType: hard

"hardhat-contract-sizer@npm:^2.4.0":
version: 2.4.0
resolution: "hardhat-contract-sizer@npm:2.4.0"
dependencies:
chalk: ^4.0.0
cli-table3: ^0.6.0
peerDependencies:
hardhat: ^2.0.0
checksum: 813111c3ae27264a1e50feecd0c2670421e9c77eb08ac474ab9b88b1c5cc7578cf3a7f0778f583d684e127084de9ca81be9412eeb02c593aa8acc7e6a42bde89
languageName: node
linkType: hard

"hardhat-deploy-ethers@npm:^0.3.0-beta.11":
version: 0.3.0-beta.13
resolution: "hardhat-deploy-ethers@npm:0.3.0-beta.13"
Expand Down