Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter authored Sep 23, 2024
0 parents commit 4828945
Show file tree
Hide file tree
Showing 61 changed files with 12,885 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .env.EXAMPLE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PK=0x{$INSERT_KEY_HERE}

MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/{$INSERT_KEY_HERE}
ETHERSCAN_API_URL=https://api.etherscan.io/api
ETHERSCAN_API_KEY={$INSERT_KEY_HERE}

POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/{$INSERT_KEY_HERE}
POLYGONSCAN_API_URL=https://api.polygonscan.com/api
POLYGONSCAN_API_KEY={$INSERT_KEY_HERE}

FRAXTAL_RPC_URL=https://rpc.frax.com
FRAXTAL_TESTNET_RPC_URL=https://rpc.testnet.frax.com
FRAXSCAN_API_URL=https://api.fraxscan.com/api
FRAXSCAN_TESTNET_API_URL=https://api-holesky.fraxscan.com/api
FRAXSCAN_API_KEY={$INSERT_KEY_HERE}
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: master
pull_request:
branches: master
jobs:
build:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
MAINNET_URL: ${{ secrets.MAINNET_RPC_URL }}
FOUNDRY_PROFILE: "test"
steps:
- uses: actions/setup-node@v2
with:
node-version: 16.x
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2
with:
version: 8.11.0

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- run: pnpm i
- run: pnpm lint:check
- run: forge build
- run: forge test
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Compiler files
cache/
out/

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

# Docs
docs/

# Dotenv file
.env

#misc
node_modules
.DS_Store
.vscode
lcov.info
report/
.idea/
1 change: 1 addition & 0 deletions .husky/_/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
8 changes: 8 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"*.{js,json,ts,yaml,yml}": [
"prettier --config ./.prettierrc.json --write"
],
"*.sol": [
"forge fmt", "prettier --config ./.prettierrc.json --write"
]
}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public-hoist-pattern=*
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# directories
out
broadcast
cache
artifacts

# files
*.env

21 changes: 21 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "auto",
"printWidth": 120,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"plugins": ["prettier-plugin-svelte", "prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"bracketSpacing": true,
"tabWidth": 4,
"singleQuote": false,
"parser": "solidity-parse"
}
}
]
}
24 changes: 24 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"code-complexity": ["warn", 8],
"compiler-version": ["warn", ">=0.8.0"],
"const-name-snakecase": "warn",
"constructor-syntax": "error",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"max-line-length": ["warn", 120],
"not-rely-on-time": "warn",
"prettier/prettier": [
"warn",
{
"endOfLine": "auto"
}
],
"reason-string": ["warn", { "maxLength": 32 }],
"func-param-name-mixedCase": "warn",
"named-parameters-mapping": "warn",
"private-vars-leading-underscore": "warn",
"no-console": "warn"
}
}
3 changes: 3 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# directories
**/artifacts
**/node_modules
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Frax Template

## Optional Setup
Add:
```
function profile() {
FOUNDRY_PROFILE=$1 "${@:2}"}
```
To easily execute specific foundry profiles like `profile test forge test -w`

## Installation
`pnpm i`

## Compile
`forge build`

## Test
`profile test forge test`

`profile test forge test -w` watch for file changes

`profile test forge test -vvv` show stack traces for failed tests

## Deploy
- Update environment variables where needed
- `source .env`
```
`forge script src/script/{ScriptName}.s.sol \
--rpc-url ${mainnet || fraxtal || fraxtal_testnet || polygon} \
--etherscan-api-key {$ETHERSCAN_API_KEY || FRAXSCAN_API_KEY || POLYGONSCAN_API_KEY} \
--broadcast --verify --watch
```

## Tooling
This repo uses the following tools:
- frax-standard-solidity for testing and scripting helpers
- forge fmt & prettier for code formatting
- lint-staged & husky for pre-commit formatting checks
- solhint for code quality and style hints
- foundry for compiling, testing, and deploying
80 changes: 80 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# To easily switch between profiles add the following to your
# .bashrc or .zshrc: function profile() { FOUNDRY_PROFILE=$1 "${@:2}" }
# Then you can invoke like this: `profile test forge build -w`

# See more config options https://github.com/foundry-rs/foundry/tree/master/config

[profile.default]
# The source directory
src = 'src/contracts'
# the test directoy
test = 'src/test'
# The artifact directory
out = 'out'
# The script directory
script = "src/script"
# A list of paths to look for libraries in
libs = ['lib', 'node_modules']
# Whether or not to enable `vm.ffi`
ffi = false
# Enables or disables the optimizer
optimizer = false
# The number of optimizer runs
optimizer_runs = 200
# use the via-ir compiler flag
via_ir = false
# include metadata hash in bytecode
bytecode_hash = "none"
# Whether to append the metadata hash to the bytecode
cbor_metadata = false
# Contracts to track with --gas-report
#gas_reports = []

[fuzz]
# Amount of runs per fuzz test
runs = 1024

[profile.src]
test = "_" # Makes building faster
script = "_"
optimizer = false

[profile.script]
src = "_"
test = "_"
optimizer = false

[profile.deploy]
src = "_"
test = "_"
optimizer = true
optimizer_runs = 1_000_000
via_ir = true

[profile.test]
src = "_"
script = "_"
optimizer = false
build_info = false
extra_output = []
verbosity = 3
via_ir = false

[fmt]
line_length = 1000 # This gets overriden by prettier afterwards
tab_width = 4
bracket_spacing = true
int_types = "long"
number_underscore = "thousands"

[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
polygon = "${POLYGON_RPC_URL}"
fraxtal = "${FRAXTAL_RPC_URL}"
fraxtal_testnet = "${FRAXTAL_TESTNET_RPC_URL}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}", url = "${ETHERSCAN_API_URL}" }
polygon = { key = "${POLYGONSCAN_API_KEY}", url = "${POLYGONSCAN_API_URL}" }
fraxtal = { key = "${FRAXSCAN_API_KEY}", url = "${FRAXSCAN_API_URL}", chain=252 }
fraxtal_testnet = { key = "${FRAXSCAN_API_KEY}", url = "${FRAXSCAN_TESTNET_API_URL}", chain=2522 }
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "frax-template",
"version": "1.3.0",
"description": "",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"lint:check": "prettier --check '**/*.(sol)' --ignore-path=.gitignore",
"lint:fix-all": "prettier --write '**/*.(sol)' --ignore-path=.gitignore",
"test": "forge test",
"prepare": "husky install",
"format": "forge fmt src && prettier --config ./.prettierrc.json --write src && forge fmt test && prettier --config ./.prettierrc.json --write test",
"generate:constants": "ts-node -T scripts/generateConstants.ts",
"deploy:mainnet": "forge script src/script{$ENTER_SCRIPT_FILE_HERE} --rpc-url $MAINNET_RPC_URL -vvvv --broadcast --verify --slow",
"deploy:polygon": "forge script src/script{$ENTER_SCRIPT_FILE_HERE} --rpc-url $POLYGON_RPC_URL -vvvv --broadcast --verify --slow"
},
"author": "Frax Finance",
"license": "ISC",
"devDependencies": {
"@openzeppelin/contracts": "^5.0.1",
"husky": "^8.0.3",
"lint-staged": "^13.3.0",
"prettier": "^3.2.4",
"prettier-plugin-solidity": "^1.3.1",
"prettier-plugin-svelte": "^3.1.2",
"solhint": "^3.6.2",
"solhint-plugin-prettier": "^0.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"ds-test": "github:dapphub/ds-test",
"forge-std": "github:foundry-rs/forge-std#e8a047e3f40f13fa37af6fe14e6e06283d9a060e",
"frax-standard-solidity": "github:FraxFinance/frax-standard-solidity",
"solidity-bytes-utils": "github:GNSPS/solidity-bytes-utils"
}
}
Loading

0 comments on commit 4828945

Please sign in to comment.