Skip to content

Commit

Permalink
WIP: Deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinWaller committed May 6, 2024
1 parent a405297 commit 35de27d
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .devcontainer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
DEBIAN_VARIANT=bullseye
1 change: 1 addition & 0 deletions .devcontainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
27 changes: 27 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
ARG VARIANT="bullseye"
FROM rust:1-${VARIANT}

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common

# Tools
RUN apt-get -y install --no-install-recommends vim git docker.io libc6 build-essential

# WASM dependencies + Rustup
RUN apt-get -y install --no-install-recommends binaryen
RUN rustup target add wasm32-wasi
RUN rustup target add wasm32-unknown-unknown

# Rustfmt with nightly toolchain
RUN rustup install nightly
RUN rustup component add rustfmt --toolchain nightly

# Dependencies
RUN apt-get -y install --no-install-recommends protobuf-compiler

COPY ./download-seda.sh ./download-seda.sh
RUN bash ./download-seda.sh
71 changes: 71 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "seda-chain-contracts",
"dockerComposeFile": "docker-compose.yml",
"service": "vscode",
"workspaceFolder": "/workspace",
// Comment the next line if you want to keep your containers running after VS Code shuts down.
"shutdownAction": "stopCompose",
"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"installZsh": "true",
"username": "vscode",
"uid": "1000",
"gid": "1000",
"upgradePackages": "true"
},
"ghcr.io/devcontainers/features/rust:1": "latest",
"ghcr.io/devcontainers/features/git:1": {
"version": "latest",
"ppa": "false"
}
},
"overrideFeatureInstallOrder": [
"ghcr.io/devcontainers/features/common-utils"
],
// Allow dubious ownership in GIT repository
"postStartCommand": "git config --global --add safe.directory $PWD",
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.rustfmt.extraArgs": [
"+nightly"
],
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"Tyriar.sort-lines",
"2gua.rainbow-brackets",
"oderwat.indent-rainbow",
"dtsvet.vscode-wasm"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"mounts": [
"source=${localWorkspaceFolderBasename}-target,target=${containerWorkspaceFolder}/target,type=volume"
],
"postCreateCommand": "sudo chown vscode target"
}
39 changes: 39 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3.8'

services:
vscode:
build:
context: .
dockerfile: Dockerfile
args:
VARIANT: ${DEBIAN_VARIANT:-bullseye}

volumes:
- ..:/workspace:cached
- /var/run/docker.sock:/var/run/docker.sock

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"

# Uncomment to run app on the same network as the service container, allows "forwardPorts" in devcontainer.json function.
# network_mode: service:another-service

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

# Uncomment the next line to use a non-root user for all processes - See https://aka.ms/vscode-remote/containers/non-root for details.
# user: vscode

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined

# Uncomment to include other services not opened by VS Code as well
# another-service:
# image: mongo:latest
# restart: unless-stopped
14 changes: 14 additions & 0 deletions .devcontainer/download-seda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
WASMVM_VERSION="v1.5.2"

ARCH=$(uname -m)
if [ $ARCH != "aarch64" ]; then
ARCH="x86_64"
fi

LIBWASMVM_URL=https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm.$ARCH.so
COSMOS_LDS=$HOME/COSMOS_LDS

printf "\n\n\nSETTING UP SHARED LIBRARY\n\n\n\n"
mkdir -p $COSMOS_LDS
curl -LO $LIBWASMVM_URL
mv $(basename $LIBWASMVM_URL) /usr/local/lib
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SEDA_RPC=
SEDA_BINARY_PATH=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
# IDEs
*.iml
.idea
sedad
.env
23 changes: 23 additions & 0 deletions scripts/1-deploy-without-proposal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Deploy the CosmWasm contract without creating a proposal
# This can only be used on devnet

# Exit if any command returns an error
set -eo pipefail

parent_path=$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
source ${parent_path}/../.env
source ${parent_path}/common.sh

# Check if seda binary is installed
check_binary
check_commands ${SEDA_BINARY_PATH} base64 uname jq

# Required variables
check_env_vars SEDA_CHAIN_RPC SEDA_CHAIN_ID SEDA_DEV_ACCOUNT

# Upload the proxy contract
proxy_contract_store_output="$($SEDA_BINARY_PATH tx wasm store ./artifacts/proxy_contract.wasm --node $SEDA_CHAIN_RPC --from $SEDA_DEV_ACCOUNT $TXN_GAS_FLAGS -y --output json --chain-id $SEDA_CHAIN_ID)"

echo $proxy_contract_store_output
172 changes: 172 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env bash

# If not defined, set to default values
TXN_GAS_FLAGS=${TXN_GAS_FLAGS:-"--gas-prices 100000000000aseda --gas auto --gas-adjustment 1.6"}
SLEEP_TIME=${SLEEP_TIME:-10}

# function: check if command exists
# Usage: check_commands <command_names...>
# Checks if the given commands are available in the system
check_commands(){
local command_names=("$@")
for command_name in "${command_names[@]}"; do
if ! command -v ${command_name} > /dev/null 2>&1; then
echo "Command \`${command_name}\` not found." >&2
command_unset=true
fi
done
[ -n "$command_unset" ] && exit 1

return 0
}

# function: check if env vars are set
# Usage: check_env_vars <var_names...>
# Checks if the given environment variables are set
check_env_vars(){
local var_names=("$@")
for var_name in "${var_names[@]}"; do
[ -z "${!var_name}" ] && echo "$var_name must be defined" >&2 && var_unset=true
done
[ -n "$var_unset" ] && exit 1

return 0
}

# function: check if seda binary is installed
# Usage: check_binary
# Checks if the seda binary is installed and sets the path if found
check_binary(){
if [ -z "${SEDA_BINARY_PATH}" ] && command -v sedad > /dev/null 2>&1; then
SEDA_BINARY_PATH=$(command -v sedad)
else
check_env_vars SEDA_BINARY_PATH
fi
}


# function: update .env file <NAME> <VALUE>
# Usage: update_env_file <NAME> <VALUE>
# Updates the .env file with the provided name and value
update_env_file() {
parent_path=$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
echo "# $(date)" >> "${parent_path}/.env"
echo "$1=$2" >> "${parent_path}/.env"
}

# function: store_contract CONTRACT_NAME_PATH
# Usage: store_contract <CONTRACT_NAME_PATH>
# Stores a contract using sedad
store_contract(){
output="$(${SEDA_BINARY_PATH} tx wasm store "$1" --node $SEDA_CHAIN_RPC --from $SEDA_DEV_ACCOUNT --chain-id $SEDA_CHAIN_ID ${TXN_GAS_FLAGS} --output json -y)"
txhash=$(echo $output | jq -r '.txhash')
echo "Transaction Hash: $txhash"
echo "Waiting to query for CODE_ID..."
sleep ${SLEEP_TIME}
output=$(${SEDA_BINARY_PATH} query tx $txhash --node $SEDA_CHAIN_RPC --output json)
CODE_ID=$(echo "$output" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "Deployed to CODE_ID=${CODE_ID}"
}

# function: instantiate_contract CODE_ID INSTANTIATE_MSG LABEL
# Usage: instantiate_contract <CODE_ID> <INSTANTIATE_MSG> <LABEL>
# Instantiates a contract using sedad
instantiate_contract(){
output=$(${SEDA_BINARY_PATH} tx wasm instantiate $1 $2 --from $SEDA_DEV_ACCOUNT --admin $SEDA_DEV_ACCOUNT --node $SEDA_CHAIN_RPC --label "$3" ${TXN_GAS_FLAGS} -y --output json --chain-id $SEDA_CHAIN_ID)
txhash=$(echo "$output" | jq -r '.txhash')
echo "Transaction Hash: $txhash"
echo "Waiting to query for CONTRACT_ADDRESS..."
sleep ${SLEEP_TIME}
output="$(${SEDA_BINARY_PATH} query tx $txhash --node $SEDA_CHAIN_RPC --output json)"
CONTRACT_ADDRESS=$(echo "$output" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
echo "Deployed to CONTRACT_ADDRESS=${CONTRACT_ADDRESS}"
}

# function: smart_query <QUERY_MSG>
# Usage: smart_query <QUERY_MSG>
# Queries the smart contract state using sedad
smart_query(){
OUTPUT="$(seda-chaind query wasm contract-state smart $SEDA_CW_TARGET_CONTRACT $1 --node $SEDA_CHAIN_RPC --output json)"
echo $OUTPUT
}

# function: wasm_execute <CONTRACT> <EXECUTE_MSG> <AMOUNT>
# Usage: wasm_execute <CONTRACT> <EXECUTE_MSG> <AMOUNT>
# Executes a wasm contract using sedad
wasm_execute(){
command="${SEDA_BINARY_PATH} tx wasm execute $1 $2 --from $SEDA_DEV_ACCOUNT --node $SEDA_CHAIN_RPC ${TXN_GAS_FLAGS} -y --output json --chain-id $SEDA_CHAIN_ID --amount "$3"seda"
echo "Command: $command"
output="$($command)"
echo $output
txhash=$(echo $output | jq -r '.txhash')
echo "Transaction Hash: $txhash"
}

# # migrate_call <OLD_CONTRACT_ADDRESS> <NEW_CODE_ID> <MIGRATION_MSG>
# migrate_call(){
# OUTPUT="$(${SEDA_BINARY_PATH} tx wasm migrate $1 $2 $3 --node $SEDA_CHAIN_RPC --output json --from $SEDA_DEV_ACCOUNT --node $SEDA_CHAIN_RPC ${TXN_GAS_FLAGS} -y --output json --chain-id $SEDA_CHAIN_ID)"
# echo $OUTPUT
# }

# function: transfer_seda <FROM> <TO> <AMOUNT>
# Usage: transfer_seda <FROM> <TO> <AMOUNT>
# Transfers a specified amount of seda tokens from one account to another using sedad
transfer_seda(){
command="${SEDA_BINARY_PATH} tx bank send $1 $2 ${3}seda --node $SEDA_CHAIN_RPC --chain-id $SEDA_CHAIN_ID ${TXN_GAS_FLAGS} --output json -y"
echo "Command: $command"
output="$($command)"
txhash=$(echo $output | jq -r '.txhash')
echo "Transaction Hash: $txhash"
}

# function: submit proposal <JSON_FILE> <FROM>
# Usage: submit_proposal <JSON_FILE> <FROM>
# Submits a proposal using the specified JSON file and account using sedad
submit_proposal(){
command="${SEDA_BINARY_PATH} tx group submit-proposal $1 --from $2 --node $SEDA_CHAIN_RPC --chain-id $SEDA_CHAIN_ID ${TXN_GAS_FLAGS} --output json -y"
echo "Command: $command"
output="$($command)"
txhash=$(echo $output | jq -r '.txhash')
echo "Transaction Hash: $txhash"
}

# function: vote proposal <PROPOSAL ID> <FROM> <VOTE_OPTION> <METADATA>
# Usage: vote_proposal <PROPOSAL ID> <FROM> <VOTE_OPTION> <METADATA>
# Votes on a proposal with the specified ID, account, vote option, and metadata using sedad
vote_proposal(){
command="${SEDA_BINARY_PATH} tx group vote $1 $2 $3 $4 --node $SEDA_CHAIN_RPC --chain-id $SEDA_CHAIN_ID ${TXN_GAS_FLAGS} --output json -y"
echo "Command: $command"
output="$($command)"
txhash=$(echo $output | jq -r '.txhash')
echo "Transaction Hash: $txhash"
}

# function: execute proposal <PROPOSAL ID> <FROM>
# Usage: exec_proposal <PROPOSAL ID> <FROM>
# Executes a proposal with the specified ID and account using sedad
exec_proposal(){
command="${SEDA_BINARY_PATH} tx group exec $1 --from $2 --node $SEDA_CHAIN_RPC --chain-id $SEDA_CHAIN_ID ${TXN_GAS_FLAGS} --output json -y"
echo "Command: $command"
output="$($command)"
txhash=$(echo $output | jq -r '.txhash')
echo "Transaction Hash: $txhash"
}

# function: query last proposal id
# Queries the ID of the last proposal using sedad
query_last_proposal_id(){
command="${SEDA_BINARY_PATH} query group proposals-by-group-policy $SEDA_GROUP_POLICY --node $SEDA_CHAIN_RPC --output json"
echo "Command: $command"
proposal_id="$($command | jq '.proposals[-1].id' | tr -d '"')"
echo "Last proposal ID: $proposal_id"
}

# function: query tally proposal <PROPOSAL_ID>
# Usage: query_tally_proposal <PROPOSAL_ID>
# Queries the tally result of a proposal with the specified ID using sedad
query_tally_proposal(){
command="${SEDA_BINARY_PATH} query group tally-result $1 --node $SEDA_CHAIN_RPC --output json"
echo "Command: $command"
tally_result="$($command | jq)"
echo "Tally: $tally_result"
}

0 comments on commit 35de27d

Please sign in to comment.