forked from Ledger-Lenz/Ledgerlens-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·149 lines (121 loc) · 5.75 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·149 lines (121 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
# Build, optimize, deploy and initialize the LedgerLens score contract.
#
# Usage:
# ./deploy.sh [options] <network> <admin-identity> <service-address>
#
# Options:
# --dry-run Print the commands that would be executed without running them.
# --help Show this help message.
#
# Arguments:
# network soroban CLI network alias (e.g. testnet, futurenet)
# admin-identity soroban CLI identity used to deploy and initialize
# service-address Stellar public key authorised to call submit_score
set -euo pipefail
DRY_RUN=false
POSITIONAL=()
for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN=true ;;
--help)
sed -n '3,20p' "$0"
exit 0
;;
*) POSITIONAL+=("$arg") ;;
esac
done
set -- "${POSITIONAL[@]+"${POSITIONAL[@]}"}"
NETWORK="${1:-testnet}"
ADMIN_IDENTITY="${2:-deployer}"
SERVICE_ADDRESS="${3:?ERROR: service-address argument is required}"
WASM_PATH="target/wasm32-unknown-unknown/release/ledgerlens_score.wasm"
OPTIMIZED_WASM_PATH="target/wasm32-unknown-unknown/release/ledgerlens_score.optimized.wasm"
# ── Helpers ───────────────────────────────────────────────────────────────────
run() {
if [ "$DRY_RUN" = true ]; then
echo "[dry-run] $*"
else
"$@"
fi
}
log() { echo "==> $*"; }
# ── Validate inputs ───────────────────────────────────────────────────────────
case "$NETWORK" in
testnet|futurenet|mainnet) ;;
*)
echo "WARNING: '$NETWORK' is not a recognised Stellar network alias." >&2
echo " Proceeding anyway — ensure the alias is configured in soroban config." >&2
;;
esac
if [ "$NETWORK" = "mainnet" ]; then
echo ""
echo " ╔══════════════════════════════════════════════════════╗"
echo " ║ MAINNET DEPLOYMENT — this action cannot be undone ║"
echo " ╚══════════════════════════════════════════════════════╝"
echo ""
read -rp " Type 'deploy-mainnet' to confirm: " CONFIRM
[ "$CONFIRM" = "deploy-mainnet" ] || { echo "Aborted."; exit 1; }
fi
# ── Build ─────────────────────────────────────────────────────────────────────
log "Building contract (wasm32-unknown-unknown, release)"
run cargo build --target wasm32-unknown-unknown --release -p ledgerlens-score
log "Optimizing wasm"
run soroban contract optimize --wasm "$WASM_PATH"
# ── Deploy ────────────────────────────────────────────────────────────────────
log "Deploying to $NETWORK"
if [ "$DRY_RUN" = true ]; then
CONTRACT_ID="<CONTRACT_ID_PLACEHOLDER>"
echo "[dry-run] soroban contract deploy --wasm $OPTIMIZED_WASM_PATH --source $ADMIN_IDENTITY --network $NETWORK"
else
CONTRACT_ID=$(soroban contract deploy \
--wasm "$OPTIMIZED_WASM_PATH" \
--source "$ADMIN_IDENTITY" \
--network "$NETWORK")
fi
log "Deployed contract: $CONTRACT_ID"
# ── Initialize ────────────────────────────────────────────────────────────────
ADMIN_ADDRESS=$(run soroban keys address "$ADMIN_IDENTITY" 2>/dev/null || echo "<ADMIN_ADDRESS>")
log "Initializing contract (admin=$ADMIN_ADDRESS, service=$SERVICE_ADDRESS)"
run soroban contract invoke \
--id "$CONTRACT_ID" \
--source "$ADMIN_IDENTITY" \
--network "$NETWORK" \
-- \
initialize \
--admin "$ADMIN_ADDRESS" \
--service "$SERVICE_ADDRESS"
# ── Verify ────────────────────────────────────────────────────────────────────
log "Verifying deployment"
if [ "$DRY_RUN" = false ]; then
STORED_ADMIN=$(soroban contract invoke \
--id "$CONTRACT_ID" \
--source "$ADMIN_IDENTITY" \
--network "$NETWORK" \
-- \
get_admin 2>/dev/null || echo "VERIFICATION_FAILED")
if [ "$STORED_ADMIN" = "VERIFICATION_FAILED" ]; then
echo "ERROR: post-deployment verification failed — get_admin returned an error." >&2
exit 1
fi
log "Admin verified on-chain: $STORED_ADMIN"
CONTRACT_VERSION=$(soroban contract invoke \
--id "$CONTRACT_ID" \
--source "$ADMIN_IDENTITY" \
--network "$NETWORK" \
-- \
get_version 2>/dev/null || echo "0")
log "Contract version: $CONTRACT_VERSION"
fi
# ── Summary ───────────────────────────────────────────────────────────────────
echo ""
echo " ── Deployment complete ──────────────────────────────────"
echo " Network: $NETWORK"
echo " Contract: $CONTRACT_ID"
echo " Admin: $ADMIN_ADDRESS"
echo " Service: $SERVICE_ADDRESS"
echo " ─────────────────────────────────────────────────────────"
echo ""
echo " Save CONTRACT_ID=$CONTRACT_ID in your environment and in"
echo " the api repo's .env before routing submit_score calls."
echo ""