@telaro/sdk 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/CHANGELOG.md +27 -0
- package/QUICKSTART.md +216 -0
- package/README.md +129 -0
- package/dist/accounts.d.ts +51 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +169 -0
- package/dist/accounts.js.map +1 -0
- package/dist/api.d.ts +177 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +158 -0
- package/dist/api.js.map +1 -0
- package/dist/borsh.d.ts +33 -0
- package/dist/borsh.d.ts.map +1 -0
- package/dist/borsh.js +100 -0
- package/dist/borsh.js.map +1 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +164 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +46 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +47 -0
- package/dist/constants.js.map +1 -0
- package/dist/credit.d.ts +61 -0
- package/dist/credit.d.ts.map +1 -0
- package/dist/credit.js +133 -0
- package/dist/credit.js.map +1 -0
- package/dist/decimal.d.ts +36 -0
- package/dist/decimal.d.ts.map +1 -0
- package/dist/decimal.js +87 -0
- package/dist/decimal.js.map +1 -0
- package/dist/discriminators.d.ts +86 -0
- package/dist/discriminators.d.ts.map +1 -0
- package/dist/discriminators.js +100 -0
- package/dist/discriminators.js.map +1 -0
- package/dist/events.d.ts +268 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +223 -0
- package/dist/events.js.map +1 -0
- package/dist/format.d.ts +10 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +39 -0
- package/dist/format.js.map +1 -0
- package/dist/hash.d.ts +9 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +33 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +368 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +841 -0
- package/dist/instructions.js.map +1 -0
- package/dist/metaplex.d.ts +64 -0
- package/dist/metaplex.d.ts.map +1 -0
- package/dist/metaplex.js +123 -0
- package/dist/metaplex.js.map +1 -0
- package/dist/pda.d.ts +35 -0
- package/dist/pda.d.ts.map +1 -0
- package/dist/pda.js +84 -0
- package/dist/pda.js.map +1 -0
- package/dist/realtime.d.ts +67 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +112 -0
- package/dist/realtime.js.map +1 -0
- package/dist/score.d.ts +51 -0
- package/dist/score.d.ts.map +1 -0
- package/dist/score.js +63 -0
- package/dist/score.js.map +1 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/package.json +88 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed HTTP client for the public Telaro REST API.
|
|
3
|
+
*
|
|
4
|
+
* DApps that just want to *read* trust data should use this — no Anchor,
|
|
5
|
+
* no wallet, no Solana SDK. For writing (register/record/claim/resolve),
|
|
6
|
+
* use {@link TelaroClient} or the `build*Ix` builders.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { TelaroApi } from "@telaro/sdk";
|
|
11
|
+
*
|
|
12
|
+
* const api = new TelaroApi("https://telaro.xyz");
|
|
13
|
+
*
|
|
14
|
+
* const top = await api.leaderboard({ limit: 5 });
|
|
15
|
+
* console.log(`TVL: $${top.ecosystem.bond_tvl_human}`);
|
|
16
|
+
*
|
|
17
|
+
* const agent = await api.agent("AgentSenda1JupiterLPv3...");
|
|
18
|
+
* if (agent && agent.score >= 700 && !agent.frozen) {
|
|
19
|
+
* // safe to delegate
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export interface ApiAgentSummary {
|
|
24
|
+
pubkey: string;
|
|
25
|
+
controller: string;
|
|
26
|
+
framework: string;
|
|
27
|
+
name: string;
|
|
28
|
+
score: number;
|
|
29
|
+
score_tier: "high" | "medium" | "low";
|
|
30
|
+
bond_atomic: string;
|
|
31
|
+
bond_human: number;
|
|
32
|
+
action_count: number;
|
|
33
|
+
success_count: number;
|
|
34
|
+
failed_count: number;
|
|
35
|
+
disputed_count: number;
|
|
36
|
+
success_rate: number;
|
|
37
|
+
bonded_since: number;
|
|
38
|
+
last_action_at: number;
|
|
39
|
+
value_handled_30d: string;
|
|
40
|
+
open_claims: number;
|
|
41
|
+
frozen: boolean;
|
|
42
|
+
network: "devnet" | "mainnet-beta";
|
|
43
|
+
/** True when the response is served from mock data (no indexer wired). */
|
|
44
|
+
is_mock?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ApiAgentDetail {
|
|
47
|
+
agent: ApiAgentSummary & {
|
|
48
|
+
image_url: string;
|
|
49
|
+
};
|
|
50
|
+
actions: Array<{
|
|
51
|
+
signature: string;
|
|
52
|
+
kind: number;
|
|
53
|
+
kind_label: string;
|
|
54
|
+
outcome: number;
|
|
55
|
+
outcome_label: "success" | "failed" | "disputed";
|
|
56
|
+
value_atomic: string;
|
|
57
|
+
value_human: number;
|
|
58
|
+
slot: number;
|
|
59
|
+
ts: number;
|
|
60
|
+
}>;
|
|
61
|
+
claims: Array<{
|
|
62
|
+
pubkey: string;
|
|
63
|
+
claimer: string;
|
|
64
|
+
claimed_atomic: string;
|
|
65
|
+
claimed_human: number;
|
|
66
|
+
evidence_uri: string;
|
|
67
|
+
status: "open" | "accepted" | "auto-accepted" | "rejected";
|
|
68
|
+
created_at: number;
|
|
69
|
+
deadline: number;
|
|
70
|
+
resolved_at: number;
|
|
71
|
+
paid_out: number;
|
|
72
|
+
}>;
|
|
73
|
+
score_series: Array<{
|
|
74
|
+
ts: number;
|
|
75
|
+
score: number;
|
|
76
|
+
}>;
|
|
77
|
+
is_mock?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface ApiEcosystemStats {
|
|
80
|
+
bond_tvl_atomic: string;
|
|
81
|
+
bond_tvl_human: number;
|
|
82
|
+
agent_count: number;
|
|
83
|
+
framework_count: number;
|
|
84
|
+
total_actions: number;
|
|
85
|
+
dispute_rate: number;
|
|
86
|
+
value_handled_30d: number;
|
|
87
|
+
open_claims: number;
|
|
88
|
+
paid_out_total: number;
|
|
89
|
+
}
|
|
90
|
+
export interface ApiLeaderboardResponse {
|
|
91
|
+
ecosystem: ApiEcosystemStats;
|
|
92
|
+
top: Array<Pick<ApiAgentSummary, "pubkey" | "name" | "framework" | "score" | "bond_atomic" | "bond_human" | "action_count" | "success_rate">>;
|
|
93
|
+
is_mock?: boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface ApiHealth {
|
|
96
|
+
ok: boolean;
|
|
97
|
+
service: string;
|
|
98
|
+
version: string;
|
|
99
|
+
network: string;
|
|
100
|
+
}
|
|
101
|
+
export interface ListAgentsQuery {
|
|
102
|
+
framework?: string;
|
|
103
|
+
/** Atomic units (USDC: 6dp). Pass as bigint or numeric string. */
|
|
104
|
+
minBond?: bigint | string;
|
|
105
|
+
minScore?: number;
|
|
106
|
+
limit?: number;
|
|
107
|
+
}
|
|
108
|
+
export interface TelaroApiOptions {
|
|
109
|
+
/** Drop-in replacement for global `fetch`. Useful for SSR/testing. */
|
|
110
|
+
fetch?: typeof globalThis.fetch;
|
|
111
|
+
/** Default headers applied to every request. */
|
|
112
|
+
headers?: Record<string, string>;
|
|
113
|
+
/** Timeout in milliseconds. Default 10s. */
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
/**
|
|
116
|
+
* API key (`ba_...`). When provided, sent as `Authorization: Bearer <key>`
|
|
117
|
+
* and the caller's quota is the keyed tier (starter/pro/enterprise) instead
|
|
118
|
+
* of the free per-IP tier. Mint one at https://telaro.xyz/keys.
|
|
119
|
+
*/
|
|
120
|
+
apiKey?: string;
|
|
121
|
+
}
|
|
122
|
+
export declare class TelaroApiError extends Error {
|
|
123
|
+
readonly status: number;
|
|
124
|
+
readonly path: string;
|
|
125
|
+
readonly body?: unknown | undefined;
|
|
126
|
+
constructor(message: string, status: number, path: string, body?: unknown | undefined);
|
|
127
|
+
/** True for HTTP 429 (rate-limit exceeded). */
|
|
128
|
+
get isRateLimit(): boolean;
|
|
129
|
+
/** Seconds the caller should wait before retrying (from the `retry_after` field or `Retry-After` header). */
|
|
130
|
+
get retryAfter(): number | undefined;
|
|
131
|
+
}
|
|
132
|
+
export interface RateLimitInfo {
|
|
133
|
+
/** Requests allowed in this window. */
|
|
134
|
+
limit: number;
|
|
135
|
+
/** Requests remaining in this window. */
|
|
136
|
+
remaining: number;
|
|
137
|
+
/** Unix epoch seconds when the window resets. */
|
|
138
|
+
resetAt: number;
|
|
139
|
+
/** Logical tier (read / card / spec). */
|
|
140
|
+
tier?: string;
|
|
141
|
+
/** Plan applied: free (no key) / starter / pro / enterprise. */
|
|
142
|
+
plan?: "free" | "starter" | "pro" | "enterprise";
|
|
143
|
+
/** True if the request was authenticated via API key. */
|
|
144
|
+
authenticated?: boolean;
|
|
145
|
+
}
|
|
146
|
+
export declare class TelaroApi {
|
|
147
|
+
private readonly base;
|
|
148
|
+
private readonly fetch;
|
|
149
|
+
private readonly headers;
|
|
150
|
+
private readonly timeoutMs;
|
|
151
|
+
/** Last seen rate-limit window. Updated on every successful response. */
|
|
152
|
+
lastRateLimit: RateLimitInfo | null;
|
|
153
|
+
constructor(baseUrl: string, opts?: TelaroApiOptions);
|
|
154
|
+
/** Liveness probe — returns service version + network. */
|
|
155
|
+
health(): Promise<ApiHealth>;
|
|
156
|
+
/**
|
|
157
|
+
* List bonded agents, sorted by score descending.
|
|
158
|
+
* Returns the array of agents (mirrors the `agents` field of the response).
|
|
159
|
+
*/
|
|
160
|
+
listAgents(query?: ListAgentsQuery): Promise<ApiAgentSummary[]>;
|
|
161
|
+
/** Single-agent full detail: identity, score, bond, last 100 actions, claims, 30d score series. */
|
|
162
|
+
agent(pubkey: string): Promise<ApiAgentDetail | null>;
|
|
163
|
+
/** Trimmed top-N + ecosystem stats. Suitable for embeds. */
|
|
164
|
+
leaderboard(query?: {
|
|
165
|
+
limit?: number;
|
|
166
|
+
}): Promise<ApiLeaderboardResponse>;
|
|
167
|
+
/** Returns the absolute URL of the dynamic Trust Card PNG for `pubkey`. */
|
|
168
|
+
cardUrl(pubkey: string): string;
|
|
169
|
+
/** Returns the absolute URL of the embed iframe for `pubkey`. */
|
|
170
|
+
embedUrl(pubkey: string): string;
|
|
171
|
+
/** Returns the latest Postman v2.1 collection JSON for this deployment. */
|
|
172
|
+
postmanCollection(): Promise<unknown>;
|
|
173
|
+
/** Returns the OpenAPI 3.1 spec JSON for this deployment. */
|
|
174
|
+
openapiSpec(): Promise<unknown>;
|
|
175
|
+
private req;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,M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,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAKlF,2EAA2E;IAC3E,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI/B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAIhC,2EAA2E;IACrE,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3C,6DAA6D;IACvD,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;YAIvB,GAAG;CA2ClB"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed HTTP client for the public Telaro REST API.
|
|
3
|
+
*
|
|
4
|
+
* DApps that just want to *read* trust data should use this — no Anchor,
|
|
5
|
+
* no wallet, no Solana SDK. For writing (register/record/claim/resolve),
|
|
6
|
+
* use {@link TelaroClient} or the `build*Ix` builders.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { TelaroApi } from "@telaro/sdk";
|
|
11
|
+
*
|
|
12
|
+
* const api = new TelaroApi("https://telaro.xyz");
|
|
13
|
+
*
|
|
14
|
+
* const top = await api.leaderboard({ limit: 5 });
|
|
15
|
+
* console.log(`TVL: $${top.ecosystem.bond_tvl_human}`);
|
|
16
|
+
*
|
|
17
|
+
* const agent = await api.agent("AgentSenda1JupiterLPv3...");
|
|
18
|
+
* if (agent && agent.score >= 700 && !agent.frozen) {
|
|
19
|
+
* // safe to delegate
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class TelaroApiError extends Error {
|
|
24
|
+
status;
|
|
25
|
+
path;
|
|
26
|
+
body;
|
|
27
|
+
constructor(message, status, path, body) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.path = path;
|
|
31
|
+
this.body = body;
|
|
32
|
+
this.name = "TelaroApiError";
|
|
33
|
+
}
|
|
34
|
+
/** True for HTTP 429 (rate-limit exceeded). */
|
|
35
|
+
get isRateLimit() {
|
|
36
|
+
return this.status === 429;
|
|
37
|
+
}
|
|
38
|
+
/** Seconds the caller should wait before retrying (from the `retry_after` field or `Retry-After` header). */
|
|
39
|
+
get retryAfter() {
|
|
40
|
+
if (typeof this.body === "object" && this.body !== null && "retry_after" in this.body) {
|
|
41
|
+
const v = this.body.retry_after;
|
|
42
|
+
if (typeof v === "number")
|
|
43
|
+
return v;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class TelaroApi {
|
|
49
|
+
base;
|
|
50
|
+
fetch;
|
|
51
|
+
headers;
|
|
52
|
+
timeoutMs;
|
|
53
|
+
/** Last seen rate-limit window. Updated on every successful response. */
|
|
54
|
+
lastRateLimit = null;
|
|
55
|
+
constructor(baseUrl, opts = {}) {
|
|
56
|
+
this.base = baseUrl.replace(/\/$/, "");
|
|
57
|
+
this.fetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
58
|
+
this.headers = {
|
|
59
|
+
Accept: "application/json",
|
|
60
|
+
...(opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {}),
|
|
61
|
+
...(opts.headers ?? {}),
|
|
62
|
+
};
|
|
63
|
+
this.timeoutMs = opts.timeoutMs ?? 10_000;
|
|
64
|
+
}
|
|
65
|
+
/** Liveness probe — returns service version + network. */
|
|
66
|
+
async health() {
|
|
67
|
+
return this.req("/api/health");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* List bonded agents, sorted by score descending.
|
|
71
|
+
* Returns the array of agents (mirrors the `agents` field of the response).
|
|
72
|
+
*/
|
|
73
|
+
async listAgents(query = {}) {
|
|
74
|
+
const qs = new URLSearchParams();
|
|
75
|
+
if (query.framework)
|
|
76
|
+
qs.set("framework", query.framework);
|
|
77
|
+
if (query.minBond !== undefined)
|
|
78
|
+
qs.set("minBond", String(query.minBond));
|
|
79
|
+
if (query.minScore !== undefined)
|
|
80
|
+
qs.set("minScore", String(query.minScore));
|
|
81
|
+
if (query.limit !== undefined)
|
|
82
|
+
qs.set("limit", String(query.limit));
|
|
83
|
+
const path = `/api/agents${qs.size ? `?${qs}` : ""}`;
|
|
84
|
+
const res = await this.req(path);
|
|
85
|
+
return res.agents;
|
|
86
|
+
}
|
|
87
|
+
/** Single-agent full detail: identity, score, bond, last 100 actions, claims, 30d score series. */
|
|
88
|
+
async agent(pubkey) {
|
|
89
|
+
try {
|
|
90
|
+
return await this.req(`/api/agent/${encodeURIComponent(pubkey)}`);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof TelaroApiError && err.status === 404)
|
|
94
|
+
return null;
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Trimmed top-N + ecosystem stats. Suitable for embeds. */
|
|
99
|
+
async leaderboard(query = {}) {
|
|
100
|
+
const path = query.limit ? `/api/leaderboard?limit=${query.limit}` : "/api/leaderboard";
|
|
101
|
+
return this.req(path);
|
|
102
|
+
}
|
|
103
|
+
/** Returns the absolute URL of the dynamic Trust Card PNG for `pubkey`. */
|
|
104
|
+
cardUrl(pubkey) {
|
|
105
|
+
return `${this.base}/api/card/${encodeURIComponent(pubkey)}.png`;
|
|
106
|
+
}
|
|
107
|
+
/** Returns the absolute URL of the embed iframe for `pubkey`. */
|
|
108
|
+
embedUrl(pubkey) {
|
|
109
|
+
return `${this.base}/embed/${encodeURIComponent(pubkey)}`;
|
|
110
|
+
}
|
|
111
|
+
/** Returns the latest Postman v2.1 collection JSON for this deployment. */
|
|
112
|
+
async postmanCollection() {
|
|
113
|
+
return this.req("/api/postman.json");
|
|
114
|
+
}
|
|
115
|
+
/** Returns the OpenAPI 3.1 spec JSON for this deployment. */
|
|
116
|
+
async openapiSpec() {
|
|
117
|
+
return this.req("/api/openapi.json");
|
|
118
|
+
}
|
|
119
|
+
async req(path) {
|
|
120
|
+
const ctrl = new AbortController();
|
|
121
|
+
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
122
|
+
try {
|
|
123
|
+
const res = await this.fetch(`${this.base}${path}`, {
|
|
124
|
+
headers: this.headers,
|
|
125
|
+
signal: ctrl.signal,
|
|
126
|
+
});
|
|
127
|
+
const limit = res.headers.get("x-ratelimit-limit");
|
|
128
|
+
if (limit) {
|
|
129
|
+
const plan = res.headers.get("x-ratelimit-plan");
|
|
130
|
+
this.lastRateLimit = {
|
|
131
|
+
limit: Number(limit),
|
|
132
|
+
remaining: Number(res.headers.get("x-ratelimit-remaining") ?? 0),
|
|
133
|
+
resetAt: Number(res.headers.get("x-ratelimit-reset") ?? 0),
|
|
134
|
+
tier: res.headers.get("x-ratelimit-tier") ?? undefined,
|
|
135
|
+
plan: plan === "free" || plan === "starter" || plan === "pro" || plan === "enterprise"
|
|
136
|
+
? plan
|
|
137
|
+
: undefined,
|
|
138
|
+
authenticated: res.headers.get("x-ratelimit-authenticated") === "1",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (!res.ok) {
|
|
142
|
+
let body;
|
|
143
|
+
try {
|
|
144
|
+
body = await res.json();
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
body = await res.text();
|
|
148
|
+
}
|
|
149
|
+
throw new TelaroApiError(`${res.status} ${res.statusText} @ ${path}`, res.status, path, body);
|
|
150
|
+
}
|
|
151
|
+
return (await res.json());
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA0GH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAG5B;IACA;IACA;IAJX,YACE,O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MAAM,IAAI,GAAG,CAAC,UAAU,MAAM,IAAI,EAAE,EAC3C,GAAG,CAAC,MAAM,EACV,IAAI,EACJ,IAAI,CACL,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAM,CAAC;QACjC,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
|
package/dist/borsh.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal Borsh reader covering the field types our program emits.
|
|
4
|
+
* Full Borsh spec: https://borsh.io/. We deliberately don't pull in the
|
|
5
|
+
* heavyweight `borsh` package — the reads we need are trivial and adding
|
|
6
|
+
* a dep just for this would bloat the SDK.
|
|
7
|
+
*
|
|
8
|
+
* Endianness: Borsh integers are little-endian.
|
|
9
|
+
* Strings: u32-LE length prefix, then UTF-8 bytes.
|
|
10
|
+
* Vec<T>: u32-LE length prefix, then T repeated.
|
|
11
|
+
* Pubkey: 32 raw bytes.
|
|
12
|
+
*/
|
|
13
|
+
export declare class BorshReader {
|
|
14
|
+
private readonly buf;
|
|
15
|
+
private offset;
|
|
16
|
+
constructor(buf: Buffer);
|
|
17
|
+
get remaining(): number;
|
|
18
|
+
private check;
|
|
19
|
+
u8(): number;
|
|
20
|
+
bool(): boolean;
|
|
21
|
+
u16(): number;
|
|
22
|
+
u32(): number;
|
|
23
|
+
i32(): number;
|
|
24
|
+
u64(): bigint;
|
|
25
|
+
i64(): bigint;
|
|
26
|
+
pubkey(): PublicKey;
|
|
27
|
+
fixedBytes(n: number): Uint8Array;
|
|
28
|
+
string(): string;
|
|
29
|
+
/** Read `n` bytes without parsing them. */
|
|
30
|
+
bytes(n: number): Buffer;
|
|
31
|
+
vec<T>(reader: (r: BorshReader) => T): T[];
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=borsh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"borsh.d.ts","sourceRoot":"","sources":["../src/borsh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,MAAM,CAAK;gBAEU,GAAG,EAAE,MAAM;IAExC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,OAAO,CAAC,KAAK;IAQb,EAAE,IAAI,MAAM;IAOZ,IAAI,IAAI,OAAO;IAIf,GAAG,IAAI,MAAM;IAOb,GAAG,IAAI,MAAM;IAOb,GAAG,IAAI,MAAM;IAOb,GAAG,IAAI,MAAM;IAOb,GAAG,IAAI,MAAM;IAOb,MAAM,IAAI,SAAS;IAOnB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU;IAOjC,MAAM,IAAI,MAAM;IAQhB,2CAA2C;IAC3C,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAOxB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,CAAC,GAAG,CAAC,EAAE;CAM3C"}
|
package/dist/borsh.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal Borsh reader covering the field types our program emits.
|
|
4
|
+
* Full Borsh spec: https://borsh.io/. We deliberately don't pull in the
|
|
5
|
+
* heavyweight `borsh` package — the reads we need are trivial and adding
|
|
6
|
+
* a dep just for this would bloat the SDK.
|
|
7
|
+
*
|
|
8
|
+
* Endianness: Borsh integers are little-endian.
|
|
9
|
+
* Strings: u32-LE length prefix, then UTF-8 bytes.
|
|
10
|
+
* Vec<T>: u32-LE length prefix, then T repeated.
|
|
11
|
+
* Pubkey: 32 raw bytes.
|
|
12
|
+
*/
|
|
13
|
+
export class BorshReader {
|
|
14
|
+
buf;
|
|
15
|
+
offset = 0;
|
|
16
|
+
constructor(buf) {
|
|
17
|
+
this.buf = buf;
|
|
18
|
+
}
|
|
19
|
+
get remaining() {
|
|
20
|
+
return this.buf.length - this.offset;
|
|
21
|
+
}
|
|
22
|
+
check(n) {
|
|
23
|
+
if (this.offset + n > this.buf.length) {
|
|
24
|
+
throw new RangeError(`Borsh read out of bounds: need ${n} bytes at offset ${this.offset} (buf len ${this.buf.length})`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
u8() {
|
|
28
|
+
this.check(1);
|
|
29
|
+
const v = this.buf.readUInt8(this.offset);
|
|
30
|
+
this.offset += 1;
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
bool() {
|
|
34
|
+
return this.u8() !== 0;
|
|
35
|
+
}
|
|
36
|
+
u16() {
|
|
37
|
+
this.check(2);
|
|
38
|
+
const v = this.buf.readUInt16LE(this.offset);
|
|
39
|
+
this.offset += 2;
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
u32() {
|
|
43
|
+
this.check(4);
|
|
44
|
+
const v = this.buf.readUInt32LE(this.offset);
|
|
45
|
+
this.offset += 4;
|
|
46
|
+
return v;
|
|
47
|
+
}
|
|
48
|
+
i32() {
|
|
49
|
+
this.check(4);
|
|
50
|
+
const v = this.buf.readInt32LE(this.offset);
|
|
51
|
+
this.offset += 4;
|
|
52
|
+
return v;
|
|
53
|
+
}
|
|
54
|
+
u64() {
|
|
55
|
+
this.check(8);
|
|
56
|
+
const v = this.buf.readBigUInt64LE(this.offset);
|
|
57
|
+
this.offset += 8;
|
|
58
|
+
return v;
|
|
59
|
+
}
|
|
60
|
+
i64() {
|
|
61
|
+
this.check(8);
|
|
62
|
+
const v = this.buf.readBigInt64LE(this.offset);
|
|
63
|
+
this.offset += 8;
|
|
64
|
+
return v;
|
|
65
|
+
}
|
|
66
|
+
pubkey() {
|
|
67
|
+
this.check(32);
|
|
68
|
+
const slice = this.buf.subarray(this.offset, this.offset + 32);
|
|
69
|
+
this.offset += 32;
|
|
70
|
+
return new PublicKey(slice);
|
|
71
|
+
}
|
|
72
|
+
fixedBytes(n) {
|
|
73
|
+
this.check(n);
|
|
74
|
+
const slice = new Uint8Array(this.buf.subarray(this.offset, this.offset + n));
|
|
75
|
+
this.offset += n;
|
|
76
|
+
return slice;
|
|
77
|
+
}
|
|
78
|
+
string() {
|
|
79
|
+
const len = this.u32();
|
|
80
|
+
this.check(len);
|
|
81
|
+
const slice = this.buf.subarray(this.offset, this.offset + len);
|
|
82
|
+
this.offset += len;
|
|
83
|
+
return slice.toString("utf8");
|
|
84
|
+
}
|
|
85
|
+
/** Read `n` bytes without parsing them. */
|
|
86
|
+
bytes(n) {
|
|
87
|
+
this.check(n);
|
|
88
|
+
const slice = Buffer.from(this.buf.subarray(this.offset, this.offset + n));
|
|
89
|
+
this.offset += n;
|
|
90
|
+
return slice;
|
|
91
|
+
}
|
|
92
|
+
vec(reader) {
|
|
93
|
+
const len = this.u32();
|
|
94
|
+
const out = new Array(len);
|
|
95
|
+
for (let i = 0; i < len; i++)
|
|
96
|
+
out[i] = reader(this);
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=borsh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"borsh.js","sourceRoot":"","sources":["../src/borsh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,WAAW;IAGO;IAFrB,MAAM,GAAG,CAAC,CAAC;IAEnB,YAA6B,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;IAE5C,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,CAAC;IAEO,KAAK,C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AI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC;QACnB,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,2CAA2C;IAC3C,KAAK,CAAC,CAAS;QACb,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACd,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC3E,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,GAAG,CAAI,MAA6B;QAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAI,GAAG,CAAC,CAAC;QAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACpD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Connection, Keypair, PublicKey, type Signer } from "@solana/web3.js";
|
|
2
|
+
import { ArbiterRuling } from "./instructions.js";
|
|
3
|
+
import { ActionKind, ActionOutcome, type RecordActionInput, type RegisterAgentInput, type SubmitClaimInput, ResolveAction } from "./types.js";
|
|
4
|
+
export interface TelaroClientOptions {
|
|
5
|
+
programId?: PublicKey;
|
|
6
|
+
/** Optional commitment override; default: "confirmed". */
|
|
7
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* High-level client. Wraps the on-chain instructions for the agent-side flow
|
|
11
|
+
* (register / record_action / top_up / withdraw) and the user-side flow
|
|
12
|
+
* (submit_claim / resolve_claim).
|
|
13
|
+
*/
|
|
14
|
+
export declare class TelaroClient {
|
|
15
|
+
readonly connection: Connection;
|
|
16
|
+
readonly signer: Signer | Keypair;
|
|
17
|
+
readonly programId: PublicKey;
|
|
18
|
+
readonly commitment: "processed" | "confirmed" | "finalized";
|
|
19
|
+
constructor(connection: Connection, signer: Signer | Keypair, opts?: TelaroClientOptions);
|
|
20
|
+
get controller(): PublicKey;
|
|
21
|
+
agentPda(controller?: PublicKey): PublicKey;
|
|
22
|
+
registerAgent(input: RegisterAgentInput): Promise<string>;
|
|
23
|
+
recordAction(input: RecordActionInput): Promise<string>;
|
|
24
|
+
topUpBond(args: {
|
|
25
|
+
agent: PublicKey;
|
|
26
|
+
bondMint: PublicKey;
|
|
27
|
+
amount: bigint;
|
|
28
|
+
}): Promise<string>;
|
|
29
|
+
submitClaim(input: SubmitClaimInput, bondMint: PublicKey): Promise<string>;
|
|
30
|
+
resolveClaim(args: {
|
|
31
|
+
agent: PublicKey;
|
|
32
|
+
actionHash: Uint8Array;
|
|
33
|
+
claimer: PublicKey;
|
|
34
|
+
bondMint: PublicKey;
|
|
35
|
+
action: ResolveAction;
|
|
36
|
+
}): Promise<string>;
|
|
37
|
+
/** v0.3: User escalates a rejected claim within 24h. Posts an
|
|
38
|
+
* additional 5% deposit. */
|
|
39
|
+
escalateClaim(args: {
|
|
40
|
+
agent: PublicKey;
|
|
41
|
+
actionHash: Uint8Array;
|
|
42
|
+
bondMint: PublicKey;
|
|
43
|
+
}): Promise<string>;
|
|
44
|
+
/** v0.3: Protocol arbiter rules ForUser (0) or ForBuilder (1). Caller
|
|
45
|
+
* must be the configured PROTOCOL_ARBITER pubkey. */
|
|
46
|
+
arbiterResolve(args: {
|
|
47
|
+
agent: PublicKey;
|
|
48
|
+
actionHash: Uint8Array;
|
|
49
|
+
claimer: PublicKey;
|
|
50
|
+
bondMint: PublicKey;
|
|
51
|
+
ruling: ArbiterRuling;
|
|
52
|
+
}): Promise<string>;
|
|
53
|
+
/** v0.3: Anyone can crank after 7d arbiter window. Defaults ForUser. */
|
|
54
|
+
arbiterTimeout(args: {
|
|
55
|
+
agent: PublicKey;
|
|
56
|
+
actionHash: Uint8Array;
|
|
57
|
+
claimer: PublicKey;
|
|
58
|
+
bondMint: PublicKey;
|
|
59
|
+
}): Promise<string>;
|
|
60
|
+
updateScore(agent: PublicKey, newScore: number, bondRatioBps: number): Promise<string>;
|
|
61
|
+
withdrawBond(args: {
|
|
62
|
+
agent: PublicKey;
|
|
63
|
+
bondMint: PublicKey;
|
|
64
|
+
amount: bigint;
|
|
65
|
+
}): Promise<string>;
|
|
66
|
+
previewViewBond(agent: PublicKey, minBond: bigint, minScore: number): Promise<boolean>;
|
|
67
|
+
private send;
|
|
68
|
+
}
|
|
69
|
+
export { ActionKind, ActionOutcome, ResolveAction };
|
|
70
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,OAAO,EACP,SAAS,EAGT,KAAK,MAAM,EACZ,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,aAAa,EAYd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,UAAU,EACV,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;CACtD;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAKrB,QAAQ,CAAC,UAAU,EAAE,UAAU;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO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