|
1 | | -import { parseEther } from "ethers/lib/utils"; |
| 1 | +import { parseUnits, parseEther } from "ethers/lib/utils"; |
2 | 2 | import { HardhatRuntimeEnvironment } from "hardhat/types"; |
3 | 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 | 4 |
|
8 | 5 | enum ForeignChains { |
9 | 6 | GNOSIS_MAINNET = 100, |
10 | 7 | GNOSIS_CHIADO = 10200, |
11 | 8 | HARDHAT = 31337, |
12 | 9 | } |
13 | 10 |
|
14 | | -const wethByChain = new Map<ForeignChains, string>([ |
15 | | - [ForeignChains.GNOSIS_MAINNET, "0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1"], |
| 11 | +const wrappedPNKByChain = new Map<ForeignChains, string>([ |
| 12 | + [ForeignChains.GNOSIS_MAINNET, "0xcb3231aBA3b451343e0Fddfc45883c842f223846"], |
16 | 13 | ]); |
17 | 14 |
|
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 | | -]); |
| 15 | +const ONE_GWEI = parseUnits("1", "gwei"); |
27 | 16 |
|
28 | 17 | const deployKlerosLiquid: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { |
29 | | - const { ethers, deployments, getNamedAccounts, getChainId, config } = hre; |
| 18 | + const { ethers, deployments, getNamedAccounts, getChainId } = hre; |
30 | 19 | const { deploy, execute } = deployments; |
31 | | - const { hexZeroPad, hexlify } = ethers.utils; |
32 | 20 |
|
33 | 21 | // fallback to hardhat node signers on local network |
34 | 22 | const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; |
35 | 23 | 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 |
| 24 | + console.log("Deploying to chainId %s with deployer %s", chainId, deployer); |
| 25 | + |
| 26 | + if (!wrappedPNKByChain.get(chainId)) { |
| 27 | + const wPnk = await deploy("WrappedPinakion", { |
| 28 | + from: deployer, |
| 29 | + log: true, |
| 30 | + maxFeePerGas: ONE_GWEI, |
| 31 | + maxPriorityFeePerGas: ONE_GWEI, |
| 32 | + }); |
| 33 | + |
| 34 | + wrappedPNKByChain.set(ForeignChains[ForeignChains[chainId]], wPnk.address); |
| 35 | + |
| 36 | + await deploy("WPNKFaucet", { |
| 37 | + from: deployer, |
| 38 | + contract: "Faucet", |
| 39 | + args: [wPnk.address], |
| 40 | + log: true, |
| 41 | + maxFeePerGas: ONE_GWEI, |
| 42 | + maxPriorityFeePerGas: ONE_GWEI, |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + const wPnkAddress = wrappedPNKByChain.get(ForeignChains[ForeignChains[chainId]]); |
| 47 | + const rng = ethers.constants.AddressZero; |
| 48 | + const minStakingTime = 99999999; |
| 49 | + const maxFreezingTime = 0; |
| 50 | + const minStake = parseEther("9999999"); |
| 51 | + const alpha = 10000; |
| 52 | + const feeForJuror = 0; |
| 53 | + const jurorsForCourtJump = 9999999; |
| 54 | + const sortitionSumTreeK = 3; |
| 55 | + const foreignGateway = await deployments.get("ForeignGatewayOnGnosis"); |
| 56 | + const weth = await deployments.get("WETH"); |
| 57 | + |
| 58 | + console.log( |
| 59 | + "Using: \nwPNK at %s, \nForeignGateway at %s, \nWETH at %s", |
| 60 | + wPnkAddress, |
| 61 | + foreignGateway.address, |
| 62 | + weth.address |
| 63 | + ); |
65 | 64 |
|
66 | | - const wPnk = await deploy("WrappedPinakion", { |
| 65 | + const sortitionSumTreeLibrary = await deploy("SortitionSumTreeFactory", { |
67 | 66 | from: deployer, |
68 | 67 | log: true, |
| 68 | + maxFeePerGas: ONE_GWEI, |
| 69 | + maxPriorityFeePerGas: ONE_GWEI, |
69 | 70 | }); |
70 | 71 |
|
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 xKlerosLiquidV2 = await deploy("xKlerosLiquidV2", { |
| 72 | + await deploy("xKlerosLiquidV2", { |
82 | 73 | from: deployer, |
83 | 74 | log: true, |
| 75 | + libraries: { |
| 76 | + SortitionSumTreeFactory: sortitionSumTreeLibrary.address, |
| 77 | + }, |
| 78 | + maxFeePerGas: ONE_GWEI, |
| 79 | + maxPriorityFeePerGas: ONE_GWEI, |
84 | 80 | }); |
85 | 81 |
|
86 | 82 | await execute( |
87 | 83 | "xKlerosLiquidV2", |
88 | | - { from: deployer, log: true }, |
| 84 | + { |
| 85 | + from: deployer, |
| 86 | + log: true, |
| 87 | + maxFeePerGas: ONE_GWEI, |
| 88 | + maxPriorityFeePerGas: ONE_GWEI, |
| 89 | + }, |
89 | 90 | "initialize", |
90 | 91 | deployer, |
91 | | - wPnk, |
92 | | - rnGenerator, |
93 | | - 99999999, |
94 | | - 0, |
| 92 | + wPnkAddress, |
| 93 | + rng, |
| 94 | + minStakingTime, |
| 95 | + maxFreezingTime, |
95 | 96 | false, |
96 | | - [999999999, 0, 0, 9999999], |
97 | | - [] |
| 97 | + [minStake, alpha, feeForJuror, jurorsForCourtJump], // minStake, alpha, feeForJuror, jurorsForCourtJump |
| 98 | + [0, 0, 0, 0], // evidencePeriod, commitPeriod, votePeriod, appealPeriod |
| 99 | + sortitionSumTreeK, |
| 100 | + foreignGateway.address, |
| 101 | + weth.address |
98 | 102 | ); |
99 | 103 |
|
100 | | - const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`; |
101 | | - |
| 104 | + const metaEvidenceUri = "INIT ME"; |
102 | 105 | await deploy("ArbitrableExample", { |
103 | 106 | from: deployer, |
104 | 107 | args: [foreignGateway.address, metaEvidenceUri], |
105 | 108 | log: true, |
| 109 | + maxFeePerGas: ONE_GWEI, |
| 110 | + maxPriorityFeePerGas: ONE_GWEI, |
106 | 111 | }); |
107 | 112 | }; |
108 | 113 |
|
| 114 | +// TODO: mock deployment on the hardhat network |
| 115 | +// const xPinakionByChain = new Map<ForeignChains, string>([ |
| 116 | +// [ForeignChains.GNOSIS_MAINNET, "0x37b60f4E9A31A64cCc0024dce7D0fD07eAA0F7B3"], |
| 117 | +// [ForeignChains.GNOSIS_CHIADO, "0x00"], |
| 118 | +// ]); |
| 119 | +// const tokenBridgeByChain = new Map<ForeignChains, string>([ |
| 120 | +// [ForeignChains.GNOSIS_MAINNET, "0xf6A78083ca3e2a662D6dd1703c939c8aCE2e268d"], |
| 121 | +// [ForeignChains.GNOSIS_CHIADO, "0xbb3c86f9918C3C1d83668fA84e79E876d147fFf2"], |
| 122 | +// ]); |
| 123 | +// const hardhatDeployer = () => { |
| 124 | +// // TODO: deploy mocks for xPinakion and tokenBridge for Hardhat network |
| 125 | +// const wEth = await deployments.get("WETH"); |
| 126 | +// const wEth = wethByChain[chainId]; |
| 127 | +// // const xPnk = await deployments.get("WPNK"); |
| 128 | +// const xPnk = xPinakionByChain[chainId]; |
| 129 | +// const tokenBridge = tokenBridgeByChain[chainId]; |
| 130 | +// const wPnk = await deploy("WrappedPinakion", { |
| 131 | +// from: deployer, |
| 132 | +// log: true, |
| 133 | +// }); |
| 134 | + |
| 135 | +// await execute( |
| 136 | +// "WrappedPinakion", |
| 137 | +// { from: deployer, log: true }, |
| 138 | +// "initialize", |
| 139 | +// "Staking PNK on xDai", |
| 140 | +// "stPNK", |
| 141 | +// xPnk, |
| 142 | +// tokenBridge |
| 143 | +// ); |
| 144 | +// }; |
| 145 | + |
109 | 146 | deployKlerosLiquid.tags = ["KlerosLiquidOnGnosis"]; |
110 | 147 | deployKlerosLiquid.skip = async ({ getChainId }) => { |
111 | 148 | const chainId = Number(await getChainId()); |
|
0 commit comments