feat(examples): add langchain-flipcoin-chatbot autonomous bettor example#1148
Open
MrTalecky wants to merge 4 commits intocoinbase:mainfrom
Open
feat(examples): add langchain-flipcoin-chatbot autonomous bettor example#1148MrTalecky wants to merge 4 commits intocoinbase:mainfrom
MrTalecky wants to merge 4 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
|
…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>
- LangChain agent wired to AgentKit's FlipCoin action provider. - Chat mode (REPL) and autonomous mode (rotating prompt bank, configurable interval). - ViemWalletProvider on Base mainnet; private key via .env. - System prompt with prediction-market trading heuristics (reject blocked price impact, prefer liquid markets, size positions 0.5-2 USDC). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Correct the preflight instructions to the two-phase single-endpoint
flow (POST /api/agent/vault/deposit with {action: "intent"|"relay"}),
matching the canonical FlipCoin Agent API / OpenAPI spec.
- Reference approvalRequired.operator for the ShareToken approval
address (surfaced by the action provider).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
557cef1 to
0715e05
Compare
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 LangChain example under
typescript/examples/langchain-flipcoin-chatbotthat demonstrates autonomous prediction-market trading on FlipCoin using theflipcoinActionProviderintroduced in #1147.AGENT_INTERVAL_SECONDS.ViemWalletProvideron Base mainnet with a local private key (signs EIP-712TradeIntenttyped data for the hybrid/intent→/relayflow).gpt-4o-minivia@langchain/openai(swap freely).Dependency
This PR depends on #1147 (the FlipCoin action provider). Please merge #1147 first; CI may fail here until the provider is on
main.Test plan
main.cd typescript/examples/langchain-flipcoin-chatbot && cp .env.example .env, fill inOPENAI_API_KEY,PRIVATE_KEY,FLIPCOIN_API_KEY.pnpm install && pnpm start— chat mode, ask"list the 5 hottest markets"and"what are the odds on <conditionId>?".pnpm start autonomous— confirm the agent rotates through prompts and respects price-impact guard.pnpm run lint— passes.Notes
POST /api/agent/vault/deposit/intentand callShareToken.setApprovalForAll(router, true)once per chain.trade,portfolio:read.Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com