-
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
Showing
20 changed files
with
733 additions
and
122 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 @@ | ||
ZkSyncDevOps:testZkSyncChainFails() (gas: 181502) |
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/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[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 |
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 unit | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,6 @@ | ||
## Foundry | ||
# Foundry Fund Me | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
|
||
Foundry consists of: | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
|
||
## Documentation | ||
|
||
https://book.getfoundry.sh/ | ||
|
||
## Usage | ||
|
||
### Build | ||
|
||
```shell | ||
$ forge build | ||
``` | ||
|
||
### Test | ||
|
||
```shell | ||
$ forge test | ||
``` | ||
|
||
### Format | ||
|
||
```shell | ||
$ forge fmt | ||
``` | ||
|
||
### Gas Snapshots | ||
|
||
```shell | ||
$ forge snapshot | ||
``` | ||
|
||
### Anvil | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
|
||
### Deploy | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
|
||
### Cast | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
|
||
### Help | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` | ||
-[ ] Proper README.md file | ||
-[ ] Integration tests | ||
-[ ] Programmatic verification | ||
-[ ] Push to GitHub |
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
6e324d
Submodule foundry-devops
added at
47393d
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,22 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {HelperConfig} from "./HelperConfig.s.sol"; | ||
import {FundMe} from "../src/FundMe.sol"; | ||
|
||
contract DeployFundMe is Script { | ||
function deployFundMe() public returns (FundMe, HelperConfig) { | ||
HelperConfig helperConfig = new HelperConfig(); // This comes with our mocks! | ||
address priceFeed = helperConfig.getConfigByChainId(block.chainid).priceFeed; | ||
|
||
vm.startBroadcast(); | ||
FundMe fundMe = new FundMe(priceFeed); | ||
vm.stopBroadcast(); | ||
return (fundMe, helperConfig); | ||
} | ||
|
||
function run() external returns (FundMe, HelperConfig) { | ||
return deployFundMe(); | ||
} | ||
} |
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,102 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import {MockV3Aggregator} from "../test/mocks/MockV3Aggregator.sol"; | ||
import {Script, console2} from "forge-std/Script.sol"; | ||
|
||
abstract contract CodeConstants { | ||
uint8 public constant DECIMALS = 8; | ||
int256 public constant INITIAL_PRICE = 2000e8; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
CHAIN IDS | ||
//////////////////////////////////////////////////////////////*/ | ||
uint256 public constant ETH_SEPOLIA_CHAIN_ID = 11155111; | ||
uint256 public constant ZKSYNC_SEPOLIA_CHAIN_ID = 300; | ||
uint256 public constant LOCAL_CHAIN_ID = 31337; | ||
} | ||
|
||
contract HelperConfig is CodeConstants, Script { | ||
/*////////////////////////////////////////////////////////////// | ||
ERRORS | ||
//////////////////////////////////////////////////////////////*/ | ||
error HelperConfig__InvalidChainId(); | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
TYPES | ||
//////////////////////////////////////////////////////////////*/ | ||
struct NetworkConfig { | ||
address priceFeed; | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
STATE VARIABLES | ||
//////////////////////////////////////////////////////////////*/ | ||
// Local network state variables | ||
NetworkConfig public localNetworkConfig; | ||
mapping(uint256 chainId => NetworkConfig) public networkConfigs; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
FUNCTIONS | ||
//////////////////////////////////////////////////////////////*/ | ||
constructor() { | ||
networkConfigs[ETH_SEPOLIA_CHAIN_ID] = getSepoliaEthConfig(); | ||
networkConfigs[ZKSYNC_SEPOLIA_CHAIN_ID] = getZkSyncSepoliaConfig(); | ||
// Note: We skip doing the local config | ||
} | ||
|
||
function getConfigByChainId( | ||
uint256 chainId | ||
) public returns (NetworkConfig memory) { | ||
if (networkConfigs[chainId].priceFeed != address(0)) { | ||
return networkConfigs[chainId]; | ||
} else if (chainId == LOCAL_CHAIN_ID) { | ||
return getOrCreateAnvilEthConfig(); | ||
} else { | ||
revert HelperConfig__InvalidChainId(); | ||
} | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
CONFIGS | ||
//////////////////////////////////////////////////////////////*/ | ||
function getSepoliaEthConfig() public pure returns (NetworkConfig memory) { | ||
return | ||
NetworkConfig({ | ||
priceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306 // ETH / USD | ||
}); | ||
} | ||
|
||
function getZkSyncSepoliaConfig() | ||
public | ||
pure | ||
returns (NetworkConfig memory) | ||
{ | ||
return | ||
NetworkConfig({ | ||
priceFeed: 0xfEefF7c3fB57d18C5C6Cdd71e45D2D0b4F9377bF // ETH / USD | ||
}); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
LOCAL CONFIG | ||
//////////////////////////////////////////////////////////////*/ | ||
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) { | ||
// Check to see if we set an active network config | ||
if (localNetworkConfig.priceFeed != address(0)) { | ||
return localNetworkConfig; | ||
} | ||
|
||
console2.log(unicode"⚠️ You have deployed a mock conract!"); | ||
console2.log("Make sure this was intentional"); | ||
vm.startBroadcast(); | ||
MockV3Aggregator mockPriceFeed = new MockV3Aggregator( | ||
DECIMALS, | ||
INITIAL_PRICE | ||
); | ||
vm.stopBroadcast(); | ||
|
||
localNetworkConfig = NetworkConfig({priceFeed: address(mockPriceFeed)}); | ||
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,45 @@ | ||
// SPDX-License-Identifier: SEE LICENSE IN LICENSE | ||
pragma solidity ^0.8.18; | ||
|
||
// Fund | ||
// Withdraw | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
import {FundMe} from "../src/FundMe.sol"; | ||
import {DevOpsTools} from "foundry-devops/src/DevOpsTools.sol"; | ||
|
||
contract FundFundMe is Script { | ||
uint256 SEND_VALUE = 0.1 ether; | ||
|
||
function fundFundMe(address mostRecentlyDeployed) public { | ||
vm.startBroadcast(); | ||
FundMe(payable(mostRecentlyDeployed)).fund{value: SEND_VALUE}(); | ||
vm.stopBroadcast(); | ||
console.log("Funded with %s", SEND_VALUE); | ||
} | ||
|
||
function run() external { | ||
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment( | ||
"FundMe", | ||
block.chainid | ||
); | ||
fundFundMe(mostRecentlyDeployed); | ||
} | ||
} | ||
|
||
contract WithdrawFundMe is Script { | ||
function withdrawFundMe(address mostRecentlyDeployed) public { | ||
vm.startBroadcast(); | ||
FundMe(payable(mostRecentlyDeployed)).withdraw(); | ||
vm.stopBroadcast(); | ||
console.log("Withdraw FundMe Balance"); | ||
} | ||
|
||
function run() external { | ||
address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment( | ||
"FundMe", | ||
block.chainid | ||
); | ||
withdrawFundMe(mostRecentlyDeployed); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.