generated from huff-language/huff-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
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
0 parents
commit 48d2ab3
Showing
13 changed files
with
300 additions
and
0 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,3 @@ | ||
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1 | ||
ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY> | ||
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 |
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,61 @@ | ||
name: ci | ||
|
||
on: [push] | ||
|
||
jobs: | ||
tests: | ||
name: Tests with Foundry | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Install Huff | ||
uses: huff-language/huff-toolchain@v2 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Tests | ||
run: forge test -vvv | ||
|
||
scripts: | ||
strategy: | ||
fail-fast: true | ||
name: Run Scripts | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Install Huff | ||
uses: huff-language/huff-toolchain@v3 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge build | ||
run: | | ||
forge --version | ||
forge build --sizes | ||
id: build | ||
continue-on-error: true | ||
|
||
- name: Run scripts | ||
run: | | ||
ls -lsa | ||
ls script/ | ||
for file in script/*; do | ||
forge script $file -vvvv | ||
done |
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 @@ | ||
# Any Node Modules | ||
node_modules/ | ||
|
||
# Environment Variables | ||
.env | ||
.env.prod | ||
|
||
# Cached Build | ||
cache/ | ||
out/ | ||
|
||
# Vscode | ||
.vscode/ | ||
|
||
# huffc artifacts | ||
artifacts | ||
|
||
# Ignore flattened files | ||
flattened.txt | ||
|
||
# Ignore Broadcasts | ||
broadcast |
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 @@ | ||
[submodule "lib/foundry-huff"] | ||
path = lib/foundry-huff | ||
url = https://github.com/huff-language/foundry-huff | ||
[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,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
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 @@ | ||
<img align="right" width="150" height="150" top="100" src="./assets/blueprint.png"> | ||
|
||
# huff-project-template • [![ci](https://github.com/huff-language/huff-project-template/actions/workflows/ci.yaml/badge.svg)](https://github.com/huff-language/huff-project-template/actions/workflows/ci.yaml) ![license](https://img.shields.io/github/license/huff-language/huff-project-template.svg) ![solidity](https://img.shields.io/badge/solidity-^0.8.15-lightgrey) | ||
|
||
Versatile Huff Project Template using Foundry. | ||
|
||
|
||
## Getting Started | ||
|
||
### Requirements | ||
|
||
The following will need to be installed in order to use this template. Please follow the links and instructions. | ||
|
||
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) | ||
- You'll know you've done it right if you can run `git --version` | ||
- [Foundry / Foundryup](https://github.com/gakonst/foundry) | ||
- This will install `forge`, `cast`, and `anvil` | ||
- You can test you've installed them right by running `forge --version` and get an output like: `forge 0.2.0 (92f8951 2022-08-06T00:09:32.96582Z)` | ||
- To get the latest of each, just run `foundryup` | ||
- [Huff Compiler](https://docs.huff.sh/get-started/installing/) | ||
- You'll know you've done it right if you can run `huffc --version` and get an output like: `huffc 0.3.0` | ||
|
||
### Quickstart | ||
|
||
1. Clone this repo or use template | ||
|
||
Click "Use this template" on [GitHub](https://github.com/huff-language/huff-project-template) to create a new repository with this repo as the initial state. | ||
|
||
Or run: | ||
|
||
``` | ||
git clone https://github.com/huff-language/huff-project-template | ||
cd huff-project-template | ||
``` | ||
|
||
2. Install dependencies | ||
|
||
Once you've cloned and entered into your repository, you need to install the necessary dependencies. In order to do so, simply run: | ||
|
||
```shell | ||
forge install | ||
``` | ||
|
||
3. Build & Test | ||
|
||
To build and test your contracts, you can run: | ||
|
||
```shell | ||
forge build | ||
forge test | ||
``` | ||
|
||
For more information on how to use Foundry, check out the [Foundry Github Repository](https://github.com/foundry-rs/foundry/tree/master/forge) and the [foundry-huff library repository](https://github.com/huff-language/foundry-huff). | ||
|
||
|
||
## Blueprint | ||
|
||
```ml | ||
lib | ||
├─ forge-std — https://github.com/foundry-rs/forge-std | ||
├─ foundry-huff — https://github.com/huff-language/foundry-huff | ||
scripts | ||
├─ Deploy.s.sol — Deployment Script | ||
src | ||
├─ SimpleStore — A Simple Storage Contract in Huff | ||
test | ||
└─ SimpleStore.t — SimpleStoreTests | ||
``` | ||
|
||
|
||
## License | ||
|
||
[The Unlicense](https://github.com/huff-language/huff-project-template/blob/master/LICENSE) | ||
|
||
|
||
## Acknowledgements | ||
|
||
- [forge-template](https://github.com/foundry-rs/forge-template) | ||
- [femplate](https://github.com/abigger87/femplate) | ||
|
||
|
||
## Disclaimer | ||
|
||
_These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk._ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
|
||
[profile.default] | ||
solc_version = '0.8.20' | ||
evm_version = 'shanghai' | ||
auto_detect_solc = false | ||
optimizer = true | ||
optimizer_runs = 200 # Default amount | ||
ffi = true | ||
fuzz_runs = 1_000 | ||
remappings = [ | ||
"forge-std=lib/forge-std/src/", | ||
"foundry-huff=lib/foundry-huff/src/", | ||
] |
Submodule foundry-huff
added at
eb9ea3
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,16 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.15; | ||
|
||
import "foundry-huff/HuffDeployer.sol"; | ||
import "forge-std/Script.sol"; | ||
|
||
interface SimpleStore { | ||
function setValue(uint256) external; | ||
function getValue() external returns (uint256); | ||
} | ||
|
||
contract Deploy is Script { | ||
function run() public returns (SimpleStore simpleStore) { | ||
simpleStore = SimpleStore(HuffDeployer.deploy("SimpleStore")); | ||
} | ||
} |
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,40 @@ | ||
/* Interface */ | ||
#define function setValue(uint256) nonpayable returns () | ||
#define function getValue() view returns (uint256) | ||
|
||
/* Storage Slots */ | ||
#define constant VALUE_LOCATION = FREE_STORAGE_POINTER() | ||
|
||
/* Methods */ | ||
#define macro SET_VALUE() = takes (0) returns (0) { | ||
0x04 calldataload // [value] | ||
[VALUE_LOCATION] // [ptr, value] | ||
sstore // [] | ||
} | ||
|
||
#define macro GET_VALUE() = takes (0) returns (0) { | ||
// Load value from storage. | ||
[VALUE_LOCATION] // [ptr] | ||
sload // [value] | ||
|
||
// Store value in memory. | ||
0x00 mstore | ||
|
||
// Return value | ||
0x20 0x00 return | ||
} | ||
|
||
#define macro MAIN() = takes (0) returns (0) { | ||
// Identify which function is being called. | ||
0x00 calldataload 0xE0 shr | ||
dup1 __FUNC_SIG(setValue) eq set jumpi | ||
dup1 __FUNC_SIG(getValue) eq get jumpi | ||
|
||
0x00 0x00 revert | ||
|
||
set: | ||
SET_VALUE() | ||
get: | ||
GET_VALUE() | ||
|
||
} |
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,29 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.15; | ||
|
||
import "foundry-huff/HuffDeployer.sol"; | ||
import "forge-std/Test.sol"; | ||
import "forge-std/console.sol"; | ||
|
||
contract SimpleStoreTest is Test { | ||
/// @dev Address of the SimpleStore contract. | ||
SimpleStore public simpleStore; | ||
|
||
/// @dev Setup the testing environment. | ||
function setUp() public { | ||
simpleStore = SimpleStore(HuffDeployer.deploy("SimpleStore")); | ||
} | ||
|
||
/// @dev Ensure that you can set and get the value. | ||
function testSetAndGetValue(uint256 value) public { | ||
simpleStore.setValue(value); | ||
console.log(value); | ||
console.log(simpleStore.getValue()); | ||
assertEq(value, simpleStore.getValue()); | ||
} | ||
} | ||
|
||
interface SimpleStore { | ||
function setValue(uint256) external; | ||
function getValue() external returns (uint256); | ||
} |