@blockrun/franklin 3.15.13 → 3.15.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent/context.js
CHANGED
|
@@ -315,6 +315,7 @@ function getToolPatternsSection() {
|
|
|
315
315
|
Your training data is frozen in the past. Live-world questions MUST be answered from tool results, not memory.
|
|
316
316
|
- Any question about a current price, quote, market state, or "should I buy/sell/hold X" → use **TradingMarket** (crypto/FX/commodity are free; stocks cost \$0.001 via the wallet).
|
|
317
317
|
- Any "what happened / why did it change / latest news on X" → use **ExaAnswer** for a cited synthesized answer, or **ExaSearch** + **ExaReadUrls** when you need more depth.
|
|
318
|
+
- Any "what are the odds of X / will Y happen / Polymarket on Z / Kalshi market for W" → use **PredictionMarket** (\$0.001 search; \$0.005 cross-platform / smart money).
|
|
318
319
|
- If the user names a thing you don't recognize (a company, ticker, project), don't demand clarification — call the research tools and figure it out. You have a wallet to spend on exactly this.
|
|
319
320
|
- If a tool returns an error (rate-limit, 404, insufficient funds), say so plainly and suggest the next action. Don't silently fall back to memory.
|
|
320
321
|
|
|
@@ -326,6 +327,13 @@ Your training data is frozen in the past. Live-world questions MUST be answered
|
|
|
326
327
|
|
|
327
328
|
If you find yourself about to emit one of these, stop and call the tool instead. If you don't know which ticker the user means, call ExaSearch or AskUser — never deflect.
|
|
328
329
|
|
|
330
|
+
**Prediction markets (PredictionMarket).** When the user asks about real-world odds — elections, "will X happen by year-end", "Polymarket on Y", "Kalshi market for Z", "what are the odds of recession" — use **PredictionMarket** instead of guessing. Four actions:
|
|
331
|
+
- \`searchPolymarket\` (\$0.001) and \`searchKalshi\` (\$0.001) — search markets by keyword. Run them **in parallel** when the user wants the current odds; comparing implied probability across two venues is the high-value answer.
|
|
332
|
+
- \`crossPlatform\` (\$0.005) — pre-matched pairs of equivalent markets across Polymarket and Kalshi. Use when the user wants arbitrage candidates or wants to know "where does the consensus disagree".
|
|
333
|
+
- \`smartMoney\` (\$0.005) — top-wallet flow on a specific Polymarket \`condition_id\`. Get the \`condition_id\` from a prior \`searchPolymarket\` call.
|
|
334
|
+
|
|
335
|
+
NEVER answer "what are the odds of X" from training-data memory — these are live markets that move every minute. NEVER claim "Polymarket doesn't have a market on this" without running \`searchPolymarket\` first. If both Polymarket and Kalshi return zero markets, say so explicitly with the searches you tried, then offer to broaden the query.
|
|
336
|
+
|
|
329
337
|
**Trading verdicts (TradingSignal).** When the user asks "how does $TICKER look" / "should I buy X" / "is BTC overbought":
|
|
330
338
|
- Run **TradingSignal** with default lookback (90d). Lower values leave MACD undefined.
|
|
331
339
|
- The tool returns a **Verdict** section with \`Direction\`, \`Bull signals\`, \`Bear signals\`. Echo it directly. Do not soften "bullish" to "leaning slightly positive" — say what the data says.
|
package/dist/tools/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import { jupiterQuoteCapability, jupiterSwapCapability } from './jupiter.js';
|
|
|
29
29
|
import { base0xQuoteCapability, base0xSwapCapability } from './zerox-base.js';
|
|
30
30
|
import { base0xGaslessSwapCapability } from './zerox-gasless.js';
|
|
31
31
|
import { defiLlamaProtocolsCapability, defiLlamaProtocolCapability, defiLlamaChainsCapability, defiLlamaYieldsCapability, defiLlamaPriceCapability, } from './defillama.js';
|
|
32
|
+
import { predictionMarketCapability } from './prediction.js';
|
|
32
33
|
import { modalCapabilities } from './modal.js';
|
|
33
34
|
import { createTradingCapabilities } from './trading-execute.js';
|
|
34
35
|
import { Portfolio } from '../trading/portfolio.js';
|
|
@@ -159,6 +160,7 @@ export const allCapabilities = [
|
|
|
159
160
|
defiLlamaChainsCapability,
|
|
160
161
|
defiLlamaYieldsCapability,
|
|
161
162
|
defiLlamaPriceCapability,
|
|
163
|
+
predictionMarketCapability, // Polymarket / Kalshi / matching / smart money via Predexon
|
|
162
164
|
// Modal GPU sandbox tools — registered but hidden by default (not in
|
|
163
165
|
// CORE_TOOL_NAMES). Agent must `ActivateTool({names:["ModalCreate",...]})`
|
|
164
166
|
// before they appear in its tool inventory. High-cost ($0.40/H100 create)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PredictionMarket — unified access to Polymarket / Kalshi / cross-platform
|
|
3
|
+
* matching / smart-money endpoints via the BlockRun gateway. Each call
|
|
4
|
+
* settles via x402 against the user's USDC wallet.
|
|
5
|
+
*
|
|
6
|
+
* Powered server-side by Predexon; surfaced to the agent as a single
|
|
7
|
+
* action-dispatched tool so the inventory stays small. Keep one cohesive
|
|
8
|
+
* tool — the way TradingMarket bundles 6 actions — instead of forty
|
|
9
|
+
* one-shot capabilities, otherwise weak models start hallucinating tool
|
|
10
|
+
* names.
|
|
11
|
+
*
|
|
12
|
+
* searchPolymarket $0.001 query Polymarket markets (event filter, sort)
|
|
13
|
+
* searchKalshi $0.001 query Kalshi markets
|
|
14
|
+
* crossPlatform $0.005 matching market pairs across Polymarket+Kalshi
|
|
15
|
+
* (the arbitrage / consensus signal)
|
|
16
|
+
* smartMoney $0.005 smart-money positioning on one Polymarket
|
|
17
|
+
* condition_id (top wallet flow + side bias)
|
|
18
|
+
*
|
|
19
|
+
* Output is filtered + truncated on the way back so a single call never
|
|
20
|
+
* dumps 100 markets into the agent's context. Default 20 rows; agents that
|
|
21
|
+
* need more should narrow the search.
|
|
22
|
+
*/
|
|
23
|
+
import type { CapabilityHandler } from '../agent/types.js';
|
|
24
|
+
export declare const predictionMarketCapability: CapabilityHandler;
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PredictionMarket — unified access to Polymarket / Kalshi / cross-platform
|
|
3
|
+
* matching / smart-money endpoints via the BlockRun gateway. Each call
|
|
4
|
+
* settles via x402 against the user's USDC wallet.
|
|
5
|
+
*
|
|
6
|
+
* Powered server-side by Predexon; surfaced to the agent as a single
|
|
7
|
+
* action-dispatched tool so the inventory stays small. Keep one cohesive
|
|
8
|
+
* tool — the way TradingMarket bundles 6 actions — instead of forty
|
|
9
|
+
* one-shot capabilities, otherwise weak models start hallucinating tool
|
|
10
|
+
* names.
|
|
11
|
+
*
|
|
12
|
+
* searchPolymarket $0.001 query Polymarket markets (event filter, sort)
|
|
13
|
+
* searchKalshi $0.001 query Kalshi markets
|
|
14
|
+
* crossPlatform $0.005 matching market pairs across Polymarket+Kalshi
|
|
15
|
+
* (the arbitrage / consensus signal)
|
|
16
|
+
* smartMoney $0.005 smart-money positioning on one Polymarket
|
|
17
|
+
* condition_id (top wallet flow + side bias)
|
|
18
|
+
*
|
|
19
|
+
* Output is filtered + truncated on the way back so a single call never
|
|
20
|
+
* dumps 100 markets into the agent's context. Default 20 rows; agents that
|
|
21
|
+
* need more should narrow the search.
|
|
22
|
+
*/
|
|
23
|
+
import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
|
|
24
|
+
import { loadChain, API_URLS, VERSION } from '../config.js';
|
|
25
|
+
import { logger } from '../logger.js';
|
|
26
|
+
const TIMEOUT_MS = 30_000;
|
|
27
|
+
const DEFAULT_LIMIT = 20;
|
|
28
|
+
const MAX_LIMIT = 50;
|
|
29
|
+
// ─── Shared GET-with-x402 flow ────────────────────────────────────────────
|
|
30
|
+
async function getWithPayment(path, query, ctx) {
|
|
31
|
+
const chain = loadChain();
|
|
32
|
+
const apiUrl = API_URLS[chain];
|
|
33
|
+
const qs = new URLSearchParams();
|
|
34
|
+
for (const [k, v] of Object.entries(query)) {
|
|
35
|
+
if (v == null || v === '')
|
|
36
|
+
continue;
|
|
37
|
+
qs.set(k, String(v));
|
|
38
|
+
}
|
|
39
|
+
const queryStr = qs.toString();
|
|
40
|
+
const endpoint = `${apiUrl}${path}${queryStr ? `?${queryStr}` : ''}`;
|
|
41
|
+
const headers = {
|
|
42
|
+
Accept: 'application/json',
|
|
43
|
+
'User-Agent': `franklin/${VERSION}`,
|
|
44
|
+
};
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
47
|
+
const onAbort = () => controller.abort();
|
|
48
|
+
ctx.abortSignal.addEventListener('abort', onAbort, { once: true });
|
|
49
|
+
try {
|
|
50
|
+
let response = await fetch(endpoint, { method: 'GET', signal: controller.signal, headers });
|
|
51
|
+
if (response.status === 402) {
|
|
52
|
+
const paymentHeaders = await signPayment(response, chain, endpoint);
|
|
53
|
+
if (!paymentHeaders) {
|
|
54
|
+
throw new Error('Payment signing failed — check wallet balance');
|
|
55
|
+
}
|
|
56
|
+
response = await fetch(endpoint, {
|
|
57
|
+
method: 'GET',
|
|
58
|
+
signal: controller.signal,
|
|
59
|
+
headers: { ...headers, ...paymentHeaders },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
const errText = await response.text().catch(() => '');
|
|
64
|
+
throw new Error(`PredictionMarket ${path} failed (${response.status}): ${errText.slice(0, 200)}`);
|
|
65
|
+
}
|
|
66
|
+
return (await response.json());
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
ctx.abortSignal.removeEventListener('abort', onAbort);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function signPayment(response, chain, endpoint) {
|
|
74
|
+
try {
|
|
75
|
+
const paymentHeader = await extractPaymentReq(response);
|
|
76
|
+
if (!paymentHeader)
|
|
77
|
+
return null;
|
|
78
|
+
if (chain === 'solana') {
|
|
79
|
+
const wallet = await getOrCreateSolanaWallet();
|
|
80
|
+
const paymentRequired = parsePaymentRequired(paymentHeader);
|
|
81
|
+
const details = extractPaymentDetails(paymentRequired, SOLANA_NETWORK);
|
|
82
|
+
const secretBytes = await solanaKeyToBytes(wallet.privateKey);
|
|
83
|
+
const feePayer = details.extra?.feePayer || details.recipient;
|
|
84
|
+
const payload = await createSolanaPaymentPayload(secretBytes, wallet.address, details.recipient, details.amount, feePayer, {
|
|
85
|
+
resourceUrl: details.resource?.url || endpoint,
|
|
86
|
+
resourceDescription: details.resource?.description || 'Franklin PredictionMarket call',
|
|
87
|
+
maxTimeoutSeconds: details.maxTimeoutSeconds || 60,
|
|
88
|
+
extra: details.extra,
|
|
89
|
+
});
|
|
90
|
+
return { 'PAYMENT-SIGNATURE': payload };
|
|
91
|
+
}
|
|
92
|
+
const wallet = await getOrCreateWallet();
|
|
93
|
+
const paymentRequired = parsePaymentRequired(paymentHeader);
|
|
94
|
+
const details = extractPaymentDetails(paymentRequired);
|
|
95
|
+
const payload = await createPaymentPayload(wallet.privateKey, wallet.address, details.recipient, details.amount, details.network || 'eip155:8453', {
|
|
96
|
+
resourceUrl: details.resource?.url || endpoint,
|
|
97
|
+
resourceDescription: details.resource?.description || 'Franklin PredictionMarket call',
|
|
98
|
+
maxTimeoutSeconds: details.maxTimeoutSeconds || 60,
|
|
99
|
+
extra: details.extra,
|
|
100
|
+
});
|
|
101
|
+
return { 'PAYMENT-SIGNATURE': payload };
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
logger.warn(`[franklin] PredictionMarket payment error: ${err.message}`);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async function extractPaymentReq(response) {
|
|
109
|
+
let header = response.headers.get('payment-required');
|
|
110
|
+
if (!header) {
|
|
111
|
+
try {
|
|
112
|
+
const body = (await response.json());
|
|
113
|
+
if (body.x402 || body.accepts)
|
|
114
|
+
header = btoa(JSON.stringify(body));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
/* ignore */
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return header;
|
|
121
|
+
}
|
|
122
|
+
// ─── Formatting helpers ────────────────────────────────────────────────────
|
|
123
|
+
function formatUsd(value) {
|
|
124
|
+
if (value == null || !Number.isFinite(value))
|
|
125
|
+
return 'n/a';
|
|
126
|
+
if (value >= 1e9)
|
|
127
|
+
return `$${(value / 1e9).toFixed(2)}B`;
|
|
128
|
+
if (value >= 1e6)
|
|
129
|
+
return `$${(value / 1e6).toFixed(2)}M`;
|
|
130
|
+
if (value >= 1e3)
|
|
131
|
+
return `$${(value / 1e3).toFixed(1)}K`;
|
|
132
|
+
return `$${value.toFixed(2)}`;
|
|
133
|
+
}
|
|
134
|
+
function formatPct(value, digits = 1) {
|
|
135
|
+
if (value == null || !Number.isFinite(value))
|
|
136
|
+
return 'n/a';
|
|
137
|
+
return `${(value * 100).toFixed(digits)}%`;
|
|
138
|
+
}
|
|
139
|
+
// API responses sometimes come wrapped as `{data: [...], pagination: ...}`,
|
|
140
|
+
// other times as a bare array. Normalise to an array.
|
|
141
|
+
function unwrapList(raw) {
|
|
142
|
+
if (Array.isArray(raw))
|
|
143
|
+
return raw;
|
|
144
|
+
if (raw && typeof raw === 'object') {
|
|
145
|
+
const obj = raw;
|
|
146
|
+
if (Array.isArray(obj.data))
|
|
147
|
+
return obj.data;
|
|
148
|
+
if (Array.isArray(obj.markets))
|
|
149
|
+
return obj.markets;
|
|
150
|
+
if (Array.isArray(obj.pairs))
|
|
151
|
+
return obj.pairs;
|
|
152
|
+
if (Array.isArray(obj.results))
|
|
153
|
+
return obj.results;
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
async function execute(input, ctx) {
|
|
158
|
+
const { action, search, status, sort, limit, conditionId } = input;
|
|
159
|
+
const cappedLimit = Math.min(Math.max(1, limit ?? DEFAULT_LIMIT), MAX_LIMIT);
|
|
160
|
+
if (!action) {
|
|
161
|
+
return { output: 'Error: action is required (searchPolymarket | searchKalshi | crossPlatform | smartMoney)', isError: true };
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
switch (action) {
|
|
165
|
+
case 'searchPolymarket': {
|
|
166
|
+
const raw = await getWithPayment('/api/v1/pm/polymarket/markets', {
|
|
167
|
+
search,
|
|
168
|
+
status: status ?? 'active',
|
|
169
|
+
sort: sort ?? 'volume',
|
|
170
|
+
limit: cappedLimit,
|
|
171
|
+
}, ctx);
|
|
172
|
+
const markets = unwrapList(raw);
|
|
173
|
+
if (markets.length === 0) {
|
|
174
|
+
return { output: 'No Polymarket markets matched the filters.' };
|
|
175
|
+
}
|
|
176
|
+
const lines = [
|
|
177
|
+
`## Polymarket — ${markets.length} market${markets.length === 1 ? '' : 's'}` +
|
|
178
|
+
(search ? ` · search="${search}"` : '') +
|
|
179
|
+
(status ? ` · status=${status}` : '') +
|
|
180
|
+
` · sort=${sort ?? 'volume'}`,
|
|
181
|
+
'',
|
|
182
|
+
];
|
|
183
|
+
markets.forEach((m, i) => {
|
|
184
|
+
const yesPx = m.outcomes && m.outcome_prices && m.outcomes.length === m.outcome_prices.length
|
|
185
|
+
? m.outcomes.map((o, j) => `${o}=${formatPct(m.outcome_prices[j])}`).join(' / ')
|
|
186
|
+
: 'n/a';
|
|
187
|
+
const cid = m.condition_id ? ` · condition_id=\`${m.condition_id.slice(0, 14)}…\`` : '';
|
|
188
|
+
lines.push(`${i + 1}. **${m.question || m.market_slug || 'untitled'}**${cid}\n` +
|
|
189
|
+
` prices: ${yesPx} · vol: ${formatUsd(m.volume)} · liq: ${formatUsd(m.liquidity)}` +
|
|
190
|
+
(m.end_date ? ` · ends ${m.end_date.slice(0, 10)}` : ''));
|
|
191
|
+
});
|
|
192
|
+
lines.push('', `_$0.001 paid via x402._`);
|
|
193
|
+
return { output: lines.join('\n') };
|
|
194
|
+
}
|
|
195
|
+
case 'searchKalshi': {
|
|
196
|
+
const raw = await getWithPayment('/api/v1/pm/kalshi/markets', {
|
|
197
|
+
search,
|
|
198
|
+
status: status ?? 'open',
|
|
199
|
+
sort: sort ?? 'volume',
|
|
200
|
+
limit: cappedLimit,
|
|
201
|
+
}, ctx);
|
|
202
|
+
const markets = unwrapList(raw);
|
|
203
|
+
if (markets.length === 0) {
|
|
204
|
+
return { output: 'No Kalshi markets matched the filters.' };
|
|
205
|
+
}
|
|
206
|
+
const lines = [
|
|
207
|
+
`## Kalshi — ${markets.length} market${markets.length === 1 ? '' : 's'}` +
|
|
208
|
+
(search ? ` · search="${search}"` : '') +
|
|
209
|
+
` · status=${status ?? 'open'} · sort=${sort ?? 'volume'}`,
|
|
210
|
+
'',
|
|
211
|
+
];
|
|
212
|
+
markets.forEach((m, i) => {
|
|
213
|
+
// Kalshi quotes prices in cents (0–100). Surface them as a tight
|
|
214
|
+
// bid/ask so the agent can read implied probability at a glance.
|
|
215
|
+
const bid = m.yes_bid != null ? `${m.yes_bid}¢` : 'n/a';
|
|
216
|
+
const ask = m.yes_ask != null ? `${m.yes_ask}¢` : 'n/a';
|
|
217
|
+
const ticker = m.ticker ? ` · ticker=\`${m.ticker}\`` : '';
|
|
218
|
+
lines.push(`${i + 1}. **${m.title || m.ticker || 'untitled'}**${ticker}\n` +
|
|
219
|
+
` yes ${bid}/${ask} · vol: ${m.volume?.toLocaleString() ?? 'n/a'} · OI: ${m.open_interest?.toLocaleString() ?? 'n/a'}` +
|
|
220
|
+
(m.close_time ? ` · closes ${m.close_time.slice(0, 10)}` : ''));
|
|
221
|
+
});
|
|
222
|
+
lines.push('', `_$0.001 paid via x402._`);
|
|
223
|
+
return { output: lines.join('\n') };
|
|
224
|
+
}
|
|
225
|
+
case 'crossPlatform': {
|
|
226
|
+
const raw = await getWithPayment('/api/v1/pm/matching-markets/pairs', {
|
|
227
|
+
limit: cappedLimit,
|
|
228
|
+
}, ctx);
|
|
229
|
+
const pairs = unwrapList(raw);
|
|
230
|
+
if (pairs.length === 0) {
|
|
231
|
+
return { output: 'No matched market pairs available right now.' };
|
|
232
|
+
}
|
|
233
|
+
const lines = [
|
|
234
|
+
`## Cross-platform matched pairs — ${pairs.length}`,
|
|
235
|
+
'_Polymarket ↔ Kalshi equivalent markets. Use these to compare implied probabilities across venues._',
|
|
236
|
+
'',
|
|
237
|
+
];
|
|
238
|
+
pairs.forEach((p, i) => {
|
|
239
|
+
const sim = p.similarity != null ? ` · similarity ${formatPct(p.similarity, 0)}` : '';
|
|
240
|
+
lines.push(`${i + 1}. **Polymarket:** ${p.polymarket_question || '(untitled)'}\n` +
|
|
241
|
+
` **Kalshi:** ${p.kalshi_title || '(untitled)'}` +
|
|
242
|
+
(p.kalshi_ticker ? ` · ticker=\`${p.kalshi_ticker}\`` : '') +
|
|
243
|
+
sim);
|
|
244
|
+
});
|
|
245
|
+
lines.push('', `_$0.005 paid via x402._`);
|
|
246
|
+
return { output: lines.join('\n') };
|
|
247
|
+
}
|
|
248
|
+
case 'smartMoney': {
|
|
249
|
+
if (!conditionId) {
|
|
250
|
+
return { output: 'Error: conditionId is required for smartMoney (Polymarket condition_id from a prior searchPolymarket call)', isError: true };
|
|
251
|
+
}
|
|
252
|
+
const path = `/api/v1/pm/polymarket/market/${encodeURIComponent(conditionId)}/smart-money`;
|
|
253
|
+
const data = await getWithPayment(path, {}, ctx);
|
|
254
|
+
const buyers = (data.buyers ?? []).slice(0, 5);
|
|
255
|
+
const sellers = (data.sellers ?? []).slice(0, 5);
|
|
256
|
+
const lines = [
|
|
257
|
+
`## Smart money — \`${conditionId.slice(0, 14)}…\``,
|
|
258
|
+
];
|
|
259
|
+
if (data.net_yes_size != null || data.net_no_size != null) {
|
|
260
|
+
const yesSize = formatUsd(data.net_yes_size);
|
|
261
|
+
const noSize = formatUsd(data.net_no_size);
|
|
262
|
+
lines.push(`**Net flow:** YES ${yesSize} / NO ${noSize}`);
|
|
263
|
+
}
|
|
264
|
+
if (buyers.length > 0) {
|
|
265
|
+
lines.push('', '**Top buyers**');
|
|
266
|
+
buyers.forEach((b, i) => {
|
|
267
|
+
const w = b.wallet ? `${b.wallet.slice(0, 8)}…${b.wallet.slice(-4)}` : 'unknown';
|
|
268
|
+
lines.push(`${i + 1}. ${w} — ${formatUsd(b.size)} on ${b.outcome ?? 'unknown side'}`);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (sellers.length > 0) {
|
|
272
|
+
lines.push('', '**Top sellers**');
|
|
273
|
+
sellers.forEach((s, i) => {
|
|
274
|
+
const w = s.wallet ? `${s.wallet.slice(0, 8)}…${s.wallet.slice(-4)}` : 'unknown';
|
|
275
|
+
lines.push(`${i + 1}. ${w} — ${formatUsd(s.size)} on ${s.outcome ?? 'unknown side'}`);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
if (buyers.length === 0 && sellers.length === 0) {
|
|
279
|
+
lines.push('No smart-money flow recorded for this market yet.');
|
|
280
|
+
}
|
|
281
|
+
lines.push('', `_$0.005 paid via x402._`);
|
|
282
|
+
return { output: lines.join('\n') };
|
|
283
|
+
}
|
|
284
|
+
default:
|
|
285
|
+
return {
|
|
286
|
+
output: `Error: unknown action "${action}". Use: searchPolymarket, searchKalshi, crossPlatform, smartMoney`,
|
|
287
|
+
isError: true,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
return { output: `Error: ${err.message}`, isError: true };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export const predictionMarketCapability = {
|
|
296
|
+
spec: {
|
|
297
|
+
name: 'PredictionMarket',
|
|
298
|
+
description: 'Real prediction market data via the BlockRun gateway (powered by Predexon). Use for any "what are the odds of X" / "Polymarket on Y" / "Kalshi market for Z" question. ' +
|
|
299
|
+
'Actions: ' +
|
|
300
|
+
'`searchPolymarket` (search Polymarket markets — $0.001), ' +
|
|
301
|
+
'`searchKalshi` (search Kalshi markets — $0.001), ' +
|
|
302
|
+
'`crossPlatform` (matched pairs across Polymarket+Kalshi for arbitrage / consensus — $0.005), ' +
|
|
303
|
+
'`smartMoney` (smart-money positioning on a Polymarket condition_id — $0.005). ' +
|
|
304
|
+
'Polymarket and Kalshi are the two largest legit prediction markets; cross-platform matching is unique to BlockRun. ' +
|
|
305
|
+
'For "should I bet on X" / "what does the market price imply": run searchPolymarket AND searchKalshi in parallel and compare implied probabilities — divergence is the signal.',
|
|
306
|
+
input_schema: {
|
|
307
|
+
type: 'object',
|
|
308
|
+
properties: {
|
|
309
|
+
action: {
|
|
310
|
+
type: 'string',
|
|
311
|
+
enum: ['searchPolymarket', 'searchKalshi', 'crossPlatform', 'smartMoney'],
|
|
312
|
+
description: 'Which prediction-market query to run. See tool description for cost per action.',
|
|
313
|
+
},
|
|
314
|
+
search: {
|
|
315
|
+
type: 'string',
|
|
316
|
+
description: 'Search query (3-100 chars). Used by searchPolymarket / searchKalshi. Skip for crossPlatform/smartMoney.',
|
|
317
|
+
},
|
|
318
|
+
status: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
description: 'Polymarket: active | closed | archived (default active). Kalshi: open | closed (default open).',
|
|
321
|
+
},
|
|
322
|
+
sort: {
|
|
323
|
+
type: 'string',
|
|
324
|
+
description: 'Polymarket: volume | liquidity | created (default volume). Kalshi: volume | open_interest | price_desc | price_asc | close_time (default volume).',
|
|
325
|
+
},
|
|
326
|
+
limit: {
|
|
327
|
+
type: 'number',
|
|
328
|
+
description: `Max results (default ${DEFAULT_LIMIT}, hard cap ${MAX_LIMIT}).`,
|
|
329
|
+
},
|
|
330
|
+
conditionId: {
|
|
331
|
+
type: 'string',
|
|
332
|
+
description: 'Polymarket condition_id. Required for smartMoney. Get one from a prior searchPolymarket call.',
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
required: ['action'],
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
execute,
|
|
339
|
+
concurrent: true,
|
|
340
|
+
};
|
|
@@ -44,6 +44,11 @@ export const CORE_TOOL_NAMES = new Set([
|
|
|
44
44
|
// training-data guessing.
|
|
45
45
|
'TradingMarket',
|
|
46
46
|
'TradingSignal',
|
|
47
|
+
// Prediction market data — Polymarket, Kalshi, cross-platform matching,
|
|
48
|
+
// smart money. The "what are the odds of X" / "Polymarket on Y"
|
|
49
|
+
// category. Cross-platform pair lookup is unique to the gateway and
|
|
50
|
+
// is the kind of data a non-wallet agent fundamentally cannot reach.
|
|
51
|
+
'PredictionMarket',
|
|
47
52
|
// Research — synthesized answers with real citations, semantic web
|
|
48
53
|
// search, and clean URL fetching. Any factual current-events question
|
|
49
54
|
// ("why did X drop?") should route here rather than the model's prior.
|
package/package.json
CHANGED