Skip to content

Commit b44a886

Browse files
committed
feat: chiado deployment scripts (WIP)
1 parent 450a2cb commit b44a886

File tree

8 files changed

+272
-2
lines changed

8 files changed

+272
-2
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { parseEther } from "ethers/lib/utils";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
3+
import { DeployFunction } from "hardhat-deploy/types";
4+
import getContractAddress from "../deploy-helpers/getContractAddress";
5+
6+
enum ForeignChains {
7+
GNOSIS_MAINNET = 100,
8+
GNOSIS_CHIADO = 10200,
9+
HARDHAT = 31337,
10+
}
11+
12+
const wethByChain = new Map<ForeignChains, string>([
13+
[ForeignChains.GNOSIS_MAINNET, "0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1"],
14+
]);
15+
16+
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
17+
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
18+
const { deploy, execute } = deployments;
19+
const { hexZeroPad, hexlify } = ethers.utils;
20+
21+
// fallback to hardhat node signers on local network
22+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
23+
const chainId = Number(await getChainId());
24+
console.log("deploying to chainId %s with deployer %s", chainId, deployer);
25+
26+
const homeNetworks = {
27+
1: config.networks.arbitrum,
28+
5: config.networks.arbitrumGoerli,
29+
};
30+
31+
// Hack to predict the deployment address on the home chain.
32+
// TODO: use deterministic deployments
33+
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[chainId].url);
34+
let nonce = await homeChainProvider.getTransactionCount(deployer);
35+
nonce += 2; // HomeGatewayToEthereum deploy tx will the third tx after this on its home network, so we add two to the current nonce.
36+
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
37+
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
38+
const homeGatewayAddress = getContractAddress(deployer, nonce);
39+
console.log("calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
40+
41+
const veaReceiver = await deployments.get("FastBridgeReceiverOnGnosis");
42+
43+
if (!wethByChain.get(chainId)) {
44+
const weth = await deploy("WETH", {
45+
from: deployer,
46+
log: true,
47+
});
48+
49+
wethByChain.set(ForeignChains[ForeignChains[chainId]], weth.address);
50+
51+
await deploy("WETHFaucet", {
52+
from: deployer,
53+
contract: "Faucet",
54+
args: [weth],
55+
log: true,
56+
});
57+
}
58+
59+
const foreignGateway = await deploy("xForeignGateway", {
60+
from: deployer,
61+
contract: "xForeignGateway",
62+
args: [deployer, veaReceiver.address, homeGatewayAddress, homeChainIdAsBytes32, wethByChain[chainId]],
63+
gasLimit: 4000000,
64+
log: true,
65+
});
66+
67+
await execute(
68+
"xForeignGateway",
69+
{ from: deployer, log: true },
70+
"changeCourtJurorFee",
71+
0,
72+
ethers.utils.parseEther("0.00001") // TODO: fix this from xKlerosLiquid xDAI -> ETH amount
73+
);
74+
};
75+
76+
deployForeignGateway.tags = ["ForeignChain", "ForeignGatewayOnGnosis"];
77+
deployForeignGateway.skip = async ({ getChainId }) => {
78+
const chainId = Number(await getChainId());
79+
return !ForeignChains[chainId];
80+
};
81+
82+
export default deployForeignGateway;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { parseEther } from "ethers/lib/utils";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
3+
import { DeployFunction } from "hardhat-deploy/types";
4+
import getContractAddress from "../deploy-helpers/getContractAddress";
5+
import { util } from "chai";
6+
import { rng } from "../typechain-types/src";
7+
8+
enum ForeignChains {
9+
GNOSIS_MAINNET = 100,
10+
GNOSIS_CHIADO = 10200,
11+
HARDHAT = 31337,
12+
}
13+
14+
const wethByChain = new Map<ForeignChains, string>([
15+
[ForeignChains.GNOSIS_MAINNET, "0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1"],
16+
]);
17+
18+
const xPinakionByChain = new Map<ForeignChains, string>([
19+
[ForeignChains.GNOSIS_MAINNET, "0x37b60f4E9A31A64cCc0024dce7D0fD07eAA0F7B3"],
20+
[ForeignChains.GNOSIS_CHIADO, "0x00"],
21+
]);
22+
23+
const tokenBridgeByChain = new Map<ForeignChains, string>([
24+
[ForeignChains.GNOSIS_MAINNET, "0xf6A78083ca3e2a662D6dd1703c939c8aCE2e268d"],
25+
[ForeignChains.GNOSIS_CHIADO, "0xbb3c86f9918C3C1d83668fA84e79E876d147fFf2"],
26+
]);
27+
28+
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
29+
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
30+
const { deploy, execute } = deployments;
31+
const { hexZeroPad, hexlify } = ethers.utils;
32+
33+
// fallback to hardhat node signers on local network
34+
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
35+
const chainId = Number(await getChainId());
36+
console.log("deploying to chainId %s with deployer %s", chainId, deployer);
37+
38+
const homeNetworks = {
39+
1: config.networks.arbitrum,
40+
5: config.networks.arbitrumGoerli,
41+
};
42+
43+
// Hack to predict the deployment address on the home chain.
44+
// TODO: use deterministic deployments
45+
const homeChainProvider = new ethers.providers.JsonRpcProvider(homeNetworks[chainId].url);
46+
let nonce = await homeChainProvider.getTransactionCount(deployer);
47+
nonce += 2; // HomeGatewayToEthereum deploy tx will the third tx after this on its home network, so we add two to the current nonce.
48+
const homeChainId = (await homeChainProvider.getNetwork()).chainId;
49+
const homeChainIdAsBytes32 = hexZeroPad(hexlify(homeChainId), 32);
50+
const homeGatewayAddress = getContractAddress(deployer, nonce);
51+
console.log("calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
52+
53+
const veaReceiver = await deployments.get("FastBridgeReceiverOnGnosis");
54+
55+
// const wEth = await deployments.get("WETH");
56+
const wEth = wethByChain[chainId];
57+
58+
// const xPnk = await deployments.get("WPNK");
59+
const xPnk = xPinakionByChain[chainId];
60+
61+
const tokenBridge = tokenBridgeByChain[chainId];
62+
const rnGenerator = ethers.constants.AddressZero;
63+
64+
// TODO: deploy mocks for xPinakion and tokenBridge for Hardhat network
65+
66+
const wPnk = await deploy("WrappedPinakion", {
67+
from: deployer,
68+
log: true,
69+
});
70+
71+
await execute(
72+
"WrappedPinakion",
73+
{ from: deployer, log: true },
74+
"initialize",
75+
"Staking PNK on xDai",
76+
"stPNK",
77+
xPnk,
78+
tokenBridge
79+
);
80+
81+
const xKlerosLiquidToV2 = await deploy("xKlerosLiquidToV2", {
82+
from: deployer,
83+
log: true,
84+
});
85+
86+
await execute(
87+
"xKlerosLiquidToV2",
88+
{ from: deployer, log: true },
89+
"initialize",
90+
deployer,
91+
wPnk,
92+
rnGenerator,
93+
99999999,
94+
0,
95+
false,
96+
[999999999, 0, 0, 9999999],
97+
[]
98+
);
99+
100+
const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`;
101+
102+
await deploy("ArbitrableExample", {
103+
from: deployer,
104+
args: [foreignGateway.address, metaEvidenceUri],
105+
log: true,
106+
});
107+
};
108+
109+
deployForeignGateway.tags = ["ForeignChain", "KlerosLiquidOnGnosis"];
110+
deployForeignGateway.skip = async ({ getChainId }) => {
111+
const chainId = Number(await getChainId());
112+
return !ForeignChains[chainId];
113+
};
114+
115+
export default deployForeignGateway;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"type": "single-select",
3+
"titles": [
4+
"Alice",
5+
"Bob",
6+
"Charlie"
7+
],
8+
"descriptions": [
9+
"Alice is right.",
10+
"Bob is right.",
11+
"Charlie is right"
12+
],
13+
"arbitratorChainID": 421613,
14+
"arbitrableChainID": 10200,
15+
"arbitrableInterfaceURI": "https://my-awesomme.dapp.io/item/1234",
16+
"dynamicScriptRequiredParams": [
17+
"arbitrableChainID",
18+
"arbitrableContractAddress"
19+
],
20+
"evidenceDisplayInterfaceRequiredParams": [
21+
"disputeID",
22+
"arbitrableContractAddress",
23+
"arbitratorContractAddress",
24+
"arbitratorChainID"
25+
],
26+
"_v": "1.0.0"
27+
}

contracts/scripts/console-init.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
core = await ethers.getContract("KlerosCore");
2+
disputeKit = await ethers.getContract("DisputeKitClassic");
3+
rng = await ethers.getContract("RandomizerRNG");
4+
rng2 = await ethers.getContract("BlockHashRNG");
5+
options = { gasLimit: 10000000, gasPrice: 5000000000 };
6+
7+
console.log("core phase: %s", await core.phase());
8+
console.log("disputekit phase: %s", await disputeKit.phase());
9+
console.log("freezingPhase timeout? %s", await core.freezingPhaseTimeout());
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8;
4+
5+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
7+
contract Faucet {
8+
IERC20 public token;
9+
mapping(address => bool) public withdrewAlready;
10+
11+
constructor(IERC20 _token) {
12+
token = _token;
13+
}
14+
15+
function balance() public view returns (uint) {
16+
return token.balanceOf(address(this));
17+
}
18+
19+
function request() public {
20+
require(
21+
!withdrewAlready[msg.sender],
22+
"You have used this faucet already. If you need more tokens, please use another address."
23+
);
24+
token.transfer(msg.sender, 10000 ether);
25+
withdrewAlready[msg.sender] = true;
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8;
4+
5+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
7+
contract WETH is ERC20 {
8+
constructor() ERC20("Wrapped ETH", "WETH") {
9+
_mint(msg.sender, 1000000 ether);
10+
}
11+
}

contracts/src/kleros-v1/kleros-liquid-xdai/WrappedPinakion.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ contract WrappedPinakion is Initializable {
7979
decimals = 18;
8080
xPinakion = _xPinakion;
8181
tokenBridge = _tokenBridge;
82-
8382
controller = msg.sender;
8483
}
8584

contracts/src/kleros-v1/kleros-liquid-xdai/xKlerosLiquidToV2.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {SortitionSumTreeFactory} from "../../libraries/SortitionSumTreeFactory.s
1313
import "../../gateway/interfaces/IForeignGateway.sol";
1414

1515
/**
16-
* @title xKlerosLiquid
16+
* @title xKlerosLiquidToV2
1717
* @dev This contract is an adaption of Mainnet's KlerosLiquid (https://github.com/kleros/kleros/blob/69cfbfb2128c29f1625b3a99a3183540772fda08/contracts/kleros/KlerosLiquid.sol)
1818
* for xDai chain. Notice that variables referring to ETH values in this contract, will hold the native token values of the chain on which xKlerosLiquid is deployed.
1919
* When this contract gets deployed on xDai chain, ETH variables will hold xDai values.

0 commit comments

Comments
 (0)