-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdeploy_mainnet.sh
More file actions
executable file
·355 lines (298 loc) · 10.4 KB
/
Copy pathdeploy_mainnet.sh
File metadata and controls
executable file
·355 lines (298 loc) · 10.4 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/bash
#
# Boundless mainnet deploy script.
#
# This is a separate script from deploy_and_upgrade.sh because mainnet deploys
# need stronger guards (explicit confirmation, env var validation, paired
# deploy of profile + events, multi-sig rotation flow) than the testnet
# scripted path can carry safely.
#
# Companion: boundless-contract/docs/mainnet-deploy-runbook.md
#
# Usage:
# ./deploy_mainnet.sh deploy-profile
# ./deploy_mainnet.sh deploy-events
# ./deploy_mainnet.sh register-token <token-sac-address>
# ./deploy_mainnet.sh rotate-admin <new-multisig-address>
# ./deploy_mainnet.sh upgrade-events <wasm-path>
# ./deploy_mainnet.sh verify
set -euo pipefail
ACTION="${1:-}"
shift || true
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
NETWORK="mainnet"
NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
DEPLOYMENTS_DIR="$(cd "$(dirname "$0")" && pwd)/deployments"
DEPLOYMENT_FILE="$DEPLOYMENTS_DIR/mainnet.json"
err() {
echo -e "${RED}error: $*${NC}" >&2
exit 1
}
info() {
echo -e "${YELLOW}$*${NC}"
}
ok() {
echo -e "${GREEN}$*${NC}"
}
confirm_mainnet() {
echo -e "${BOLD}You are about to operate on Stellar MAINNET.${NC}"
echo "Network passphrase: $NETWORK_PASSPHRASE"
echo ""
read -rp "Type 'mainnet' to continue: " ack
if [ "$ack" != "mainnet" ]; then
err "aborted"
fi
}
require_env() {
local var="$1"
if [ -z "${!var:-}" ]; then
err "missing required env var: $var"
fi
}
require_cli() {
command -v stellar >/dev/null 2>&1 || err "stellar CLI not on PATH"
command -v jq >/dev/null 2>&1 || err "jq not on PATH"
command -v sha256sum >/dev/null 2>&1 || command -v shasum >/dev/null 2>&1 || \
err "sha256sum or shasum not on PATH"
}
hash_wasm() {
local f="$1"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$f" | cut -d' ' -f1
else
shasum -a 256 "$f" | cut -d' ' -f1
fi
}
ensure_deployments_dir() {
mkdir -p "$DEPLOYMENTS_DIR"
if [ ! -f "$DEPLOYMENT_FILE" ]; then
echo "{\"network\":\"$NETWORK\",\"passphrase\":\"$NETWORK_PASSPHRASE\"}" > "$DEPLOYMENT_FILE"
fi
}
deployment_get() {
local key="$1"
jq -r ".\"$key\" // empty" "$DEPLOYMENT_FILE"
}
deployment_set() {
local key="$1" val="$2"
local tmp
tmp="$(mktemp)"
jq ".\"$key\" = \"$val\"" "$DEPLOYMENT_FILE" > "$tmp"
mv "$tmp" "$DEPLOYMENT_FILE"
}
deployment_set_raw() {
local key="$1" val="$2"
local tmp
tmp="$(mktemp)"
jq ".\"$key\" = $val" "$DEPLOYMENT_FILE" > "$tmp"
mv "$tmp" "$DEPLOYMENT_FILE"
}
cmd_build_release() {
info "Building contracts in release mode..."
stellar contract build
ok "Build complete."
}
cmd_deploy_profile() {
require_env INITIAL_ADMIN_KEY
require_env BOOTSTRAP_PROFILE_CREDITS
require_cli
confirm_mainnet
ensure_deployments_dir
if [ -n "$(deployment_get profile_contract)" ]; then
err "profile contract already deployed: $(deployment_get profile_contract). Refusing to re-deploy."
fi
cmd_build_release
local wasm="target/wasm32-unknown-unknown/release/boundless_profile.wasm"
[ -f "$wasm" ] || err "missing wasm: $wasm"
info "Deploying boundless-profile..."
local profile_id
profile_id=$(stellar contract deploy \
--network "$NETWORK" \
--source "$INITIAL_ADMIN_KEY" \
--wasm "$wasm" \
-- \
--admin "$(stellar keys address "$INITIAL_ADMIN_KEY")" \
--bootstrap_credits "$BOOTSTRAP_PROFILE_CREDITS")
ok "profile_contract=$profile_id"
deployment_set profile_contract "$profile_id"
deployment_set profile_wasm_hash "$(hash_wasm "$wasm")"
deployment_set deployed_at "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
cmd_deploy_events() {
require_env INITIAL_ADMIN_KEY
require_env FEE_ACCOUNT
require_env INITIAL_GLOBAL_FEE_BPS
require_cli
confirm_mainnet
ensure_deployments_dir
local profile_id
profile_id="$(deployment_get profile_contract)"
[ -n "$profile_id" ] || err "deploy-profile first; profile_contract not set"
if [ -n "$(deployment_get events_contract)" ]; then
err "events contract already deployed: $(deployment_get events_contract). Refusing to re-deploy. Use upgrade-events instead."
fi
cmd_build_release
local wasm="target/wasm32-unknown-unknown/release/boundless_events.wasm"
[ -f "$wasm" ] || err "missing wasm: $wasm"
info "Deploying boundless-events..."
local events_id
events_id=$(stellar contract deploy \
--network "$NETWORK" \
--source "$INITIAL_ADMIN_KEY" \
--wasm "$wasm" \
-- \
--admin "$(stellar keys address "$INITIAL_ADMIN_KEY")" \
--fee_account "$FEE_ACCOUNT" \
--fee_bps "$INITIAL_GLOBAL_FEE_BPS" \
--profile_contract "$profile_id")
ok "events_contract=$events_id"
deployment_set events_contract "$events_id"
deployment_set events_wasm_hash "$(hash_wasm "$wasm")"
deployment_set fee_account "$FEE_ACCOUNT"
deployment_set_raw initial_fee_bps "$INITIAL_GLOBAL_FEE_BPS"
info "Wiring profile -> events..."
stellar contract invoke \
--network "$NETWORK" \
--source "$INITIAL_ADMIN_KEY" \
--id "$profile_id" \
-- set_events_contract \
--new_addr "$events_id"
ok "profile.events_contract = $events_id"
}
cmd_register_token() {
local token="${1:-}"
[ -n "$token" ] || err "usage: register-token <token-sac-address>"
require_env INITIAL_ADMIN_KEY
require_cli
confirm_mainnet
local events_id
events_id="$(deployment_get events_contract)"
[ -n "$events_id" ] || err "events contract not deployed"
info "Registering token $token..."
stellar contract invoke \
--network "$NETWORK" \
--source "$INITIAL_ADMIN_KEY" \
--id "$events_id" \
-- register_supported_token \
--token "$token"
local supported
supported=$(stellar contract invoke \
--network "$NETWORK" \
--source "$INITIAL_ADMIN_KEY" \
--id "$events_id" \
-- is_supported_token \
--token "$token")
[ "$supported" = "true" ] || err "token registration not confirmed; got: $supported"
ok "Token registered: $token"
# Append to registered_tokens array.
local tmp
tmp="$(mktemp)"
jq ".registered_tokens = ((.registered_tokens // []) + [\"$token\"] | unique)" \
"$DEPLOYMENT_FILE" > "$tmp"
mv "$tmp" "$DEPLOYMENT_FILE"
}
cmd_rotate_admin() {
local new_admin="${1:-}"
[ -n "$new_admin" ] || err "usage: rotate-admin <new-multisig-address>"
require_env INITIAL_ADMIN_KEY
require_cli
confirm_mainnet
local events_id profile_id
events_id="$(deployment_get events_contract)"
profile_id="$(deployment_get profile_contract)"
[ -n "$events_id" ] || err "events contract not deployed"
[ -n "$profile_id" ] || err "profile contract not deployed"
info "Setting pending admin on events..."
stellar contract invoke \
--network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$events_id" \
-- set_admin --new_admin "$new_admin"
info "Setting pending admin on profile..."
stellar contract invoke \
--network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$profile_id" \
-- set_admin --new_admin "$new_admin"
echo ""
echo -e "${BOLD}Now the new admin ($new_admin) must call accept_admin on both contracts.${NC}"
echo "This step requires the multi-sig quorum to sign. After both accept ops"
echo "land, run 'verify' to confirm get_admin returns the new address."
}
cmd_upgrade_events() {
local wasm="${1:-}"
[ -n "$wasm" ] || err "usage: upgrade-events <path-to-new-wasm>"
[ -f "$wasm" ] || err "wasm file not found: $wasm"
require_env ADMIN_SOURCE
require_cli
confirm_mainnet
local events_id
events_id="$(deployment_get events_contract)"
[ -n "$events_id" ] || err "events contract not deployed"
info "Uploading new wasm..."
local wasm_hash
wasm_hash=$(stellar contract upload \
--source-account "$ADMIN_SOURCE" \
--network "$NETWORK" \
--wasm "$wasm")
info "Upgrading events contract to $wasm_hash..."
stellar contract invoke \
--network "$NETWORK" \
--source "$ADMIN_SOURCE" \
--id "$events_id" \
-- upgrade \
--new_wasm_hash "$wasm_hash"
# Append to upgrade log.
local upgrades_log="$DEPLOYMENTS_DIR/mainnet-upgrades.jsonl"
echo "{\"timestamp\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"wasm_hash\":\"$wasm_hash\",\"wasm_path\":\"$wasm\"}" \
>> "$upgrades_log"
deployment_set events_wasm_hash "$(hash_wasm "$wasm")"
ok "Events contract upgraded to $wasm_hash."
}
cmd_verify() {
require_env INITIAL_ADMIN_KEY # for the read-source; any key works for invoke-as-read
require_cli
local events_id profile_id
events_id="$(deployment_get events_contract)"
profile_id="$(deployment_get profile_contract)"
[ -n "$events_id" ] || err "events contract not in deployment file"
[ -n "$profile_id" ] || err "profile contract not in deployment file"
info "Verifying mainnet state..."
echo "events.get_admin:"
stellar contract invoke --network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$events_id" -- get_admin
echo "events.get_fee_bps:"
stellar contract invoke --network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$events_id" -- get_fee_bps
echo "events.get_fee_account:"
stellar contract invoke --network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$events_id" -- get_fee_account
echo "events.is_paused:"
stellar contract invoke --network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$events_id" -- is_paused
echo "profile.get_admin:"
stellar contract invoke --network "$NETWORK" --source "$INITIAL_ADMIN_KEY" --id "$profile_id" -- get_admin
ok "Verification reads complete. Compare against the runbook expectations."
}
case "$ACTION" in
"deploy-profile")
cmd_deploy_profile
;;
"deploy-events")
cmd_deploy_events
;;
"register-token")
cmd_register_token "$@"
;;
"rotate-admin")
cmd_rotate_admin "$@"
;;
"upgrade-events")
cmd_upgrade_events "$@"
;;
"verify")
cmd_verify
;;
"")
err "no action specified. See mainnet-deploy-runbook.md for usage."
;;
*)
err "unknown action: $ACTION. See mainnet-deploy-runbook.md for usage."
;;
esac