11import { HardhatRuntimeEnvironment } from "hardhat/types" ;
22import { BigNumber } from "ethers" ;
33import { DeployFunction } from "hardhat-deploy/types" ;
4- import { SortitionModule , VRFSubscriptionManagerV2Mock } from "../typechain-types" ;
4+ import { SortitionModule , VRFSubscriptionManagerV2Mock , VRFSubscriptionManagerV2 } from "../typechain-types" ;
55import { HomeChains , isSkipped } from "./utils" ;
66import { deployUpgradable } from "./utils/deployUpgradable" ;
77
@@ -10,22 +10,26 @@ const pnkByChain = new Map<HomeChains, string>([
1010 [ HomeChains . ARBITRUM_GOERLI , "0x3483FA1b87792cd5BE4100822C4eCEC8D3E531ee" ] ,
1111] ) ;
1212
13+ // https://randomizer.ai/docs#addresses
1314const randomizerByChain = new Map < HomeChains , string > ( [
1415 [ HomeChains . ARBITRUM_ONE , "0x5b8bB80f2d72D0C85caB8fB169e8170A05C94bAF" ] ,
1516 [ HomeChains . ARBITRUM_GOERLI , "0x923096Da90a3b60eb7E12723fA2E1547BA9236Bc" ] ,
1617] ) ;
1718
19+ // https://docs.chain.link/resources/link-token-contracts?parent=vrf#arbitrum
1820const linkByChain = new Map < HomeChains , string > ( [
1921 [ HomeChains . ARBITRUM_ONE , "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4" ] ,
2022 [ HomeChains . ARBITRUM_GOERLI , "0xd14838A68E8AFBAdE5efb411d5871ea0011AFd28" ] ,
2123] ) ;
2224
25+ // https://docs.chain.link/vrf/v2/subscription/supported-networks#arbitrum-mainnet
2326const keyHashByChain = new Map < HomeChains , string > ( [
2427 [ HomeChains . ARBITRUM_ONE , "0x72d2b016bb5b62912afea355ebf33b91319f828738b111b723b78696b9847b63" ] , // 30 gwei key Hash
2528 [ HomeChains . ARBITRUM_GOERLI , "0x83d1b6e3388bed3d76426974512bb0d270e9542a765cd667242ea26c0cc0b730" ] ,
26- [ HomeChains . HARDHAT , "0x83d1b6e3388bed3d76426974512bb0d270e9542a765cd667242ea26c0cc0b730 " ] ,
29+ [ HomeChains . HARDHAT , "0x0000000000000000000000000000000000000000000000000000000000000000 " ] ,
2730] ) ;
2831
32+ // https://docs.chain.link/vrf/v2/subscription/supported-networks#arbitrum-mainnet
2933const vrfCoordinatorByChain = new Map < HomeChains , string > ( [
3034 [ HomeChains . ARBITRUM_ONE , "0x41034678D6C633D8a95c75e1138A360a28bA15d1" ] ,
3135 [ HomeChains . ARBITRUM_GOERLI , "0x6D80646bEAdd07cE68cab36c27c626790bBcf17f" ] ,
@@ -85,13 +89,14 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
8589 const sortitionModule = ( await hre . ethers . getContract ( "SortitionModule" ) ) as SortitionModule ;
8690 await sortitionModule . changeRandomNumberGenerator ( rng . address , RNG_LOOKAHEAD ) ;
8791
88- const link = linkByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
92+ const link = linkByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ; // LINK not needed on hardhat local node
8993 const keyHash = keyHashByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
90- const requestConfirmations = 3 ;
91- const callbackGasLimit = 100000 ;
94+ const requestConfirmations = 3 ; // Paramater to be fixed, range [1 ; 200] on Arbitrum
95+ const callbackGasLimit = 100000 ; // Parameter to be fixed, 50000 on RandomizerRNG but no external call to sortitionModule.passPhase() in the callback
9296 const numWords = 1 ;
9397 const vrfCoordinator = vrfCoordinatorByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
94- const vrfSubscriptionManagerDeploy = vrfCoordinator
98+ // Deploy the VRF Subscription Manager contract on Arbitrum, a mock contract on Hardhat node or nothing on other networks.
99+ const vrfSubscriptionManager = vrfCoordinator
95100 ? chainId === HomeChains . HARDHAT
96101 ? await deploy ( "VRFSubscriptionManagerV2Mock" , {
97102 from : deployer ,
@@ -105,31 +110,51 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
105110 } )
106111 : AddressZero ;
107112
108- if ( vrfSubscriptionManagerDeploy ) {
113+ // Execute the setup transactions for using VRF and deploy the Consumer contract on Hardhat node
114+ // The Sortition Module rng source is not changed to the VRF Consumer.
115+ if ( vrfSubscriptionManager ) {
109116 if ( chainId === HomeChains . HARDHAT ) {
110- const vrfSubscriptionManager = ( await hre . ethers . getContract (
117+ const vrfSubscriptionManagerContract = ( await hre . ethers . getContract (
111118 "VRFSubscriptionManagerV2Mock"
112119 ) ) as VRFSubscriptionManagerV2Mock ;
113- await vrfSubscriptionManager . createNewSubscription ( ) ;
114- await vrfSubscriptionManager . topUpSubscription ( BigNumber . from ( 10 ) . pow ( 20 ) ) ; // 100 LINK
115- const subId = await vrfSubscriptionManager . subscriptionId ( ) ;
120+ await vrfSubscriptionManagerContract . topUpSubscription ( BigNumber . from ( 10 ) . pow ( 20 ) ) ; // 100 LINK
121+ const subscriptionId = await vrfSubscriptionManagerContract . subscriptionId ( ) ;
116122 const vrfConsumer = await deploy ( "VRFConsumerV2" , {
117123 from : deployer ,
118124 args : [
119125 deployer ,
120126 vrfCoordinator ,
121127 sortitionModule . address ,
122128 keyHash ,
123- subId ,
129+ subscriptionId ,
124130 requestConfirmations ,
125131 callbackGasLimit ,
126132 numWords ,
127133 ] ,
128134 log : true ,
129135 } ) ;
130- await vrfSubscriptionManager . addConsumer ( vrfConsumer . address ) ;
131- await sortitionModule . changeRandomNumberGenerator ( vrfConsumer . address , RNG_LOOKAHEAD ) ;
136+ await vrfSubscriptionManagerContract . addConsumer ( vrfConsumer . address ) ;
132137 }
138+ } else {
139+ const vrfSubscriptionManagerContract = ( await hre . ethers . getContract (
140+ "VRFSubscriptionManagerV2"
141+ ) ) as VRFSubscriptionManagerV2 ;
142+ const subscriptionId = await vrfSubscriptionManagerContract . subscriptionId ( ) ;
143+ const vrfConsumer = await deploy ( "VRFConsumerV2" , {
144+ from : deployer ,
145+ args : [
146+ deployer ,
147+ vrfCoordinator ,
148+ sortitionModule . address ,
149+ keyHash ,
150+ subscriptionId ,
151+ requestConfirmations ,
152+ callbackGasLimit ,
153+ numWords ,
154+ ] ,
155+ log : true ,
156+ } ) ;
157+ await vrfSubscriptionManagerContract . addConsumer ( vrfConsumer . address ) ;
133158 }
134159} ;
135160
0 commit comments