@zenland/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/LICENSE +21 -0
- package/README.md +246 -0
- package/dist/index.cjs +502 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +382 -0
- package/dist/index.d.ts +382 -0
- package/dist/index.js +465 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +743 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +554 -0
- package/dist/react.d.ts +554 -0
- package/dist/react.js +704 -0
- package/dist/react.js.map +1 -0
- package/package.json +78 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated types from the Zenland indexer GraphQL schema.
|
|
3
|
+
* These types are bundled with the SDK for convenience.
|
|
4
|
+
*/
|
|
5
|
+
type Maybe<T> = T | null;
|
|
6
|
+
type InputMaybe<T> = T | null | undefined;
|
|
7
|
+
/** GraphQL BigInt scalar - can be string or number from the API */
|
|
8
|
+
type BigIntScalar = string | number | bigint;
|
|
9
|
+
/** Page info for paginated queries */
|
|
10
|
+
interface GqlPageInfo {
|
|
11
|
+
hasNextPage: boolean;
|
|
12
|
+
hasPreviousPage: boolean;
|
|
13
|
+
startCursor?: Maybe<string>;
|
|
14
|
+
endCursor?: Maybe<string>;
|
|
15
|
+
}
|
|
16
|
+
interface GqlAgent {
|
|
17
|
+
id: string;
|
|
18
|
+
isActive: boolean;
|
|
19
|
+
isAvailable: boolean;
|
|
20
|
+
stablecoinDecimals: number;
|
|
21
|
+
stablecoinToken: string;
|
|
22
|
+
stablecoinStake: BigIntScalar;
|
|
23
|
+
daoTokenStake: BigIntScalar;
|
|
24
|
+
disputeFeeBps: number;
|
|
25
|
+
assignmentFeeBps: number;
|
|
26
|
+
description: string;
|
|
27
|
+
contact: string;
|
|
28
|
+
totalResolved: number;
|
|
29
|
+
activeCases: number;
|
|
30
|
+
registrationTime: BigIntScalar;
|
|
31
|
+
lastEngagementTimestamp: BigIntScalar;
|
|
32
|
+
totalEarnings: BigIntScalar;
|
|
33
|
+
totalSlashed: BigIntScalar;
|
|
34
|
+
cases?: Maybe<GqlAgentCasePage>;
|
|
35
|
+
}
|
|
36
|
+
interface GqlAgentCase {
|
|
37
|
+
id: string;
|
|
38
|
+
escrow: string;
|
|
39
|
+
agent: string;
|
|
40
|
+
invitedAt: BigIntScalar;
|
|
41
|
+
resolvedAt?: Maybe<BigIntScalar>;
|
|
42
|
+
timedOut: boolean;
|
|
43
|
+
feeEarned?: Maybe<BigIntScalar>;
|
|
44
|
+
escrowRef?: Maybe<GqlEscrow>;
|
|
45
|
+
}
|
|
46
|
+
interface GqlAgentCasePage {
|
|
47
|
+
items: GqlAgentCase[];
|
|
48
|
+
totalCount: number;
|
|
49
|
+
pageInfo: GqlPageInfo;
|
|
50
|
+
}
|
|
51
|
+
interface GqlAgentPage {
|
|
52
|
+
items: GqlAgent[];
|
|
53
|
+
totalCount: number;
|
|
54
|
+
pageInfo: GqlPageInfo;
|
|
55
|
+
}
|
|
56
|
+
interface GqlAgentFilter {
|
|
57
|
+
id?: InputMaybe<string>;
|
|
58
|
+
id_in?: InputMaybe<string[]>;
|
|
59
|
+
isActive?: InputMaybe<boolean>;
|
|
60
|
+
isAvailable?: InputMaybe<boolean>;
|
|
61
|
+
AND?: InputMaybe<GqlAgentFilter[]>;
|
|
62
|
+
OR?: InputMaybe<GqlAgentFilter[]>;
|
|
63
|
+
}
|
|
64
|
+
interface GqlEscrow {
|
|
65
|
+
id: string;
|
|
66
|
+
buyer: string;
|
|
67
|
+
seller: string;
|
|
68
|
+
agent?: Maybe<string>;
|
|
69
|
+
amount: BigIntScalar;
|
|
70
|
+
token: string;
|
|
71
|
+
state: string;
|
|
72
|
+
createdAt: BigIntScalar;
|
|
73
|
+
sellerAcceptDeadline: BigIntScalar;
|
|
74
|
+
buyerProtectionTime: BigIntScalar;
|
|
75
|
+
termsHash: string;
|
|
76
|
+
version: number;
|
|
77
|
+
fundedAt: BigIntScalar;
|
|
78
|
+
fulfilledAt?: Maybe<BigIntScalar>;
|
|
79
|
+
resolvedAt?: Maybe<BigIntScalar>;
|
|
80
|
+
agentInvitedAt?: Maybe<BigIntScalar>;
|
|
81
|
+
splitProposer?: Maybe<string>;
|
|
82
|
+
proposedBuyerBps?: Maybe<number>;
|
|
83
|
+
proposedSellerBps?: Maybe<number>;
|
|
84
|
+
buyerApprovedSplit?: Maybe<boolean>;
|
|
85
|
+
sellerApprovedSplit?: Maybe<boolean>;
|
|
86
|
+
agentFeeReceived?: Maybe<BigIntScalar>;
|
|
87
|
+
buyerReceived?: Maybe<BigIntScalar>;
|
|
88
|
+
sellerReceived?: Maybe<BigIntScalar>;
|
|
89
|
+
creationFee: BigIntScalar;
|
|
90
|
+
sellerAcceptedAt?: Maybe<BigIntScalar>;
|
|
91
|
+
sellerDeclinedAt?: Maybe<BigIntScalar>;
|
|
92
|
+
cancelledExpiredAt?: Maybe<BigIntScalar>;
|
|
93
|
+
}
|
|
94
|
+
interface GqlEscrowPage {
|
|
95
|
+
items: GqlEscrow[];
|
|
96
|
+
totalCount: number;
|
|
97
|
+
pageInfo: GqlPageInfo;
|
|
98
|
+
}
|
|
99
|
+
interface GqlEscrowFilter {
|
|
100
|
+
id?: InputMaybe<string>;
|
|
101
|
+
id_in?: InputMaybe<string[]>;
|
|
102
|
+
buyer?: InputMaybe<string>;
|
|
103
|
+
seller?: InputMaybe<string>;
|
|
104
|
+
agent?: InputMaybe<string>;
|
|
105
|
+
state?: InputMaybe<string>;
|
|
106
|
+
state_in?: InputMaybe<string[]>;
|
|
107
|
+
token?: InputMaybe<string>;
|
|
108
|
+
AND?: InputMaybe<GqlEscrowFilter[]>;
|
|
109
|
+
OR?: InputMaybe<GqlEscrowFilter[]>;
|
|
110
|
+
}
|
|
111
|
+
interface GqlProtocolStats {
|
|
112
|
+
id: string;
|
|
113
|
+
totalEscrowsCreated: number;
|
|
114
|
+
totalVolumeEscrowed: BigIntScalar;
|
|
115
|
+
totalFeesCollected: BigIntScalar;
|
|
116
|
+
currentTVL: BigIntScalar;
|
|
117
|
+
activeEscrowCount: number;
|
|
118
|
+
totalAgentsRegistered: number;
|
|
119
|
+
activeAgentsCount: number;
|
|
120
|
+
}
|
|
121
|
+
interface GqlTransactionLog {
|
|
122
|
+
id: string;
|
|
123
|
+
txHash: string;
|
|
124
|
+
blockNumber: BigIntScalar;
|
|
125
|
+
timestamp: BigIntScalar;
|
|
126
|
+
eventName: string;
|
|
127
|
+
contractAddress: string;
|
|
128
|
+
contractType: string;
|
|
129
|
+
escrowAddress?: Maybe<string>;
|
|
130
|
+
agentAddress?: Maybe<string>;
|
|
131
|
+
userAddress?: Maybe<string>;
|
|
132
|
+
eventData: string;
|
|
133
|
+
}
|
|
134
|
+
interface GqlTransactionLogPage {
|
|
135
|
+
items: GqlTransactionLog[];
|
|
136
|
+
totalCount: number;
|
|
137
|
+
pageInfo: GqlPageInfo;
|
|
138
|
+
}
|
|
139
|
+
interface GqlTransactionLogFilter {
|
|
140
|
+
escrowAddress?: InputMaybe<string>;
|
|
141
|
+
agentAddress?: InputMaybe<string>;
|
|
142
|
+
userAddress?: InputMaybe<string>;
|
|
143
|
+
eventName?: InputMaybe<string>;
|
|
144
|
+
AND?: InputMaybe<GqlTransactionLogFilter[]>;
|
|
145
|
+
OR?: InputMaybe<GqlTransactionLogFilter[]>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Escrow domain module for the Zenland SDK
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/** State groups for filtering escrows */
|
|
153
|
+
declare const STATE_GROUPS: {
|
|
154
|
+
readonly ACTIVE: readonly ["PENDING", "ACTIVE", "FULFILLED"];
|
|
155
|
+
readonly IN_DISPUTE: readonly ["DISPUTED", "AGENT_INVITED"];
|
|
156
|
+
readonly COMPLETED: readonly ["RELEASED", "AGENT_RESOLVED", "REFUNDED", "SPLIT"];
|
|
157
|
+
};
|
|
158
|
+
type StateGroup = keyof typeof STATE_GROUPS;
|
|
159
|
+
interface ListEscrowsArgs {
|
|
160
|
+
limit?: number;
|
|
161
|
+
offset?: number;
|
|
162
|
+
buyer?: string;
|
|
163
|
+
seller?: string;
|
|
164
|
+
agent?: string;
|
|
165
|
+
/** Search across buyer, seller, or agent roles */
|
|
166
|
+
user?: string;
|
|
167
|
+
state?: string;
|
|
168
|
+
/** Multiple states for group filtering */
|
|
169
|
+
states?: string[];
|
|
170
|
+
orderBy?: string;
|
|
171
|
+
orderDirection?: "asc" | "desc";
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Creates escrow domain functions bound to a base URL
|
|
175
|
+
*/
|
|
176
|
+
declare function createEscrowsDomain(baseUrl: string): {
|
|
177
|
+
list: (args?: ListEscrowsArgs) => Promise<GqlEscrowPage>;
|
|
178
|
+
getById: (id: string) => Promise<GqlEscrow | null>;
|
|
179
|
+
getByUser: (userAddress: string, args?: Omit<ListEscrowsArgs, "user" | "buyer" | "seller" | "agent">) => Promise<GqlEscrowPage>;
|
|
180
|
+
getByStateGroup: (stateGroup: StateGroup, args?: Omit<ListEscrowsArgs, "state" | "states">) => Promise<GqlEscrowPage>;
|
|
181
|
+
};
|
|
182
|
+
type EscrowsDomain = ReturnType<typeof createEscrowsDomain>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Agent domain module for the Zenland SDK
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
interface ListAgentsArgs {
|
|
189
|
+
limit?: number;
|
|
190
|
+
offset?: number;
|
|
191
|
+
onlyActive?: boolean;
|
|
192
|
+
onlyAvailable?: boolean;
|
|
193
|
+
orderBy?: string;
|
|
194
|
+
orderDirection?: "asc" | "desc";
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Creates agent domain functions bound to a base URL
|
|
198
|
+
*/
|
|
199
|
+
declare function createAgentsDomain(baseUrl: string): {
|
|
200
|
+
list: (args?: ListAgentsArgs) => Promise<GqlAgentPage>;
|
|
201
|
+
getById: (id: string) => Promise<GqlAgent | null>;
|
|
202
|
+
getAvailable: (args?: Omit<ListAgentsArgs, "onlyActive" | "onlyAvailable">) => Promise<GqlAgentPage>;
|
|
203
|
+
};
|
|
204
|
+
type AgentsDomain = ReturnType<typeof createAgentsDomain>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Protocol Stats domain module for the Zenland SDK
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
/** Normalized protocol stats with BigInt values */
|
|
211
|
+
interface ProtocolStats {
|
|
212
|
+
id: string;
|
|
213
|
+
totalEscrowsCreated: number;
|
|
214
|
+
totalVolumeEscrowed: bigint;
|
|
215
|
+
totalFeesCollected: bigint;
|
|
216
|
+
currentTVL: bigint;
|
|
217
|
+
activeEscrowCount: number;
|
|
218
|
+
totalAgentsRegistered: number;
|
|
219
|
+
activeAgentsCount: number;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Creates protocol stats domain functions bound to a base URL
|
|
223
|
+
*/
|
|
224
|
+
declare function createProtocolStatsDomain(baseUrl: string): {
|
|
225
|
+
get: () => Promise<ProtocolStats | null>;
|
|
226
|
+
getRaw: () => Promise<GqlProtocolStats | null>;
|
|
227
|
+
};
|
|
228
|
+
type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Transaction Logs domain module for the Zenland SDK
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
interface ListTransactionLogsArgs {
|
|
235
|
+
escrowAddress?: string;
|
|
236
|
+
limit?: number;
|
|
237
|
+
offset?: number;
|
|
238
|
+
orderBy?: string;
|
|
239
|
+
orderDirection?: "asc" | "desc";
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Creates transaction logs domain functions bound to a base URL
|
|
243
|
+
*/
|
|
244
|
+
declare function createTransactionLogsDomain(baseUrl: string): {
|
|
245
|
+
list: (args?: ListTransactionLogsArgs) => Promise<GqlTransactionLog[]>;
|
|
246
|
+
getByEscrow: (escrowAddress: string, args?: Omit<ListTransactionLogsArgs, "escrowAddress">) => Promise<GqlTransactionLog[]>;
|
|
247
|
+
parseEventData: (eventData: string) => Record<string, unknown>;
|
|
248
|
+
};
|
|
249
|
+
type TransactionLogsDomain = ReturnType<typeof createTransactionLogsDomain>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Zenland SDK Client
|
|
253
|
+
*
|
|
254
|
+
* The main entry point for interacting with the Zenland indexer.
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
interface ZenlandClientConfig {
|
|
258
|
+
/** Base URL for the indexer API. Defaults to https://api.zen.land */
|
|
259
|
+
baseUrl?: string;
|
|
260
|
+
}
|
|
261
|
+
interface ZenlandClient {
|
|
262
|
+
/** The base URL being used by this client */
|
|
263
|
+
readonly baseUrl: string;
|
|
264
|
+
/** Escrow-related operations */
|
|
265
|
+
readonly escrows: EscrowsDomain;
|
|
266
|
+
/** Agent-related operations */
|
|
267
|
+
readonly agents: AgentsDomain;
|
|
268
|
+
/** Protocol statistics */
|
|
269
|
+
readonly protocolStats: ProtocolStatsDomain;
|
|
270
|
+
/** Transaction logs */
|
|
271
|
+
readonly transactionLogs: TransactionLogsDomain;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Create a new Zenland SDK client.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* // Use production API (default)
|
|
279
|
+
* const client = createZenlandClient();
|
|
280
|
+
*
|
|
281
|
+
* // Use custom endpoint (e.g., local development)
|
|
282
|
+
* const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });
|
|
283
|
+
*
|
|
284
|
+
* // Fetch escrows
|
|
285
|
+
* const { items, totalCount } = await client.escrows.list({ limit: 10 });
|
|
286
|
+
*
|
|
287
|
+
* // Fetch a specific escrow
|
|
288
|
+
* const escrow = await client.escrows.getById('0x...');
|
|
289
|
+
*
|
|
290
|
+
* // Fetch agents
|
|
291
|
+
* const agents = await client.agents.list({ onlyActive: true });
|
|
292
|
+
*
|
|
293
|
+
* // Fetch protocol stats
|
|
294
|
+
* const stats = await client.protocolStats.get();
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare function createZenlandClient(config?: ZenlandClientConfig): ZenlandClient;
|
|
298
|
+
/**
|
|
299
|
+
* Default client instance using production API.
|
|
300
|
+
* Use this for quick access without creating a new client.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* import { zenland } from '@zenland/sdk';
|
|
305
|
+
*
|
|
306
|
+
* const escrows = await zenland.escrows.list();
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
declare const zenland: ZenlandClient;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Agent eligibility utilities.
|
|
313
|
+
*
|
|
314
|
+
* This is protocol/business logic (React-agnostic) and is safe to consume
|
|
315
|
+
* from any app (interface, backend, bots, etc.).
|
|
316
|
+
*/
|
|
317
|
+
/**
|
|
318
|
+
* Minimal view of an Agent returned by the indexer.
|
|
319
|
+
*/
|
|
320
|
+
type IndexerAgent = {
|
|
321
|
+
id: string;
|
|
322
|
+
isActive: boolean;
|
|
323
|
+
isAvailable: boolean;
|
|
324
|
+
stablecoinStake: bigint;
|
|
325
|
+
stablecoinDecimals: number;
|
|
326
|
+
registrationTime: bigint;
|
|
327
|
+
activeCases: number;
|
|
328
|
+
totalResolved: number;
|
|
329
|
+
};
|
|
330
|
+
type AgentEligibilityFailureReason = "NOT_REGISTERED" | "NOT_ACTIVE" | "NOT_AVAILABLE" | "INSUFFICIENT_MAV";
|
|
331
|
+
type AgentEligibilityResult = {
|
|
332
|
+
ok: true;
|
|
333
|
+
agentMavUsd: bigint;
|
|
334
|
+
requiredUsd: bigint;
|
|
335
|
+
} | {
|
|
336
|
+
ok: false;
|
|
337
|
+
reason: AgentEligibilityFailureReason;
|
|
338
|
+
agentMavUsd?: bigint;
|
|
339
|
+
requiredUsd: bigint;
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Compute agent MAV from its stablecoin stake.
|
|
343
|
+
*
|
|
344
|
+
* Bigint-safe:
|
|
345
|
+
* - stablecoinStake is in smallest units (stablecoinDecimals)
|
|
346
|
+
* - return MAV in the same smallest units (stablecoinDecimals)
|
|
347
|
+
*/
|
|
348
|
+
declare function computeAgentMavUsd(agent: Pick<IndexerAgent, "stablecoinStake" | "stablecoinDecimals">): bigint;
|
|
349
|
+
/**
|
|
350
|
+
* Evaluate whether an agent is eligible for a given escrow amount.
|
|
351
|
+
*
|
|
352
|
+
* NOTE: escrowAmount must be the escrow principal ONLY (fees excluded).
|
|
353
|
+
*/
|
|
354
|
+
declare function isAgentEligibleForEscrow(args: {
|
|
355
|
+
agent: IndexerAgent | null | undefined;
|
|
356
|
+
escrowAmount: bigint;
|
|
357
|
+
}): AgentEligibilityResult;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* GraphQL request utilities for the Zenland SDK
|
|
361
|
+
*/
|
|
362
|
+
type GraphQLErrorLike = {
|
|
363
|
+
message?: string;
|
|
364
|
+
[key: string]: unknown;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Error thrown when the indexer returns GraphQL errors
|
|
368
|
+
*/
|
|
369
|
+
declare class ZenlandGraphQLError extends Error {
|
|
370
|
+
readonly errors: GraphQLErrorLike[];
|
|
371
|
+
constructor(message: string, errors: GraphQLErrorLike[]);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Error thrown when the indexer request fails at the network/HTTP level
|
|
375
|
+
*/
|
|
376
|
+
declare class ZenlandRequestError extends Error {
|
|
377
|
+
readonly status: number;
|
|
378
|
+
readonly statusText: string;
|
|
379
|
+
constructor(message: string, status: number, statusText: string);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export { type AgentEligibilityFailureReason, type AgentEligibilityResult, type AgentsDomain, type BigIntScalar, type EscrowsDomain, type GqlAgent, type GqlAgentCase, type GqlAgentCasePage, type GqlAgentFilter, type GqlAgentPage, type GqlEscrow, type GqlEscrowFilter, type GqlEscrowPage, type GqlPageInfo, type GqlProtocolStats, type GqlTransactionLog, type GqlTransactionLogFilter, type GqlTransactionLogPage, type IndexerAgent, type InputMaybe, type ListAgentsArgs, type ListEscrowsArgs, type ListTransactionLogsArgs, type Maybe, type ProtocolStats, type ProtocolStatsDomain, STATE_GROUPS, type StateGroup, type TransactionLogsDomain, type ZenlandClient, type ZenlandClientConfig, ZenlandGraphQLError, ZenlandRequestError, computeAgentMavUsd, createAgentsDomain, createEscrowsDomain, createProtocolStatsDomain, createTransactionLogsDomain, createZenlandClient, isAgentEligibleForEscrow, zenland };
|