Skip to content

Commit

Permalink
add rate bot service (#84)
Browse files Browse the repository at this point in the history
* add rate bot service

* fix rate_daddy command for alpine

* create env var for the amount of time to wait before changing the rate

* Modify profiles and address source

* Add artifacts volume

* Fix volumes

* Change service name

* remove dynamic-rate from --all until published

* Add rate bot to test_images

* Add rate bot to docker publish workflow

---------

Co-authored-by: Ryan Goree <[email protected]>
  • Loading branch information
jrhea and ryangoree authored Oct 17, 2023
1 parent 7eb09f7 commit 547ee2f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ jobs:
with:
name: fund-accounts
context: ./images/fund-accounts

push-rate-bot-image:
uses: ./.github/workflows/publish-image.yml
with:
name: rate-bot
context: ./images/rate-bot
11 changes: 11 additions & 0 deletions docker-compose.rate-bot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.9"
services:
rate-bot:
image: ${RATE_BOT_IMAGE}
profiles:
- "dynamic-rate"
volumes:
- artifacts:/artifacts/

volumes:
artifacts:
1 change: 1 addition & 0 deletions env/env.images
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TESTNET_IMAGE=ghcr.io/delvtech/hyperdrive/testnet:0.0.16
# Infra
ARTIFACTS_IMAGE=ghcr.io/delvtech/infra/artifacts:0.0.4
FUND_ACCOUNTS_IMAGE=ghcr.io/delvtech/infra/fund-accounts:0.0.4
RATE_BOT_IMAGE=rate-bot

# Elfpy (bots)
ELFPY_IMAGE=ghcr.io/delvtech/elf-simulations/elf-simulations:0.8.0
Expand Down
15 changes: 15 additions & 0 deletions images/rate-bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ghcr.io/foundry-rs/foundry:master
WORKDIR /src

COPY ./rate_daddy.sh ./rate_daddy.sh

ENV ETH_FROM=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
ENV PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
ENV RPC_URL=http://ethereum:8545
ENV WAIT_TIME=1800
RUN apk add --no-cache jq curl bc sed
RUN chmod +x ./rate_daddy.sh

#ENTRYPOINT ["watch", "-n", "${WAIT_TIME}", "./rate_daddy.sh"]
ENTRYPOINT watch -n ${WAIT_TIME} ./rate_daddy.sh

4 changes: 4 additions & 0 deletions images/rate-bot/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# must be ended with a new line "LF" (Unix) and not "CRLF" (Windows)
*/30 * * * * rate_daddy.sh >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.

10 changes: 10 additions & 0 deletions images/rate-bot/rate_daddy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# Get the base token address from /artifact/addresses.json
CONTRACT_ADDRESS=$(jq -r '.mockHyperdrive' /artifacts/addresses.json)

sleep 3
VAULT_ADDRESS=$(cast call ${CONTRACT_ADDRESS} "pool()(address)" --rpc-url ${RPC_URL})
NEW_RATE=$(echo "scale=16; 3+$(od -t u2 -An -N2 /dev/random)/(2 ^ 16)"| bc |sed 's/\.//g')
cast send --from ${ETH_FROM} --private-key ${PRIVATE_KEY} $VAULT_ADDRESS "setRate(uint256)" $NEW_RATE --rpc-url ${RPC_URL}

15 changes: 14 additions & 1 deletion setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
echo " --all : Fund accounts and enable all components: anvil, bots, frontend, and ports."
echo " --competition : Fund accounts and enable anvil, bots and ports. Use this for a trading competition deployment."
echo " --develop : Fund accounts and enable anvil, bots and ports. Suitable for local development work."
echo " --dynamic-rate : Yield source will have a dynamic variable rate."
exit 0
fi

Expand All @@ -27,6 +28,7 @@ POSTGRES=false
DATA=false
FUND_ACCOUNTS=false
COMPETITION=false
DYNAMIC_RATE=false

## Loop through the arguments
while [[ $# -gt 0 ]]; do
Expand All @@ -38,13 +40,16 @@ while [[ $# -gt 0 ]]; do
PORTS=true
DATA=true
FUND_ACCOUNTS=true
# to be added once the image is published
# DYNAMIC_RATE=true
;;
--competition)
ANVIL=true
PORTS=true
DATA=true
FUND_ACCOUNTS=true
COMPETITION=true
DYNAMIC_RATE=true
;;
--develop)
ANVIL=true
Expand All @@ -59,6 +64,9 @@ while [[ $# -gt 0 ]]; do
--data)
DATA=true
;;
--dynamic-rate)
DYNAMIC_RATE=true
;;
--postgres)
POSTGRES=true
;;
Expand Down Expand Up @@ -89,11 +97,12 @@ echo "# Environment for Docker compose" >>.env
# turned on using docker compose profiles.
anvil_compose="docker-compose.anvil.yaml"
data_compose="docker-compose.data.yaml"
rate_bot_compose="docker-compose.rate-bot.yaml"
frontend_compose="docker-compose.frontend.yaml"
postgres_compose="docker-compose.postgres.yaml"
testnet_compose="docker-compose.testnet.yaml"
ports_compose="docker-compose.ports.yaml"
full_compose_files="COMPOSE_FILE=$anvil_compose:$data_compose:$frontend_compose:$postgres_compose:"
full_compose_files="COMPOSE_FILE=$anvil_compose:$data_compose:$frontend_compose:$postgres_compose:$rate_bot_compose:"
if $COMPETITION; then
full_compose_files+="$testnet_compose:"
fi
Expand All @@ -117,6 +126,7 @@ postgres_profile="postgres"
data_profile="data"
fund_accounts_profile="fund-accounts"
competition_profile="competition"
dynamic_rate_profile="dynamic-rate"
full_compose_profiles="COMPOSE_PROFILES="
if $FRONTEND; then
full_compose_profiles+="$frontend_profile,"
Expand All @@ -133,6 +143,9 @@ fi
if $COMPETITION; then
full_compose_profiles+="$competition_profile,"
fi
if $DYNAMIC_RATE; then
full_compose_profiles+="$dynamic_rate_profile,"
fi
# Check if "," is at the end of the string
if [[ $full_compose_profiles == *"," ]]; then
# Remove "," from the end of the string
Expand Down
3 changes: 3 additions & 0 deletions test/test_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ timestamp=$(date +%s)

export ARTIFACTS_IMAGE="test/artifacts:$timestamp"
export FUND_ACCOUNTS_IMAGE="test/fund-accounts:$timestamp"
export RATE_BOT_IMAGE="test/rate-bot:$timestamp"

echo "Building images..."
docker build images/artifacts -t "$ARTIFACTS_IMAGE"
docker build images/fund-accounts -t "$FUND_ACCOUNTS_IMAGE"
docker build images/rate-bot -t "$RATE_BOT_IMAGE"

sh test/test_compose.sh

echo "Removing images..."
docker image rm "$ARTIFACTS_IMAGE"
docker image rm "$FUND_ACCOUNTS_IMAGE"
docker image rm "$RATE_BOT_IMAGE"

0 comments on commit 547ee2f

Please sign in to comment.