@x402-api/elizaos-plugin 1.0.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/README.md +346 -0
- package/dist/actions/dexQuotes.d.ts +4 -0
- package/dist/actions/dexQuotes.d.ts.map +1 -0
- package/dist/actions/dexQuotes.js +80 -0
- package/dist/actions/dexQuotes.js.map +1 -0
- package/dist/actions/fundingRates.d.ts +4 -0
- package/dist/actions/fundingRates.d.ts.map +1 -0
- package/dist/actions/fundingRates.js +85 -0
- package/dist/actions/fundingRates.js.map +1 -0
- package/dist/actions/gasTracker.d.ts +4 -0
- package/dist/actions/gasTracker.d.ts.map +1 -0
- package/dist/actions/gasTracker.js +60 -0
- package/dist/actions/gasTracker.js.map +1 -0
- package/dist/actions/priceFeed.d.ts +4 -0
- package/dist/actions/priceFeed.d.ts.map +1 -0
- package/dist/actions/priceFeed.js +75 -0
- package/dist/actions/priceFeed.js.map +1 -0
- package/dist/actions/tokenScanner.d.ts +4 -0
- package/dist/actions/tokenScanner.d.ts.map +1 -0
- package/dist/actions/tokenScanner.js +83 -0
- package/dist/actions/tokenScanner.js.map +1 -0
- package/dist/actions/walletProfiler.d.ts +4 -0
- package/dist/actions/walletProfiler.d.ts.map +1 -0
- package/dist/actions/walletProfiler.js +92 -0
- package/dist/actions/walletProfiler.js.map +1 -0
- package/dist/actions/whaleTracker.d.ts +4 -0
- package/dist/actions/whaleTracker.d.ts.map +1 -0
- package/dist/actions/whaleTracker.js +71 -0
- package/dist/actions/whaleTracker.js.map +1 -0
- package/dist/actions/yieldScanner.d.ts +4 -0
- package/dist/actions/yieldScanner.d.ts.map +1 -0
- package/dist/actions/yieldScanner.js +93 -0
- package/dist/actions/yieldScanner.js.map +1 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +154 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +63 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +108 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +280 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { x402ApiRequest } from '../client.js';
|
|
2
|
+
export function createPriceFeedAction(config) {
|
|
3
|
+
return {
|
|
4
|
+
name: 'GET_CRYPTO_PRICES',
|
|
5
|
+
similes: [
|
|
6
|
+
'PRICE_FEED',
|
|
7
|
+
'GET_PRICES',
|
|
8
|
+
'CRYPTO_PRICES',
|
|
9
|
+
'TOKEN_PRICES',
|
|
10
|
+
'MARKET_PRICES',
|
|
11
|
+
'CHECK_PRICE',
|
|
12
|
+
'PRICE_CHECK',
|
|
13
|
+
'CURRENT_PRICES',
|
|
14
|
+
'MARKET_DATA',
|
|
15
|
+
],
|
|
16
|
+
description: 'Fetch live crypto prices for BTC, ETH, SOL and top movers by 24h change. ' +
|
|
17
|
+
'Data sourced from CoinGecko. Costs $0.001 USDC via x402.',
|
|
18
|
+
validate: async (_runtime, _message, _state) => {
|
|
19
|
+
// Always valid — no required parameters
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
22
|
+
handler: async (_runtime, message, _state, _options, callback) => {
|
|
23
|
+
try {
|
|
24
|
+
const data = await x402ApiRequest('/api/price-feed', {}, config);
|
|
25
|
+
const { core, top_movers } = data.data;
|
|
26
|
+
// Format a readable summary
|
|
27
|
+
const coreLines = core
|
|
28
|
+
.map(c => {
|
|
29
|
+
const sign = (c.change_24h_pct ?? 0) >= 0 ? '📈' : '📉';
|
|
30
|
+
const change = c.change_24h_pct != null ? `${sign} ${c.change_24h_pct > 0 ? '+' : ''}${c.change_24h_pct}%` : '';
|
|
31
|
+
const price = c.price_usd != null ? `$${c.price_usd.toLocaleString()}` : 'N/A';
|
|
32
|
+
return `• **${c.id.toUpperCase()}**: ${price} ${change}`;
|
|
33
|
+
})
|
|
34
|
+
.join('\n');
|
|
35
|
+
const gainersLine = top_movers.gainers
|
|
36
|
+
.slice(0, 3)
|
|
37
|
+
.map(c => `${c.id.toUpperCase()} +${c.change_24h_pct}%`)
|
|
38
|
+
.join(', ');
|
|
39
|
+
const losersLine = top_movers.losers
|
|
40
|
+
.slice(0, 3)
|
|
41
|
+
.map(c => `${c.id.toUpperCase()} ${c.change_24h_pct}%`)
|
|
42
|
+
.join(', ');
|
|
43
|
+
const text = `## 💰 Crypto Prices\n\n${coreLines}\n\n` +
|
|
44
|
+
`**Top Gainers (24h):** ${gainersLine}\n` +
|
|
45
|
+
`**Top Losers (24h):** ${losersLine}\n\n` +
|
|
46
|
+
`*Source: ${data.source} • Updated: ${data.timestamp}${data.cached ? ' (cached)' : ''}*`;
|
|
47
|
+
if (callback) {
|
|
48
|
+
await callback({ text, source: message.content.source });
|
|
49
|
+
}
|
|
50
|
+
return { success: true, text, data: data.data };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const errMsg = `Failed to fetch crypto prices: ${error.message}`;
|
|
54
|
+
if (callback)
|
|
55
|
+
await callback({ text: errMsg });
|
|
56
|
+
return { success: false, text: errMsg };
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
examples: [
|
|
60
|
+
[
|
|
61
|
+
{ name: '{{user}}', content: { text: 'What are the current crypto prices?' } },
|
|
62
|
+
{ name: '{{agent}}', content: { text: '## 💰 Crypto Prices\n\n• **BITCOIN**: $98,000 📈 +2.1%\n• **ETHEREUM**: $2,750 📉 -0.8%\n• **SOLANA**: $185 📈 +4.2%\n\n**Top Gainers:** SUI +8.2%, SOL +4.2%, BTC +2.1%', actions: ['GET_CRYPTO_PRICES'] } },
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
{ name: '{{user}}', content: { text: 'Check the price feed' } },
|
|
66
|
+
{ name: '{{agent}}', content: { text: 'Fetching live crypto prices...', actions: ['GET_CRYPTO_PRICES'] } },
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
{ name: '{{user}}', content: { text: 'How is the market doing?' } },
|
|
70
|
+
{ name: '{{agent}}', content: { text: '## 💰 Crypto Prices\n\nFetching latest market data via x402...', actions: ['GET_CRYPTO_PRICES'] } },
|
|
71
|
+
],
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=priceFeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priceFeed.js","sourceRoot":"","sources":["../../src/actions/priceFeed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAC;AAGrE,MAAM,UAAU,qBAAqB,CAAC,MAAwB;IAC5D,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE;YACP,YAAY;YACZ,YAAY;YACZ,eAAe;YACf,cAAc;YACd,eAAe;YACf,aAAa;YACb,aAAa;YACb,gBAAgB;YAChB,aAAa;SACd;QACD,WAAW,EACT,2EAA2E;YAC3E,0DAA0D;QAE5D,QAAQ,EAAE,KAAK,EAAE,QAAuB,EAAE,QAAgB,EAAE,MAAc,EAAE,EAAE;YAC5E,wCAAwC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,EAAE,KAAK,EACZ,QAAuB,EACvB,OAAe,EACf,MAAc,EACd,QAAyB,EACzB,QAA0B,EAC1B,EAAE;YACF,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,cAAc,CAAoB,iBAAiB,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;gBAEpF,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;gBAEvC,4BAA4B;gBAC5B,MAAM,SAAS,GAAG,IAAI;qBACnB,GAAG,CAAC,CAAC,CAAC,EAAE;oBACP,MAAM,IAAI,GAAG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,EAAE;gBACnE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,gEAAgE,EAAE,OAAO,EAAE,CAAC,mBAAmB,CAAC,EAAE,EAAE;aAC3I;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenScanner.d.ts","sourceRoot":"","sources":["../../src/actions/tokenScanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA+E,MAAM,eAAe,CAAC;AACzH,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAqGzE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { x402ApiRequest } from '../client.js';
|
|
2
|
+
const RISK_EMOJIS = { LOW: '🟢', MEDIUM: '🟡', HIGH: '🔴', CRITICAL: '💀' };
|
|
3
|
+
export function createTokenScannerAction(config) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'SCAN_TOKEN',
|
|
6
|
+
similes: [
|
|
7
|
+
'TOKEN_SCANNER',
|
|
8
|
+
'CHECK_TOKEN',
|
|
9
|
+
'TOKEN_SECURITY',
|
|
10
|
+
'TOKEN_AUDIT',
|
|
11
|
+
'RUG_CHECK',
|
|
12
|
+
'HONEYPOT_CHECK',
|
|
13
|
+
'TOKEN_SAFETY',
|
|
14
|
+
'ANALYZE_TOKEN',
|
|
15
|
+
'TOKEN_RISK',
|
|
16
|
+
],
|
|
17
|
+
description: 'Scan a token for security risks: contract verification, mint function, proxy, liquidity lock, ' +
|
|
18
|
+
'honeypot detection, buy/sell tax, holder count, market cap. ' +
|
|
19
|
+
'Detects potential rug-pulls. Query with token symbol or address. Costs $0.003 USDC via x402.',
|
|
20
|
+
validate: async (_runtime, _message, _state) => {
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
handler: async (_runtime, message, _state, options, callback) => {
|
|
24
|
+
try {
|
|
25
|
+
const text = message.content.text || '';
|
|
26
|
+
// Extract token from message
|
|
27
|
+
const addressMatch = text.match(/0x[0-9a-fA-F]{40}/);
|
|
28
|
+
const symbolMatch = text.match(/\b([A-Z]{2,8})\b/);
|
|
29
|
+
const token = options?.token ||
|
|
30
|
+
addressMatch?.[0] ||
|
|
31
|
+
symbolMatch?.[1] ||
|
|
32
|
+
'PEPE';
|
|
33
|
+
const chainMatch = text.match(/\b(ethereum|base|arbitrum|polygon)\b/i);
|
|
34
|
+
const chain = options?.chain || chainMatch?.[1]?.toLowerCase() || 'ethereum';
|
|
35
|
+
const data = await x402ApiRequest('/api/token-scanner', { token, chain }, config);
|
|
36
|
+
const t = data.data;
|
|
37
|
+
const riskEmoji = RISK_EMOJIS[t.risk_level];
|
|
38
|
+
const flags = t.risk_flags;
|
|
39
|
+
const flagLines = [
|
|
40
|
+
`${flags.is_verified ? '✅' : '❌'} Contract verified`,
|
|
41
|
+
`${!flags.has_proxy ? '✅' : '⚠️'} ${flags.has_proxy ? 'Has proxy (upgradeable)' : 'No proxy'}`,
|
|
42
|
+
`${!flags.has_mint_function ? '✅' : '⚠️'} ${flags.has_mint_function ? 'Has mint function' : 'No mint function'}`,
|
|
43
|
+
`${flags.liquidity_locked ? '✅' : '❌'} Liquidity ${flags.liquidity_locked ? 'locked' : 'NOT locked'}`,
|
|
44
|
+
`${!flags.honeypot_risk ? '✅' : '💀'} ${flags.honeypot_risk ? 'HONEYPOT DETECTED' : 'No honeypot'}`,
|
|
45
|
+
`${!flags.high_buy_tax ? '✅' : '⚠️'} Buy tax: ${t.buy_tax}%`,
|
|
46
|
+
`${!flags.high_sell_tax ? '✅' : '⚠️'} Sell tax: ${t.sell_tax}%`,
|
|
47
|
+
].join('\n');
|
|
48
|
+
const response = `## 🔍 Token Scanner: ${t.symbol} (${t.name})\n\n` +
|
|
49
|
+
`${riskEmoji} **Risk: ${t.risk_level}** (score: ${t.risk_score}/100)\n\n` +
|
|
50
|
+
`**Contract:** \`${t.address}\` on ${t.chain}\n` +
|
|
51
|
+
`**Price:** $${t.price_usd} | **Market Cap:** $${t.market_cap_usd?.toLocaleString()}\n` +
|
|
52
|
+
`**Liquidity:** $${t.liquidity_usd?.toLocaleString()} | **Holders:** ${t.holder_count?.toLocaleString()}\n` +
|
|
53
|
+
`**Age:** ${t.age_days} days\n\n` +
|
|
54
|
+
`### Security Checks\n${flagLines}`;
|
|
55
|
+
if (callback) {
|
|
56
|
+
await callback({ text: response, source: message.content.source });
|
|
57
|
+
}
|
|
58
|
+
return { success: true, text: response, data: data.data };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const errMsg = `Failed to scan token: ${error.message}`;
|
|
62
|
+
if (callback)
|
|
63
|
+
await callback({ text: errMsg });
|
|
64
|
+
return { success: false, text: errMsg };
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
examples: [
|
|
68
|
+
[
|
|
69
|
+
{ name: '{{user}}', content: { text: 'Is PEPE safe to buy? Check for rug' } },
|
|
70
|
+
{ name: '{{agent}}', content: { text: '## 🔍 Token Scanner: PEPE\n\n🟢 **Risk: LOW** (score: 15/100)\n\n✅ Contract verified\n✅ No proxy\n✅ Liquidity locked\n✅ No honeypot', actions: ['SCAN_TOKEN'] } },
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
{ name: '{{user}}', content: { text: 'Scan this token: 0x6982508145454Ce325dDbE47a25d4ec3d2311933' } },
|
|
74
|
+
{ name: '{{agent}}', content: { text: 'Scanning token security for 0x698...', actions: ['SCAN_TOKEN'] } },
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
{ name: '{{user}}', content: { text: 'Check if this is a honeypot' } },
|
|
78
|
+
{ name: '{{agent}}', content: { text: 'Running security scan...', actions: ['SCAN_TOKEN'] } },
|
|
79
|
+
],
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=t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EAAE,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,QAAQ,EAAE;YACR;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,oCAAoC,EAAE,EAAE;gBAC7E,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,qIAAqI,EAAE,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE;aACzM;YACD;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,6DAA6D,EAAE,EAAE;gBACtG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,sCAAsC,EAAE,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE;aAC1G;YACD;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,6BAA6B,EAAE,EAAE;gBACtE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,OAAO,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE;aAC9F;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletProfiler.d.ts","sourceRoot":"","sources":["../../src/actions/walletProfiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA+E,MAAM,eAAe,CAAC;AACzH,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrE,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAgH3E"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { x402ApiRequest } from '../client.js';
|
|
2
|
+
const RISK_EMOJIS = { conservative: '🟢', moderate: '🟡', aggressive: '🔴' };
|
|
3
|
+
export function createWalletProfilerAction(config) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'PROFILE_WALLET',
|
|
6
|
+
similes: [
|
|
7
|
+
'WALLET_PROFILER',
|
|
8
|
+
'WALLET_ANALYSIS',
|
|
9
|
+
'ANALYZE_WALLET',
|
|
10
|
+
'CHECK_WALLET',
|
|
11
|
+
'WALLET_PORTFOLIO',
|
|
12
|
+
'WALLET_HOLDINGS',
|
|
13
|
+
'ADDRESS_ANALYSIS',
|
|
14
|
+
'WALLET_INTEL',
|
|
15
|
+
'WALLET_INFO',
|
|
16
|
+
],
|
|
17
|
+
description: 'Profile an Ethereum wallet: portfolio holdings, DeFi positions, activity metrics, ' +
|
|
18
|
+
'risk classification, and chain distribution. ' +
|
|
19
|
+
'Query with ?address=0x... Costs $0.008 USDC via x402.',
|
|
20
|
+
validate: async (_runtime, message, _state) => {
|
|
21
|
+
const text = message.content.text || '';
|
|
22
|
+
// Valid if there's a wallet address in the message, or we'll use a default
|
|
23
|
+
const hasAddress = /0x[0-9a-fA-F]{40}/.test(text);
|
|
24
|
+
const hasWalletKeywords = /wallet|address|portfolio|holdings|profile/i.test(text);
|
|
25
|
+
return hasAddress || hasWalletKeywords;
|
|
26
|
+
},
|
|
27
|
+
handler: async (_runtime, message, _state, options, callback) => {
|
|
28
|
+
try {
|
|
29
|
+
const text = message.content.text || '';
|
|
30
|
+
// Extract wallet address
|
|
31
|
+
const addressMatch = text.match(/0x[0-9a-fA-F]{40}/);
|
|
32
|
+
const address = options?.address ||
|
|
33
|
+
addressMatch?.[0] ||
|
|
34
|
+
'0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; // Vitalik default
|
|
35
|
+
const chainMatch = text.match(/\b(ethereum|base|arbitrum|polygon|all)\b/i);
|
|
36
|
+
const chain = options?.chain || chainMatch?.[1]?.toLowerCase() || 'all';
|
|
37
|
+
const data = await x402ApiRequest('/api/wallet-profiler', { address, chain }, config);
|
|
38
|
+
const w = data.data;
|
|
39
|
+
const riskEmoji = RISK_EMOJIS[w.risk_profile.classification];
|
|
40
|
+
// Format total value
|
|
41
|
+
const totalFormatted = w.total_value_usd >= 1e6
|
|
42
|
+
? `$${(w.total_value_usd / 1e6).toFixed(2)}M`
|
|
43
|
+
: `$${w.total_value_usd.toLocaleString()}`;
|
|
44
|
+
// Top holdings
|
|
45
|
+
const holdingsLines = w.portfolio.top_holdings.slice(0, 5)
|
|
46
|
+
.map(h => ` • ${h.token} (${h.chain}): $${h.value_usd.toLocaleString()} (${h.portfolio_pct}%)`)
|
|
47
|
+
.join('\n');
|
|
48
|
+
// DeFi positions
|
|
49
|
+
const defiLines = w.defi_positions.length > 0
|
|
50
|
+
? w.defi_positions
|
|
51
|
+
.map(p => ` • ${p.protocol} ${p.type}: ${p.asset} — $${p.value_usd.toLocaleString()} @ ${p.apy}% APY`)
|
|
52
|
+
.join('\n')
|
|
53
|
+
: ' No active DeFi positions';
|
|
54
|
+
const alloc = w.portfolio.allocation;
|
|
55
|
+
const activity = w.activity;
|
|
56
|
+
const response = `## 👛 Wallet Profile\n\n` +
|
|
57
|
+
`**Address:** \`${w.address}\`${w.label ? ` (${w.label})` : ''}\n` +
|
|
58
|
+
`**Type:** ${w.wallet_type} | **Chains:** ${w.chains_active.join(', ')}\n` +
|
|
59
|
+
`**Total Value:** ${totalFormatted} | **DeFi:** $${w.defi_value_usd.toLocaleString()}\n\n` +
|
|
60
|
+
`### Portfolio Allocation\n` +
|
|
61
|
+
` Native: ${alloc.native_tokens_pct}% | Stablecoins: ${alloc.stablecoins_pct}% | DeFi tokens: ${alloc.defi_tokens_pct}%\n\n` +
|
|
62
|
+
`### Top Holdings\n${holdingsLines}\n\n` +
|
|
63
|
+
`### DeFi Positions\n${defiLines}\n\n` +
|
|
64
|
+
`### Activity\n` +
|
|
65
|
+
` ${activity.total_transactions.toLocaleString()} txns | ${activity.age_days} days old | Last active: ${new Date(activity.last_active).toLocaleDateString()}\n\n` +
|
|
66
|
+
`### Risk Profile\n` +
|
|
67
|
+
` ${riskEmoji} **${w.risk_profile.classification.toUpperCase()}** | Diversification: ${w.risk_profile.diversification_score}/10 | DeFi exposure: ${w.risk_profile.defi_exposure_pct}%`;
|
|
68
|
+
if (callback) {
|
|
69
|
+
await callback({ text: response, source: message.content.source });
|
|
70
|
+
}
|
|
71
|
+
return { success: true, text: response, data: data.data };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const errMsg = `Failed to profile wallet: ${error.message}`;
|
|
75
|
+
if (callback)
|
|
76
|
+
await callback({ text: errMsg });
|
|
77
|
+
return { success: false, text: errMsg };
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
examples: [
|
|
81
|
+
[
|
|
82
|
+
{ name: '{{user}}', content: { text: 'Analyze wallet 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' } },
|
|
83
|
+
{ name: '{{agent}}', content: { text: '## 👛 Wallet Profile\n\n**Address:** `0xd8dA...` (vitalik.eth)\n**Total Value:** $4.82M | **DeFi:** $820K', actions: ['PROFILE_WALLET'] } },
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
{ name: '{{user}}', content: { text: 'What\'s in this wallet? 0xBE0eB53F46cd790Cd13851d5EFf43D12404d33E8' } },
|
|
87
|
+
{ name: '{{agent}}', content: { text: 'Profiling wallet 0xBE0e...', actions: ['PROFILE_WALLET'] } },
|
|
88
|
+
],
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=walletProfiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walletProfiler.js","sourceRoot":"","sources":["../../src/actions/walletProfiler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAC;AAGrE,MAAM,WAAW,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAW,CAAC;AAEtF,MAAM,UAAU,0BAA0B,CAAC,MAAwB;IACjE,OAAO;QACL,IAAI,EAAE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IAAI,QAAQ;oBAAE,MAAM,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC/C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,QAAQ,EAAE;YACR;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,2DAA2D,EAAE,EAAE;gBACpG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,2GAA2G,EAAE,OAAO,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE;aACnL;YACD;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,oEAAoE,EAAE,EAAE;gBAC7G,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE;aACpG;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whaleTracker.d.ts","sourceRoot":"","sources":["../../src/actions/whaleTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA+E,MAAM,eAAe,CAAC;AACzH,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CA2FzE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { x402ApiRequest } from '../client.js';
|
|
2
|
+
export function createWhaleTrackerAction(config) {
|
|
3
|
+
return {
|
|
4
|
+
name: 'TRACK_WHALES',
|
|
5
|
+
similes: [
|
|
6
|
+
'WHALE_TRACKER',
|
|
7
|
+
'WHALE_ACTIVITY',
|
|
8
|
+
'CHECK_WHALES',
|
|
9
|
+
'TOP_HOLDERS',
|
|
10
|
+
'HOLDER_ANALYSIS',
|
|
11
|
+
'CONCENTRATION_ANALYSIS',
|
|
12
|
+
'WHALE_MOVEMENTS',
|
|
13
|
+
'LARGE_HOLDERS',
|
|
14
|
+
],
|
|
15
|
+
description: 'Analyze whale concentration and top holder distribution for any token. ' +
|
|
16
|
+
'Returns top holders, Gini coefficient, distribution buckets, and recent large transfers. ' +
|
|
17
|
+
'Costs $0.005 USDC via x402.',
|
|
18
|
+
validate: async (_runtime, _message, _state) => {
|
|
19
|
+
return true;
|
|
20
|
+
},
|
|
21
|
+
handler: async (_runtime, message, _state, options, callback) => {
|
|
22
|
+
try {
|
|
23
|
+
const text = message.content.text || '';
|
|
24
|
+
const symbolMatch = text.match(/\b(BTC|ETH|SOL|PEPE|SHIB|DOGE|LINK|UNI|AAVE|ARB|OP|SUI|AVAX)\b/i);
|
|
25
|
+
const chainMatch = text.match(/\b(ethereum|base|solana|arbitrum|optimism)\b/i);
|
|
26
|
+
const token = options?.token || symbolMatch?.[1]?.toUpperCase() || 'ETH';
|
|
27
|
+
const chain = options?.chain || chainMatch?.[1]?.toLowerCase() || 'ethereum';
|
|
28
|
+
const data = await x402ApiRequest('/api/whale-tracker', { token, chain }, config);
|
|
29
|
+
const w = data.data;
|
|
30
|
+
const cm = w.concentration_metrics;
|
|
31
|
+
// Concentration health indicator
|
|
32
|
+
const giniRisk = cm.gini_coefficient > 0.8 ? '🔴 Very concentrated'
|
|
33
|
+
: cm.gini_coefficient > 0.65 ? '🟡 Moderately concentrated'
|
|
34
|
+
: '🟢 Well distributed';
|
|
35
|
+
const topHolderLines = w.top_holders.slice(0, 5)
|
|
36
|
+
.map(h => ` ${h.rank}. ${h.label} (${h.wallet_type}): **${h.percentage}%**`)
|
|
37
|
+
.join('\n');
|
|
38
|
+
const recentTx = w.recent_large_transfers
|
|
39
|
+
.map(tx => ` • $${tx.usd_value.toLocaleString()} ${tx.transfer_type} — ${new Date(tx.timestamp).toLocaleDateString()}`)
|
|
40
|
+
.join('\n');
|
|
41
|
+
const response = `## 🐋 Whale Tracker: ${w.token} on ${w.chain}\n\n` +
|
|
42
|
+
`**Distribution:** ${giniRisk}\n` +
|
|
43
|
+
`**Gini coefficient:** ${cm.gini_coefficient} | **Top 10 hold:** ${cm.top_10_pct}%\n` +
|
|
44
|
+
`**Total holders:** ${w.holder_count?.toLocaleString()}\n\n` +
|
|
45
|
+
`### Top 5 Holders\n${topHolderLines}\n\n` +
|
|
46
|
+
`### Recent Large Transfers\n${recentTx || ' No recent large transfers'}`;
|
|
47
|
+
if (callback) {
|
|
48
|
+
await callback({ text: response, source: message.content.source });
|
|
49
|
+
}
|
|
50
|
+
return { success: true, text: response, data: data.data };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const errMsg = `Failed to track whales: ${error.message}`;
|
|
54
|
+
if (callback)
|
|
55
|
+
await callback({ text: errMsg });
|
|
56
|
+
return { success: false, text: errMsg };
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
examples: [
|
|
60
|
+
[
|
|
61
|
+
{ name: '{{user}}', content: { text: 'Are whales accumulating ETH?' } },
|
|
62
|
+
{ name: '{{agent}}', content: { text: '## 🐋 Whale Tracker: ETH\n\nTop 10 holders own 42% of supply. Gini: 0.72\n\nRecent large transfers detected...', actions: ['TRACK_WHALES'] } },
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
{ name: '{{user}}', content: { text: 'Show me whale activity for PEPE' } },
|
|
66
|
+
{ name: '{{agent}}', content: { text: 'Fetching PEPE whale distribution and recent transfers...', actions: ['TRACK_WHALES'] } },
|
|
67
|
+
],
|
|
68
|
+
],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=whaleTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whaleTracker.js","sourceRoot":"","sources":["../../src/actions/whaleTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,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E,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,IAA0C,EAAE,CAAC;YAClG,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,MAAM,GAAG,2BAA4B,KAAe,CAAC,OAAO,EAAE,CAAC;gBACrE,IAAI,QAAQ;oBAAE,MAAM,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC/C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,QAAQ,EAAE;YACR;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,8BAA8B,EAAE,EAAE;gBACvE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,gHAAgH,EAAE,OAAO,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE;aACtL;YACD;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,iCAAiC,EAAE,EAAE;gBAC1E,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,0DAA0D,EAAE,OAAO,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE;aAChI;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yieldScanner.d.ts","sourceRoot":"","sources":["../../src/actions/yieldScanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA+E,MAAM,eAAe,CAAC;AACzH,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAcrE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAsGzE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { x402ApiRequest } from '../client.js';
|
|
2
|
+
const RISK_EMOJIS = { low: '🟢', medium: '🟡', high: '🔴' };
|
|
3
|
+
export function createYieldScannerAction(config) {
|
|
4
|
+
return {
|
|
5
|
+
name: 'SCAN_YIELDS',
|
|
6
|
+
similes: [
|
|
7
|
+
'YIELD_SCANNER',
|
|
8
|
+
'FIND_YIELDS',
|
|
9
|
+
'BEST_APY',
|
|
10
|
+
'DEFI_YIELDS',
|
|
11
|
+
'YIELD_OPPORTUNITIES',
|
|
12
|
+
'HIGH_YIELD',
|
|
13
|
+
'STAKING_RATES',
|
|
14
|
+
'LENDING_RATES',
|
|
15
|
+
'PASSIVE_INCOME',
|
|
16
|
+
'DEFI_APY',
|
|
17
|
+
],
|
|
18
|
+
description: 'Find the best DeFi yield opportunities across Aave, Compound, Morpho, Lido, Pendle, Ethena, ' +
|
|
19
|
+
'Yearn, Convex, and more. Filter by chain, asset, TVL, and risk tier. ' +
|
|
20
|
+
'Costs $0.005 USDC via x402.',
|
|
21
|
+
validate: async (_runtime, _message, _state) => {
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
handler: async (_runtime, message, _state, options, callback) => {
|
|
25
|
+
try {
|
|
26
|
+
const text = message.content.text || '';
|
|
27
|
+
const chainMatch = text.match(/\b(ethereum|base|arbitrum|polygon|all)\b/i);
|
|
28
|
+
const assetMatch = text.match(/\b(ETH|USDC|USDT|DAI|stETH|rETH|sUSDe|sDAI|WBTC)\b/i);
|
|
29
|
+
const minTvlMatch = text.match(/(?:min\s+tvl|tvl\s+above|minimum\s+tvl)[:\s]+\$?([\d,kmb]+)/i);
|
|
30
|
+
const chain = options?.chain || chainMatch?.[1]?.toLowerCase() || 'all';
|
|
31
|
+
const asset = options?.asset || assetMatch?.[1]?.toUpperCase();
|
|
32
|
+
const limit = options?.limit || 10;
|
|
33
|
+
// Parse min_tvl (supports "1m", "500k", etc.)
|
|
34
|
+
let minTvl = options?.min_tvl || 0;
|
|
35
|
+
if (minTvlMatch) {
|
|
36
|
+
const tvlStr = minTvlMatch[1].toLowerCase().replace(',', '');
|
|
37
|
+
if (tvlStr.endsWith('b'))
|
|
38
|
+
minTvl = parseFloat(tvlStr) * 1e9;
|
|
39
|
+
else if (tvlStr.endsWith('m'))
|
|
40
|
+
minTvl = parseFloat(tvlStr) * 1e6;
|
|
41
|
+
else if (tvlStr.endsWith('k'))
|
|
42
|
+
minTvl = parseFloat(tvlStr) * 1e3;
|
|
43
|
+
else
|
|
44
|
+
minTvl = parseFloat(tvlStr);
|
|
45
|
+
}
|
|
46
|
+
const params = { chain, limit };
|
|
47
|
+
if (asset)
|
|
48
|
+
params.asset = asset;
|
|
49
|
+
if (minTvl > 0)
|
|
50
|
+
params.min_tvl = minTvl;
|
|
51
|
+
const data = await x402ApiRequest('/api/yield-scanner', params, config);
|
|
52
|
+
const pools = data.data.slice(0, limit);
|
|
53
|
+
const poolLines = pools
|
|
54
|
+
.map((p, i) => {
|
|
55
|
+
const riskEmoji = RISK_EMOJIS[p.risk_tier];
|
|
56
|
+
const tvlFormatted = p.tvl >= 1e9 ? `$${(p.tvl / 1e9).toFixed(1)}B`
|
|
57
|
+
: p.tvl >= 1e6 ? `$${(p.tvl / 1e6).toFixed(0)}M`
|
|
58
|
+
: `$${(p.tvl / 1e3).toFixed(0)}K`;
|
|
59
|
+
return `${i + 1}. ${riskEmoji} **${p.protocol}** — ${p.asset} on ${p.chain}: **${p.apy}% APY** (TVL: ${tvlFormatted}, ${p.type})`;
|
|
60
|
+
})
|
|
61
|
+
.join('\n');
|
|
62
|
+
const response = `## 🌾 Yield Scanner${asset ? ` — ${asset}` : ''}${chain !== 'all' ? ` on ${chain}` : ''}\n\n` +
|
|
63
|
+
`${poolLines}\n\n` +
|
|
64
|
+
`*🟢 low risk 🟡 medium 🔴 high | ${data.total_results} results • ${data.timestamp}*`;
|
|
65
|
+
if (callback) {
|
|
66
|
+
await callback({ text: response, source: message.content.source });
|
|
67
|
+
}
|
|
68
|
+
return { success: true, text: response, data: data.data };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const errMsg = `Failed to scan yields: ${error.message}`;
|
|
72
|
+
if (callback)
|
|
73
|
+
await callback({ text: errMsg });
|
|
74
|
+
return { success: false, text: errMsg };
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
examples: [
|
|
78
|
+
[
|
|
79
|
+
{ name: '{{user}}', content: { text: 'What are the best DeFi yields right now?' } },
|
|
80
|
+
{ name: '{{agent}}', content: { text: '## 🌾 Yield Scanner\n\n1. 🔴 Camelot — GRAIL/ETH on arbitrum: 28.3% APY\n2. 🔴 Aerodrome — USDC/ETH on base: 22.1% APY\n3. 🔴 Ethena — sUSDe on ethereum: 18.5% APY', actions: ['SCAN_YIELDS'] } },
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
{ name: '{{user}}', content: { text: 'Find safe USDC yields on Base' } },
|
|
84
|
+
{ name: '{{agent}}', content: { text: 'Scanning USDC yield opportunities on Base...', actions: ['SCAN_YIELDS'] } },
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
{ name: '{{user}}', content: { text: 'Best staking rates for ETH?' } },
|
|
88
|
+
{ name: '{{agent}}', content: { text: 'Finding ETH yield opportunities across all chains...', actions: ['SCAN_YIELDS'] } },
|
|
89
|
+
],
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=yieldScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yieldScanner.js","sourceRoot":"","sources":["../../src/actions/yieldScanner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAC;AAYrE,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAW,CAAC;AAErE,MAAM,UAAU,wBAAwB,CAAC,MAAwB;IAC/D,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE;YACP,eA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E,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,0CAA0C,EAAE,EAAE;gBACnF,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,qKAAqK,EAAE,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE;aAC1O;YACD;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,+BAA+B,EAAE,EAAE;gBACxE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,8CAA8C,EAAE,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE;aACnH;YACD;gBACE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,6BAA6B,EAAE,EAAE;gBACtE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,sDAAsD,EAAE,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,EAAE;aAC3H;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 API Client
|
|
3
|
+
*
|
|
4
|
+
* Handles HTTP requests to the x402 DeFi API with x402 payment support.
|
|
5
|
+
*
|
|
6
|
+
* ## Payment Flow
|
|
7
|
+
*
|
|
8
|
+
* The x402 API uses the HTTP 402 Payment Required protocol:
|
|
9
|
+
* 1. Agent makes a request
|
|
10
|
+
* 2. Server returns 402 with payment details (amount, token, payTo address)
|
|
11
|
+
* 3. Agent pays via USDC on Base
|
|
12
|
+
* 4. Agent retries with payment proof header (X-PAYMENT)
|
|
13
|
+
* 5. Server validates payment and returns data
|
|
14
|
+
*
|
|
15
|
+
* ## Setup Options
|
|
16
|
+
*
|
|
17
|
+
* ### Option A: x402-fetch (Recommended for autonomous agents)
|
|
18
|
+
* Install x402-fetch and configure your wallet private key.
|
|
19
|
+
* The client will auto-handle the 402 flow transparently.
|
|
20
|
+
*
|
|
21
|
+
* ### Option B: Pre-authorized fetch
|
|
22
|
+
* If you have a pre-authorized session token from the x402 facilitator.
|
|
23
|
+
*
|
|
24
|
+
* ### Option C: Manual (for testing)
|
|
25
|
+
* Just make the request — you'll get the 402 details to handle manually.
|
|
26
|
+
*/
|
|
27
|
+
export declare const X402_API_BASE_URL = "https://x402-api.fly.dev";
|
|
28
|
+
export interface X402ClientConfig {
|
|
29
|
+
/**
|
|
30
|
+
* Base URL for the x402 API.
|
|
31
|
+
* @default 'https://x402-api.fly.dev'
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Wallet private key for automatic x402 payment handling.
|
|
36
|
+
* Required for autonomous payment. Keep this in your .env file!
|
|
37
|
+
* Used with x402-fetch to auto-pay 402 responses.
|
|
38
|
+
*/
|
|
39
|
+
walletPrivateKey?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Your wallet address (for display/logging purposes).
|
|
42
|
+
*/
|
|
43
|
+
walletAddress?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Request timeout in milliseconds.
|
|
46
|
+
* @default 30000
|
|
47
|
+
*/
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
}
|
|
50
|
+
export type FetchWithX402 = (url: string | URL, init?: RequestInit) => Promise<Response>;
|
|
51
|
+
/**
|
|
52
|
+
* Make a request to the x402 API.
|
|
53
|
+
*
|
|
54
|
+
* @param endpoint - API endpoint path (e.g. '/api/price-feed')
|
|
55
|
+
* @param params - Query parameters
|
|
56
|
+
* @param config - Client configuration
|
|
57
|
+
* @returns Parsed JSON response
|
|
58
|
+
* @throws Error with helpful message on 402 (payment required) or other errors
|
|
59
|
+
*/
|
|
60
|
+
export declare function x402ApiRequest<T>(endpoint: string, params: Record<string, string | number | undefined>, config?: X402ClientConfig): Promise<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Extract key information from a message for API parameters.
|
|
63
|
+
* Parses natural language to extract token symbols, addresses, chains, etc.
|
|
64
|
+
*/
|
|
65
|
+
export declare function extractParams(text: string): Record<string, string>;
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAqDzF;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,EACnD,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CAAC,CAAC,CAAC,CAuDZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBlE"}
|