Skip to content

Commit

Permalink
feat: chainlink vrf rng deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Dec 7, 2024
1 parent 09a13de commit b0fba7f
Show file tree
Hide file tree
Showing 6 changed files with 4,337 additions and 1 deletion.
76 changes: 76 additions & 0 deletions contracts/deploy/00-chainlink-rng.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HomeChains, isSkipped } from "./utils";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

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

const KEY_HASHES = {
// https://docs.chain.link/vrf/v2-5/supported-networks#arbitrum-mainnet
[HomeChains.ARBITRUM_ONE]: {
2: "0x9e9e46732b32662b9adc6f3abdf6c5e926a666d174a4d6b8e39c4cca76a38897",
30: "0x8472ba59cf7134dfe321f4d61a430c4857e8b19cdd5230b09952a92671c24409",
150: "0xe9f223d7d83ec85c4f78042a4845af3a1c8df7757b4997b815ce4b8d07aca68c",
},
// https://docs.chain.link/vrf/v2-5/supported-networks#arbitrum-sepolia-testnet
[HomeChains.ARBITRUM_SEPOLIA]: {
150: "0x1770bdc7eec7771f7ba4ffd640f34260d7f095b79c92d34a5b2551d6f6cfd2be",
},
[HomeChains.HARDHAT]: {
0: "0x0000000000000000000000000000000000000000000000000000000000000000",
},
};

const SUBSCRIPTION_ID = {
[HomeChains.ARBITRUM_ONE]: "66240499937595191069677958665918759554657443303079118766000192000140992834352",
[HomeChains.ARBITRUM_SEPOLIA]: "38502597312983100069991953687934627561654236680431968938019951490339399569548",
[HomeChains.HARDHAT]: "0x0000000000000000000000000000000000000000000000000000000000000000",
};

function getKeyHash({ gasPrice }: { gasPrice: keyof (typeof KEY_HASHES)[HomeChains.ARBITRUM_ONE] }): string {
if (chainId == HomeChains.HARDHAT) return KEY_HASHES[chainId][0];
if (chainId == HomeChains.ARBITRUM_ONE) return KEY_HASHES[chainId][gasPrice];
if (chainId == HomeChains.ARBITRUM_SEPOLIA) return KEY_HASHES[chainId][150];
throw new Error(`Unknown chainId ${chainId}`);
}

const ChainlinkVRFCoordinator = await getContractOrDeploy(hre, "ChainlinkVRFCoordinator", {
from: deployer,
contract: "ChainlinkVRFCoordinator",
args: [],
log: true,
});

const keyHash = getKeyHash({ gasPrice: 150 });
const subscriptionId = SUBSCRIPTION_ID[chainId];
const requestConfirmations = 200; // between 1 and 200 L2 blocks
const callbackGasLimit = 100000;

await deploy("ChainlinkRNG", {
from: deployer,
args: [
deployer,
deployer,
ChainlinkVRFCoordinator.target,
keyHash,
subscriptionId,
requestConfirmations,
callbackGasLimit,
],
log: true,
});
};

deployArbitration.tags = ["ChainlinkRNG"];
deployArbitration.skip = async ({ network }) => {
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
};

export default deployArbitration;
18 changes: 18 additions & 0 deletions contracts/deployments/arbitrum/ChainlinkVRFCoordinator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"address": "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4",
"abi": [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"stateMutability": "payable",
"type": "fallback"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
}
Loading

0 comments on commit b0fba7f

Please sign in to comment.