Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
174 lines (150 loc) · 5.38 KB
/
Copy pathdeploy.sh
File metadata and controls
174 lines (150 loc) · 5.38 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
#!/bin/bash
set -e
echo "🚀 EsuStellar Contract Deployment"
echo "=================================="
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
NETWORK="${NETWORK:-testnet}"
ROOT_DIR="$(pwd)"
REGISTRY_DIR="contracts/registry"
SAVINGS_DIR="contracts/savings"
REGISTRY_WASM="$ROOT_DIR/target/wasm32v1-none/release/group_registry.wasm"
SAVINGS_WASM="$ROOT_DIR/target/wasm32v1-none/release/esustellar_savings.wasm"
ENV_FILE="$ROOT_DIR/apps/web/.env.local"
# Check CLI
command -v stellar >/dev/null 2>&1 || {
echo "❌ Stellar CLI not found"
exit 1
}
# Safety: confirm non-testnet deploys
if [ "$NETWORK" != "testnet" ]; then
echo -e "${YELLOW}⚠️ Deploying to ${NETWORK} — this is NOT testnet.${NC}"
read -rp "Type the network name to confirm: " confirm
if [ "$confirm" != "$NETWORK" ]; then
echo "Aborted."
exit 1
fi
fi
echo ""
echo -e "${YELLOW}📝 Step 1: Building contracts...${NC}"
# Build registry contract
echo "Building registry contract..."
cd "$REGISTRY_DIR"
stellar contract build
cd "$ROOT_DIR"
echo -e "${GREEN}✅ Registry contract built${NC}"
# Build savings contract
echo "Building savings contract..."
cd "$SAVINGS_DIR"
stellar contract build
cd "$ROOT_DIR"
echo -e "${GREEN}✅ Savings contract built${NC}"
echo ""
echo -e "${YELLOW}📝 Step 2: Preparing deployer identity...${NC}"
if ! stellar keys ls | awk '{print $1}' | grep -xq deployer; then
stellar keys generate deployer --network "$NETWORK"
fi
if [ "$NETWORK" = "testnet" ]; then
echo "Funding deployer account (if needed)..."
stellar keys fund deployer --network "$NETWORK" || true
fi
echo ""
echo -e "${YELLOW}📝 Step 3: Deploying Registry Contract...${NC}"
REGISTRY_CONTRACT_ID=$(stellar contract deploy \
--wasm "$REGISTRY_WASM" \
--source-account deployer \
--network "$NETWORK")
echo -e "${GREEN}✅ Registry deployment successful${NC}"
echo -e "Registry Contract ID: ${BLUE}${REGISTRY_CONTRACT_ID}${NC}"
# Verify registry contract is live
echo -e "${YELLOW}🔍 Verifying registry contract is responding...${NC}"
stellar contract invoke \
--id "$REGISTRY_CONTRACT_ID" \
--source-account deployer \
--network "$NETWORK" \
-- get_group_count > /dev/null 2>&1 || {
echo -e "❌ Registry contract verification failed"
exit 1
}
echo -e "${GREEN}✅ Registry contract verified${NC}"
echo ""
echo -e "${YELLOW}📝 Step 4: Deploying Savings Contract...${NC}"
SAVINGS_CONTRACT_ID=$(stellar contract deploy \
--wasm "$SAVINGS_WASM" \
--source-account deployer \
--network "$NETWORK")
echo -e "${GREEN}✅ Savings deployment successful${NC}"
echo -e "Savings Contract ID: ${BLUE}${SAVINGS_CONTRACT_ID}${NC}"
# Verify savings contract is live
echo -e "${YELLOW}🔍 Verifying savings contract is responding...${NC}"
stellar contract invoke \
--id "$SAVINGS_CONTRACT_ID" \
--source-account deployer \
--network "$NETWORK" \
-- get_all_groups > /dev/null 2>&1 || {
echo -e "❌ Savings contract verification failed"
exit 1
}
echo -e "${GREEN}✅ Savings contract verified${NC}"
echo ""
echo -e "${YELLOW}💾 Updating frontend env...${NC}"
mkdir -p "$(dirname "$ENV_FILE")"
# Create or update .env.local file
{
# Preserve existing env vars that aren't contract IDs
if [ -f "$ENV_FILE" ]; then
grep -v '^NEXT_PUBLIC_REGISTRY_CONTRACT_ID=' "$ENV_FILE" 2>/dev/null | \
grep -v '^NEXT_PUBLIC_SAVINGS_CONTRACT_ID=' | \
grep -v '^NEXT_PUBLIC_CONTRACT_ID=' || true
fi
# Add contract IDs with NEXT_PUBLIC_ prefix
echo "NEXT_PUBLIC_REGISTRY_CONTRACT_ID=$REGISTRY_CONTRACT_ID"
echo "NEXT_PUBLIC_SAVINGS_CONTRACT_ID=$SAVINGS_CONTRACT_ID"
# Legacy support - keep CONTRACT_ID pointing to savings
echo "NEXT_PUBLIC_CONTRACT_ID=$SAVINGS_CONTRACT_ID"
} > "$ENV_FILE.tmp"
mv "$ENV_FILE.tmp" "$ENV_FILE"
echo -e "${GREEN}✅ Updated $ENV_FILE${NC}"
# Create deployment info file
cat > deployment-info.json <<EOF
{
"registry_contract_id": "$REGISTRY_CONTRACT_ID",
"savings_contract_id": "$SAVINGS_CONTRACT_ID",
"network": "$NETWORK",
"deployed_at": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"deployer": "deployer"
}
EOF
echo ""
if [ "${SKIP_SMOKE_TEST:-false}" != "true" ]; then
echo -e "${YELLOW}📝 Step 5: Running post-deploy smoke tests...${NC}"
if [ -f "$ROOT_DIR/scripts/post-deploy-smoke-test.sh" ]; then
bash "$ROOT_DIR/scripts/post-deploy-smoke-test.sh" \
--registry "$REGISTRY_CONTRACT_ID" \
--savings "$SAVINGS_CONTRACT_ID" \
--network "$NETWORK" || echo -e "${YELLOW}⚠️ Smoke tests finished with warnings or errors.${NC}"
fi
fi
echo ""
echo -e "${GREEN}🎉 Deployment complete!${NC}"
echo ""
echo "📋 Contract IDs:"
echo -e " Registry: ${BLUE}${REGISTRY_CONTRACT_ID}${NC}"
echo -e " Savings: ${BLUE}${SAVINGS_CONTRACT_ID}${NC}"
echo ""
echo "🔗 Linking contracts on-chain..."
echo " NOTE: Cross-contract linking requires implementing register_group/add_member"
echo " calls in the savings contract (see issue #65). Until then, the registry"
echo " must be updated manually or via off-chain client."
echo ""
echo "🔍 Explorers:"
echo " Registry: https://stellar.expert/explorer/$NETWORK/contract/$REGISTRY_CONTRACT_ID"
echo " Savings: https://stellar.expert/explorer/$NETWORK/contract/$SAVINGS_CONTRACT_ID"
echo ""
echo "💡 Next Steps:"
echo " 1. When creating savings groups, register them in the registry"
echo " 2. When users join groups, update registry membership"
echo " 3. Use registry for group discovery in the frontend"