-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelperConfig.s.sol
97 lines (83 loc) · 3.34 KB
/
HelperConfig.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {Script} from "forge-std/Script.sol";
import {VRFCoordinatorV2_5Mock} from "lib/chainlink-brownie-contracts/contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2_5Mock.sol";
import {LinkToken} from "test/mocks/LinkToken.sol";
abstract contract CodeConstants {
uint256 public constant ETH_SEPOLIA_CHAIN_ID = 11155111;
uint256 public constant LOCAL_CHAIN_ID = 31337;
uint96 public MOCK_BASE_FEE = 0.01 ether;
uint96 public MOCK_GAS_PRICE_LINK = 1e9;
// LINK/ETH price
int256 public MOCK_WEI_PER_UINT_LINK = 4e15;
}
contract HelperConfig is CodeConstants, Script {
error HelperConfig__InvalidChainId();
struct NetworkConfig {
uint256 entranceFee;
uint256 interval;
address vrfCoordinator;
bytes32 gasLane;
uint256 subscriptionId;
uint32 callbackGasLimit;
address link;
address account;
}
NetworkConfig public localNetworkConfig;
mapping(uint256 chainId => NetworkConfig) public networkConfigs;
constructor() {
networkConfigs[ETH_SEPOLIA_CHAIN_ID] = getSepoliaEthConfig();
}
function getConfigByChainId(
uint256 chainID
) public returns (NetworkConfig memory) {
if (networkConfigs[chainID].vrfCoordinator != address(0)) {
return networkConfigs[chainID];
} else if (chainID == LOCAL_CHAIN_ID) {
return getOrCreateAnvilEthConfig();
} else {
revert HelperConfig__InvalidChainId();
}
}
function getConfig() public returns (NetworkConfig memory) {
return getConfigByChainId(block.chainid);
}
function getSepoliaEthConfig() public pure returns (NetworkConfig memory) {
return
NetworkConfig({
entranceFee: 0.1 ether,
interval: 28800, //8 hours, in seconds
vrfCoordinator: 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B,
gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae,
callbackGasLimit: 500000,
subscriptionId: 9163330437940327401783702480672388761100097639670764612684504579048797480184,
link: 0x779877A7B0D9E8603169DdbD7836e478b4624789,
account: 0x5965f45573848033fEd62B0E404E5b6989683697
});
}
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) {
if (localNetworkConfig.vrfCoordinator != address(0)) {
return localNetworkConfig;
}
//Deploy mocks
vm.startBroadcast();
VRFCoordinatorV2_5Mock vrfCoordinatorMock = new VRFCoordinatorV2_5Mock(
MOCK_BASE_FEE,
MOCK_GAS_PRICE_LINK,
MOCK_WEI_PER_UINT_LINK
);
LinkToken linkToken = new LinkToken(); //deploy mock link token contract locally
vm.stopBroadcast();
localNetworkConfig = NetworkConfig({
entranceFee: 0.01 ether,
interval: 30, //30 seconds
vrfCoordinator: address(vrfCoordinatorMock),
gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae,
subscriptionId: 0,
callbackGasLimit: 500000,
link: address(linkToken),
account: 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38
});
return localNetworkConfig;
}
}