-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Carlos Sánchez <oceanrdn@gmail.com> Co-authored-by: Pablo Alayeto <55535804+Pabl0cks@users.noreply.github.com>
- Loading branch information
1 parent
35b4c67
commit e1b39d0
Showing
39 changed files
with
947 additions
and
4,940 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
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. | ||
# On anvil chain the value of it can be empty since we 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, it should | ||
# 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 from the contract | ||
* @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,31 @@ | ||
{ | ||
"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", | ||
"postinstall": "shx cp -n .env.example .env", | ||
"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" | ||
}, | ||
"devDependencies": { | ||
"shx": "^0.3.4" | ||
} | ||
} |
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.