@leashmarket/mcp-core 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/dist/helpers/base64-json.d.ts +9 -0
- package/dist/helpers/base64-json.d.ts.map +1 -0
- package/dist/helpers/base64-json.js +16 -0
- package/dist/helpers/base64-json.js.map +1 -0
- package/dist/helpers/discover-reputation.d.ts +118 -0
- package/dist/helpers/discover-reputation.d.ts.map +1 -0
- package/dist/helpers/discover-reputation.js +148 -0
- package/dist/helpers/discover-reputation.js.map +1 -0
- package/dist/helpers/index.d.ts +6 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/probe-payment-link.d.ts +22 -0
- package/dist/helpers/probe-payment-link.d.ts.map +1 -0
- package/dist/helpers/probe-payment-link.js +78 -0
- package/dist/helpers/probe-payment-link.js.map +1 -0
- package/dist/helpers/solana-address.d.ts +8 -0
- package/dist/helpers/solana-address.d.ts.map +1 -0
- package/dist/helpers/solana-address.js +15 -0
- package/dist/helpers/solana-address.js.map +1 -0
- package/dist/helpers/token-catalog.d.ts +35 -0
- package/dist/helpers/token-catalog.d.ts.map +1 -0
- package/dist/helpers/token-catalog.js +83 -0
- package/dist/helpers/token-catalog.js.map +1 -0
- package/dist/host.d.ts +326 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/tool.d.ts +64 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +40 -0
- package/dist/tool.js.map +1 -0
- package/dist/tools/check-balances.d.ts +2 -0
- package/dist/tools/check-balances.d.ts.map +1 -0
- package/dist/tools/check-balances.js +15 -0
- package/dist/tools/check-balances.js.map +1 -0
- package/dist/tools/create-payment-link.d.ts +2 -0
- package/dist/tools/create-payment-link.d.ts.map +1 -0
- package/dist/tools/create-payment-link.js +28 -0
- package/dist/tools/create-payment-link.js.map +1 -0
- package/dist/tools/daily-transactions.d.ts +26 -0
- package/dist/tools/daily-transactions.d.ts.map +1 -0
- package/dist/tools/daily-transactions.js +47 -0
- package/dist/tools/daily-transactions.js.map +1 -0
- package/dist/tools/discover.d.ts +2 -0
- package/dist/tools/discover.d.ts.map +1 -0
- package/dist/tools/discover.js +40 -0
- package/dist/tools/discover.js.map +1 -0
- package/dist/tools/get-identity.d.ts +2 -0
- package/dist/tools/get-identity.d.ts.map +1 -0
- package/dist/tools/get-identity.js +14 -0
- package/dist/tools/get-identity.js.map +1 -0
- package/dist/tools/get-receipt.d.ts +22 -0
- package/dist/tools/get-receipt.d.ts.map +1 -0
- package/dist/tools/get-receipt.js +41 -0
- package/dist/tools/get-receipt.js.map +1 -0
- package/dist/tools/get-spend-limit.d.ts +14 -0
- package/dist/tools/get-spend-limit.d.ts.map +1 -0
- package/dist/tools/get-spend-limit.js +31 -0
- package/dist/tools/get-spend-limit.js.map +1 -0
- package/dist/tools/index.d.ts +28 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +43 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/pay-payment-link.d.ts +2 -0
- package/dist/tools/pay-payment-link.d.ts.map +1 -0
- package/dist/tools/pay-payment-link.js +18 -0
- package/dist/tools/pay-payment-link.js.map +1 -0
- package/dist/tools/pay-skills-endpoints.d.ts +2 -0
- package/dist/tools/pay-skills-endpoints.d.ts.map +1 -0
- package/dist/tools/pay-skills-endpoints.js +28 -0
- package/dist/tools/pay-skills-endpoints.js.map +1 -0
- package/dist/tools/receipts.d.ts +2 -0
- package/dist/tools/receipts.d.ts.map +1 -0
- package/dist/tools/receipts.js +26 -0
- package/dist/tools/receipts.js.map +1 -0
- package/dist/tools/register-agent.d.ts +2 -0
- package/dist/tools/register-agent.d.ts.map +1 -0
- package/dist/tools/register-agent.js +62 -0
- package/dist/tools/register-agent.js.map +1 -0
- package/dist/tools/reputation.d.ts +2 -0
- package/dist/tools/reputation.d.ts.map +1 -0
- package/dist/tools/reputation.js +24 -0
- package/dist/tools/reputation.js.map +1 -0
- package/dist/tools/set-spend-limit.d.ts +23 -0
- package/dist/tools/set-spend-limit.d.ts.map +1 -0
- package/dist/tools/set-spend-limit.js +52 -0
- package/dist/tools/set-spend-limit.js.map +1 -0
- package/dist/tools/transaction-history.d.ts +23 -0
- package/dist/tools/transaction-history.d.ts.map +1 -0
- package/dist/tools/transaction-history.js +55 -0
- package/dist/tools/transaction-history.js.map +1 -0
- package/dist/tools/withdraw-treasury.d.ts +2 -0
- package/dist/tools/withdraw-treasury.d.ts.map +1 -0
- package/dist/tools/withdraw-treasury.js +29 -0
- package/dist/tools/withdraw-treasury.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode a base64url-or-base64 JSON blob (the encoding the x402
|
|
3
|
+
* `payment-required` header uses). Tolerates missing padding.
|
|
4
|
+
*
|
|
5
|
+
* Throws if the input isn't decodable / parseable JSON — callers
|
|
6
|
+
* should turn that into a clean `error` tool result.
|
|
7
|
+
*/
|
|
8
|
+
export declare function decodeBase64Json(input: string): unknown;
|
|
9
|
+
//# sourceMappingURL=base64-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-json.d.ts","sourceRoot":"","sources":["../../src/helpers/base64-json.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAQvD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode a base64url-or-base64 JSON blob (the encoding the x402
|
|
3
|
+
* `payment-required` header uses). Tolerates missing padding.
|
|
4
|
+
*
|
|
5
|
+
* Throws if the input isn't decodable / parseable JSON — callers
|
|
6
|
+
* should turn that into a clean `error` tool result.
|
|
7
|
+
*/
|
|
8
|
+
export function decodeBase64Json(input) {
|
|
9
|
+
const normalized = input.replace(/-/g, '+').replace(/_/g, '/');
|
|
10
|
+
const padded = normalized + '='.repeat((4 - (normalized.length % 4)) % 4);
|
|
11
|
+
const raw = typeof globalThis.atob === 'function'
|
|
12
|
+
? globalThis.atob(padded)
|
|
13
|
+
: Buffer.from(padded, 'base64').toString('utf8');
|
|
14
|
+
return JSON.parse(raw);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=base64-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-json.js","sourceRoot":"","sources":["../../src/helpers/base64-json.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/D,MAAM,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,MAAM,GAAG,GACP,OAAO,UAAU,CAAC,IAAI,KAAK,UAAU;QACnC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;QACzB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HTTP wrappers for the public `/v1/discover` and
|
|
3
|
+
* `/v1/agents/:mint/reputation` endpoints.
|
|
4
|
+
*
|
|
5
|
+
* Both surfaces (chat product + standalone MCP) call the same
|
|
6
|
+
* Leash API; nothing host-specific happens here, so the fetcher
|
|
7
|
+
* lives in the host-agnostic core. Adapters call these from their
|
|
8
|
+
* `LeashHost.discover` / `LeashHost.reputation` methods.
|
|
9
|
+
*/
|
|
10
|
+
import type { LeashToolResult } from '../tool.js';
|
|
11
|
+
import type { DiscoverArgs, PaySkillsProviderArgs, ReputationArgs, SvmNetwork } from '../host.js';
|
|
12
|
+
export type DiscoverSource = 'leash' | 'pay-skills';
|
|
13
|
+
export type DiscoverItem = {
|
|
14
|
+
/**
|
|
15
|
+
* Catalogue this entry came from. `'leash'` items are agents listed
|
|
16
|
+
* on the Leash marketplace; `'pay-skills'` items come from the
|
|
17
|
+
* Solana Foundation `pay-skills` registry and have no on-chain
|
|
18
|
+
* seller identity.
|
|
19
|
+
*/
|
|
20
|
+
source: DiscoverSource;
|
|
21
|
+
url: string;
|
|
22
|
+
title: string;
|
|
23
|
+
description: string;
|
|
24
|
+
slug: string;
|
|
25
|
+
category: string;
|
|
26
|
+
price_usdc: string | null;
|
|
27
|
+
pricing_type: 'free' | 'per_call' | 'variable';
|
|
28
|
+
seller_agent_mint: string | null;
|
|
29
|
+
/** Owner wallet for Leash entries; null for pay-skills entries. */
|
|
30
|
+
seller_wallet: string | null;
|
|
31
|
+
rating: number | null;
|
|
32
|
+
health_status: 'ok' | 'warn' | 'down' | null;
|
|
33
|
+
tags: string[];
|
|
34
|
+
tools: Array<{
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
export type ReputationSnapshot = {
|
|
40
|
+
agent_mint: string;
|
|
41
|
+
network: SvmNetwork;
|
|
42
|
+
total_volume_usdc: string;
|
|
43
|
+
settled_calls: number;
|
|
44
|
+
denied_calls: number;
|
|
45
|
+
distinct_counterparties: number;
|
|
46
|
+
dispute_rate: number;
|
|
47
|
+
oldest_receipt_at: string | null;
|
|
48
|
+
newest_receipt_at: string | null;
|
|
49
|
+
rating: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* GET /v1/discover. Returns the parsed payload as a `kind:
|
|
53
|
+
* 'discover'` tool result so callers can return it verbatim.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fetchDiscover(args: {
|
|
56
|
+
apiBaseUrl: string;
|
|
57
|
+
network: SvmNetwork;
|
|
58
|
+
query: DiscoverArgs;
|
|
59
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
60
|
+
}): Promise<LeashToolResult>;
|
|
61
|
+
export type PaySkillsEndpoint = {
|
|
62
|
+
method: string;
|
|
63
|
+
path: string;
|
|
64
|
+
url: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
resource?: string;
|
|
67
|
+
pricing?: {
|
|
68
|
+
mode?: string;
|
|
69
|
+
dimensions?: Array<{
|
|
70
|
+
direction?: string;
|
|
71
|
+
scale?: number;
|
|
72
|
+
unit?: string;
|
|
73
|
+
tiers?: Array<{
|
|
74
|
+
price_usd?: number;
|
|
75
|
+
threshold?: number;
|
|
76
|
+
}>;
|
|
77
|
+
}>;
|
|
78
|
+
} | null;
|
|
79
|
+
protocol?: string[];
|
|
80
|
+
supported_usd?: string[];
|
|
81
|
+
probe_status?: string;
|
|
82
|
+
probe_description?: string;
|
|
83
|
+
};
|
|
84
|
+
export type PaySkillsProvider = {
|
|
85
|
+
fqn: string;
|
|
86
|
+
title: string;
|
|
87
|
+
description: string;
|
|
88
|
+
use_case?: string;
|
|
89
|
+
category: string;
|
|
90
|
+
service_url: string;
|
|
91
|
+
version?: string;
|
|
92
|
+
endpoints: PaySkillsEndpoint[];
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* GET /v1/discover/pay-skills/:fqn. Expands a chosen pay-skills
|
|
96
|
+
* provider into its endpoints[] so the agent can pay individual
|
|
97
|
+
* paid endpoints (the second hop in pay.sh's `search_skills →
|
|
98
|
+
* get_skill_endpoints → curl` flow).
|
|
99
|
+
*
|
|
100
|
+
* Returns a `kind: 'pay_skills_provider'` tool result.
|
|
101
|
+
*/
|
|
102
|
+
export declare function fetchPaySkillsProvider(args: {
|
|
103
|
+
apiBaseUrl: string;
|
|
104
|
+
network: SvmNetwork;
|
|
105
|
+
query: PaySkillsProviderArgs;
|
|
106
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
107
|
+
}): Promise<LeashToolResult>;
|
|
108
|
+
/**
|
|
109
|
+
* GET /v1/agents/:mint/reputation. Returns a `kind: 'reputation'`
|
|
110
|
+
* tool result for direct surfacing to the LLM.
|
|
111
|
+
*/
|
|
112
|
+
export declare function fetchReputation(args: {
|
|
113
|
+
apiBaseUrl: string;
|
|
114
|
+
network: SvmNetwork;
|
|
115
|
+
query: ReputationArgs;
|
|
116
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
117
|
+
}): Promise<LeashToolResult>;
|
|
118
|
+
//# sourceMappingURL=discover-reputation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-reputation.d.ts","sourceRoot":"","sources":["../../src/helpers/discover-reputation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAElG,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,YAAY,CAAC;AAEpD,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;OAKG;IACH,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;IAC/C,iBAAiB,EA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;CACrC,GAAG,OAAO,CAAC,eAAe,CAAC,CA+B3B"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HTTP wrappers for the public `/v1/discover` and
|
|
3
|
+
* `/v1/agents/:mint/reputation` endpoints.
|
|
4
|
+
*
|
|
5
|
+
* Both surfaces (chat product + standalone MCP) call the same
|
|
6
|
+
* Leash API; nothing host-specific happens here, so the fetcher
|
|
7
|
+
* lives in the host-agnostic core. Adapters call these from their
|
|
8
|
+
* `LeashHost.discover` / `LeashHost.reputation` methods.
|
|
9
|
+
*/
|
|
10
|
+
import { jsonResult } from '../tool.js';
|
|
11
|
+
/**
|
|
12
|
+
* GET /v1/discover. Returns the parsed payload as a `kind:
|
|
13
|
+
* 'discover'` tool result so callers can return it verbatim.
|
|
14
|
+
*/
|
|
15
|
+
export async function fetchDiscover(args) {
|
|
16
|
+
const fetchImpl = args.fetchImpl ?? globalThis.fetch;
|
|
17
|
+
const url = new URL(`${args.apiBaseUrl.replace(/\/+$/, '')}/v1/discover`);
|
|
18
|
+
if (args.query.capability)
|
|
19
|
+
url.searchParams.set('capability', args.query.capability);
|
|
20
|
+
if (args.query.max_price_usdc != null) {
|
|
21
|
+
url.searchParams.set('max_price_usdc', String(args.query.max_price_usdc));
|
|
22
|
+
}
|
|
23
|
+
if (args.query.pricing_type)
|
|
24
|
+
url.searchParams.set('pricing_type', args.query.pricing_type);
|
|
25
|
+
if (args.query.source)
|
|
26
|
+
url.searchParams.set('source', args.query.source);
|
|
27
|
+
if (args.query.limit)
|
|
28
|
+
url.searchParams.set('limit', String(args.query.limit));
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetchImpl(url);
|
|
31
|
+
const text = await res.text();
|
|
32
|
+
if (!res.ok) {
|
|
33
|
+
return jsonResult({
|
|
34
|
+
kind: 'discover',
|
|
35
|
+
status: 'error',
|
|
36
|
+
message: `Leash API ${res.status}: ${text.slice(0, 300)}`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const payload = JSON.parse(text);
|
|
40
|
+
return jsonResult({
|
|
41
|
+
kind: 'discover',
|
|
42
|
+
status: 'ok',
|
|
43
|
+
network: args.network,
|
|
44
|
+
query: args.query,
|
|
45
|
+
count: payload.items.length,
|
|
46
|
+
items: payload.items,
|
|
47
|
+
next_cursor: payload.next_cursor,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
return jsonResult({
|
|
52
|
+
kind: 'discover',
|
|
53
|
+
status: 'error',
|
|
54
|
+
message: err instanceof Error ? err.message : 'unknown error',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* GET /v1/discover/pay-skills/:fqn. Expands a chosen pay-skills
|
|
60
|
+
* provider into its endpoints[] so the agent can pay individual
|
|
61
|
+
* paid endpoints (the second hop in pay.sh's `search_skills →
|
|
62
|
+
* get_skill_endpoints → curl` flow).
|
|
63
|
+
*
|
|
64
|
+
* Returns a `kind: 'pay_skills_provider'` tool result.
|
|
65
|
+
*/
|
|
66
|
+
export async function fetchPaySkillsProvider(args) {
|
|
67
|
+
const fetchImpl = args.fetchImpl ?? globalThis.fetch;
|
|
68
|
+
const fqn = args.query.fqn.trim().replace(/^\/+|\/+$/g, '');
|
|
69
|
+
if (!fqn || !fqn.includes('/')) {
|
|
70
|
+
return jsonResult({
|
|
71
|
+
kind: 'pay_skills_provider',
|
|
72
|
+
status: 'error',
|
|
73
|
+
message: `pay-skills FQN must include at least one '/' (got "${args.query.fqn}")`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const segs = fqn
|
|
77
|
+
.split('/')
|
|
78
|
+
.map((s) => encodeURIComponent(s))
|
|
79
|
+
.join('/');
|
|
80
|
+
const url = `${args.apiBaseUrl.replace(/\/+$/, '')}/v1/discover/pay-skills/${segs}`;
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetchImpl(url);
|
|
83
|
+
const text = await res.text();
|
|
84
|
+
if (res.status === 404) {
|
|
85
|
+
return jsonResult({
|
|
86
|
+
kind: 'pay_skills_provider',
|
|
87
|
+
status: 'error',
|
|
88
|
+
message: `pay-skills provider not found: ${fqn}`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (!res.ok) {
|
|
92
|
+
return jsonResult({
|
|
93
|
+
kind: 'pay_skills_provider',
|
|
94
|
+
status: 'error',
|
|
95
|
+
message: `Leash API ${res.status}: ${text.slice(0, 300)}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const payload = JSON.parse(text);
|
|
99
|
+
return jsonResult({
|
|
100
|
+
kind: 'pay_skills_provider',
|
|
101
|
+
status: 'ok',
|
|
102
|
+
network: args.network,
|
|
103
|
+
...payload,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
return jsonResult({
|
|
108
|
+
kind: 'pay_skills_provider',
|
|
109
|
+
status: 'error',
|
|
110
|
+
message: err instanceof Error ? err.message : 'unknown error',
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* GET /v1/agents/:mint/reputation. Returns a `kind: 'reputation'`
|
|
116
|
+
* tool result for direct surfacing to the LLM.
|
|
117
|
+
*/
|
|
118
|
+
export async function fetchReputation(args) {
|
|
119
|
+
const fetchImpl = args.fetchImpl ?? globalThis.fetch;
|
|
120
|
+
const network = args.query.network ?? args.network;
|
|
121
|
+
const url = new URL(`${args.apiBaseUrl.replace(/\/+$/, '')}/v1/agents/${encodeURIComponent(args.query.agent_mint)}/reputation`);
|
|
122
|
+
url.searchParams.set('network', network);
|
|
123
|
+
try {
|
|
124
|
+
const res = await fetchImpl(url);
|
|
125
|
+
const text = await res.text();
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
return jsonResult({
|
|
128
|
+
kind: 'reputation',
|
|
129
|
+
status: 'error',
|
|
130
|
+
message: `Leash API ${res.status}: ${text.slice(0, 300)}`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const payload = JSON.parse(text);
|
|
134
|
+
return jsonResult({
|
|
135
|
+
kind: 'reputation',
|
|
136
|
+
status: 'ok',
|
|
137
|
+
...payload,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
return jsonResult({
|
|
142
|
+
kind: 'reputation',
|
|
143
|
+
status: 'error',
|
|
144
|
+
message: err instanceof Error ? err.message : 'unknown error',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=discover-reputation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-reputation.js","sourceRoot":"","sources":["../../src/helpers/discover-reputation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0CxC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAKnC;IACC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC;IACrD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC;IAC1E,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU;QAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACrF,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC;QACtC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY;QAAE,GAAG,CAAC,YAAY,CAAC,GA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zC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,OAAO,UAAU,CAAC;gBAChB,IAAI,EAAE,YAAY;gBAClB,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,aAAa,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;aAC1D,CAAC,CAAC;QACL,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAuB,CAAC;QACvD,OAAO,UAAU,CAAC;YAChB,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,IAAI;YACZ,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,UAAU,CAAC;YAChB,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;SAC9D,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { isLikelyBase58Address } from './solana-address.js';
|
|
2
|
+
export { lookupTokenBySymbolSafe, symbolForMintSafe, type TokenMeta, type TokenProgramId, } from './token-catalog.js';
|
|
3
|
+
export { decodeBase64Json } from './base64-json.js';
|
|
4
|
+
export { probePaymentLink, type PaymentRequirementPreview } from './probe-payment-link.js';
|
|
5
|
+
export { fetchDiscover, fetchPaySkillsProvider, fetchReputation, type DiscoverItem, type DiscoverSource, type PaySkillsEndpoint, type PaySkillsProvider, type ReputationSnapshot, } from './discover-reputation.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,KAAK,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { isLikelyBase58Address } from './solana-address.js';
|
|
2
|
+
export { lookupTokenBySymbolSafe, symbolForMintSafe, } from './token-catalog.js';
|
|
3
|
+
export { decodeBase64Json } from './base64-json.js';
|
|
4
|
+
export { probePaymentLink } from './probe-payment-link.js';
|
|
5
|
+
export { fetchDiscover, fetchPaySkillsProvider, fetchReputation, } from './discover-reputation.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAGlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAkC,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,eAAe,GAMhB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET an x402 payment link and decode the `payment-required` header
|
|
3
|
+
* into a typed preview the buyer-side artifact (or the MCP `pay`
|
|
4
|
+
* implementation) can consume.
|
|
5
|
+
*
|
|
6
|
+
* The paywall always serves a single-network link, so we pick the
|
|
7
|
+
* `accepts[]` entry whose network matches the URL's `?network=`
|
|
8
|
+
* query (with a lenient fallback to `accepts[0]`).
|
|
9
|
+
*
|
|
10
|
+
* Throws on every error path so callers can wrap once and surface
|
|
11
|
+
* the message verbatim to the model.
|
|
12
|
+
*/
|
|
13
|
+
export type PaymentRequirementPreview = {
|
|
14
|
+
network: string;
|
|
15
|
+
pay_to: string;
|
|
16
|
+
asset: string;
|
|
17
|
+
amount_atomic: string;
|
|
18
|
+
currency: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function probePaymentLink(url: string): Promise<PaymentRequirementPreview>;
|
|
22
|
+
//# sourceMappingURL=probe-payment-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe-payment-link.d.ts","sourceRoot":"","sources":["../../src/helpers/probe-payment-link.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAcF,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAqEtF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET an x402 payment link and decode the `payment-required` header
|
|
3
|
+
* into a typed preview the buyer-side artifact (or the MCP `pay`
|
|
4
|
+
* implementation) can consume.
|
|
5
|
+
*
|
|
6
|
+
* The paywall always serves a single-network link, so we pick the
|
|
7
|
+
* `accepts[]` entry whose network matches the URL's `?network=`
|
|
8
|
+
* query (with a lenient fallback to `accepts[0]`).
|
|
9
|
+
*
|
|
10
|
+
* Throws on every error path so callers can wrap once and surface
|
|
11
|
+
* the message verbatim to the model.
|
|
12
|
+
*/
|
|
13
|
+
import { decodeBase64Json } from './base64-json.js';
|
|
14
|
+
import { symbolForMintSafe } from './token-catalog.js';
|
|
15
|
+
/**
|
|
16
|
+
* Reverse-lookup a ticker by mint trying *both* network buckets. The
|
|
17
|
+
* x402 envelope's `network` field is often a CAIP-2 chain reference
|
|
18
|
+
* like `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (the genesis hash of
|
|
19
|
+
* Solana devnet), not the friendly `solana-devnet` slug — so a literal
|
|
20
|
+
* `/devnet/i` heuristic misses every CAIP-2 quote. Stable mints are
|
|
21
|
+
* disjoint across mainnet/devnet so this is safe.
|
|
22
|
+
*/
|
|
23
|
+
function symbolForMintAnyNetwork(mint) {
|
|
24
|
+
return symbolForMintSafe(mint, 'devnet') ?? symbolForMintSafe(mint, 'mainnet') ?? null;
|
|
25
|
+
}
|
|
26
|
+
export async function probePaymentLink(url) {
|
|
27
|
+
const res = await fetch(url, { method: 'GET' });
|
|
28
|
+
if (res.status !== 402) {
|
|
29
|
+
throw new Error(`expected 402 from paywall, got HTTP ${res.status}`);
|
|
30
|
+
}
|
|
31
|
+
const header = res.headers.get('payment-required') ?? res.headers.get('PAYMENT-REQUIRED');
|
|
32
|
+
if (!header) {
|
|
33
|
+
throw new Error('seller did not send a `payment-required` header');
|
|
34
|
+
}
|
|
35
|
+
const decoded = decodeBase64Json(header);
|
|
36
|
+
if (!decoded || !Array.isArray(decoded.accepts) || decoded.accepts.length === 0) {
|
|
37
|
+
throw new Error(decoded?.error ?? 'malformed payment-required header');
|
|
38
|
+
}
|
|
39
|
+
const wantNetwork = (() => {
|
|
40
|
+
try {
|
|
41
|
+
const u = new URL(url);
|
|
42
|
+
return u.searchParams.get('network') ?? null;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
const chosen = (wantNetwork
|
|
49
|
+
? decoded.accepts.find((a) => (a.network ?? '')
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.includes(wantNetwork.replace('solana-', '').toLowerCase()))
|
|
52
|
+
: null) ?? decoded.accepts[0];
|
|
53
|
+
if (!chosen.network || !chosen.payTo || !chosen.asset || !chosen.amount) {
|
|
54
|
+
throw new Error('payment-required entry missing required fields');
|
|
55
|
+
}
|
|
56
|
+
// Currency resolution order:
|
|
57
|
+
// 1. explicit `currency` on the chosen accept (extension surface;
|
|
58
|
+
// vanilla x402 envelopes don't carry it, but we look anyway),
|
|
59
|
+
// 2. catalog reverse-lookup keyed by the asset mint (covers every
|
|
60
|
+
// Leash-self-hosted x402 link since the API shapes 402 quotes
|
|
61
|
+
// from the catalogued USDC/USDG/USDT mint),
|
|
62
|
+
// 3. last-resort 'USDC' so the model never sees an empty ticker.
|
|
63
|
+
// The previous unconditional `?? 'USDC'` mis-labelled USDG/USDT links
|
|
64
|
+
// and caused buyer-kit to ask for the wrong asset → `preferred_asset_unavailable`.
|
|
65
|
+
const fromRegistry = symbolForMintAnyNetwork(chosen.asset);
|
|
66
|
+
const currency = chosen.currency ?? fromRegistry ?? 'USDC';
|
|
67
|
+
const out = {
|
|
68
|
+
network: chosen.network,
|
|
69
|
+
pay_to: chosen.payTo,
|
|
70
|
+
asset: chosen.asset,
|
|
71
|
+
amount_atomic: chosen.amount,
|
|
72
|
+
currency,
|
|
73
|
+
};
|
|
74
|
+
if (chosen.description)
|
|
75
|
+
out.description = chosen.description;
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=probe-payment-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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EAAE,MAAM,CAAC,MAAM;QAC5B,QAAQ;KACT,CAAC;IACF,IAAI,MAAM,CAAC,WAAW;QAAE,GAAG,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IAC7D,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cheap base58 sanity check — Solana pubkeys are 32–44 base58 chars.
|
|
3
|
+
* Rejects obvious typos (whitespace, '0OIl' confusables) so we don't
|
|
4
|
+
* silently pass garbage to the chain. The real signature check happens
|
|
5
|
+
* downstream (in the buyer-kit / mpl-core::Execute instruction).
|
|
6
|
+
*/
|
|
7
|
+
export declare function isLikelyBase58Address(s: string): boolean;
|
|
8
|
+
//# sourceMappingURL=solana-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-address.d.ts","sourceRoot":"","sources":["../../src/helpers/solana-address.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAKxD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cheap base58 sanity check — Solana pubkeys are 32–44 base58 chars.
|
|
3
|
+
* Rejects obvious typos (whitespace, '0OIl' confusables) so we don't
|
|
4
|
+
* silently pass garbage to the chain. The real signature check happens
|
|
5
|
+
* downstream (in the buyer-kit / mpl-core::Execute instruction).
|
|
6
|
+
*/
|
|
7
|
+
export function isLikelyBase58Address(s) {
|
|
8
|
+
if (typeof s !== 'string')
|
|
9
|
+
return false;
|
|
10
|
+
const trimmed = s.trim();
|
|
11
|
+
if (trimmed.length < 32 || trimmed.length > 44)
|
|
12
|
+
return false;
|
|
13
|
+
return /^[1-9A-HJ-NP-Za-km-z]+$/.test(trimmed);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=solana-address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-address.js","sourceRoot":"","sources":["../../src/helpers/solana-address.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,CAAS;IAC7C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACxC,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACzB,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static catalogue of the SPL stablecoins Leash treasuries
|
|
3
|
+
* understand. Mirrors `apps/agents/lib/agents/leash-mcp.ts` so the
|
|
4
|
+
* shared withdraw tool can resolve `mint`, `decimals`, and `program`
|
|
5
|
+
* without taking a hard import dep on `@leashmarket/core/tokens` (which
|
|
6
|
+
* pulls in the full mpl-toolbox graph and is heavier than what an
|
|
7
|
+
* MCP STDIO server should bundle).
|
|
8
|
+
*
|
|
9
|
+
* Mints + program ids are static and operationally stable; if a
|
|
10
|
+
* stablecoin reissues, update the table here AND in
|
|
11
|
+
* `apps/api/src/lib/faucet.ts::FAUCET_TOKENS`.
|
|
12
|
+
*/
|
|
13
|
+
export type TokenProgramId = 'spl-token' | 'spl-token-2022';
|
|
14
|
+
export type TokenMeta = {
|
|
15
|
+
symbol: 'USDC' | 'USDG' | 'USDT';
|
|
16
|
+
mint: string;
|
|
17
|
+
decimals: number;
|
|
18
|
+
program: TokenProgramId;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Look up a stablecoin by symbol on the requested cluster. Returns
|
|
22
|
+
* `null` when the symbol isn't catalogued — callers should surface a
|
|
23
|
+
* "try USDC/USDG/USDT" error verbatim to the model.
|
|
24
|
+
*/
|
|
25
|
+
export declare function lookupTokenBySymbolSafe(symbol: string, network: 'mainnet' | 'devnet'): TokenMeta | null;
|
|
26
|
+
/**
|
|
27
|
+
* Reverse-lookup: given an SPL mint, return the catalogued ticker
|
|
28
|
+
* (`USDC` | `USDG` | `USDT`) or `null` when the mint is unknown. Used
|
|
29
|
+
* by `probePaymentLink` to label an x402 quote correctly when the
|
|
30
|
+
* seller omits the optional `currency` field — without this we were
|
|
31
|
+
* mis-labelling USDG/USDT links as USDC, then asking buyer-kit to
|
|
32
|
+
* pay in the wrong asset (`preferred_asset_unavailable`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function symbolForMintSafe(mint: string, network: 'mainnet' | 'devnet'): TokenMeta['symbol'] | null;
|
|
35
|
+
//# sourceMappingURL=token-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-catalog.d.ts","sourceRoot":"","sources":["../../src/helpers/token-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,gBAAgB,CAAC;AAE5D,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AA6CF;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,GAAG,QAAQ,GAC5B,SAAS,GAAG,IAAI,CAKlB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,GAAG,QAAQ,GAC5B,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAM5B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static catalogue of the SPL stablecoins Leash treasuries
|
|
3
|
+
* understand. Mirrors `apps/agents/lib/agents/leash-mcp.ts` so the
|
|
4
|
+
* shared withdraw tool can resolve `mint`, `decimals`, and `program`
|
|
5
|
+
* without taking a hard import dep on `@leashmarket/core/tokens` (which
|
|
6
|
+
* pulls in the full mpl-toolbox graph and is heavier than what an
|
|
7
|
+
* MCP STDIO server should bundle).
|
|
8
|
+
*
|
|
9
|
+
* Mints + program ids are static and operationally stable; if a
|
|
10
|
+
* stablecoin reissues, update the table here AND in
|
|
11
|
+
* `apps/api/src/lib/faucet.ts::FAUCET_TOKENS`.
|
|
12
|
+
*/
|
|
13
|
+
const CATALOG = {
|
|
14
|
+
mainnet: {
|
|
15
|
+
USDC: {
|
|
16
|
+
symbol: 'USDC',
|
|
17
|
+
mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
18
|
+
decimals: 6,
|
|
19
|
+
program: 'spl-token',
|
|
20
|
+
},
|
|
21
|
+
USDT: {
|
|
22
|
+
symbol: 'USDT',
|
|
23
|
+
mint: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
|
|
24
|
+
decimals: 6,
|
|
25
|
+
program: 'spl-token',
|
|
26
|
+
},
|
|
27
|
+
USDG: {
|
|
28
|
+
symbol: 'USDG',
|
|
29
|
+
mint: '2u1tszSeqZ3qBWF3uNGPFc8TzMk2tdiwknnRMWGWjGWH',
|
|
30
|
+
decimals: 6,
|
|
31
|
+
program: 'spl-token-2022',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
devnet: {
|
|
35
|
+
USDC: {
|
|
36
|
+
symbol: 'USDC',
|
|
37
|
+
mint: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',
|
|
38
|
+
decimals: 6,
|
|
39
|
+
program: 'spl-token',
|
|
40
|
+
},
|
|
41
|
+
USDT: {
|
|
42
|
+
symbol: 'USDT',
|
|
43
|
+
mint: 'EcFc2cMyZxaKBkFK1XooxiyDyCPneLXiMwSJiVY6eTad',
|
|
44
|
+
decimals: 6,
|
|
45
|
+
program: 'spl-token',
|
|
46
|
+
},
|
|
47
|
+
USDG: {
|
|
48
|
+
symbol: 'USDG',
|
|
49
|
+
mint: '4F6PM96JJxngmHnZLBh9n58RH4aTVNWvDs2nuwrT5BP7',
|
|
50
|
+
decimals: 6,
|
|
51
|
+
program: 'spl-token-2022',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Look up a stablecoin by symbol on the requested cluster. Returns
|
|
57
|
+
* `null` when the symbol isn't catalogued — callers should surface a
|
|
58
|
+
* "try USDC/USDG/USDT" error verbatim to the model.
|
|
59
|
+
*/
|
|
60
|
+
export function lookupTokenBySymbolSafe(symbol, network) {
|
|
61
|
+
const upper = symbol.trim().toUpperCase();
|
|
62
|
+
const hit = CATALOG[network][upper];
|
|
63
|
+
if (!hit)
|
|
64
|
+
return null;
|
|
65
|
+
return hit;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reverse-lookup: given an SPL mint, return the catalogued ticker
|
|
69
|
+
* (`USDC` | `USDG` | `USDT`) or `null` when the mint is unknown. Used
|
|
70
|
+
* by `probePaymentLink` to label an x402 quote correctly when the
|
|
71
|
+
* seller omits the optional `currency` field — without this we were
|
|
72
|
+
* mis-labelling USDG/USDT links as USDC, then asking buyer-kit to
|
|
73
|
+
* pay in the wrong asset (`preferred_asset_unavailable`).
|
|
74
|
+
*/
|
|
75
|
+
export function symbolForMintSafe(mint, network) {
|
|
76
|
+
const trimmed = mint.trim();
|
|
77
|
+
for (const meta of Object.values(CATALOG[network])) {
|
|
78
|
+
if (meta.mint === trimmed)
|
|
79
|
+
return meta.symbol;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=token-catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-catalog.js","s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