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

scripts for ics721 setup #94

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
45 changes: 45 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Setup ICS721

For ICS721 it requires these contracts:

- ICS721: the bridge itself
- Incoming Proxy: optional contract for filtering incoming packets
- Outgoing Proxy: optional contract for filtering incoming packets

NOTE:
Below scripts use [select-chain.sh](./select-chain.sh). For each selected chain there is an `.env` file like `stargaze.env` and `osmosis.env`.

## Scripts

### Initial Setup

Scripts for setup must be executed in this order:

1. ICS721 without proxies: [instantiate-ics721.sh](./instantiate-ics721.sh)
2. Incoming Proxy: [instantiate-incoming-proxy.sh](./instantiate-incoming-proxy.sh)
3. Outgoing Proxy: [instantiate-outgoing-proxy.sh](.instantiate-outgoing-proxy.sh)

After instantiation:

- update `ADDR_ICS721`, `ADDR_INCOMING_PROXY`, `ADDR_OUTGOING_PROXY` in env file
- Note: ICS721 is instantiated without(!) proxies, proxies are added via migration (velow)

### Migration

1. ICS721 : [migrate-ics721.sh](./migrate-ics721.sh)
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

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
```

The owner of the outgoing proxy contract can add, remove and enable whitelists for collections, channels, collection checksums, and collection fees.
24 changes: 24 additions & 0 deletions scripts/instantiate-ics721.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# ----------------------------------------------------
# Instantiates the ICS721 contract with cw721_base_code_id and pauser
# ----------------------------------------------------

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# select chain
if [[ -z "$CHAIN" ]]; then
source "$SCRIPT_DIR"/select-chain.sh
CHAIN=$(select_chain)
export CHAIN
fi
echo "reading $SCRIPT_DIR/$CHAIN.env"
source "$SCRIPT_DIR"/"$CHAIN".env

printf -v MSG '{"cw721_base_code_id": %s, "pauser": "%s"}' $CODE_ID_CW721 $WALLET_OWNER
CMD="$CLI tx wasm instantiate $CODE_ID_ICS721 '$MSG' --label 'ICS721 with rate limiter outgoing proxy'"
CMD+=" --from $WALLET --admin $WALLET_ADMIN"
CMD+=" --gas $CLI_GAS --gas-prices $CLI_GAS_PRICES --gas-adjustment $CLI_GAS_ADJUSTMENT"
CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y"

echo "executing: $CMD" >&2
eval $CMD
27 changes: 27 additions & 0 deletions scripts/instantiate-incoming-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# ----------------------------------------------------
# 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)

# select chain
if [[ -z "$CHAIN" ]]; then
source "$SCRIPT_DIR"/select-chain.sh
CHAIN=$(select_chain)
export CHAIN
fi
echo "reading $SCRIPT_DIR/$CHAIN.env"
source "$SCRIPT_DIR"/"$CHAIN".env

printf -v MSG '{"origin": "%s", "channels": %s}' $ADDR_ICS721 $CHANNELS
LABEL="ICS721 Incoming Whitelist Channel Proxy, Managed by Ark Protocol"
CMD="$CLI tx wasm instantiate $CODE_ID_INCOMING_PROXY '$MSG'"
CMD+=" --label '$LABEL'"
CMD+=" --from $WALLET --admin $WALLET_ADMIN"
CMD+=" --gas $CLI_GAS --gas-prices $CLI_GAS_PRICES --gas-adjustment $CLI_GAS_ADJUSTMENT"
CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y"

echo "executing: $CMD" >&2
eval $CMD
41 changes: 41 additions & 0 deletions scripts/instantiate-outgoing-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
# ----------------------------------------------------
# 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)

# select chain
if [[ -z "$CHAIN" ]]; then
source "$SCRIPT_DIR"/select-chain.sh
CHAIN=$(select_chain)
export CHAIN
fi
echo "reading $SCRIPT_DIR/$CHAIN.env"
source "$SCRIPT_DIR"/"$CHAIN".env

MSG=$(
cat <<EOF
{
"config": {
"origin": "$ADDR_ICS721",
"owner": "$WALLET_OWNER"
},
"proxy": {
"rate_limit": {"per_block": 100},
"channels": $CHANNELS,
"collections": $COLLECTIONS
}
}
EOF
)
LABEL="ICS721 Outgoing Whitelist Channel Proxy"
CMD="$CLI tx wasm instantiate $CODE_ID_OUTGOING_PROXY '$MSG'"
CMD+=" --label '$LABEL'"
CMD+=" --from $WALLET --admin $WALLET_ADMIN"
CMD+=" --gas $CLI_GAS --gas-prices $CLI_GAS_PRICES --gas-adjustment $CLI_GAS_ADJUSTMENT"
CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y"

echo "executing: $CMD" >&2
eval $CMD
64 changes: 64 additions & 0 deletions scripts/migrate-ics721.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# ----------------------------------------------------
# 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)

# select chain
if [[ -z "$CHAIN" ]]; then
source "$SCRIPT_DIR"/select-chain.sh
CHAIN=$(select_chain)
export CHAIN
fi
echo "reading $SCRIPT_DIR/$CHAIN.env"
source "$SCRIPT_DIR"/"$CHAIN".env

function query_config() {
echo "cw721 code id: $($CLI query wasm contract-state smart $ADDR_ICS721 '{"cw721_code_id": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
echo "cw721 admin: $($CLI query wasm contract-state smart $ADDR_ICS721 '{"cw721_admin": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
echo "outgoing proxy: $($CLI query wasm contract-state smart $ADDR_ICS721 '{"outgoing_proxy": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
echo "incoming proxy: $($CLI query wasm contract-state smart $ADDR_ICS721 '{"incoming_proxy": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
echo "pauser: $($CLI query wasm contract-state smart $ADDR_ICS721 '{"pauser": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
echo "contract: $($CLI query wasm contract $ADDR_ICS721 --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
}

echo "==========================================================================================" >&2
echo "configs before migration $ADDR_ICS721:" >&2
query_config

echo "==========================================================================================" >&2
echo "!!! migrating $ADDR_ICS721 data: proxy: $ADDR_OUTGOING_PROXY, cw721 code id: $CODE_ID_CW721 !!!" >&2 # use CW721 if not set
MSG=$(
cat <<EOF
{"with_update":{
"incoming_proxy": "$ADDR_INCOMING_PROXY",
"outgoing_proxy": "$ADDR_OUTGOING_PROXY",
"cw721_base_code_id": $CODE_ID_CW721,
"pauser": "$WALLET_OWNER",
"cw721_admin": "$WALLET_ADMIN"
}
}
EOF
)
CMD="$CLI tx wasm migrate $ADDR_ICS721 $CODE_ID_ICS721 '$MSG'"
CMD+=" --from $WALLET_ADMIN"
CMD+=" --gas $CLI_GAS --gas-prices $CLI_GAS_PRICES --gas-adjustment $CLI_GAS_ADJUSTMENT"
CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y"

echo "executing: $CMD" >&2
eval $CMD
if [ $? -ne 0 ]; then
echo "failed to migrate $ADDR_ICS721" >&2
exit 1
fi

echo "==========================================================================================" >&2
echo "configs after migration $ADDR_ICS721:" >&2
sleep 10
query_config
76 changes: 76 additions & 0 deletions scripts/migrate-incoming-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
# ----------------------------------------------------
# Migrate the Incoming Whitelist Channel Proxy contract, and sets:
# - origin
# - optional channels
# ----------------------------------------------------

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# select chain
if [[ -z "$CHAIN" ]]; then
source "$SCRIPT_DIR"/select-chain.sh
CHAIN=$(select_chain)
export CHAIN
fi
echo "reading $SCRIPT_DIR/$CHAIN.env"
source "$SCRIPT_DIR"/"$CHAIN".env

function query_config() {
echo "contract: $($CLI query wasm contract $ADDR_INCOMING_PROXY --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
echo "origin: $($CLI query wasm contract-state smart $ADDR_INCOMING_PROXY '{"get_origin": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)" >&2
CURRENT_CHANNELS=$($CLI query wasm contract-state smart $ADDR_INCOMING_PROXY '{"get_channels": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)
echo "channels: $CURRENT_CHANNELS" >&2
}

echo "==========================================================================================" >&2
echo "configs before migration $ADDR_INCOMING_PROXY:" >&2
query_config

echo "==========================================================================================" >&2
echo "Do you want to migrate channels?" >&2
echo "current channels whitelist: $CURRENT_CHANNELS" >&2
echo "Channels from config: $CHANNELS" >&2
select yn in "Yes" "No"; do
case $yn in
Yes)
MIGRATE_CHANNELS=true
OPTION_ONE=", \"channels\": $CHANNELS"
break
;;
No)
MIGRATE_CHANNELS=false
OPTION_ONE=""
break
;;
*)
echo "Please select Yes or No." >&2
;;
esac
done

printf -v MSG '{
"with_update": {
"origin": "%s"
%s
}
}' \
"$ADDR_ICS721" \
"$OPTION_ONE"

CMD="$CLI tx wasm migrate $ADDR_INCOMING_PROXY $CODE_ID_INCOMING_PROXY '$MSG'"
CMD+=" --from $WALLET_ADMIN"
CMD+=" --gas-prices $CLI_GAS_PRICES --gas $CLI_GAS --gas-adjustment $CLI_GAS_ADJUSTMENT"
CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y"

echo "executing: $CMD" >&2
eval $CMD
if [ $? -ne 0 ]; then
echo "failed to migrate $ADDR_ICS721" >&2
exit 1
fi

echo "==========================================================================================" >&2
echo "configs after migration $ADDR_INCOMING_PROXY:" >&2
sleep 10
query_config
112 changes: 112 additions & 0 deletions scripts/migrate-outgoing-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
# ----------------------------------------------------
# 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)

# select chain
if [[ -z "$CHAIN" ]]; then
source "$SCRIPT_DIR"/select-chain.sh
CHAIN=$(select_chain)
export CHAIN
fi
echo "reading $SCRIPT_DIR/$CHAIN.env"
source "$SCRIPT_DIR"/"$CHAIN".env

function query_config() {
echo "config: $($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_config": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | 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
CURRENT_CHANNELS=$($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_channels_whitelist": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)
echo "channels whitelist: $CURRENT_CHANNELS" >&2
CURRENT_COLLECTIONS=$($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_collections_whitelist": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)
echo "collections whitelist: $CURRENT_COLLECTIONS" >&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
CURRENT_COLLECTION_CHECKSUMS=$($CLI query wasm contract-state smart $ADDR_OUTGOING_PROXY '{"get_collection_checksums_whitelist": {}}' --chain-id $CHAIN_ID --node $CHAIN_NODE | jq)
echo "collection checksums whitelist: $CURRENT_COLLECTION_CHECKSUMS" >&2
}

echo "==========================================================================================" >&2
echo "configs before migration $ADDR_OUTGOING_PROXY:" >&2
query_config

echo "==========================================================================================" >&2
echo "Do you want to migrate channels?" >&2
echo "current channels whitelist: $CURRENT_CHANNELS" >&2
echo "Channels from config: $CHANNELS" >&2
select yn in "Yes" "No"; do
case $yn in
Yes)
MIGRATE_CHANNELS=true
OPTION_ONE=", \"channels\": $CHANNELS"
break
;;
No)
MIGRATE_CHANNELS=false
OPTION_ONE=""
break
;;
*)
echo "Please select Yes or No." >&2
;;
esac
done

echo "Do you want to migrate collections?" >&2
echo "current collections whitelist: $CURRENT_COLLECTIONS" >&2
echo "Collection from config: $COLLECTIONS" >&2
select yn in "Yes" "No"; do
case $yn in
Yes)
MIGRATE_COLLECTIONS=true
OPTION_TWO=", \"collections\": $COLLECTIONS"
break
;;
No)
MIGRATE_COLLECTIONS=false
OPTION_TWO=""
break
;;
*)
echo "Please select Yes or No." >&2
;;
esac
done

printf -v MSG '{
"with_update": {
"config": {
"origin": "%s",
"owner": "%s"
},
"proxy": {
%s
%s
}
}
}' \
"$ADDR_ICS721" \
"$WALLET_OWNER" \
"$OPTION_ONE" \
"$OPTION_TWO"

CMD="$CLI tx wasm migrate $ADDR_OUTGOING_PROXY $CODE_ID_OUTGOING_PROXY '$MSG'"
CMD+=" --from $WALLET_ADMIN"
CMD+=" --gas-prices $CLI_GAS_PRICES --gas $CLI_GAS --gas-adjustment $CLI_GAS_ADJUSTMENT"
CMD+=" --chain-id $CHAIN_ID --node $CHAIN_NODE -y"

echo "executing: $CMD" >&2
eval $CMD
if [ $? -ne 0 ]; then
echo "failed to migrate $ADDR_ICS721" >&2
exit 1
fi

echo "==========================================================================================" >&2
echo "configs after migration $ADDR_OUTGOING_PROXY:" >&2
query_config
Loading
Loading