Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bruh122004 committed Sep 7, 2024
1 parent cf3932b commit 6f5418a
Show file tree
Hide file tree
Showing 22 changed files with 649 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FundMeTest:test_withdraw_from_multiple_funders() (gas: 461103)
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ out/
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
broadcast/

lib/
# Docs
docs/

# Dotenv file
.env
.DS_Store/
zkout/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "lib/chainlink-brownie-contracts"]
path = lib/chainlink-brownie-contracts
url = https://github.com/smartcontractkit/chainlink-brownie-contracts
[submodule "lib/foundry-devops"]
path = lib/foundry-devops
url = https://github.com/cyfrin/foundry-devops
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-include .env

.PHONY: all test clean deploy fund help install snapshot format anvil zktest

DEFAULT_ANVIL_KEY := 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
DEFAULT_ZKSYNC_LOCAL_KEY := 0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110

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

# Update Dependencies
update:; forge update

build:; forge build

zkbuild :; forge build --zksync

test :; forge test

zktest :; foundryup-zksync && forge test --zksync && foundryup

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

zk-anvil :; npx zksync-cli dev start

deploy:
@forge script script/DeployFundMe.S.sol:DeployFundMe $(NETWORK_ARGS)

NETWORK_ARGS := --rpc-url http://localhost:8545 --private-key $(DEFAULT_ANVIL_KEY) --broadcast

ifeq ($(findstring --network sepolia,$(ARGS)),--network sepolia)
NETWORK_ARGS := --rpc-url $(SEPOLIA_RPC_URL) --account $(ACCOUNT) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv
endif

deploy-sepolia:
@forge script script/DeployFundMe.s.sol:DeployFundMe $(NETWORK_ARGS)

# As of writing, the Alchemy zkSync RPC URL is not working correctly
deploy-zk:
forge create src/FundMe.sol:FundMe --rpc-url http://127.0.0.1:8011 --private-key $(DEFAULT_ZKSYNC_LOCAL_KEY) --constructor-args $(shell forge create test/mock/MockV3Aggregator.sol:MockV3Aggregator --rpc-url http://127.0.0.1:8011 --private-key $(DEFAULT_ZKSYNC_LOCAL_KEY) --constructor-args 8 200000000000 --legacy --zksync | grep "Deployed to:" | awk '{print $$3}') --legacy --zksync

deploy-zk-sepolia:
forge create src/FundMe.sol:FundMe --rpc-url ${ZKSYNC_SEPOLIA_RPC_URL} --account default --constructor-args 0xfEefF7c3fB57d18C5C6Cdd71e45D2D0b4F9377bF --legacy --zksync


# For deploying Interactions.s.sol:FundFundMe as well as for Interactions.s.sol:WithdrawFundMe we have to include a sender's address `--sender <ADDRESS>`
SENDER_ADDRESS := <sender's address>

fund:
@forge script script/Interactions.s.sol:FundFundMe --sender $(SENDER_ADDRESS) $(NETWORK_ARGS)

withdraw:
@forge script script/Interactions.s.sol:WithdrawFundMe --sender $(SENDER_ADDRESS) $(NETWORK_ARGS)
6 changes: 5 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
src = "src"
out = "out"
libs = ["lib"]

remappings = ["@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/"]
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
fs_permissions = [
{ access = "read", path = "./broadcast" },
{ access = "read", path = "./reports" },
]
1 change: 1 addition & 0 deletions lib/chainlink-brownie-contracts
1 change: 1 addition & 0 deletions lib/foundry-devops
Submodule foundry-devops added at df9f90
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

19 changes: 19 additions & 0 deletions script/DeployFundMe.S.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {FundMe} from "../src/FundMe.sol";
import {HelperConfig} from "./HelperConfig.s.sol";

contract DeployFundMe is Script{
function run() external returns (FundMe) {

HelperConfig helperconfiginterface = new HelperConfig();
address ethUsdPricfeed = helperconfiginterface.activeNetworkconfig();
vm.startBroadcast();
FundMe fundMe = new FundMe(ethUsdPricfeed);
vm.stopBroadcast();
return fundMe;
}

}
49 changes: 49 additions & 0 deletions script/DeployStorageFun.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Script, console} from "forge-std/Script.sol";
import {FunWithStorage} from "../src/exampleContracts/FunWithStorage.sol";

contract DeployFunWithStorage is Script {
function run() external returns (FunWithStorage) {
vm.startBroadcast();
FunWithStorage funWithStorage = new FunWithStorage();
vm.stopBroadcast();
printStorageData(address(funWithStorage));
printFirstArrayElement(address(funWithStorage));
return (funWithStorage);
}

function printStorageData(address contractAddress) public view {
for (uint256 i = 0; i < 10; i++) {
bytes32 value = vm.load(contractAddress, bytes32(i));
console.log("Vaule at location", i, ":");
console.logBytes32(value);
}
}

function printFirstArrayElement(address contractAddress) public view {
bytes32 arrayStorageSlotLength = bytes32(uint256(2));
bytes32 firstElementStorageSlot = keccak256(abi.encode(arrayStorageSlotLength));
bytes32 value = vm.load(contractAddress, firstElementStorageSlot);
console.log("First element in array:");
console.logBytes32(value);
}

// Option 1
/*
* cast storage ADDRESS
*/

// Option 2
// cast k 0x0000000000000000000000000000000000000000000000000000000000000002
// cast storage ADDRESS <OUTPUT_OF_ABOVE>

// Option 3:
/*
* curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["0xe98bc0fd715a075b83acbbfd72b4df8bb62633daf1768e9823896bfae4758906"],"id":1}' http://127.0.0.1:8545 > debug_tx.json
* Go through the JSON and find the storage slot you want
*/

// You could also replay every transaction and track the `SSTORE` opcodes... but that's a lot of work
}
50 changes: 50 additions & 0 deletions script/HelperConfig.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE

//1.Deploy mocks when we are on a local anvil chain
//2.keep track of contract address across different chains
//Sepolia ETH/USD
//Mainnet ETH/USD
pragma solidity ^0.8.18;
//next import allows access to the vm
import {Script} from "forge-std/Script.sol";
import {MockV3Aggregator} from "../test/mocks/MockV3Aggregator.sol";
contract HelperConfig is Script {
//If we are on a local anvil, we deploy mocks
//Otherwise, grab the existing address from the live network
NetworkConfig public activeNetworkconfig;
uint8 public constant DECIMALS = 8;
int256 public constant INITIAL_UNIT_PRICE=2000e8;
uint256 public constant SEPOLIA_CHAINID = 11155111;
constructor() {
if (block.chainid == SEPOLIA_CHAINID) {
activeNetworkconfig = getSepliaEthConfig();
} else {
activeNetworkconfig = creat_AnvilEthConfig();
}
}

struct NetworkConfig {
address pricefeed;
}

function getSepliaEthConfig() public pure returns (NetworkConfig memory){
NetworkConfig memory sepoliaNetwork = NetworkConfig({pricefeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306});
return sepoliaNetwork;
}

function creat_AnvilEthConfig() public returns (NetworkConfig memory){
if (activeNetworkconfig.pricefeed != address(0)) {
return activeNetworkconfig;
}
//Deploy the mocks
//return the mockaddress
vm.startBroadcast();

MockV3Aggregator mockpricefeed = new MockV3Aggregator(DECIMALS, INITIAL_UNIT_PRICE);

vm.stopBroadcast();
NetworkConfig memory anvilConfig = NetworkConfig({pricefeed: address(mockpricefeed)});

return anvilConfig;
}
}
46 changes: 46 additions & 0 deletions script/Interactions.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
// Fund
// WithDraw
pragma solidity ^0.8.18;

import {Script, console} from "forge-std/Script.sol";
import {DevOpsTools} from "foundry-devops/src/DevOpsTools.sol";
import {FundMe} from "../src/FundMe.sol";
contract FundMe_Funds is Script{
address USER = makeAddr("user");
uint256 constant SEND_VALUE = 0.01 ether;
function fundeFundMe(address mostRecentlyDeployed) public {
vm.prank(USER);
FundMe(payable(mostRecentlyDeployed)).fund{value: SEND_VALUE}();
console.log(mostRecentlyDeployed, "Funded FundeMe with %s", SEND_VALUE);
}

function run() external {
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment("FundMe", block.chainid);
vm.startBroadcast();
fundeFundMe(mostRecentlyDeployed);
vm.stopBroadcast();
}
}

contract FundeMe_Withdrawal is Script {
uint256 constant SEND_VALUE = 0.01 ether;

function withdrawFundMe(address mostRecentlyDeployed) public {
vm.startBroadcast();
FundMe(payable(mostRecentlyDeployed)).withdraw();
vm.stopBroadcast();

}

function run() external {
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment("FundMe", block.chainid);

vm.startBroadcast();
withdrawFundMe(mostRecentlyDeployed);
vm.stopBroadcast();
}


}

14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

Loading

0 comments on commit 6f5418a

Please sign in to comment.