razvan commited on
Commit
58cb4a0
·
verified ·
1 Parent(s): d589324

Upload REAL_VS_SIMULATED.md

Browse files
Files changed (1) hide show
  1. REAL_VS_SIMULATED.md +292 -0
REAL_VS_SIMULATED.md ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Real vs Simulated Integration Status
2
+
3
+ This document tracks which BuilderBrain components are **real APIs** vs **simulated stubs**.
4
+
5
+ ## Quick Reference
6
+
7
+ | Component | Status | What Works Now | What Needs Credentials |
8
+ |-----------|--------|---------------|----------------------|
9
+ | **Quant Engine (Kelly)** | ✅ REAL | Full `cvxpy` optimization with real math | None |
10
+ | **Correlation Matrix** | ✅ REAL | Block-diagonal structure with real estimates | None |
11
+ | **Reasoning Agent** | ✅ REAL | Structured trace generation with SHA256 hashing | None |
12
+ | **Polymarket Market Data** | ✅ REAL | Live Gamma API calls (`gamma-api.polymarket.com`) | None (public API) |
13
+ | **Polymarket Orderbook** | ✅ REAL | Live CLOB API calls (`clob.polymarket.com`) | None (public API) |
14
+ | **Builder Code Routing** | ⚠️ SIMULATED | Field structure correct; needs `POLY_BUILDER_CODE` + live CLOB key | `POLY_API_KEY`, `POLY_PRIVATE_KEY`, registered builder code |
15
+ | **Circle Gateway** | ⚠️ SIMULATED | Real HTTP client skeleton; needs `CIRCLE_API_KEY` + burn intent encoding | `CIRCLE_API_KEY`, depositor address, domain info |
16
+ | **Arc Nanopayments** | ⚠️ SIMULATED | App-level ledger; real settlement requires x402 + EIP-3009 + Gateway | Buyer signatures, seller DB, Gateway batch settlement |
17
+ | **USYC Yield** | ⚠️ SIMULATED | Balance tracking; real rotation needs Teller contract calls | Web3 provider, Teller contract ABI, wallet |
18
+ | **Paymaster** | ⚠️ SIMULATED | Log-only; real needs ERC-4337 UserOp + bundler RPC | Pimlico bundler, EntryPoint address, paymaster contract |
19
+ | **Wallets** | ⚠️ SIMULATED | Config only; real needs Circle Wallets API or self-custody | `CIRCLE_WALLET_API_KEY`, `CIRCLE_WALLET_SET_ID` |
20
+
21
+ ---
22
+
23
+ ## Detailed Breakdown
24
+
25
+ ### ✅ Quant Engine — FULLY REAL
26
+
27
+ ```python
28
+ from builderbrain import KellyEngine, CorrelationMatrix
29
+
30
+ engine = KellyEngine(bankroll_usd=10000)
31
+ positions = engine.size_positions(edges)
32
+ # Uses cvxpy + ECOS solver — real convex optimization
33
+ ```
34
+
35
+ **No credentials needed.** The Kelly criterion implementation uses `cvxpy` for convex quadratic programming. This is production-grade numerical optimization.
36
+
37
+ **References:** Tepelyan (Bloomberg, 2026) — we implement a QP approximation to his Laplace quadrature method.
38
+
39
+ ---
40
+
41
+ ### ✅ Reasoning Agent — FULLY REAL
42
+
43
+ ```python
44
+ from builderbrain import ReasoningAgent
45
+
46
+ agent = ReasoningAgent()
47
+ trace = agent.reason_about_market(...)
48
+ # Generates structured traces with SHA256 hashing
49
+ ```
50
+
51
+ **No credentials needed.** The reasoning trace generation, argument structure, risk factor identification, and SHA256 canonical hashing are all implemented and functional.
52
+
53
+ **What's real:**
54
+ - `ReasoningTrace` dataclass with full audit trail
55
+ - `Argument` and `RiskFactor` structures
56
+ - SHA256 hash of canonical JSON representation
57
+ - Trade signal generation with urgency classification
58
+
59
+ ---
60
+
61
+ ### ✅ Polymarket Market Data — FULLY REAL (Public API)
62
+
63
+ ```python
64
+ from builderbrain import PolymarketClient
65
+
66
+ client = PolymarketClient(paper_trade=True)
67
+ markets = client.fetch_markets(limit=50)
68
+ # Calls https://gamma-api.polymarket.com/markets (live)
69
+ ```
70
+
71
+ **No credentials needed for read-only.** The Gamma API is public and requires no authentication.
72
+
73
+ **What's real:**
74
+ - Live market data (prices, liquidity, volume, categories)
75
+ - Orderbook fetching from CLOB API
76
+ - Market parsing with price normalization
77
+
78
+ **What needs credentials:**
79
+ - Order submission to CLOB (`POLY_API_KEY`, `POLY_PRIVATE_KEY`)
80
+ - Builder code attribution (needs registered builder code)
81
+
82
+ ---
83
+
84
+ ### ⚠️ Polymarket Builder Codes — SIMULATED
85
+
86
+ **Current:** Paper trading with simulated order execution. Builder code is attached as a field in the order struct but never submitted on-chain.
87
+
88
+ **To make real:**
89
+ 1. Register at https://polymarket.com/settings?tab=builder
90
+ 2. Get your `bytes32` builder code (e.g., `0x0000...0001`)
91
+ 3. Set `POLY_BUILDER_CODE` in `.env`
92
+ 4. Implement CLOB order signing + submission in `polymarket_client.py::_live_execute()`
93
+
94
+ **Architecture is correct:** Builder code is passed as an order field, serialized on-chain as the `builder` field. This matches Polymarket's documented TypeScript pattern.
95
+
96
+ ---
97
+
98
+ ### ⚠️ Circle Gateway — SIMULATED (Real API Skeleton)
99
+
100
+ **Current:** `CircleGatewayClient` has real HTTP methods but `ArcBridge` falls back to simulation.
101
+
102
+ **Real API implemented:**
103
+ ```python
104
+ from builderbrain import CircleGatewayClient
105
+
106
+ client = CircleGatewayClient(api_key="sk_test_...")
107
+ domains = client.get_gateway_info() # GET /v1/gateway-info
108
+ balances = client.get_balances("0x...", 0) # POST /v1/balances
109
+ # attestation = client.create_transfer_attestation(...) # POST /v1/transfer
110
+ ```
111
+
112
+ **What's simulated:**
113
+ - Cross-chain routing in `ArcBridge.route_usdc()` (creates fake tx hashes)
114
+ - No actual burn intent encoding + signing
115
+
116
+ **To make real:**
117
+ 1. Set `CIRCLE_API_KEY` in `.env`
118
+ 2. Pass `gateway_client=CircleGatewayClient(api_key)` to `ArcBridge`
119
+ 3. Implement burn intent encoding (requires domain info from `get_gateway_info()`)
120
+ 4. Implement depositor signature (requires wallet integration)
121
+
122
+ **Gateway Info endpoint works without full setup:** You can call `get_gateway_info()` and `get_balances()` with just an API key.
123
+
124
+ ---
125
+
126
+ ### ⚠️ Arc Nanopayments — SIMULATED
127
+
128
+ **Current:** App-level payment ledger with batch aggregation. No actual cryptographic settlement.
129
+
130
+ **Real architecture (from docs):**
131
+ 1. Buyer signs EIP-3009 authorization (off-chain)
132
+ 2. Seller verifies signature (off-chain)
133
+ 3. Seller logs in own "virtual ledger" DB
134
+ 4. Periodic batch settlement via Circle Gateway transfer on Arc
135
+
136
+ **What's simulated:**
137
+ - Payment creation (just appends to list)
138
+ - Batch settlement (just aggregates and clears list)
139
+ - No EIP-3009 signatures
140
+ - No x402 HTTP 402 protocol negotiation
141
+
142
+ **To make real:**
143
+ 1. Implement EIP-3009 authorization signing (requires buyer wallet)
144
+ 2. Implement signature verification (seller side)
145
+ 3. Add database for virtual ledger
146
+ 4. Wire batch settlement to `CircleGatewayClient`
147
+
148
+ **No public REST API exists** for `/v1/nanopayments/batches` — this is by design. Settlement is through Gateway.
149
+
150
+ ---
151
+
152
+ ### ⚠️ USYC Yield — SIMULATED
153
+
154
+ **Current:** Balance tracking with simulated rotation.
155
+
156
+ **Real contracts (Arc Testnet):**
157
+ - USYC Token: `0xe9185F0c5F296Ed1797AaE4238D26CCaBEadb86C`
158
+ - Teller: `0x9fdF14c5B14173D74C08Af27AebFf39240dC105A`
159
+ - Oracle: `0x52b56c7642E71dc54714d879127d97cd0B3D4581`
160
+
161
+ **What's simulated:**
162
+ - `rotate_to_usyc()` just updates balance dict
163
+ - No Teller contract interaction
164
+ - No Oracle price fetching
165
+
166
+ **To make real:**
167
+ 1. Add Web3 provider (e.g., `web3.py` or `ethers.js` via Python wrapper)
168
+ 2. Load Teller ABI
169
+ 3. Call Teller.subscribe() with USDC amount
170
+ 4. Call Oracle for NAV/share price
171
+ 5. Use `https://usyc.dev.hashnote.com/api/price` for reference pricing
172
+
173
+ ---
174
+
175
+ ### ⚠️ Paymaster (Gas Abstraction) — SIMULATED
176
+
177
+ **Current:** Log-only. No actual ERC-4337 UserOperation construction or submission.
178
+
179
+ **Real architecture (from docs):**
180
+ - Arc supports standard ERC-4337 EntryPoint
181
+ - Use Pimlico bundler on Arc
182
+ - Circle Paymaster: users sign EIP-2612 permit
183
+ - `paymasterData` = encodePacked([uint8, address, uint256, bytes], [0, usdcAddress, permitAmount, permitSignature])
184
+ - Submit UserOperation via bundler RPC
185
+
186
+ **What's simulated:**
187
+ - `sponsor_transaction()` just logs the intent
188
+ - No UserOperation construction
189
+ - No bundler RPC call
190
+ - No paymaster contract interaction
191
+
192
+ **To make real:**
193
+ 1. Set `PIMLICO_BUNDLER_URL` in `.env`
194
+ 2. Implement UserOperation construction (standard ERC-4337 library)
195
+ 3. Implement EIP-2612 permit signing
196
+ 4. Submit to Pimlico bundler
197
+
198
+ ---
199
+
200
+ ### ⚠️ Wallets — SIMULATED
201
+
202
+ **Current:** Configuration only. No actual wallet creation or transaction signing.
203
+
204
+ **Real options:**
205
+ 1. **Circle Dev-Controlled Wallets:**
206
+ - API: `create-developer-transaction-transfer`, `create-developer-transaction-contract-execution`
207
+ - Custodied by Circle; no key exposure
208
+ - Set `CIRCLE_WALLET_API_KEY` + `CIRCLE_WALLET_SET_ID`
209
+
210
+ 2. **Self-custody (EOA or SCA):**
211
+ - Import private key
212
+ - Use standard Web3 libraries
213
+ - For SCA: deploy ERC-4337 smart contract wallet
214
+
215
+ **What's simulated:**
216
+ - No wallet addresses
217
+ - No transaction signing
218
+ - No API calls to Circle Wallet service
219
+
220
+ ---
221
+
222
+ ## Migration Path: Simulated → Real
223
+
224
+ ### Phase 1: Read-Only Live Data (Day 1)
225
+
226
+ ```python
227
+ # Already works — just run it
228
+ brain = BuilderBrain(paper_trade=True)
229
+ brain.run_cycle() # Fetches real Polymarket data
230
+ ```
231
+
232
+ ### Phase 2: Real Polymarket Builder Codes (Day 2-3)
233
+
234
+ 1. Register builder code at https://polymarket.com/settings?tab=builder
235
+ 2. Set `POLY_BUILDER_CODE` in `.env`
236
+ 3. Implement CLOB order signing (use `py_clob_client` or Polymarket's Python SDK)
237
+ 4. Switch `paper_trade=False`
238
+
239
+ ### Phase 3: Circle Gateway Integration (Day 3-4)
240
+
241
+ 1. Get Circle API key from https://developers.circle.com/
242
+ 2. Set `CIRCLE_API_KEY` in `.env`
243
+ 3. Test `CircleGatewayClient.get_gateway_info()`
244
+ 4. Implement burn intent encoding for transfers
245
+ 5. Wire `ArcBridge` with real `gateway_client`
246
+
247
+ ### Phase 4: USYC + Paymaster (Day 4-5)
248
+
249
+ 1. Get Arc Testnet USDC from faucet
250
+ 2. Test Teller contract interaction (subscribe/redeem)
251
+ 3. Set up Pimlico bundler for paymaster
252
+ 4. Test ERC-4337 UserOperation flow
253
+
254
+ ### Phase 5: Nanopayments (Day 5-6)
255
+
256
+ 1. Implement EIP-3009 authorization flow
257
+ 2. Set up virtual ledger DB
258
+ 3. Wire batch settlement to Gateway
259
+ 4. Test end-to-end: insight → payment → settlement
260
+
261
+ ---
262
+
263
+ ## What Judges Will See
264
+
265
+ | Demo Element | What They See | What's Actually Happening |
266
+ |-------------|--------------|---------------------------|
267
+ | Market prices | Real Polymarket data | Live Gamma API calls |
268
+ | Kelly sizing | Real optimization | `cvxpy` convex QP solver |
269
+ | Reasoning traces | Structured arguments + risks | SHA256-hashed audit artifacts |
270
+ | Trade execution | Simulated fills with builder codes | Paper trading; fields correct |
271
+ | Cross-chain settlement | Simulated transfer hashes | No actual Gateway call |
272
+ | Nanopayments | Aggregated fee log | No EIP-3009 signatures |
273
+ | USYC rotation | Balance update | No Teller contract call |
274
+ | Gas sponsorship | Log entry | No UserOperation |
275
+
276
+ **Recommendation for hackathon:** Run in simulated mode for the demo, but show the real API client code and explain the integration path. Judges appreciate architectural thinking and honest documentation.
277
+
278
+ ---
279
+
280
+ ## Credentials Checklist
281
+
282
+ To go fully live, you need:
283
+
284
+ - [ ] Circle Developer account + API key
285
+ - [ ] Polymarket account + API key + private key
286
+ - [ ] Registered Polymarket builder code
287
+ - [ ] Arc Testnet RPC endpoint
288
+ - [ ] Arc Testnet USDC (from faucet)
289
+ - [ ] Pimlico bundler access (for paymaster)
290
+ - [ ] Circle Wallet API key + Wallet Set ID (optional, for embedded wallets)
291
+
292
+ See `.env.example` for all required environment variables.