From 3dd5c802f707e890f082659e07edc85cd9c530aa Mon Sep 17 00:00:00 2001 From: snowrugar-beep Date: Wed, 27 May 2026 15:17:21 +0000 Subject: [PATCH] feat: set up Soroban testnet deployment pipeline (#160) - Add scripts/deploy.sh: idempotent deploy script for testnet/sandbox/mainnet - Loads funded admin keypair from .env (SOROBAN_ADMIN_SECRET_KEY) - Outputs deployed contract ID to stdout - Saves deployment record to deployments/.json - Skips re-deploy if deployments/.json already exists (idempotent) - Validates WASM exists and secret key is set before attempting deploy - Add deployments/ directory tracked via .gitkeep - Update .gitignore to exclude deployments/*.json and .stellaraid_contract_id Usage: bash scripts/deploy.sh testnet # deploy to Stellar testnet bash scripts/deploy.sh sandbox # deploy to local sandbox bash scripts/deploy.sh mainnet # deploy to mainnet Closes #160 --- .gitignore | 4 ++ deployments/.gitkeep | 0 scripts/deploy.sh | 106 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 deployments/.gitkeep create mode 100755 scripts/deploy.sh diff --git a/.gitignore b/.gitignore index e4a1730..e8dd875 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ Thumbs.db # Soroban .stellar/ soroban.toml + +# Deployment records (network-specific; commit intentionally when needed) +deployments/*.json +.stellaraid_contract_id diff --git a/deployments/.gitkeep b/deployments/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..56e6bde --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +# scripts/deploy.sh — Deploy StellarAid core contract to a Soroban network. +# +# Usage: +# bash scripts/deploy.sh [testnet|sandbox|mainnet] +# +# Environment variables (loaded from .env if present): +# SOROBAN_ADMIN_SECRET_KEY — funded account secret key (required) +# SOROBAN_NETWORK — fallback network name (default: testnet) +# +# Closes #160 + +set -euo pipefail + +# ── Load .env if present ────────────────────────────────────────────────────── +if [ -f ".env" ]; then + # shellcheck disable=SC1091 + set -o allexport + source .env + set +o allexport +fi + +# ── Resolve network ─────────────────────────────────────────────────────────── +NETWORK="${1:-${SOROBAN_NETWORK:-testnet}}" + +# ── Network-specific RPC / passphrase ──────────────────────────────────────── +case "$NETWORK" in + testnet) + RPC_URL="${SOROBAN_TESTNET_RPC_URL:-https://soroban-testnet.stellar.org:443}" + PASSPHRASE="${SOROBAN_TESTNET_PASSPHRASE:-Test SDF Network ; September 2015}" + ;; + mainnet) + RPC_URL="${SOROBAN_MAINNET_RPC_URL:-https://soroban-rpc.mainnet.stellar.gateway.fm}" + PASSPHRASE="${SOROBAN_MAINNET_PASSPHRASE:-Public Global Stellar Network ; September 2015}" + ;; + sandbox) + RPC_URL="${SOROBAN_SANDBOX_RPC_URL:-http://localhost:8000/soroban/rpc}" + PASSPHRASE="${SOROBAN_SANDBOX_PASSPHRASE:-Standalone Network ; February 2017}" + ;; + *) + echo "❌ Unknown network: $NETWORK (use testnet | sandbox | mainnet)" + exit 1 + ;; +esac + +# ── Paths ───────────────────────────────────────────────────────────────────── +WASM_PATH="target/wasm32-unknown-unknown/release/stellaraid_core.wasm" +DEPLOYMENTS_DIR="deployments" +DEPLOYMENT_FILE="${DEPLOYMENTS_DIR}/${NETWORK}.json" + +# ── Validate prerequisites ──────────────────────────────────────────────────── +if [ ! -f "$WASM_PATH" ]; then + echo "❌ WASM not found at $WASM_PATH — run 'make build-wasm' first" + exit 1 +fi + +if [ -z "${SOROBAN_ADMIN_SECRET_KEY:-}" ]; then + echo "❌ SOROBAN_ADMIN_SECRET_KEY is not set." + echo " Add it to .env or export it before running this script." + exit 1 +fi + +# ── Idempotency check ───────────────────────────────────────────────────────── +if [ -f "$DEPLOYMENT_FILE" ]; then + EXISTING_ID=$(python3 -c \ + "import json; d=json.load(open('$DEPLOYMENT_FILE')); print(d.get('contract_id',''))" \ + 2>/dev/null || true) + if [ -n "$EXISTING_ID" ]; then + echo "ℹ️ Contract already deployed on $NETWORK: $EXISTING_ID" + echo " Delete $DEPLOYMENT_FILE to force a re-deploy." + exit 0 + fi +fi + +# ── Deploy ──────────────────────────────────────────────────────────────────── +echo "🚀 Deploying StellarAid core contract to $NETWORK..." +echo " RPC: $RPC_URL" +echo " WASM: $WASM_PATH" + +CONTRACT_ID=$(stellar contract deploy \ + --wasm "$WASM_PATH" \ + --source "$SOROBAN_ADMIN_SECRET_KEY" \ + --rpc-url "$RPC_URL" \ + --network-passphrase "$PASSPHRASE") + +echo "✅ Contract deployed!" +echo "📝 Contract ID: $CONTRACT_ID" + +# ── Persist deployment record ───────────────────────────────────────────────── +mkdir -p "$DEPLOYMENTS_DIR" +TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") +cat > "$DEPLOYMENT_FILE" < .stellaraid_contract_id +echo "✅ Contract ID also stored in .stellaraid_contract_id"