-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interactions.s.sol
101 lines (91 loc) · 3.36 KB
/
Interactions.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Script,console} from "forge-std/Script.sol";
import {HelperConfig} from "./HelperConfig.s.sol";
import {VRFCoordinatorV2Mock} from "@chainlink/contracts/src/v0.8/mocks/VRFCoordinatorV2Mock.sol";
import {LinkToken} from "../test/mocks/LinkToken.sol";
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
contract CreateSubscription is Script {
function createSubscriptionUsingConfig() public returns (uint64){
HelperConfig helperConfig = new HelperConfig();
(, , address vrfCoordinator, , , , ) = helperConfig.activeNetworkConfig();
return createSubscription(vrfCoordinator);
}
function createSubscription(address vrfCoordinator)
public returns (uint64) {
console.log("Creating subscription on chainId :",block.chainid);
vm.startBroadcast();
uint64 subId = VRFCoordinatorV2Mock(vrfCoordinator).createSubscription();
vm.stopBroadcast();
console.log("Your subscription Id ", subId);
console.log("Please update subscriptionId in HelperConfig.s.sol");
return subId;
}
function run() external returns (uint64) {
return createSubscriptionUsingConfig();
}
}
contract FundSubscription is Script {
uint96 public constant FUND_AMOUNT = 3 ether;
function funcdSubscriptionUsingConfig() public {
HelperConfig helperConfig = new HelperConfig();
(, ,address vrfCoordinator, ,uint64 subId, ,address link ) = helperConfig.activeNetworkConfig();
fundSubscription(vrfCoordinator,subId,link);
}
function fundSubscription(address vrfCoordinator,uint64 subId,address link) public{
console.log("Funding subscription :",subId);
console.log("using VrfCorrdinator :", vrfCoordinator);
console.log("ON-cahinid:", block.chainid);
if(block.chainid == 31337){
vm.startBroadcast();
VRFCoordinatorV2Mock(vrfCoordinator).fundSubscription(subId,FUND_AMOUNT);
vm.stopBroadcast();
}
else{
vm.startBroadcast();
LinkToken(link).transferAndCall(vrfCoordinator,FUND_AMOUNT,abi.encode(subId));
vm.stopBroadcast();
}
}
function run() external{
funcdSubscriptionUsingConfig();
}
}
contract AddConsumer is Script {
function addConsumer(
address lottery,
address vrfCoordinator,
uint64 subId
) public {
console.log("Adding consumer contract: ", lottery);
console.log("Using vrfCoordinator: ", vrfCoordinator);
console.log("On ChainID: ", block.chainid);
vm.startBroadcast();
VRFCoordinatorV2Mock(vrfCoordinator).addConsumer(
subId,
lottery
);
vm.stopBroadcast();
}
function addConsumerUsingConfig(address lottery) public {
HelperConfig helperConfig = new HelperConfig();
(
,
,
address vrfCoordinator
,
,
uint64 subId
,
,
) = helperConfig.activeNetworkConfig();
addConsumer(lottery, vrfCoordinator, subId);
}
function run() external {
address lottery = DevOpsTools.get_most_recent_deployment(
"Lottery",
block.chainid
);
addConsumerUsingConfig(lottery);
}
}