Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid authored Oct 2, 2024
0 parents commit 619942b
Show file tree
Hide file tree
Showing 18 changed files with 3,066 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Mnemonic phrase
MNEMONIC=""

# Private key
PRIVATE_KEY=""

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

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

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

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

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

on: ["push", "pull_request"]

env:
FOUNDRY_PROFILE: ci

jobs:
forge:
environment: ci
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/[email protected]

- 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/[email protected]
with:
coverage-files: lcov.info
minimum-coverage: 100
github-token: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Compiler files
cache/
coverage/
out/

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

# Mac
.DS_Store

# Secrets
.env
.envrc

# Coverage
lcov.info

# VS Code
.history

# Modules
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.24",
"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.24"],
"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.24"
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
Loading

0 comments on commit 619942b

Please sign in to comment.