94 lines
3.0 KiB
Solidity
94 lines
3.0 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.19;
|
|
|
|
import {Script} from "forge-std/Script.sol";
|
|
import {VRFCoordinatorV2_5Mock} from "@chainlink/contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2_5Mock.sol";
|
|
import {LinkToken} from "test/mocks/LinkToken.sol";
|
|
|
|
abstract contract CodeConstants {
|
|
/* VRF Mock Values */
|
|
uint96 public MOCK_BASE_FEE = 0.25 ether;
|
|
uint96 public MOCK_GAS_PRICE_LINK = 1e9;
|
|
// LINK / ETH price
|
|
int256 public MOCK_WEI_PER_UINT_LINK = 4e15;
|
|
|
|
uint256 public constant ETH_SEPOLIA_CHAIN_ID = 11155111;
|
|
uint256 public constant LOCAL_CHAIN_ID = 31337;
|
|
}
|
|
|
|
contract HelperConfig is CodeConstants, Script {
|
|
error HelperConfig__InvalidChainId();
|
|
|
|
struct NetworkConfig {
|
|
uint256 entranceFee;
|
|
uint256 interval;
|
|
address vrfCoordinator;
|
|
bytes32 gasLane;
|
|
uint32 callbackGasLimit;
|
|
uint256 subscriptionId;
|
|
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) {
|
|
// get or create anvil eth config
|
|
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.01 ether, // 1e16
|
|
interval: 30, // 30 seconds
|
|
vrfCoordinator: 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B,
|
|
gasLane: 0x130dba50ad435d4ecc214aad0d5820474137bd68e7e77724144f27c3c377d3d4,
|
|
callbackGasLimit: 500000, // 500,000 gas
|
|
subscriptionId: 0,
|
|
link: 0x779877A7B0D9E8603169DdbD7836e478b4624789,
|
|
account: address(1)
|
|
});
|
|
}
|
|
|
|
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) {
|
|
// check if already set network config
|
|
if (localNetworkConfig.vrfCoordinator != address(0)) {
|
|
return localNetworkConfig;
|
|
}
|
|
|
|
// deploy mocks and such
|
|
vm.startBroadcast();
|
|
VRFCoordinatorV2_5Mock vrfCoordinatorMock = new VRFCoordinatorV2_5Mock(MOCK_BASE_FEE, MOCK_GAS_PRICE_LINK, MOCK_WEI_PER_UINT_LINK);
|
|
LinkToken linkToken = new LinkToken();
|
|
vm.stopBroadcast();
|
|
|
|
localNetworkConfig = NetworkConfig({
|
|
entranceFee: 0.01 ether, // 1e16
|
|
interval: 30, // 30 seconds
|
|
vrfCoordinator: address(vrfCoordinatorMock),
|
|
// doesn't matter
|
|
gasLane: 0x130dba50ad435d4ecc214aad0d5820474137bd68e7e77724144f27c3c377d3d4,
|
|
callbackGasLimit: 500000, // 500,000 gas
|
|
subscriptionId: 0, // might have to fix
|
|
link: address(linkToken),
|
|
account: 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38
|
|
});
|
|
return localNetworkConfig;
|
|
}
|
|
}
|