Skip to content

Commit

Permalink
Merge pull request #44 from aragon/f/lifecycle-makefile
Browse files Browse the repository at this point in the history
Lifecycle makefile
  • Loading branch information
brickpop authored Nov 29, 2024
2 parents 0f176d3 + ace49cb commit 8240322
Show file tree
Hide file tree
Showing 8 changed files with 588 additions and 139 deletions.
28 changes: 22 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# NETWORK AND DEPLOYMENT WALLET
DEPLOYMENT_PRIVATE_KEY="..."
ALCHEMY_API_KEY="..."
ETHERSCAN_API_KEY="..."
NETWORK="holesky"
DEPLOY_AS_PRODUCTION=true # With false, the script will deploy mock helpers
# NETWORK AND ACCOUNT(s)
DEPLOYMENT_PRIVATE_KEY="0x..."
REFUND_ADDRESS="0x..."

# The name of the networks to use for test/production
TESTNET_NETWORK="holesky"
PRODNET_NETWORK="mainnet"

# The RPC of the networks to use for test/production
TESTNET_RPC_URL="https://holesky.drpc.org"
PRODNET_RPC_URL="https://eth.drpc.org"

# API Keys (optional)
# Note that having these active will slow down unit tests even when not needed
# So recommended to only activate when needed
# ALCHEMY_API_KEY="..."
# ETHERSCAN_API_KEY="..."

# MULTISIG PARAMETERS
# define a list of multisig members - said multisig will be assigned administrator roles of the ve contracts
MULTISIG_MEMBERS_JSON_FILE_NAME="/script/multisig-members.json"

# GOVERNANCE PARAMETERS
MIN_VETO_RATIO="300000" # 30% (base 1_000_000)
Expand All @@ -24,6 +39,7 @@ TAIKO_BRIDGE_ADDRESS="0xA098b76a3Dd499D3F6D58D8AcCaFC8efBFd06807" # Address of t
DAO_FACTORY="0xE640Da5AD169630555A86D9b6b9C145B4961b1EB"
PLUGIN_SETUP_PROCESSOR="0xCe0B4124dea6105bfB85fB4461c4D39f360E9ef3"
PLUGIN_REPO_FACTORY="0x95D563382BeD5AcB458759EE05b27DF2CB019Cc7"

GOVERNANCE_ERC20_BASE="0xC24188a73dc09aA7C721f96Ad8857B469C01dC9f"
GOVERNANCE_WRAPPED_ERC20_BASE="0x7a62da7B56fB3bfCdF70E900787010Bc4c9Ca42e"

Expand Down
14 changes: 14 additions & 0 deletions .env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# If deploying against a fork, pass the address of a large token holder.
# This address will be impersonated to distribute tokens to addresses inside test cases.
# The whale needs to hold at least 3000 tokens
TEST_TOKEN_WHALE=""

# If you are testing with `make test-fork-factory-*`, you need to define the address of the
# existing factory to use. Otherwise, you should use `make test-fork-*`
FACTORY_ADDRESS=""

# The block number to run test forks against
# If left empty, the live onchain state will be used, which may
# consume API calls or cause rate limits
FORK_TESTNET_BLOCK_NUMBER=2643743
FORK_PRODNET_BLOCK_NUMBER=21084855
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ docs/

# Dotenv file
.env
.env.test

lcov.info
.DS_Store

*.tree

logs/*
37 changes: 37 additions & 0 deletions DEPLOYMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@

## Holesly

### November 18th 2024

Deployment for internal testing:
- Exit window of 7 days
- L2 disabled
- Using a pre-release voting token

Deployment with the encryption registry available

```
Deploying from: 0x424797Ed6d902E17b9180BFcEF452658e148e0Ab
Chain ID: 17000
Using test token settings
Minting test tokens for the multisig members and the bridge
Factory: 0x7D3dA38E856f002f4623B0D32a494E358f72adC9
DAO: 0x8caD8b62769710233f319611d064462b633Bbb8C
Voting token: 0x18EE0C13EC97a60fc190bABB348FD87421368920
Taiko Bridge: 0x0000000000000000000000000000001234567890
Plugins
- Multisig plugin: 0xc880dB28A9105e6D69d30E93d99E38eFE84c54CB
- Emergency multisig plugin: 0x3bE6294EB67A3501bF091fD229282F2A51c532d2
- Optimistic token voting plugin: 0xBB249c027c5De908288104F665A605ceC88ad6CE
Helpers
- Signer list 0x7716DcB9B83f5f9fB5266767841c3F29555cE2d5
- Encryption registry 0x94224B656D7D174B2Aa97FFCB188A847E6EA4511
- Delegation wall 0xb8D78b40014D36F83dDc8219c0621d35E8043167
Plugin repositories
- Multisig plugin repository: 0x2d870FCedF2C1204839C3b8bca2Bf6e632b4E602
- Emergency multisig plugin repository: 0xe069Ae1DCB19A9DE9C516097FaC20ea070311D48
- Optimistic token voting plugin repository: 0xd774b0976C67832C84848dC6fdadE6189B297A71
```

### October 16th 2024

Deployment for internal testing:
Expand Down
209 changes: 194 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
.DEFAULT_TARGET: help

# Import the .env files and export their values (ignore any error if missing)
-include .env
-include .env.test

# RULE SPECIFIC ENV VARS [optional]

# Override the verifier and block explorer parameters (network dependent)
deploy-testnet: export ETHERSCAN_API_KEY_PARAM = --etherscan-api-key $(ETHERSCAN_API_KEY)
deploy-prodnet: export ETHERSCAN_API_KEY_PARAM = --etherscan-api-key $(ETHERSCAN_API_KEY)
# deploy-testnet: export VERIFIER_TYPE_PARAM = --verifier blockscout
# deploy-testnet: export VERIFIER_URL_PARAM = --verifier-url "https://server/api\?"

# CONSTANTS

TEST_COVERAGE_SRC_FILES:=$(wildcard test/*.sol test/**/*.sol script/*.sol script/**/*.sol src/escrow/increasing/delegation/*.sol src/libs/ProxyLib.sol)
DEPLOY_SCRIPT:=script/Deploy.s.sol:Deploy
VERBOSITY:=-vvv
SHELL:=/bin/bash

SOLIDITY_VERSION=0.8.17
TEST_TREE_MARKDOWN=TEST_TREE.md
SOURCE_FILES=$(wildcard test/*.t.yaml test/integration/*.t.yaml)
Expand All @@ -8,15 +27,55 @@ TARGET_TEST_FILES = $(SOURCE_FILES:.tree=.t.sol)
MAKE_TEST_TREE=deno run ./test/script/make-test-tree.ts
MAKEFILE=Makefile

# TARGETS

.PHONY: help
help:
@echo "Available targets:"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE) \
| sed -n 's/^\(.*\): \(.*\)##\(.*\)/- make \1 \3/p'
@grep -E '^[a-zA-Z0-9_-]*:.*?## .*$$' Makefile \
| sed -n 's/^\(.*\): \(.*\)##\(.*\)/- make \1 \3/p' \
| sed 's/^- make $$//g'

: ##

.PHONY: init
init: .env .env.test ## Check the dependencies and prompt to install if needed
@which deno > /dev/null && echo "Deno is available" || echo "Install Deno: curl -fsSL https://deno.land/install.sh | sh"
@which bulloak > /dev/null && echo "bulloak is available" || echo "Install bulloak: cargo install bulloak"

@which forge > /dev/null || curl -L https://foundry.paradigm.xyz | bash
@forge build
@which lcov > /dev/null || echo "Note: lcov can be installed by running 'sudo apt install lcov'"

.PHONY: clean
clean: ## Clean the build artifacts
rm -f $(TREE_FILES)
rm -f $(TEST_TREE_MARKDOWN)
rm -Rf ./out/* lcov.info* ./report/*

: ##

.PHONY: test
test: ## Run unit tests, locally
forge test $(VERBOSITY)
# forge test --no-match-path $(FORK_TEST_WILDCARD) $(VERBOSITY)

test-coverage: report/index.html ## Generate an HTML coverage report under ./report
@which open > /dev/null && open report/index.html || echo -n
@which xdg-open > /dev/null && xdg-open report/index.html || echo -n

report/index.html: lcov.info.pruned
genhtml $^ -o report --branch-coverage

all: sync markdown ## Builds all tree files and updates the test tree markdown
lcov.info.pruned: lcov.info
lcov --remove ./$< -o ./$@ $^

sync: $(TREE_FILES) ## Scaffold or sync tree files into solidity tests
lcov.info: $(TEST_COVERAGE_SRC_FILES)
forge coverage --no-match-path $(FORK_TEST_WILDCARD) --report lcov

: ##

sync-tests: $(TREE_FILES) ## Scaffold or sync tree files into solidity tests
@for file in $^; do \
if [ ! -f $${file%.tree}.t.sol ]; then \
echo "[Scaffold] $${file%.tree}.t.sol" ; \
Expand All @@ -27,10 +86,10 @@ sync: $(TREE_FILES) ## Scaffold or sync tree files into solidity tests
fi \
done

check: $(TREE_FILES) ## Checks if solidity files are out of sync
check-tests: $(TREE_FILES) ## Checks if solidity files are out of sync
bulloak check $^

markdown: $(TEST_TREE_MARKDOWN) ## Generates a markdown file with the test definitions rendered as a tree
markdown-tests: $(TEST_TREE_MARKDOWN) ## Generates a markdown file with the test definitions rendered as a tree

# Internal targets

Expand Down Expand Up @@ -59,14 +118,134 @@ $(TREE_FILES): $(SOURCE_FILES)
cat $$file | $(MAKE_TEST_TREE) > $${file%.t.yaml}.tree ; \
done

# Global
# Copy the .env files if not present
.env:
cp .env.example .env
@echo "NOTE: Edit the correct values of .env before you continue"

.PHONY: init
init: ## Check the dependencies and prompt to install if needed
@which deno > /dev/null && echo "Deno is available" || echo "Install Deno: curl -fsSL https://deno.land/install.sh | sh"
@which bulloak > /dev/null && echo "bulloak is available" || echo "Install bulloak: cargo install bulloak"
.env.test:
cp .env.test.example .env.test
@echo "NOTE: Edit the correct values of .env.test before you continue"

.PHONY: clean
clean: ## Clean the intermediary tree files
rm -f $(TREE_FILES)
rm -f $(TEST_TREE_MARKDOWN)
# : ##

# #### Fork testing ####

# test-fork-mint-testnet: export MINT_TEST_TOKENS = true
# test-fork-mint-prodnet: export MINT_TEST_TOKENS = true

# test-fork-mint-testnet: test-fork-testnet ## Clean fork test, minting test tokens (testnet)
# test-fork-mint-prodnet: test-fork-prodnet ## Clean fork test, minting test tokens (production network)

# : ##

# test-fork-testnet: export RPC_URL = $(TESTNET_RPC_URL)
# test-fork-prodnet: export RPC_URL = $(PRODNET_RPC_URL)
# test-fork-testnet: export FORK_BLOCK_NUMBER = $(FORK_TESTNET_BLOCK_NUMBER)
# test-fork-prodnet: export FORK_BLOCK_NUMBER = $(FORK_PRODNET_BLOCK_NUMBER)

# test-fork-testnet: test-fork ## Fork test using the existing token(s), new factory (testnet)
# test-fork-prodnet: test-fork ## Fork test using the existing token(s), new factory (production network)

# : ##

# # Override the fork test mode (existing factory)
# test-fork-factory-testnet: export FORK_TEST_MODE = existing-factory
# test-fork-factory-prodnet: export FORK_TEST_MODE = existing-factory

# test-fork-factory-testnet: test-fork-testnet ## Fork test using an existing factory (testnet)
# test-fork-factory-prodnet: test-fork-prodnet ## Fork test using an existing factory (production network)

# .PHONY: test-fork
# test-fork:
# @if [ -z "$(strip $(FORK_BLOCK_NUMBER))" ] ; then \
# forge test --match-contract $(E2E_TEST_NAME) \
# --rpc-url $(RPC_URL) \
# $(VERBOSITY) ; \
# else \
# forge test --match-contract $(E2E_TEST_NAME) \
# --rpc-url $(RPC_URL) \
# --fork-block-number $(FORK_BLOCK_NUMBER) \
# $(VERBOSITY) ; \
# fi

: ##

#### Deployment targets ####

pre-deploy-mint-testnet: export MINT_TEST_TOKENS = true
pre-deploy-testnet: export RPC_URL = $(TESTNET_RPC_URL)
pre-deploy-testnet: export NETWORK = $(TESTNET_NETWORK)
pre-deploy-prodnet: export RPC_URL = $(PRODNET_RPC_URL)
pre-deploy-prodnet: export NETWORK = $(PRODNET_NETWORK)

pre-deploy-mint-testnet: pre-deploy-testnet ## Simulate a deployment to the testnet, minting test token(s)
pre-deploy-testnet: pre-deploy ## Simulate a deployment to the testnet
pre-deploy-prodnet: pre-deploy ## Simulate a deployment to the production network

: ##

deploy-mint-testnet: export MINT_TEST_TOKENS = true
deploy-testnet: export RPC_URL = $(TESTNET_RPC_URL)
deploy-testnet: export NETWORK = $(TESTNET_NETWORK)
deploy-prodnet: export RPC_URL = $(PRODNET_RPC_URL)
deploy-prodnet: export NETWORK = $(PRODNET_NETWORK)

deploy-testnet: export DEPLOYMENT_LOG_FILE=./deployment-$(patsubst "%",%,$(TESTNET_NETWORK))-$(shell date +"%y-%m-%d-%H-%M").log
deploy-prodnet: export DEPLOYMENT_LOG_FILE=./deployment-$(patsubst "%",%,$(PRODNET_NETWORK))-$(shell date +"%y-%m-%d-%H-%M").log

deploy-mint-testnet: deploy-testnet ## Deploy to the testnet, mint a token and verify
deploy-testnet: deploy ## Deploy to the testnet and verify
deploy-prodnet: deploy ## Deploy to the production network and verify

.PHONY: pre-deploy
pre-deploy:
@echo "Simulating the deployment"
forge script $(DEPLOY_SCRIPT) \
--chain $(NETWORK) \
--rpc-url $(RPC_URL) \
$(VERBOSITY)

.PHONY: deploy
deploy: test
@echo "Starting the deployment"
@mkdir -p logs/
forge script $(DEPLOY_SCRIPT) \
--chain $(NETWORK) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
$(VERIFIER_TYPE_PARAM) \
$(VERIFIER_URL_PARAM) \
$(ETHERSCAN_API_KEY_PARAM) \
$(VERBOSITY) | tee logs/$(DEPLOYMENT_LOG_FILE)

: ##

refund: export DEPLOYMENT_ADDRESS = $(shell cast wallet address --private-key $(DEPLOYMENT_PRIVATE_KEY))

.PHONY: refund
refund: ## Refund the remaining balance left on the deployment account
@echo "Refunding the remaining balance on $(DEPLOYMENT_ADDRESS)"
@if [ -z $(REFUND_ADDRESS) -o $(REFUND_ADDRESS) = "0x0000000000000000000000000000000000000000" ]; then \
echo "- The refund address is empty" ; \
exit 1; \
fi
@BALANCE=$(shell cast balance $(DEPLOYMENT_ADDRESS) --rpc-url $(PRODNET_RPC_URL)) && \
GAS_PRICE=$(shell cast gas-price --rpc-url $(PRODNET_RPC_URL)) && \
REMAINING=$$(echo "$$BALANCE - $$GAS_PRICE * 21000" | bc) && \
\
ENOUGH_BALANCE=$$(echo "$$REMAINING > 0" | bc) && \
if [ "$$ENOUGH_BALANCE" = "0" ]; then \
echo -e "- No balance can be refunded: $$BALANCE wei\n- Minimum balance: $${REMAINING:1} wei" ; \
exit 1; \
fi ; \
echo -n -e "Summary:\n- Refunding: $$REMAINING (wei)\n- Recipient: $(REFUND_ADDRESS)\n\nContinue? (y/N) " && \
\
read CONFIRM && \
if [ "$$CONFIRM" != "y" ]; then echo "Aborting" ; exit 1; fi ; \
\
cast send --private-key $(DEPLOYMENT_PRIVATE_KEY) \
--rpc-url $(PRODNET_RPC_URL) \
--value $$REMAINING \
$(REFUND_ADDRESS)
Loading

0 comments on commit 8240322

Please sign in to comment.