#!/bin/bash

set -e

DOTENV=../.env
[ -f $DOTENV ] || (echo "$DOTENV does not exist." >&2; exit 1)

# 1. load variables from .env file
. $DOTENV

# 2. next we get all the token bridge registration VAAs from the environment
# if a new VAA is added, this will automatically pick it up
VAAS=$(set | grep "REGISTER_.*_TOKEN_BRIDGE_VAA" | grep -v APTOS | cut -d '=' -f1)

# TODO: this will not be needed when the sdk is published
TOKEN_BRIDGE_ADDR=$(worm contract devnet aptos TokenBridge)

# 3. use 'worm' to submit each registration VAA
for VAA in $VAAS
do
    VAA=${!VAA}
    worm submit $VAA --chain aptos --contract-address $TOKEN_BRIDGE_ADDR --network devnet
done
echo "Registrations successful."
