Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows for running service bots on remote chain #119

Merged
merged 10 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ compose app. The compose app is composed of several services:
- artifacts: A file server that serves up artifacts about the Hyperdrive deployment.
- frontend: A full monorepo with a trading UI and supporting packages
- data: A service that gathers data from the chain and deploys a data dashboard.
- bots: Bot services for running auto trades on a chain.

## Setup

Expand Down Expand Up @@ -44,19 +45,19 @@ To select an environment, run `sh setup_env.sh` with one or more of the followin
- `--blocktime` : Sets the anvil node to run in blocktime mode.
- `--testnet` : Uses the testnet hyperdrive image with restricted mint access.
- `--frontend` : Build the frontend container.
- `--data` : Runs the data framework, queries the chain, writes to postgres, and deploys the dashboard.
- `--postgres` : Launches a local postgres server for the data pipeline.
- `--data` : Runs the data framework, querying the chain and writing to postgres.
- `--service-bot` : Runs checkpoint bot and invariance check bots on the chain."
- `--random-bot` : Runs random bots on the chain.
- `--ports` : Expose docker images to your machine, as specified in `env/env.ports`.
- `--fund-accounts` : Fund accounts from `/accounts/balances.json`.
- `--dynamic-rate` : Yield source will have a dynamic variable rate.
- `--fuzzbot` : Runs fuzzbots on the chain.
- `--rate-bot` : Yield source will have a dynamic variable rate.

We also support shortcuts for common combinations. The most inclusive tag used will take priority.

- `--all` : Fund accounts and enable all components: anvil, data, postgres, frontend, and ports.
- `--competition` : Fund accounts and enable anvil on block time with testnet image, data (without postgres), and ports. Use this for a trading competition deployment.
- `--develop` : Fund accounts and enable anvil, data, and ports. Suitable for local development work.
- `--fuzz` : Enable anvil on block time, data, and ports. Runs fuzzbots and outputs crash reports. See [Fuzz Agents](#fuzz-agents) for more details.
- `--remote-service-bots`: Runs service bots on a remote chain. See [Service Bots](./service-bots.md) for more details.

You can also change the tags in `env/env.images` to modify which docker image you build from.

Expand All @@ -76,12 +77,6 @@ See live logs with `docker logs CONTAINER_NAME -f`.

Run `docker compose down -v`. The `-v` ensures that storage volumes are deleted.

## Fuzz agents

We provide a method for launching [agents making random trades](https://github.com/delvtech/agent0/blob/main/scripts/fuzz_bots.py) on Hyperdrive along with the rest of the
infrastructure by providing the `--fuzz` argument to `setup_env.sh`. These agents also support detailed
crash reports in the event that an error is detected, located in the `.crash_report` directory. By default,
the chain will be paused when a crash happens, freezing the anvil state for further analysis.

## Disclaimer

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.agent0-bots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
image: ${AGENT0_IMAGE}
profiles:
- "service-bot"
restart: always
command: |
/bin/sh -c "sleep 1; python scripts/checkpoint_bots.py --pool-check-sleep-blocks 30 --infra"
env_file:
Expand All @@ -12,8 +13,9 @@ services:
image: ${AGENT0_IMAGE}
profiles:
- "service-bot"
restart: always
command: |
/bin/sh -c "sleep 1; python scripts/fuzz_bot_invariant_checks.py --pool-check-sleep-blocks 30 --infra"
/bin/sh -c "sleep 1; python scripts/invariant_checks.py --pool-check-sleep-blocks 30 --infra"
env_file:
- .env

Expand Down
15 changes: 11 additions & 4 deletions docker-compose.anvil.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
services:
ethereum:
image: ${DEVNET_IMAGE}
profiles:
- "anvil"
# without --block-time we're in "automine" mode and blocks are mined
# as soon as transactions are received, or with manual commands.
# this is "hecking fast" mode.
Expand All @@ -13,9 +15,18 @@ services:
# read calls.
mine:
image: curlimages/curl:latest
profiles:
- "anvil"
command: |
/bin/sh -c "sleep 2; curl -X POST -H \"Content-Type: application/json\" --data '{\"jsonrpc\":\"2.0\", \"method\":\"anvil_mine\", \"params\":[], \"id\":1}' ${RPC_URI}"

artifacts:
image: ${ARTIFACTS_IMAGE}
profiles:
- "anvil"
volumes:
- artifacts:/var/www/artifacts/

# Set the block timestamp interval
timestamp_interval:
image: curlimages/curl:latest
Expand All @@ -35,10 +46,6 @@ services:
env_file:
- .env

artifacts:
image: ${ARTIFACTS_IMAGE}
volumes:
- artifacts:/var/www/artifacts/

volumes:
artifacts:
7 changes: 7 additions & 0 deletions env/env.anvil
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# The artifacts uri for the artifacts container
ARTIFACTS_URI=http://artifacts:8080

# Choose a chain id for the eth node
# Common choices are: 42069 for CloudChain or 31337 for local development
CHAIN_ID=42069

# Migration configuration
ADMIN=0x6043bF4ec8834F918242BaCA0F1F3805F2a2988D
ADMIN_PRIVATE_KEY=0x0f1616bb59774b929ba5256c2204123d9dedc4c142d013179b90f929997d119b
5 changes: 5 additions & 0 deletions env/env.bots
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The private key of the account that's paying gas for checkpoints
CHECKPOINT_BOT_KEY=

# The rollbar api key
ROLLBAR_API_KEY=
8 changes: 3 additions & 5 deletions env/env.common
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Networking configuration
ARTIFACTS_URI=http://artifacts:8080
RPC_URI=http://ethereum:8545

# Migration configuration
ADMIN=0x6043bF4ec8834F918242BaCA0F1F3805F2a2988D
ADMIN_PRIVATE_KEY=0x0f1616bb59774b929ba5256c2204123d9dedc4c142d013179b90f929997d119b
# Registry address defaults to looking in artifacts
# This can be overwritten by specifying here.
REGISTRY_ADDRESS=
6 changes: 3 additions & 3 deletions env/env.images
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# - edge = The newest image regardless of stability

# Anvil
DEVNET_IMAGE=ghcr.io/delvtech/hyperdrive/devnet:1.0.10
TESTNET_IMAGE=ghcr.io/delvtech/hyperdrive/testnet:1.0.10
DEVNET_IMAGE=ghcr.io/delvtech/hyperdrive/devnet:1.0.14
TESTNET_IMAGE=ghcr.io/delvtech/hyperdrive/testnet:1.0.14

# Infra
ARTIFACTS_IMAGE=ghcr.io/delvtech/infra/artifacts:0.0.8
FUND_ACCOUNTS_IMAGE=ghcr.io/delvtech/infra/fund-accounts:0.0.8
RATE_BOT_IMAGE=ghcr.io/delvtech/infra/rate-bot:0.0.8

# Agent0 (bots)
AGENT0_IMAGE=ghcr.io/delvtech/agent0/agent0:0.20.2
AGENT0_IMAGE=ghcr.io/delvtech/agent0/agent0:0.21.9

# Frontend
FRONTEND_IMAGE=ghcr.io/delvtech/hyperdrive-frontend/hyperdrive-frontend:1.6.5
13 changes: 13 additions & 0 deletions service-bots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Service Bots
Infra can be used to run service bots on a remote chain (e.g., Sepolia testnet).

- Setup infra as documented in the [README](README.md#setup).
- Run `./setup_env.sh --remote-service-bots`
- Edit the generated `.env` file and replace the following fields:
- `RPC_URI`: The URI to the RPC for connecting to the chain.
- `REGISTRY_ADDRESS`: The contract address of the hyperdrive registry.
- `CHECKPOINT_BOT_KEY`: The private key of the account that's making checkpoints.
- `ROLLBAR_API_KEY`: The API key for Rollbar for logging.
- Run `docker compose up -d` to bring up bots.

The above will run (1) checkpoint bots and (2) invariance check bots on all registered pools.
54 changes: 35 additions & 19 deletions setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
echo "Usage: ./setup_env.sh [flags]"
echo "Flag Groups:"
echo " --all : Fund accounts and enable all components: anvil, data, postgres, frontend, and ports."
echo " --develop : Fund accounts and enable anvil, data, and ports. Suitable for local development work."
echo " --all : Fund accounts and enable all components."
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 " --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."
echo " --data : Runs the data framework, querying the chain and writing to postgres."
echo " --service-bot : Runs checkpoint bot and invariance check bots on the chain."
echo " --random-bot : Runs random bots on the chain."
echo " --ports : Expose docker images to your machine, as specified in env/env.ports."
echo " --fund-accounts : Fund accounts from /accounts/balances.json."
echo " --rate-bot : Yield source will have a dynamic variable rate."
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 " --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."
echo " --data : Runs the data framework, querying the chain and writing to postgres."
echo " --service-bot : Runs checkpoint bot and invariance check bots on the chain."
echo " --random-bot : Runs random bots on the chain."
echo " --ports : Expose docker images to your machine, as specified in env/env.ports."
echo " --fund-accounts : Fund accounts from /accounts/balances.json."
echo " --rate-bot : Yield source will have a dynamic variable rate."
exit 0
fi

Expand Down Expand Up @@ -62,6 +63,11 @@ while [[ $# -gt 0 ]]; do
PORTS=true
FUND_ACCOUNTS=true
;;
--remote-service-bots)
POSTGRES=true
PORTS=true
SERVICE_BOT=true
;;
# Flags
--anvil)
ANVIL=true
Expand Down Expand Up @@ -142,6 +148,7 @@ echo $full_compose_files >>.env

# Set up the COMPOSE_PROFILES environment variable. This toggles which layers
# should be started.
anvil_profile="anvil"
blocktime_profile="blocktime"
frontend_profile="frontend"
postgres_profile="postgres"
Expand All @@ -151,6 +158,9 @@ random_bot_profile="random-bot"
rate_bot_profile="rate-bot"
fund_accounts_profile="fund-accounts"
full_compose_profiles="COMPOSE_PROFILES="
if $ANVIL; then
full_compose_profiles+="$anvil_profile,"
fi
if $BLOCKTIME; then
full_compose_profiles+="$blocktime_profile,"
fi
Expand Down Expand Up @@ -187,6 +197,13 @@ echo $full_compose_profiles >>.env
# cat env.common and env.ports to the .env file
echo "" >>.env
cat env/env.common >> .env

# optionally cat env.anvil to .env file if --anvil
if $ANVIL; then
echo "" >>.env
cat env/env.anvil >>.env
fi

echo "" >>.env
cat env/env.ports >>.env

Expand All @@ -196,12 +213,6 @@ echo "" >>.env
cat env/env.images >>.env
source env/env.images

# optionally cat env.anvil to .env file if --anvil
if $ANVIL; then
echo "" >>.env
cat env/env.anvil >>.env
fi

# optionally add an env.time to .env file if --blocktime
if $BLOCKTIME; then
echo "" >>.env
Expand All @@ -222,4 +233,9 @@ if $POSTGRES || $DATA || $SERVICE_BOT || $RANDOM_BOT || $RATE_BOT; then
cat env/env.postgres >> .env
fi

if $SERVICE_BOT; then
echo "" >>.env
cat env/env.bots >> .env
fi

echo "Environment filed created at .env"
Loading