LiberFi Prediction Market
Browse prediction market events, manage positions, and place orders on Kalshi and Polymarket using the LiberFi CLI.
Pre-flight Checks
See bootstrap.md for CLI installation and connectivity verification.
This skill's auth requirements:
| Command |
Requires Auth |
lfi predict events |
No |
lfi predict event <slug> |
No |
lfi predict balance |
No |
lfi predict positions |
No |
lfi predict trades |
No |
lfi predict orders |
No (Polymarket needs POLY_* headers) |
lfi predict order <id> |
No (Polymarket needs POLY_* headers) |
lfi predict polymarket-tick-size |
No |
lfi predict polymarket-fee-rate |
No |
lfi predict polymarket-setup-status |
No (uses TEE wallet if logged in) |
lfi predict polymarket-deposit-addresses |
No |
lfi predict polymarket-setup |
Yes (LiberFi JWT) |
lfi predict polymarket-place |
Yes (LiberFi JWT — server signs via TEE) |
lfi predict kalshi-place |
Yes (LiberFi JWT — server signs via TEE) |
lfi predict cancel |
Yes (LiberFi JWT — auto L2 auth for polymarket) |
lfi predict kalshi-quote (DEPRECATED) |
No |
lfi predict kalshi-submit (DEPRECATED) |
No |
lfi predict polymarket-order (DEPRECATED) |
No (requires POLY_* headers) |
Recommended flow (TEE auto): polymarket-setup → polymarket-place /
kalshi-place / cancel. The server holds the user's TEE wallet via Privy
and signs every transaction internally — no POLY_* HMAC, no Solana signing,
no EIP-712 work for the caller.
Legacy flow: Polymarket order operations via polymarket-order require
CLOB HMAC authentication via five --poly-* flags. These are NOT LiberFi
JWT credentials — they are the user's own Polymarket CLOB API credentials.
TEE Auto Order Flow (CRITICAL)
For the canonical end-to-end order placement flow — including pre-flight
status checks, deposit handling, market vs limit order branching, and post-
order verification — see reference/order-flow.md.
The CLI/skill expects this exact ordering for Polymarket:
lfi status — confirm authenticated; if not, run lfi login key
lfi predict polymarket-setup-status --json — check Safe deployment +
token approvals
- If
safe_deployed=false or any approval missing: lfi predict polymarket-setup --json (one-shot; gasless via Builder Relayer)
- Check Safe USDC balance — pass the TEE EOA, NOT the Safe:
lfi predict balance --source polymarket --user <tee-eoa> --json
(server derives Safe from EOA internally). If balance < 2, fetch
BRIDGE deposit addresses using the Safe address from step 2/3:
lfi predict polymarket-deposit-addresses --safe-address <safe> --json
→ returns { evm, svm, btc, tron }. Pick the field matching the user's
chain (default evm for ETH/Polygon/Base/Arb/Op/BNB). Tell user to send
≥ $2 USDC to that bridge address (NEVER to the Safe address — the Safe
is Polymarket's internal custody contract, not a user-facing deposit
target). The Polymarket Bridge service auto-credits the Safe.
- Ask the user: market or limit? For limit, also ask price + size + GTC
vs GTD (with expiration if GTD). For market, ask USDC spend (BUY) or
share count (SELL)
- Show the final order summary, wait for explicit confirmation
lfi predict polymarket-place --token-id <id> --side <s> --order-type <t> [--price <p>] [--size <sz>] [--expiration <epoch>] --json
lfi predict orders --source polymarket --json — verify open orders
lfi predict cancel <id> --source polymarket --json — cancel if user
asks
For Kalshi the flow is shorter: lfi predict kalshi-place --input-mint <inMint> --output-mint <outMint> --amount <amt> --json — quote, sign
(SignSOL), and submit are all done server-side.
Skill Routing
| If user asks about... |
Route to |
| Token search, price, details, security |
liberfi-token |
| Token K-line, candlestick chart |
liberfi-token |
| Trending tokens, market rankings |
liberfi-market |
| Newly listed tokens |
liberfi-market |
| Wallet holdings, balance (non-prediction), PnL |
liberfi-portfolio |
| Wallet activity, transaction history |
liberfi-portfolio |
| Token swap, trade execution |
liberfi-swap |
| Login, logout, session management |
liberfi-auth |
CLI Command Index
Query Commands (read-only)
| Command |
Description |
Auth |
lfi predict events |
List prediction events with filtering |
No |
lfi predict event <slug> --source <s> |
Get event details by slug |
No |
lfi predict balance --source <s> --user <addr> |
Get USDC balance |
No |
lfi predict positions --user <addr> |
Get portfolio positions |
No |
lfi predict trades --wallet <addr> |
List trade history |
No |
lfi predict orders |
List orders |
No (POLY_* for Polymarket) |
lfi predict order <id> --source <s> |
Get order details |
No (POLY_* for Polymarket) |
TEE Auto Flow Commands (recommended)
| Command |
Description |
Auth |
lfi predict polymarket-tick-size --token-id <id> |
Min tick size for a token |
No |
lfi predict polymarket-fee-rate --token-id <id> |
Base fee rate (bps) |
No |
lfi predict polymarket-setup-status [--wallet-address <addr>] |
Safe deployment + approval status |
No (uses TEE wallet if logged in) |
lfi predict polymarket-setup |
Deploy Safe + approve all tokens (gasless) |
JWT |
lfi predict polymarket-deposit-addresses --safe-address <addr> |
Multi-chain deposit addresses for Safe |
No |
lfi predict polymarket-place --token-id <id> --side BUY|SELL --order-type GTC|GTD|FOK|FAK|MARKET [--price <p>] [--size <sz>] [--expiration <epoch>] [...] |
Prepare → TEE sign → execute Polymarket order |
JWT |
lfi predict kalshi-place --input-mint <m> --output-mint <m> --amount <a> [--slippage-bps <bps>] |
Quote → SignSOL → submit Kalshi order |
JWT |
lfi predict cancel <id> --source polymarket|kalshi |
Cancel order (auto L2 auth for poly) |
JWT |
Legacy / Deprecated Commands
| Command |
Description |
Auth |
lfi predict kalshi-quote --input-mint <m> --output-mint <m> --amount <a> --user-public-key <k> |
DEPRECATED — use kalshi-place. Request Kalshi quote |
No |
lfi predict kalshi-submit --signed-transaction <tx> --order-context '<json>' |
DEPRECATED — use kalshi-place. Submit pre-signed Kalshi tx |
No |
lfi predict polymarket-order --body '<json>' --poly-api-key <k> --poly-address <a> --poly-signature <s> --poly-passphrase <p> --poly-timestamp <t> |
DEPRECATED — use polymarket-place. Create Polymarket order with caller-managed POLY_* headers |
POLY_* headers |
Parameter Reference
Events list (lfi predict events):
--limit <n> — Max results per page
--cursor <cursor> — Pagination cursor
--status <status> — Event status filter (e.g. active, resolved)
--source <source> — Provider source: kalshi or polymarket
--tag-slug <slug> — Filter by tag
--search <query> — Free-text search
--sort-by <field> — Sort field
--sort-asc <bool> — Sort ascending: true or false
--with-markets <bool> — Include embedded markets: true or false
Event detail (lfi predict event <slug>):
<slug> — Required. Event slug identifier
--source <source> — Required. Provider source: kalshi or polymarket
Balance (lfi predict balance):
--source <source> — Required. Provider source: kalshi or polymarket
--user <address> — Required. For polymarket: pass the user's TEE EOA (e.g. evmAddress from lfi whoami); the server auto-derives the Safe via CREATE2. NEVER pass a Safe address here. For kalshi: pass the Solana public key (solAddress).
Positions (lfi predict positions):
--user <address> — Required. Same rule as balance: TEE EOA for polymarket (server derives Safe), Solana public key for kalshi.
--source <source> — Optional provider source filter
Trades (lfi predict trades):
--wallet <address> — Required. Same rule as balance: TEE EOA for polymarket (server derives Safe), Solana public key for kalshi.
--source <source> — Optional provider source filter
--limit <n> — Max results per page
--cursor <cursor> — Pagination cursor
--type <types> — Comma-separated trade types
--side <side> — Trade side filter
Orders (lfi predict orders):
--source <source> — Provider source
--wallet-address <address> — Wallet address (required for kalshi)
--market-id <id> — Market ID filter
--asset-id <id> — Asset ID filter
--next-cursor <cursor> — Pagination cursor
--poly-api-key, --poly-address, --poly-signature, --poly-passphrase, --poly-timestamp — Polymarket CLOB auth (required when source is polymarket)
Order detail (lfi predict order <id>):
<id> — Required. Order ID
--source <source> — Required. Provider source
- Same
--poly-* flags as orders list
Polymarket tick size (lfi predict polymarket-tick-size):
--token-id <id> — Required. Polymarket CLOB token ID
Polymarket fee rate (lfi predict polymarket-fee-rate):
--token-id <id> — Required. Polymarket CLOB token ID
Polymarket setup status (lfi predict polymarket-setup-status):
--wallet-address <addr> — Optional EVM address. Defaults to caller's TEE wallet when authenticated.
Polymarket setup (run) (lfi predict polymarket-setup):
- No flags. Requires authentication. Idempotent — safe to call repeatedly.
Polymarket deposit addresses (lfi predict polymarket-deposit-addresses):
--safe-address <addr> — Required. Safe wallet address (from polymarket-setup-status)
Polymarket place (TEE auto) (lfi predict polymarket-place):
--token-id <id> — Required. Polymarket CLOB token ID
--side BUY|SELL — Required.
--order-type GTC|GTD|FOK|FAK|MARKET — Required.
--price <p> — Limit price (limit orders only, e.g. 0.55). Required for GTC/GTD/FOK/FAK.
--size <sz> — Limit: shares; market BUY: USDC; market SELL: shares. Required for limit and market.
--expiration <epochSec> — Required for GTD.
--neg-risk true|false — Force NegRisk exchange. Auto-detected when omitted.
--fee-rate-bps <n> — Override fee rate (PS auto-resolves when omitted).
--tick-size <n> — Override tick size (PS auto-resolves when omitted).
--taker-address <addr> — Restrict the taker (advanced).
Kalshi place (TEE auto) (lfi predict kalshi-place):
--input-mint <addr> — Required. Input token mint
--output-mint <addr> — Required. Output token mint
--amount <amt> — Required. Amount in smallest unit
--slippage-bps <bps> — Slippage tolerance in basis points
Cancel order (lfi predict cancel <id>):
<id> — Required. Order ID
--source polymarket|kalshi — Required. For polymarket the L2 HMAC headers are derived from the caller's TEE wallet automatically.
Kalshi quote (lfi predict kalshi-quote):
--input-mint <address> — Required. Input token mint address
--output-mint <address> — Required. Output token mint address
--amount <amount> — Required. Swap amount
--user-public-key <key> — Required. User's Solana public key
--slippage-bps <bps> — Slippage tolerance in basis points
Kalshi submit (lfi predict kalshi-submit):
--signed-transaction <tx> — Required. Signed transaction data
--order-context <json> — Required. Order context as JSON string (contains user_public_key, market_slug, side, outcome, mints, amount, price, slippage_bps)
Polymarket order (lfi predict polymarket-order):
--body <json> — Required. Raw order JSON string
--poly-api-key <key> — Required. Polymarket API key
--poly-address <address> — Required. Polymarket address
--poly-signature <sig> — Required. Polymarket HMAC signature
--poly-passphrase <pass> — Required. Polymarket passphrase
--poly-timestamp <ts> — Required. Polymarket timestamp
Operation Flow
Browse Prediction Events
- Fetch events:
lfi predict events --with-markets true --limit 20 --json
- Present results: Show event title, status, number of markets, volume
- Suggest next step: "Want to see details for a specific event?" / "需要查看某个事件的详情?"
Browse Events by Source
- Determine source: Ask user for
kalshi or polymarket
- Fetch:
lfi predict events --source kalshi --with-markets true --limit 20 --json
- Present: Events filtered by provider
- Suggest next step: "Pick an event to view its markets and outcomes"
View Event Details
- Determine slug: From user selection or input
- Fetch event:
lfi predict event <slug> --source <source> --json
- Present: Event title, description, status, resolution sources, markets with outcomes and prices
- Suggest next step: "Want to check your balance or place an order?"
Check USDC Balance
If the user says "我的余额", "my balance", "我在 Polymarket/Kalshi 有多少钱"
or any first-person variant — DO NOT ask for a wallet address. Use the
"My ..." auto-flow below.
Generic flow (when the user explicitly provides someone else's address):
- Collect inputs: Source (kalshi/polymarket) and wallet address
- Fetch:
lfi predict balance --source <source> --user <address> --json
- Present: Available USDC balance
- Suggest next step: "Ready to place a prediction?" / "准备下注了吗?"
Kalshi Order Flow (Quote → Sign → Submit)
- Browse events:
lfi predict events --source kalshi --with-markets true --json
- View event:
lfi predict event <slug> --source kalshi --json — identify market, outcomes, and mints
- Check balance:
lfi predict balance --source kalshi --user <publicKey> --json
- Get quote:
lfi predict kalshi-quote --input-mint <inMint> --output-mint <outMint> --amount <amt> --user-public-key <key> --json
- Present quote: Show expected output amount, price, slippage
- (mandatory) Wait for explicit user confirmation
- User signs the transaction (externally, e.g. via wallet)
- Submit:
lfi predict kalshi-submit --signed-transaction <signedTx> --order-context '<contextJson>' --json
- Present result: Show signature, status
Polymarket Order Flow
- Browse events:
lfi predict events --source polymarket --with-markets true --json
- View event:
lfi predict event <slug> --source polymarket --json
- Check balance:
lfi predict balance --source polymarket --user <address> --json
- Prepare order body: Construct the Polymarket order JSON
- (mandatory) Show order summary and wait for explicit user confirmation
- Create order:
lfi predict polymarket-order --body '<orderJson>' --poly-api-key <key> --poly-address <addr> --poly-signature <sig> --poly-passphrase <pass> --poly-timestamp <ts> --json
- Present result: Show order response
View Positions
If the user says "我的持仓", "我现在押了哪些", "my positions", "我赌了什么"
or any first-person variant — DO NOT ask for a wallet address. Use the
"My ..." auto-flow below.
Generic flow (when the user explicitly provides someone else's address):
- Determine user: Get wallet address from user
- Fetch:
lfi predict positions --user <address> --json
- Present: Show event/market, outcome, size, entry price, current value
- Suggest next step: "Want to see your trade history?" / "需要查看交易历史?"
View Trade History
If the user says "我的交易", "我赚了多少", "我亏了多少", "my trades",
"我的盈亏" or any first-person variant — DO NOT ask for a wallet address.
Use the "My ..." auto-flow below.
Generic flow (when the user explicitly provides someone else's address):
- Determine wallet: Get wallet address from user
- Fetch:
lfi predict trades --wallet <address> --limit 20 --json
- Present: Show trade timestamp, event/market, side, price, size
- Suggest next step: "Want to check your current positions?" / "需要查看当前持仓?"
"My ..." auto-flow (CRITICAL — covers "我的", "my", "我自己")
Whenever the user asks about THEIR OWN prediction-market data — positions,
trades, balance, PnL, "我现在押了哪些", "我在预测市场赚了多少",
"我在 Polymarket 上的钱", etc. — run this exact sequence. NEVER ask the
user to type their wallet address.
- Check session:
lfi status --json
- If not authenticated (or
expired: true):
lfi login key --role AGENT --name "OpenClawAgent" --json
- Fetch TEE wallet addresses:
lfi whoami --json
→ returns evmAddress (use for Polymarket) and solAddress (use for Kalshi).
- Determine source(s):
- If the user named "Polymarket" → use
evmAddress only.
- If the user named "Kalshi" → use
solAddress only.
- If neither was named (e.g. "我在预测市场赚了多少") → query BOTH and merge.
- Run the matching query for each source — pass the TEE EOA / SOL pubkey
from step 3 DIRECTLY. NEVER convert to a Safe address first; the server
does that internally for Polymarket.
- Positions:
lfi predict positions --user <evmAddress|solAddress> [--source <s>] --json
- Trades:
lfi predict trades --wallet <evmAddress|solAddress> [--source <s>] --limit 50 --json
- Balance:
lfi predict balance --source <s> --user <evmAddress|solAddress> --json
- Present a single consolidated answer that names the source(s) used and,
for the "我赚了多少" / PnL question, sums realized + unrealized PnL across
the returned trades/positions.
Why this is mandatory: prediction queries always require an address parameter
in the CLI, but a normal user does NOT know their TEE wallet address — the
LiberFi server holds it. The skill must resolve "我" → TEE wallet via
whoami, transparently. The user should never have to type or even see the
hex/Base58 address unless they ask.
EOA vs Safe — critical distinction for Polymarket: The address from
whoami.evmAddress is the user's TEE EOA. For balance / positions /
trades queries, ALWAYS pass the EOA — the prediction-server derives the
Polymarket Safe via CREATE2 internally. The Safe address (returned by
polymarket-setup-status) is ONLY for polymarket-deposit-addresses --safe-address (Polymarket Bridge requires the actual Safe as bridge key).
Mixing these up → balance / positions / trades return EMPTY because the
server tries to derive a Safe from an already-Safe address.
Check Order Status
- List orders:
lfi predict orders --source <source> --wallet-address <address> --json
- Or get specific order:
lfi predict order <id> --source <source> --json
- Present: Show order status, side, price, filled amount
Cross-Skill Workflows
"Research an event and place a bet"
Full flow: predict → predict → predict → predict → predict
- predict →
lfi predict events --search "bitcoin" --with-markets true --json
- predict →
lfi predict event <slug> --source kalshi --json — view markets and outcomes
- predict →
lfi predict balance --source kalshi --user <publicKey> --json — check funds
- predict →
lfi predict kalshi-quote --input-mint <in> --output-mint <out> --amount <amt> --user-public-key <key> --json — get quote
- Present quote, wait for confirmation, user signs transaction
- predict →
lfi predict kalshi-submit --signed-transaction <tx> --order-context '<ctx>' --json
"Check my prediction portfolio and trade history"
Full flow: predict → predict
- predict →
lfi predict positions --user <address> --json — current positions
- predict →
lfi predict trades --wallet <address> --limit 50 --json — trade history
- Present consolidated portfolio view
"Browse events, then research the underlying token"
Full flow: predict → token → token
- predict →
lfi predict events --with-markets true --limit 10 --json
- User selects an event related to a specific token
- token →
lfi token info sol <tokenAddress> --json — token details
- token →
lfi token security sol <tokenAddress> --json — security audit
Suggest Next Steps
| Just completed |
Suggest to user |
| Events list |
"Want to view a specific event?" / "需要查看某个事件的详情?" |
| Event detail |
"Want to check your balance or place an order?" / "需要查看余额或下单?" |
| Balance check |
"Ready to place a prediction?" / "准备下注了吗?" |
| Kalshi quote |
"Want to proceed with this trade?" / "要继续这笔交易吗?" |
| Kalshi submit |
"Order submitted! Check your positions to verify." / "订单已提交!查看持仓确认。" |
| Polymarket order |
"Order created! Check order status to confirm." / "订单已创建!查看订单状态确认。" |
| Positions view |
"Want to see trade history?" / "需要查看交易历史?" |
| Trade history |
"Want to check current positions?" / "需要查看当前持仓?" |
| Orders list |
"Want to see details for a specific order?" / "需要查看某个订单的详情?" |
Edge Cases
- Invalid source: If the API returns an error about source, list valid sources (
kalshi, polymarket) and ask the user to choose
- No events found: Inform user: "No prediction events found matching your criteria. Try different filters or search terms."
- Empty positions: Inform user: "No open positions found for this wallet. You can browse events to find prediction opportunities."
- Insufficient balance: If balance is too low for a trade, inform the user and suggest depositing funds
- Invalid slug: If event not found, suggest searching events first via
lfi predict events --search <keyword>
- Polymarket auth missing: If POLY_* flags are missing for Polymarket operations, list all required flags and ask the user to provide them
- Invalid JSON in --body or --order-context: If JSON parsing fails, show the parse error and ask the user to correct the JSON
- Quote expired: Kalshi quotes have limited validity; if too much time passes, get a new quote
- Network timeout: Retry once after 3 seconds; if still fails, suggest checking connectivity via
lfi ping --json
Common Pitfalls
| Pitfall |
Correct Approach |
Forgetting --source on event detail |
Always specify --source kalshi or --source polymarket |
| Missing POLY_* flags for Polymarket |
All five --poly-* flags are required for Polymarket orders and order queries |
| Modifying the quote response before submitting |
Pass quote data through as-is in --order-context |
| Submitting without user confirmation |
ALWAYS show order/quote summary and wait for explicit "yes" |
| Fabricating a signed transaction |
The --signed-transaction must come from the user's actual wallet signing |
| Using wrong mint addresses |
Verify mints from the event detail response before quoting |
Security Notes
See security-policy.md for global security rules.
Skill-specific rules:
- Polymarket CLOB credentials are sensitive — never log, display, or store POLY_* values beyond the immediate command execution
- Kalshi transactions involve real funds — never fabricate or guess signed transaction data
- NEVER place orders without explicit user confirmation — always show the order summary first
- The
--order-context and --body fields are opaque — pass them through as-is; do not interpret, modify, or display raw content beyond summarizing key fields (amount, side, market)
- After order submission, provide the result so the user can independently verify
1---2name: liberfi-predict3description: Browse and trade prediction markets: list events with filtering and search, view event details and embedded markets, check USDC balances on Kalshi and Polymarket, view portfolio positions and trade history, list and inspect orders, request Kalshi quotes, submit signed Kalshi transactions, and create Polymarket orders. Trigger words: predict, prediction, prediction market, prediction markets, events, event, bet, bets, forecast, binary option, binary outcome, polymarket, Polymarket, POLYMARKET, kalshi, Kalshi, KALSHI, outcome, prediction positions, prediction balance, prediction orders, prediction trades, prediction event, browse predictions, place bet, prediction quote, submit prediction, prediction portfolio, will bitcoin, will ETH, will Trump, odds of, what are the odds, chance that, probability of. Chinese: 预测, 预测市场, 事件, 投注, 下注, 预测仓位, 预测余额, 预测订单, 预测交易, 预测事件, 浏览预测, 预测报价, 提交预测, 预测持仓, Polymarket, Kalshi, Polymarket 上, Kalshi 上, Polymarket 预测, Kalshi 预测, Polymarket 事件, Kalshi 事件, 比特币预测, BTC 预测, ETH 预测, 大选预测, 押注4---56# LiberFi Prediction Market78Browse prediction market events, manage positions, and place orders on Kalshi and Polymarket using the LiberFi CLI.910## Pre-flight Checks1112See [bootstrap.md](../shared/bootstrap.md) for CLI installation and connectivity verification.1314This skill's auth requirements:1516| Command | Requires Auth |17|---------|--------------|18| `lfi predict events` | No |19| `lfi predict event <slug>` | No |20| `lfi predict balance` | No |21| `lfi predict positions` | No |22| `lfi predict trades` | No |23| `lfi predict orders` | No (Polymarket needs POLY_* headers) |24| `lfi predict order <id>` | No (Polymarket needs POLY_* headers) |25| `lfi predict polymarket-tick-size` | No |26| `lfi predict polymarket-fee-rate` | No |27| `lfi predict polymarket-setup-status` | No (uses TEE wallet if logged in) |28| `lfi predict polymarket-deposit-addresses` | No |29| `lfi predict polymarket-setup` | **Yes** (LiberFi JWT) |30| `lfi predict polymarket-place` | **Yes** (LiberFi JWT — server signs via TEE) |31| `lfi predict kalshi-place` | **Yes** (LiberFi JWT — server signs via TEE) |32| `lfi predict cancel` | **Yes** (LiberFi JWT — auto L2 auth for polymarket) |33| `lfi predict kalshi-quote` (DEPRECATED) | No |34| `lfi predict kalshi-submit` (DEPRECATED) | No |35| `lfi predict polymarket-order` (DEPRECATED) | No (requires POLY_* headers) |3637**Recommended flow (TEE auto)**: `polymarket-setup` → `polymarket-place` /38`kalshi-place` / `cancel`. The server holds the user's TEE wallet via Privy39and signs every transaction internally — no POLY_* HMAC, no Solana signing,40no EIP-712 work for the caller.4142**Legacy flow**: Polymarket order operations via `polymarket-order` require43CLOB HMAC authentication via five `--poly-*` flags. These are NOT LiberFi44JWT credentials — they are the user's own Polymarket CLOB API credentials.4546## TEE Auto Order Flow (CRITICAL)4748For the canonical end-to-end order placement flow — including pre-flight49status checks, deposit handling, market vs limit order branching, and post-50order verification — see [reference/order-flow.md](reference/order-flow.md).5152The CLI/skill expects this exact ordering for Polymarket:53541. `lfi status` — confirm authenticated; if not, run `lfi login key`552. `lfi predict polymarket-setup-status --json` — check Safe deployment +56 token approvals573. If `safe_deployed=false` or any approval missing: `lfi predict58 polymarket-setup --json` (one-shot; gasless via Builder Relayer)594. Check Safe USDC balance — **pass the TEE EOA, NOT the Safe**:60 `lfi predict balance --source polymarket --user <tee-eoa> --json`61 (server derives Safe from EOA internally). If `balance < 2`, fetch62 BRIDGE deposit addresses using the **Safe** address from step 2/3:63 `lfi predict polymarket-deposit-addresses --safe-address <safe> --json`64 → returns `{ evm, svm, btc, tron }`. Pick the field matching the user's65 chain (default `evm` for ETH/Polygon/Base/Arb/Op/BNB). Tell user to send66 ≥ $2 USDC to that bridge address (NEVER to the Safe address — the Safe67 is Polymarket's internal custody contract, not a user-facing deposit68 target). The Polymarket Bridge service auto-credits the Safe.695. Ask the user: market or limit? For limit, also ask price + size + GTC70 vs GTD (with expiration if GTD). For market, ask USDC spend (BUY) or71 share count (SELL)726. Show the final order summary, wait for explicit confirmation737. `lfi predict polymarket-place --token-id <id> --side <s> --order-type74 <t> [--price <p>] [--size <sz>] [--expiration <epoch>] --json`758. `lfi predict orders --source polymarket --json` — verify open orders769. `lfi predict cancel <id> --source polymarket --json` — cancel if user77 asks7879For Kalshi the flow is shorter: `lfi predict kalshi-place --input-mint80<inMint> --output-mint <outMint> --amount <amt> --json` — quote, sign81(SignSOL), and submit are all done server-side.8283## Skill Routing8485| If user asks about... | Route to |86|-----------------------|----------|87| Token search, price, details, security | liberfi-token |88| Token K-line, candlestick chart | liberfi-token |89| Trending tokens, market rankings | liberfi-market |90| Newly listed tokens | liberfi-market |91| Wallet holdings, balance (non-prediction), PnL | liberfi-portfolio |92| Wallet activity, transaction history | liberfi-portfolio |93| Token swap, trade execution | liberfi-swap |94| Login, logout, session management | liberfi-auth |9596## CLI Command Index9798### Query Commands (read-only)99100| Command | Description | Auth |101|---------|-------------|------|102| `lfi predict events` | List prediction events with filtering | No |103| `lfi predict event <slug> --source <s>` | Get event details by slug | No |104| `lfi predict balance --source <s> --user <addr>` | Get USDC balance | No |105| `lfi predict positions --user <addr>` | Get portfolio positions | No |106| `lfi predict trades --wallet <addr>` | List trade history | No |107| `lfi predict orders` | List orders | No (POLY_* for Polymarket) |108| `lfi predict order <id> --source <s>` | Get order details | No (POLY_* for Polymarket) |109110### TEE Auto Flow Commands (recommended)111112| Command | Description | Auth |113|---------|-------------|------|114| `lfi predict polymarket-tick-size --token-id <id>` | Min tick size for a token | No |115| `lfi predict polymarket-fee-rate --token-id <id>` | Base fee rate (bps) | No |116| `lfi predict polymarket-setup-status [--wallet-address <addr>]` | Safe deployment + approval status | No (uses TEE wallet if logged in) |117| `lfi predict polymarket-setup` | Deploy Safe + approve all tokens (gasless) | **JWT** |118| `lfi predict polymarket-deposit-addresses --safe-address <addr>` | Multi-chain deposit addresses for Safe | No |119| `lfi predict polymarket-place --token-id <id> --side BUY\|SELL --order-type GTC\|GTD\|FOK\|FAK\|MARKET [--price <p>] [--size <sz>] [--expiration <epoch>] [...]` | Prepare → TEE sign → execute Polymarket order | **JWT** |120| `lfi predict kalshi-place --input-mint <m> --output-mint <m> --amount <a> [--slippage-bps <bps>]` | Quote → SignSOL → submit Kalshi order | **JWT** |121| `lfi predict cancel <id> --source polymarket\|kalshi` | Cancel order (auto L2 auth for poly) | **JWT** |122123### Legacy / Deprecated Commands124125| Command | Description | Auth |126|---------|-------------|------|127| `lfi predict kalshi-quote --input-mint <m> --output-mint <m> --amount <a> --user-public-key <k>` | **DEPRECATED** — use `kalshi-place`. Request Kalshi quote | No |128| `lfi predict kalshi-submit --signed-transaction <tx> --order-context '<json>'` | **DEPRECATED** — use `kalshi-place`. Submit pre-signed Kalshi tx | No |129| `lfi predict polymarket-order --body '<json>' --poly-api-key <k> --poly-address <a> --poly-signature <s> --poly-passphrase <p> --poly-timestamp <t>` | **DEPRECATED** — use `polymarket-place`. Create Polymarket order with caller-managed POLY_* headers | POLY_* headers |130131### Parameter Reference132133**Events list** (`lfi predict events`):134- `--limit <n>` — Max results per page135- `--cursor <cursor>` — Pagination cursor136- `--status <status>` — Event status filter (e.g. `active`, `resolved`)137- `--source <source>` — Provider source: `kalshi` or `polymarket`138- `--tag-slug <slug>` — Filter by tag139- `--search <query>` — Free-text search140- `--sort-by <field>` — Sort field141- `--sort-asc <bool>` — Sort ascending: `true` or `false`142- `--with-markets <bool>` — Include embedded markets: `true` or `false`143144**Event detail** (`lfi predict event <slug>`):145- `<slug>` — **Required**. Event slug identifier146- `--source <source>` — **Required**. Provider source: `kalshi` or `polymarket`147148**Balance** (`lfi predict balance`):149- `--source <source>` — **Required**. Provider source: `kalshi` or `polymarket`150- `--user <address>` — **Required**. For `polymarket`: pass the user's **TEE EOA** (e.g. `evmAddress` from `lfi whoami`); the server auto-derives the Safe via CREATE2. NEVER pass a Safe address here. For `kalshi`: pass the Solana public key (`solAddress`).151152**Positions** (`lfi predict positions`):153- `--user <address>` — **Required**. Same rule as `balance`: TEE EOA for polymarket (server derives Safe), Solana public key for kalshi.154- `--source <source>` — Optional provider source filter155156**Trades** (`lfi predict trades`):157- `--wallet <address>` — **Required**. Same rule as `balance`: TEE EOA for polymarket (server derives Safe), Solana public key for kalshi.158- `--source <source>` — Optional provider source filter159- `--limit <n>` — Max results per page160- `--cursor <cursor>` — Pagination cursor161- `--type <types>` — Comma-separated trade types162- `--side <side>` — Trade side filter163164**Orders** (`lfi predict orders`):165- `--source <source>` — Provider source166- `--wallet-address <address>` — Wallet address (required for kalshi)167- `--market-id <id>` — Market ID filter168- `--asset-id <id>` — Asset ID filter169- `--next-cursor <cursor>` — Pagination cursor170- `--poly-api-key`, `--poly-address`, `--poly-signature`, `--poly-passphrase`, `--poly-timestamp` — Polymarket CLOB auth (required when source is polymarket)171172**Order detail** (`lfi predict order <id>`):173- `<id>` — **Required**. Order ID174- `--source <source>` — **Required**. Provider source175- Same `--poly-*` flags as orders list176177**Polymarket tick size** (`lfi predict polymarket-tick-size`):178- `--token-id <id>` — **Required**. Polymarket CLOB token ID179180**Polymarket fee rate** (`lfi predict polymarket-fee-rate`):181- `--token-id <id>` — **Required**. Polymarket CLOB token ID182183**Polymarket setup status** (`lfi predict polymarket-setup-status`):184- `--wallet-address <addr>` — Optional EVM address. Defaults to caller's TEE wallet when authenticated.185186**Polymarket setup (run)** (`lfi predict polymarket-setup`):187- No flags. Requires authentication. Idempotent — safe to call repeatedly.188189**Polymarket deposit addresses** (`lfi predict polymarket-deposit-addresses`):190- `--safe-address <addr>` — **Required**. Safe wallet address (from `polymarket-setup-status`)191192**Polymarket place (TEE auto)** (`lfi predict polymarket-place`):193- `--token-id <id>` — **Required**. Polymarket CLOB token ID194- `--side BUY|SELL` — **Required**.195- `--order-type GTC|GTD|FOK|FAK|MARKET` — **Required**.196- `--price <p>` — Limit price (limit orders only, e.g. `0.55`). Required for GTC/GTD/FOK/FAK.197- `--size <sz>` — Limit: shares; market BUY: USDC; market SELL: shares. Required for limit and market.198- `--expiration <epochSec>` — Required for `GTD`.199- `--neg-risk true|false` — Force NegRisk exchange. Auto-detected when omitted.200- `--fee-rate-bps <n>` — Override fee rate (PS auto-resolves when omitted).201- `--tick-size <n>` — Override tick size (PS auto-resolves when omitted).202- `--taker-address <addr>` — Restrict the taker (advanced).203204**Kalshi place (TEE auto)** (`lfi predict kalshi-place`):205- `--input-mint <addr>` — **Required**. Input token mint206- `--output-mint <addr>` — **Required**. Output token mint207- `--amount <amt>` — **Required**. Amount in smallest unit208- `--slippage-bps <bps>` — Slippage tolerance in basis points209210**Cancel order** (`lfi predict cancel <id>`):211- `<id>` — **Required**. Order ID212- `--source polymarket|kalshi` — **Required**. For polymarket the L2 HMAC headers are derived from the caller's TEE wallet automatically.213214**Kalshi quote** (`lfi predict kalshi-quote`):215- `--input-mint <address>` — **Required**. Input token mint address216- `--output-mint <address>` — **Required**. Output token mint address217- `--amount <amount>` — **Required**. Swap amount218- `--user-public-key <key>` — **Required**. User's Solana public key219- `--slippage-bps <bps>` — Slippage tolerance in basis points220221**Kalshi submit** (`lfi predict kalshi-submit`):222- `--signed-transaction <tx>` — **Required**. Signed transaction data223- `--order-context <json>` — **Required**. Order context as JSON string (contains `user_public_key`, `market_slug`, `side`, `outcome`, mints, `amount`, `price`, `slippage_bps`)224225**Polymarket order** (`lfi predict polymarket-order`):226- `--body <json>` — **Required**. Raw order JSON string227- `--poly-api-key <key>` — **Required**. Polymarket API key228- `--poly-address <address>` — **Required**. Polymarket address229- `--poly-signature <sig>` — **Required**. Polymarket HMAC signature230- `--poly-passphrase <pass>` — **Required**. Polymarket passphrase231- `--poly-timestamp <ts>` — **Required**. Polymarket timestamp232233## Operation Flow234235### Browse Prediction Events2362371. **Fetch events**: `lfi predict events --with-markets true --limit 20 --json`2382. **Present results**: Show event title, status, number of markets, volume2393. **Suggest next step**: "Want to see details for a specific event?" / "需要查看某个事件的详情?"240241### Browse Events by Source2422431. **Determine source**: Ask user for `kalshi` or `polymarket`2442. **Fetch**: `lfi predict events --source kalshi --with-markets true --limit 20 --json`2453. **Present**: Events filtered by provider2464. **Suggest next step**: "Pick an event to view its markets and outcomes"247248### View Event Details2492501. **Determine slug**: From user selection or input2512. **Fetch event**: `lfi predict event <slug> --source <source> --json`2523. **Present**: Event title, description, status, resolution sources, markets with outcomes and prices2534. **Suggest next step**: "Want to check your balance or place an order?"254255### Check USDC Balance256257**If the user says "我的余额", "my balance", "我在 Polymarket/Kalshi 有多少钱"258or any first-person variant — DO NOT ask for a wallet address. Use the259"My ..." auto-flow below.**260261Generic flow (when the user explicitly provides someone else's address):2622631. **Collect inputs**: Source (kalshi/polymarket) and wallet address2642. **Fetch**: `lfi predict balance --source <source> --user <address> --json`2653. **Present**: Available USDC balance2664. **Suggest next step**: "Ready to place a prediction?" / "准备下注了吗?"267268### Kalshi Order Flow (Quote → Sign → Submit)2692701. **Browse events**: `lfi predict events --source kalshi --with-markets true --json`2712. **View event**: `lfi predict event <slug> --source kalshi --json` — identify market, outcomes, and mints2723. **Check balance**: `lfi predict balance --source kalshi --user <publicKey> --json`2734. **Get quote**: `lfi predict kalshi-quote --input-mint <inMint> --output-mint <outMint> --amount <amt> --user-public-key <key> --json`2745. **Present quote**: Show expected output amount, price, slippage2756. **(mandatory)** Wait for explicit user confirmation2767. **User signs the transaction** (externally, e.g. via wallet)2778. **Submit**: `lfi predict kalshi-submit --signed-transaction <signedTx> --order-context '<contextJson>' --json`2789. **Present result**: Show signature, status279280### Polymarket Order Flow2812821. **Browse events**: `lfi predict events --source polymarket --with-markets true --json`2832. **View event**: `lfi predict event <slug> --source polymarket --json`2843. **Check balance**: `lfi predict balance --source polymarket --user <address> --json`2854. **Prepare order body**: Construct the Polymarket order JSON2865. **(mandatory)** Show order summary and wait for explicit user confirmation2876. **Create order**: `lfi predict polymarket-order --body '<orderJson>' --poly-api-key <key> --poly-address <addr> --poly-signature <sig> --poly-passphrase <pass> --poly-timestamp <ts> --json`2887. **Present result**: Show order response289290### View Positions291292**If the user says "我的持仓", "我现在押了哪些", "my positions", "我赌了什么"293or any first-person variant — DO NOT ask for a wallet address. Use the294"My ..." auto-flow below.**295296Generic flow (when the user explicitly provides someone else's address):2972981. **Determine user**: Get wallet address from user2992. **Fetch**: `lfi predict positions --user <address> --json`3003. **Present**: Show event/market, outcome, size, entry price, current value3014. **Suggest next step**: "Want to see your trade history?" / "需要查看交易历史?"302303### View Trade History304305**If the user says "我的交易", "我赚了多少", "我亏了多少", "my trades",306"我的盈亏" or any first-person variant — DO NOT ask for a wallet address.307Use the "My ..." auto-flow below.**308309Generic flow (when the user explicitly provides someone else's address):3103111. **Determine wallet**: Get wallet address from user3122. **Fetch**: `lfi predict trades --wallet <address> --limit 20 --json`3133. **Present**: Show trade timestamp, event/market, side, price, size3144. **Suggest next step**: "Want to check your current positions?" / "需要查看当前持仓?"315316### "My ..." auto-flow (CRITICAL — covers "我的", "my", "我自己")317318Whenever the user asks about THEIR OWN prediction-market data — positions,319trades, balance, PnL, "我现在押了哪些", "我在预测市场赚了多少",320"我在 Polymarket 上的钱", etc. — run this exact sequence. NEVER ask the321user to type their wallet address.3223231. **Check session**: `lfi status --json`3242. **If not authenticated** (or `expired: true`):325 `lfi login key --role AGENT --name "OpenClawAgent" --json`3263. **Fetch TEE wallet addresses**: `lfi whoami --json`327 → returns `evmAddress` (use for Polymarket) and `solAddress` (use for Kalshi).3284. **Determine source(s)**:329 - If the user named "Polymarket" → use `evmAddress` only.330 - If the user named "Kalshi" → use `solAddress` only.331 - If neither was named (e.g. "我在预测市场赚了多少") → query BOTH and merge.3325. **Run the matching query** for each source — pass the TEE EOA / SOL pubkey333 from step 3 DIRECTLY. NEVER convert to a Safe address first; the server334 does that internally for Polymarket.335 - Positions: `lfi predict positions --user <evmAddress|solAddress> [--source <s>] --json`336 - Trades: `lfi predict trades --wallet <evmAddress|solAddress> [--source <s>] --limit 50 --json`337 - Balance: `lfi predict balance --source <s> --user <evmAddress|solAddress> --json`3386. **Present** a single consolidated answer that names the source(s) used and,339 for the "我赚了多少" / PnL question, sums realized + unrealized PnL across340 the returned trades/positions.341342Why this is mandatory: prediction queries always require an address parameter343in the CLI, but a normal user does NOT know their TEE wallet address — the344LiberFi server holds it. The skill must resolve "我" → TEE wallet via345`whoami`, transparently. The user should never have to type or even see the346hex/Base58 address unless they ask.347348**EOA vs Safe — critical distinction for Polymarket**: The address from349`whoami.evmAddress` is the user's TEE EOA. For `balance` / `positions` /350`trades` queries, ALWAYS pass the EOA — the prediction-server derives the351Polymarket Safe via CREATE2 internally. The Safe address (returned by352`polymarket-setup-status`) is ONLY for `polymarket-deposit-addresses353--safe-address` (Polymarket Bridge requires the actual Safe as bridge key).354Mixing these up → balance / positions / trades return EMPTY because the355server tries to derive a Safe from an already-Safe address.356357### Check Order Status3583591. **List orders**: `lfi predict orders --source <source> --wallet-address <address> --json`3602. **Or get specific order**: `lfi predict order <id> --source <source> --json`3613. **Present**: Show order status, side, price, filled amount362363## Cross-Skill Workflows364365### "Research an event and place a bet"366367> Full flow: predict → predict → predict → predict → predict3683691. **predict** → `lfi predict events --search "bitcoin" --with-markets true --json`3702. **predict** → `lfi predict event <slug> --source kalshi --json` — view markets and outcomes3713. **predict** → `lfi predict balance --source kalshi --user <publicKey> --json` — check funds3724. **predict** → `lfi predict kalshi-quote --input-mint <in> --output-mint <out> --amount <amt> --user-public-key <key> --json` — get quote3735. Present quote, wait for confirmation, user signs transaction3746. **predict** → `lfi predict kalshi-submit --signed-transaction <tx> --order-context '<ctx>' --json`375376### "Check my prediction portfolio and trade history"377378> Full flow: predict → predict3793801. **predict** → `lfi predict positions --user <address> --json` — current positions3812. **predict** → `lfi predict trades --wallet <address> --limit 50 --json` — trade history3823. Present consolidated portfolio view383384### "Browse events, then research the underlying token"385386> Full flow: predict → token → token3873881. **predict** → `lfi predict events --with-markets true --limit 10 --json`3892. User selects an event related to a specific token3903. **token** → `lfi token info sol <tokenAddress> --json` — token details3914. **token** → `lfi token security sol <tokenAddress> --json` — security audit392393## Suggest Next Steps394395| Just completed | Suggest to user |396|----------------|-----------------|397| Events list | "Want to view a specific event?" / "需要查看某个事件的详情?" |398| Event detail | "Want to check your balance or place an order?" / "需要查看余额或下单?" |399| Balance check | "Ready to place a prediction?" / "准备下注了吗?" |400| Kalshi quote | "Want to proceed with this trade?" / "要继续这笔交易吗?" |401| Kalshi submit | "Order submitted! Check your positions to verify." / "订单已提交!查看持仓确认。" |402| Polymarket order | "Order created! Check order status to confirm." / "订单已创建!查看订单状态确认。" |403| Positions view | "Want to see trade history?" / "需要查看交易历史?" |404| Trade history | "Want to check current positions?" / "需要查看当前持仓?" |405| Orders list | "Want to see details for a specific order?" / "需要查看某个订单的详情?" |406407## Edge Cases408409- **Invalid source**: If the API returns an error about source, list valid sources (`kalshi`, `polymarket`) and ask the user to choose410- **No events found**: Inform user: "No prediction events found matching your criteria. Try different filters or search terms."411- **Empty positions**: Inform user: "No open positions found for this wallet. You can browse events to find prediction opportunities."412- **Insufficient balance**: If balance is too low for a trade, inform the user and suggest depositing funds413- **Invalid slug**: If event not found, suggest searching events first via `lfi predict events --search <keyword>`414- **Polymarket auth missing**: If POLY_* flags are missing for Polymarket operations, list all required flags and ask the user to provide them415- **Invalid JSON in --body or --order-context**: If JSON parsing fails, show the parse error and ask the user to correct the JSON416- **Quote expired**: Kalshi quotes have limited validity; if too much time passes, get a new quote417- **Network timeout**: Retry once after 3 seconds; if still fails, suggest checking connectivity via `lfi ping --json`418419## Common Pitfalls420421| Pitfall | Correct Approach |422|---------|-----------------|423| Forgetting `--source` on event detail | Always specify `--source kalshi` or `--source polymarket` |424| Missing POLY_* flags for Polymarket | All five `--poly-*` flags are required for Polymarket orders and order queries |425| Modifying the quote response before submitting | Pass quote data through as-is in `--order-context` |426| Submitting without user confirmation | ALWAYS show order/quote summary and wait for explicit "yes" |427| Fabricating a signed transaction | The `--signed-transaction` must come from the user's actual wallet signing |428| Using wrong mint addresses | Verify mints from the event detail response before quoting |429430## Security Notes431432See [security-policy.md](../shared/security-policy.md) for global security rules.433434Skill-specific rules:435- **Polymarket CLOB credentials are sensitive** — never log, display, or store POLY_* values beyond the immediate command execution436- **Kalshi transactions involve real funds** — never fabricate or guess signed transaction data437- NEVER place orders without explicit user confirmation — always show the order summary first438- The `--order-context` and `--body` fields are opaque — pass them through as-is; do not interpret, modify, or display raw content beyond summarizing key fields (amount, side, market)439- After order submission, provide the result so the user can independently verify