-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdeploy_mainnet.sh
More file actions
executable file
·1457 lines (1303 loc) · 54.1 KB
/
Copy pathdeploy_mainnet.sh
File metadata and controls
executable file
·1457 lines (1303 loc) · 54.1 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/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 upload-profile-wasm <wasm-path>
# ./deploy_mainnet.sh upload-events-wasm <wasm-path>
# ./deploy_mainnet.sh prepare-pause-profile <xdr-output>
# ./deploy_mainnet.sh prepare-pause-events <xdr-output>
# ./deploy_mainnet.sh prepare-propose-upgrade-profile <wasm-path> <new-version> <xdr-output>
# ./deploy_mainnet.sh prepare-propose-upgrade-events <wasm-path> <new-version> <xdr-output>
# ./deploy_mainnet.sh verify-proposed-upgrade-profile <wasm-path> <new-version>
# ./deploy_mainnet.sh verify-proposed-upgrade-events <wasm-path> <new-version>
# ./deploy_mainnet.sh prepare-apply-upgrade-profile <wasm-path> <expected-version> <xdr-output>
# ./deploy_mainnet.sh prepare-apply-upgrade-events <wasm-path> <expected-version> <xdr-output>
# ./deploy_mainnet.sh prepare-migrate-upgrade-profile <expected-version> <xdr-output>
# ./deploy_mainnet.sh prepare-migrate-upgrade-events <expected-version> <xdr-output>
# ./deploy_mainnet.sh prepare-cancel-upgrade-profile <xdr-output>
# ./deploy_mainnet.sh prepare-cancel-upgrade-events <xdr-output>
# ./deploy_mainnet.sh prepare-unpause-profile <expected-version> <xdr-output>
# ./deploy_mainnet.sh prepare-unpause-events <expected-version> <xdr-output>
# ./deploy_mainnet.sh verify-upgrade-profile <wasm-path> <expected-version>
# ./deploy_mainnet.sh verify-upgrade-events <wasm-path> <expected-version>
# ./deploy_mainnet.sh upgrade-status
# ./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="${STELLAR_NETWORK:-}"
NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
REQUIRED_STELLAR_CLI_VERSION="27.0.0"
SDK27_EVENTS_VERSION="1.5.0"
SDK27_EVENTS_WASM_HASH="31b27e9d5fe554e0710161dd9387693e166bdd755d985a9771b1ed71b9e28321"
SDK27_PROFILE_VERSION="1.2.0"
SDK27_PROFILE_WASM_HASH="d2d025d0f7c2c29e6dbd95401841cf62b8b61be608c48615cffb5934050890c0"
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 "CLI network config: $NETWORK"
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() {
[ -n "$NETWORK" ] || \
err "set STELLAR_NETWORK to the configured mainnet network name"
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 awk >/dev/null 2>&1 || err "awk not on PATH"
command -v sha256sum >/dev/null 2>&1 || command -v shasum >/dev/null 2>&1 || \
err "sha256sum or shasum not on PATH"
local stellar_cli_version
stellar_cli_version="$(stellar --version | awk 'NR == 1 { print $2 }')"
[ "$stellar_cli_version" = "$REQUIRED_STELLAR_CLI_VERSION" ] || \
err "stellar CLI version mismatch: expected $REQUIRED_STELLAR_CLI_VERSION, got ${stellar_cli_version:-unknown}"
if [ -n "${STELLAR_RPC_URL:-}" ] || [ -n "${STELLAR_NETWORK_PASSPHRASE:-}" ]; then
err "unset STELLAR_RPC_URL and STELLAR_NETWORK_PASSPHRASE when using --network $NETWORK"
fi
local networks configured_rpc configured_passphrase
networks="$(stellar network ls --long)"
configured_rpc="$(printf '%s\n' "$networks" | awk -v target="$NETWORK" '
$0 == "Name: " target { found = 1; next }
found && /^RPC url: / { sub(/^RPC url: /, ""); print; exit }
found && /^Name: / { exit }
')"
configured_passphrase="$(printf '%s\n' "$networks" | awk -v target="$NETWORK" '
$0 == "Name: " target { found = 1; next }
found && /^Network passphrase: / {
sub(/^Network passphrase: /, ""); print; exit
}
found && /^Name: / { exit }
')"
[ "$configured_passphrase" = "$NETWORK_PASSPHRASE" ] || \
err "network $NETWORK is not configured with the Stellar public-network passphrase"
[ -n "$configured_rpc" ] && [[ "$configured_rpc" != "Bring Your Own:"* ]] || \
err "network $NETWORK does not have a usable RPC URL"
}
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
}
deployed_wasm_hash() {
local contract_id="$1"
stellar contract info hash \
--network "$NETWORK" \
--contract-id "$contract_id"
}
assert_local_wasm_hash() {
local label="$1" wasm="$2" expected="$3"
local actual
actual="$(hash_wasm "$wasm")"
[ "$actual" = "$expected" ] || \
err "$label artifact hash mismatch: expected $expected, got $actual"
}
assert_deployed_wasm_hash() {
local label="$1" contract_id="$2" expected="$3"
local actual
actual="$(deployed_wasm_hash "$contract_id")" || \
err "could not read deployed $label WASM hash"
[ "$actual" = "$expected" ] || \
err "deployed $label WASM hash mismatch: expected $expected, got $actual"
}
assert_sdk27_profile_artifact() {
local wasm="$1" version="$2"
if [ "$version" = "$SDK27_PROFILE_VERSION" ]; then
assert_local_wasm_hash "profile SDK 27" "$wasm" "$SDK27_PROFILE_WASM_HASH"
fi
}
assert_sdk27_events_artifact() {
local wasm="$1" version="$2"
if [ "$version" = "$SDK27_EVENTS_VERSION" ]; then
assert_local_wasm_hash "events SDK 27" "$wasm" "$SDK27_EVENTS_WASM_HASH"
fi
}
assert_profile_sdk27_wasm_live() {
assert_deployed_wasm_hash "profile SDK 27" "$1" "$SDK27_PROFILE_WASM_HASH"
}
assert_events_sdk27_wasm_live() {
assert_deployed_wasm_hash "events SDK 27" "$1" "$SDK27_EVENTS_WASM_HASH"
}
assert_version_argument() {
local label="$1" actual="$2" expected="$3"
[ "$actual" = "$expected" ] || \
err "$label version must be $expected for this pinned mainnet flow; got $actual"
}
assert_unpause_version_argument() {
local label="$1" actual="$2" upgraded="$3"
case "$actual" in
"1.1.0"|"$upgraded") ;;
*) err "$label unpause version must be 1.1.0 for pre-apply recovery or $upgraded after upgrade; got $actual" ;;
esac
}
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"
}
events_contract_id() {
local events_id="${EVENTS_ID:-}"
if [ -z "$events_id" ] && [ -f "$DEPLOYMENT_FILE" ]; then
events_id="$(deployment_get events_contract)"
fi
[ -n "$events_id" ] || \
err "events contract id missing; set EVENTS_ID or restore deployments/mainnet.json"
printf '%s\n' "$events_id"
}
profile_contract_id() {
local profile_id="${PROFILE_ID:-}"
if [ -z "$profile_id" ] && [ -f "$DEPLOYMENT_FILE" ]; then
profile_id="$(deployment_get profile_contract)"
fi
[ -n "$profile_id" ] || \
err "profile contract id missing; set PROFILE_ID or restore deployments/mainnet.json"
printf '%s\n' "$profile_id"
}
events_read() {
local events_id="$1"
shift
stellar contract invoke \
--send no \
--network "$NETWORK" \
--source "$ADMIN_SOURCE" \
--id "$events_id" \
-- "$@"
}
profile_read() {
local profile_id="$1"
shift
stellar contract invoke \
--send no \
--network "$NETWORK" \
--source "$ADMIN_SOURCE" \
--id "$profile_id" \
-- "$@"
}
read_json_string() {
jq -er 'if type == "string" then . else error("expected JSON string") end'
}
assert_events_version() {
local events_id="$1" expected="$2"
local actual
actual="$(events_read "$events_id" version | read_json_string)" || \
err "could not read the current events contract version"
[ "$actual" = "$expected" ] || \
err "events version mismatch: expected $expected, got $actual"
}
assert_profile_version() {
local profile_id="$1" expected="$2"
local actual
actual="$(profile_read "$profile_id" version | read_json_string)" || \
err "could not read the current profile contract version"
[ "$actual" = "$expected" ] || \
err "profile version mismatch: expected $expected, got $actual"
}
assert_admin_source_matches() {
local events_id="$1"
local actual_admin
actual_admin="$(events_read "$events_id" get_admin | read_json_string)" || \
err "could not read the current events admin"
[ "$actual_admin" = "$ADMIN_SOURCE" ] || \
err "ADMIN_SOURCE mismatch: contract admin is $actual_admin, got $ADMIN_SOURCE"
}
assert_profile_admin_source_matches() {
local profile_id="$1"
local actual_admin
actual_admin="$(profile_read "$profile_id" get_admin | read_json_string)" || \
err "could not read the current profile admin"
[ "$actual_admin" = "$ADMIN_SOURCE" ] || \
err "ADMIN_SOURCE mismatch: profile contract admin is $actual_admin, got $ADMIN_SOURCE"
}
assert_profile_events_binding() {
local profile_id="$1" expected_events_id="$2"
local actual_events_id
actual_events_id="$(profile_read "$profile_id" get_events_contract | read_json_string)" || \
err "could not read profile.get_events_contract"
[ "$actual_events_id" = "$expected_events_id" ] || \
err "profile events-contract binding changed: expected $expected_events_id, got $actual_events_id"
}
assert_no_pending_events_contract_rotation() {
local profile_id="$1"
local pending
pending="$(profile_read "$profile_id" get_pending_events_contract)" || \
err "could not read profile.get_pending_events_contract"
[ "$pending" = "null" ] || \
err "a profile events-contract rotation is pending; cancel or complete it before the upgrade"
}
assert_upgrade_governance_stable() {
local profile_id="$1" events_id="$2"
assert_admin_source_matches "$events_id"
assert_profile_admin_source_matches "$profile_id"
assert_profile_events_binding "$profile_id" "$events_id"
assert_no_pending_events_contract_rotation "$profile_id"
}
assert_events_paused() {
local events_id="$1"
local paused
paused="$(events_read "$events_id" is_paused)" || \
err "could not read events.is_paused"
[ "$paused" = "true" ] || \
err "events contract is not paused; refusing to rely on a zero-event snapshot"
}
assert_events_unpaused() {
local events_id="$1"
local paused
paused="$(events_read "$events_id" is_paused)" || \
err "could not read events.is_paused"
[ "$paused" = "false" ] || \
err "events contract is still paused after unpause"
}
assert_profile_paused() {
local profile_id="$1"
local paused
paused="$(profile_read "$profile_id" is_paused)" || \
err "could not read profile.is_paused"
[ "$paused" = "true" ] || \
err "profile contract is not paused"
}
assert_profile_unpaused() {
local profile_id="$1"
local paused
paused="$(profile_read "$profile_id" is_paused)" || \
err "could not read profile.is_paused"
[ "$paused" = "false" ] || \
err "profile contract is still paused after unpause"
}
assert_no_pending_events_upgrade() {
local events_id="$1"
local pending
pending="$(events_read "$events_id" get_pending_upgrade)" || \
err "could not read pending events upgrade"
[ "$pending" = "null" ] || \
err "an events upgrade is already pending; inspect it with upgrade-status"
}
assert_pending_events_upgrade() {
local events_id="$1" expected_version="$2" expected_hash="$3"
local pending actual_version actual_hash
pending="$(events_read "$events_id" get_pending_upgrade)" || \
err "could not read pending events upgrade"
[ "$pending" != "null" ] || err "no events upgrade is pending"
actual_version="$(printf '%s' "$pending" | jq -er '.new_version')" || \
err "pending events upgrade did not contain new_version"
actual_hash="$(printf '%s' "$pending" | jq -er '.wasm_hash')" || \
err "pending events upgrade did not contain wasm_hash"
[ "$actual_version" = "$expected_version" ] || \
err "pending version mismatch: expected $expected_version, got $actual_version"
[ "$actual_hash" = "$expected_hash" ] || \
err "pending wasm mismatch: expected $expected_hash, got $actual_hash"
}
assert_no_pending_profile_upgrade() {
local profile_id="$1"
local pending
pending="$(profile_read "$profile_id" get_pending_upgrade)" || \
err "could not read pending profile upgrade"
[ "$pending" = "null" ] || \
err "a profile upgrade is already pending; inspect it with upgrade-status"
}
assert_pending_profile_upgrade() {
local profile_id="$1" expected_version="$2" expected_hash="$3"
local pending actual_version actual_hash
pending="$(profile_read "$profile_id" get_pending_upgrade)" || \
err "could not read pending profile upgrade"
[ "$pending" != "null" ] || err "no profile upgrade is pending"
actual_version="$(printf '%s' "$pending" | jq -er '.new_version')" || \
err "pending profile upgrade did not contain new_version"
actual_hash="$(printf '%s' "$pending" | jq -er '.wasm_hash')" || \
err "pending profile upgrade did not contain wasm_hash"
[ "$actual_version" = "$expected_version" ] || \
err "pending profile version mismatch: expected $expected_version, got $actual_version"
[ "$actual_hash" = "$expected_hash" ] || \
err "pending profile wasm mismatch: expected $expected_hash, got $actual_hash"
}
assert_pending_events_version() {
local events_id="$1" expected_version="$2"
local pending actual_version
pending="$(events_read "$events_id" get_pending_upgrade)" || \
err "could not read pending events upgrade"
[ "$pending" != "null" ] || err "no events upgrade is pending"
actual_version="$(printf '%s' "$pending" | jq -er '.new_version')" || \
err "pending events upgrade did not contain new_version"
[ "$actual_version" = "$expected_version" ] || \
err "pending events version mismatch: expected $expected_version, got $actual_version"
}
assert_profile_sdk27_staged_or_applied() {
local profile_id="$1"
local version pending
version="$(profile_read "$profile_id" version | read_json_string)" || \
err "could not read the current profile contract version"
pending="$(profile_read "$profile_id" get_pending_upgrade)" || \
err "could not read pending profile upgrade"
assert_profile_paused "$profile_id"
if [ "$version" = "1.1.0" ]; then
assert_pending_profile_upgrade \
"$profile_id" "$SDK27_PROFILE_VERSION" "$SDK27_PROFILE_WASM_HASH"
elif [ "$version" = "1.2.0" ]; then
[ "$pending" = "null" ] || \
err "profile is 1.2.0 but still has a pending upgrade"
assert_profile_sdk27_wasm_live "$profile_id"
else
err "profile must be staged at 1.1.0 or applied at 1.2.0; got $version"
fi
}
assert_profile_sdk27_applied_paused() {
local profile_id="$1"
assert_profile_version "$profile_id" "1.2.0"
assert_profile_sdk27_wasm_live "$profile_id"
assert_profile_paused "$profile_id"
assert_no_pending_profile_upgrade "$profile_id"
}
assert_profile_sdk27_migrated_paused() {
local profile_id="$1"
assert_profile_sdk27_applied_paused "$profile_id"
assert_profile_migrated_version "$profile_id" "1.2.0"
}
assert_profile_sdk27_ready() {
local profile_id="$1"
assert_profile_version "$profile_id" "1.2.0"
assert_profile_sdk27_wasm_live "$profile_id"
assert_profile_migrated_version "$profile_id" "1.2.0"
assert_no_pending_profile_upgrade "$profile_id"
assert_profile_unpaused "$profile_id"
}
assert_no_events_exist() {
local events_id="$1"
local base first_event_id output status
base="$(events_read "$events_id" id_base)" || \
err "could not read events.id_base"
[[ "$base" =~ ^[0-9]+$ ]] || \
err "events.id_base returned a non-numeric value: $base"
first_event_id=$((base + 1))
set +e
output="$(events_read "$events_id" get_event --event_id "$first_event_id" 2>&1)"
status=$?
set -e
if [ "$status" -eq 0 ]; then
err "event $first_event_id exists; abort the upgrade and implement a legacy-total migration"
fi
if [[ "$output" != *"Error(Contract, #30)"* ]]; then
err "could not prove event $first_event_id is absent; refusing to continue: $output"
fi
ok "Zero-event guard confirmed: $first_event_id returned EventNotFound."
}
is_zero_event_guarded_target() {
[ "$1" = "$SDK27_EVENTS_VERSION" ]
}
assert_migrated_version() {
local events_id="$1" expected="$2"
local migrated_version
migrated_version="$(events_read "$events_id" get_migrated_to_version | read_json_string)" || \
err "could not read migrated-to version"
[ "$migrated_version" = "$expected" ] || \
err "migration marker mismatch: expected $expected, got $migrated_version"
}
assert_profile_migrated_version() {
local profile_id="$1" expected="$2"
local migrated_version
migrated_version="$(profile_read "$profile_id" get_migrated_to_version | read_json_string)" || \
err "could not read profile migrated-to version"
[ "$migrated_version" = "$expected" ] || \
err "profile migration marker mismatch: expected $expected, got $migrated_version"
}
prepare_events_invoke() {
local events_id="$1" output_file="$2"
shift 2
local output_dir
output_dir="$(dirname "$output_file")"
[ -d "$output_dir" ] || err "XDR output directory does not exist: $output_dir"
assert_admin_source_matches "$events_id"
local tmp
tmp="$(mktemp)"
if ! stellar contract invoke \
--network "$NETWORK" \
--source-account "$ADMIN_SOURCE" \
--id "$events_id" \
--build-only \
-- "$@" \
| stellar tx simulate \
--network "$NETWORK" \
--source-account "$ADMIN_SOURCE" \
> "$tmp"; then
rm -f "$tmp"
err "could not build and simulate the multisig transaction"
fi
[ -s "$tmp" ] || {
rm -f "$tmp"
err "prepared transaction was empty"
}
mv "$tmp" "$output_file"
ok "Prepared simulated XDR: $output_file"
echo "Sign it sequentially with the required multi-sig quorum, then submit with:"
echo " stellar tx send \"<signed-xdr>\" --network $NETWORK"
}
prepare_profile_invoke() {
local profile_id="$1" output_file="$2"
shift 2
local output_dir
output_dir="$(dirname "$output_file")"
[ -d "$output_dir" ] || err "XDR output directory does not exist: $output_dir"
assert_profile_admin_source_matches "$profile_id"
local tmp
tmp="$(mktemp)"
if ! stellar contract invoke \
--network "$NETWORK" \
--source-account "$ADMIN_SOURCE" \
--id "$profile_id" \
--build-only \
-- "$@" \
| stellar tx simulate \
--network "$NETWORK" \
--source-account "$ADMIN_SOURCE" \
> "$tmp"; then
rm -f "$tmp"
err "could not build and simulate the profile multisig transaction"
fi
[ -s "$tmp" ] || {
rm -f "$tmp"
err "prepared profile transaction was empty"
}
mv "$tmp" "$output_file"
ok "Prepared simulated XDR: $output_file"
echo "Sign it sequentially with the required multi-sig quorum, then submit with:"
echo " stellar tx send \"<signed-xdr>\" --network $NETWORK"
}
append_upgrade_log() {
local action="$1" version="$2" wasm_hash="${3:-}"
local upgrades_log="$DEPLOYMENTS_DIR/mainnet-upgrades.jsonl"
jq -nc \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--arg action "$action" \
--arg version "$version" \
--arg wasm_hash "$wasm_hash" \
'{timestamp: $timestamp, action: $action, version: $version, wasm_hash: $wasm_hash}' \
>> "$upgrades_log"
}
cmd_build_release() {
info "Building contracts in release mode..."
stellar contract build --locked
ok "Build complete."
}
cmd_deploy_profile() {
require_env INITIAL_ADMIN_KEY
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/wasm32v1-none/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")")
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 the guarded upgrade flow in the mainnet runbook."
fi
cmd_build_release
local wasm="target/wasm32v1-none/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_upload_profile_wasm() {
local wasm="${1:-}"
[ -n "$wasm" ] || err "usage: upload-profile-wasm <path-to-new-wasm>"
[ -f "$wasm" ] || err "wasm file not found: $wasm"
require_env UPLOAD_SOURCE
require_env ADMIN_SOURCE
require_cli
confirm_mainnet
ensure_deployments_dir
local profile_id expected_hash uploaded_hash
profile_id="$(profile_contract_id)"
assert_profile_version "$profile_id" "1.1.0"
assert_profile_admin_source_matches "$profile_id"
expected_hash="$(hash_wasm "$wasm")"
assert_local_wasm_hash "profile SDK 27" "$wasm" "$SDK27_PROFILE_WASM_HASH"
uploaded_hash="$(stellar contract upload \
--source-account "$UPLOAD_SOURCE" \
--network "$NETWORK" \
--optimize=false \
--wasm "$wasm")"
[ "$uploaded_hash" = "$expected_hash" ] || \
err "uploaded profile wasm hash mismatch: expected $expected_hash, got $uploaded_hash"
append_upgrade_log "profile-uploaded" "" "$uploaded_hash"
ok "Uploaded exact profile WASM: $uploaded_hash"
}
cmd_prepare_pause_profile() {
local output_file="${1:-}"
[ -n "$output_file" ] || err "usage: prepare-pause-profile <xdr-output>"
require_env ADMIN_SOURCE
require_cli
local profile_id events_id
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
assert_events_version "$events_id" "1.1.0"
assert_events_paused "$events_id"
assert_no_events_exist "$events_id"
assert_no_pending_events_upgrade "$events_id"
assert_profile_version "$profile_id" "1.1.0"
assert_profile_unpaused "$profile_id"
assert_no_pending_profile_upgrade "$profile_id"
prepare_profile_invoke "$profile_id" "$output_file" pause
}
cmd_prepare_propose_upgrade_profile() {
local wasm="${1:-}" new_version="${2:-}" output_file="${3:-}"
[ -n "$wasm" ] || \
err "usage: prepare-propose-upgrade-profile <path-to-new-wasm> <new-version> <xdr-output>"
[ -n "$new_version" ] || \
err "usage: prepare-propose-upgrade-profile <path-to-new-wasm> <new-version> <xdr-output>"
[ -n "$output_file" ] || \
err "usage: prepare-propose-upgrade-profile <path-to-new-wasm> <new-version> <xdr-output>"
[ -f "$wasm" ] || err "wasm file not found: $wasm"
assert_version_argument "profile upgrade" "$new_version" "$SDK27_PROFILE_VERSION"
require_env ADMIN_SOURCE
require_cli
local profile_id events_id wasm_hash
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
wasm_hash="$(hash_wasm "$wasm")"
assert_sdk27_profile_artifact "$wasm" "$new_version"
assert_events_version "$events_id" "1.1.0"
assert_events_paused "$events_id"
assert_no_events_exist "$events_id"
assert_no_pending_events_upgrade "$events_id"
assert_no_pending_profile_upgrade "$profile_id"
assert_profile_paused "$profile_id"
if [ "$new_version" = "1.2.0" ]; then
assert_profile_version "$profile_id" "1.1.0"
fi
prepare_profile_invoke "$profile_id" "$output_file" propose_upgrade \
--new_wasm_hash "$wasm_hash" \
--new_version "$new_version"
echo "Expected profile version: $new_version"
echo "Expected profile WASM: $wasm_hash"
}
cmd_verify_proposed_upgrade_profile() {
local wasm="${1:-}" expected_version="${2:-}"
[ -n "$wasm" ] || \
err "usage: verify-proposed-upgrade-profile <path-to-new-wasm> <expected-version>"
[ -n "$expected_version" ] || \
err "usage: verify-proposed-upgrade-profile <path-to-new-wasm> <expected-version>"
[ -f "$wasm" ] || err "wasm file not found: $wasm"
assert_version_argument "profile upgrade" "$expected_version" "$SDK27_PROFILE_VERSION"
require_env ADMIN_SOURCE
require_cli
ensure_deployments_dir
local profile_id events_id expected_hash
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
expected_hash="$(hash_wasm "$wasm")"
assert_sdk27_profile_artifact "$wasm" "$expected_version"
assert_events_version "$events_id" "1.1.0"
assert_events_paused "$events_id"
assert_no_events_exist "$events_id"
assert_no_pending_events_upgrade "$events_id"
assert_pending_profile_upgrade "$profile_id" "$expected_version" "$expected_hash"
assert_profile_paused "$profile_id"
if [ "$expected_version" = "1.2.0" ]; then
assert_profile_version "$profile_id" "1.1.0"
fi
append_upgrade_log "profile-proposal-verified" "$expected_version" "$expected_hash"
ok "Queued profile upgrade matches the expected version and exact WASM."
}
cmd_prepare_apply_upgrade_profile() {
local wasm="${1:-}" expected_version="${2:-}" output_file="${3:-}"
[ -n "$wasm" ] || \
err "usage: prepare-apply-upgrade-profile <path-to-new-wasm> <expected-version> <xdr-output>"
[ -n "$expected_version" ] || \
err "usage: prepare-apply-upgrade-profile <path-to-new-wasm> <expected-version> <xdr-output>"
[ -n "$output_file" ] || \
err "usage: prepare-apply-upgrade-profile <path-to-new-wasm> <expected-version> <xdr-output>"
[ -f "$wasm" ] || err "wasm file not found: $wasm"
assert_version_argument "profile upgrade" "$expected_version" "$SDK27_PROFILE_VERSION"
require_env ADMIN_SOURCE
require_cli
local profile_id events_id expected_hash
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
expected_hash="$(hash_wasm "$wasm")"
assert_sdk27_profile_artifact "$wasm" "$expected_version"
assert_events_version "$events_id" "1.1.0"
assert_events_paused "$events_id"
assert_no_events_exist "$events_id"
assert_pending_events_upgrade \
"$events_id" "$SDK27_EVENTS_VERSION" "$SDK27_EVENTS_WASM_HASH"
assert_pending_profile_upgrade "$profile_id" "$expected_version" "$expected_hash"
assert_profile_paused "$profile_id"
if [ "$expected_version" = "1.2.0" ]; then
assert_profile_version "$profile_id" "1.1.0"
fi
prepare_profile_invoke "$profile_id" "$output_file" apply_upgrade
}
cmd_prepare_migrate_upgrade_profile() {
local expected_version="${1:-}" output_file="${2:-}"
[ -n "$expected_version" ] || \
err "usage: prepare-migrate-upgrade-profile <expected-version> <xdr-output>"
[ -n "$output_file" ] || \
err "usage: prepare-migrate-upgrade-profile <expected-version> <xdr-output>"
assert_version_argument "profile upgrade" "$expected_version" "$SDK27_PROFILE_VERSION"
require_env ADMIN_SOURCE
require_cli
local profile_id events_id migrated_version
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
assert_events_version "$events_id" "1.5.0"
assert_events_sdk27_wasm_live "$events_id"
assert_events_paused "$events_id"
assert_no_pending_events_upgrade "$events_id"
assert_profile_version "$profile_id" "$expected_version"
if [ "$expected_version" = "$SDK27_PROFILE_VERSION" ]; then
assert_profile_sdk27_wasm_live "$profile_id"
fi
assert_profile_paused "$profile_id"
assert_no_pending_profile_upgrade "$profile_id"
migrated_version="$(profile_read "$profile_id" get_migrated_to_version | jq -r '. // empty')" || \
err "could not read profile migrated-to version"
[ "$migrated_version" != "$expected_version" ] || \
err "profile migration marker is already $expected_version; do not replay migrate"
prepare_profile_invoke "$profile_id" "$output_file" migrate
}
cmd_prepare_cancel_upgrade_profile() {
local output_file="${1:-}"
[ -n "$output_file" ] || \
err "usage: prepare-cancel-upgrade-profile <xdr-output>"
require_env ADMIN_SOURCE
require_cli
local profile_id events_id pending_version
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
pending_version="$(profile_read "$profile_id" get_pending_upgrade | jq -r '.new_version // empty')" || \
err "could not read pending profile upgrade"
[ -n "$pending_version" ] || err "no profile upgrade is pending"
if [ "$pending_version" = "1.2.0" ]; then
assert_profile_version "$profile_id" "1.1.0"
assert_profile_paused "$profile_id"
assert_events_version "$events_id" "1.1.0"
assert_events_paused "$events_id"
assert_no_events_exist "$events_id"
fi
prepare_profile_invoke "$profile_id" "$output_file" cancel_pending_upgrade
echo "Cancelling queued profile version: $pending_version"
echo "This transaction does not unpause the profile contract."
}
cmd_prepare_unpause_profile() {
local expected_version="${1:-}" output_file="${2:-}"
[ -n "$expected_version" ] || \
err "usage: prepare-unpause-profile <expected-version> <xdr-output>"
[ -n "$output_file" ] || \
err "usage: prepare-unpause-profile <expected-version> <xdr-output>"
assert_unpause_version_argument "profile" "$expected_version" "$SDK27_PROFILE_VERSION"
require_env ADMIN_SOURCE
require_cli
local profile_id events_id
profile_id="$(profile_contract_id)"
events_id="$(events_contract_id)"
assert_upgrade_governance_stable "$profile_id" "$events_id"
assert_profile_version "$profile_id" "$expected_version"
assert_profile_paused "$profile_id"
assert_no_pending_profile_upgrade "$profile_id"
if [ "$expected_version" = "1.2.0" ]; then
assert_profile_sdk27_wasm_live "$profile_id"
assert_profile_migrated_version "$profile_id" "$expected_version"
assert_events_version "$events_id" "1.5.0"
assert_events_sdk27_wasm_live "$events_id"
assert_events_paused "$events_id"
assert_no_pending_events_upgrade "$events_id"
assert_migrated_version "$events_id" "1.5.0"
elif [ "$expected_version" = "1.1.0" ]; then
assert_events_version "$events_id" "1.1.0"
assert_events_paused "$events_id"
assert_no_pending_events_upgrade "$events_id"
assert_no_events_exist "$events_id"
fi
prepare_profile_invoke "$profile_id" "$output_file" unpause
}
cmd_verify_upgrade_profile() {
local wasm="${1:-}" expected_version="${2:-}"
[ -n "$wasm" ] || \
err "usage: verify-upgrade-profile <path-to-new-wasm> <expected-version>"
[ -n "$expected_version" ] || \
err "usage: verify-upgrade-profile <path-to-new-wasm> <expected-version>"
[ -f "$wasm" ] || err "wasm file not found: $wasm"
assert_version_argument "profile upgrade" "$expected_version" "$SDK27_PROFILE_VERSION"
require_env ADMIN_SOURCE
require_cli