@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.
@@ -0,0 +1,554 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import * as _tanstack_react_query from '@tanstack/react-query';
4
+
5
+ /**
6
+ * Generated types from the Zenland indexer GraphQL schema.
7
+ * These types are bundled with the SDK for convenience.
8
+ */
9
+ type Maybe<T> = T | null;
10
+ /** GraphQL BigInt scalar - can be string or number from the API */
11
+ type BigIntScalar = string | number | bigint;
12
+ /** Page info for paginated queries */
13
+ interface GqlPageInfo {
14
+ hasNextPage: boolean;
15
+ hasPreviousPage: boolean;
16
+ startCursor?: Maybe<string>;
17
+ endCursor?: Maybe<string>;
18
+ }
19
+ interface GqlAgent {
20
+ id: string;
21
+ isActive: boolean;
22
+ isAvailable: boolean;
23
+ stablecoinDecimals: number;
24
+ stablecoinToken: string;
25
+ stablecoinStake: BigIntScalar;
26
+ daoTokenStake: BigIntScalar;
27
+ disputeFeeBps: number;
28
+ assignmentFeeBps: number;
29
+ description: string;
30
+ contact: string;
31
+ totalResolved: number;
32
+ activeCases: number;
33
+ registrationTime: BigIntScalar;
34
+ lastEngagementTimestamp: BigIntScalar;
35
+ totalEarnings: BigIntScalar;
36
+ totalSlashed: BigIntScalar;
37
+ cases?: Maybe<GqlAgentCasePage>;
38
+ }
39
+ interface GqlAgentCase {
40
+ id: string;
41
+ escrow: string;
42
+ agent: string;
43
+ invitedAt: BigIntScalar;
44
+ resolvedAt?: Maybe<BigIntScalar>;
45
+ timedOut: boolean;
46
+ feeEarned?: Maybe<BigIntScalar>;
47
+ escrowRef?: Maybe<GqlEscrow>;
48
+ }
49
+ interface GqlAgentCasePage {
50
+ items: GqlAgentCase[];
51
+ totalCount: number;
52
+ pageInfo: GqlPageInfo;
53
+ }
54
+ interface GqlAgentPage {
55
+ items: GqlAgent[];
56
+ totalCount: number;
57
+ pageInfo: GqlPageInfo;
58
+ }
59
+ interface GqlEscrow {
60
+ id: string;
61
+ buyer: string;
62
+ seller: string;
63
+ agent?: Maybe<string>;
64
+ amount: BigIntScalar;
65
+ token: string;
66
+ state: string;
67
+ createdAt: BigIntScalar;
68
+ sellerAcceptDeadline: BigIntScalar;
69
+ buyerProtectionTime: BigIntScalar;
70
+ termsHash: string;
71
+ version: number;
72
+ fundedAt: BigIntScalar;
73
+ fulfilledAt?: Maybe<BigIntScalar>;
74
+ resolvedAt?: Maybe<BigIntScalar>;
75
+ agentInvitedAt?: Maybe<BigIntScalar>;
76
+ splitProposer?: Maybe<string>;
77
+ proposedBuyerBps?: Maybe<number>;
78
+ proposedSellerBps?: Maybe<number>;
79
+ buyerApprovedSplit?: Maybe<boolean>;
80
+ sellerApprovedSplit?: Maybe<boolean>;
81
+ agentFeeReceived?: Maybe<BigIntScalar>;
82
+ buyerReceived?: Maybe<BigIntScalar>;
83
+ sellerReceived?: Maybe<BigIntScalar>;
84
+ creationFee: BigIntScalar;
85
+ sellerAcceptedAt?: Maybe<BigIntScalar>;
86
+ sellerDeclinedAt?: Maybe<BigIntScalar>;
87
+ cancelledExpiredAt?: Maybe<BigIntScalar>;
88
+ }
89
+ interface GqlEscrowPage {
90
+ items: GqlEscrow[];
91
+ totalCount: number;
92
+ pageInfo: GqlPageInfo;
93
+ }
94
+ interface GqlProtocolStats {
95
+ id: string;
96
+ totalEscrowsCreated: number;
97
+ totalVolumeEscrowed: BigIntScalar;
98
+ totalFeesCollected: BigIntScalar;
99
+ currentTVL: BigIntScalar;
100
+ activeEscrowCount: number;
101
+ totalAgentsRegistered: number;
102
+ activeAgentsCount: number;
103
+ }
104
+ interface GqlTransactionLog {
105
+ id: string;
106
+ txHash: string;
107
+ blockNumber: BigIntScalar;
108
+ timestamp: BigIntScalar;
109
+ eventName: string;
110
+ contractAddress: string;
111
+ contractType: string;
112
+ escrowAddress?: Maybe<string>;
113
+ agentAddress?: Maybe<string>;
114
+ userAddress?: Maybe<string>;
115
+ eventData: string;
116
+ }
117
+
118
+ /**
119
+ * Escrow domain module for the Zenland SDK
120
+ */
121
+
122
+ /** State groups for filtering escrows */
123
+ declare const STATE_GROUPS: {
124
+ readonly ACTIVE: readonly ["PENDING", "ACTIVE", "FULFILLED"];
125
+ readonly IN_DISPUTE: readonly ["DISPUTED", "AGENT_INVITED"];
126
+ readonly COMPLETED: readonly ["RELEASED", "AGENT_RESOLVED", "REFUNDED", "SPLIT"];
127
+ };
128
+ type StateGroup = keyof typeof STATE_GROUPS;
129
+ interface ListEscrowsArgs {
130
+ limit?: number;
131
+ offset?: number;
132
+ buyer?: string;
133
+ seller?: string;
134
+ agent?: string;
135
+ /** Search across buyer, seller, or agent roles */
136
+ user?: string;
137
+ state?: string;
138
+ /** Multiple states for group filtering */
139
+ states?: string[];
140
+ orderBy?: string;
141
+ orderDirection?: "asc" | "desc";
142
+ }
143
+ /**
144
+ * Creates escrow domain functions bound to a base URL
145
+ */
146
+ declare function createEscrowsDomain(baseUrl: string): {
147
+ list: (args?: ListEscrowsArgs) => Promise<GqlEscrowPage>;
148
+ getById: (id: string) => Promise<GqlEscrow | null>;
149
+ getByUser: (userAddress: string, args?: Omit<ListEscrowsArgs, "user" | "buyer" | "seller" | "agent">) => Promise<GqlEscrowPage>;
150
+ getByStateGroup: (stateGroup: StateGroup, args?: Omit<ListEscrowsArgs, "state" | "states">) => Promise<GqlEscrowPage>;
151
+ };
152
+ type EscrowsDomain = ReturnType<typeof createEscrowsDomain>;
153
+
154
+ /**
155
+ * Agent domain module for the Zenland SDK
156
+ */
157
+
158
+ interface ListAgentsArgs {
159
+ limit?: number;
160
+ offset?: number;
161
+ onlyActive?: boolean;
162
+ onlyAvailable?: boolean;
163
+ orderBy?: string;
164
+ orderDirection?: "asc" | "desc";
165
+ }
166
+ /**
167
+ * Creates agent domain functions bound to a base URL
168
+ */
169
+ declare function createAgentsDomain(baseUrl: string): {
170
+ list: (args?: ListAgentsArgs) => Promise<GqlAgentPage>;
171
+ getById: (id: string) => Promise<GqlAgent | null>;
172
+ getAvailable: (args?: Omit<ListAgentsArgs, "onlyActive" | "onlyAvailable">) => Promise<GqlAgentPage>;
173
+ };
174
+ type AgentsDomain = ReturnType<typeof createAgentsDomain>;
175
+
176
+ /**
177
+ * Protocol Stats domain module for the Zenland SDK
178
+ */
179
+
180
+ /** Normalized protocol stats with BigInt values */
181
+ interface ProtocolStats {
182
+ id: string;
183
+ totalEscrowsCreated: number;
184
+ totalVolumeEscrowed: bigint;
185
+ totalFeesCollected: bigint;
186
+ currentTVL: bigint;
187
+ activeEscrowCount: number;
188
+ totalAgentsRegistered: number;
189
+ activeAgentsCount: number;
190
+ }
191
+ /**
192
+ * Creates protocol stats domain functions bound to a base URL
193
+ */
194
+ declare function createProtocolStatsDomain(baseUrl: string): {
195
+ get: () => Promise<ProtocolStats | null>;
196
+ getRaw: () => Promise<GqlProtocolStats | null>;
197
+ };
198
+ type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;
199
+
200
+ /**
201
+ * Transaction Logs domain module for the Zenland SDK
202
+ */
203
+
204
+ interface ListTransactionLogsArgs {
205
+ escrowAddress?: string;
206
+ limit?: number;
207
+ offset?: number;
208
+ orderBy?: string;
209
+ orderDirection?: "asc" | "desc";
210
+ }
211
+ /**
212
+ * Creates transaction logs domain functions bound to a base URL
213
+ */
214
+ declare function createTransactionLogsDomain(baseUrl: string): {
215
+ list: (args?: ListTransactionLogsArgs) => Promise<GqlTransactionLog[]>;
216
+ getByEscrow: (escrowAddress: string, args?: Omit<ListTransactionLogsArgs, "escrowAddress">) => Promise<GqlTransactionLog[]>;
217
+ parseEventData: (eventData: string) => Record<string, unknown>;
218
+ };
219
+ type TransactionLogsDomain = ReturnType<typeof createTransactionLogsDomain>;
220
+
221
+ /**
222
+ * Zenland SDK Client
223
+ *
224
+ * The main entry point for interacting with the Zenland indexer.
225
+ */
226
+
227
+ interface ZenlandClientConfig {
228
+ /** Base URL for the indexer API. Defaults to https://api.zen.land */
229
+ baseUrl?: string;
230
+ }
231
+ interface ZenlandClient {
232
+ /** The base URL being used by this client */
233
+ readonly baseUrl: string;
234
+ /** Escrow-related operations */
235
+ readonly escrows: EscrowsDomain;
236
+ /** Agent-related operations */
237
+ readonly agents: AgentsDomain;
238
+ /** Protocol statistics */
239
+ readonly protocolStats: ProtocolStatsDomain;
240
+ /** Transaction logs */
241
+ readonly transactionLogs: TransactionLogsDomain;
242
+ }
243
+ /**
244
+ * Create a new Zenland SDK client.
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * // Use production API (default)
249
+ * const client = createZenlandClient();
250
+ *
251
+ * // Use custom endpoint (e.g., local development)
252
+ * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });
253
+ *
254
+ * // Fetch escrows
255
+ * const { items, totalCount } = await client.escrows.list({ limit: 10 });
256
+ *
257
+ * // Fetch a specific escrow
258
+ * const escrow = await client.escrows.getById('0x...');
259
+ *
260
+ * // Fetch agents
261
+ * const agents = await client.agents.list({ onlyActive: true });
262
+ *
263
+ * // Fetch protocol stats
264
+ * const stats = await client.protocolStats.get();
265
+ * ```
266
+ */
267
+ declare function createZenlandClient(config?: ZenlandClientConfig): ZenlandClient;
268
+
269
+ interface ZenlandProviderProps {
270
+ children: ReactNode;
271
+ /** Optional configuration for the SDK client */
272
+ config?: ZenlandClientConfig;
273
+ }
274
+ /**
275
+ * Provider component for the Zenland SDK.
276
+ *
277
+ * Wrap your app with this provider to use the React hooks.
278
+ *
279
+ * @example
280
+ * ```tsx
281
+ * import { ZenlandProvider } from '@zenland/sdk/react';
282
+ *
283
+ * function App() {
284
+ * return (
285
+ * <ZenlandProvider>
286
+ * <YourApp />
287
+ * </ZenlandProvider>
288
+ * );
289
+ * }
290
+ *
291
+ * // With custom config
292
+ * <ZenlandProvider config={{ baseUrl: 'http://localhost:42069' }}>
293
+ * <YourApp />
294
+ * </ZenlandProvider>
295
+ * ```
296
+ */
297
+ declare function ZenlandProvider({ children, config }: ZenlandProviderProps): react_jsx_runtime.JSX.Element;
298
+ /**
299
+ * Hook to access the Zenland SDK client.
300
+ *
301
+ * Must be used within a ZenlandProvider.
302
+ *
303
+ * @example
304
+ * ```tsx
305
+ * import { useZenlandClient } from '@zenland/sdk/react';
306
+ *
307
+ * function MyComponent() {
308
+ * const client = useZenlandClient();
309
+ * // Use client.escrows, client.agents, etc.
310
+ * }
311
+ * ```
312
+ */
313
+ declare function useZenlandClient(): ZenlandClient;
314
+ /**
315
+ * Hook to access the Zenland SDK client, creating a default one if not in a provider.
316
+ *
317
+ * This is useful for components that might be used outside of a ZenlandProvider.
318
+ */
319
+ declare function useZenlandClientOptional(): ZenlandClient;
320
+
321
+ interface UseEscrowOptions {
322
+ /** Whether to enable the query */
323
+ enabled?: boolean;
324
+ }
325
+ /**
326
+ * Hook to fetch a single escrow by ID.
327
+ *
328
+ * @example
329
+ * ```tsx
330
+ * import { useEscrow } from '@zenland/sdk/react';
331
+ *
332
+ * function EscrowDetail({ id }: { id: string }) {
333
+ * const { data: escrow, isLoading, error } = useEscrow(id);
334
+ *
335
+ * if (isLoading) return <div>Loading...</div>;
336
+ * if (error) return <div>Error: {error.message}</div>;
337
+ * if (!escrow) return <div>Escrow not found</div>;
338
+ *
339
+ * return <div>{escrow.state}</div>;
340
+ * }
341
+ * ```
342
+ */
343
+ declare function useEscrow(id: string | undefined, options?: UseEscrowOptions): _tanstack_react_query.UseQueryResult<GqlEscrow | null, Error>;
344
+
345
+ type EscrowRole = "all" | "buyer" | "seller" | "agent";
346
+ type EscrowStateTab = "all" | StateGroup;
347
+ interface UseEscrowsArgs {
348
+ /** User address to filter by */
349
+ address?: string;
350
+ /** Pagination limit */
351
+ limit?: number;
352
+ /** Pagination offset */
353
+ offset?: number;
354
+ /** Filter by role (requires address) */
355
+ role?: EscrowRole;
356
+ /** Filter by state group */
357
+ stateTab?: EscrowStateTab;
358
+ /** Filter by specific state */
359
+ state?: string;
360
+ /** Filter by multiple states */
361
+ states?: string[];
362
+ /** Whether to enable the query */
363
+ enabled?: boolean;
364
+ }
365
+ /**
366
+ * Hook to fetch escrows with filtering and pagination.
367
+ *
368
+ * @example
369
+ * ```tsx
370
+ * import { useEscrows } from '@zenland/sdk/react';
371
+ *
372
+ * function MyEscrows({ address }: { address: string }) {
373
+ * const { data, isLoading } = useEscrows({
374
+ * address,
375
+ * role: 'buyer',
376
+ * stateTab: 'ACTIVE',
377
+ * });
378
+ *
379
+ * if (isLoading) return <div>Loading...</div>;
380
+ *
381
+ * return (
382
+ * <ul>
383
+ * {data?.items.map(escrow => (
384
+ * <li key={escrow.id}>{escrow.state}</li>
385
+ * ))}
386
+ * </ul>
387
+ * );
388
+ * }
389
+ * ```
390
+ */
391
+ declare function useEscrows(args?: UseEscrowsArgs): _tanstack_react_query.UseQueryResult<GqlEscrowPage, Error>;
392
+
393
+ interface UseAgentOptions {
394
+ /** Whether to enable the query */
395
+ enabled?: boolean;
396
+ }
397
+ /**
398
+ * Hook to fetch a single agent by address.
399
+ *
400
+ * @example
401
+ * ```tsx
402
+ * import { useAgent } from '@zenland/sdk/react';
403
+ *
404
+ * function AgentProfile({ address }: { address: string }) {
405
+ * const { data: agent, isLoading, error } = useAgent(address);
406
+ *
407
+ * if (isLoading) return <div>Loading...</div>;
408
+ * if (error) return <div>Error: {error.message}</div>;
409
+ * if (!agent) return <div>Agent not found</div>;
410
+ *
411
+ * return <div>{agent.description}</div>;
412
+ * }
413
+ * ```
414
+ */
415
+ declare function useAgent(address: string | undefined, options?: UseAgentOptions): _tanstack_react_query.UseQueryResult<GqlAgent | null, Error>;
416
+
417
+ interface UseAgentsArgs {
418
+ /** Only return active agents */
419
+ onlyActive?: boolean;
420
+ /** Only return available agents */
421
+ onlyAvailable?: boolean;
422
+ /** Pagination limit */
423
+ limit?: number;
424
+ /** Pagination offset */
425
+ offset?: number;
426
+ /** Whether to enable the query */
427
+ enabled?: boolean;
428
+ }
429
+ /**
430
+ * Hook to fetch agents with filtering and pagination.
431
+ *
432
+ * @example
433
+ * ```tsx
434
+ * import { useAgents } from '@zenland/sdk/react';
435
+ *
436
+ * function AgentList() {
437
+ * const { data, isLoading } = useAgents({ onlyActive: true });
438
+ *
439
+ * if (isLoading) return <div>Loading...</div>;
440
+ *
441
+ * return (
442
+ * <ul>
443
+ * {data?.items.map(agent => (
444
+ * <li key={agent.id}>{agent.description}</li>
445
+ * ))}
446
+ * </ul>
447
+ * );
448
+ * }
449
+ * ```
450
+ */
451
+ declare function useAgents(args?: UseAgentsArgs): _tanstack_react_query.UseQueryResult<GqlAgentPage, Error>;
452
+
453
+ interface UseProtocolStatsOptions {
454
+ /** Whether to enable the query */
455
+ enabled?: boolean;
456
+ /** Stale time in milliseconds (default: 30s) */
457
+ staleTime?: number;
458
+ /** Refetch interval in milliseconds (default: 60s) */
459
+ refetchInterval?: number;
460
+ }
461
+ /**
462
+ * Hook to fetch global protocol statistics.
463
+ *
464
+ * @example
465
+ * ```tsx
466
+ * import { useProtocolStats } from '@zenland/sdk/react';
467
+ *
468
+ * function ProtocolOverview() {
469
+ * const { data: stats, isLoading } = useProtocolStats();
470
+ *
471
+ * if (isLoading) return <div>Loading...</div>;
472
+ * if (!stats) return <div>Stats not available</div>;
473
+ *
474
+ * return (
475
+ * <div>
476
+ * <p>Total Escrows: {stats.totalEscrowsCreated}</p>
477
+ * <p>TVL: {stats.currentTVL.toString()}</p>
478
+ * </div>
479
+ * );
480
+ * }
481
+ * ```
482
+ */
483
+ declare function useProtocolStats(options?: UseProtocolStatsOptions): _tanstack_react_query.UseQueryResult<ProtocolStats | null, Error>;
484
+
485
+ interface UseRecentEscrowsOptions {
486
+ /** Number of escrows to fetch (default: 5) */
487
+ limit?: number;
488
+ /** Whether to enable the query */
489
+ enabled?: boolean;
490
+ /** Stale time in milliseconds (default: 15s) */
491
+ staleTime?: number;
492
+ /** Refetch interval in milliseconds (default: 30s) */
493
+ refetchInterval?: number;
494
+ }
495
+ /**
496
+ * Hook to fetch recent escrows for activity feeds.
497
+ *
498
+ * @example
499
+ * ```tsx
500
+ * import { useRecentEscrows } from '@zenland/sdk/react';
501
+ *
502
+ * function ActivityFeed() {
503
+ * const { data: escrows, isLoading } = useRecentEscrows({ limit: 10 });
504
+ *
505
+ * if (isLoading) return <div>Loading...</div>;
506
+ *
507
+ * return (
508
+ * <ul>
509
+ * {escrows?.map(escrow => (
510
+ * <li key={escrow.id}>
511
+ * {escrow.state} - {escrow.amount}
512
+ * </li>
513
+ * ))}
514
+ * </ul>
515
+ * );
516
+ * }
517
+ * ```
518
+ */
519
+ declare function useRecentEscrows(options?: UseRecentEscrowsOptions): _tanstack_react_query.UseQueryResult<GqlEscrow[], Error>;
520
+
521
+ interface UserDashboardStats {
522
+ activeCount: number;
523
+ disputeCount: number;
524
+ completedCount: number;
525
+ tvl: bigint;
526
+ recentEscrows: GqlEscrow[];
527
+ }
528
+ /**
529
+ * Hook to fetch user-specific dashboard statistics.
530
+ */
531
+ declare function useUserStats(userAddress: string | undefined): _tanstack_react_query.UseQueryResult<UserDashboardStats | null, Error>;
532
+ /**
533
+ * Hook to fetch global dashboard statistics.
534
+ */
535
+ declare function useGlobalStats(): _tanstack_react_query.UseQueryResult<Omit<UserDashboardStats, "tvl"> & {
536
+ tvl: null;
537
+ }, Error>;
538
+
539
+ interface UseTransactionLogsByEscrowOptions {
540
+ /** Whether to enable the query */
541
+ enabled?: boolean;
542
+ /** Stale time in milliseconds (default: 30s) */
543
+ staleTime?: number;
544
+ /** Refetch interval in milliseconds */
545
+ refetchInterval?: number;
546
+ /** Transaction log list options */
547
+ list?: Omit<ListTransactionLogsArgs, "escrowAddress">;
548
+ }
549
+ /**
550
+ * Hook to fetch transaction logs for a specific escrow.
551
+ */
552
+ declare function useTransactionLogsByEscrow(escrowAddress: string | undefined | null, options?: UseTransactionLogsByEscrowOptions): _tanstack_react_query.UseQueryResult<GqlTransactionLog[], Error>;
553
+
554
+ export { type EscrowRole, type EscrowStateTab, type GqlAgent, type GqlAgentPage, type GqlEscrow, type GqlEscrowPage, type GqlPageInfo, type GqlProtocolStats, type GqlTransactionLog, type ProtocolStats, STATE_GROUPS, type UseAgentOptions, type UseAgentsArgs, type UseEscrowOptions, type UseEscrowsArgs, type UseProtocolStatsOptions, type UseRecentEscrowsOptions, type UseTransactionLogsByEscrowOptions, type UserDashboardStats, type ZenlandClient, type ZenlandClientConfig, ZenlandProvider, type ZenlandProviderProps, createZenlandClient, useAgent, useAgents, useEscrow, useEscrows, useGlobalStats, useProtocolStats, useRecentEscrows, useTransactionLogsByEscrow, useUserStats, useZenlandClient, useZenlandClientOptional };