-
Notifications
You must be signed in to change notification settings - Fork 49
Chainlink RNG #1778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Chainlink RNG #1778
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
14d46fa
feat: chainlink rng, updated randomizer rng for consistency
jaybuidl 09a13de
chore: prettier plugin missing in config
jaybuidl b0fba7f
feat: chainlink vrf rng deploy script
jaybuidl 2866a7a
test: chainlink vrf testing with coordinator mock
jaybuidl 3f2baa0
chore: randomizer rng does not need to be upgradable
jaybuidl 555f04a
feat: added support for the chainlink rng in the keeper bot
jaybuidl 0e2264a
chore: deploy scripts now use the chainlink rng
jaybuidl eabb03b
chore: chainlink RNG deployed, not used by the sortition module yet
jaybuidl a5944f5
fix: workaround graphql-request ESM import in keeper-bot
jaybuidl 03749f3
fix: rng deploy script
jaybuidl 83c4367
test: added tests for concurrent requests for both chainlink and rand…
jaybuidl e317649
Merge branch 'dev' into feat/chainlink-vrf-as-rng2
jaybuidl ab392c8
Merge branch 'dev' into feat/chainlink-vrf-as-rng2
jaybuidl 9e0f05b
chore: dependencies resolutions
jaybuidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 deployRng: 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]: "0x0000000000000000000000000000000000000000000000000000000000000001", | ||
}; | ||
|
||
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}`); | ||
} | ||
jaybuidl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const ChainlinkVRFCoordinator = await getContractOrDeploy(hre, "ChainlinkVRFCoordinator", { | ||
from: deployer, | ||
contract: "ChainlinkVRFCoordinatorV2Mock", | ||
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; | ||
jaybuidl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await deploy("ChainlinkRNG", { | ||
from: deployer, | ||
args: [ | ||
deployer, | ||
deployer, // The consumer is configured as the SortitionModule later | ||
ChainlinkVRFCoordinator.target, | ||
keyHash, | ||
subscriptionId, | ||
requestConfirmations, | ||
callbackGasLimit, | ||
], | ||
log: true, | ||
}); | ||
}; | ||
|
||
deployRng.tags = ["ChainlinkRNG"]; | ||
deployRng.skip = async ({ network }) => { | ||
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); | ||
}; | ||
|
||
export default deployRng; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { HomeChains, isSkipped } from "./utils"; | ||
import { getContractOrDeploy } from "./utils/getContractOrDeploy"; | ||
|
||
const deployRng: 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); | ||
|
||
// Randomizer.ai: https://randomizer.ai/docs#addresses | ||
const randomizerOracle = await getContractOrDeploy(hre, "RandomizerOracle", { | ||
from: deployer, | ||
contract: "RandomizerMock", // The mock is deployed only on the Hardhat network | ||
args: [], | ||
log: true, | ||
}); | ||
|
||
await getContractOrDeploy(hre, "RandomizerRNG", { | ||
from: deployer, | ||
args: [deployer, deployer, randomizerOracle.target], // The consumer is configured as the SortitionModule later | ||
log: true, | ||
}); | ||
}; | ||
|
||
deployRng.tags = ["RandomizerRNG"]; | ||
deployRng.skip = async ({ network }) => { | ||
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]); | ||
}; | ||
|
||
export default deployRng; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.