Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Feb 20, 2024
0 parents commit 4384fb9
Show file tree
Hide file tree
Showing 18 changed files with 3,054 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Mnemonic phrase
export MNEMONIC=""

# Private key
export PRIVATE_KEY=""

# Mainnet RPC URLs
export MAINNET_RPC_URL=""
export ARBITRUM_RPC_URL=""
export OPTIMISM_RPC_URL=""

# Testnet RPC URLs
export SEPOLIA_RPC_URL=""
export ARBITRUM_SEPOLIA_RPC_URL=""
export OPTIMISM_SEPOLIA_RPC_URL=""

# Used for verifying contracts on Etherscan
export ETHERSCAN_API_KEY=""
export ARBITRUM_ETHERSCAN_API_KEY=""
export OPTIMISM_ETHERSCAN_API_KEY=""
export POLYGONSCAN_API_KEY=""

# Used to run Hardhat scripts in fork mode
export FORK_ENABLED=true

# Used to report gas usage when running Forge tests
export FORGE_GAS_REPORT=true
54 changes: 54 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: coverage

on: ["push", "pull_request"]

env:
FOUNDRY_PROFILE: ci

jobs:
forge:
strategy:
fail-fast: true
permissions:
pull-requests: write
name: Foundry project
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: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge test with gas report
env:
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
run: |
forge test --gas-report
id: test

- name: Install lcov
uses: hrishikesh-kadam/setup-lcov@v1.0.0

- name: Run Forge coverage
env:
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
run: |
forge coverage --report lcov && lcov --extract lcov.info -o lcov.info 'src/*'
id: coverage

- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v1.5.0
with:
coverage-files: lcov.info
minimum-coverage: 90
github-token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
coverage/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

.DS_Store
.envrc
lcov.info
node_modules
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.3.0
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint-staged && npm test
8 changes: 8 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"*.{json,md,sol,yml}": [
"npm run format"
],
"*.sol": [
"npm run hint"
]
}
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
artifacts
broadcast
cache
cache_hardhat
deployments
lib
out
types

package.json
14 changes: 14 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"compiler": "0.8.21",
"bracketSpacing": true,
"printWidth": 120,
"tabWidth": 4
}
}
]
}
11 changes: 11 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"avoid-low-level-calls": "off",
"compiler-version": ["error", "0.8.21"],
"func-visibility": "off",
"no-empty-blocks": "off",
"no-inline-assembly": "off"
}
}
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Foundry template

Template to kickstart a Foundry project.

## Getting started

The easiest way to get started is by clicking the [Use this template](https://github.com/GenerationSoftware/foundry-template/generate) button at the top right of this page.

If you prefer to go the CLI way:

```
forge init my-project --template https://github.com/GenerationSoftware/foundry-template
```

## Development

### Installation

You may have to install the following tools to use this repository:

- [Foundry](https://github.com/foundry-rs/foundry) to compile and test contracts
- [direnv](https://direnv.net/) to handle environment variables
- [lcov](https://github.com/linux-test-project/lcov) to generate the code coverage report

Install dependencies:

```
npm i
```

### Env

Copy `.envrc.example` and write down the env variables needed to run this project.

```
cp .envrc.example .envrc
```

Once your env variables are setup, load them with:

```
direnv allow
```

### Compile

Run the following command to compile the contracts:

```
npm run compile
```

### Coverage

Forge is used for coverage, run it with:

```
npm run coverage
```

You can then consult the report by opening `coverage/index.html`:

```
open coverage/index.html
```

### Code quality

[Husky](https://typicode.github.io/husky/#/) is used to run [lint-staged](https://github.com/okonet/lint-staged) and tests when committing.

[Prettier](https://prettier.io) is used to format TypeScript and Solidity code. Use it by running:

```
npm run format
```

[Solhint](https://protofire.github.io/solhint/) is used to lint Solidity files. Run it with:

```
npm run hint
```

### CI

A default Github Actions workflow is setup to execute on push and pull request.

It will build the contracts and run the test coverage.

You can modify it here: [.github/workflows/coverage.yml](.github/workflows/coverage.yml)

For the coverage to work, you will need to setup the `MAINNET_RPC_URL` repository secret in the settings of your Github repository.
28 changes: 28 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[profile.default]
src = 'src'
out = 'out'
test = 'test'
libs = ['lib']
solc = "0.8.21"
fs_permissions = [{ access = "read", path = "./broadcast" }]
gas_reports = ["Foo"]

[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
arbitrum = "${ARBITRUM_RPC_URL}"
optimism = "${OPTIMISM_RPC_URL}"

sepolia = "${SEPOLIA_RPC_URL}"
arbitrum-sepolia = "${ARBITRUM_SEPOLIA_RPC_URL}"
optimism-sepolia = "${OPTIMISM_SEPOLIA_RPC_URL}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}", url = "https://api.etherscan.io/api" }
arbitrum = { key = "${ARBITRUM_ETHERSCAN_API_KEY}", url = "https://api.arbiscan.io/api" }
optimism = { key = "${OPTIMISM_ETHERSCAN_API_KEY}", url = "https://api-optimistic.etherscan.io/api" }

sepolia = { key = "${ETHERSCAN_API_KEY}", url = "https://api-sepolia.etherscan.io/api" }
arbitrum-sepolia = { key = "${ARBITRUM_ETHERSCAN_API_KEY}", url = "https://api-sepolia.arbiscan.io/api" }
optimism-sepolia = { key = "${OPTIMISM_ETHERSCAN_API_KEY}", url = "https://api-sepolia-optimistic.etherscan.io/api" }

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 066ff1

0 comments on commit 4384fb9

Please sign in to comment.