Skip to content

Commit

Permalink
Merge pull request #37 from aragon/f/static-env-file
Browse files Browse the repository at this point in the history
Static env files
  • Loading branch information
brickpop authored Oct 31, 2024
2 parents d1db1e9 + f87f6e2 commit 5dcc440
Show file tree
Hide file tree
Showing 11 changed files with 614 additions and 354 deletions.
39 changes: 15 additions & 24 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
# Fork Test mode:
# "fork-deploy" will run against the live network fork, deploying new contracts via a new instance of the factory
# "fork-existing" will run against the live network fork, using the existing factory & therefore the existing contracts
FORK_TEST_MODE="fork-deploy"
# NETWORK AND ACCOUNT(s)
DEPLOYMENT_PRIVATE_KEY="0x..."
REFUND_ADDRESS="0x..."

# With false, the script will deploy mock tokens with open mint functions
DEPLOY_AS_PRODUCTION=false
# The name of the networks to use for test/production
TESTNET_NETWORK="holesky"
PRODNET_NETWORK="mainnet"

# If deploying against a fork, pass the address of a large token holder who will be
# impersonated to distribute tokens to addresses inside test cases
# the whale should have >= 3000 tokens
TOKEN_TEST_WHALE="0x"

# If the factory singleton is deployed, pass the address. "Fork existing" mode will use this previously
# deployed factory, and "fork deploy" will deploy a new factory instance
FACTORY="0x0000000000000000000000000000000000000000"

# NETWORK AND DEPLOYMENT WALLET
DEPLOYMENT_PRIVATE_KEY="..."
NETWORK="sepolia"
# 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
# ETHERSCAN_API_KEY="..."
# ALCHEMY_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"
MIN_APPROVALS="1" # How many multisig approvals are required
MIN_APPROVALS="1" # How many multisig approvals are required
MULTISIG_PROPOSAL_EXPIRATION_PERIOD="864000" # How long until a pending proposal expires (10 days)

# GAUGE VOTER PARAMETERS
# The token to be used for the escrow
# The main token for the escrow and the escrow details
TOKEN1_ADDRESS="0x0000000000000000000000000000000000000000"
VE_TOKEN1_NAME="Voting Escrow Token 1"
VE_TOKEN1_SYMBOL="veTK1"

# Additional tokens these will have secondary escrow contracts
TOKEN2_ADDRESS="0x0000000000000000000000000000000000000000" # Ignored if 0x0
# Additional tokens (optional)
# Each token gets its own escrow
TOKEN2_ADDRESS="0x0000000000000000000000000000000000000000" # Ignored when zero
VE_TOKEN2_NAME="Voting Escrow Token 2"
VE_TOKEN2_SYMBOL="veTK2"

Expand All @@ -59,7 +50,7 @@ MIN_LOCK_DURATION="3600" # 1 hour
VOTING_PAUSED=true

# Initial minimum amount needed (in wei) to create a lock
MIN_DEPOSIT="1000000000000000000" # 1 ether
MIN_DEPOSIT="1000000000000000000" # 1 ether (in token terms)

# PLUGIN REPO PARAMETERS (per-network)
# SEPOLIA
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="0x0000000000000000000000000000000000000000"

# 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="0x0000000000000000000000000000000000000000"

# The block number to run fork tests on
# 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=
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
^.env.example
.env*
!.env.example
!.env.test.example

# Logs
*.log

# Foundry
cache/
Expand Down
239 changes: 180 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,68 +1,189 @@
.DEFAULT_TARGET: help

# include .env file and export its env vars
# (-include to ignore error if it does not exist)
# Import the .env files and export their values (ignore any error if missing)
-include .env
-include .env.test

# linux: allow shell scripts to be executed
allow-scripts:; chmod +x ./coverage.sh
# RULE SPECIFIC ENV VARS [optional]

# init the repo
install :; make allow-scripts && forge build
# Override the verifier and block explorer parameters (network dependent)
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://sepolia.explorer.mode.network/api\?"

# create an HTML coverage report in ./report (requires lcov & genhtml)
coverage:; ./coverage.sh
#
# run unit tests
test-unit :; forge test --no-match-path "test/fork/**/*.sol"
# CONSTANTS

TEST_COVERAGE_SRC_FILES:=$(wildcard test/*.sol test/**/*.sol script/*.sol script/**/*.sol src/escrow/increasing/delegation/*.sol src/libs/ProxyLib.sol)
FORK_TEST_WILDCARD:="test/fork/**/*.sol"
E2E_TEST_NAME:=TestE2EV2
DEPLOY_SCRIPT:=script/DeployGauges.s.sol:DeployGauges
VERBOSITY:=-vvv
SHELL:=/bin/bash

# TARGETS

.PHONY: help
help:
@echo "Available targets:"
@echo
@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 required tools and dependencies
@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 -Rf ./out/* lcov.info* ./report/*

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

.env.test:
cp .env.test.example .env.test
@echo "NOTE: Edit the correct values of .env.test before you continue"

: ##

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

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

lcov.info.pruned: lcov.info
lcov --remove ./$< -o ./$@ $^

lcov.info: $(TEST_COVERAGE_SRC_FILES)
forge coverage --no-match-path $(FORK_TEST_WILDCARD) --report lcov

: ##

#### Fork testing ####

# Fork testing - mode sepolia
ft-mode-sepolia-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://sepolia.mode.network \
-vv

# Fork testing - mode mainnet
ft-mode-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://mainnet.mode.network/ \
-vvvvv

# Fork testing - holesky
ft-holesky-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://holesky.drpc.org \
-vvvvv

# Fork testing - sepolia
ft-sepolia-fork :; forge test --match-contract TestE2EV2 \
--rpc-url https://sepolia.drpc.org \
-vvvvv

#### Deployments ####

deploy-preview-mode-sepolia :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://sepolia.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
-vvvvv

deploy-mode-sepolia :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://sepolia.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
--broadcast \
--verify \
--verifier blockscout \
--verifier-url https://sepolia.explorer.mode.network/api\? \
-vvvvv

deploy-preview-mode :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://mainnet.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
-vvvvv

deploy-mode :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://mainnet.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
--broadcast \
--verify \
--etherscan-api-key $(ETHERSCAN_API_KEY) \
-vvv
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-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-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"
forge script $(DEPLOY_SCRIPT) \
--chain $(NETWORK) \
--rpc-url $(RPC_URL) \
--broadcast \
--verify \
$(VERIFIER_TYPE_PARAM) \
$(VERIFIER_URL_PARAM) \
$(ETHERSCAN_API_KEY_PARAM) \
$(VERBOSITY) | tee $(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 5dcc440

Please sign in to comment.