-
Notifications
You must be signed in to change notification settings - Fork 52
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 58116e4
Showing
27 changed files
with
4,984 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,7 @@ | ||
MAINNET_RPC= | ||
MAINNET_DEPLOYER_PK= | ||
|
||
RINKEBY_RPC= | ||
RINKEBY_DEPLOYER_PK= | ||
|
||
ETHERSCAN_API_KEY= |
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 @@ | ||
*.sol linguist-language=Solidity |
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,110 @@ | ||
name: CI | ||
|
||
on: [push] | ||
|
||
concurrency: | ||
group: ${{github.workflow}}-${{github.ref}} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
lint: | ||
name: Run Linters | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
run: yarn --frozen-lockfile --network-concurrency 1 | ||
|
||
- run: yarn lint:check | ||
|
||
forge: | ||
name: Run Unit and E2E Tests | ||
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 forge dependencies | ||
run: forge install | ||
|
||
- name: Precompile using 0.8.14 and via-ir=false | ||
run: yarn build | ||
|
||
- name: "Create env file" | ||
run: | | ||
touch .env | ||
echo MAINNET_RPC="${{ secrets.MAINNET_RPC }}" >> .env | ||
echo RINKEBY_RPC="${{ secrets.RINKEBY_RPC }}" >> .env | ||
cat .env | ||
- name: Run tests | ||
shell: bash | ||
run: yarn test | ||
|
||
forge-optimized: | ||
name: Run Optimized Unit Tests | ||
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 forge dependencies | ||
run: forge install | ||
|
||
- name: Precompile using 0.8.14 and via-ir=true | ||
run: yarn build:optimized | ||
|
||
- name: Run tests | ||
run: yarn test:unit | ||
|
||
# coverage: | ||
# name: Run Coverage Tests | ||
# runs-on: ubuntu-latest | ||
|
||
# strategy: | ||
# matrix: | ||
# node-version: [16.x] | ||
|
||
# steps: | ||
# - uses: actions/checkout@v3 | ||
# - name: Use Node.js | ||
# uses: actions/setup-node@v3 | ||
# with: | ||
# node-version: ${{ matrix.node-version }} | ||
# cache: "yarn" | ||
# - run: yarn install | ||
# - run: yarn build | ||
# - run: yarn coverage | ||
# - uses: codecov/codecov-action@v3 | ||
# with: | ||
# files: ./coverage/lcov.info | ||
# flags: production |
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 @@ | ||
# General | ||
yarn-error.log | ||
node_modules | ||
.DS_STORE | ||
|
||
# Foundry files | ||
cache | ||
out-via-ir | ||
|
||
# Config files | ||
.env | ||
|
||
# Avoid ignoring gitkeep | ||
!/**/.gitkeep | ||
|
||
# Keep related abi | ||
out/*/* | ||
!out/Greeter.sol/* | ||
|
||
# Keep the latest deployment only | ||
broadcast/*/*/* | ||
!broadcast/*/*/run-latest.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,16 @@ | ||
[submodule "lib/ds-test"] | ||
path = lib/ds-test | ||
url = https://github.com/dapphub/ds-test | ||
branch = master | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/brockelmore/forge-std | ||
branch = master | ||
[submodule "lib/prb-test"] | ||
path = lib/prb-test | ||
url = https://github.com/paulrberg/prb-test | ||
branch = 0.1.1 | ||
[submodule "lib/isolmate"] | ||
path = lib/isolmate | ||
url = https://github.com/defi-wonderland/isolmate | ||
branch = main |
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 @@ | ||
_ |
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,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx --no-install commitlint --edit $1 |
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,7 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
# 1. Build the contracts | ||
# 2. Stage build output | ||
# 2. Lint and stage style improvements | ||
yarn build && git add out && npx lint-staged |
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,28 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"plugins": ["defi-wonderland"], | ||
"rules": { | ||
"compiler-version": ["off"], | ||
"constructor-syntax": "warn", | ||
"quotes": ["error", "single"], | ||
"func-visibility": ["warn", { "ignoreConstructors": true }], | ||
"not-rely-on-time": "off", | ||
"func-name-mixedcase": "off", | ||
"var-name-mixedcase": "off", | ||
"const-name-snakecase": "off", | ||
"no-inline-assembly": "off", | ||
"no-empty-blocks": "off", | ||
"private-vars-leading-underscore": ["warn", { "strict": false }], | ||
"defi-wonderland/non-state-vars-leading-underscore": ["warn"], | ||
"defi-wonderland/contract-data-order": ["warn"], | ||
"defi-wonderland/enum-name-camelcase": ["warn"], | ||
"defi-wonderland/immutable-name-snakecase": ["warn"], | ||
"defi-wonderland/import-statement-format": ["warn"], | ||
"defi-wonderland/interface-member-order": ["warn"], | ||
"defi-wonderland/interface-starts-with-i": ["warn"], | ||
"defi-wonderland/named-return-values": ["warn"], | ||
"defi-wonderland/struct-name-camelcase": ["warn"], | ||
"defi-wonderland/wonder-var-name-mixedcase": ["warn"], | ||
"avoid-low-level-calls": "off" | ||
} | ||
} |
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,110 @@ | ||
<img src="https://raw.githubusercontent.com/defi-wonderland/brand/v1.0.0/external/solidity-foundry-boilerplate-banner.png" alt="wonderland banner" align="center" /> | ||
<br /> | ||
|
||
<div align="center"><strong>Start your next Solidity project with Foundry in seconds</strong></div> | ||
<div align="center">A highly scalable foundation focused on DX and best practices</div> | ||
|
||
<br /> | ||
|
||
## Features | ||
|
||
<dl> | ||
<dt>Sample contracts</dt> | ||
<dd>Basic Greeter contract with an external interface.</dd> | ||
|
||
<dt>Foundry setup</dt> | ||
<dd>Foundry configuration with multiple custom profiles and remappings.</dd> | ||
|
||
<dt>Deployment scripts</dt> | ||
<dd>Sample scripts to deploy contracts on both mainnet and testnet.</dd> | ||
|
||
<dt>Sample e2e & unit tests</dt> | ||
<dd>Example tests showcasing mocking, assertions and configuration for mainnet forking. As well it includes everything needed in order to check code coverage.</dd> | ||
|
||
<dt>Linter</dt> | ||
<dd>Simple and fast solidity linting thanks to forge fmt</a>.</dd> | ||
|
||
<dt>Github workflows CI</dt> | ||
<dd>Run all tests and see the coverage as you push your changes.</dd> | ||
</dl> | ||
|
||
## Setup | ||
|
||
1. Install Foundry by following the instructions from [their repository](https://github.com/foundry-rs/foundry#installation). | ||
2. Copy the `.env.example` file to `.env` and fill in the variables | ||
3. Install the dependencies by running : `yarn install && forge install` | ||
|
||
## Build | ||
|
||
The default way to build the code is suboptimal but fast, you can run it via: | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
In order to build a more optimized code ([via IR](https://docs.soliditylang.org/en/v0.8.15/ir-breaking-changes.html#solidity-ir-based-codegen-changes)), run: | ||
|
||
```bash | ||
yarn build:optimized | ||
``` | ||
|
||
## Running tests | ||
|
||
Unit tests should be isolated from any externalities, while E2E usually run in a fork of the blockchain. In this boilerplate you will find example of both. | ||
|
||
In order to run both unit and E2E tests, run: | ||
|
||
```bash | ||
yarn test | ||
``` | ||
|
||
In order to just run unit tests, run: | ||
|
||
```bash | ||
yarn test:unit | ||
``` | ||
|
||
In order to run unit tests and run way more fuzzing than usual (5x), run: | ||
|
||
```bash | ||
yarn test:unit:deep | ||
``` | ||
|
||
In order to just run e2e tests, run: | ||
|
||
```bash | ||
yarn test:e2e | ||
``` | ||
|
||
In order to check your current code coverage, run: | ||
|
||
```bash | ||
yarn coverage | ||
``` | ||
|
||
> **⚠ WARNING: Forge coverage is having some issues...** | ||
> As stated in this [github issue](https://github.com/foundry-rs/foundry/issues/2165), checking the code coverage with Forge when using abstract contract is not currently working. | ||
<br> | ||
|
||
## Deploy & verify | ||
|
||
### Setup | ||
|
||
Configure the `.env` variables. | ||
|
||
### Rinkeby | ||
|
||
```bash | ||
yarn deploy:rinkeby | ||
``` | ||
|
||
### Mainnet | ||
|
||
```bash | ||
yarn deploy:mainnet | ||
``` | ||
|
||
The deployments are stored in ./broadcast | ||
|
||
See the [Foundry Book for available options](https://book.getfoundry.sh/reference/forge/forge-create.html). |
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 @@ | ||
module.exports = { extends: ['@commitlint/config-conventional'] }; |
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,32 @@ | ||
[fmt] | ||
line_length = 120 | ||
tab_width = 2 | ||
bracket_spacing = false | ||
int_types = 'long' | ||
quote_style = 'single' | ||
number_underscore = 'thousands' | ||
multiline_func_header = 'params_first' | ||
|
||
[profile.default] | ||
solc = '0.8.14' | ||
src = 'solidity' | ||
test = 'solidity/test' | ||
out = 'out' | ||
libs = ['lib'] | ||
fuzz_runs = 1000 | ||
optimizer_runs = 10_000 | ||
|
||
[profile.optimized] | ||
via_ir = true | ||
out = 'out-via-ir' | ||
fuzz_runs = 5000 | ||
|
||
[profile.test] | ||
via_ir = true | ||
out = 'out-via-ir' | ||
fuzz_runs = 5000 | ||
src = 'solidity/test' | ||
|
||
[rpc_endpoints] | ||
mainnet = "${MAINNET_RPC}" | ||
rinkeby = "${RINKEBY_RPC}" |
Oops, something went wrong.