This commit is contained in:
@@ -3,7 +3,7 @@ pragma solidity ^0.8.19;
|
||||
|
||||
import {Script} from "forge-std/Script.sol";
|
||||
import {HelperConfig} from "./HelperConfig.s.sol";
|
||||
import {Raffle} from "../contracts/Raffle.sol";
|
||||
import {Raffle} from "contracts/Raffle.sol";
|
||||
import {AddConsumer, CreateSubscription, FundSubscription} from "./Interactions.s.sol";
|
||||
|
||||
contract DeployRaffle is Script {
|
||||
@@ -15,20 +15,20 @@ contract DeployRaffle is Script {
|
||||
if (config.subscriptionId == 0) {
|
||||
CreateSubscription createSubscription = new CreateSubscription();
|
||||
(config.subscriptionId, config.vrfCoordinatorV2_5) = createSubscription
|
||||
.createSubscription(config.vrfCoordinatorV2_5, config.account);
|
||||
.createSubscription(config.vrfCoordinatorV2_5, config.myAccount);
|
||||
|
||||
FundSubscription fundSubscription = new FundSubscription();
|
||||
fundSubscription.fundSubscription(
|
||||
config.vrfCoordinatorV2_5,
|
||||
config.subscriptionId,
|
||||
config.link,
|
||||
config.account
|
||||
config.myAccount
|
||||
);
|
||||
|
||||
helperConfig.setConfig(block.chainid, config);
|
||||
}
|
||||
|
||||
vm.startBroadcast(config.account);
|
||||
vm.startBroadcast(config.myAccount);
|
||||
Raffle raffle = new Raffle(
|
||||
config.vrfCoordinatorV2_5,
|
||||
config.subscriptionId,
|
||||
@@ -44,7 +44,7 @@ contract DeployRaffle is Script {
|
||||
address(raffle),
|
||||
config.vrfCoordinatorV2_5,
|
||||
config.subscriptionId,
|
||||
config.account
|
||||
config.myAccount
|
||||
);
|
||||
return (raffle, helperConfig);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import {LinkToken} from "../test/mocks/LinkToken.sol";
|
||||
import {Script, console2} 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 MOCK_BASE_FEE = 0.25 ether;
|
||||
@@ -35,7 +35,7 @@ contract HelperConfig is CodeConstants, Script {
|
||||
uint32 callbackGasLimit;
|
||||
address vrfCoordinatorV2_5;
|
||||
address link;
|
||||
address account;
|
||||
address myAccount;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////
|
||||
@@ -81,20 +81,21 @@ contract HelperConfig is CodeConstants, Script {
|
||||
callbackGasLimit: 500000, // 500,000 gas
|
||||
vrfCoordinatorV2_5: 0x271682DEB8C4E0901D1a1550aD2e64D568E69909,
|
||||
link: 0x514910771AF9Ca656af840dff83E8264EcF986CA,
|
||||
account: 0x643315C9Be056cDEA171F4e7b2222a4ddaB9F88D
|
||||
myAccount: 0x643315C9Be056cDEA171F4e7b2222a4ddaB9F88D
|
||||
});
|
||||
}
|
||||
|
||||
function getSepoliaEthConfig() public pure returns (NetworkConfig memory sepoliaNetworkConfig) {
|
||||
sepoliaNetworkConfig = NetworkConfig({
|
||||
subscriptionId: 0, // If left as 0, our scripts will create one!
|
||||
// If left as 0, our scripts will create one!
|
||||
subscriptionId: 54852953177758767717007928774683925681326589777506065303357242036079980899870,
|
||||
gasLane: 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae,
|
||||
automationUpdateInterval: 30, // 30 seconds
|
||||
raffleEntranceFee: 0.01 ether,
|
||||
raffleEntranceFee: 0.01 ether, // 1e16
|
||||
callbackGasLimit: 500000, // 500,000 gas
|
||||
vrfCoordinatorV2_5: 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B,
|
||||
link: 0x779877A7B0D9E8603169DdbD7836e478b4624789,
|
||||
account: 0x643315C9Be056cDEA171F4e7b2222a4ddaB9F88D
|
||||
link: 0x779877A7B0D9E8603169DdbD7836e478b4624789, // This is fixed LINK token address
|
||||
myAccount: 0xc9445E993dAeA4bA3F1FE1080F0F6f8c46b4d967 // my address with supplied private key
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,6 +113,7 @@ contract HelperConfig is CodeConstants, Script {
|
||||
MOCK_GAS_PRICE_LINK,
|
||||
MOCK_WEI_PER_UINT_LINK
|
||||
);
|
||||
|
||||
LinkToken link = new LinkToken();
|
||||
uint256 subscriptionId = vrfCoordinatorV2_5Mock.createSubscription();
|
||||
vm.stopBroadcast();
|
||||
@@ -124,9 +126,9 @@ contract HelperConfig is CodeConstants, Script {
|
||||
callbackGasLimit: 500000, // 500,000 gas
|
||||
vrfCoordinatorV2_5: address(vrfCoordinatorV2_5Mock),
|
||||
link: address(link),
|
||||
account: FOUNDRY_DEFAULT_SENDER
|
||||
myAccount: FOUNDRY_DEFAULT_SENDER
|
||||
});
|
||||
vm.deal(localNetworkConfig.account, 100 ether);
|
||||
vm.deal(localNetworkConfig.myAccount, 100 ether);
|
||||
return localNetworkConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@ contract CreateSubscription is Script {
|
||||
address vrfCoordinatorV2_5 = helperConfig
|
||||
.getConfigByChainId(block.chainid)
|
||||
.vrfCoordinatorV2_5;
|
||||
address account = helperConfig.getConfigByChainId(block.chainid).account;
|
||||
return createSubscription(vrfCoordinatorV2_5, account);
|
||||
address myAccount = helperConfig.getConfigByChainId(block.chainid).myAccount;
|
||||
return createSubscription(vrfCoordinatorV2_5, myAccount);
|
||||
}
|
||||
|
||||
function createSubscription(
|
||||
address vrfCoordinatorV2_5,
|
||||
address account
|
||||
address myAccount
|
||||
) public returns (uint256, address) {
|
||||
console.log("Creating subscription on chainId: ", block.chainid);
|
||||
vm.startBroadcast(account);
|
||||
vm.startBroadcast(myAccount);
|
||||
uint256 subId = VRFCoordinatorV2_5Mock(vrfCoordinatorV2_5).createSubscription();
|
||||
vm.stopBroadcast();
|
||||
console.log("Your subscription Id is: ", subId);
|
||||
@@ -38,28 +38,89 @@ contract CreateSubscription is Script {
|
||||
}
|
||||
}
|
||||
|
||||
contract AddConsumer is Script {
|
||||
function addConsumer(
|
||||
address contractToAddToVrf,
|
||||
address vrfCoordinator,
|
||||
uint256 subId,
|
||||
address account
|
||||
) public {
|
||||
console.log("Adding consumer contract: ", contractToAddToVrf);
|
||||
console.log("Using vrfCoordinator: ", vrfCoordinator);
|
||||
console.log("On ChainID: ", block.chainid);
|
||||
vm.startBroadcast(account);
|
||||
VRFCoordinatorV2_5Mock(vrfCoordinator).addConsumer(subId, contractToAddToVrf);
|
||||
vm.stopBroadcast();
|
||||
/*
|
||||
Fund Subscription Script:
|
||||
forge script script/Interactions.s.sol:FundSubscription --rpc-url $SEPOLIA_RPC_URL --broadcast --private-key $SEPOLIA_PRIVATE_KEY
|
||||
forge script script/Interactions.s.sol:FundSubscription --rpc-url $SEPOLIA_RPC_URL --broadcast --myAccount hoelee
|
||||
*/
|
||||
contract FundSubscription is CodeConstants, Script {
|
||||
uint96 public constant FUND_AMOUNT = 0.5 ether;
|
||||
|
||||
function fundSubscriptionUsingConfig() public {
|
||||
HelperConfig helperConfig = new HelperConfig();
|
||||
uint256 subId = helperConfig.getConfig().subscriptionId;
|
||||
address vrfCoordinatorV2_5 = helperConfig.getConfig().vrfCoordinatorV2_5;
|
||||
address link = helperConfig.getConfig().link;
|
||||
address myAccount = helperConfig.getConfig().myAccount;
|
||||
|
||||
if (subId == 0) {
|
||||
CreateSubscription createSub = new CreateSubscription();
|
||||
(uint256 updatedSubId, address updatedVRFv2) = createSub.run();
|
||||
subId = updatedSubId;
|
||||
vrfCoordinatorV2_5 = updatedVRFv2;
|
||||
console.log("New SubId Created! ", subId, "VRF Address: ", vrfCoordinatorV2_5);
|
||||
}
|
||||
|
||||
fundSubscription(vrfCoordinatorV2_5, subId, link, myAccount);
|
||||
}
|
||||
|
||||
function fundSubscription(
|
||||
address vrfCoordinatorV2_5,
|
||||
uint256 subId,
|
||||
address linkToken,
|
||||
address myAccount
|
||||
) public {
|
||||
console.log("Funding subscription:", subId);
|
||||
console.log("Using vrfCoordinator:", vrfCoordinatorV2_5);
|
||||
console.log("On ChainID:", block.chainid);
|
||||
if (block.chainid == LOCAL_CHAIN_ID) {
|
||||
vm.startBroadcast(myAccount);
|
||||
VRFCoordinatorV2_5Mock(vrfCoordinatorV2_5).fundSubscription(subId, FUND_AMOUNT);
|
||||
vm.stopBroadcast();
|
||||
} else {
|
||||
console.log("Sender balance:", LinkToken(linkToken).balanceOf(msg.sender));
|
||||
console.log("Sender address:", msg.sender);
|
||||
console.log("LINK: ", linkToken);
|
||||
console.log("myAccount: ", myAccount);
|
||||
console.log("Subscription myAccount:", LinkToken(linkToken).balanceOf(address(this)));
|
||||
console.log("Subscription address", address(this));
|
||||
vm.startBroadcast(myAccount);
|
||||
LinkToken(linkToken).transferAndCall(
|
||||
vrfCoordinatorV2_5,
|
||||
FUND_AMOUNT,
|
||||
abi.encode(subId)
|
||||
);
|
||||
vm.stopBroadcast();
|
||||
}
|
||||
}
|
||||
|
||||
function run() external {
|
||||
fundSubscriptionUsingConfig();
|
||||
}
|
||||
}
|
||||
|
||||
contract AddConsumer is Script {
|
||||
function addConsumerUsingConfig(address mostRecentlyDeployed) public {
|
||||
HelperConfig helperConfig = new HelperConfig();
|
||||
uint256 subId = helperConfig.getConfig().subscriptionId;
|
||||
address vrfCoordinatorV2_5 = helperConfig.getConfig().vrfCoordinatorV2_5;
|
||||
address account = helperConfig.getConfig().account;
|
||||
address myAccount = helperConfig.getConfig().myAccount;
|
||||
|
||||
addConsumer(mostRecentlyDeployed, vrfCoordinatorV2_5, subId, account);
|
||||
addConsumer(mostRecentlyDeployed, vrfCoordinatorV2_5, subId, myAccount);
|
||||
}
|
||||
|
||||
function addConsumer(
|
||||
address contractToAddToVrf,
|
||||
address vrfCoordinator,
|
||||
uint256 subId,
|
||||
address myAccount
|
||||
) public {
|
||||
console.log("Adding consumer contract: ", contractToAddToVrf);
|
||||
console.log("Using vrfCoordinator: ", vrfCoordinator);
|
||||
console.log("On ChainID: ", block.chainid);
|
||||
vm.startBroadcast(myAccount);
|
||||
VRFCoordinatorV2_5Mock(vrfCoordinator).addConsumer(subId, contractToAddToVrf);
|
||||
vm.stopBroadcast();
|
||||
}
|
||||
|
||||
function run() external {
|
||||
@@ -70,53 +131,3 @@ contract AddConsumer is Script {
|
||||
addConsumerUsingConfig(mostRecentlyDeployed);
|
||||
}
|
||||
}
|
||||
|
||||
contract FundSubscription is CodeConstants, Script {
|
||||
uint96 public constant FUND_AMOUNT = 3 ether;
|
||||
|
||||
function fundSubscriptionUsingConfig() public {
|
||||
HelperConfig helperConfig = new HelperConfig();
|
||||
uint256 subId = helperConfig.getConfig().subscriptionId;
|
||||
address vrfCoordinatorV2_5 = helperConfig.getConfig().vrfCoordinatorV2_5;
|
||||
address link = helperConfig.getConfig().link;
|
||||
address account = helperConfig.getConfig().account;
|
||||
|
||||
if (subId == 0) {
|
||||
CreateSubscription createSub = new CreateSubscription();
|
||||
(uint256 updatedSubId, address updatedVRFv2) = createSub.run();
|
||||
subId = updatedSubId;
|
||||
vrfCoordinatorV2_5 = updatedVRFv2;
|
||||
console.log("New SubId Created! ", subId, "VRF Address: ", vrfCoordinatorV2_5);
|
||||
}
|
||||
|
||||
fundSubscription(vrfCoordinatorV2_5, subId, link, account);
|
||||
}
|
||||
|
||||
function fundSubscription(
|
||||
address vrfCoordinatorV2_5,
|
||||
uint256 subId,
|
||||
address link,
|
||||
address account
|
||||
) public {
|
||||
console.log("Funding subscription: ", subId);
|
||||
console.log("Using vrfCoordinator: ", vrfCoordinatorV2_5);
|
||||
console.log("On ChainID: ", block.chainid);
|
||||
if (block.chainid == LOCAL_CHAIN_ID) {
|
||||
vm.startBroadcast(account);
|
||||
VRFCoordinatorV2_5Mock(vrfCoordinatorV2_5).fundSubscription(subId, FUND_AMOUNT);
|
||||
vm.stopBroadcast();
|
||||
} else {
|
||||
console.log(LinkToken(link).balanceOf(msg.sender));
|
||||
console.log(msg.sender);
|
||||
console.log(LinkToken(link).balanceOf(address(this)));
|
||||
console.log(address(this));
|
||||
vm.startBroadcast(account);
|
||||
LinkToken(link).transferAndCall(vrfCoordinatorV2_5, FUND_AMOUNT, abi.encode(subId));
|
||||
vm.stopBroadcast();
|
||||
}
|
||||
}
|
||||
|
||||
function run() external {
|
||||
fundSubscriptionUsingConfig();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user