-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeployRaffle.s.sol
65 lines (56 loc) · 3.05 KB
/
DeployRaffle.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {Script} from "forge-std/Script.sol";
import {Raffle} from "src/Raffle.sol";
import {HelperConfig} from "script/HelperConfig.s.sol";
import {CreateSubscription, FundSubscription, AddConsumer} from "script/Interactions.s.sol";
contract DeployRaffle is Script {
// Function to deploy the Raffle contract and set up VRF subscription
function run() public returns (Raffle, HelperConfig) {
// Create an instance of HelperConfig to get network-specific configurations
HelperConfig helperConfig = new HelperConfig();
// Retrieve the network configuration
HelperConfig.NetworkConfig memory config = helperConfig.getConfig();
// If the subscriptionId is zero, create and fund a new Chainlink VRF subscription
if (config.subscriptionId == 0) {
// Create a new subscription
CreateSubscription createSubscription = new CreateSubscription();
// Create the subscription and retrieve the subscriptionId and vrfCoordinator address
(config.subscriptionId, config.vrfCoordinator) = createSubscription
.createSubscription(config.vrfCoordinator, config.account);
// Fund the newly created subscription
FundSubscription fundSubscription = new FundSubscription();
fundSubscription.fundSubscription(
config.vrfCoordinator, // Address of the VRF Coordinator
config.subscriptionId, // The subscription ID
config.link, // Amount of LINK to fund the subscription with
config.account // The account that will fund the subscription
);
}
// Start broadcasting transactions from the specified account
vm.startBroadcast(config.account);
// Deploy the Raffle contract with the retrieved configurations
Raffle raffle = new Raffle(
config.entranceFee, // The entrance fee for the raffle
config.interval, // The duration of the raffle
config.vrfCoordinator, // The VRF Coordinator address
config.gasLane, // The key hash for the VRF
config.subscriptionId, // The subscription ID for VRF
config.callbackGasLimit // The gas limit for the VRF callback
);
// Stop broadcasting transactions
vm.stopBroadcast();
// Add the Raffle contract as a consumer of the VRF subscription
AddConsumer addConsumer = new AddConsumer();
// Call the addConsumer function to register the Raffle contract with the subscription
// Broadcasting is handled within the addConsumer function
addConsumer.addConsumer(
address(raffle), // The address of the Raffle contract
config.vrfCoordinator, // The VRF Coordinator address
config.subscriptionId, // The subscription ID
config.account // The account that owns the subscription
);
// Return the deployed Raffle contract and the helper configuration
return (raffle, helperConfig);
}
}