diff --git a/scripts/README.md b/scripts/README.md index e84228b2..36217999 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -12,6 +12,7 @@ Below scripts use [select-chain.sh](./select-chain.sh). For each selected chain ## Scripts ### Initial Setup + Scripts for setup must be executed in this order: 1. ICS721 without proxies: [instantiate-ics721.sh](./instantiate-ics721.sh) @@ -29,8 +30,16 @@ After instantiation: 2. Incoming Proxy: [migrate-incoming-proxy.sh](./migrate-incoming-proxy.sh) 3. Outgoing Proxy: [migrate-outgoing-proxy.sh](.migrate-outgoing-proxy.sh) +### Outgoing Proxy Messages -### Proxy Messages +Usage: +```sh +$ ./scripts/whitelist-outgoing-proxy.sh +Usage: ./scripts/whitelist-outgoing-proxy.sh stargaze|osmosis [--add WHITELIST|--remove WHITELIST|--enable true_or_false] --type collection|channel|checksum|fees +Example: +./scripts/whitelist-outgoing-proxy.sh stargaze|osmosis --add channel-1 --type channel +./scripts/whitelist-outgoing-proxy.sh stargaze|osmosis --enable false --type collection +``` -TBD +The owner of the outgoing proxy contract can add, remove and enable whitelists for collections, channels, collection checksums, and collection fees. diff --git a/scripts/instantiate-ics721.sh b/scripts/instantiate-ics721.sh index 7baded51..157e3042 100755 --- a/scripts/instantiate-ics721.sh +++ b/scripts/instantiate-ics721.sh @@ -1,6 +1,6 @@ #!/bin/bash # ---------------------------------------------------- -# - exports CHAIN_NET and CHAIN based on user input - +# Instantiates the ICS721 contract with cw721_base_code_id and pauser # ---------------------------------------------------- SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) diff --git a/scripts/instantiate-incoming-proxy.sh b/scripts/instantiate-incoming-proxy.sh index 16da2729..d8982d68 100755 --- a/scripts/instantiate-incoming-proxy.sh +++ b/scripts/instantiate-incoming-proxy.sh @@ -1,6 +1,7 @@ #!/bin/bash # ---------------------------------------------------- -# - exports CHAIN_NET and CHAIN based on user input - +# Instantiates the Incoming Whitelist Channel Proxy contract +# with the whitelist channels and reference to the ICS721 contract # ---------------------------------------------------- SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) diff --git a/scripts/instantiate-outgoing-proxy.sh b/scripts/instantiate-outgoing-proxy.sh index dab0e631..e2609937 100755 --- a/scripts/instantiate-outgoing-proxy.sh +++ b/scripts/instantiate-outgoing-proxy.sh @@ -1,6 +1,7 @@ #!/bin/bash # ---------------------------------------------------- -# - exports CHAIN_NET and CHAIN based on user input - +# Instantiates the ICS721 Outgoing Whitelist Channel Proxy contract +# with the (channels, collections, checksums, collection fees) whitelist and reference to the ICS721 contract # ---------------------------------------------------- SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) diff --git a/scripts/migrate-ics721.sh b/scripts/migrate-ics721.sh index 4015239c..7b85dc64 100755 --- a/scripts/migrate-ics721.sh +++ b/scripts/migrate-ics721.sh @@ -1,6 +1,11 @@ #!/bin/bash # ---------------------------------------------------- -# - exports CHAIN_NET and CHAIN based on user input - +# Migrates the ICS721 contract, and sets optional: +# - incoming proxy +# - outgoing proxy +# - cw721 code id +# - pauser +# - cw721 admin # ---------------------------------------------------- SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) diff --git a/scripts/migrate-incoming-proxy.sh b/scripts/migrate-incoming-proxy.sh index 0ba5be81..1db1c1ec 100755 --- a/scripts/migrate-incoming-proxy.sh +++ b/scripts/migrate-incoming-proxy.sh @@ -1,6 +1,8 @@ #!/bin/bash # ---------------------------------------------------- -# - exports CHAIN_NET and CHAIN based on user input - +# Migrate the Incoming Whitelist Channel Proxy contract, and sets: +# - origin +# - optional channels # ---------------------------------------------------- SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) diff --git a/scripts/migrate-outgoing-proxy.sh b/scripts/migrate-outgoing-proxy.sh index 1ed4f404..887a8aa3 100755 --- a/scripts/migrate-outgoing-proxy.sh +++ b/scripts/migrate-outgoing-proxy.sh @@ -1,6 +1,10 @@ #!/bin/bash # ---------------------------------------------------- -# - exports CHAIN_NET and CHAIN based on user input - +# Migrate the ICS721 Outgoing Whitelist Channel Proxy contract, and sets: +# - config with origin (ICS721) and owner +# - optional channels +# - optional collections +# - proxy with optional channels and collections whitelist # ---------------------------------------------------- SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) @@ -81,9 +85,6 @@ printf -v MSG '{ "owner": "%s" }, "proxy": { - "rate_limit": { - "per_block": 100 - } %s %s } diff --git a/scripts/select-chain.sh b/scripts/select-chain.sh index 527c14ca..d83750c7 100755 --- a/scripts/select-chain.sh +++ b/scripts/select-chain.sh @@ -2,10 +2,14 @@ # ---------------------------------------------------- # - exports CHAIN based on user input - # ---------------------------------------------------- +export CHAIN_CHOICES=("stargaze" "osmosis") +export CHAIN_CHOICES_STR=$( + IFS=\| + echo "${CHAIN_CHOICES[*]}" +) function select_chain() { # Read chains from the file into an array - CHAIN_CHOICES=("stargaze" "osmosis") echo "Available chains: ${CHAIN_CHOICES[*]}" >&2 echo "Please select the chain:" >&2 diff --git a/scripts/whitelist-outgoing-proxy.sh b/scripts/whitelist-outgoing-proxy.sh new file mode 100755 index 00000000..3dcd02f6 --- /dev/null +++ b/scripts/whitelist-outgoing-proxy.sh @@ -0,0 +1,148 @@ +#!/bin/bash +# ---------------------------------------------------- +# execute messages on the outgoing proxy contract, for whitelist management: +# - add/remove collection +# - add/remove channel +# - add/remove collection checksum +# - enable/disable collection|channel|checksum|fees +# ---------------------------------------------------- + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +set -o pipefail + +# get CHAIN_CHOICES +source "$SCRIPT_DIR"/select-chain.sh + +function query_config() { + echo "config: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_config": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE --output json | jq)" >&2 + echo "contract: $($CLI query wasm contract $ADDR_OUTGOING_PROXY --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2 + echo "rate limit: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_rate_limit": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2 + echo "channels whitelist: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_channels_whitelist": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2 + echo "collections whitelist: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_collections_whitelist": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2 + echo "collection checkums whitelist: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_collection_checksums_whitelist": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2 + echo "fees collection map: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_fees_collection_map": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2 +} + +ACTION="" +CHAIN="" +VALUE="" +TYPE="" + +prev_arg="" +for arg in "$@"; do + case $arg in + --add | --remove | --enable) + ACTION="$arg" + ;; + --fees) ;; + --type) ;; + collection | channel | fees | checksum) + if [[ "$prev_arg" != "--type" ]]; then + echo "Invalid argument order. Use --type before specifying 'collection' or 'channel'." >&2 + exit 1 + fi + TYPE="$arg" + ;; + *) + if [[ " ${CHAIN_CHOICES[*]} " =~ " $arg " ]]; then + CHAIN="$arg" + elif [[ "$prev_arg" == "--generate-only" || "$prev_arg" == "--broadcast" ]]; then + FILE="$arg" + elif [[ "$prev_arg" == "--add" || "$prev_arg" == "--remove" || "$prev_arg" == "--enable" ]]; then + VALUE="$arg" + elif [[ "$prev_arg" == "--fees" ]]; then + FEES="$arg" + else + echo "Invalid argument: $arg" >&2 + echo "Usage: $0 ${CHAIN_CHOICES_STR// /|} [--add WHITELIST|--remove WHITELIST|--enable true_or_false] --type collection|channel|checksum|fees" >&2 + exit 1 + fi + ;; + esac + prev_arg="$arg" +done + +# Check if all required arguments are provided +if [[ -z "$ACTION" || -z "$CHAIN" || -z "$VALUE" ]]; then + echo "Usage: $0 ${CHAIN_CHOICES_STR// /|} [--add WHITELIST|--remove WHITELIST|--enable true_or_false] --type collection|channel|checksum|fees" >&2 + echo "Example:" >&2 + echo "$0 ${CHAIN_CHOICES_STR// /|} --add channel-1 --type channel" >&2 + echo "$0 ${CHAIN_CHOICES_STR// /|} --enable false --type collection" >&2 + exit 1 +fi + +echo "reading $SCRIPT_DIR/$CHAIN.env" +source "$SCRIPT_DIR"/"$CHAIN".env + +case $ACTION in +--add) + if [ "$TYPE" == "collection" ]; then + printf -v MSG '{"update_config": {"add_collection_to_whitelist": {"collection": "%s"}}}' $VALUE + elif [ "$TYPE" == "channel" ]; then + printf -v MSG '{"update_config": {"add_channel_to_whitelist": {"channel": "%s"}}}' $VALUE + elif [ "$TYPE" == "fees" ]; then + printf -v MSG '{"update_config": {"add_fees_collection": {"collection": "%s", "fees": {"amount": "%s", "denom": "%s"}}}}' $VALUE $FEES $CLI_DENOM + elif [ "$TYPE" == "checksum" ]; then + printf -v MSG '{"update_config": {"add_collection_checksum_to_whitelist": {"checksum": "%s"}}}' $VALUE + fi + ;; +--remove) + if [ "$TYPE" == "collection" ]; then + printf -v MSG '{"update_config": {"remove_collection_from_whitelist": {"collection": "%s"}}}' $VALUE + elif [ "$TYPE" == "channel" ]; then + printf -v MSG '{"update_config": {"remove_channel_from_whitelist": {"channel": "%s"}}}' $VALUE + elif [ "$TYPE" == "fees" ]; then + printf -v MSG '{"update_config": {"remove_fees_collection": {"collection": "%s"}}}' $VALUE + elif [ "$TYPE" == "checksum" ]; then + printf -v MSG '{"update_config": {"remove_collection_checksum_from_whitelist": {"checksum": "%s"}}}' $VALUE + fi + ;; +--enable) + if [ "$TYPE" == "collection" ]; then + printf -v MSG '{"update_config": {"enable_collections_whitelist": %s}}' $VALUE + elif [ "$TYPE" == "channel" ]; then + printf -v MSG '{"update_config": {"enable_channels_whitelist": %s}}' $VALUE + elif [ "$TYPE" == "fees" ]; then + printf -v MSG '{"update_config": {"enable_fees_collections_whitelist": %s}}' $VALUE + elif [ "$TYPE" == "checksum" ]; then + printf -v MSG '{"update_config": {"enable_collection_checksums_whitelist": %s}}' $VALUE + fi + ;; +*) + echo "Invalid action $ACTION. Use --add, --remove, or --enable." >&2 + exit 1 + ;; +esac + +echo "==========================================================================================" >&2 +echo "=============== updating $ADDR_OUTGOING_PROXY using dev wallet $WALLET_DEV" >&2 +CMD="$CLI tx wasm execute $ADDR_OUTGOING_PROXY '$MSG'" +CMD+=" --from $WALLET" +CMD+=" --gas $CLI_GAS --gas-prices $CLI_GAS_PRICES --gas-adjustment $CLI_GAS_ADJUSTMENT" +CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y" +echo "$CMD" >&2 +echo "Execute TX?" >&2 +select yn in "Yes" "No"; do + case $yn in + Yes) + break + ;; + No) + exit 0 + ;; + *) + echo "Please select Yes or No." >&2 + ;; + esac +done +eval $CMD +ERROR_CODE=${PIPESTATUS[0]} +if [ $ERROR_CODE -ne 0 ]; then + echo "ERROR executing" >&2 + exit $ERROR_CODE +fi + +echo "==========================================================================================" >&2 +echo "config before change $ADDR_OUTGOING_PROXY=$ADDR_OUTGOING_PROXY:" >&2 +sleep 10 +query_config