Skip to content
Open
Changes from all 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
70 changes: 14 additions & 56 deletions scripts/deploy_testnet.sh
Original file line number Diff line number Diff line change
@@ -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" <<EOF
# Auto-generated by scripts/deploy_testnet.sh — do not edit manually
STELLAR_NETWORK=${STELLAR_NETWORK}
PAYMENT_PROCESSOR_ID=${PAYMENT_PROCESSOR_ID}
REFUND_MANAGER_ID=${REFUND_MANAGER_ID}
MERCHANT_REGISTRY_ID=${MERCHANT_REGISTRY_ID}
FX_ORACLE_ID=${FX_ORACLE_ID}
EOF
echo "Auto-funding deployer account ($PUBLIC_KEY) via Stellar Testnet Friendbot Faucet..."
curl -X POST -s "https://friendbot.stellar.org?addr=${PUBLIC_KEY}" > /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"