|
| 1 | +import { HardhatRuntimeEnvironment } from "hardhat/types"; |
| 2 | +import { DeployFunction } from "hardhat-deploy/types"; |
| 3 | +import { HomeChains, isSkipped } from "./utils"; |
| 4 | +import { getContractOrDeploy } from "./utils/getContractOrDeploy"; |
| 5 | + |
| 6 | +const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { |
| 7 | + const { deployments, getNamedAccounts, getChainId } = hre; |
| 8 | + const { deploy } = deployments; |
| 9 | + |
| 10 | + // fallback to hardhat node signers on local network |
| 11 | + const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address; |
| 12 | + const chainId = Number(await getChainId()) as unknown as HomeChains; // Checked at runtime by skip() |
| 13 | + console.log("deploying to %s with deployer %s", HomeChains[chainId], deployer); |
| 14 | + |
| 15 | + const KEY_HASHES = { |
| 16 | + // https://docs.chain.link/vrf/v2-5/supported-networks#arbitrum-mainnet |
| 17 | + [HomeChains.ARBITRUM_ONE]: { |
| 18 | + 2: "0x9e9e46732b32662b9adc6f3abdf6c5e926a666d174a4d6b8e39c4cca76a38897", |
| 19 | + 30: "0x8472ba59cf7134dfe321f4d61a430c4857e8b19cdd5230b09952a92671c24409", |
| 20 | + 150: "0xe9f223d7d83ec85c4f78042a4845af3a1c8df7757b4997b815ce4b8d07aca68c", |
| 21 | + }, |
| 22 | + // https://docs.chain.link/vrf/v2-5/supported-networks#arbitrum-sepolia-testnet |
| 23 | + [HomeChains.ARBITRUM_SEPOLIA]: { |
| 24 | + 150: "0x1770bdc7eec7771f7ba4ffd640f34260d7f095b79c92d34a5b2551d6f6cfd2be", |
| 25 | + }, |
| 26 | + [HomeChains.HARDHAT]: { |
| 27 | + 0: "0x0000000000000000000000000000000000000000000000000000000000000000", |
| 28 | + }, |
| 29 | + }; |
| 30 | + |
| 31 | + const SUBSCRIPTION_ID = { |
| 32 | + [HomeChains.ARBITRUM_ONE]: "66240499937595191069677958665918759554657443303079118766000192000140992834352", |
| 33 | + [HomeChains.ARBITRUM_SEPOLIA]: "38502597312983100069991953687934627561654236680431968938019951490339399569548", |
| 34 | + [HomeChains.HARDHAT]: "0x0000000000000000000000000000000000000000000000000000000000000000", |
| 35 | + }; |
| 36 | + |
| 37 | + function getKeyHash({ gasPrice }: { gasPrice: keyof (typeof KEY_HASHES)[HomeChains.ARBITRUM_ONE] }): string { |
| 38 | + if (chainId == HomeChains.HARDHAT) return KEY_HASHES[chainId][0]; |
| 39 | + if (chainId == HomeChains.ARBITRUM_ONE) return KEY_HASHES[chainId][gasPrice]; |
| 40 | + if (chainId == HomeChains.ARBITRUM_SEPOLIA) return KEY_HASHES[chainId][150]; |
| 41 | + throw new Error(`Unknown chainId ${chainId}`); |
| 42 | + } |
| 43 | + |
| 44 | + const ChainlinkVRFCoordinator = await getContractOrDeploy(hre, "ChainlinkVRFCoordinator", { |
| 45 | + from: deployer, |
| 46 | + contract: "ChainlinkVRFCoordinator", |
| 47 | + args: [], |
| 48 | + log: true, |
| 49 | + }); |
| 50 | + |
| 51 | + const keyHash = getKeyHash({ gasPrice: 150 }); |
| 52 | + const subscriptionId = SUBSCRIPTION_ID[chainId]; |
| 53 | + const requestConfirmations = 200; // between 1 and 200 L2 blocks |
| 54 | + const callbackGasLimit = 100000; |
| 55 | + |
| 56 | + await deploy("ChainlinkRNG", { |
| 57 | + from: deployer, |
| 58 | + args: [ |
| 59 | + deployer, |
| 60 | + deployer, |
| 61 | + ChainlinkVRFCoordinator.target, |
| 62 | + keyHash, |
| 63 | + subscriptionId, |
| 64 | + requestConfirmations, |
| 65 | + callbackGasLimit, |
| 66 | + ], |
| 67 | + log: true, |
| 68 | + }); |
| 69 | +}; |
| 70 | + |
| 71 | +deployArbitration.tags = ["ChainlinkRNG"]; |
| 72 | +deployArbitration.skip = async ({ network }) => { |
| 73 | + return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); |
| 74 | +}; |
| 75 | + |
| 76 | +export default deployArbitration; |
0 commit comments