forked from SO4-Markets/contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_frontend_config.sh
More file actions
executable file
·148 lines (128 loc) · 4.79 KB
/
Copy pathexport_frontend_config.sh
File metadata and controls
executable file
·148 lines (128 loc) · 4.79 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
#!/usr/bin/env bash
# scripts/export_frontend_config.sh — Generate a frontend-consumable config file
# from deployed contract IDs.
#
# Reads .deployed/<NETWORK>.env and .deployed/tokens-<NETWORK>.env and writes:
# .deployed/frontend-<NETWORK>.env (KEY=VALUE shell format for CI/env)
# .deployed/frontend-<NETWORK>.ts (typed TypeScript constants for direct import)
#
# Usage:
# bash scripts/export_frontend_config.sh [NETWORK]
#
# NETWORK : testnet (default) | local
set -euo pipefail
NETWORK="${1:-testnet}"
DEPLOYED_DIR=".deployed"
DEPLOYED_ENV="$DEPLOYED_DIR/$NETWORK.env"
TOKEN_ENV="$DEPLOYED_DIR/tokens-$NETWORK.env"
FRONTEND_ENV="$DEPLOYED_DIR/frontend-$NETWORK.env"
FRONTEND_TS="$DEPLOYED_DIR/frontend-$NETWORK.ts"
RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; NC='\033[0m'
die() { echo -e "${RED}✖ $*${NC}" >&2; exit 1; }
[[ -f "$DEPLOYED_ENV" ]] || die "Missing $DEPLOYED_ENV. Run 'make deploy-all NETWORK=$NETWORK' first."
# Load deployed contracts
source "$DEPLOYED_ENV"
[[ -f "$TOKEN_ENV" ]] && source "$TOKEN_ENV"
# Helpers — default to empty string so we can report missing fields
_v() { echo "${!1:-}"; }
# ── Shell env file ─────────────────────────────────────────────────────────────
cat > "$FRONTEND_ENV" <<EOF
# SO4.market frontend env — $NETWORK
# Generated by scripts/export_frontend_config.sh — do not edit manually.
# Re-run after each bootstrap to pick up new market token IDs.
#
# Protocol contracts
ROLE_STORE=$(_v ROLE_STORE)
DATA_STORE=$(_v DATA_STORE)
ORACLE=$(_v ORACLE)
MARKET_FACTORY=$(_v MARKET_FACTORY)
DEPOSIT_HANDLER=$(_v DEPOSIT_HANDLER)
WITHDRAWAL_HANDLER=$(_v WITHDRAWAL_HANDLER)
ORDER_HANDLER=$(_v ORDER_HANDLER)
EXCHANGE_ROUTER=$(_v EXCHANGE_ROUTER)
READER=$(_v READER)
# Test tokens
TOKEN_TUSDC=$(_v TUSDC)
TOKEN_TWBTC=$(_v TWBTC)
TOKEN_TETH=$(_v TETH)
TOKEN_TXLM=$(_v TXLM)
FAUCET=$(_v FAUCET)
# Market tokens (LP tokens) — set after bootstrap
# Each market token is the unique identifier for an LP pool.
MARKET_TOKEN_TWBTC_TUSDC=$(_v MARKET_TOKEN_TWBTC_TUSDC)
MARKET_TOKEN_TETH_TUSDC=$(_v MARKET_TOKEN_TETH_TUSDC)
MARKET_TOKEN_TXLM_TUSDC=$(_v MARKET_TOKEN_TXLM_TUSDC)
EOF
echo -e "${GREEN}✔${NC} Written $FRONTEND_ENV"
# ── TypeScript constants file ─────────────────────────────────────────────────
TUSDC=$(_v TUSDC)
TWBTC=$(_v TWBTC)
TETH=$(_v TETH)
TXLM=$(_v TXLM)
FAUCET_ID=$(_v FAUCET)
MT_TWBTC_TUSDC=$(_v MARKET_TOKEN_TWBTC_TUSDC)
MT_TETH_TUSDC=$(_v MARKET_TOKEN_TETH_TUSDC)
MT_TXLM_TUSDC=$(_v MARKET_TOKEN_TXLM_TUSDC)
cat > "$FRONTEND_TS" <<EOF
// SO4.market contract addresses — $NETWORK
// Generated by scripts/export_frontend_config.sh — do not edit manually.
// Re-run after each bootstrap to pick up new market token IDs.
export const NETWORK = "$NETWORK" as const;
export const TESTNET_CONFIG = {
rpcUrl: "https://soroban-testnet.stellar.org",
networkPassphrase: "Test SDF Network ; September 2015",
} as const;
// Core protocol contracts
export const PROTOCOL = {
roleStore: "$(_v ROLE_STORE)",
dataStore: "$(_v DATA_STORE)",
oracle: "$(_v ORACLE)",
marketFactory: "$(_v MARKET_FACTORY)",
depositHandler: "$(_v DEPOSIT_HANDLER)",
withdrawalHandler:"$(_v WITHDRAWAL_HANDLER)",
orderHandler: "$(_v ORDER_HANDLER)",
exchangeRouter: "$(_v EXCHANGE_ROUTER)",
reader: "$(_v READER)",
} as const;
// Test tokens (faucet-mintable, testnet only)
export const TOKENS = {
TUSDC: "$TUSDC",
TWBTC: "$TWBTC",
TETH: "$TETH",
TXLM: "$TXLM",
faucet:"$FAUCET_ID",
} as const;
// Market pools: key = display label, value = on-chain addresses
// marketToken is the LP token contract and the unique market identifier.
// Always use these addresses when calling protocol contracts — never symbolic strings.
export const MARKETS = {
"TWBTC/TUSDC": {
marketToken: "$MT_TWBTC_TUSDC",
indexToken: "$TWBTC",
longToken: "$TWBTC",
shortToken: "$TUSDC",
},
"TETH/TUSDC": {
marketToken: "$MT_TETH_TUSDC",
indexToken: "$TETH",
longToken: "$TETH",
shortToken: "$TUSDC",
},
"TXLM/TUSDC": {
marketToken: "$MT_TXLM_TUSDC",
indexToken: "$TXLM",
longToken: "$TXLM",
shortToken: "$TUSDC",
},
} as const;
export type MarketLabel = keyof typeof MARKETS;
export type MarketConfig = (typeof MARKETS)[MarketLabel];
EOF
echo -e "${GREEN}✔${NC} Written $FRONTEND_TS"
echo
echo -e "${CYAN}Frontend config exported for $NETWORK.${NC}"
echo " Shell env : $FRONTEND_ENV"
echo " TypeScript: $FRONTEND_TS"
echo
echo "In the frontend repo, import from the TS file:"
echo " import { MARKETS, TOKENS, PROTOCOL } from '../../contracts/$FRONTEND_TS'"