forked from tupui/soroban-versioning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
291 lines (245 loc) · 8.95 KB
/
Makefile
File metadata and controls
291 lines (245 loc) · 8.95 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
.PHONY: help install prepare rust-lint clean testnet_reset contract_build contract_test contract_deploy contract_help pre_push_hook
.DEFAULT_GOAL := help
SHELL:=/bin/bash
ifndef network
override network = testnet
endif
ifndef admin
override admin = mando-$(network)
endif
ifndef wasm
override wasm = target/wasm32v1-none/release/tansu.optimized.wasm
endif
override tansu_id = $(shell cat .stellar/tansu_id-$(network))
override domain_contract_id_mainnet = $(shell cat .stellar/soroban_domain_id-mainnet)
override domain_contract_id = $(shell cat .stellar/soroban_domain_id-$(network))
override domain_wasm_hash = $(shell stellar contract fetch --id $(domain_contract_id) --network $(network) | openssl sha256 | awk '{print $$2}')
override collateral_contract_id = $(shell stellar contract id asset --asset native --network $(network))
# Add help text after each target name starting with '\#\#'
help: ## show this help
@echo -e "Help for this makefile\n"
@echo "Possible commands are:"
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\(.*\):.*##\(.*\)/ \1: \2/'
install: ## install Rust and Soroban-CLI
# uv for the pre-push hook
curl -LsSf https://astral.sh/uv/install.sh | sh
# install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh && \
# install Soroban and config
rustup target add wasm32v1-none && \
cargo install --locked stellar-cli
prepare-network: ## Setup network
ifeq ($(network),testnet)
stellar network add testnet \
--rpc-url https://soroban-testnet.stellar.org:443 \
--network-passphrase "Test SDF Network ; September 2015"
else ifeq ($(network),mainnet)
stellar network add mainnet \
--rpc-url https://rpc.lightsail.network/ \
--network-passphrase "Public Global Stellar Network ; September 2015"
else
stellar network add testnet-local \
--rpc-url http://localhost:8000/soroban/rpc \
--network-passphrase "Standalone Network ; February 2017"
endif
prepare: prepare-network ## Setup network and generate addresses and add funds
stellar keys generate grogu-$(network) --network $(network) && \
stellar keys generate $(admin) --network $(network)
funds:
stellar keys fund grogu-$(network) --network $(network) && \
stellar keys fund $(admin) --network $(network)
rust-lint:
cargo clippy --all-targets --all-features -- -Dwarnings
cargo fmt -- --emit files
clean:
rm target/wasm32v1-none/release/*.wasm
rm target/wasm32v1-none/release/*.d
cargo clean
# --------- Events --------- #
events_test:
echo 0
# --------- Fullstack --------- #
local-stack: ## local stack
docker compose up
# --------- CONTRACT BUILD/TEST/DEPLOY --------- #
contract_build:
stellar contract build
@ls -l target/wasm32v1-none/release/*.wasm
contract_test:
cargo test
contract_build-release: contract_build
stellar contract optimize --wasm target/wasm32v1-none/release/tansu.wasm
@ls -l target/wasm32v1-none/release/*.wasm
# --contract-id $(tansu_id-$(network))
contract_bindings: contract_build-release ## Create bindings
stellar contract bindings typescript \
--network $(network) \
--wasm $(wasm) \
--output-dir dapp/packages/tansu \
--overwrite && \
cd dapp/packages/tansu && \
bun install --latest && \
bun run build && \
cd ../.. && \
bun format
contract_deploy: ## Deploy Soroban contract to testnet
stellar contract deploy \
--wasm $(wasm) \
--source-account $(admin) \
--network $(network) \
--salt $(shell printf tansu | openssl sha256 | cut -d " " -f2) \
--fee 200 \
-- \
--admin $(shell stellar keys address $(admin)) \
> .stellar/tansu_id-$(network) && \
cat .stellar/tansu_id-$(network)
contract_unpause: ## Unpause the contract
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
pause \
--admin $(shell stellar keys address $(admin)) \
--paused false
contract_propose_upgrade: contract_build-release ## After manually pulling the wasm from the pipeline, use it to propose to update the contract
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
propose_upgrade \
--admin $(shell stellar keys address $(admin)) \
--new_wasm_hash $(shell stellar contract upload --source-account $(admin) --network $(network) --wasm $(wasm))
contract_approve_upgrade: ## Approve the current upgrade proposal
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
approve_upgrade \
--admin $(shell stellar keys address $(admin))
contract_finalize_upgrade: ## Execute the approved upgrade proposal
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
finalize_upgrade \
--admin $(shell stellar keys address $(admin)) \
--accept true
contract_get_upgrade_proposal: ## Get the current upgrade proposal
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
get_upgrade_proposal
# --------- Soroban Domains --------- #
contract_domain_deploy:
stellar contract deploy \
--wasm contracts/domain_current.wasm \
--source-account $(admin) \
--network $(network) \
--salt $(shell printf soroban_domain | openssl sha256 | cut -d " " -f2) \
> .stellar/soroban_domain_id-$(network) && \
cat .stellar/soroban_domain_id-$(network)
contract_domain_init:
stellar contract invoke \
--source-account mando-testnet \
--network testnet \
--id $(shell cat .stellar/soroban_domain_id) \
-- \
init \
--adm $(shell stellar keys address $(admin)) \
--node_rate 100 \
--col_asset $(shell stellar contract id asset --asset native --network $(network)) \
--min_duration 31536000 \
--allowed_tlds '[{"bytes": "786c6d"}]'
contract_domain_fetch_latest: ## Fetch latest Domain wasm from mainnet and store as domain_<sha256>.wasm
@echo "Fetching domain contract $(domain_contract_id_mainnet) from mainnet..."
stellar contract fetch --id $(domain_contract_id_mainnet) --network mainnet > contracts/domain_latest.wasm
mv contracts/domain_latest.wasm contracts/domain_current.wasm; \
echo "Updated contracts/domain_current.wasm"
# --------- Setup --------- #
contract_set_domain_contract: ## Set the SorobanDomain contract address
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
set_domain_contract \
--admin $(shell stellar keys address $(admin)) \
--domain_contract '{"address":"$(domain_contract_id)","wasm_hash":"$(domain_wasm_hash)"}'
contract_set_collateral_contract: ## Set the SorobanDomain contract address
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
set_collateral_contract \
--admin $(shell stellar keys address $(admin)) \
--collateral_contract '{"address":"$(collateral_contract_id)","wasm_hash":null}'
# --------- Testnet --------- #
testnet_reset: ## Playbook for testnet reset
make funds && \
make contract_bindings && \
make contract_deploy && \
make contract_domain_deploy && \
make contract_domain_init && \
make contract_set_domain_contract && \
make contract_set_collateral_contract && \
make contract_unpause && \
make contract_register && \
make contract_commit
# --------- CONTRACT USAGE EXAMPLES --------- #
contract_help:
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
--help
contract_version:
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
version
# bafybeift4uou7f4qdrchrbwebxxvgf2ecmx56qqo6l2fyimmr4skb3iibi for salib
contract_register:
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
register \
--maintainer $(shell stellar keys address $(admin)) \
--name tansu \
--maintainers '["$(shell stellar keys address $(admin))", "$(shell stellar keys address grogu-$(network))"]' \
--url https://github.com/tupui/soroban-versioning \
--ipfs bafybeicnbbhyc4vhbuokk57lrmg4hkbvkmtcp6p3ubaptbus6kl2idthki
contract_commit:
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
commit \
--maintainer $(shell stellar keys address $(admin)) \
--project_key 37ae83c06fde1043724743335ac2f3919307892ee6307cce8c0c63eaa549e156 \
--hash bc4d84f2b00501ce6c176d797371f65799838720
contract_get_commit:
stellar contract invoke \
--source-account $(admin) \
--network $(network) \
--id $(tansu_id) \
-- \
get_commit \
--project_key 37ae83c06fde1043724743335ac2f3919307892ee6307cce8c0c63eaa549e156
# --------- Hook --------- #
pre_push_hook:
TANSU_CONTRACT_ID=$(tansu_id) \
TANSU_PROJECT_KEY=37ae83c06fde1043724743335ac2f3919307892ee6307cce8c0c63eaa549e156 \
uv run --with soroban pre-commit/soroban_versioning_pre_push.py