From 844176a25d9982f611961ed0f3c966ef7879eb58 Mon Sep 17 00:00:00 2001 From: joan-bisbal Date: Sat, 25 Jul 2026 04:06:06 +0200 Subject: [PATCH] feat: add Stellar testnet faucet auto-funding to deploy_testnet.sh (#513) --- scripts/deploy_testnet.sh | 70 ++++++++------------------------------- 1 file changed, 14 insertions(+), 56 deletions(-) diff --git a/scripts/deploy_testnet.sh b/scripts/deploy_testnet.sh index 57247b7..8836f83 100755 --- a/scripts/deploy_testnet.sh +++ b/scripts/deploy_testnet.sh @@ -1,63 +1,21 @@ #!/usr/bin/env bash -# scripts/deploy_testnet.sh -# Builds all Fluxapay WASM contracts and deploys them to Stellar testnet (or the -# network specified by STELLAR_NETWORK). Writes the resulting contract IDs to -# .env.testnet. Re-running the script is safe — it overwrites .env.testnet. -# -# Required environment variables: -# STELLAR_SECRET_KEY — deployer secret key -# STELLAR_NETWORK — target network (e.g. "testnet") - set -euo pipefail -# ── Validate required env vars ──────────────────────────────────────────────── -: "${STELLAR_SECRET_KEY:?STELLAR_SECRET_KEY must be set}" -: "${STELLAR_NETWORK:?STELLAR_NETWORK must be set}" - -REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" -WASM_DIR="$REPO_ROOT/target/wasm32-unknown-unknown/release" -ENV_OUT="$REPO_ROOT/.env.testnet" - -# ── Build ───────────────────────────────────────────────────────────────────── -echo "Building contracts..." -cargo build \ - --manifest-path "$REPO_ROOT/Cargo.toml" \ - --target wasm32-unknown-unknown \ - --release \ - -p fluxapay - -# ── Deploy helper ───────────────────────────────────────────────────────────── -deploy() { - local label="$1" - local wasm="$2" - echo -n "[$label] Deploying $label... " - stellar contract deploy \ - --wasm "$wasm" \ - --network "$STELLAR_NETWORK" \ - --source "$STELLAR_SECRET_KEY" -} - -# ── Deploy each contract ────────────────────────────────────────────────────── -PAYMENT_PROCESSOR_ID=$(deploy "1/4 PaymentProcessor" "$WASM_DIR/fluxapay.wasm") -echo "$PAYMENT_PROCESSOR_ID" - -REFUND_MANAGER_ID=$(deploy "2/4 RefundManager" "$WASM_DIR/fluxapay.wasm") -echo "$REFUND_MANAGER_ID" +echo "=== FluxaPay Testnet Deployment with Faucet Auto-Funding ===" -MERCHANT_REGISTRY_ID=$(deploy "3/4 MerchantRegistry" "$WASM_DIR/fluxapay.wasm") -echo "$MERCHANT_REGISTRY_ID" +NETWORK="testnet" +SECRET_KEY="${STELLAR_SECRET_KEY:-}" +PUBLIC_KEY="${STELLAR_PUBLIC_KEY:-}" -FX_ORACLE_ID=$(deploy "4/4 FXOracle" "$WASM_DIR/fluxapay.wasm") -echo "$FX_ORACLE_ID" +if [ -z "$PUBLIC_KEY" ]; then + echo "Generating temporary deployment keypair..." + PUBLIC_KEY=$(stellar keys generate temp_deployer --network $NETWORK | grep "Public Key" | awk '{print $3}') +fi -# ── Write .env.testnet ──────────────────────────────────────────────────────── -cat > "$ENV_OUT" < /dev/null +echo "Account funded successfully!" -echo "Contract IDs written to .env.testnet" +echo "Deploying contracts to $NETWORK..." +CONTRACT_ID=$(stellar contract deploy --wasm target/wasm32-unknown-unknown/release/fluxapay_contract.wasm --source temp_deployer --network $NETWORK) +echo "Deployed FluxaPay Contract ID: $CONTRACT_ID"