forked from SO4-Markets/contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.mk
More file actions
104 lines (95 loc) · 4.31 KB
/
Copy pathupgrade.mk
File metadata and controls
104 lines (95 loc) · 4.31 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
# Upgrade workflows.
#
# Contract upgrades require the deployed contract to expose:
# pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>)
# where the function authenticates the stored admin and calls:
# env.deployer().update_current_contract_wasm(new_wasm_hash)
# Contracts that are intentionally immutable and must never be upgraded.
# make upgrade will print "skipped (immutable)" for each of these.
IMMUTABLE_CONTRACTS := market_token
UPGRADE_CONTRACTS ?= \
role_store \
data_store \
oracle \
market_factory \
deposit_vault \
deposit_handler \
withdrawal_vault \
withdrawal_handler \
order_vault \
order_handler \
liquidation_handler \
adl_handler \
fee_handler \
referral_storage \
reader \
exchange_router
DRY_RUN ?= 0
.PHONY: upload upgrade upgrade-contract upgrade-all upgrade-with-hash
upload: preflight build
@test -n "$(CONTRACT)" || { printf '%s\n' 'Usage: make upload CONTRACT=deposit_handler'; exit 1; }
@test -f "$(WASM_DIR)/$(CONTRACT).wasm" || { printf 'Missing wasm: %s/%s.wasm\n' "$(WASM_DIR)" "$(CONTRACT)"; exit 1; }
stellar contract upload \
--wasm "$(WASM_DIR)/$(CONTRACT).wasm" \
--source "$(SOURCE)" \
--network "$(NETWORK)"
upgrade: upgrade-contract
upgrade-contract: preflight build
@test -n "$(CONTRACT)" || { printf '%s\n' 'Usage: make upgrade-contract CONTRACT=deposit_handler'; exit 1; }
@for imm in $(IMMUTABLE_CONTRACTS); do \
if [ "$$imm" = "$(CONTRACT)" ]; then \
printf 'skipped (immutable) %s\n' "$(CONTRACT)"; exit 0; \
fi; \
done
@test -f "$(DEPLOY_ENV)" || { printf 'Missing %s. Run make deploy-all first or pass CONTRACT_ID=...\n' "$(DEPLOY_ENV)"; exit 1; }
source "$(DEPLOY_ENV)"
contract_key="$$(printf '%s' "$(CONTRACT)" | tr '[:lower:]-' '[:upper:]_')"
contract_id="$${CONTRACT_ID:-$${!contract_key:-}}"
test -n "$$contract_id" || { printf 'failed %s (no address in %s)\n' "$(CONTRACT)" "$(DEPLOY_ENV)"; exit 1; }
if [ "$(DRY_RUN)" = "1" ]; then \
printf 'dry-run %s would upgrade at %s\n' "$(CONTRACT)" "$$contract_id"; \
else \
wasm_hash="$$(stellar contract upload --wasm "$(WASM_DIR)/$(CONTRACT).wasm" --source "$(SOURCE)" --network "$(NETWORK)")" && \
printf 'uploaded %s -> %s\n' "$(CONTRACT)" "$$wasm_hash" && \
stellar contract invoke \
--id "$$contract_id" \
--source "$(SOURCE)" \
--network "$(NETWORK)" \
-- upgrade --new_wasm_hash "$$wasm_hash" && \
printf 'upgraded %s at %s\n' "$(CONTRACT)" "$$contract_id" || \
printf 'failed %s at %s\n' "$(CONTRACT)" "$$contract_id"; \
fi
upgrade-all: preflight build
@test -f "$(DEPLOY_ENV)" || { printf 'Missing %s. Run deploy-all first.\n' "$(DEPLOY_ENV)"; exit 1; }
@if [ "$(DRY_RUN)" = "1" ]; then printf 'DRY RUN — no transactions will be submitted\n'; fi
source "$(DEPLOY_ENV)"
for contract in $(UPGRADE_CONTRACTS) $(IMMUTABLE_CONTRACTS); do \
is_immutable=0; \
for imm in $(IMMUTABLE_CONTRACTS); do [ "$$imm" = "$$contract" ] && is_immutable=1; done; \
if [ "$$is_immutable" = "1" ]; then \
printf 'skipped (immutable) %s\n' "$$contract"; continue; \
fi; \
contract_key="$$(printf '%s' "$$contract" | tr '[:lower:]-' '[:upper:]_')"; \
contract_id="$${!contract_key:-}"; \
if [ -z "$$contract_id" ]; then \
printf 'failed %s (no address in $(DEPLOY_ENV))\n' "$$contract"; continue; \
fi; \
if [ "$(DRY_RUN)" = "1" ]; then \
printf 'dry-run %s would upgrade at %s\n' "$$contract" "$$contract_id"; continue; \
fi; \
wasm_hash="$$(stellar contract upload --wasm "$(WASM_DIR)/$$contract.wasm" --source "$(SOURCE)" --network "$(NETWORK)" 2>&1)" && \
stellar contract invoke \
--id "$$contract_id" --source "$(SOURCE)" --network "$(NETWORK)" \
-- upgrade --new_wasm_hash "$$wasm_hash" \
&& printf 'upgraded %s at %s\n' "$$contract" "$$contract_id" \
|| printf 'failed %s at %s\n' "$$contract" "$$contract_id"; \
done
printf 'Done — %s\n' "$(NETWORK)"
upgrade-with-hash: preflight
@test -n "$(CONTRACT_ID)" || { printf '%s\n' 'Usage: make upgrade-with-hash CONTRACT_ID=C... WASM_HASH=...'; exit 1; }
@test -n "$(WASM_HASH)" || { printf '%s\n' 'Usage: make upgrade-with-hash CONTRACT_ID=C... WASM_HASH=...'; exit 1; }
stellar contract invoke \
--id "$(CONTRACT_ID)" \
--source "$(SOURCE)" \
--network "$(NETWORK)" \
-- upgrade --new_wasm_hash "$(WASM_HASH)"