feat: add FlipCoin action provider for prediction markets on Base#1147
Open
MrTalecky wants to merge 2 commits intocoinbase:mainfrom
Open
feat: add FlipCoin action provider for prediction markets on Base#1147MrTalecky wants to merge 2 commits intocoinbase:mainfrom
MrTalecky wants to merge 2 commits intocoinbase:mainfrom
Conversation
…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.
🟡 Heimdall Review Status
|
5 tasks
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
@coinbase/agentkitaction 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:
/api/agent/trade/intentto get an EIP-712TradeIntenttyped-data payload + a firm quote.EvmWalletProvider.signTypedData()signs it (so any AgentKit-compatible wallet works: CDP, Viem, Privy, ZeroDev, etc.)./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"), missingShareToken.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 actionstypescript/agentkit/src/action-providers/flipcoin/schemas.ts— Zod input schemastypescript/agentkit/src/action-providers/flipcoin/constants.ts— base URL, API version, supported networkstypescript/agentkit/src/action-providers/flipcoin/types.ts— FlipCoin API response typestypescript/agentkit/src/action-providers/flipcoin/flipcoinActionProvider.test.ts— 19 unit teststypescript/agentkit/src/action-providers/flipcoin/README.md— usage docstypescript/agentkit/src/action-providers/index.ts— registrationtypescript/.changeset/flipcoin-action-provider.md— changesetTest plan
pnpm run lint(no warnings/errors on flipcoin/)pnpm run build(clean tsc)pnpm test→ 883/883 tests pass (61 suites), 19 new tests for FlipCoin covering:supportsNetwork(Base mainnet/sepolia allow, others reject, non-EVM reject)get_prediction_marketshappy path, filters, error pathget_market_oddsfirm quote + default $1 simulationbuy_prediction_sharesintent→sign→relay happy pathbuy_prediction_sharesapproval-required short-circuit (no sign)buy_prediction_sharesprice-impact guard block (no sign)buy_prediction_sharesmissing API key errorbuy_prediction_sharesretryable relay errors surfacedsell_prediction_sharessendsaction: "sell"to intentget_agent_portfolioauth header + shapeNetwork support
base-mainnet, chainId 8453)base-sepolia, chainId 84532)Links
A follow-up PR will add an
autonomous-bettorexample undertypescript/examples/that uses this provider end-to-end.