-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Collin Pixley
authored and
Collin Pixley
committed
Oct 19, 2024
1 parent
d0b74da
commit 40ea363
Showing
20 changed files
with
1,081 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
-include .env | ||
|
||
.PHONY: all test clean deploy fund help install snapshot format anvil | ||
|
||
DEFAULT_ANVIL_KEY := 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | ||
|
||
help: | ||
@echo "Usage:" | ||
@echo " make deploy [ARGS=...]\n example: make deploy ARGS=\"--network sepolia\"" | ||
@echo "" | ||
@echo " make fund [ARGS=...]\n example: make deploy ARGS=\"--network sepolia\"" | ||
|
||
all: clean remove install update build | ||
|
||
# Clean the repo | ||
clean :; forge clean | ||
|
||
# Remove modules | ||
remove :; rm -rf .gitmodules && rm -rf .git/modules/* && rm -rf lib && touch .gitmodules && git add . && git commit -m "modules" | ||
|
||
install :; forge install cyfrin/[email protected] --no-commit && forge install smartcontractkit/[email protected] --no-commit && forge install foundry-rs/[email protected] --no-commit && forge install transmissions11/solmate@v6 --no-commit | ||
|
||
# Update Dependencies | ||
update:; forge update | ||
|
||
build:; forge build | ||
|
||
test :; forge test | ||
|
||
snapshot :; forge snapshot | ||
|
||
format :; forge fmt | ||
|
||
anvil :; anvil -m 'test test test test test test test test test test test junk' --steps-tracing --block-time 1 | ||
|
||
make test-fork: | ||
forge test --fork-url $(SEPOLIA_RPC_URL) --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv | ||
|
||
make deploy-mainnet: | ||
forge script script/DeployRaffle.s.sol:DeployRaffle --rpc-url $(MAINNET_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv | ||
|
||
make deploy-sepolia: | ||
forge script script/DeployRaffle.s.sol:DeployRaffle --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv | ||
|
||
make deploy-anvil: | ||
forge script script/DeployRaffle.s.sol:DeployRaffle --private-key $(PRIVATE_KEY) --broadcast --verify -vvvv | ||
|
||
make create-sepolia-sub: | ||
forge script script/Interactions.s.sol:CreateSubscription --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast | ||
|
||
make add-sepolia-consumer: | ||
forge script script/Interactions.s.sol:AddConsumer --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast | ||
|
||
make fund-sepolia-subscription: | ||
forge script script/Interactions.s.sol:FundSubscription --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast | ||
|
||
make create-mainnet-sub: | ||
forge script script/Interactions.s.sol:CreateSubscription --rpc-url $(MAINNET_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast | ||
|
||
make add-mainnet-consumer: | ||
forge script script/Interactions.s.sol:AddConsumer --rpc-url $(MAINNET_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast | ||
|
||
make fund-mainnet-subscription: | ||
forge script script/Interactions.s.sol:FundSubscription --rpc-url $(MAINNET_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast | ||
|
||
make enter-sepolia-raffle: | ||
cast send 0x3282332b209D5E109475C4B4FC5ac7760d45EF0F "enterRaffle()" --value 0.01ether --private-key $(PRIVATE_KEY) --rpc-url $(SEPOLIA_RPC_URL) | ||
|
||
make enter-mainnet-raffle: | ||
cast send <Contract-Address> "enterRaffle()" --value 0.01ether --private-key $(PRIVATE_KEY) --rpc-url $(MAINNET_RPC_URL) | ||
|
||
make enter-anvil-raffle: | ||
cast send <Contract-Address> "enterRaffle()" --value 0.01ether --private-key $(PRIVATE_KEY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
out = "out" | ||
src = "src" | ||
|
||
[etherscan] | ||
mainnet = {key = "${ETHERSCAN_API_KEY}"} | ||
sepolia = {key = "${ETHERSCAN_API_KEY}"} | ||
|
||
[rpc_endpoints] | ||
sepolia = "${SEPOLIA_RPC_ENDPOINT}" | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
Binary file not shown.
Submodule chainlink
added at
505e43
Submodule chainlink-brownie-contracts
updated
from c6d0ca to b0591b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.26; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {Raffle} from "../src/Raffle.sol"; | ||
import {HelperConfig} from "../script/HelperConfig.s.sol"; | ||
import {AddConsumer, CreateSubscription, FundSubscription} from "./Interactions.s.sol"; | ||
|
||
contract DeployRaffle is Script { | ||
function run() external returns (Raffle, HelperConfig) { | ||
HelperConfig helperConfig = new HelperConfig(); // This comes with our mocks! | ||
AddConsumer addConsumer = new AddConsumer(); | ||
HelperConfig.NetworkConfig memory config = helperConfig.getConfig(); | ||
|
||
if (config.subscriptionId == 0) { | ||
CreateSubscription createSubscription = new CreateSubscription(); | ||
( | ||
config.subscriptionId, | ||
config.vrfCoordinatorV2_5 | ||
) = createSubscription.createSubscription( | ||
config.vrfCoordinatorV2_5, | ||
config.account | ||
); | ||
|
||
FundSubscription fundSubscription = new FundSubscription(); | ||
fundSubscription.fundSubscription( | ||
config.vrfCoordinatorV2_5, | ||
config.subscriptionId, | ||
config.link, | ||
config.account | ||
); | ||
|
||
helperConfig.setConfig(block.chainid, config); | ||
} | ||
|
||
vm.startBroadcast(config.account); | ||
Raffle raffle = new Raffle( | ||
config.subscriptionId, | ||
config.gasLane, | ||
config.automationUpdateInterval, | ||
config.raffleEntranceFee, | ||
config.callbackGasLimit, | ||
config.vrfCoordinatorV2_5 | ||
); | ||
vm.stopBroadcast(); | ||
|
||
addConsumer.addConsumer( | ||
address(raffle), | ||
config.vrfCoordinatorV2_5, | ||
config.subscriptionId, | ||
config.account | ||
); | ||
return (raffle, helperConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
//SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.26; | ||
|
||
import {Script, console2} from "forge-std/Script.sol"; | ||
import {VRFCoordinatorV2_5Mock} from "../lib/chainlink/contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2_5Mock.sol"; | ||
import {LinkToken} from "../test/mocks/LinkToken.sol"; | ||
|
||
abstract contract CodeConstants { | ||
uint96 public MOCK_BASE_FEE = 0.25 ether; | ||
uint96 public MOCK_GAS_PRICE_LINK = 1e9; | ||
int256 public MOCK_WEI_PER_UINT_LINK = 4e15; | ||
|
||
address public FOUNDRY_DEFAULT_SENDER = | ||
0x7132F9c2a50e40BeC4a54B3B373537239A044a16; | ||
|
||
uint256 public constant ETH_SEPOLIA_CHAIN_ID = 11155111; | ||
uint256 public constant ETH_MAINNET_CHAIN_ID = 1; | ||
uint256 public constant LOCAL_CHAIN_ID = 31337; | ||
} | ||
|
||
contract HelperConfig is CodeConstants, Script { | ||
error HelperConfig__InvalidChainId(); | ||
|
||
struct NetworkConfig { | ||
uint256 subscriptionId; | ||
bytes32 gasLane; | ||
uint256 automationUpdateInterval; | ||
uint256 raffleEntranceFee; | ||
uint32 callbackGasLimit; | ||
address vrfCoordinatorV2_5; | ||
address link; | ||
address account; | ||
} | ||
|
||
NetworkConfig public localNetworkConfig; | ||
mapping(uint256 chainId => NetworkConfig) public networkConfigs; | ||
|
||
constructor() { | ||
networkConfigs[ETH_SEPOLIA_CHAIN_ID] = getSepoliaEthConfig(); | ||
networkConfigs[ETH_MAINNET_CHAIN_ID] = getMainnetEthConfig(); | ||
} | ||
|
||
function getConfig() public returns (NetworkConfig memory) { | ||
return getConfigByChainId(block.chainid); | ||
} | ||
|
||
function setConfig( | ||
uint256 chainId, | ||
NetworkConfig memory networkConfig | ||
) public { | ||
networkConfigs[chainId] = networkConfig; | ||
} | ||
|
||
function getConfigByChainId( | ||
uint256 chainId | ||
) public returns (NetworkConfig memory) { | ||
if (networkConfigs[chainId].vrfCoordinatorV2_5 != address(0)) { | ||
return networkConfigs[chainId]; | ||
} else if (chainId == LOCAL_CHAIN_ID) { | ||
return getOrCreateAnvilEthConfig(); | ||
} else { | ||
revert HelperConfig__InvalidChainId(); | ||
} | ||
} | ||
|
||
function getMainnetEthConfig() | ||
public | ||
view | ||
returns (NetworkConfig memory mainnetNetworkConfig) | ||
{ | ||
mainnetNetworkConfig = NetworkConfig({ | ||
subscriptionId: 0, // Replace 0 with your subId from the Chainlink VRF UI here | ||
gasLane: 0x9fe0eebf5e446e3c998ec9bb19951541aee00bb90ea201ae456421a2ded86805, | ||
automationUpdateInterval: 604800, // 1 week | ||
raffleEntranceFee: 0.01 ether, | ||
callbackGasLimit: 500000, // 500,000 gas | ||
vrfCoordinatorV2_5: 0x271682DEB8C4E0901D1a1550aD2e64D568E69909, | ||
link: 0x514910771AF9Ca656af840dff83E8264EcF986CA, | ||
account: FOUNDRY_DEFAULT_SENDER | ||
}); | ||
} | ||
|
||
function getSepoliaEthConfig() | ||
public | ||
view | ||
returns (NetworkConfig memory sepoliaNetworkConfig) | ||
{ | ||
sepoliaNetworkConfig = NetworkConfig({ | ||
subscriptionId: 4244416522498249141814610753008696399081896929023878836802545309793195337341, // Replace with your subId from the Chainlink VRF UI here | ||
gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae, | ||
automationUpdateInterval: 604800, // 1 week | ||
raffleEntranceFee: 0.01 ether, | ||
callbackGasLimit: 500000, // 500,000 gas | ||
vrfCoordinatorV2_5: 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B, | ||
link: 0x779877A7B0D9E8603169DdbD7836e478b4624789, | ||
account: FOUNDRY_DEFAULT_SENDER | ||
}); | ||
} | ||
|
||
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) { | ||
if (localNetworkConfig.vrfCoordinatorV2_5 != address(0)) { | ||
return localNetworkConfig; | ||
} | ||
|
||
console2.log(unicode"⚠️ You have deployed a mock conract!"); | ||
console2.log("Make sure this was intentional"); | ||
vm.startBroadcast(); | ||
VRFCoordinatorV2_5Mock vrfCoordinatorV2_5Mock = new VRFCoordinatorV2_5Mock( | ||
MOCK_BASE_FEE, | ||
MOCK_GAS_PRICE_LINK, | ||
MOCK_WEI_PER_UINT_LINK | ||
); | ||
LinkToken link = new LinkToken(); | ||
uint256 subscriptionId = vrfCoordinatorV2_5Mock.createSubscription(); | ||
vm.stopBroadcast(); | ||
|
||
localNetworkConfig = NetworkConfig({ | ||
subscriptionId: subscriptionId, | ||
gasLane: 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c, // doesn't really matter | ||
automationUpdateInterval: 30, // 30 seconds | ||
raffleEntranceFee: 0.01 ether, | ||
callbackGasLimit: 500000, // 500,000 gas | ||
vrfCoordinatorV2_5: address(vrfCoordinatorV2_5Mock), | ||
link: address(link), | ||
account: FOUNDRY_DEFAULT_SENDER | ||
}); | ||
vm.deal(localNetworkConfig.account, 100 ether); | ||
return localNetworkConfig; | ||
} | ||
} |
Oops, something went wrong.