File size: 4,668 Bytes
37d1c5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Devnet Deployment Guide

This guide covers deploying all components to Solana devnet for testing.

## Prerequisites

- Solana CLI installed and configured for devnet
- PostgreSQL database running
- Redis server running
- Python 3.9+
- Rust and Cargo (for Solana program)
- CMake (for C++ workers)

## 1. Catacomb Underwriter Service (133x Scaling)

**Location:** `catacomb-underwriter-service/`

**Steps:**
```bash
cd catacomb-underwriter-service

# Create .env from example
cp .env.example .env

# Edit .env with your devnet credentials:
# - DATABASE_URL (PostgreSQL)
# - REDIS_URL (Redis)
# - STRIPE_SECRET_KEY (test mode: sk_test_*)
# - STRIPE_PUBLISHABLE_KEY (test mode: pk_test_*)
# - SECRET_KEY

# Install dependencies
pip install -r requirements.txt

# Initialize database
python -c "from database import get_database_manager; db = get_database_manager(); db.initialize_schema()"

# Start service
python underwriter_app.py
```

**Devnet Configuration:**
- Solana RPC: `https://api.devnet.solana.com`
- Stripe: Test mode keys
- Port: 5002

**Test Endpoints:**
- `GET http://localhost:5002/api/scaling/health`
- `GET http://localhost:5002/api/scaling/metrics`
- `GET http://localhost:5002/api/loadbalancer/metrics`

## 2. C++ Gate.io WebSocket Workers

**Location:** `cpp-trading-trainer/`

**Steps:**
```bash
cd cpp-trading-trainer

# Build workers
mkdir -p build
cd build
cmake ..
make gateio_worker_manager
cd ..

# Start aggregation server (port 5003)
python aggregation_server.py &

# Start workers
./build/gateio_worker_manager "BTC_USDT,ETH_USDT,SOL_USDT" "1m"
```

**Test Endpoints:**
- `GET http://localhost:5003/api/status`
- `GET http://localhost:5003/api/symbols`
- `GET http://localhost:5003/api/candles/BTC_USDT?limit=10`
- `GET http://localhost:5003/api/stream` (SSE)

## 3. ShadowPool Solana Program

**Location:** `shadowpool/`

**Steps:**
```bash
cd shadowpool

# Configure Solana CLI for devnet
solana config set --url https://api.devnet.solana.com

# Airdrop devnet SOL
solana airdrop 2

# Build program
cargo build-bpf

# Deploy program
solana program deploy target/deploy/shadowpool.so

# Save the program ID for client configuration
```

**Program Features:**
- Pool-native token (Token ≡ Pool Share)
- Lambda-stabilized shadow liquidity
- Anti-fake rules (ambiguity, distortion limits)
- Shadow rebase mechanism

**Program Fields:**
- `shadow_root: [u8; 32]` - Merkle root of shadow projection
- `projection_hash: [u8; 32]` - Hash of projection
- `shadow_liquidity_bps: u16` - Liquidity score in basis points
- `ambiguity_bps: u16` - Ambiguity penalty
- `distortion_bps: u16` - Distortion penalty
- `shadow_index_q64: u128` - Shadow index (Q64 fixed-point)
- `lambda_coefficient: u64` - Lambda coefficient

## 4. Proof-of-Shadow-Liquidity Components

**Components to Deploy:**
- LiquidDB (off-chain manifold storage)
- IPFS (for Merkle tree storage)
- Manifold projection service
- Shadow rebase instruction handlers

**Steps:**
```bash
# Deploy LiquidDB (PostgreSQL)
createdb liquiddb_devnet
psql liquiddb_devnet < schema.sql

# Start IPFS daemon
ipfs daemon

# Configure manifold projection service
# (implementation depends on your embedding model)
```

## Environment Variables Summary

**Catacomb Underwriter (.env):**
```
SOLANA_RPC_URL=https://api.devnet.solana.com
STRIPE_SECRET_KEY=sk_test_*
STRIPE_PUBLISHABLE_KEY=pk_test_*
DATABASE_URL=postgresql://user:pass@localhost:5432/catacomb_devnet
REDIS_URL=redis://localhost:6379/0
REDIS_HOSTS=localhost
REDIS_MAX_CONNECTIONS=500
NUM_WORKERS=133
ENABLE_AUTO_SCALING=true
```

**ShadowPool (Solana):**
- Network: Devnet
- Program ID: (after deployment)
- Authority: Your devnet keypair

## Testing

**Test Underwriter Service:**
```bash
curl http://localhost:5002/api/scaling/health
curl http://localhost:5002/api/scaling/metrics
```

**Test Gate.io Workers:**
```bash
curl http://localhost:5003/api/status
curl http://localhost:5003/api/symbols
```

**Test ShadowPool:**
```bash
solana program show <PROGRAM_ID>
solana logs <PROGRAM_ID>
```

## Troubleshooting

**Cargo lock file version error:**
```bash
rm Cargo.lock
cargo update
cargo build-bpf
```

**Redis not running:**
```bash
redis-server
```

**PostgreSQL not running:**
```bash
# macOS
brew services start postgresql

# Linux
sudo systemctl start postgresql
```

**Solana airdrop failed:**
```bash
# Request more SOL
solana airdrop 2
```

## Next Steps After Devnet Testing

1. Verify all components work together
2. Test shadow rebase mechanism
3. Test lambda coefficient calculations
4. Test anti-fake rules
5. Test 133x scaling under load
6. Document any issues
7. Prepare for mainnet deployment with real credentials