-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to foundry #867
Merged
Merged
Migrate to foundry #867
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1a7a131
add foundry changes without submodules
technophile-04 f0c14ec
forge install: forge-std
technophile-04 2b6a766
forge install: openzeppelin-contracts
technophile-04 f15c6d1
forge install: solidity-bytes-utils
technophile-04 941797a
update gh workflow file
technophile-04 5247608
fix gh-actions: unignore deployments 31337.json
technophile-04 ae36666
Revert "fix gh-actions: unignore deployments 31337.json"
technophile-04 d0755b9
add .gitignore inside deployemnts folder
technophile-04 b272a98
remove workflow file from foundry package
technophile-04 bc0323b
update .env.example
technophile-04 e68e0a7
use node es modules
technophile-04 72dc85d
move all js files inder scripts-js dir
technophile-04 96e9f18
update README
technophile-04 dac5c05
configure basic lint/formatting code
technophile-04 b8cc2d6
remove types devDependencies from foundry package
technophile-04 ad9b88c
minor tweak to README
technophile-04 40e0107
minor tweak to .env.example
technophile-04 3c1659a
Merge branch 'main' into foundry-main
carletex caff159
yarn.lock regenerate
carletex 951f733
Use cpy-cli to create .env on postinstall
carletex 5e43708
update .env.example
technophile-04 3257010
remove console.log from generateAccount.js
technophile-04 52882e7
update YourContract comment
technophile-04 46443fb
use shx instead of cpy-cli
carletex abf1e81
Merge remote-tracking branch 'origin/foundry-main--cp-env' into found…
technophile-04 b2d0cfc
remove cp command from readme
technophile-04 a126be9
Add installation note for windows users
Pabl0cks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,9 @@ | ||
[submodule "packages/foundry/lib/forge-std"] | ||
path = packages/foundry/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "packages/foundry/lib/openzeppelin-contracts"] | ||
path = packages/foundry/lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "packages/foundry/lib/solidity-bytes-utils"] | ||
path = packages/foundry/lib/solidity-bytes-utils | ||
url = https://github.com/gnsps/solidity-bytes-utils |
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Template for foundry environment variables. | ||
|
||
# For local development, copy this file, rename it to .env, and fill in the values. | ||
|
||
# We provide default values so developers can start prototyping out of the box, | ||
# but we recommend getting your own API Keys for Production Apps. | ||
|
||
# DEPLOYER_PRIVATE_KEY is used while deploying contract, while deploying contract. | ||
technophile-04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# On anvil chain the value of it can be empty and we will use the prefunded account | ||
# which comes with anvil chain to deploy contract. | ||
# NOTE: You don't need to manually change the value of DEPLOYER_PRIVATE_KEY manually, it should | ||
technophile-04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# be auto filled when run `yarn generate`. | ||
# Although `.env` is ignored by git, it's still important that you don't paste your | ||
# actual account private key and use the generated one. | ||
DEPLOYER_PRIVATE_KEY= | ||
|
||
# Alchemy rpc URL is used while deploying the contracts to some testnets/mainnets, checkout `foundry.toml` for it's use. | ||
ALCHEMY_API_KEY=oKxs-03sij-U_N0iOlrSsZFr29-IqbuF | ||
|
||
# Etherscan API key is used to verify the contract on etherscan. | ||
ETHERSCAN_API_KEY=DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW |
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,14 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env | ||
localhost.json |
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,6 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"trailingComma": "all" | ||
} |
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,84 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
// Useful for debugging. Remove when deploying to a live network. | ||
import "forge-std/console.sol"; | ||
|
||
// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc) | ||
// import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
/** | ||
* A smart contract that allows changing a state variable of the contract and tracking the changes | ||
* It also allows the owner to withdraw the Ether in the contract | ||
rin-st marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @author BuidlGuidl | ||
*/ | ||
contract YourContract { | ||
// State Variables | ||
address public immutable owner; | ||
string public greeting = "Building Unstoppable Apps!!!"; | ||
bool public premium = false; | ||
uint256 public totalCounter = 0; | ||
mapping(address => uint256) public userGreetingCounter; | ||
|
||
// Events: a way to emit log statements from smart contract that can be listened to by external parties | ||
event GreetingChange( | ||
address indexed greetingSetter, | ||
string newGreeting, | ||
bool premium, | ||
uint256 value | ||
); | ||
|
||
// Constructor: Called once on contract deployment | ||
// Check packages/foundry/deploy/Deploy.s.sol | ||
constructor(address _owner) { | ||
owner = _owner; | ||
} | ||
|
||
// Modifier: used to define a set of rules that must be met before or after a function is executed | ||
// Check the withdraw() function | ||
modifier isOwner() { | ||
// msg.sender: predefined variable that represents address of the account that called the current function | ||
require(msg.sender == owner, "Not the Owner"); | ||
_; | ||
} | ||
|
||
/** | ||
* Function that allows anyone to change the state variable "greeting" of the contract and increase the counters | ||
* | ||
* @param _newGreeting (string memory) - new greeting to save on the contract | ||
*/ | ||
function setGreeting(string memory _newGreeting) public payable { | ||
// Print data to the anvil chain console. Remove when deploying to a live network. | ||
|
||
console.logString("Setting new greeting"); | ||
console.logString(_newGreeting); | ||
|
||
greeting = _newGreeting; | ||
totalCounter += 1; | ||
userGreetingCounter[msg.sender] += 1; | ||
|
||
// msg.value: built-in global variable that represents the amount of ether sent with the transaction | ||
if (msg.value > 0) { | ||
premium = true; | ||
} else { | ||
premium = false; | ||
} | ||
|
||
// emit: keyword used to trigger an event | ||
emit GreetingChange(msg.sender, _newGreeting, msg.value > 0, msg.value); | ||
} | ||
|
||
/** | ||
* Function that allows the owner to withdraw all the Ether in the contract | ||
* The function can only be called by the owner of the contract as defined by the isOwner modifier | ||
*/ | ||
function withdraw() public isOwner { | ||
(bool success,) = owner.call{ value: address(this).balance }(""); | ||
require(success, "Failed to send Ether"); | ||
} | ||
|
||
/** | ||
* Function that allows the contract to receive ETH | ||
*/ | ||
receive() external payable { } | ||
} |
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,2 @@ | ||
# Ignore 31337 deployments | ||
31337.json |
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,44 @@ | ||
[profile.default] | ||
src = 'contracts' | ||
out = 'out' | ||
libs = ['lib'] | ||
fs_permissions = [{ access = "read-write", path = "./"}] | ||
|
||
[rpc_endpoints] | ||
default_network = "http://127.0.0.1:8545" | ||
localhost = "http://127.0.0.1:8545" | ||
|
||
mainnet = "https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_API_KEY}" | ||
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
arbitrum = "https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
arbitrumSepolia = "https://arb-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
optimism = "https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
optimismSepolia = "https://opt-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
polygon = "https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
polygonMumbai = "https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
gnosis = "https://rpc.gnosischain.com" | ||
chiado = "https://rpc.chiadochain.net" | ||
base = "https://mainnet.base.org" | ||
baseGoerli = "https://goerli.base.org" | ||
baseSepolia = "https://sepolia.base.org" | ||
polygonZkEvm = "https://polygonzkevm-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
polygonZkEvmTestnet = "https://polygonzkevm-testnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" | ||
zkSyncTestnet = "https://testnet.era.zksync.dev" | ||
zkSync = "https://mainnet.era.zksync.io" | ||
scrollSepolia = "https://sepolia-rpc.scroll.io" | ||
scroll = "https://rpc.scroll.io" | ||
|
||
[etherscan] | ||
polygonMumbai = { key = "${ETHERSCAN_API_KEY}" } | ||
sepolia = { key = "${ETHERSCAN_API_KEY}" } | ||
|
||
|
||
[fmt] | ||
multiline_func_header = "params_first" | ||
line_length = 80 | ||
tab_width = 2 | ||
quote_style = "double" | ||
bracket_spacing = true | ||
int_types = "long" | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/tree/master/config |
Submodule openzeppelin-contracts
added at
dbb610
Submodule solidity-bytes-utils
added at
e0115c
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,27 @@ | ||
{ | ||
"name": "@se-2/foundry", | ||
"version": "0.0.1", | ||
"type": "module", | ||
"scripts": { | ||
"account": "node scripts-js/ListAccount.js", | ||
"chain": "anvil --config-out localhost.json", | ||
"compile": "forge compile", | ||
"deploy": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy && node scripts-js/generateTsAbis.js", | ||
"deploy:verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/Deploy.s.sol --rpc-url ${1:-default_network} --broadcast --legacy --verify ; node scripts-js/generateTsAbis.js", | ||
"flatten": "forge flatten", | ||
"fork": "anvil --fork-url ${0:-mainnet} --chain-id 31337 --config-out localhost.json", | ||
"format": "forge fmt && prettier --write ./script/**/*.js", | ||
"generate": "node scripts-js/generateAccount.js", | ||
"lint": "forge fmt --check && prettier --check ./script/**/*.js", | ||
"test": "forge test", | ||
"verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/VerifyAll.s.sol --ffi --rpc-url ${1:-default_network}" | ||
}, | ||
"dependencies": { | ||
"dotenv": "~16.3.1", | ||
"envfile": "~6.18.0", | ||
"ethers": "~5.7.1", | ||
"prettier": "~2.8.8", | ||
"qrcode": "~1.5.3", | ||
"toml": "~3.0.0" | ||
} | ||
} |
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 @@ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that you already commented about this in the PR comment. Having to do this is a PITA (the 3 magic commands don't work out of the box), so I've been trying some options (postinstall as you mentioned)
branch: https://github.com/scaffold-eth/scaffold-eth-2/commits/foundry-main--cp-env/
commit: 951f733
Using the smallest
copy
lib that I could find (even tho it installs a few other deps, maybe we can explore other options), which should work on any OS.I remember that we had some issues with the postinstall script (not running at all in some OS? Or running after every time you run
yarn install
? Added the--no-overwrite
in case it's the latter).What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we take this path, this can help to decide about the lib to use. https://pkg-size.dev/
eg. https://pkg-size.dev/cpy-cli => 1.3MB vs the 5 KB advertised (which doesn't count the deps)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After researching for a while I think postinstall seems a safe option.
Some notes on `postinstall` script:
Postinstall in yarn will run only when something in root
node_modules
changes(which means some package is added in dependency or devDependency of rootpackage.json
) ornode_moduels
is initializedexample image :
Postinstall in yarn does not log output to stdout, which means If you do
postinstall: echo 'hello world'
it won't log hello world. It will only show output on error (example this image )Running
yarn install
multiple times won't runpostinstall
multiple times until you add any package to rootpacakage.json
. If you add npm package innextjs
it won't run.So considering all the above points, I think
postinstall
seems a fine options for usEven I had the same feeling, but went through SE-2 issues throughly and could only found this : #275
The above issue was not related too much related to
postinstall
(since postinstall ran) but it was related to node js script not resolving proper path on windows.So yeah 951f733 seems good if it works nicely on windows (hopefully it resolves path correctly internally)
Another options we could also put our own node script at root of monorepo and call it in
postinstall: node startUp.js
but we need to make sure it works properly on windows the path resolution thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was just trying https://github.com/scaffold-eth/scaffold-eth-2/tree/foundry-main--cp-env and found a minor disadvantage that:
yarn install
this creates.env.example
nicely inpacakge/foundry
foundry
packagecd packages/foundry
andyarn add viem
it will fail :basically you won't be able to install any node / js dependency in
foundry
package because it will fail since we are using---no-overwrite
it throwing errorAn alternatie solution will be finding a library which doesn't throw error or writting our own node script which doesn't throw error if
.env
is already present. The only reason I am afraid of writing our own script is because of #275 where isn't properly able to get the path but maybe we should give it another shot?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is what we need: https://www.npmjs.com/package/shx (we can use commands from linux, and we could copy... or even test if the file exist before copying)
And it takes less space https://pkg-size.dev/shx
I'll give it a shot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this (using shx): 46443fb
I pushed it to https://github.com/scaffold-eth/scaffold-eth-2/commits/foundry-main--cp-env/
If we like it, we can have Pablo to test on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noiicee, just tried it out and works great!! Tysm!!, I think this works great!! Will merge in this changes!