-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdeploy.sh
More file actions
124 lines (104 loc) · 3.62 KB
/
deploy.sh
File metadata and controls
124 lines (104 loc) · 3.62 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
#!/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="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
}
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}"
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}"
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 ""
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 "🔍 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"