-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: initial foundry deployment/utils/tests
Co-authored-by: Sean Casey <[email protected]> Co-authored-by: Paweł Kędzia <[email protected]>
- Loading branch information
1 parent
da8ed1e
commit 667381b
Showing
54 changed files
with
7,001 additions
and
1,484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ cache/ | |
artifacts/ | ||
deployments/ | ||
node_modules/ | ||
tests/interfaces/internal/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ deployments/ | |
|
||
# Ignore dependencies. | ||
lib/ | ||
|
||
# Ignore tests directory (uses `forge fmt`). | ||
tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,133 @@ | ||
clean: | ||
git clean -dfX --exclude !**/.env* --exclude !**/cache/hardhat-network-fork | ||
# See https://tech.davis-hansson.com/p/make | ||
SHELL := bash | ||
.ONESHELL: | ||
.SHELLFLAGS := -eu -o pipefail -c | ||
.DELETE_ON_ERROR: | ||
.DEFAULT_GOAL := all | ||
|
||
MAKEFLAGS += --warn-undefined-variables | ||
MAKEFLAGS += --no-builtin-rules | ||
|
||
ifndef VERBOSE | ||
MAKEFLAGS += --silent | ||
endif | ||
|
||
ifeq ($(origin .RECIPEPREFIX), undefined) | ||
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later) | ||
endif | ||
.RECIPEPREFIX = > | ||
|
||
CAST := cast | ||
FORGE := forge | ||
|
||
TESTS_DIR := tests/ | ||
CONTRACTS_DIR := contracts/ | ||
ARTIFACTS_DIR := artifacts/ | ||
INTERFACES_DIR := tests/interfaces/internal/ | ||
INTERFACES_LICENSE_HEADER := // SPDX-License-Identifier: Unlicense | ||
|
||
.PHONY: help | ||
help: ## Describe useful make targets | ||
> grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}' | ||
|
||
.PHONY: all | ||
all: build lint test ## Run build, lint (default) | ||
|
||
.PHONY: build | ||
build: artifacts interfaces ## Build all contract artifacts & interfaces | ||
|
||
.PHONY: artifacts | ||
artifacts: $(ARTIFACTS_DIR) ## Build all contract artifacts | ||
|
||
.PHONY: interfaces | ||
interfaces: $(INTERFACES_DIR) ## ## Generate interfaces for all contracts listed in interfaces.txt | ||
|
||
.PHONY: test | ||
test: ## Run the entire test suite | ||
> $(FORGE) test | ||
|
||
.PHONY: lint | ||
lint: ## Lint all contract source files | ||
# TODO: Switch to `forge fmt` for the contract source files too. | ||
> $(FORGE) fmt --check $(TESTS_DIR) $(INTERFACES_DIR) | ||
|
||
.PHONY: format | ||
format: ## Format all contract source files | ||
# TODO: Switch to `forge fmt` for the contract source files too. | ||
> $(FORGE) fmt $(TESTS_DIR) $(INTERFACES_DIR) | ||
|
||
.PHONY: clean | ||
clean: ## Remove all untracked files and directories | ||
> git clean -dfX --exclude !**/.env* --exclude !**/deployments --exclude !**/cache/hardhat-network-fork | ||
|
||
$(ARTIFACTS_DIR): Makefile $(shell find $(CONTRACTS_DIR) -type f -name "*.sol") | ||
> mkdir -p $(@D) | ||
> # Remove this once the `forge build` command supports a more capable version of the `--skip` option. | ||
> export FOUNDRY_TEST=this-directory-does-not-exist | ||
> $(FORGE) build --extra-output-files abi | ||
> touch $@ | ||
|
||
$(INTERFACES_DIR): Makefile $(ARTIFACTS_DIR) interfaces.txt | ||
> mkdir -p $(@D) | ||
> | ||
> # Remove all existing interfaces and abis. | ||
> find $(INTERFACES_DIR) -type f -name "*.sol" -delete | ||
> find $(INTERFACES_DIR) -type f -name "*.abi.json" -delete | ||
> | ||
> # Read interfaces.txt line by line and use `cast interface` to generate the interfaces. | ||
> while read -r line; do | ||
> # Skip empty lines and lines starting with `#`. | ||
> if [[ -z "$$line" || "$$line" == \#* ]]; then | ||
> continue | ||
> fi | ||
> | ||
> # The line format is `output: input`. | ||
> output="$$(echo $$line | cut -d ':' -f1 | xargs)" | ||
> input="$$(echo $$line | cut -d ':' -f2 | xargs)" | ||
> if [[ -z "$$output" || -z "$$input" ]]; then | ||
> echo "Invalid line format n interfaces.txt ($$line)" | ||
> exit 1; | ||
> fi | ||
> | ||
> # Extract the output name of the interface from the output path. | ||
> name="$$(basename $$output | cut -d '.' -f1)" | ||
> if [[ -z "$$name" ]]; then | ||
> echo "Invalid output $$output in interfaces.txt" | ||
> exit 1 | ||
> fi | ||
> | ||
> # Prepend the interfaces directory to the output path and check the file extension. | ||
> output="$(INTERFACES_DIR)$$output" | ||
> if [[ ! "$$input" == *.abi.json ]]; then | ||
> echo "Invalid extension for interface source $$input" | ||
> exit 1 | ||
> fi | ||
> | ||
> # If the input is a path, use it directly. Otherwise, try to find the file in the artifacts directory. | ||
> if echo "$$input" | grep -q "/"; then | ||
> path="$$input" | ||
> else | ||
> path="$$(find $(ARTIFACTS_DIR) -type f -name $$input | head -n 1)" | ||
> fi | ||
> | ||
> # Check if the source file was found. | ||
> if [[ -z "$$path" || ! -f "$$path" ]]; then | ||
> echo "Failed to locate source file for $$input" | ||
> exit 1 | ||
> fi | ||
> | ||
> dir="$$(dirname $$output)" | ||
> abi="$$dir/$$name.abi.json" | ||
> | ||
> # Create the parent directory and copy the abi file over. | ||
> mkdir -p "$$dir" | ||
> cp "$$path" "$$abi" | ||
> | ||
> # Generate the interface using `cast interface`. | ||
> $(CAST) interface "$$abi" -o "$$output" -n "$$name" | ||
> | ||
> # Add a license header to the generated interface. | ||
> echo -e "$(INTERFACES_LICENSE_HEADER)\n$$(cat $$output)" > $$output | ||
> done < "interfaces.txt" | ||
> | ||
> touch $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,43 +4,85 @@ | |
|
||
Enzyme is an Ethereum-based protocol for decentralized on-chain asset management. It is a protocol for people or entities to manage their wealth & the wealth of others within a customizable and safe environment. Enzyme empowers anyone to set up, manage and invest in customized on-chain investment vehicles. | ||
|
||
## Install | ||
## Security Issues and Bug Bounty | ||
|
||
If you find a vulnerability that may affect live deployments, you can submit a report via: | ||
|
||
A. Immunefi(https://immunefi.com/bounty/enzymefinance/), or | ||
|
||
B. Direct email to [[email protected]](mailto:[email protected]) | ||
|
||
Please **DO NOT** open a public issue. | ||
|
||
## Using this Repo | ||
|
||
### A Tale of Two Frameworks | ||
|
||
:construction: | ||
|
||
This repo is currently in-flux for a gradual move from Hardhat to Foundry, so there are mixed dependencies, deployment mechanisms, helpers, and tests. The following rules should hold: | ||
|
||
- all production contracts live in `contracts/persistent/` and `contracts/release/` (deployed contracts [here](https://docs.enzyme.finance/developers/contracts)) | ||
- the "old" Hardhat-based dependencies / deployment / helpers / tests live in `packages/` | ||
- the "new" Foundry-based dependencies / deployment / helpers / tests live in `tests/` | ||
|
||
Test suites are being gradually migrated from the Hardhat setup to Foundry, so check both for test coverage. | ||
|
||
### Prerequisites | ||
|
||
1. Make sure to have the following installed: | ||
|
||
- [node](https://www.nodejs.org) | ||
- [pnpm](https://pnpm.io) | ||
- [foundry](https://github.com/foundry-rs/foundry) | ||
- [make](https://www.gnu.org/software/make/) | ||
|
||
```sh | ||
2. Clone this repo: | ||
|
||
``` | ||
git clone [GIT_REPOSITORY_URL] | ||
cd protocol | ||
``` | ||
|
||
### Dependencies | ||
|
||
1. Install node packages: | ||
|
||
```sh | ||
pnpm install | ||
``` | ||
|
||
## Compile contracts | ||
2. Generate internal interfaces for foundry deployment and tests: | ||
|
||
```sh | ||
make build | ||
``` | ||
|
||
### Compile contracts | ||
|
||
```sh | ||
pnpm compile | ||
``` | ||
|
||
## Test | ||
### Run tests | ||
|
||
First, create a `.env` file by copying `.env.example`. Input your Ethereum node endpoint info as-needed (generally, only setting `ETHEREUM_NODE_MAINNET` is fine). | ||
1. Create a `.env` file by copying `.env.example`. Input your Ethereum (and/or other networks) node endpoint info as-needed (generally, only setting `ETHEREUM_NODE_MAINNET`, `ETHEREUM_NODE_POLYGON`, etc is fine). | ||
|
||
Then, you can run tests. The full test suite can be run with: | ||
2. Run hardhat tests with (defaults to full test suite): | ||
|
||
```sh | ||
pnpm test | ||
``` | ||
|
||
3. Run foundry tests with (defaults to full test suite): | ||
|
||
```sh | ||
forge test | ||
``` | ||
|
||
Note that tests might fail on the first runs while building a cache for the fork block, due to timeout. Continue to run tests as-needed, which will build the cache. | ||
|
||
## Contribute | ||
|
||
See [our contributing instructions](CONTRIBUTING.md). | ||
|
||
Please note that all repositories hosted under this organization follow our [Code of Conduct](CODE_OF_CONDUCT.md), make sure to review and follow it. | ||
|
||
### Security Issues | ||
|
||
If you find a vulnerability that may affect live or testnet deployments, please send your report privately to [[email protected]](mailto:[email protected]). Please **DO NOT** file a public issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.