You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: remove all direct RPC calls, route through Turbine API (#30)
* feat: remove all direct RPC calls, route through Turbine API
Eliminates the SDK's dependency on direct blockchain RPC connections.
All on-chain queries now route through the Turbine API.
Changes:
- _get_contract_nonce() → GET /contracts/nonce/:contract/:owner
- get_usdc_balance() → GET /users/:address/balances
- get_usdc_allowance() → GET /users/:address/balances
- approve_usdc() → gasless permit via POST /relayer/usdc-permit
- claim_winnings() → GET /users/:address/claim-data + sign + POST /relayer/ctf-redemption
- batch_claim_winnings() → same pattern, batched
- discover_positions() → GET /users/:address/claimable (replaces Multicall3)
- Removed hardcoded Ankr RPC key from discovery.py
- Removed web3 from required dependencies
All method signatures remain backward compatible. The SDK no longer
requires any RPC URL or web3 connection.
Requires: ojo-network/turbine-clob#241 (new API endpoints)
* docs: update all docs to reflect API-only SDK (no RPC/web3)
- CLAUDE.md: added API-only description, updated approve_usdc to return dict,
updated Gasless concept, added API routing details under the hood
- create-bot/SKILL.md: updated gasless approval pattern
- create-liquidity-bot/SKILL.md: updated gasless approval pattern
- setup/SKILL.md: noted API-only in env var description
- README.md: added API-only overview, no RPC note in credentials
- docs/onboarding.md: reinforced no RPC/web3 needed
Copy file name to clipboardExpand all lines: .claude/skills/create-bot/SKILL.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -364,7 +364,7 @@ After the bot is running, suggest next steps based on the user's goals (from `us
364
364
365
365
1. **Order verification chain:** After `post_order()`, sleep 2 seconds, then check failed trades → pending trades → recent trades → open orders. This sequence ensures the bot knows the true state of its order. Skipping steps causes phantom orders or missed fills.
366
366
367
-
2. **Gasless USDC approval:** One-time max EIP-2612 permit per settlement contract. Check allowance first, skip if already approved. Never do per-order approvals.
367
+
2. **Gasless USDC approval:** One-time gasless permit via API per settlement contract. `approve_usdc()` returns a dict with `tx_hash` key (not a raw tx hash string). Check allowance first via API, skip if already approved. Never do per-order approvals. No web3 or RPC needed.
368
368
369
369
3. **Market transitions:** Poll every 5 seconds for new markets. On transition: cancel all orders on the old market, reset state (pending orders, processed trade IDs, expiration flag), approve USDC for the new settlement if needed, then resume trading.
Copy file name to clipboardExpand all lines: .claude/skills/create-liquidity-bot/SKILL.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -329,7 +329,7 @@ After the bot is running, suggest next steps based on the user's goals:
329
329
330
330
**DO NOT modify these when generating bots.** They exist in `examples/market_maker.py` for a reason and must be preserved exactly:
331
331
332
-
1. **Gasless USDC approval:** One-time max EIP-2612 permit per settlement contract. Check allowance first, skip if already approved. Never do per-order approvals.
332
+
1. **Gasless USDC approval:** One-time gasless permit via API per settlement contract. `approve_usdc()` returns a dict with `tx_hash` key (not a raw tx hash string). Check allowance first via API, skip if already approved. Never do per-order approvals. No web3 or RPC needed.
333
333
334
334
2. **Graceful rebalance:** Place new orders FIRST, brief pause, then cancel old ones. This ensures continuous liquidity — no gap where traders can't trade. This is critical and different from cancel-then-place.
-`TURBINE_PRIVATE_KEY` — Their wallet's signing key. Never leaves this machine.
229
229
-`TURBINE_API_KEY_ID` / `TURBINE_API_PRIVATE_KEY` — Left blank intentionally. The bot auto-registers API credentials on first run and saves them back to this file.
230
230
-`CHAIN_ID=137` — Polygon mainnet. This is where Turbine's active markets are.
231
-
-`TURBINE_HOST` — Turbine's API endpoint.
231
+
-`TURBINE_HOST` — Turbine's API endpoint. All SDK operations (approvals, claims, balance checks) route through this — no RPC URL or web3 needed.
Copy file name to clipboardExpand all lines: CLAUDE.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,8 @@ This matters because it dramatically lowers the barrier to entry. A new user doe
47
47
48
48
Turbine runs an off-chain orderbook (CLOB) with on-chain settlement. Orders are signed off-chain using EIP-712, matched by Turbine's API, then settled on-chain via modified Gnosis CTF smart contracts. Market resolution is handled by the UMA Optimistic Oracle — after 15 minutes, the oracle checks BTC's price against the strike and declares a winner. The 1% flat fee per trade is the only cost.
49
49
50
+
**From the SDK's perspective**, everything goes through the Turbine API — there are no direct RPC or on-chain calls. USDC approvals use gasless permits via `/relayer/usdc-permit`, balance/allowance checks go through `/users/:address/balances`, claims go through `/users/:address/claim-data` + the relayer, and contract nonces come from `/contracts/nonce/:contract/:owner`.
51
+
50
52
### Competitions and Hackathons
51
53
52
54
Turbine is actively growing its user base through two channels:
@@ -61,6 +63,8 @@ Turbine is actively growing its user base through two channels:
61
63
62
64
This is the official Python SDK for Turbine's API, bundled with example trading bots and Claude Code skills for bot generation. It exists to get people trading on Turbine as fast as possible.
63
65
66
+
**The SDK is fully API-routed** — all operations go through `api.turbinefi.com`. There is no RPC URL, no web3 dependency, and no direct blockchain node access required. Users only need a private key, chain ID, and the API host.
67
+
64
68
**Why it exists:** Turbine is a prediction markets platform, but a platform without traders is empty. This repo is the primary onboarding funnel — it's how new users go from "curious" to "actively trading." The easier it is to clone this repo, build a bot, and start competing, the more traders Turbine gets.
65
69
66
70
The typical user journey:
@@ -213,7 +217,7 @@ When a user wants to create or modify a bot:
213
217
214
218
4.**Preserve critical infrastructure patterns.** These exist in every working bot and must not be removed or altered:
215
219
-**Order verification chain:** After submitting an order, wait 2 seconds, then check failed trades → pending trades → recent trades → open orders. This sequence ensures the bot knows the true state of its order.
216
-
-**Gasless USDC approval:** One-time max EIP-2612 permit per settlement contract. Check allowance first, skip if already approved.
220
+
-**Gasless USDC approval:** One-time gasless permit via API per settlement contract. `approve_usdc()` returns a dict with `tx_hash` (not a raw tx hash string). Check allowance first via API, skip if already approved.
217
221
-**Market transitions:** Poll for new markets every 5 seconds. When a new market appears, cancel all orders on the old market, reset state, and start trading the new one.
218
222
-**Claiming:** Background task that checks for resolved markets and claims winnings via the gasless relayer. Enforce a 15-second delay between claims (API rate limit).
219
223
-**Market expiration:** Stop placing new orders when less than 60 seconds remain in a market. The `market_expiring` flag prevents the bot from getting stuck with orders on an expired market.
@@ -255,7 +259,7 @@ client.get_user_positions(address) # Current positions
255
259
client.get_orders(trader) # Open orders
256
260
257
261
# Gasless relayer operations
258
-
client.approve_usdc_for_settlement(addr) # One-time max USDC permit (gasless)
262
+
client.approve_usdc_for_settlement(addr) # One-time gasless permit via API (returns dict with tx_hash)
259
263
client.claim_winnings(contract_addr) # Claim from a resolved market (gasless)
260
264
client.batch_claim_winnings(addrs) # Claim from multiple markets at once
261
265
```
@@ -275,8 +279,8 @@ For a deeper explanation aimed at newcomers, see `docs/prediction-markets.md`.
275
279
-**Strike price:** The BTC price threshold set when the market opens. If BTC ends above it, YES wins. Below, NO wins. This is the anchor that every trading decision revolves around.
276
280
-**Settlement address:** The on-chain contract that holds USDC collateral and executes trades. There's one per chain, shared across all markets. Requires a one-time gasless approval before the bot can trade.
277
281
-**Contract address:** A per-market contract for outcome tokens (ERC1155). Only needed when claiming winnings after a market resolves — not during trading.
278
-
-**Gasless:** Turbine's relayer pays all gas fees. Users sign messages with their private key (free, off-chain), and the relayer handles on-chain submission. This is why users only need USDC — no ETH, MATIC, or AVAX.
279
-
-**USDC approval:** A one-time max EIP-2612 permit per settlement contract. Once approved, all future orders on that chain reuse the allowance. No per-trade approval overhead.
282
+
-**Gasless:**The SDK is fully API-routed — all operations (approvals, claims, balance checks) go through Turbine's API, which handles on-chain submission via a relayer. Users sign messages with their private key (free, off-chain) and never need RPC access, web3, or native gas tokens (no ETH, MATIC, or AVAX). Only USDC is needed.
283
+
-**USDC approval:** A one-time gasless EIP-2612 permit via the API's `/relayer/usdc-permit` endpoint. Returns a dict with `tx_hash`. Once approved, all future orders on that chain reuse the allowance. No per-trade approval overhead.
280
284
-**UMA Oracle:** The decentralized oracle that resolves markets. After a market expires, UMA checks BTC's price and declares whether YES or NO wins. This is trustless — no single party controls the outcome.
281
285
-**Pyth Network:** Provides real-time BTC price data. This is the same feed Turbine uses for market resolution, which is why the Price Action strategy (which trades based on Pyth data) is recommended — the bot's signal aligns with how winners are determined.
0 commit comments