|
| 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; |
0 commit comments