diff --git a/.editorconfig b/.editorconfig index e15b2b1df..243e9f40b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 3d615903e..dde0217ae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ +# -*- mode: gitattributes; -*- +justfile linguist-language=Make +*.t.sol linguist-language=Solidity .dapprc linguist-language=Shell * text=auto eol=lf diff --git a/.gitignore b/.gitignore index ad3d4baa8..baeaa7d94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .DS_Store cache/ artifacts/ - +out/ coverage* /types/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 2c5d69346..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "test/dapp_test/lib/ds-test"] - path = test/dapp_test/lib/ds-test - url = https://github.com/dapphub/ds-test diff --git a/foundry.toml b/foundry.toml new file mode 100644 index 000000000..c5bfa0050 --- /dev/null +++ b/foundry.toml @@ -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 diff --git a/justfile b/justfile new file mode 100755 index 000000000..6e2293123 --- /dev/null +++ b/justfile @@ -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 +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 : \ No newline at end of file