Skip to content

feat: add FlipCoin action provider for prediction markets on Base#1147

Open
MrTalecky wants to merge 2 commits intocoinbase:mainfrom
MrTalecky:feat/flipcoin-action-provider
Open

feat: add FlipCoin action provider for prediction markets on Base#1147
MrTalecky wants to merge 2 commits intocoinbase:mainfrom
MrTalecky:feat/flipcoin-action-provider

Conversation

@MrTalecky
Copy link
Copy Markdown

Summary

Adds a new @coinbase/agentkit action provider for FlipCoin — a LMSR-based prediction-market protocol on Base (mainnet + Sepolia). This is the first prediction-market provider in AgentKit.

FlipCoin agents can now:

  • get_prediction_markets — list tradable markets with YES/NO prices, volume and deadlines.
  • get_market_odds — fetch a firm quote: priceYesBps, priceNoBps, sharesOut, priceImpact, avgPriceBps (quote is valid ~12s).
  • buy_prediction_shares — buy YES/NO shares with USDC from the agent's vault.
  • sell_prediction_shares — sell YES/NO shares back into the LMSR pool.
  • get_agent_portfolio — read the agent's open/resolved positions with net side, entry price and unrealized P&L.

Trades use FlipCoin's two-phase intent → sign → relay pattern:

  1. The provider POSTs to /api/agent/trade/intent to get an EIP-712 TradeIntent typed-data payload + a firm quote.
  2. The supplied EvmWalletProvider.signTypedData() signs it (so any AgentKit-compatible wallet works: CDP, Viem, Privy, ZeroDev, etc.).
  3. The signature is POSTed to /api/agent/trade/relay; FlipCoin's relayer covers gas and broadcasts on-chain.

The provider also surfaces structured errors for: price-impact guard blocking the trade (priceImpactGuard.level === "blocked"), missing ShareToken.setApprovalForAll(router, true) approval (pre-flight, before signing), and retryable RPC failures during relay.

Why this matters

Prediction markets are a natural fit for autonomous agents — they expose probabilistic claims about future events with pricing that reflects crowd wisdom. Until now there was no prediction-market provider in AgentKit. FlipCoin is fully open (contracts + Python/TS SDKs) and exposes a dedicated Agent API with API keys, EIP-712 trade intents, on-chain delegation for autonomous signing, and webhook streaming — perfect for AgentKit wallet providers.

Files

  • typescript/agentkit/src/action-providers/flipcoin/flipcoinActionProvider.ts — provider + 5 actions
  • typescript/agentkit/src/action-providers/flipcoin/schemas.ts — Zod input schemas
  • typescript/agentkit/src/action-providers/flipcoin/constants.ts — base URL, API version, supported networks
  • typescript/agentkit/src/action-providers/flipcoin/types.ts — FlipCoin API response types
  • typescript/agentkit/src/action-providers/flipcoin/flipcoinActionProvider.test.ts — 19 unit tests
  • typescript/agentkit/src/action-providers/flipcoin/README.md — usage docs
  • typescript/agentkit/src/action-providers/index.ts — registration
  • typescript/.changeset/flipcoin-action-provider.md — changeset

Test plan

  • pnpm run lint (no warnings/errors on flipcoin/)
  • pnpm run build (clean tsc)
  • pnpm test883/883 tests pass (61 suites), 19 new tests for FlipCoin covering:
    • supportsNetwork (Base mainnet/sepolia allow, others reject, non-EVM reject)
    • get_prediction_markets happy path, filters, error path
    • get_market_odds firm quote + default $1 simulation
    • buy_prediction_shares intent→sign→relay happy path
    • buy_prediction_shares approval-required short-circuit (no sign)
    • buy_prediction_shares price-impact guard block (no sign)
    • buy_prediction_shares missing API key error
    • buy_prediction_shares retryable relay errors surfaced
    • sell_prediction_shares sends action: "sell" to intent
    • get_agent_portfolio auth header + shape

Network support

  • Base Mainnet (base-mainnet, chainId 8453)
  • Base Sepolia (base-sepolia, chainId 84532)

Links

A follow-up PR will add an autonomous-bettor example under typescript/examples/ that uses this provider end-to-end.

…n Base

FlipCoin (https://www.flipcoin.fun) is a LMSR-based prediction-market protocol
deployed on Base. This provider gives AgentKit agents 5 actions:

- get_prediction_markets: list tradable markets with prices and volume
- get_market_odds: fetch firm quote (priceYesBps, sharesOut, priceImpact)
- buy_prediction_shares: buy YES/NO shares via EIP-712 intent -> wallet
  signTypedData -> FlipCoin relay, which broadcasts the tx on-chain
- sell_prediction_shares: sell YES/NO shares back into the LMSR pool
- get_agent_portfolio: read agent positions and unrealized P&L

Trades use FlipCoin's two-phase intent/relay pattern: the provider requests
an EIP-712 TradeIntent from /api/agent/trade/intent, signs it with the
supplied EvmWalletProvider, and submits it to /api/agent/trade/relay where
FlipCoin's relayer covers gas and broadcasts the transaction.

Supports Base mainnet and Base Sepolia. Requires a FlipCoin agent API key
(obtained at https://www.flipcoin.fun/app/settings).

19 unit tests covering all actions, error paths, price-impact guard and
approval-required flow.
@MrTalecky MrTalecky requested a review from murrlincoln as a code owner April 23, 2026 20:57
@cb-heimdall
Copy link
Copy Markdown

cb-heimdall commented Apr 23, 2026

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider typescript labels Apr 23, 2026
…h OpenAPI spec

Review against canonical OpenAPI + Agent API docs surfaced three issues that would
break the provider at runtime:

1. Trade intent body used `amount`, but the API requires `usdcAmount` (buy) or
   `sharesAmount` (sell). See openapi TradeIntentRequest schema. Without this fix
   every buy/sell returns 400 `usdcAmount is required for buy` /
   `sharesAmount is required for sell`.

2. `approvalRequired` gate was `approvalRequired && !approvalRequired.approved`,
   but the intent route always returns `approved: true` inside the object (it's
   the target value to pass to setApprovalForAll, not the current state). The
   mere presence of the object means approval is missing. Gate now checks
   presence only.

3. `get_market_odds` for sells must pass `amount` in shares (the quote endpoint
   switches amountType based on action). Schema field renamed from `amountUsdc`
   to a generic `amount` with docs clarifying the per-action interpretation.

Also:
- DEFAULT_MAX_SLIPPAGE_BPS: 200 → 100 (matches FlipCoin's documented default).
- DEFAULT_MAX_FEE_BPS: 300 → 200 (matches FlipCoin's documented default).
- Remove fabricated `minOut` / `maxFeeBps` / per-quote echo fields from
  TradeIntentResponse.quote type — OpenAPI spec only declares sharesOut,
  avgPriceBps, priceImpactBps, fee.
- README: updated `router` to `operator` (provider surfaces it from
  approvalRequired.operator), fixed vault deposit example to use the
  single-endpoint `{action: "intent"|"relay"}` pattern.

Tests updated to assert the new request body shape and approvalRequired
semantics. All 39 provider tests pass; lint + format clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation typescript

Development

Successfully merging this pull request may close these issues.

2 participants