From ac0d2390ad9c2c5f8f2fdca4532785e1e0bf85e4 Mon Sep 17 00:00:00 2001 From: "John McClure (pickleback)" Date: Fri, 5 Jul 2024 02:49:50 -0500 Subject: [PATCH] add fork config --- docker-compose.anvil.yaml | 5 ++-- docker-compose.blocktime.yaml | 5 ---- docker-compose.fork.yaml | 54 +++++++++++++++++++++++++++++++++++ env/env.common | 1 + env/env.fork | 1 + env/env.images | 4 +-- setup_env.sh | 27 +++++++++++++++--- 7 files changed, 84 insertions(+), 13 deletions(-) delete mode 100644 docker-compose.blocktime.yaml create mode 100644 docker-compose.fork.yaml create mode 100644 env/env.fork diff --git a/docker-compose.anvil.yaml b/docker-compose.anvil.yaml index 5ef0024..7812ada 100644 --- a/docker-compose.anvil.yaml +++ b/docker-compose.anvil.yaml @@ -7,9 +7,11 @@ services: # as soon as transactions are received, or with manual commands. # this is "hecking fast" mode. command: | - 'anvil --load-state ./data --host 0.0.0.0 --code-size-limit 9999999999 --chain-id ${CHAIN_ID}' + 'anvil ${ANVIL_STATE_SOURCE} ${ANVIL_BLOCKTIME} --chain-id=${CHAIN_ID} --host 0.0.0.0 --code-size-limit 9999999999' volumes: - artifacts:/src/artifacts/ + env_file: + - .env # Mine the first block to prevent overflow/underflow errors on the first # read calls. @@ -46,6 +48,5 @@ services: env_file: - .env - volumes: artifacts: diff --git a/docker-compose.blocktime.yaml b/docker-compose.blocktime.yaml deleted file mode 100644 index d977e67..0000000 --- a/docker-compose.blocktime.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - ethereum: - # This file overwrites docker-compose.anvil.yaml - command: | - 'anvil --load-state ./data --block-time ${BLOCK_TIME} --host 0.0.0.0 --code-size-limit 9999999999 --chain-id ${CHAIN_ID}' diff --git a/docker-compose.fork.yaml b/docker-compose.fork.yaml new file mode 100644 index 0000000..667ddd5 --- /dev/null +++ b/docker-compose.fork.yaml @@ -0,0 +1,54 @@ +services: + deployer: + image: ${DEVNET_IMAGE} + command: | + '/src/scripts/configure-clone.sh' + restart: on-failure + env_file: + - .env + volumes: + - artifacts:/src/artifacts/ + + artifacts: + image: ${ARTIFACTS_IMAGE} + volumes: + - artifacts:/var/www/artifacts/ + depends_on: + deployer: + condition: service_completed_successfully + + yield-bot: + image: ${DEVNET_IMAGE} + command: | + 'cp /src/artifacts/deployments.local.json /src/deployments.local.json && npx hardhat fork:maintain-rate --network mainnet_fork --config hardhat.config.mainnet_fork.ts --show-stack-traces' + restart: unless-stopped + env_file: + - .env + volumes: + - artifacts:/src/artifacts/ + depends_on: + deployer: + condition: service_completed_successfully + + checkpoint-bot: + depends_on: + deployer: + condition: service_completed_successfully + + invariance-check-bot: + depends_on: + deployer: + condition: service_completed_successfully + + random-bot: + depends_on: + deployer: + condition: service_completed_successfully + + data: + depends_on: + deployer: + condition: service_completed_successfully + +volumes: + artifacts: diff --git a/env/env.common b/env/env.common index 5cc4a31..f9d56e8 100644 --- a/env/env.common +++ b/env/env.common @@ -1,5 +1,6 @@ # Networking configuration RPC_URI=http://ethereum:8545 +RPC_URL=http://ethereum:8545 # Registry address defaults to looking in artifacts # This can be overwritten by specifying here. REGISTRY_ADDRESS= diff --git a/env/env.fork b/env/env.fork new file mode 100644 index 0000000..a75f5ff --- /dev/null +++ b/env/env.fork @@ -0,0 +1 @@ +NETWORK=mainnet_fork diff --git a/env/env.images b/env/env.images index db27b02..a531641 100644 --- a/env/env.images +++ b/env/env.images @@ -5,8 +5,8 @@ # - edge = The newest image regardless of stability # Anvil -DEVNET_IMAGE=ghcr.io/delvtech/hyperdrive/devnet:1.0.14 -TESTNET_IMAGE=ghcr.io/delvtech/hyperdrive/testnet:1.0.14 +DEVNET_IMAGE=ghcr.io/delvtech/hyperdrive/devnet:e8c339b7bd05a11c204c907e7fb66500bb1b7dcd +TESTNET_IMAGE=ghcr.io/delvtech/hyperdrive/testnet:e8c339b7bd05a11c204c907e7fb66500bb1b7dcd # Infra ARTIFACTS_IMAGE=ghcr.io/delvtech/infra/artifacts:0.0.8 diff --git a/setup_env.sh b/setup_env.sh index d1c0e5d..5c30342 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -11,8 +11,9 @@ if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then echo " --develop : Fund accounts and enable anvil, data, and ports. Suitable for local development work." echo " --remote-service-bots : Runs service bots on a remote chain." echo "Flags:" - echo " --anvil : Spin up an Anvil node, deploy Hyperdrive to it, and serve artifacts on an nginx server." - echo " --blocktime : Sets the anvil node to run in blocktime mode." + echo " --anvil : Spin up a fresh Anvil node, deploy Hyperdrive to it, and serve artifacts for the fresh deploy on an nginx server." + echo " --blocktime : Sets the anvil node to run in blocktime mode. (not included in --all)" + echo " --fork : Sets the anvil node to fork mainnet. (not included in --all)" echo " --testnet : Uses the testnet hyperdrive image with restricted mint access." echo " --frontend : Build the frontend container." echo " --postgres : Runs a postgres db container for storing data." @@ -28,6 +29,7 @@ fi # Parse all of the arguments ## Initialize variables ANVIL=false +FORK=false BLOCKTIME=false TESTNET=false FRONTEND=false @@ -46,6 +48,7 @@ while [[ $# -gt 0 ]]; do --all) ANVIL=true # Don't run blocktime here, we want chain to be in fast mode + # Don't run fork here, forks cannot save/load state # Don't run testnet image here since random bots need to be able to mint FRONTEND=true POSTGRES=true @@ -75,6 +78,9 @@ while [[ $# -gt 0 ]]; do --blocktime) BLOCKTIME=true ;; + --fork) + FORK=true + ;; --testnet) TESTNET=true ;; @@ -117,6 +123,7 @@ echo "# Environment for Docker compose" >>.env # turned on using docker compose profiles. anvil_compose="docker-compose.anvil.yaml" blocktime_compose="docker-compose.blocktime.yaml" +fork_compose="docker-compose.fork.yaml" testnet_compose="docker-compose.testnet.yaml" frontend_compose="docker-compose.frontend.yaml" postgres_compose="docker-compose.postgres.yaml" @@ -130,6 +137,9 @@ full_compose_files="COMPOSE_FILE=$anvil_compose:$frontend_compose:$postgres_comp if $BLOCKTIME; then full_compose_files+="$blocktime_compose:" fi +if $FORK; then + full_compose_files+="$fork_compose:" +fi if $TESTNET; then full_compose_files+="$testnet_compose:" fi @@ -150,6 +160,7 @@ echo $full_compose_files >>.env # should be started. anvil_profile="anvil" blocktime_profile="blocktime" +fork_profile="fork" frontend_profile="frontend" postgres_profile="postgres" data_profile="data" @@ -164,6 +175,9 @@ fi if $BLOCKTIME; then full_compose_profiles+="$blocktime_profile," fi +if $FORK; then + full_compose_profiles+="$fork_profile," +fi if $FRONTEND; then full_compose_profiles+="$frontend_profile," fi @@ -199,9 +213,14 @@ echo "" >>.env cat env/env.common >> .env # optionally cat env.anvil to .env file if --anvil +# set fork url if FORK is true +# set block time if BLOCKTIME is true if $ANVIL; then echo "" >>.env - cat env/env.anvil >>.env + cat env/env.anvil >> .env + echo "" >>.env + [[ $FORK = true ]] && echo "ANVIL_STATE_SOURCE='--fork-url '" >> .env || echo \'ANVIL_STATE_SOURCE='--load-state ./data'\' >>.env + [[ $BLOCKTIME = true ]] && echo ANVIL_BLOCKTIME='--block-time ${BLOCK_TIME}' >>.env fi echo "" >>.env @@ -226,7 +245,7 @@ if $FRONTEND; then fi # optionally add an env.frontend to .env file if --postgres or --data -# POSTGRES uses these flags to launch postgres. +# POSTGRES uses these flags to launch postgres. # All agent0 images uses these flags to connect if $POSTGRES || $DATA || $SERVICE_BOT || $RANDOM_BOT || $RATE_BOT; then echo "" >>.env