-
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
juliapolbach
committed
Oct 11, 2024
1 parent
253681b
commit 9e2aa2a
Showing
15 changed files
with
816 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"cSpell.words": ["chainid", "Dont", "solmate", "struct", "VRFV"] | ||
} |
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
Submodule chainlink-brownie-contracts
updated
190 files
Submodule forge-std
updated
12 files
+1 −1 | package.json | |
+1 −10 | src/StdChains.sol | |
+0 −9 | src/StdInvariant.sol | |
+1 −1 | src/StdStorage.sol | |
+58 −188 | src/Vm.sol | |
+382 −401 | src/console.sol | |
+1,555 −1 | src/console2.sol | |
+5 −1 | src/mocks/MockERC721.sol | |
+4 −693 | src/safeconsole.sol | |
+0 −5 | test/StdChains.t.sol | |
+0 −8 | test/StdStorage.t.sol | |
+2 −2 | test/Vm.t.sol |
Submodule solmate
updated
73 files
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
// 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 "./HelperConfig.s.sol"; | ||
import {CreateSubscription, FundSubscription, AddConsumer} from "./Interactions.s.sol"; | ||
|
||
contract DeployRaffle is Script { | ||
function run() public { | ||
deployContract(); | ||
} | ||
|
||
function deployContract() public returns (Raffle, HelperConfig) { | ||
HelperConfig helperConfig = new HelperConfig(); | ||
HelperConfig.NetworkConfig memory config = helperConfig.getConfig(); | ||
|
||
// It automates de Chainlink VRF subscription creation | ||
if (config.subscriptionId == 0) { | ||
// Create Subscription | ||
CreateSubscription createSubscription = new CreateSubscription(); | ||
(config.subscriptionId, config.vrfCoordinator) = createSubscription | ||
.createSubscription(config.vrfCoordinator, config.account); | ||
|
||
// Fund Subscription | ||
FundSubscription fundSubscription = new FundSubscription(); | ||
fundSubscription.fundSubscription( | ||
config.vrfCoordinator, | ||
config.subscriptionId, | ||
config.link, | ||
config.account | ||
); | ||
} | ||
|
||
// Deploy Raffle | ||
vm.startBroadcast(config.account); | ||
Raffle raffle = new Raffle( | ||
config.entranceFee, | ||
config.interval, | ||
config.vrfCoordinator, | ||
config.gasLane, | ||
config.subscriptionId, | ||
config.callbackGasLimit | ||
); | ||
vm.stopBroadcast(); | ||
|
||
//Add Consumer | ||
AddConsumer addConsumer = new AddConsumer(); | ||
addConsumer.addConsumer( | ||
address(raffle), | ||
config.vrfCoordinator, | ||
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,95 @@ | ||
// 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 { | ||
uint96 public constant MOCK_BASE_FEE = 0.25 ether; | ||
uint96 public constant MOCK_GAS_PRICE_LINK = 1e9; | ||
int256 public constant MOCK_WEI_PER_UNIT_LINK = 1e18; | ||
uint256 public constant ETH_SEPOLIA_CHAIN_ID = 11155111; | ||
uint256 public constant LOCAL_CHAIN_ID = 31337; | ||
} | ||
|
||
contract HelperConfig is Script, CodeConstants { | ||
error HelperConfig__InvalidChainId(uint256 chainId); | ||
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 getConfig() public returns (NetworkConfig memory) { | ||
return getConfigByChainId(block.chainid); | ||
} | ||
|
||
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(chainId); | ||
} | ||
} | ||
|
||
function getSepoliaETHConfig() public pure returns (NetworkConfig memory) { | ||
return | ||
NetworkConfig({ | ||
entranceFee: 0.01 ether, | ||
interval: 30, //30 seconds | ||
vrfCoordinator: 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B, | ||
gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae, | ||
callbackGasLimit: 500000, | ||
subscriptionId: 0, | ||
link: 0x779877A7B0D9E8603169DdbD7836e478b4624789, | ||
account: 0x70004B4008B51D3D2501e93FDD0f279E31b593f0 | ||
}); | ||
} | ||
|
||
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) { | ||
// check if we set the config already | ||
if (localNetworkConfig.vrfCoordinator != address(0)) { | ||
return localNetworkConfig; | ||
} | ||
|
||
// DeployMocks | ||
vm.startBroadcast(); | ||
VRFCoordinatorV2_5Mock vrfCoordinatorMock = new VRFCoordinatorV2_5Mock( | ||
MOCK_BASE_FEE, | ||
MOCK_GAS_PRICE_LINK, | ||
MOCK_WEI_PER_UNIT_LINK | ||
); | ||
LinkToken linkToken = new LinkToken(); | ||
vm.stopBroadcast(); | ||
|
||
localNetworkConfig = NetworkConfig({ | ||
entranceFee: 0.01 ether, | ||
interval: 30, //30 seconds | ||
vrfCoordinator: address(vrfCoordinatorMock), | ||
gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae, // Mock doesn't matter | ||
callbackGasLimit: 500000, // Mock doesn't matter | ||
subscriptionId: 0, | ||
link: address(linkToken), | ||
account: 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38 | ||
}); | ||
|
||
return localNetworkConfig; | ||
} | ||
} |
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,123 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
import {Script, console} from "forge-std/Script.sol"; | ||
import {HelperConfig, CodeConstants} from "./HelperConfig.s.sol"; | ||
import {VRFCoordinatorV2_5Mock} from "@chainlink/contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2_5Mock.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 (uint256, address) { | ||
HelperConfig helperConfig = new HelperConfig(); | ||
address vrfCoordinator = helperConfig.getConfig().vrfCoordinator; | ||
address account = helperConfig.getConfig().account; | ||
(uint256 subscriptionId, ) = createSubscription( | ||
vrfCoordinator, | ||
account | ||
); | ||
return (subscriptionId, vrfCoordinator); | ||
} | ||
|
||
function createSubscription( | ||
address vrfCoordinator, | ||
address account | ||
) public returns (uint256, address) { | ||
console.log("Creating subscription on chain Id: ", block.chainid); | ||
vm.startBroadcast(account); | ||
uint256 subscriptionId = VRFCoordinatorV2_5Mock(vrfCoordinator) | ||
.createSubscription(); | ||
vm.stopBroadcast(); | ||
|
||
console.log("Your Subscription Id is: ", subscriptionId); | ||
console.log( | ||
"Please update your config with this subscription Id in HelperConfig.s.sol" | ||
); | ||
|
||
return (subscriptionId, vrfCoordinator); | ||
} | ||
|
||
function run() public { | ||
createSubscriptionUsingConfig(); | ||
} | ||
} | ||
|
||
contract FundSubscription is Script, CodeConstants { | ||
uint256 public constant FUND_AMOUNT = 3 ether; // 3 LINK | ||
|
||
function fundSubscriptionUsingConfig() public { | ||
HelperConfig helperConfig = new HelperConfig(); | ||
address vrfCoordinator = helperConfig.getConfig().vrfCoordinator; | ||
uint256 subscriptionId = helperConfig.getConfig().subscriptionId; | ||
address linkToken = helperConfig.getConfig().link; | ||
address account = helperConfig.getConfig().account; | ||
fundSubscription(vrfCoordinator, subscriptionId, linkToken, account); | ||
} | ||
|
||
function fundSubscription( | ||
address vrfCoordinator, | ||
uint256 subscriptionId, | ||
address linkToken, | ||
address account | ||
) public { | ||
console.log("Funding subscription: ", subscriptionId); | ||
console.log("Using vrfCoordinator: ", vrfCoordinator); | ||
console.log("On chainId: ", block.chainid); | ||
|
||
if (block.chainid == LOCAL_CHAIN_ID) { | ||
vm.startBroadcast(); | ||
VRFCoordinatorV2_5Mock(vrfCoordinator).fundSubscription( | ||
subscriptionId, | ||
FUND_AMOUNT * 100 | ||
); | ||
vm.stopBroadcast(); | ||
} else { | ||
vm.startBroadcast(account); | ||
LinkToken(linkToken).transferAndCall( | ||
vrfCoordinator, | ||
FUND_AMOUNT, | ||
abi.encode(subscriptionId) | ||
); | ||
vm.stopBroadcast(); | ||
} | ||
} | ||
|
||
function run() public { | ||
fundSubscriptionUsingConfig(); | ||
} | ||
} | ||
|
||
contract AddConsumer is Script { | ||
function addConsumerUsingConfig(address mostRecentlyDeployed) public { | ||
HelperConfig helperConfig = new HelperConfig(); | ||
uint256 subId = helperConfig.getConfig().subscriptionId; | ||
address vrfCoordinator = helperConfig.getConfig().vrfCoordinator; | ||
address account = helperConfig.getConfig().account; | ||
addConsumer(mostRecentlyDeployed, vrfCoordinator, subId, account); | ||
} | ||
|
||
function addConsumer( | ||
address contractToAddToVrf, | ||
address vrfCoordinator, | ||
uint256 subId, | ||
address account | ||
) public { | ||
console.log("Adding consumer contract: ", contractToAddToVrf); | ||
console.log("To vrfCoordinator: ", vrfCoordinator); | ||
console.log("On chain Id: ", block.chainid); | ||
|
||
vm.startBroadcast(account); | ||
VRFCoordinatorV2_5Mock(vrfCoordinator).addConsumer( | ||
subId, | ||
contractToAddToVrf | ||
); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function run() external { | ||
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment( | ||
"Raffle", | ||
block.chainid | ||
); | ||
addConsumerUsingConfig(mostRecentlyDeployed); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.