Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(foundry): 100% migration from dapptools #311

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,81 @@
# top-most EditorConfig file
root = true

# All files
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.sol]
indent_size = 4

# Markdown
[*.{md,adoc,asciidoc}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = false

# Match nix files, set indent to spaces with width of two
[*.nix]
indent_style = space
indent_size = 2

# JavaScript, JSON, JSX, JavaScript Modules, TypeScript
# https://github.com/feross/standard
# https://prettier.io
[*.{cjs,js,json,jsx,mjs,ts,tsx}]
indent_size = 2
indent_style = space

# HTML
# https://google.github.io/styleguide/htmlcssguide.xml#General_Formatting_Rules
[*.{htm,html}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
# TOML
# https://github.com/toml-lang/toml/tree/master/examples
[*.toml]
indent_size = 2
indent_style = space

[*.sol]
indent_size = 4
# YAML
# http://yaml.org/spec/1.2/2009-07-21/spec.html#id2576668
[*.{yaml,yml}]
indent_size = 2
indent_style = space

# Shell
# https://google.github.io/styleguide/shell.xml#Indentation
[*.{bash,sh,zsh}]
indent_size = 2
indent_style = space

# confg + cfg
[*.{conf,cfg}]
charset = UTF-8
end_of_line = LF
indent_size = 4
indent_style = tab
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true

# Match diffs, avoid to trim trailing whitespace
[*.{diff,patch}]
trim_trailing_whitespace = false


# Ignore fixtures and vendored files
[{dist,artifacts,vendor,test/fixtures}/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
insert_final_newline = unset
trim_trailing_spaces = unset
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# -*- mode: gitattributes; -*-
justfile linguist-language=Make
*.t.sol linguist-language=Solidity
.dapprc linguist-language=Shell
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
cache/
artifacts/

out/
coverage*
/types/

Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

47 changes: 47 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[default]
auto_detect_solc = true
block_base_fee_per_gas = 0
block_coinbase = '0x0000000000000000000000000000000000000000'
block_difficulty = 0
block_number = 1
block_timestamp = 1
bytecode_hash = 'none'
cache = true
cache_path = 'cache'
evm_version = 'london'
extra_output = []
extra_output_files = []
ffi = false
force = false
fuzz_max_global_rejects = 65536
fuzz_max_local_rejects = 1024
fuzz_runs = 1024
gas_limit = 9223372036854775807
gas_price = 0
gas_reports = ['*']
ignored_error_codes = [1878]
initial_balance = '0xffffffffffffffffffffffff'
libraries = []
libs = ['node_modules', 'test/dapp_test/src']
memory_limit = 33554432
names = false
no_storage_caching = false
offline = false
optimizer = true
optimizer_runs = 1024
out = 'out'
remappings = [
'@ensdomains/=node_modules/@ensdomains/',
'@openzeppelin/=node_modules/@openzeppelin/',
'@rari-capital/=node_modules/@rari-capital/',
'hardhat/=node_modules/hardhat/',
"ds-test/=test/dapp_test/lib/ds-test/src/"
]
sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
sizes = false
sparse_mode = false
src = 'contracts'
test = 'test'
tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
verbosity = 3
via_ir = false
103 changes: 103 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env just --justfile
# OlympusDAO (c) 2022
# github.com/casey/just#packages

bt := '0'
export RUST_BACKTRACE := bt

log := "warn"
export JUST_LOG := log

_default:
just --list

# load .env file
set dotenv-load

# pass justfile recipe args as positional arguments to commands
set positional-arguments

# sourced from https://github.com/sense-finance/sense-v1
DAPP_BUILD_OPTIMIZE := "1"
DAPP_COVERAGE := "1"
DAPP_TEST_FUZZ_RUNS := "100"

# 1e18 decimals
HEX_18 := "0x0000000000000000000000000000000000000000000000000000000000000012"
HEX_12 := "0x000000000000000000000000000000000000000000000000000000000000000c"
HEX_8 := "0x0000000000000000000000000000000000000000000000000000000000000008"
HEX_6 := "0x0000000000000000000000000000000000000000000000000000000000000006"

# set mock target to 18 decimals by default
FORGE_MOCK_TARGET_DECIMALS := env_var_or_default("FORGE_MOCK_TARGET_DECIMALS", HEX_18)
FORGE_MOCK_UNDERLYING_DECIMALS := env_var_or_default("FORGE_MOCK_UNDERLYING_DECIMALS", HEX_18)

# Alchemy API Key is public
# Mnemonic is hardhat's default
ALCHEMY_KEY := env_var_or_default("ALCHEMY_KEY", "vI8OBZj4Wue9yNPSDVa7Klqt-UeRywrx")
MAINNET_RPC := "https://eth-mainnet.alchemyapi.io/v2/" + ALCHEMY_KEY
MNEMONIC := env_var_or_default("MNEMONIC", "test test test test test test test test test test test junk")

# export just vars as env vars
set export

# Contract Size
size:
forge build --sizes --force

# Build Output
build: && _timer
cd {{ invocation_directory() }}; forge build --sizes --names --force

# [TEST] mainnet test
build-mainnet: && _timer
cd {{ invocation_directory() }}; forge test --match-path "*.t.sol" --fork-url {{ MAINNET_RPC }}

# [TEST] default test scripts
test: test-local

# [TEST] run local forge test using --match-path <PATTERN>
test-local *commands="": && _timer
cd {{ invocation_directory() }}; forge test --match-path "*.t.sol" {{ commands }}

# [TEST] run mainnet fork forge tests (all files with the extension .t.sol)
test-mainnet *commands="": && _timer
cd {{ invocation_directory() }}; forge test --rpc-url {{ MAINNET_RPC }} --match-path "*.t.sol" {{ commands }}

# [TEST] run mainnet fork forge debug tests (all files with the extension .t.sol)
test-debug *commands="": && _timer
cd {{ invocation_directory() }}; forge test --rpc-url {{ MAINNET_RPC }} --match-path "*.t.sol" {{ commands }}


# [GAS] default gas snapshot script
gas-snapshot: gas-snapshot-local

# [GAS] get gas snapshot from local tests and save it to file
gas-snapshot-local:
cd {{ invocation_directory() }}; \
just test-local | grep 'gas:' | cut -d " " -f 2-4 | sort > \
{{ justfile_directory() }}/gas-snapshots/.$( \
cat {{ invocation_directory() }}/package.json | jq .name | tr -d '"' | cut -d"/" -f2- \
)
# [GAS] get gas snapshot timer
forge-gas-snapshot: && _timer
@cd {{ invocation_directory() }}; forge snapshot --no-match-path ".*.*"

forge-gas-snapshot-diff: && _timer
@cd {{ invocation_directory() }}; forge snapshot --no-match-path ".*.*" --diff

# Solidity test ffi callback to get Target decimals for the base Mock Target token
_forge_mock_target_decimals:
@printf {{ FORGE_MOCK_TARGET_DECIMALS }}

_forge_mock_underlying_decimals:
@printf {{ FORGE_MOCK_UNDERLYING_DECIMALS }}

# [UTILS] utility functions
start_time := `date +%s`
_timer:
@echo "[TASK]: Executed in $(($(date +%s) - {{ start_time }})) seconds"

# mode: makefile
# End:
# vim: set ft=make :