Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 authored Mar 4, 2024
0 parents commit d97b212
Show file tree
Hide file tree
Showing 28 changed files with 10,753 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/alpine
{
"name": "Foundry",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "../Dockerfile"
}
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
soft_wrap = true
end_of_line = lf
[*.{sol}]
tab_width = 4
[*.{js,ts}]
tab_width = 2
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Deploy Properties

PRIVATE_KEY=

## Arbitrum
### key
ABISCAN_API_KEY=
### arbitrum-sepolia rpc
ARBITRUM_SEPOLIA_RPC=

## Localhost
### rpc
RPC_URL=http://localhost:8545
24 changes: 24 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Setup
description: Install and cache npm and node_modules to reuse them in workflows and jobs
inputs:
foundry:
description: "Boolean to flag foundry installation"

runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
cache: "npm"
node-version: 20.x
- uses: actions/cache@v4
id: cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
- run: make install-ci
shell: bash
if: steps.cache.outputs.cache-hit != 'true'
- name: Install Foundry
if: ${{ inputs.foundry }}
uses: foundry-rs/foundry-toolchain@v1
62 changes: 62 additions & 0 deletions .github/workflows/quality-gate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Quality Gate
on:
push:

concurrency:
group: quality-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
packages: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: make lint

check-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
with:
foundry: true
- run: make compile
- run: make deploy

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
with:
foundry: true
- run: make test

slither:
permissions:
# required for all workflows
security-events: write
packages: read
# only required for workflows in private repositorie
contents: read
actions: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: rm foundry.toml && touch .env
- uses: crytic/[email protected]
id: slither
with:
node-version: 20.11.0
sarif: results.sarif
fail-on: none
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cache/
out/
cache_hardhat/
artifacts/
.gas-snapshot
.vscode/
.env
.encryptedKey
broadcast/
abi/

node_modules
.yarn

.DS_Store
src/.DS_Store
local.deployment-lock.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
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"

npx lint-staged;
5 changes: 5 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

make lint;
make test;
6 changes: 6 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"src/**/*.sol": ["solhint --fix --noPrompt", "forge fmt"],
"test/**/*.sol": ["solhint --fix --noPrompt", "forge fmt"],
"integration/**/*.js": "prettier --write",
"deployment-lock.json": "prettier --write"
}
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
build
coverage
out
lib
assets
node_modules
.next
artifacts
cache_hardhat
cache
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"printWidth": 100,
"singleQuote": false
}
27 changes: 27 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-throw": "off",
"avoid-suicide": "error",
"avoid-sha3": "warn",
"compiler-version": ["error", ">=0.8.0 <0.9.0"],
"func-name-mixedcase": "off",
"var-name-mixedcase": "off",
"code-complexity": ["error", 8],
"constructor-syntax": "error",
"func-visibility": [
"error",
{
"ignoreConstructors": true
}
],
"max-line-length": ["error", 100],
"not-rely-on-time": "off",
"reason-string": [
"warn",
{
"maxLength": 64
}
]
}
}
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ghcr.io/foundry-rs/foundry:latest
WORKDIR /usr/src/app
COPY . .
RUN apk update
RUN apk add --no-cache make
RUN apk add --no-cache nodejs npm
RUN make
ENTRYPOINT ["/bin/sh","-c","sleep infinity"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Dzmitry Lahunouski, Dzianis Roi, Tikhon Scherbakov.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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 OR COPYRIGHT HOLDERS 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.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-include .env

.PHONY: all test clean install compile snapshot

all: clean install test

# Clean the repo
clean :; forge clean

# Local installation
install :; npm i && npx husky install

# CI installation
install-ci :; touch .env; npm ci

# Update Dependencies
forge-update:; forge update

compile :; npx hardhat compile

test :; forge test -vvv; npx hardhat test

snapshot :; forge snapshot

format :; forge fmt src/; forge fmt test/

lint :; npx solhint src/**/*.sol

node :; npx hardhat node

network?=hardhat

deploy :; npx hardhat --network $(network) deploy-bundle

-include ${FCT_PLUGIN_PATH}/makefile-external
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Sol-starter

Template to bootstrap solidity project

## Features

- Foundry for unit testing
- Hardhat for integration tests & deployment
- hardhat-sol-bundler for declarative and smart deployments
- linters, code formatter, pre-commit and pre-push hooks
- Makefile & Docker dev container for convenient and safe development
- Custom github action and quality gate workflow for fast CI strategy implementation

## Requirements

- [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 (f016135 2022-07-04T00:15:02.930499Z)`
- To get the latest of each, just run `foundryup`
- [Node.js](https://nodejs.org/en)
- Optional. [Docker](https://www.docker.com/)
- You'll need to run docker if you want to use dev container and safely play with smartcontracts & scripts

## Configuration

- use forge as solidity formatter in your IDE settings
For VS it's recommended to use [Juan Blanco Plugin](https://github.com/juanfranblanco/vscode-solidity) and have the next sittings.json

```json
{
"solidity.formatter": "forge",
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": ["node_modules", "lib"],
"solidity.remappings": [
"@std=lib/forge-std/src/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/=node_modules/@openzeppelin/",
"src=src/"
],
"solidity.defaultCompiler": "localNodeModule",
"[solidity]": {
"editor.defaultFormatter": "JuanBlanco.solidity"
}
}
```

## Contributing

Contributions are always welcome! Open a PR or an issue!

Please install the following:

And you probably already have `make` installed... but if not [try looking here.](https://askubuntu.com/questions/161104/how-do-i-install-make)

## Resources

- [Foundry Documentation](https://book.getfoundry.sh/)
- [Hardhat Documentation](https://hardhat.org/docs)
- [hardhat-sol-bundler Documentation](https://github.com/dgma/hardhat-sol-bundler)
```
18 changes: 18 additions & 0 deletions deployment.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { VerifyPlugin } = require("@dgma/hardhat-sol-bundler/plugins/Verify");

const config = {
Template: {},
};

module.exports = {
hardhat: {
config: config,
},
localhost: { lockFile: "./local.deployment-lock.json", config: config },
"arbitrum-sepolia": {
lockFile: "./deployment-lock.json",
verify: true,
plugins: [VerifyPlugin],
config: config,
},
};
24 changes: 24 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[profile.default]
gas_reports = ["*"]
libs = ['lib']
out = 'out'
solc-version = "0.8.20"
src = 'src'
test = 'test'

remappings = [
'@std=lib/forge-std/src/',
'forge-std/=lib/forge-std/src/',
'@openzeppelin/=node_modules/@openzeppelin/',
'src=src/'
]

[fmt]
bracket_spacing = false
line_length = 100
tab_width = 4
wrap_comments = true

# Remappings in remappings.txt

# See more config options https://github.com/gakonst/foundry/tree/master/config
Loading

0 comments on commit d97b212

Please sign in to comment.