-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjustfile
More file actions
353 lines (286 loc) · 11 KB
/
justfile
File metadata and controls
353 lines (286 loc) · 11 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
# Subscriptions - Solana program build automation
# https://github.com/casey/just
# Use bash for all recipes
set shell := ["bash", "-uc"]
# Variables
program_dir := "program"
ts_client_dir := "clients/typescript"
webapp_dir := "webapp"
idl_file := "idl/subscriptions.json"
generated_paths := "idl clients/typescript/src/generated clients/rust/src/generated"
# List available recipes
default:
@just --list
# ============================================
# Setup and initialization
# ============================================
# Install dependencies and configure git hooks
setup: setup-hooks
#!/usr/bin/env bash
set -euo pipefail
commands=(pnpm cargo solana-keygen surfpool)
for cmd in "${commands[@]}"; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: $cmd is required but not installed"
exit 1
fi
done
pnpm install
echo "✓ Setup complete"
# Configure git hooks path
setup-hooks:
git config core.hooksPath .githooks
@echo "✓ Git hooks configured"
# Print program ID from keypair
program-id:
@sed -n 's/.*declare_id!("\([^"]*\)").*/\1/p' "{{program_dir}}/src/lib.rs"
# ============================================
# Build recipes
# ============================================
# Build everything (program + clients)
build: build-program build-client
# Compile Solana program to .so
build-program:
cd {{program_dir}} && cargo build-sbf
@echo "✓ Program built"
# Generate IDL from Rust source
generate-idl:
pnpm run generate-idl
@echo "✓ IDL generated"
# Generate TypeScript and Rust clients from IDL
generate-clients: generate-idl
pnpm run generate-clients
@echo "✓ Clients generated"
# Check that committed IDL and generated clients are current
check-generated: generate-clients
#!/usr/bin/env bash
set -euo pipefail
if ! git diff --quiet -- {{generated_paths}} || [[ -n "$(git ls-files --others --exclude-standard -- {{generated_paths}})" ]]; then
echo "Error: IDL or generated clients are out of date"
echo "Run: just generate-clients"
git status --short -- {{generated_paths}}
git diff -- {{generated_paths}}
exit 1
fi
echo "✓ IDL and generated clients are up-to-date"
# Backwards-compatible alias for the old recipe name
generate-client: generate-clients
@true
# Build TypeScript client
build-client: generate-clients
cd {{ts_client_dir}} && pnpm run build
@echo "✓ TypeScript client built"
# ============================================
# Test recipes
# ============================================
# Run all tests
test *args: unit-test (integration-test args) test-client
# Run Rust unit tests
unit-test:
cargo test -p subscriptions
# Backwards-compatible alias for the old recipe name
test-program: unit-test
@true
# Run Rust integration tests
integration-test *args: build-program
#!/usr/bin/env bash
set -euo pipefail
cargo test -p tests-subscriptions "$@"
# Run tests with compute unit benchmark report
test-and-benchmark: build-program
CU_REPORT=1 CU_REPORT_DATE=$(date +%Y-%m-%d) cargo test -p tests-subscriptions
# Run TypeScript client integration tests
test-client: build-program generate-clients ensure-surfpool
cd {{ts_client_dir}} && pnpm run test
# ============================================
# Validator management
# ============================================
# Start surfpool validator if not already running
ensure-surfpool:
#!/usr/bin/env bash
set -euo pipefail
if curl -sf -X POST http://localhost:8899 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}' &>/dev/null; then
echo "✓ Validator already running"
exit 0
fi
PROG_ID=$(sed -n 's/.*declare_id!("\([^"]*\)").*/\1/p' "{{program_dir}}/src/lib.rs")
if [[ -z "$PROG_ID" ]]; then
echo "Error: could not parse declare_id! from {{program_dir}}/src/lib.rs"
exit 1
fi
echo "Starting surfpool validator..."
mkdir -p .surfpool
nohup surfpool start --ci --no-tui --block-production-mode transaction \
--runbook surfnet-setup \
> /tmp/surfpool.log 2>&1 &
echo $! > .surfpool/pid.txt
for i in {1..30}; do
if curl -sf -X POST http://localhost:8899 \
-H "Content-Type: application/json" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getAccountInfo\",\"params\":[\"$PROG_ID\",{\"encoding\":\"base64\"}]}" \
| grep -q '"executable":true'; then
echo "✓ Program deployed successfully ($PROG_ID)"
exit 0
fi
echo "Waiting for program deployment... ($i/30)"
sleep 2
done
echo "Error: Program deployment failed"
echo "Surfpool logs:"
cat /tmp/surfpool.log
just kill-validator
exit 1
# Bootstrap localnet (validator + program + mock USDC) and write webapp/.env.local for pnpm dev (no api server)
dev-local: ensure-surfpool
#!/usr/bin/env bash
set -euo pipefail
pushd {{webapp_dir}}/scripts > /dev/null
pnpm install --silent
NETWORK=localnet RPC_URL=http://127.0.0.1:8899 pnpm run init
popd > /dev/null
PROG_ID=$(just program-id)
USDC_MINT=$(node -e "const c=JSON.parse(require('fs').readFileSync('{{webapp_dir}}/config.json'));process.stdout.write(c.networks.localnet.tokens.find(t=>t.symbol==='USDC').mint)")
{
echo "VITE_DEFAULT_CLUSTER=solana:localnet"
echo "VITE_LOCALNET_PROGRAM=$PROG_ID"
echo "VITE_LOCALNET_USDC_MINT=$USDC_MINT"
} > {{webapp_dir}}/.env.local
echo "✓ {{webapp_dir}}/.env.local written"
echo " VITE_LOCALNET_PROGRAM=$PROG_ID"
echo " VITE_LOCALNET_USDC_MINT=$USDC_MINT"
echo ""
echo "Next: pnpm --filter webapp dev"
# Stop all validators
kill-validator:
#!/usr/bin/env bash
set -euo pipefail
if [[ -f .surfpool/pid.txt ]]; then
pid=$(cat .surfpool/pid.txt)
kill -9 "$pid" 2>/dev/null || true
fi
killall -9 solana-test-validator 2>/dev/null || true
killall -9 surfpool 2>/dev/null || true
rm -f .surfpool/pid.txt 2>/dev/null || true
rm -rf .validator-ledger 2>/dev/null || true
echo "✓ All validators stopped"
# ============================================
# Webapp recipes
# ============================================
# Start webapp stack (builds client, starts API + Vite)
webapp-run:
./scripts/start-webapp.sh
webapp-test:
cd {{webapp_dir}} && pnpm run test
# Kill all webapp processes and remove all generated state
webapp-clean:
#!/usr/bin/env bash
set -euo pipefail
echo "Stopping webapp processes..."
pkill -f "surfpool" 2>/dev/null || true
pkill -f "solana-test-validator" 2>/dev/null || true
pkill -f "tsx.*server.ts" 2>/dev/null || true
pkill -f "vite" 2>/dev/null || true
echo "Removing generated state..."
rm -rf target/deploy/
rm -rf {{webapp_dir}}/{dist,node_modules,api/node_modules,scripts/node_modules}
rm -rf .validator-ledger .surfpool
rm -f /tmp/{surfpool,api,webapp,validator}.log
echo "Done"
# ============================================
# Clean recipes
# ============================================
# Clean everything: build artifacts, deps, validators, ledger
clean:
#!/usr/bin/env bash
set -euo pipefail
echo "Stopping services..."
pkill -f "solana-test-validator" 2>/dev/null || true
pkill -f "surfpool" 2>/dev/null || true
echo "Cleaning program build artifacts..."
cargo clean
echo "Cleaning client build artifacts..."
cd {{ts_client_dir}} && pnpm run clean || true
cd -
echo "Cleaning webapp..."
rm -rf {{webapp_dir}}/{node_modules,dist,api/node_modules,scripts/node_modules}
rm -rf .{validator-ledger,surfpool}
rm -f /tmp/{surfpool,api,webapp}.log
echo "✓ Clean complete"
# ============================================
# Format and lint recipes
# ============================================
# Check formatting without fixing
fmt-check:
@echo "Checking Rust formatting..."
@cargo fmt -p subscriptions -p tests-subscriptions --check
@echo "Checking TypeScript formatting..."
@pnpm run format:check
@echo "✓ Format check passed"
# Auto-format all code
fmt:
@echo "Formatting Rust..."
@cargo fmt -p subscriptions -p tests-subscriptions
@echo "Formatting TypeScript..."
@pnpm run format
@echo "✓ Code formatted"
# Lint with auto-fix
lint:
@echo "Linting Rust..."
@cargo clippy --workspace --exclude subscriptions-client --all-targets --no-deps --fix -- -D warnings
@echo "Linting TypeScript..."
@pnpm run lint:fix
@echo "✓ Code linted"
# Check linting without fixing
lint-check:
@echo "Checking Rust lint..."
@cargo clippy --workspace --exclude subscriptions-client --all-targets --no-deps -- -D warnings
@echo "Checking TypeScript lint..."
@pnpm run lint
@echo "✓ Lint check passed"
# Run all code quality checks
check: fmt-check lint-check
# ============================================
# IDL Deployment (uses Program Metadata Program)
# ============================================
[private]
check-program-metadata:
@command -v program-metadata >/dev/null 2>&1 || { echo "Error: program-metadata not installed. See https://github.com/solana-program/program-metadata"; exit 1; }
# Deploy IDL to devnet (requires PROGRAM_UPGRADE_AUTHORITY_KEYPAIR env var)
deploy-idl-devnet: check-program-metadata
#!/usr/bin/env bash
set -euo pipefail
KP="${PROGRAM_UPGRADE_AUTHORITY_KEYPAIR:?Set PROGRAM_UPGRADE_AUTHORITY_KEYPAIR (e.g. via doppler run -- just deploy-idl-devnet)}"
PROG_ID=$(sed -n 's/.*declare_id!("\([^"]*\)").*/\1/p' "{{program_dir}}/src/lib.rs")
program-metadata write idl "$PROG_ID" {{idl_file}} \
--keypair "$KP" \
--rpc https://api.devnet.solana.com
# Deploy IDL to mainnet (requires PROGRAM_UPGRADE_AUTHORITY_KEYPAIR env var)
deploy-idl-mainnet: check-program-metadata
#!/usr/bin/env bash
set -euo pipefail
KP="${PROGRAM_UPGRADE_AUTHORITY_KEYPAIR:?Set PROGRAM_UPGRADE_AUTHORITY_KEYPAIR (e.g. via doppler run -- just deploy-idl-mainnet)}"
PROG_ID=$(sed -n 's/.*declare_id!("\([^"]*\)").*/\1/p' "{{program_dir}}/src/lib.rs")
program-metadata write idl "$PROG_ID" {{idl_file}} \
--keypair "$KP" \
--rpc https://api.mainnet-beta.solana.com
# ============================================
# Build Verification (uses solana-verify CLI)
# ============================================
[private]
check-solana-verify:
@command -v solana-verify >/dev/null 2>&1 || { echo "Error: solana-verify not installed. Run: cargo install solana-verify"; exit 1; }
# Verify mainnet deployment against repo (remote build via OtterSec).
# Note: Remote verification (--remote) only works on mainnet.
verify-mainnet: check-solana-verify
#!/usr/bin/env bash
set -euo pipefail
PROG_ID=$(sed -n 's/.*declare_id!("\([^"]*\)").*/\1/p' "{{program_dir}}/src/lib.rs")
solana-verify verify-from-repo \
https://github.com/solana-program/subscriptions \
--program-id "$PROG_ID" \
--library-name subscriptions \
--mount-path program \
--remote \
-um