1
1
import { HardhatRuntimeEnvironment } from "hardhat/types" ;
2
2
import { BigNumber } from "ethers" ;
3
3
import { DeployFunction } from "hardhat-deploy/types" ;
4
- import { SortitionModule , RandomizerRNG , VRFSubscriptionManagerV2Mock } from "../typechain-types" ;
4
+ import {
5
+ SortitionModule ,
6
+ RandomizerRNG ,
7
+ VRFSubscriptionManagerV2Mock ,
8
+ VRFSubscriptionManagerV2 ,
9
+ } from "../typechain-types" ;
5
10
6
11
enum HomeChains {
7
12
ARBITRUM_ONE = 42161 ,
@@ -14,22 +19,26 @@ const pnkByChain = new Map<HomeChains, string>([
14
19
[ HomeChains . ARBITRUM_GOERLI , "0x4DEeeFD054434bf6721eF39Aa18EfB3fd0D12610" ] ,
15
20
] ) ;
16
21
22
+ // https://randomizer.ai/docs#addresses
17
23
const randomizerByChain = new Map < HomeChains , string > ( [
18
24
[ HomeChains . ARBITRUM_ONE , "0x00" ] ,
19
25
[ HomeChains . ARBITRUM_GOERLI , "0x57F7a8aA8291A04B325F3f0d2c4d03353d3Ef25f" ] ,
20
26
] ) ;
21
27
28
+ // https://docs.chain.link/resources/link-token-contracts?parent=vrf#arbitrum
22
29
const linkByChain = new Map < HomeChains , string > ( [
23
30
[ HomeChains . ARBITRUM_ONE , "0xf97f4df75117a78c1A5a0DBb814Af92458539FB4" ] ,
24
31
[ HomeChains . ARBITRUM_GOERLI , "0xd14838A68E8AFBAdE5efb411d5871ea0011AFd28" ] ,
25
32
] ) ;
26
33
34
+ // https://docs.chain.link/vrf/v2/subscription/supported-networks#arbitrum-mainnet
27
35
const keyHashByChain = new Map < HomeChains , string > ( [
28
36
[ HomeChains . ARBITRUM_ONE , "0x72d2b016bb5b62912afea355ebf33b91319f828738b111b723b78696b9847b63" ] , // 30 gwei key Hash
29
37
[ HomeChains . ARBITRUM_GOERLI , "0x83d1b6e3388bed3d76426974512bb0d270e9542a765cd667242ea26c0cc0b730" ] ,
30
- [ HomeChains . HARDHAT , "0x83d1b6e3388bed3d76426974512bb0d270e9542a765cd667242ea26c0cc0b730 " ] ,
38
+ [ HomeChains . HARDHAT , "0x0000000000000000000000000000000000000000000000000000000000000000 " ] ,
31
39
] ) ;
32
40
41
+ // https://docs.chain.link/vrf/v2/subscription/supported-networks#arbitrum-mainnet
33
42
const vrfCoordinatorByChain = new Map < HomeChains , string > ( [
34
43
[ HomeChains . ARBITRUM_ONE , "0x41034678D6C633D8a95c75e1138A360a28bA15d1" ] ,
35
44
[ HomeChains . ARBITRUM_GOERLI , "0x6D80646bEAdd07cE68cab36c27c626790bBcf17f" ] ,
@@ -88,13 +97,14 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
88
97
const sortitionModule = ( await hre . ethers . getContract ( "SortitionModule" ) ) as SortitionModule ;
89
98
await sortitionModule . changeRandomNumberGenerator ( rng . address , RNG_LOOKAHEAD ) ;
90
99
91
- const link = linkByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
100
+ const link = linkByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ; // LINK not needed on hardhat local node
92
101
const keyHash = keyHashByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
93
- const requestConfirmations = 3 ;
94
- const callbackGasLimit = 100000 ;
102
+ const requestConfirmations = 3 ; // Paramater to be fixed, range [1 ; 200] on Arbitrum
103
+ const callbackGasLimit = 100000 ; // Parameter to be fixed, 50000 on RandomizerRNG but no external call to sortitionModule.passPhase() in the callback
95
104
const numWords = 1 ;
96
105
const vrfCoordinator = vrfCoordinatorByChain . get ( Number ( await getChainId ( ) ) ) ?? AddressZero ;
97
- const vrfSubscriptionManagerDeploy = vrfCoordinator
106
+ // Deploy the VRF Subscription Manager contract on Arbitrum, a mock contract on Hardhat node or nothing on other networks.
107
+ const vrfSubscriptionManager = vrfCoordinator
98
108
? chainId === HomeChains . HARDHAT
99
109
? await deploy ( "VRFSubscriptionManagerV2Mock" , {
100
110
from : deployer ,
@@ -108,31 +118,51 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
108
118
} )
109
119
: AddressZero ;
110
120
111
- if ( vrfSubscriptionManagerDeploy ) {
121
+ // Execute the setup transactions for using VRF and deploy the Consumer contract on Hardhat node
122
+ // The Sortition Module rng source is not changed to the VRF Consumer.
123
+ if ( vrfSubscriptionManager ) {
112
124
if ( chainId === HomeChains . HARDHAT ) {
113
- const vrfSubscriptionManager = ( await hre . ethers . getContract (
125
+ const vrfSubscriptionManagerContract = ( await hre . ethers . getContract (
114
126
"VRFSubscriptionManagerV2Mock"
115
127
) ) as VRFSubscriptionManagerV2Mock ;
116
- await vrfSubscriptionManager . createNewSubscription ( ) ;
117
- await vrfSubscriptionManager . topUpSubscription ( BigNumber . from ( 10 ) . pow ( 20 ) ) ; // 100 LINK
118
- const subId = await vrfSubscriptionManager . subscriptionId ( ) ;
128
+ await vrfSubscriptionManagerContract . topUpSubscription ( BigNumber . from ( 10 ) . pow ( 20 ) ) ; // 100 LINK
129
+ const subscriptionId = await vrfSubscriptionManagerContract . subscriptionId ( ) ;
119
130
const vrfConsumer = await deploy ( "VRFConsumerV2" , {
120
131
from : deployer ,
121
132
args : [
122
133
deployer ,
123
134
vrfCoordinator ,
124
135
sortitionModule . address ,
125
136
keyHash ,
126
- subId ,
137
+ subscriptionId ,
127
138
requestConfirmations ,
128
139
callbackGasLimit ,
129
140
numWords ,
130
141
] ,
131
142
log : true ,
132
143
} ) ;
133
- await vrfSubscriptionManager . addConsumer ( vrfConsumer . address ) ;
134
- await sortitionModule . changeRandomNumberGenerator ( vrfConsumer . address , RNG_LOOKAHEAD ) ;
144
+ await vrfSubscriptionManagerContract . addConsumer ( vrfConsumer . address ) ;
135
145
}
146
+ } else {
147
+ const vrfSubscriptionManagerContract = ( await hre . ethers . getContract (
148
+ "VRFSubscriptionManagerV2"
149
+ ) ) as VRFSubscriptionManagerV2 ;
150
+ const subscriptionId = await vrfSubscriptionManagerContract . subscriptionId ( ) ;
151
+ const vrfConsumer = await deploy ( "VRFConsumerV2" , {
152
+ from : deployer ,
153
+ args : [
154
+ deployer ,
155
+ vrfCoordinator ,
156
+ sortitionModule . address ,
157
+ keyHash ,
158
+ subscriptionId ,
159
+ requestConfirmations ,
160
+ callbackGasLimit ,
161
+ numWords ,
162
+ ] ,
163
+ log : true ,
164
+ } ) ;
165
+ await vrfSubscriptionManagerContract . addConsumer ( vrfConsumer . address ) ;
136
166
}
137
167
} ;
138
168
0 commit comments