@xpr-agents/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.
@@ -0,0 +1,253 @@
1
+ import { JsonRpc, ProtonSession, TransactionResult, PaginatedResult } from './types';
2
+ export interface Job {
3
+ id: number;
4
+ client: string;
5
+ agent: string;
6
+ title: string;
7
+ description: string;
8
+ deliverables: string[];
9
+ amount: number;
10
+ symbol: string;
11
+ funded_amount: number;
12
+ released_amount: number;
13
+ state: JobState;
14
+ deadline: number;
15
+ arbitrator: string;
16
+ job_hash: string;
17
+ created_at: number;
18
+ updated_at: number;
19
+ }
20
+ export interface JobRaw {
21
+ id: string;
22
+ client: string;
23
+ agent: string;
24
+ title: string;
25
+ description: string;
26
+ deliverables: string;
27
+ amount: string;
28
+ symbol: string;
29
+ funded_amount: string;
30
+ released_amount: string;
31
+ state: number;
32
+ deadline: string;
33
+ arbitrator: string;
34
+ job_hash: string;
35
+ created_at: string;
36
+ updated_at: string;
37
+ }
38
+ export type JobState = 'created' | 'funded' | 'accepted' | 'inprogress' | 'delivered' | 'disputed' | 'completed' | 'refunded' | 'arbitrated';
39
+ export interface Milestone {
40
+ id: number;
41
+ job_id: number;
42
+ title: string;
43
+ description: string;
44
+ amount: number;
45
+ order: number;
46
+ state: MilestoneState;
47
+ evidence_uri: string;
48
+ submitted_at: number;
49
+ approved_at: number;
50
+ }
51
+ export interface MilestoneRaw {
52
+ id: string;
53
+ job_id: string;
54
+ title: string;
55
+ description: string;
56
+ amount: string;
57
+ order: number;
58
+ state: number;
59
+ evidence_uri: string;
60
+ submitted_at: string;
61
+ approved_at: string;
62
+ }
63
+ export type MilestoneState = 'pending' | 'submitted' | 'approved' | 'disputed';
64
+ export interface EscrowDispute {
65
+ id: number;
66
+ job_id: number;
67
+ raised_by: string;
68
+ reason: string;
69
+ evidence_uri: string;
70
+ client_amount: number;
71
+ agent_amount: number;
72
+ resolution: DisputeResolution;
73
+ resolver: string;
74
+ resolution_notes: string;
75
+ created_at: number;
76
+ resolved_at: number;
77
+ }
78
+ export type DisputeResolution = 'pending' | 'client_wins' | 'agent_wins' | 'split';
79
+ export interface Arbitrator {
80
+ account: string;
81
+ stake: number;
82
+ fee_percent: number;
83
+ total_cases: number;
84
+ successful_cases: number;
85
+ active_disputes: number;
86
+ active: boolean;
87
+ }
88
+ export interface CreateJobData {
89
+ agent: string;
90
+ title: string;
91
+ description: string;
92
+ deliverables: string[];
93
+ amount: number;
94
+ symbol?: string;
95
+ deadline?: number;
96
+ arbitrator?: string;
97
+ job_hash?: string;
98
+ }
99
+ export interface AddMilestoneData {
100
+ job_id: number;
101
+ title: string;
102
+ description: string;
103
+ amount: number;
104
+ order: number;
105
+ }
106
+ export interface JobListOptions {
107
+ limit?: number;
108
+ cursor?: string;
109
+ state?: JobState;
110
+ }
111
+ export declare class EscrowRegistry {
112
+ private rpc;
113
+ private session;
114
+ private contract;
115
+ constructor(rpc: JsonRpc, session?: ProtonSession, contract?: string);
116
+ /**
117
+ * Get a job by ID
118
+ */
119
+ getJob(id: number): Promise<Job | null>;
120
+ /**
121
+ * List jobs for a client
122
+ */
123
+ listJobsByClient(client: string, options?: JobListOptions): Promise<PaginatedResult<Job>>;
124
+ /**
125
+ * List jobs for an agent
126
+ */
127
+ listJobsByAgent(agent: string, options?: JobListOptions): Promise<PaginatedResult<Job>>;
128
+ /**
129
+ * Get milestones for a job
130
+ */
131
+ getJobMilestones(jobId: number): Promise<Milestone[]>;
132
+ /**
133
+ * Get dispute for a job
134
+ */
135
+ getJobDispute(jobId: number): Promise<EscrowDispute | null>;
136
+ /**
137
+ * List available arbitrators
138
+ */
139
+ listArbitrators(): Promise<Arbitrator[]>;
140
+ /**
141
+ * Create a new job
142
+ */
143
+ createJob(data: CreateJobData): Promise<TransactionResult>;
144
+ /**
145
+ * Fund a job
146
+ */
147
+ fundJob(jobId: number, amount: string): Promise<TransactionResult>;
148
+ /**
149
+ * Accept a job (as agent)
150
+ */
151
+ acceptJob(jobId: number): Promise<TransactionResult>;
152
+ /**
153
+ * Start working on a job (as agent)
154
+ */
155
+ startJob(jobId: number): Promise<TransactionResult>;
156
+ /**
157
+ * Deliver a job (as agent)
158
+ */
159
+ deliverJob(jobId: number, evidenceUri: string): Promise<TransactionResult>;
160
+ /**
161
+ * Approve delivery (as client)
162
+ */
163
+ approveDelivery(jobId: number): Promise<TransactionResult>;
164
+ /**
165
+ * Add a milestone to a job
166
+ */
167
+ addMilestone(data: AddMilestoneData): Promise<TransactionResult>;
168
+ /**
169
+ * Submit a milestone (as agent)
170
+ */
171
+ submitMilestone(milestoneId: number, evidenceUri: string): Promise<TransactionResult>;
172
+ /**
173
+ * Approve a milestone (as client)
174
+ */
175
+ approveMilestone(milestoneId: number): Promise<TransactionResult>;
176
+ /**
177
+ * Raise a dispute
178
+ */
179
+ raiseDispute(jobId: number, reason: string, evidenceUri?: string): Promise<TransactionResult>;
180
+ /**
181
+ * Cancel a job (as client)
182
+ */
183
+ cancelJob(jobId: number): Promise<TransactionResult>;
184
+ /**
185
+ * Claim timeout (refund or auto-approve)
186
+ */
187
+ claimTimeout(jobId: number): Promise<TransactionResult>;
188
+ /**
189
+ * Claim acceptance timeout refund (as client)
190
+ */
191
+ claimAcceptanceTimeout(jobId: number): Promise<TransactionResult>;
192
+ /**
193
+ * Register as an arbitrator
194
+ */
195
+ registerArbitrator(feePercent: number): Promise<TransactionResult>;
196
+ /**
197
+ * Stake XPR as arbitrator (via token transfer)
198
+ *
199
+ * @param amount - Amount string (e.g., "1000.0000 XPR")
200
+ */
201
+ stakeArbitrator(amount: string): Promise<TransactionResult>;
202
+ /**
203
+ * Arbitrate a dispute
204
+ *
205
+ * @param disputeId - The dispute to resolve
206
+ * @param clientPercent - Percentage of remaining funds to give to client (0-100)
207
+ * @param resolutionNotes - Explanation of the resolution
208
+ */
209
+ arbitrate(disputeId: number, clientPercent: number, resolutionNotes: string): Promise<TransactionResult>;
210
+ /**
211
+ * Resolve a dispute after timeout (owner-only fallback).
212
+ * Can only be called after 14 days since dispute creation.
213
+ *
214
+ * @param disputeId - The dispute to resolve
215
+ * @param clientPercent - Percentage of remaining funds to give to client (0-100)
216
+ * @param resolutionNotes - Explanation of the resolution
217
+ */
218
+ resolveTimeout(disputeId: number, clientPercent: number, resolutionNotes: string): Promise<TransactionResult>;
219
+ /**
220
+ * Activate arbitrator (must have sufficient stake)
221
+ */
222
+ activateArbitrator(): Promise<TransactionResult>;
223
+ /**
224
+ * Deactivate arbitrator (stop accepting new cases)
225
+ */
226
+ deactivateArbitrator(): Promise<TransactionResult>;
227
+ /**
228
+ * Request to unstake arbitrator funds (7-day delay).
229
+ * Must be deactivated and have no pending disputes first.
230
+ *
231
+ * @param amount - Amount to unstake in smallest units (e.g., 10000 = 1.0000 XPR)
232
+ */
233
+ unstakeArbitrator(amount: number): Promise<TransactionResult>;
234
+ /**
235
+ * Withdraw unstaked arbitrator funds (after 7-day delay)
236
+ */
237
+ withdrawArbitratorStake(): Promise<TransactionResult>;
238
+ /**
239
+ * Cancel a pending unstake request (returns funds to active stake)
240
+ */
241
+ cancelArbitratorUnstake(): Promise<TransactionResult>;
242
+ /**
243
+ * Clean up completed jobs (permissionless)
244
+ */
245
+ cleanJobs(maxAge: number, maxDelete: number): Promise<TransactionResult>;
246
+ /**
247
+ * Clean up resolved disputes (permissionless)
248
+ */
249
+ cleanDisputes(maxAge: number, maxDelete: number): Promise<TransactionResult>;
250
+ private requireSession;
251
+ private parseJob;
252
+ private parseMilestone;
253
+ }