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

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -52
README.md CHANGED
@@ -1,13 +1,11 @@
1
- ---
2
- tags:
3
- - ml-intern
4
- ---
5
  # BuilderBrain
6
 
7
  **Agentic Prediction Market Intelligence** β€” An AI research and trading agent that reads the prediction-market universe, produces structured probabilities and reasoning traces, and routes orders via Polymarket builder codes, settling capital over Arc using USDC Nanopayments and Gateway.
8
 
9
  Built for the **Agora Agents Hackathon** (Canteen Γ— Circle).
10
 
 
 
11
  ---
12
 
13
  ## What It Does
@@ -26,13 +24,17 @@ Polymarket Data β†’ Reasoning Agent β†’ Kelly Engine β†’ Builder Code Router β†’
26
 
27
  ### Key Features
28
 
29
- | Component | What It Does | Why It Wins |
30
- |-----------|-------------|-------------|
31
- | **Reasoning Agent** | Generates structured reasoning traces (arguments, evidence, risks) for every trade | "Trading-R1": reasoning as a first-class product, hashed and auditable |
32
- | **QP Kelly Engine** | Convex optimization for correlation-aware position sizing | References Tepelyan (Bloomberg 2026) Laplace quadrature; achieves 95%+ optimal in <10ms |
33
- | **Block-Diagonal Correlation** | Politics/crypto/sports/macro theme blocks with intra-theme correlations | Jane Street-level rigor; most teams do independent Kelly |
34
- | **Builder Code Router** | Routes orders through builder codes, earning fees on every fill | Real monetization; aligns with Polymarket's builder ecosystem |
35
- | **Arc Integration** | Gateway, Nanopayments, USYC, Paymaster, Wallets | Full Circle primitive showcase |
 
 
 
 
36
 
37
  ---
38
 
@@ -42,7 +44,7 @@ Polymarket Data β†’ Reasoning Agent β†’ Kelly Engine β†’ Builder Code Router β†’
42
  # Install dependencies
43
  pip install -r requirements.txt
44
 
45
- # Run demo
46
  python demo.py
47
  ```
48
 
@@ -59,7 +61,7 @@ brain = BuilderBrain(
59
  min_edge=0.03, # 3% minimum edge
60
  )
61
 
62
- # Run one cycle
63
  signals = brain.run_cycle()
64
 
65
  # Get top signals
@@ -72,46 +74,76 @@ for sig in brain.get_top_signals(5):
72
  brain.export_audit_log("audit.json")
73
  ```
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  ---
76
 
77
  ## Architecture
78
 
79
  ```
80
  builderbrain/
81
- β”œβ”€β”€ __init__.py # Package exports
82
- β”œβ”€β”€ quant_engine.py # KellyEngine + CorrelationMatrix
83
- β”œβ”€β”€ polymarket_client.py # PolymarketClient + BuilderCodeRouter
84
- β”œβ”€β”€ reasoning_agent.py # ReasoningAgent + TradeSignal
85
- β”œβ”€β”€ arc_bridge.py # ArcBridge + NanopaymentConfig
86
- └── pipeline.py # BuilderBrain main orchestrator
87
-
88
- demo.py # Hackathon demo script
89
- requirements.txt # Dependencies
 
 
 
 
 
90
  ```
91
 
92
- ### Quant Engine (`quant_engine.py`)
93
 
94
- - **KellyEngine**: Convex QP approximation to multivariate Kelly
95
  - **CorrelationMatrix**: Block-diagonal structure (politics, crypto, sports, macro)
96
  - **Constraints**: Leverage ≀2Γ—, drawdown ≀20%, per-position ≀25%
 
97
 
98
- ### Reasoning Agent (`reasoning_agent.py`)
99
 
100
  - **ReasoningTrace**: Complete audit artifact with sources, arguments, risks
101
  - **TradeSignal**: Executable recommendation with urgency classification
102
  - **On-chain anchoring**: SHA256 hash of canonical JSON representation
103
 
104
- ### Polymarket Client (`polymarket_client.py`)
105
 
106
- - **PolymarketClient**: Live market data via Gamma API + paper trading
107
- - **BuilderCodeRouter**: Intelligent builder code selection (category match, fee share, volume)
 
108
 
109
- ### Arc Bridge (`arc_bridge.py`)
110
 
111
- - **Gateway + CCTP**: Cross-chain USDC routing
112
- - **Nanopayments**: Per-trade (5bps) + per-insight (1Β’) fees
113
- - **USYC**: 4.3% APY on idle capital with auto risk-off rotation
114
- - **Paymaster**: Gas-abstracted UX
 
 
 
 
 
 
115
 
116
  ---
117
 
@@ -147,6 +179,30 @@ s.t. f β‰₯ 0
147
 
148
  ---
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  ## Hackathon Alignment
151
 
152
  ### RFB 02: Prediction Market Trader Intelligence
@@ -223,7 +279,7 @@ Canteen's stack: Market Creation β†’ Liquidity β†’ Resolution β†’ Settlement β†’
223
  ```
224
  numpy>=1.24.0 # Numerical computing
225
  cvxpy>=1.3.0 # Convex optimization
226
- requests>=2.28.0 # HTTP client for Polymarket API
227
  ```
228
 
229
  ---
@@ -244,22 +300,6 @@ requests>=2.28.0 # HTTP client for Polymarket API
244
  - Canteen (2026). *Unbundling the Prediction Market Stack*.
245
  - Circle (2026). *USDC OpenClaw Hackathon*.
246
 
247
- <!-- ml-intern-provenance -->
248
- ## Generated by ML Intern
249
-
250
- This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
251
-
252
- - Try ML Intern: https://smolagents-ml-intern.hf.space
253
- - Source code: https://github.com/huggingface/ml-intern
254
-
255
- ## Usage
256
-
257
- ```python
258
- from transformers import AutoModelForCausalLM, AutoTokenizer
259
-
260
- model_id = "razvan/builderbrain"
261
- tokenizer = AutoTokenizer.from_pretrained(model_id)
262
- model = AutoModelForCausalLM.from_pretrained(model_id)
263
- ```
264
 
265
- For non-causal architectures, replace `AutoModelForCausalLM` with the appropriate `AutoModel` class.
 
 
 
 
 
1
  # BuilderBrain
2
 
3
  **Agentic Prediction Market Intelligence** β€” An AI research and trading agent that reads the prediction-market universe, produces structured probabilities and reasoning traces, and routes orders via Polymarket builder codes, settling capital over Arc using USDC Nanopayments and Gateway.
4
 
5
  Built for the **Agora Agents Hackathon** (Canteen Γ— Circle).
6
 
7
+ **Status:** Core quant engine, reasoning agent, and Polymarket market data are **fully functional**. Arc/Circle settlement layer has **real API skeletons + simulated fallback** β€” documented with exact integration paths. See [`REAL_VS_SIMULATED.md`](./REAL_VS_SIMULATED.md) for detailed status.
8
+
9
  ---
10
 
11
  ## What It Does
 
24
 
25
  ### Key Features
26
 
27
+ | Component | Status | What It Does | Why It Wins |
28
+ |-----------|--------|-------------|-------------|
29
+ | **Reasoning Agent** | βœ… Real | Generates structured reasoning traces (arguments, evidence, risks) for every trade | "Trading-R1": reasoning as a first-class product, hashed and auditable |
30
+ | **QP Kelly Engine** | βœ… Real | Convex optimization for correlation-aware position sizing | References Tepelyan (Bloomberg 2026) Laplace quadrature; achieves 95%+ optimal in <10ms |
31
+ | **Block-Diagonal Correlation** | βœ… Real | Politics/crypto/sports/macro theme blocks with intra-theme correlations | Jane Street-level rigor; most teams do independent Kelly |
32
+ | **Polymarket Data** | βœ… Real | Live market data via Gamma API (public, no auth) | Real prices, liquidity, orderbook |
33
+ | **Builder Code Router** | ⚠️ Simulated | Routes orders through builder codes, earning fees on every fill | Real monetization; fields correct per Polymarket docs |
34
+ | **Circle Gateway** | ⚠️ Simulated | Cross-chain USDC routing via CCTP | Real HTTP client skeleton; needs API key + burn intent encoding |
35
+ | **Arc Nanopayments** | ⚠️ Simulated | Per-trade (5bps) + per-insight (1’) fees | Architecture correct per x402/EIP-3009 docs; needs signatures |
36
+ | **USYC Yield** | ⚠️ Simulated | 4.3% APY on idle capital with auto risk-off rotation | Real Arc Testnet contracts documented |
37
+ | **Paymaster** | ⚠️ Simulated | Gas-abstracted UX via ERC-4337 | Architecture correct per Pimlico + Circle docs |
38
 
39
  ---
40
 
 
44
  # Install dependencies
45
  pip install -r requirements.txt
46
 
47
+ # Run demo (simulated mode, works without credentials)
48
  python demo.py
49
  ```
50
 
 
61
  min_edge=0.03, # 3% minimum edge
62
  )
63
 
64
+ # Run one cycle (fetches real Polymarket data)
65
  signals = brain.run_cycle()
66
 
67
  # Get top signals
 
74
  brain.export_audit_log("audit.json")
75
  ```
76
 
77
+ ### Using Real Circle Gateway API
78
+
79
+ ```python
80
+ from builderbrain import BuilderBrain, CircleGatewayClient
81
+
82
+ # Initialize with real Gateway client
83
+ gateway = CircleGatewayClient(api_key="sk_test_...")
84
+ brain = BuilderBrain(
85
+ bankroll_usd=10000,
86
+ arc_bridge=gateway, # Use real Gateway instead of simulated
87
+ )
88
+
89
+ # Query balances
90
+ balances = gateway.get_balances(depositor="0x...", domain=0)
91
+ print(balances)
92
+ ```
93
+
94
  ---
95
 
96
  ## Architecture
97
 
98
  ```
99
  builderbrain/
100
+ β”œβ”€β”€ __init__.py # Package exports
101
+ β”œβ”€β”€ quant_engine.py # KellyEngine + CorrelationMatrix (REAL)
102
+ β”œβ”€β”€ polymarket_client.py # PolymarketClient + BuilderCodeRouter (Market data REAL, orders SIMULATED)
103
+ β”œβ”€β”€ reasoning_agent.py # ReasoningAgent + TradeSignal (REAL)
104
+ β”œβ”€β”€ arc_bridge.py # ArcBridge β€” simulated with real API patterns documented
105
+ β”œβ”€β”€ circle_gateway_client.py # CircleGatewayClient β€” REAL HTTP client for Gateway API
106
+ β”œβ”€β”€ pipeline.py # BuilderBrain main orchestrator
107
+
108
+ demo.py # Hackathon demo script
109
+ requirements.txt # Dependencies
110
+ .env.example # All required credentials for live mode
111
+ REAL_VS_SIMULATED.md # Detailed real vs simulated breakdown
112
+ tests/
113
+ └── test_quant_engine.py # Unit tests for Kelly engine
114
  ```
115
 
116
+ ### Quant Engine (`quant_engine.py`) β€” βœ… FULLY REAL
117
 
118
+ - **KellyEngine**: Convex QP approximation to multivariate Kelly using `cvxpy` + `ECOS` solver
119
  - **CorrelationMatrix**: Block-diagonal structure (politics, crypto, sports, macro)
120
  - **Constraints**: Leverage ≀2Γ—, drawdown ≀20%, per-position ≀25%
121
+ - **Reference**: Tepelyan (Bloomberg, 2026) β€” QP approximation achieves >95% of Laplace quadrature solution in <10ms
122
 
123
+ ### Reasoning Agent (`reasoning_agent.py`) β€” βœ… FULLY REAL
124
 
125
  - **ReasoningTrace**: Complete audit artifact with sources, arguments, risks
126
  - **TradeSignal**: Executable recommendation with urgency classification
127
  - **On-chain anchoring**: SHA256 hash of canonical JSON representation
128
 
129
+ ### Polymarket Client (`polymarket_client.py`) β€” MIXED
130
 
131
+ - βœ… **Market data**: Live Gamma API calls (public, no auth)
132
+ - βœ… **Orderbook**: Live CLOB API calls
133
+ - ⚠️ **Order execution**: Simulated paper trading; builder code field structure is correct per Polymarket docs
134
 
135
+ ### Arc Bridge (`arc_bridge.py`) β€” SIMULATED WITH REAL PATTERNS
136
 
137
+ - Documented with exact real API endpoints and request/response schemas
138
+ - Simulated for hackathon demo without credentials
139
+ - Dual mode: pass `gateway_client` for real API calls
140
+
141
+ ### Circle Gateway Client (`circle_gateway_client.py`) β€” βœ… REAL HTTP CLIENT
142
+
143
+ - **GET /v1/gateway-info**: Enumerate domains/chains/contracts
144
+ - **POST /v1/balances**: Query unified USDC balance
145
+ - **POST /v1/transfer**: Create transfer attestation (needs burn intent encoding + signatures)
146
+ - Base URL: `https://gateway-api-testnet.circle.com`
147
 
148
  ---
149
 
 
179
 
180
  ---
181
 
182
+ ## Real vs Simulated: Migration Path
183
+
184
+ ### Already Working (No Credentials)
185
+
186
+ - βœ… Live Polymarket market data
187
+ - βœ… Kelly optimization with correlation-aware sizing
188
+ - βœ… Structured reasoning trace generation
189
+ - βœ… Paper trading with builder code field tracking
190
+
191
+ ### Needs Credentials (See `.env.example`)
192
+
193
+ | Step | What You Need | Estimated Time |
194
+ |------|--------------|---------------|
195
+ | 1. Polymarket builder codes | Register at polymarket.com/settings?tab=builder | 10 min |
196
+ | 2. Circle API key | Sign up at developers.circle.com | 30 min |
197
+ | 3. Gateway transfers | API key + depositor address + domain info | 2-4 hours |
198
+ | 4. Nanopayments | x402 client + EIP-3009 signing | 1 day |
199
+ | 5. USYC yield | Web3 provider + Teller ABI | 2-3 hours |
200
+ | 6. Paymaster | Pimlico bundler + ERC-4337 setup | 1 day |
201
+
202
+ See [`REAL_VS_SIMULATED.md`](./REAL_VS_SIMULATED.md) for detailed integration paths, exact API endpoints, and contract addresses.
203
+
204
+ ---
205
+
206
  ## Hackathon Alignment
207
 
208
  ### RFB 02: Prediction Market Trader Intelligence
 
279
  ```
280
  numpy>=1.24.0 # Numerical computing
281
  cvxpy>=1.3.0 # Convex optimization
282
+ requests>=2.28.0 # HTTP client for Polymarket + Circle APIs
283
  ```
284
 
285
  ---
 
300
  - Canteen (2026). *Unbundling the Prediction Market Stack*.
301
  - Circle (2026). *USDC OpenClaw Hackathon*.
302
 
303
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
+ *ML Intern generated repository. See source code for implementation details and REAL_VS_SIMULATED.md for integration status.*