oculon 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +344 -2
- package/dist/agent.d.ts +47 -0
- package/dist/agent.js +104 -0
- package/dist/cases.d.ts +68 -0
- package/dist/cases.js +158 -0
- package/dist/cli/main.d.ts +12 -0
- package/dist/cli/main.js +1999 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/core/context.d.ts +19 -0
- package/dist/core/context.js +19 -0
- package/dist/core/features.d.ts +22 -0
- package/dist/core/features.js +28 -0
- package/dist/core/graph.d.ts +38 -0
- package/dist/core/graph.js +81 -0
- package/dist/core/http.d.ts +42 -0
- package/dist/core/http.js +266 -0
- package/dist/core/keys.d.ts +8 -0
- package/dist/core/keys.js +22 -0
- package/dist/core/llm.d.ts +93 -0
- package/dist/core/llm.js +180 -0
- package/dist/core/merkle.d.ts +15 -0
- package/dist/core/merkle.js +46 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +6 -0
- package/dist/core/png.d.ts +17 -0
- package/dist/core/png.js +101 -0
- package/dist/core/quota.d.ts +15 -0
- package/dist/core/quota.js +90 -0
- package/dist/core/stats.d.ts +24 -0
- package/dist/core/stats.js +67 -0
- package/dist/core/store.d.ts +20 -0
- package/dist/core/store.js +213 -0
- package/dist/core/text.d.ts +9 -0
- package/dist/core/text.js +30 -0
- package/dist/core/types.d.ts +38 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +495 -0
- package/dist/live.d.ts +53 -0
- package/dist/live.js +236 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +651 -0
- package/dist/modules/airport.d.ts +60 -0
- package/dist/modules/airport.js +111 -0
- package/dist/modules/audit.d.ts +73 -0
- package/dist/modules/audit.js +211 -0
- package/dist/modules/bgp.d.ts +147 -0
- package/dist/modules/bgp.js +206 -0
- package/dist/modules/blackout.d.ts +41 -0
- package/dist/modules/blackout.js +98 -0
- package/dist/modules/brief.d.ts +26 -0
- package/dist/modules/brief.js +99 -0
- package/dist/modules/calendar.d.ts +27 -0
- package/dist/modules/calendar.js +145 -0
- package/dist/modules/calibrate.d.ts +46 -0
- package/dist/modules/calibrate.js +92 -0
- package/dist/modules/cloud.d.ts +32 -0
- package/dist/modules/cloud.js +94 -0
- package/dist/modules/condor.d.ts +66 -0
- package/dist/modules/condor.js +214 -0
- package/dist/modules/connect.d.ts +47 -0
- package/dist/modules/connect.js +114 -0
- package/dist/modules/contradictions.d.ts +27 -0
- package/dist/modules/contradictions.js +76 -0
- package/dist/modules/country.d.ts +82 -0
- package/dist/modules/country.js +136 -0
- package/dist/modules/cricket.d.ts +34 -0
- package/dist/modules/cricket.js +166 -0
- package/dist/modules/darkships.d.ts +219 -0
- package/dist/modules/darkships.js +400 -0
- package/dist/modules/defi.d.ts +237 -0
- package/dist/modules/defi.js +512 -0
- package/dist/modules/emailsec.d.ts +47 -0
- package/dist/modules/emailsec.js +146 -0
- package/dist/modules/exposure.d.ts +43 -0
- package/dist/modules/exposure.js +89 -0
- package/dist/modules/factcheck.d.ts +39 -0
- package/dist/modules/factcheck.js +127 -0
- package/dist/modules/falcon.d.ts +58 -0
- package/dist/modules/falcon.js +219 -0
- package/dist/modules/feedback.d.ts +24 -0
- package/dist/modules/feedback.js +37 -0
- package/dist/modules/fence.d.ts +52 -0
- package/dist/modules/fence.js +128 -0
- package/dist/modules/ferret.d.ts +47 -0
- package/dist/modules/ferret.js +220 -0
- package/dist/modules/filings.d.ts +86 -0
- package/dist/modules/filings.js +166 -0
- package/dist/modules/fires.d.ts +56 -0
- package/dist/modules/fires.js +150 -0
- package/dist/modules/hazards.d.ts +37 -0
- package/dist/modules/hazards.js +83 -0
- package/dist/modules/health.d.ts +24 -0
- package/dist/modules/health.js +82 -0
- package/dist/modules/heron.d.ts +68 -0
- package/dist/modules/heron.js +184 -0
- package/dist/modules/hound.d.ts +100 -0
- package/dist/modules/hound.js +301 -0
- package/dist/modules/impact.d.ts +39 -0
- package/dist/modules/impact.js +63 -0
- package/dist/modules/launches.d.ts +24 -0
- package/dist/modules/launches.js +61 -0
- package/dist/modules/listen.d.ts +48 -0
- package/dist/modules/listen.js +125 -0
- package/dist/modules/lynx.d.ts +43 -0
- package/dist/modules/lynx.js +127 -0
- package/dist/modules/magpie.d.ts +70 -0
- package/dist/modules/magpie.js +174 -0
- package/dist/modules/meerkat.d.ts +42 -0
- package/dist/modules/meerkat.js +293 -0
- package/dist/modules/monitor.d.ts +27 -0
- package/dist/modules/monitor.js +105 -0
- package/dist/modules/narratives.d.ts +33 -0
- package/dist/modules/narratives.js +136 -0
- package/dist/modules/owl.d.ts +71 -0
- package/dist/modules/owl.js +290 -0
- package/dist/modules/papers.d.ts +46 -0
- package/dist/modules/papers.js +135 -0
- package/dist/modules/personal.d.ts +54 -0
- package/dist/modules/personal.js +153 -0
- package/dist/modules/pulse.d.ts +19 -0
- package/dist/modules/pulse.js +59 -0
- package/dist/modules/raven.d.ts +80 -0
- package/dist/modules/raven.js +147 -0
- package/dist/modules/recall.d.ts +44 -0
- package/dist/modules/recall.js +123 -0
- package/dist/modules/regs.d.ts +88 -0
- package/dist/modules/regs.js +142 -0
- package/dist/modules/rewind.d.ts +22 -0
- package/dist/modules/rewind.js +68 -0
- package/dist/modules/sanctions.d.ts +62 -0
- package/dist/modules/sanctions.js +173 -0
- package/dist/modules/scam.d.ts +43 -0
- package/dist/modules/scam.js +111 -0
- package/dist/modules/scoop.d.ts +31 -0
- package/dist/modules/scoop.js +74 -0
- package/dist/modules/ships.d.ts +33 -0
- package/dist/modules/ships.js +113 -0
- package/dist/modules/sky.d.ts +47 -0
- package/dist/modules/sky.js +183 -0
- package/dist/modules/squawk.d.ts +46 -0
- package/dist/modules/squawk.js +106 -0
- package/dist/modules/tortoise.d.ts +40 -0
- package/dist/modules/tortoise.js +104 -0
- package/dist/modules/travel.d.ts +94 -0
- package/dist/modules/travel.js +241 -0
- package/dist/modules/urlcheck.d.ts +63 -0
- package/dist/modules/urlcheck.js +223 -0
- package/dist/modules/vulns.d.ts +142 -0
- package/dist/modules/vulns.js +276 -0
- package/dist/plugins.d.ts +41 -0
- package/dist/plugins.js +70 -0
- package/dist/report.d.ts +12 -0
- package/dist/report.js +90 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.js +139 -0
- package/dist/sources/aircraft.d.ts +76 -0
- package/dist/sources/aircraft.js +107 -0
- package/dist/sources/airports.d.ts +28 -0
- package/dist/sources/airports.js +100 -0
- package/dist/sources/ais.d.ts +32 -0
- package/dist/sources/ais.js +111 -0
- package/dist/sources/apify.d.ts +28 -0
- package/dist/sources/apify.js +80 -0
- package/dist/sources/arxiv.d.ts +13 -0
- package/dist/sources/arxiv.js +27 -0
- package/dist/sources/certs.d.ts +12 -0
- package/dist/sources/certs.js +23 -0
- package/dist/sources/corp.d.ts +46 -0
- package/dist/sources/corp.js +60 -0
- package/dist/sources/earth.d.ts +39 -0
- package/dist/sources/earth.js +76 -0
- package/dist/sources/fda.d.ts +77 -0
- package/dist/sources/fda.js +121 -0
- package/dist/sources/finance.d.ts +181 -0
- package/dist/sources/finance.js +270 -0
- package/dist/sources/gdelt.d.ts +19 -0
- package/dist/sources/gdelt.js +33 -0
- package/dist/sources/github.d.ts +17 -0
- package/dist/sources/github.js +33 -0
- package/dist/sources/hackernews.d.ts +20 -0
- package/dist/sources/hackernews.js +37 -0
- package/dist/sources/labels.d.ts +21 -0
- package/dist/sources/labels.js +87 -0
- package/dist/sources/launch.d.ts +16 -0
- package/dist/sources/launch.js +41 -0
- package/dist/sources/ofac.d.ts +29 -0
- package/dist/sources/ofac.js +86 -0
- package/dist/sources/onchain.d.ts +77 -0
- package/dist/sources/onchain.js +189 -0
- package/dist/sources/opentimestamps.d.ts +44 -0
- package/dist/sources/opentimestamps.js +131 -0
- package/dist/sources/polymarket.d.ts +36 -0
- package/dist/sources/polymarket.js +70 -0
- package/dist/sources/predict.d.ts +18 -0
- package/dist/sources/predict.js +59 -0
- package/dist/sources/press.d.ts +30 -0
- package/dist/sources/press.js +111 -0
- package/dist/sources/resend.d.ts +14 -0
- package/dist/sources/resend.js +29 -0
- package/dist/sources/robinhood.d.ts +109 -0
- package/dist/sources/robinhood.js +129 -0
- package/dist/sources/sec.d.ts +67 -0
- package/dist/sources/sec.js +129 -0
- package/dist/sources/sentinel.d.ts +13 -0
- package/dist/sources/sentinel.js +63 -0
- package/dist/sources/signatures.d.ts +14 -0
- package/dist/sources/signatures.js +103 -0
- package/dist/sources/social.d.ts +22 -0
- package/dist/sources/social.js +56 -0
- package/dist/sources/space.d.ts +160 -0
- package/dist/sources/space.js +230 -0
- package/dist/sources/usgs.d.ts +17 -0
- package/dist/sources/usgs.js +24 -0
- package/dist/sources/wayback.d.ts +10 -0
- package/dist/sources/wayback.js +28 -0
- package/dist/sources/websec.d.ts +19 -0
- package/dist/sources/websec.js +40 -0
- package/dist/sources/wikidata.d.ts +11 -0
- package/dist/sources/wikidata.js +30 -0
- package/dist/sources/wikimedia.d.ts +28 -0
- package/dist/sources/wikimedia.js +52 -0
- package/dist/telegram.d.ts +104 -0
- package/dist/telegram.js +927 -0
- package/dist/web/assets/favicon-32.png +0 -0
- package/dist/web/assets/fx.js +178 -0
- package/dist/web/assets/icon-192.png +0 -0
- package/dist/web/assets/icon-512.png +0 -0
- package/dist/web/assets/icon-maskable-512.png +0 -0
- package/dist/web/assets/night-americas.jpg +0 -0
- package/dist/web/assets/night-emea.jpg +0 -0
- package/dist/web/assets/og.png +0 -0
- package/dist/web/assets/redsea-bm.jpg +0 -0
- package/dist/web/docs.html +263 -0
- package/dist/web/index.html +1828 -0
- package/dist/web/insights.d.ts +100 -0
- package/dist/web/insights.js +134 -0
- package/dist/web/landing.html +1143 -0
- package/dist/web/legal.html +176 -0
- package/dist/web/manifest.webmanifest +20 -0
- package/dist/web/mcp.html +104 -0
- package/dist/web/mcphttp.d.ts +10 -0
- package/dist/web/mcphttp.js +67 -0
- package/dist/web/openapi.d.ts +1 -0
- package/dist/web/openapi.js +51 -0
- package/dist/web/public.d.ts +45 -0
- package/dist/web/public.js +135 -0
- package/dist/web/server.d.ts +69 -0
- package/dist/web/server.js +750 -0
- package/dist/web/share.d.ts +35 -0
- package/dist/web/share.js +132 -0
- package/dist/web/sw.js +28 -0
- package/package.json +60 -4
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-chain sources: Zerion (portfolio), Etherscan v2 (transactions, multi-chain), GoPlus (token/address security),
|
|
3
|
+
* (public endpoints; GoPlus keys are not needed for these calls), Webacy (address risk), DexScreener (pairs, keyless), Helius (Solana), Robinhood Chain RPC + Blockscout.
|
|
4
|
+
*/
|
|
5
|
+
import { enc } from '../core/context.js';
|
|
6
|
+
import { key, noKey } from '../core/keys.js';
|
|
7
|
+
import { postJson } from './press.js';
|
|
8
|
+
import { decodeSelectors, methodName } from './signatures.js';
|
|
9
|
+
export const isEvmAddress = (s) => /^0x[0-9a-fA-F]{40}$/.test(s.trim());
|
|
10
|
+
export const isSolanaAddress = (s) => /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(s.trim()) && !isEvmAddress(s);
|
|
11
|
+
export const CHAINS = {
|
|
12
|
+
eth: { id: 1, goplus: '1', coingecko: 'ethereum', label: 'Ethereum' },
|
|
13
|
+
base: { id: 8453, goplus: '8453', coingecko: 'base', label: 'Base' },
|
|
14
|
+
arbitrum: { id: 42161, goplus: '42161', coingecko: 'arbitrum-one', label: 'Arbitrum' },
|
|
15
|
+
bsc: { id: 56, goplus: '56', coingecko: 'binance-smart-chain', label: 'BNB Chain' },
|
|
16
|
+
polygon: { id: 137, goplus: '137', coingecko: 'polygon-pos', label: 'Polygon' },
|
|
17
|
+
robinhood: { id: 4663, goplus: null, coingecko: null, label: 'Robinhood Chain' },
|
|
18
|
+
};
|
|
19
|
+
export async function zerionPortfolio(ctx, address) {
|
|
20
|
+
const k = key('ZERION_API_KEY');
|
|
21
|
+
if (!k)
|
|
22
|
+
return noKey('zerion', 'ZERION_API_KEY');
|
|
23
|
+
const auth = { authorization: `Basic ${Buffer.from(`${k}:`).toString('base64')}` };
|
|
24
|
+
const [p, pos] = await Promise.all([
|
|
25
|
+
ctx.http.get(`https://api.zerion.io/v1/wallets/${enc(address)}/portfolio`, { source: 'zerion', ttlSec: 600, headers: auth }),
|
|
26
|
+
ctx.http.get(`https://api.zerion.io/v1/wallets/${enc(address)}/positions/?filter[positions]=only_simple&filter[trash]=only_non_trash¤cy=usd&sort=-value`, {
|
|
27
|
+
source: 'zerion',
|
|
28
|
+
ttlSec: 600,
|
|
29
|
+
headers: auth,
|
|
30
|
+
// Big wallets return thousands of positions; only the 50 largest are ever shown.
|
|
31
|
+
keep: (d) => ({
|
|
32
|
+
data: (d.data ?? [])
|
|
33
|
+
.sort((x, y) => (y.attributes.value ?? 0) - (x.attributes.value ?? 0))
|
|
34
|
+
.slice(0, 50)
|
|
35
|
+
.map((x) => ({ attributes: { value: x.attributes.value, fungible_info: { name: x.attributes.fungible_info?.name, symbol: x.attributes.fungible_info?.symbol } }, relationships: { chain: { data: { id: x.relationships?.chain?.data?.id } } } })),
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
]);
|
|
39
|
+
const a = p.data?.data?.attributes;
|
|
40
|
+
if (!a)
|
|
41
|
+
return { data: null, prov: p.prov };
|
|
42
|
+
return {
|
|
43
|
+
data: {
|
|
44
|
+
totalUsd: a.total?.positions ?? 0,
|
|
45
|
+
change1dPct: a.changes?.percent_1d ?? null,
|
|
46
|
+
byChain: a.positions_distribution_by_chain ?? {},
|
|
47
|
+
top: (pos.data?.data ?? [])
|
|
48
|
+
.filter((x) => (x.attributes.value ?? 0) >= 1)
|
|
49
|
+
.sort((x, y) => (y.attributes.value ?? 0) - (x.attributes.value ?? 0))
|
|
50
|
+
.slice(0, 10)
|
|
51
|
+
.map((x) => ({ name: x.attributes.fungible_info?.name ?? '?', symbol: x.attributes.fungible_info?.symbol ?? '?', chain: x.relationships?.chain?.data?.id ?? '?', valueUsd: x.attributes.value ?? 0 })),
|
|
52
|
+
},
|
|
53
|
+
prov: p.prov,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export async function etherscanTxs(ctx, address, chainId = 1, sort = 'desc', n = 20) {
|
|
57
|
+
const k = key('ETHERSCAN_API_KEY');
|
|
58
|
+
if (!k)
|
|
59
|
+
return noKey('etherscan', 'ETHERSCAN_API_KEY');
|
|
60
|
+
const r = await ctx.http.get(`https://api.etherscan.io/v2/api?chainid=${chainId}&module=account&action=txlist&address=${enc(address)}&page=1&offset=${n}&sort=${sort}&apikey=${k}`, { source: 'etherscan', ttlSec: 600 });
|
|
61
|
+
const res = r.data?.result;
|
|
62
|
+
const prov = { ...r.prov, url: r.prov.url.replace(/apikey=[^&]+/, 'apikey=***') };
|
|
63
|
+
if (!Array.isArray(res))
|
|
64
|
+
return { data: r.data?.message === 'No transactions found' ? [] : null, prov: Array.isArray(res) ? prov : { ...prov, ...(typeof res === 'string' ? { note: res.slice(0, 80) } : {}) } };
|
|
65
|
+
// Unverified contracts come back without a function name: decode the 4-byte selector instead.
|
|
66
|
+
const unknown = [...new Set(res.filter((t) => !t.functionName && t.methodId && t.methodId !== '0x').map((t) => t.methodId.toLowerCase()))];
|
|
67
|
+
const decoded = unknown.length ? await decodeSelectors(ctx, unknown).catch(() => ({})) : {};
|
|
68
|
+
return {
|
|
69
|
+
data: res.map((t) => {
|
|
70
|
+
const sig = t.functionName || (t.methodId ? decoded[t.methodId.toLowerCase()] : null) || '';
|
|
71
|
+
return { hash: t.hash, time: new Date(Number(t.timeStamp) * 1000).toISOString(), from: t.from, to: t.to, valueEth: Number(t.value) / 1e18, method: sig ? methodName(sig) : t.methodId && t.methodId !== '0x' ? t.methodId : 'transfer' };
|
|
72
|
+
}),
|
|
73
|
+
prov,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const RISK_FLAGS = [
|
|
77
|
+
['is_honeypot', 'honeypot'],
|
|
78
|
+
['cannot_sell_all', 'cannot sell all'],
|
|
79
|
+
['is_blacklisted', 'blacklist function'],
|
|
80
|
+
['hidden_owner', 'hidden owner'],
|
|
81
|
+
['can_take_back_ownership', 'can take back ownership'],
|
|
82
|
+
['owner_change_balance', 'owner can change balances'],
|
|
83
|
+
['selfdestruct', 'self-destruct'],
|
|
84
|
+
['is_mintable', 'mintable'],
|
|
85
|
+
['transfer_pausable', 'transfers pausable'],
|
|
86
|
+
['is_proxy', 'upgradeable proxy'],
|
|
87
|
+
['slippage_modifiable', 'tax modifiable'],
|
|
88
|
+
['external_call', 'external calls'],
|
|
89
|
+
];
|
|
90
|
+
export async function tokenSecurity(ctx, chain, address) {
|
|
91
|
+
const r = await ctx.http.get(`https://api.gopluslabs.io/api/v1/token_security/${enc(chain)}?contract_addresses=${enc(address.toLowerCase())}`, { source: 'goplus', ttlSec: 1800 });
|
|
92
|
+
const d = r.data?.result?.[address.toLowerCase()];
|
|
93
|
+
if (!d)
|
|
94
|
+
return { data: null, prov: r.data ? { ...r.prov, status: 'UNAVAILABLE', note: 'token not indexed by GoPlus' } : r.prov };
|
|
95
|
+
const num = (v) => (v === undefined || v === '' ? null : Number(v));
|
|
96
|
+
return {
|
|
97
|
+
data: {
|
|
98
|
+
name: String(d.token_name ?? ''),
|
|
99
|
+
symbol: String(d.token_symbol ?? ''),
|
|
100
|
+
flags: RISK_FLAGS.filter(([k]) => d[k] === '1').map(([, label]) => label),
|
|
101
|
+
buyTax: num(d.buy_tax),
|
|
102
|
+
sellTax: num(d.sell_tax),
|
|
103
|
+
holders: num(d.holder_count),
|
|
104
|
+
ownerPercent: num(d.owner_percent),
|
|
105
|
+
inDex: d.is_in_dex === '1',
|
|
106
|
+
},
|
|
107
|
+
prov: r.prov,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** GoPlus malicious-address labels (phishing, sanctioned, stealing attack, ...). */
|
|
111
|
+
export async function addressSecurity(ctx, address, chainId = '1') {
|
|
112
|
+
const r = await ctx.http.get(`https://api.gopluslabs.io/api/v1/address_security/${enc(address)}?chain_id=${chainId}`, {
|
|
113
|
+
source: 'goplus',
|
|
114
|
+
ttlSec: 3600,
|
|
115
|
+
});
|
|
116
|
+
const d = r.data?.result;
|
|
117
|
+
return { data: d ? Object.entries(d).filter(([k, v]) => v === '1' && k !== 'contract_address' && k !== 'data_source').map(([k]) => k.replace(/_/g, ' ')) : null, prov: r.prov };
|
|
118
|
+
}
|
|
119
|
+
export async function webacyRisk(ctx, address, chain = 'eth') {
|
|
120
|
+
const k = key('WEBACY_API_KEY');
|
|
121
|
+
if (!k)
|
|
122
|
+
return noKey('webacy', 'WEBACY_API_KEY');
|
|
123
|
+
const r = await ctx.http.get(`https://api.webacy.com/addresses/${enc(address)}?chain=${enc(chain)}`, {
|
|
124
|
+
source: 'webacy',
|
|
125
|
+
ttlSec: 3600,
|
|
126
|
+
headers: { 'x-api-key': k },
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
data: r.data ? { score: r.data.overallRisk ?? null, issues: [...new Set((r.data.issues ?? []).flatMap((i) => (i.tags ?? []).map((t) => t.name ?? t.key ?? '')).filter(Boolean))].slice(0, 10) } : null,
|
|
130
|
+
prov: r.prov,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/** DexScreener chain ids for our chain names. */
|
|
134
|
+
export const DEX_CHAIN = { eth: 'ethereum', base: 'base', arbitrum: 'arbitrum', bsc: 'bsc', polygon: 'polygon', robinhood: 'robinhood' };
|
|
135
|
+
/** Pairs for a token on one chain only (same contract addresses exist on forks such as PulseChain). */
|
|
136
|
+
export async function dexPairs(ctx, token, chain = 'eth') {
|
|
137
|
+
const r = await ctx.http.get(`https://api.dexscreener.com/tokens/v1/${enc(DEX_CHAIN[chain] ?? chain)}/${enc(token)}`, { source: 'dexscreener', ttlSec: 300 });
|
|
138
|
+
const list = Array.isArray(r.data) ? r.data : (r.data?.pairs ?? null);
|
|
139
|
+
return {
|
|
140
|
+
data: list
|
|
141
|
+
?.map((p) => ({
|
|
142
|
+
chain: p.chainId,
|
|
143
|
+
dex: p.dexId,
|
|
144
|
+
pair: `${p.baseToken.symbol}/${p.quoteToken.symbol}`,
|
|
145
|
+
priceUsd: p.priceUsd ? Number(p.priceUsd) : null,
|
|
146
|
+
liquidityUsd: p.liquidity?.usd ?? null,
|
|
147
|
+
volume24h: p.volume?.h24 ?? null,
|
|
148
|
+
change24h: p.priceChange?.h24 ?? null,
|
|
149
|
+
createdAt: p.pairCreatedAt ? new Date(p.pairCreatedAt).toISOString() : null,
|
|
150
|
+
url: p.url,
|
|
151
|
+
}))
|
|
152
|
+
.sort((a, b) => (b.liquidityUsd ?? 0) - (a.liquidityUsd ?? 0)) ?? (r.data ? [] : null),
|
|
153
|
+
prov: r.prov,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function rpc(ctx, url, method, params, source, ttlSec = 30) {
|
|
157
|
+
const r = await postJson(ctx, url, { jsonrpc: '2.0', id: 1, method, params }, {}, source, ttlSec);
|
|
158
|
+
const prov = { ...r.prov, url: r.prov.url.replace(/api-key=[^&]+/, 'api-key=***').replace(/\/v2\/[^/]+$/, '/v2/***') };
|
|
159
|
+
if (r.data?.error)
|
|
160
|
+
return { data: null, prov: { ...prov, status: 'ERROR', note: r.data.error.message } };
|
|
161
|
+
return { data: r.data?.result ?? null, prov };
|
|
162
|
+
}
|
|
163
|
+
/** Native balance and transaction count on Robinhood Chain (public RPC). */
|
|
164
|
+
export async function robinhoodAccount(ctx, address) {
|
|
165
|
+
const url = key('ROBINHOOD_PUBLIC_RPC_URL');
|
|
166
|
+
if (!url)
|
|
167
|
+
return noKey('robinhood-rpc', 'ROBINHOOD_PUBLIC_RPC_URL');
|
|
168
|
+
const [bal, n, code] = await Promise.all([
|
|
169
|
+
rpc(ctx, url, 'eth_getBalance', [address, 'latest'], 'robinhood-rpc'),
|
|
170
|
+
rpc(ctx, url, 'eth_getTransactionCount', [address, 'latest'], 'robinhood-rpc'),
|
|
171
|
+
rpc(ctx, url, 'eth_getCode', [address, 'latest'], 'robinhood-rpc', 3600),
|
|
172
|
+
]);
|
|
173
|
+
if (bal.data === null)
|
|
174
|
+
return { data: null, prov: bal.prov };
|
|
175
|
+
return { data: { balanceEth: Number(BigInt(bal.data)) / 1e18, txCount: n.data ? Number(BigInt(n.data)) : 0, isContract: Boolean(code.data && code.data !== '0x') }, prov: bal.prov };
|
|
176
|
+
}
|
|
177
|
+
export async function solanaAccount(ctx, address) {
|
|
178
|
+
const k = key('HELIUS_API_KEY');
|
|
179
|
+
if (!k)
|
|
180
|
+
return noKey('helius', 'HELIUS_API_KEY');
|
|
181
|
+
const url = `https://mainnet.helius-rpc.com/?api-key=${k}`;
|
|
182
|
+
const [bal, toks] = await Promise.all([
|
|
183
|
+
rpc(ctx, url, 'getBalance', [address], 'helius'),
|
|
184
|
+
rpc(ctx, url, 'getTokenAccountsByOwner', [address, { programId: 'TokenkegQfeZyiNwAJbNbGywRYdTXJ8ZqKt8kXq6S' }, { encoding: 'jsonParsed' }], 'helius'),
|
|
185
|
+
]);
|
|
186
|
+
if (!bal.data)
|
|
187
|
+
return { data: null, prov: bal.prov };
|
|
188
|
+
return { data: { sol: bal.data.value / 1e9, tokens: toks.data?.value?.length ?? 0 }, prov: bal.prov };
|
|
189
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { Provenance, Sourced } from '../core/types.js';
|
|
3
|
+
export declare const CALENDARS: string[];
|
|
4
|
+
export type Attestation = {
|
|
5
|
+
kind: 'pending';
|
|
6
|
+
uri: string;
|
|
7
|
+
commitment: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'bitcoin';
|
|
10
|
+
height: number;
|
|
11
|
+
commitment: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'unknown';
|
|
14
|
+
tag: string;
|
|
15
|
+
commitment: string;
|
|
16
|
+
};
|
|
17
|
+
/** Walk a serialized timestamp (as returned by a calendar) starting from `digest`, collecting attestations. */
|
|
18
|
+
export declare function parseTimestamp(bytes: Buffer, digest: Buffer): Attestation[];
|
|
19
|
+
export interface Receipt {
|
|
20
|
+
calendar: string;
|
|
21
|
+
/** Hex of the calendar's serialized timestamp for our digest. */
|
|
22
|
+
ots: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function submit(ctx: Ctx, digestHex: string): Promise<{
|
|
25
|
+
receipts: Receipt[];
|
|
26
|
+
provenance: Provenance[];
|
|
27
|
+
}>;
|
|
28
|
+
/** Ask the calendar for the upgraded timestamp of a pending commitment. 404 means still pending. */
|
|
29
|
+
export declare function upgrade(ctx: Ctx, att: Extract<Attestation, {
|
|
30
|
+
kind: 'pending';
|
|
31
|
+
}>): Promise<{
|
|
32
|
+
attestations: Attestation[];
|
|
33
|
+
prov: Provenance;
|
|
34
|
+
}>;
|
|
35
|
+
export interface BlockInfo {
|
|
36
|
+
height: number;
|
|
37
|
+
hash: string;
|
|
38
|
+
/** Merkle root in display (big-endian) hex, as block explorers show it. */
|
|
39
|
+
merkleRoot: string;
|
|
40
|
+
time: number;
|
|
41
|
+
}
|
|
42
|
+
export declare function bitcoinBlock(ctx: Ctx, height: number): Promise<Sourced<BlockInfo>>;
|
|
43
|
+
/** OTS commitments are in internal byte order; explorers display the merkle root reversed. */
|
|
44
|
+
export declare const matchesMerkleRoot: (commitmentHex: string, displayRootHex: string) => boolean;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTimestamps: free, keyless timestamping anchored in Bitcoin.
|
|
3
|
+
* We submit a 32-byte digest to public calendars, keep their receipts, and later check
|
|
4
|
+
* (a) whether a calendar has upgraded the receipt to a Bitcoin block attestation, and
|
|
5
|
+
* (b) that the attested commitment equals that block's merkle root (fetched from Blockstream).
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
export const CALENDARS = ['https://a.pool.opentimestamps.org', 'https://b.pool.opentimestamps.org'];
|
|
9
|
+
const PENDING_TAG = '83dfe30d2ef90c8e';
|
|
10
|
+
const BITCOIN_TAG = '0588960d73d71901';
|
|
11
|
+
class Reader {
|
|
12
|
+
buf;
|
|
13
|
+
pos = 0;
|
|
14
|
+
constructor(buf) {
|
|
15
|
+
this.buf = buf;
|
|
16
|
+
}
|
|
17
|
+
byte() {
|
|
18
|
+
if (this.pos >= this.buf.length)
|
|
19
|
+
throw new Error('ots: unexpected end');
|
|
20
|
+
return this.buf[this.pos++];
|
|
21
|
+
}
|
|
22
|
+
bytes(n) {
|
|
23
|
+
if (this.pos + n > this.buf.length)
|
|
24
|
+
throw new Error('ots: unexpected end');
|
|
25
|
+
const b = this.buf.subarray(this.pos, this.pos + n);
|
|
26
|
+
this.pos += n;
|
|
27
|
+
return b;
|
|
28
|
+
}
|
|
29
|
+
varuint() {
|
|
30
|
+
let v = 0;
|
|
31
|
+
let shift = 0;
|
|
32
|
+
for (;;) {
|
|
33
|
+
const b = this.byte();
|
|
34
|
+
v += (b & 0x7f) * 2 ** shift;
|
|
35
|
+
if (!(b & 0x80))
|
|
36
|
+
return v;
|
|
37
|
+
shift += 7;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
varbytes() {
|
|
41
|
+
return this.bytes(this.varuint());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const hash = (alg, data) => createHash(alg).update(data).digest();
|
|
45
|
+
function applyOp(op, msg, r) {
|
|
46
|
+
switch (op) {
|
|
47
|
+
case 0xf0:
|
|
48
|
+
return Buffer.concat([msg, r.varbytes()]);
|
|
49
|
+
case 0xf1:
|
|
50
|
+
return Buffer.concat([r.varbytes(), msg]);
|
|
51
|
+
case 0x08:
|
|
52
|
+
return hash('sha256', msg);
|
|
53
|
+
case 0x02:
|
|
54
|
+
return hash('sha1', msg);
|
|
55
|
+
case 0x03:
|
|
56
|
+
return hash('ripemd160', msg);
|
|
57
|
+
case 0xf2:
|
|
58
|
+
return Buffer.from(msg).reverse();
|
|
59
|
+
case 0xf3:
|
|
60
|
+
return Buffer.from(msg.toString('hex'), 'utf8');
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(`ots: unsupported op 0x${op.toString(16)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Walk a serialized timestamp (as returned by a calendar) starting from `digest`, collecting attestations. */
|
|
66
|
+
export function parseTimestamp(bytes, digest) {
|
|
67
|
+
const r = new Reader(bytes);
|
|
68
|
+
const out = [];
|
|
69
|
+
const item = (tag, msg) => {
|
|
70
|
+
if (tag === 0x00) {
|
|
71
|
+
const t = r.bytes(8).toString('hex');
|
|
72
|
+
const payload = new Reader(r.varbytes());
|
|
73
|
+
const commitment = msg.toString('hex');
|
|
74
|
+
if (t === PENDING_TAG)
|
|
75
|
+
out.push({ kind: 'pending', uri: payload.varbytes().toString('utf8'), commitment });
|
|
76
|
+
else if (t === BITCOIN_TAG)
|
|
77
|
+
out.push({ kind: 'bitcoin', height: payload.varuint(), commitment });
|
|
78
|
+
else
|
|
79
|
+
out.push({ kind: 'unknown', tag: t, commitment });
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
walk(applyOp(tag, msg, r));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const walk = (msg) => {
|
|
86
|
+
for (;;) {
|
|
87
|
+
const tag = r.byte();
|
|
88
|
+
if (tag === 0xff) {
|
|
89
|
+
item(r.byte(), msg);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
item(tag, msg);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
walk(digest);
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
export async function submit(ctx, digestHex) {
|
|
100
|
+
const body = Buffer.from(digestHex, 'hex');
|
|
101
|
+
const results = await Promise.all(CALENDARS.map((c) => ctx.http.postBytes(`${c}/digest`, body, { source: 'opentimestamps', headers: { accept: 'application/vnd.opentimestamps.v1' } })));
|
|
102
|
+
const receipts = results.flatMap((r, i) => (r.data ? [{ calendar: CALENDARS[i], ots: r.data.toString('hex') }] : []));
|
|
103
|
+
return { receipts, provenance: results.map((r) => r.prov) };
|
|
104
|
+
}
|
|
105
|
+
/** Ask the calendar for the upgraded timestamp of a pending commitment. 404 means still pending. */
|
|
106
|
+
export async function upgrade(ctx, att) {
|
|
107
|
+
const r = await ctx.http.getBytes(`${att.uri.replace(/\/$/, '')}/timestamp/${att.commitment}`, {
|
|
108
|
+
source: 'opentimestamps',
|
|
109
|
+
headers: { accept: 'application/vnd.opentimestamps.v1' },
|
|
110
|
+
});
|
|
111
|
+
if (!r.data)
|
|
112
|
+
return { attestations: [], prov: r.prov };
|
|
113
|
+
try {
|
|
114
|
+
return { attestations: parseTimestamp(r.data, Buffer.from(att.commitment, 'hex')), prov: r.prov };
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
return { attestations: [], prov: { ...r.prov, status: 'ERROR', note: e.message } };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export async function bitcoinBlock(ctx, height) {
|
|
121
|
+
const h = await ctx.http.get(`https://blockstream.info/api/block-height/${height}`, { source: 'blockstream', as: 'text', ttlSec: 30 * 86_400 });
|
|
122
|
+
if (!h.data)
|
|
123
|
+
return { data: null, prov: h.prov };
|
|
124
|
+
const b = await ctx.http.get(`https://blockstream.info/api/block/${h.data.trim()}`, {
|
|
125
|
+
source: 'blockstream',
|
|
126
|
+
ttlSec: 30 * 86_400,
|
|
127
|
+
});
|
|
128
|
+
return { data: b.data ? { height: b.data.height, hash: b.data.id, merkleRoot: b.data.merkle_root, time: b.data.timestamp } : null, prov: b.prov };
|
|
129
|
+
}
|
|
130
|
+
/** OTS commitments are in internal byte order; explorers display the merkle root reversed. */
|
|
131
|
+
export const matchesMerkleRoot = (commitmentHex, displayRootHex) => Buffer.from(commitmentHex, 'hex').reverse().toString('hex') === displayRootHex.toLowerCase();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { Sourced } from '../core/types.js';
|
|
3
|
+
export interface Market {
|
|
4
|
+
id: string;
|
|
5
|
+
slug: string | null;
|
|
6
|
+
question: string;
|
|
7
|
+
closed: boolean;
|
|
8
|
+
url: string;
|
|
9
|
+
outcomes: string[];
|
|
10
|
+
prices: number[];
|
|
11
|
+
volume24h: number;
|
|
12
|
+
/** Change in the first outcome's price over 24h, in probability points (0.1 = +10pp). */
|
|
13
|
+
change1d: number | null;
|
|
14
|
+
endDate: string | null;
|
|
15
|
+
}
|
|
16
|
+
interface GammaMarket {
|
|
17
|
+
id?: string | number;
|
|
18
|
+
question?: string;
|
|
19
|
+
slug?: string;
|
|
20
|
+
outcomes?: string;
|
|
21
|
+
outcomePrices?: string;
|
|
22
|
+
volume24hr?: number | string;
|
|
23
|
+
oneDayPriceChange?: number | string;
|
|
24
|
+
endDate?: string;
|
|
25
|
+
closed?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function toMarket(m: GammaMarket): Market | null;
|
|
28
|
+
/** Open markets whose event matches a free-text query. */
|
|
29
|
+
export declare function searchMarkets(ctx: Ctx, query: string, limit?: number): Promise<Sourced<Market[]>>;
|
|
30
|
+
/** One market by slug, open or closed. */
|
|
31
|
+
export declare function marketBySlug(ctx: Ctx, slug: string, ttlSec?: number): Promise<Sourced<Market>>;
|
|
32
|
+
/** 1 or 0 for the first outcome once the market is closed with a settled price; null while unresolved. */
|
|
33
|
+
export declare function resolution(m: Market): 0 | 1 | null;
|
|
34
|
+
/** Active markets ranked by 24h volume. */
|
|
35
|
+
export declare function topMarkets(ctx: Ctx, limit?: number): Promise<Sourced<Market[]>>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function parseList(s) {
|
|
2
|
+
if (!s)
|
|
3
|
+
return [];
|
|
4
|
+
try {
|
|
5
|
+
const v = JSON.parse(s);
|
|
6
|
+
return Array.isArray(v) ? v.map(String) : [];
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const num = (v) => {
|
|
13
|
+
const n = typeof v === 'string' ? Number(v) : typeof v === 'number' ? v : NaN;
|
|
14
|
+
return Number.isFinite(n) ? n : null;
|
|
15
|
+
};
|
|
16
|
+
export function toMarket(m) {
|
|
17
|
+
if (!m.question)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
id: String(m.id ?? m.slug ?? m.question),
|
|
21
|
+
slug: m.slug ?? null,
|
|
22
|
+
question: m.question,
|
|
23
|
+
closed: m.closed === true,
|
|
24
|
+
url: m.slug ? `https://polymarket.com/market/${m.slug}` : 'https://polymarket.com',
|
|
25
|
+
outcomes: parseList(m.outcomes),
|
|
26
|
+
prices: parseList(m.outcomePrices).map(Number),
|
|
27
|
+
volume24h: num(m.volume24hr) ?? 0,
|
|
28
|
+
change1d: num(m.oneDayPriceChange),
|
|
29
|
+
endDate: m.endDate ?? null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Open markets whose event matches a free-text query. */
|
|
33
|
+
export async function searchMarkets(ctx, query, limit = 10) {
|
|
34
|
+
const url = `https://gamma-api.polymarket.com/public-search?q=${encodeURIComponent(query)}&limit_per_type=${limit}&events_status=active`;
|
|
35
|
+
const r = await ctx.http.get(url, {
|
|
36
|
+
source: 'polymarket',
|
|
37
|
+
ttlSec: 600,
|
|
38
|
+
});
|
|
39
|
+
const data = r.data?.events
|
|
40
|
+
?.filter((e) => !e.closed)
|
|
41
|
+
.flatMap((e) => e.markets ?? [])
|
|
42
|
+
.filter((m) => m.active !== false && m.closed !== true)
|
|
43
|
+
.map(toMarket)
|
|
44
|
+
.filter((m) => m !== null)
|
|
45
|
+
.sort((a, b) => b.volume24h - a.volume24h) ?? null;
|
|
46
|
+
return { data, prov: r.prov };
|
|
47
|
+
}
|
|
48
|
+
/** One market by slug, open or closed. */
|
|
49
|
+
export async function marketBySlug(ctx, slug, ttlSec = 300) {
|
|
50
|
+
const r = await ctx.http.get(`https://gamma-api.polymarket.com/markets?slug=${encodeURIComponent(slug)}`, { source: 'polymarket', ttlSec });
|
|
51
|
+
const m = r.data?.[0];
|
|
52
|
+
return { data: m ? toMarket(m) : null, prov: r.data && !m ? { ...r.prov, status: 'UNAVAILABLE', note: 'no market with that slug' } : r.prov };
|
|
53
|
+
}
|
|
54
|
+
/** 1 or 0 for the first outcome once the market is closed with a settled price; null while unresolved. */
|
|
55
|
+
export function resolution(m) {
|
|
56
|
+
if (!m.closed || m.prices.length < 2)
|
|
57
|
+
return null;
|
|
58
|
+
if (m.prices[0] === 1 && m.prices[1] === 0)
|
|
59
|
+
return 1;
|
|
60
|
+
if (m.prices[0] === 0 && m.prices[1] === 1)
|
|
61
|
+
return 0;
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/** Active markets ranked by 24h volume. */
|
|
65
|
+
export async function topMarkets(ctx, limit = 100) {
|
|
66
|
+
const url = `https://gamma-api.polymarket.com/markets?active=true&closed=false&order=volume24hr&ascending=false&limit=${limit}`;
|
|
67
|
+
const r = await ctx.http.get(url, { source: 'polymarket', ttlSec: 600 });
|
|
68
|
+
const data = r.data?.map(toMarket).filter((m) => m !== null) ?? null;
|
|
69
|
+
return { data, prov: r.prov };
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Other prediction markets: Kalshi (public market data) and Manifold (play-money, public API). Both keyless. */
|
|
2
|
+
import { type Ctx } from '../core/context.js';
|
|
3
|
+
import type { Provenance, Sourced } from '../core/types.js';
|
|
4
|
+
export interface OtherMarket {
|
|
5
|
+
venue: 'kalshi' | 'manifold';
|
|
6
|
+
question: string;
|
|
7
|
+
probability: number;
|
|
8
|
+
volume: number | null;
|
|
9
|
+
url: string;
|
|
10
|
+
closes: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** Open Kalshi markets with a usable price, excluding multi-leg sports parlays. Up to `pages` x 200 events. */
|
|
13
|
+
export declare function kalshiMarkets(ctx: Ctx, pages?: number): Promise<{
|
|
14
|
+
data: OtherMarket[] | null;
|
|
15
|
+
provs: Provenance[];
|
|
16
|
+
}>;
|
|
17
|
+
/** Binary Manifold markets matching a search term. */
|
|
18
|
+
export declare function manifoldSearch(ctx: Ctx, term: string, limit?: number): Promise<Sourced<OtherMarket[]>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Other prediction markets: Kalshi (public market data) and Manifold (play-money, public API). Both keyless. */
|
|
2
|
+
import { enc } from '../core/context.js';
|
|
3
|
+
const num = (v) => {
|
|
4
|
+
const n = Number(v);
|
|
5
|
+
return Number.isFinite(n) ? n : null;
|
|
6
|
+
};
|
|
7
|
+
/** Open Kalshi markets with a usable price, excluding multi-leg sports parlays. Up to `pages` x 200 events. */
|
|
8
|
+
export async function kalshiMarkets(ctx, pages = 10) {
|
|
9
|
+
const out = [];
|
|
10
|
+
const provs = [];
|
|
11
|
+
let cursor = '';
|
|
12
|
+
for (let i = 0; i < pages; i++) {
|
|
13
|
+
const r = await ctx.http.get(`https://api.elections.kalshi.com/trade-api/v2/events?status=open&with_nested_markets=true&limit=200${cursor ? `&cursor=${enc(cursor)}` : ''}`, {
|
|
14
|
+
source: 'kalshi',
|
|
15
|
+
ttlSec: 1800,
|
|
16
|
+
timeoutMs: 40_000,
|
|
17
|
+
// Pages are megabytes of fields we never read; cache only these.
|
|
18
|
+
keep: (d) => ({
|
|
19
|
+
cursor: d.cursor,
|
|
20
|
+
events: (d.events ?? []).map((e) => ({
|
|
21
|
+
event_ticker: e.event_ticker,
|
|
22
|
+
title: e.title,
|
|
23
|
+
markets: e.event_ticker.startsWith('KXMVE') ? [] : (e.markets ?? []).map((m) => ({ title: m.title, yes_sub_title: m.yes_sub_title, last_price_dollars: m.last_price_dollars, yes_bid_dollars: m.yes_bid_dollars, yes_ask_dollars: m.yes_ask_dollars, volume_fp: m.volume_fp, close_time: m.close_time })),
|
|
24
|
+
})),
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
provs.push(r.prov);
|
|
28
|
+
if (!r.data)
|
|
29
|
+
return { data: i === 0 ? null : out, provs };
|
|
30
|
+
for (const e of r.data.events ?? []) {
|
|
31
|
+
if (e.event_ticker.startsWith('KXMVE'))
|
|
32
|
+
continue;
|
|
33
|
+
for (const m of e.markets ?? []) {
|
|
34
|
+
const last = num(m.last_price_dollars);
|
|
35
|
+
const bid = num(m.yes_bid_dollars);
|
|
36
|
+
const ask = num(m.yes_ask_dollars);
|
|
37
|
+
const p = last && last > 0 ? last : bid !== null && ask !== null && ask > 0 ? (bid + ask) / 2 : null;
|
|
38
|
+
if (p === null || p <= 0 || p >= 1)
|
|
39
|
+
continue;
|
|
40
|
+
const sub = m.yes_sub_title && !e.title.includes(m.yes_sub_title) ? ` — ${m.yes_sub_title}` : '';
|
|
41
|
+
out.push({ venue: 'kalshi', question: `${m.title ?? e.title}${sub}`, probability: p, volume: num(m.volume_fp), url: `https://kalshi.com/markets/${e.event_ticker.toLowerCase()}`, closes: m.close_time ?? null });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
cursor = r.data.cursor ?? '';
|
|
45
|
+
if (!cursor)
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return { data: out, provs };
|
|
49
|
+
}
|
|
50
|
+
/** Binary Manifold markets matching a search term. */
|
|
51
|
+
export async function manifoldSearch(ctx, term, limit = 8) {
|
|
52
|
+
const r = await ctx.http.get(`https://api.manifold.markets/v0/search-markets?term=${enc(term)}&filter=open&contractType=BINARY&limit=${limit}`, { source: 'manifold', ttlSec: 3600 });
|
|
53
|
+
return {
|
|
54
|
+
data: r.data
|
|
55
|
+
?.filter((m) => m.outcomeType === 'BINARY' && typeof m.probability === 'number')
|
|
56
|
+
.map((m) => ({ venue: 'manifold', question: m.question, probability: m.probability, volume: m.volume ?? null, url: m.url, closes: m.closeTime ? new Date(m.closeTime).toISOString() : null })) ?? null,
|
|
57
|
+
prov: r.prov,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** News and web search: GNews, The Guardian, New York Times, Tavily, Exa, plus Jina/Firecrawl page reading. */
|
|
2
|
+
import { type Ctx } from '../core/context.js';
|
|
3
|
+
import type { Sourced } from '../core/types.js';
|
|
4
|
+
import type { NewsItem } from './finance.js';
|
|
5
|
+
/** Search options for finding the FIRST coverage of something: oldest first, from a fixed start date. */
|
|
6
|
+
export interface EarliestOpts {
|
|
7
|
+
fromIso: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function gnews(ctx: Ctx, q: string, max?: number, earliest?: EarliestOpts): Promise<Sourced<NewsItem[]>>;
|
|
10
|
+
export declare function guardian(ctx: Ctx, q: string, days?: number, max?: number, earliest?: EarliestOpts): Promise<Sourced<NewsItem[]>>;
|
|
11
|
+
/** Guardian news stories published on one day (YYYY-MM-DD), in the main news sections. */
|
|
12
|
+
export declare function guardianDay(ctx: Ctx, date: string, max?: number): Promise<Sourced<NewsItem[]>>;
|
|
13
|
+
/** Number of Guardian articles matching `q` between two dates (YYYY-MM-DD, inclusive). */
|
|
14
|
+
export declare function guardianCount(ctx: Ctx, q: string, from: string, to: string): Promise<Sourced<number>>;
|
|
15
|
+
export declare function nytSearch(ctx: Ctx, q: string, days?: number, earliest?: EarliestOpts): Promise<Sourced<NewsItem[]>>;
|
|
16
|
+
export declare function nytTopStories(ctx: Ctx): Promise<Sourced<NewsItem[]>>;
|
|
17
|
+
export interface WebResult {
|
|
18
|
+
title: string;
|
|
19
|
+
url: string;
|
|
20
|
+
snippet: string;
|
|
21
|
+
date: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Web search: Tavily first, Exa as fallback. */
|
|
24
|
+
export declare function webSearch(ctx: Ctx, q: string, max?: number, news?: boolean): Promise<Sourced<WebResult[]>>;
|
|
25
|
+
/** Readable text of a web page: Jina Reader first, Firecrawl as fallback. Capped at `maxChars`. */
|
|
26
|
+
export declare function readPage(ctx: Ctx, url: string, maxChars?: number): Promise<Sourced<string>>;
|
|
27
|
+
/**
|
|
28
|
+
* POST JSON with caching keyed on the body. Used for search APIs whose results are fine to reuse for a few hours.
|
|
29
|
+
*/
|
|
30
|
+
export declare function postJson<T>(ctx: Ctx, url: string, body: unknown, headers: Record<string, string>, source: string, ttlSec?: number): Promise<Sourced<T>>;
|