-
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
1 parent
cf3932b
commit 6f5418a
Showing
22 changed files
with
649 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 @@ | ||
FundMeTest:test_withdraw_from_multiple_funders() (gas: 461103) |
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,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 |
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,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) |
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
added at
12393b
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 foundry-devops
added at
df9f90
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,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; | ||
} | ||
|
||
} |
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,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 | ||
} |
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,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; | ||
} | ||
} |
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,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(); | ||
} | ||
|
||
|
||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.