Skip to content

Commit

Permalink
✅ All test OK
Browse files Browse the repository at this point in the history
  • Loading branch information
juliapolbach committed Oct 11, 2024
1 parent 253681b commit 9e2aa2a
Show file tree
Hide file tree
Showing 15 changed files with 816 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["chainid", "Dont", "solmate", "struct", "VRFV"]
}
11 changes: 11 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
src = "src"
out = "out"
libs = ["lib"]
remappings = [
'@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/',
'@solmate=lib/solmate/src/'
]
fs_permissions = [
{ access = "read", path = "./broadcast" },
{ access = "read", path = "./reports" },
]

[fuzz]
runs = 256

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion lib/chainlink-brownie-contracts
2 changes: 1 addition & 1 deletion lib/solmate
Submodule solmate updated 73 files
+14 −0 .dapprc
+183 −568 .gas-snapshot
+2 −0 .gitattributes
+0 −13 .github/pull_request_template.md
+10 −12 .github/workflows/tests.yml
+3 −0 .gitmodules
+0 −1 .prettierignore
+2 −1 .vscode/settings.json
+7 −0 Makefile
+9 −21 README.md
+0 −7 foundry.toml
+1 −1 lib/ds-test
+1 −0 lib/weird-erc20
+2 −2 package-lock.json
+4 −4 package.json
+15 −0 shell.nix
+7 −7 src/auth/Auth.sol
+0 −44 src/auth/Owned.sol
+15 −15 src/auth/authorities/MultiRolesAuthority.sol
+11 −11 src/auth/authorities/RolesAuthority.sol
+39 −41 src/test/Auth.t.sol
+1 −1 src/test/Bytes32AddressLib.t.sol
+2 −27 src/test/CREATE3.t.sol
+7 −31 src/test/DSTestPlus.t.sol
+159 −159 src/test/ERC1155.t.sol
+58 −72 src/test/ERC20.t.sol
+0 −446 src/test/ERC4626.t.sol
+0 −378 src/test/ERC6909.t.sol
+138 −117 src/test/ERC721.t.sol
+54 −283 src/test/FixedPointMathLib.t.sol
+0 −148 src/test/LibString.t.sol
+0 −50 src/test/MerkleProofLib.t.sol
+1 −1 src/test/MultiRolesAuthority.t.sol
+0 −40 src/test/Owned.t.sol
+3 −3 src/test/ReentrancyGuard.t.sol
+1 −1 src/test/RolesAuthority.t.sol
+13 −41 src/test/SSTORE2.t.sol
+6 −537 src/test/SafeCastLib.t.sol
+89 −401 src/test/SafeTransferLib.t.sol
+0 −74 src/test/SignedWadMath.t.sol
+5 −5 src/test/WETH.t.sol
+24 −57 src/test/utils/DSTestPlus.sol
+2 −81 src/test/utils/Hevm.sol
+0 −28 src/test/utils/mocks/MockERC4626.sol
+0 −22 src/test/utils/mocks/MockERC6909.sol
+0 −12 src/test/utils/mocks/MockOwned.sol
+56 −0 src/test/utils/users/ERC1155User.sol
+40 −0 src/test/utils/users/ERC20User.sol
+54 −0 src/test/utils/users/ERC721User.sol
+24 −0 src/test/utils/users/GenericUser.sol
+0 −83 src/test/utils/weird-tokens/MissingReturnToken.sol
+0 −61 src/test/utils/weird-tokens/ReturnsFalseToken.sol
+0 −115 src/test/utils/weird-tokens/ReturnsGarbageToken.sol
+0 −70 src/test/utils/weird-tokens/ReturnsTooLittleToken.sol
+0 −98 src/test/utils/weird-tokens/ReturnsTooMuchToken.sol
+0 −61 src/test/utils/weird-tokens/ReturnsTwoToken.sol
+0 −61 src/test/utils/weird-tokens/RevertingToken.sol
+48 −52 src/tokens/ERC1155.sol
+26 −37 src/tokens/ERC20.sol
+0 −183 src/tokens/ERC4626.sol
+0 −118 src/tokens/ERC6909.sol
+45 −56 src/tokens/ERC721.sol
+1 −1 src/tokens/WETH.sol
+1 −1 src/utils/Bytes32AddressLib.sol
+2 −7 src/utils/CREATE3.sol
+68 −117 src/utils/FixedPointMathLib.sol
+0 −77 src/utils/LibString.sol
+0 −48 src/utils/MerkleProofLib.sol
+6 −6 src/utils/ReentrancyGuard.sol
+5 −7 src/utils/SSTORE2.sol
+6 −162 src/utils/SafeCastLib.sol
+77 −65 src/utils/SafeTransferLib.sol
+0 −245 src/utils/SignedWadMath.sol
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

58 changes: 58 additions & 0 deletions script/DeployRaffle.s.sol
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);
}
}
95 changes: 95 additions & 0 deletions script/HelperConfig.s.sol
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;
}
}
123 changes: 123 additions & 0 deletions script/Interactions.s.sol
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);
}
}
14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

Loading

0 comments on commit 9e2aa2a

Please sign in to comment.