@zenland/sdk 0.1.0 → 0.1.2
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/index.cjs +10 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +10 -5
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +17 -2
- package/dist/react.d.ts +17 -2
- package/dist/react.js +10 -5
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -158,6 +158,7 @@ var ESCROW_QUERY = `
|
|
|
158
158
|
query escrow($id: String!) {
|
|
159
159
|
escrow(id: $id) {
|
|
160
160
|
id
|
|
161
|
+
chainId
|
|
161
162
|
buyer
|
|
162
163
|
seller
|
|
163
164
|
agent
|
|
@@ -202,6 +203,7 @@ query escrows(
|
|
|
202
203
|
) {
|
|
203
204
|
items {
|
|
204
205
|
id
|
|
206
|
+
chainId
|
|
205
207
|
buyer
|
|
206
208
|
seller
|
|
207
209
|
agent
|
|
@@ -229,9 +231,10 @@ query escrows(
|
|
|
229
231
|
}
|
|
230
232
|
`;
|
|
231
233
|
var PROTOCOL_STATS_QUERY = `
|
|
232
|
-
query protocolStats($id: String! = "
|
|
234
|
+
query protocolStats($id: String! = "mainnet") {
|
|
233
235
|
protocolStats(id: $id) {
|
|
234
236
|
id
|
|
237
|
+
chainId
|
|
235
238
|
totalEscrowsCreated
|
|
236
239
|
totalVolumeEscrowed
|
|
237
240
|
totalFeesCollected
|
|
@@ -372,9 +375,11 @@ function createAgentsDomain(baseUrl) {
|
|
|
372
375
|
}
|
|
373
376
|
|
|
374
377
|
// src/domains/protocol-stats.ts
|
|
378
|
+
var DEFAULT_STATS_ID = "mainnet";
|
|
375
379
|
function normalizeProtocolStats(raw) {
|
|
376
380
|
return {
|
|
377
381
|
id: raw.id,
|
|
382
|
+
chainId: raw.chainId,
|
|
378
383
|
totalEscrowsCreated: raw.totalEscrowsCreated,
|
|
379
384
|
totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),
|
|
380
385
|
totalFeesCollected: BigInt(raw.totalFeesCollected),
|
|
@@ -385,8 +390,8 @@ function normalizeProtocolStats(raw) {
|
|
|
385
390
|
};
|
|
386
391
|
}
|
|
387
392
|
function createProtocolStatsDomain(baseUrl) {
|
|
388
|
-
async function get() {
|
|
389
|
-
const variables = { id:
|
|
393
|
+
async function get(options) {
|
|
394
|
+
const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };
|
|
390
395
|
const response = await graphqlRequest(
|
|
391
396
|
baseUrl,
|
|
392
397
|
PROTOCOL_STATS_QUERY,
|
|
@@ -397,8 +402,8 @@ function createProtocolStatsDomain(baseUrl) {
|
|
|
397
402
|
}
|
|
398
403
|
return normalizeProtocolStats(response.protocolStats);
|
|
399
404
|
}
|
|
400
|
-
async function getRaw() {
|
|
401
|
-
const variables = { id:
|
|
405
|
+
async function getRaw(options) {
|
|
406
|
+
const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };
|
|
402
407
|
const response = await graphqlRequest(
|
|
403
408
|
baseUrl,
|
|
404
409
|
PROTOCOL_STATS_QUERY,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/request.ts","../src/queries.ts","../src/domains/escrows.ts","../src/domains/agents.ts","../src/domains/protocol-stats.ts","../src/domains/transaction-logs.ts","../src/client.ts","../src/agents/eligibility.ts"],"sourcesContent":["/**\n * @zenland/sdk\n *\n * Official SDK for interacting with the Zenland escrow protocol indexer.\n *\n * @example\n * ```typescript\n * import { createZenlandClient, zenland } from '@zenland/sdk';\n *\n * // Use the default client (production API)\n * const escrows = await zenland.escrows.list();\n *\n * // Or create a custom client\n * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });\n * const agents = await client.agents.list({ onlyActive: true });\n * ```\n */\n\n// Main client\nexport { createZenlandClient, zenland } from \"./client\";\nexport type { ZenlandClient, ZenlandClientConfig } from \"./client\";\n\n// Domain modules (for advanced usage)\nexport {\n createEscrowsDomain,\n createAgentsDomain,\n createProtocolStatsDomain,\n createTransactionLogsDomain,\n STATE_GROUPS,\n} from \"./domains\";\nexport type {\n EscrowsDomain,\n AgentsDomain,\n ProtocolStatsDomain,\n TransactionLogsDomain,\n ListEscrowsArgs,\n ListAgentsArgs,\n ListTransactionLogsArgs,\n StateGroup,\n ProtocolStats,\n} from \"./domains\";\n\n// Types\nexport type {\n // GraphQL types\n GqlAgent,\n GqlAgentCase,\n GqlAgentCasePage,\n GqlAgentPage,\n GqlAgentFilter,\n GqlEscrow,\n GqlEscrowPage,\n GqlEscrowFilter,\n GqlProtocolStats,\n GqlTransactionLog,\n GqlTransactionLogPage,\n GqlTransactionLogFilter,\n GqlPageInfo,\n BigIntScalar,\n Maybe,\n InputMaybe,\n} from \"./generated/types\";\n\n// Protocol / business-logic utilities\nexport {\n computeAgentMavUsd,\n isAgentEligibleForEscrow,\n} from \"./agents/eligibility\";\nexport type {\n IndexerAgent,\n AgentEligibilityFailureReason,\n AgentEligibilityResult,\n} from \"./agents/eligibility\";\n\n// Errors\nexport { ZenlandGraphQLError, ZenlandRequestError } from \"./request\";\n","/**\n * GraphQL request utilities for the Zenland SDK\n */\n\ntype GraphQLErrorLike = {\n message?: string;\n [key: string]: unknown;\n};\n\ntype GraphQLResponse<TData> = {\n data?: TData;\n errors?: GraphQLErrorLike[];\n};\n\n/**\n * Error thrown when the indexer returns GraphQL errors\n */\nexport class ZenlandGraphQLError extends Error {\n public readonly errors: GraphQLErrorLike[];\n\n constructor(message: string, errors: GraphQLErrorLike[]) {\n super(message);\n this.name = \"ZenlandGraphQLError\";\n this.errors = errors;\n }\n}\n\n/**\n * Error thrown when the indexer request fails at the network/HTTP level\n */\nexport class ZenlandRequestError extends Error {\n public readonly status: number;\n public readonly statusText: string;\n\n constructor(message: string, status: number, statusText: string) {\n super(message);\n this.name = \"ZenlandRequestError\";\n this.status = status;\n this.statusText = statusText;\n }\n}\n\nexport interface GraphQLRequestOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Execute a GraphQL request against the Zenland indexer\n */\nexport async function graphqlRequest<TData, TVariables extends object | undefined>(\n baseUrl: string,\n document: string,\n variables?: TVariables,\n options?: GraphQLRequestOptions,\n): Promise<TData> {\n const endpoint = `${baseUrl}/graphql`;\n\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({ query: document, variables }),\n signal: options?.signal,\n cache: \"no-store\",\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ZenlandRequestError(\n `Zenland request failed (${res.status} ${res.statusText})${text ? `: ${text}` : \"\"}`,\n res.status,\n res.statusText,\n );\n }\n\n const json = (await res.json()) as GraphQLResponse<TData>;\n\n if (json.errors?.length) {\n throw new ZenlandGraphQLError(\n json.errors.map((e) => e.message ?? \"GraphQL error\").join(\"; \"),\n json.errors,\n );\n }\n\n if (!json.data) {\n throw new Error(\"Zenland response missing data.\");\n }\n\n return json.data;\n}\n","/**\n * GraphQL query strings for the Zenland indexer.\n * These are compiled into the SDK to avoid runtime parsing.\n */\n\nexport const AGENT_QUERY = `\nquery Agent($id: String!) {\n agent(id: $id) {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinToken\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n cases(limit: 5, orderBy: \"invitedAt\", orderDirection: \"desc\") {\n items {\n id\n escrow\n invitedAt\n resolvedAt\n timedOut\n escrowRef {\n id\n amount\n token\n state\n }\n }\n totalCount\n }\n }\n}\n`;\n\nexport const AGENTS_QUERY = `\nquery Agents($where: agentFilter, $orderBy: String, $orderDirection: String, $limit: Int, $offset: Int) {\n agents(where: $where, orderBy: $orderBy, orderDirection: $orderDirection, limit: $limit, offset: $offset) {\n totalCount\n items {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n }\n}\n`;\n\nexport const ESCROW_QUERY = `\nquery escrow($id: String!) {\n escrow(id: $id) {\n id\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n sellerAcceptDeadline\n buyerProtectionTime\n termsHash\n version\n fundedAt\n fulfilledAt\n resolvedAt\n agentInvitedAt\n splitProposer\n proposedBuyerBps\n proposedSellerBps\n buyerApprovedSplit\n sellerApprovedSplit\n agentFeeReceived\n buyerReceived\n sellerReceived\n creationFee\n }\n}\n`;\n\nexport const ESCROWS_QUERY = `\nquery escrows(\n $limit: Int = 30\n $offset: Int = 0\n $orderBy: String = \"createdAt\"\n $orderDirection: String = \"desc\"\n $where: escrowFilter\n) {\n escrows(\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n items {\n id\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n fundedAt\n fulfilledAt\n sellerAcceptDeadline\n agentInvitedAt\n buyerProtectionTime\n splitProposer\n buyerApprovedSplit\n sellerApprovedSplit\n proposedBuyerBps\n proposedSellerBps\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n totalCount\n }\n}\n`;\n\nexport const PROTOCOL_STATS_QUERY = `\nquery protocolStats($id: String! = \"global\") {\n protocolStats(id: $id) {\n id\n totalEscrowsCreated\n totalVolumeEscrowed\n totalFeesCollected\n currentTVL\n activeEscrowCount\n totalAgentsRegistered\n activeAgentsCount\n }\n}\n`;\n\nexport const RECENT_ESCROWS_QUERY = `\nquery recentEscrows($limit: Int = 5) {\n escrows(\n limit: $limit\n orderBy: \"createdAt\"\n orderDirection: \"desc\"\n ) {\n items {\n id\n amount\n token\n state\n createdAt\n }\n }\n}\n`;\n\nexport const TRANSACTION_LOGS_QUERY = `\nquery transactionLogs(\n $escrowAddress: String\n $limit: Int\n $offset: Int\n $orderBy: String\n $orderDirection: String\n) {\n transactionLogs(\n where: { escrowAddress: $escrowAddress }\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n items {\n id\n txHash\n blockNumber\n timestamp\n eventName\n contractAddress\n contractType\n escrowAddress\n agentAddress\n userAddress\n eventData\n }\n }\n}\n`;\n","/**\n * Escrow domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { ESCROW_QUERY, ESCROWS_QUERY } from \"../queries\";\nimport type {\n GqlEscrow,\n GqlEscrowPage,\n GqlEscrowFilter,\n EscrowQueryResponse,\n EscrowsQueryResponse,\n} from \"../generated/types\";\n\n/** State groups for filtering escrows */\nexport const STATE_GROUPS = {\n ACTIVE: [\"PENDING\", \"ACTIVE\", \"FULFILLED\"] as const,\n IN_DISPUTE: [\"DISPUTED\", \"AGENT_INVITED\"] as const,\n COMPLETED: [\"RELEASED\", \"AGENT_RESOLVED\", \"REFUNDED\", \"SPLIT\"] as const,\n} as const;\n\nexport type StateGroup = keyof typeof STATE_GROUPS;\n\nexport interface ListEscrowsArgs {\n limit?: number;\n offset?: number;\n buyer?: string;\n seller?: string;\n agent?: string;\n /** Search across buyer, seller, or agent roles */\n user?: string;\n state?: string;\n /** Multiple states for group filtering */\n states?: string[];\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates escrow domain functions bound to a base URL\n */\nexport function createEscrowsDomain(baseUrl: string) {\n /**\n * List escrows with filtering and pagination\n */\n async function list(args?: ListEscrowsArgs): Promise<GqlEscrowPage> {\n const where: GqlEscrowFilter = {};\n\n // Role-specific filters\n if (args?.buyer) where.buyer = args.buyer.toLowerCase();\n if (args?.seller) where.seller = args.seller.toLowerCase();\n if (args?.agent) where.agent = args.agent.toLowerCase();\n\n // State filters - single or multiple\n if (args?.states && args.states.length > 0) {\n where.state_in = args.states;\n } else if (args?.state) {\n where.state = args.state;\n }\n\n // User filter: search across buyer, seller, or agent roles\n if (args?.user) {\n const userLower = args.user.toLowerCase();\n where.OR = [{ buyer: userLower }, { seller: userLower }, { agent: userLower }];\n }\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"createdAt\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<EscrowsQueryResponse, typeof variables>(\n baseUrl,\n ESCROWS_QUERY,\n variables,\n );\n\n return response.escrows;\n }\n\n /**\n * Get a single escrow by ID (address)\n */\n async function getById(id: string): Promise<GqlEscrow | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<EscrowQueryResponse, typeof variables>(\n baseUrl,\n ESCROW_QUERY,\n variables,\n );\n\n return response.escrow;\n }\n\n /**\n * Get escrows for a specific user across all roles\n */\n async function getByUser(\n userAddress: string,\n args?: Omit<ListEscrowsArgs, \"user\" | \"buyer\" | \"seller\" | \"agent\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, user: userAddress });\n }\n\n /**\n * Get escrows by state group\n */\n async function getByStateGroup(\n stateGroup: StateGroup,\n args?: Omit<ListEscrowsArgs, \"state\" | \"states\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, states: [...STATE_GROUPS[stateGroup]] });\n }\n\n return {\n list,\n getById,\n getByUser,\n getByStateGroup,\n };\n}\n\nexport type EscrowsDomain = ReturnType<typeof createEscrowsDomain>;\n","/**\n * Agent domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { AGENT_QUERY, AGENTS_QUERY } from \"../queries\";\nimport type {\n GqlAgent,\n GqlAgentPage,\n GqlAgentFilter,\n AgentQueryResponse,\n AgentsQueryResponse,\n} from \"../generated/types\";\n\nexport interface ListAgentsArgs {\n limit?: number;\n offset?: number;\n onlyActive?: boolean;\n onlyAvailable?: boolean;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates agent domain functions bound to a base URL\n */\nexport function createAgentsDomain(baseUrl: string) {\n /**\n * List agents with filtering and pagination\n */\n async function list(args?: ListAgentsArgs): Promise<GqlAgentPage> {\n const where: GqlAgentFilter = {};\n\n if (args?.onlyActive) where.isActive = true;\n if (args?.onlyAvailable) where.isAvailable = true;\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"totalResolved\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<AgentsQueryResponse, typeof variables>(\n baseUrl,\n AGENTS_QUERY,\n variables,\n );\n\n return response.agents;\n }\n\n /**\n * Get a single agent by ID (address)\n */\n async function getById(id: string): Promise<GqlAgent | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<AgentQueryResponse, typeof variables>(\n baseUrl,\n AGENT_QUERY,\n variables,\n );\n\n return response.agent;\n }\n\n /**\n * Get all active and available agents\n */\n async function getAvailable(args?: Omit<ListAgentsArgs, \"onlyActive\" | \"onlyAvailable\">): Promise<GqlAgentPage> {\n return list({ ...args, onlyActive: true, onlyAvailable: true });\n }\n\n return {\n list,\n getById,\n getAvailable,\n };\n}\n\nexport type AgentsDomain = ReturnType<typeof createAgentsDomain>;\n","/**\n * Protocol Stats domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { PROTOCOL_STATS_QUERY } from \"../queries\";\nimport type { GqlProtocolStats, ProtocolStatsQueryResponse } from \"../generated/types\";\n\n/** Normalized protocol stats with BigInt values */\nexport interface ProtocolStats {\n id: string;\n totalEscrowsCreated: number;\n totalVolumeEscrowed: bigint;\n totalFeesCollected: bigint;\n currentTVL: bigint;\n activeEscrowCount: number;\n totalAgentsRegistered: number;\n activeAgentsCount: number;\n}\n\n/**\n * Convert raw GraphQL response to normalized ProtocolStats\n */\nfunction normalizeProtocolStats(raw: GqlProtocolStats): ProtocolStats {\n return {\n id: raw.id,\n totalEscrowsCreated: raw.totalEscrowsCreated,\n totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),\n totalFeesCollected: BigInt(raw.totalFeesCollected),\n currentTVL: BigInt(raw.currentTVL),\n activeEscrowCount: raw.activeEscrowCount,\n totalAgentsRegistered: raw.totalAgentsRegistered,\n activeAgentsCount: raw.activeAgentsCount,\n };\n}\n\n/**\n * Creates protocol stats domain functions bound to a base URL\n */\nexport function createProtocolStatsDomain(baseUrl: string) {\n /**\n * Fetch global protocol statistics\n */\n async function get(): Promise<ProtocolStats | null> {\n const variables = { id: \"global\" };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n if (!response.protocolStats) {\n return null;\n }\n\n return normalizeProtocolStats(response.protocolStats);\n }\n\n /**\n * Fetch raw protocol statistics (without BigInt conversion)\n */\n async function getRaw(): Promise<GqlProtocolStats | null> {\n const variables = { id: \"global\" };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n return response.protocolStats;\n }\n\n return {\n get,\n getRaw,\n };\n}\n\nexport type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;\n","/**\n * Transaction Logs domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { TRANSACTION_LOGS_QUERY } from \"../queries\";\nimport type { GqlTransactionLog, TransactionLogsQueryResponse } from \"../generated/types\";\n\nexport interface ListTransactionLogsArgs {\n escrowAddress?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates transaction logs domain functions bound to a base URL\n */\nexport function createTransactionLogsDomain(baseUrl: string) {\n /**\n * List transaction logs with filtering and pagination\n */\n async function list(args?: ListTransactionLogsArgs): Promise<GqlTransactionLog[]> {\n const variables = {\n escrowAddress: args?.escrowAddress?.toLowerCase(),\n limit: args?.limit ?? 100,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"timestamp\",\n orderDirection: args?.orderDirection ?? \"asc\",\n };\n\n const response = await graphqlRequest<TransactionLogsQueryResponse, typeof variables>(\n baseUrl,\n TRANSACTION_LOGS_QUERY,\n variables,\n );\n\n return response.transactionLogs.items;\n }\n\n /**\n * Get transaction logs for a specific escrow\n */\n async function getByEscrow(\n escrowAddress: string,\n args?: Omit<ListTransactionLogsArgs, \"escrowAddress\">,\n ): Promise<GqlTransactionLog[]> {\n return list({ ...args, escrowAddress });\n }\n\n /**\n * Parse eventData JSON string from a transaction log\n */\n function parseEventData(eventData: string): Record<string, unknown> {\n try {\n return JSON.parse(eventData);\n } catch {\n return {};\n }\n }\n\n return {\n list,\n getByEscrow,\n parseEventData,\n };\n}\n\nexport type TransactionLogsDomain = ReturnType<typeof createTransactionLogsDomain>;\n","/**\n * Zenland SDK Client\n *\n * The main entry point for interacting with the Zenland indexer.\n */\n\nimport { createEscrowsDomain, type EscrowsDomain } from \"./domains/escrows\";\nimport { createAgentsDomain, type AgentsDomain } from \"./domains/agents\";\nimport { createProtocolStatsDomain, type ProtocolStatsDomain } from \"./domains/protocol-stats\";\nimport { createTransactionLogsDomain, type TransactionLogsDomain } from \"./domains/transaction-logs\";\n\n/** Default production indexer URL */\nconst DEFAULT_BASE_URL = \"https://api.zen.land\";\n\nexport interface ZenlandClientConfig {\n /** Base URL for the indexer API. Defaults to https://api.zen.land */\n baseUrl?: string;\n}\n\nexport interface ZenlandClient {\n /** The base URL being used by this client */\n readonly baseUrl: string;\n\n /** Escrow-related operations */\n readonly escrows: EscrowsDomain;\n\n /** Agent-related operations */\n readonly agents: AgentsDomain;\n\n /** Protocol statistics */\n readonly protocolStats: ProtocolStatsDomain;\n\n /** Transaction logs */\n readonly transactionLogs: TransactionLogsDomain;\n}\n\n/**\n * Create a new Zenland SDK client.\n *\n * @example\n * ```typescript\n * // Use production API (default)\n * const client = createZenlandClient();\n *\n * // Use custom endpoint (e.g., local development)\n * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });\n *\n * // Fetch escrows\n * const { items, totalCount } = await client.escrows.list({ limit: 10 });\n *\n * // Fetch a specific escrow\n * const escrow = await client.escrows.getById('0x...');\n *\n * // Fetch agents\n * const agents = await client.agents.list({ onlyActive: true });\n *\n * // Fetch protocol stats\n * const stats = await client.protocolStats.get();\n * ```\n */\nexport function createZenlandClient(config?: ZenlandClientConfig): ZenlandClient {\n const baseUrl = normalizeBaseUrl(config?.baseUrl ?? DEFAULT_BASE_URL);\n\n return {\n baseUrl,\n escrows: createEscrowsDomain(baseUrl),\n agents: createAgentsDomain(baseUrl),\n protocolStats: createProtocolStatsDomain(baseUrl),\n transactionLogs: createTransactionLogsDomain(baseUrl),\n };\n}\n\n/**\n * Normalize base URL by removing trailing slash\n */\nfunction normalizeBaseUrl(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\n/**\n * Default client instance using production API.\n * Use this for quick access without creating a new client.\n *\n * @example\n * ```typescript\n * import { zenland } from '@zenland/sdk';\n *\n * const escrows = await zenland.escrows.list();\n * ```\n */\nexport const zenland = createZenlandClient();\n","/**\n * Agent eligibility utilities.\n *\n * This is protocol/business logic (React-agnostic) and is safe to consume\n * from any app (interface, backend, bots, etc.).\n */\n\n/**\n * Minimal view of an Agent returned by the indexer.\n */\nexport type IndexerAgent = {\n id: string;\n isActive: boolean;\n isAvailable: boolean;\n stablecoinStake: bigint;\n stablecoinDecimals: number;\n registrationTime: bigint;\n activeCases: number;\n totalResolved: number;\n};\n\nexport type AgentEligibilityFailureReason =\n | \"NOT_REGISTERED\"\n | \"NOT_ACTIVE\"\n | \"NOT_AVAILABLE\"\n | \"INSUFFICIENT_MAV\";\n\nexport type AgentEligibilityResult =\n | {\n ok: true;\n agentMavUsd: bigint;\n requiredUsd: bigint;\n }\n | {\n ok: false;\n reason: AgentEligibilityFailureReason;\n agentMavUsd?: bigint;\n requiredUsd: bigint;\n };\n\n/**\n * MAV multiplier - how much MAV you get per dollar staked.\n * $1 stake * 20 = $20 MAV\n */\nconst MAV_MULTIPLIER = 20n;\n\n/**\n * Compute agent MAV from its stablecoin stake.\n *\n * Bigint-safe:\n * - stablecoinStake is in smallest units (stablecoinDecimals)\n * - return MAV in the same smallest units (stablecoinDecimals)\n */\nexport function computeAgentMavUsd(\n agent: Pick<IndexerAgent, \"stablecoinStake\" | \"stablecoinDecimals\">,\n): bigint {\n // decimals are not used in arithmetic; they’re carried for formatting.\n // MAV is a simple multiplier in the same units.\n return BigInt(agent.stablecoinStake) * MAV_MULTIPLIER;\n}\n\n/**\n * Evaluate whether an agent is eligible for a given escrow amount.\n *\n * NOTE: escrowAmount must be the escrow principal ONLY (fees excluded).\n */\nexport function isAgentEligibleForEscrow(args: {\n agent: IndexerAgent | null | undefined;\n escrowAmount: bigint;\n}): AgentEligibilityResult {\n const requiredUsd = args.escrowAmount;\n\n if (!args.agent) {\n return { ok: false, reason: \"NOT_REGISTERED\", requiredUsd };\n }\n\n if (!args.agent.isActive) {\n return { ok: false, reason: \"NOT_ACTIVE\", requiredUsd };\n }\n\n if (!args.agent.isAvailable) {\n return { ok: false, reason: \"NOT_AVAILABLE\", requiredUsd };\n }\n\n const agentMavUsd = computeAgentMavUsd(args.agent);\n\n if (agentMavUsd < requiredUsd) {\n return { ok: false, reason: \"INSUFFICIENT_MAV\", agentMavUsd, requiredUsd };\n }\n\n return { ok: true, agentMavUsd, requiredUsd };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EAEhB,YAAY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AW,gBAAgB;AAEpE,SAAO;AAAA,IACL;AAAA,IACA,SAAS,oBAAoB,OAAO;AAAA,IACpC,QAAQ,mBAAmB,OAAO;AAAA,IAClC,eAAe,0BAA0B,OAAO;AAAA,IAChD,iBAAiB,4BAA4B,OAAO;AAAA,EACtD;AACF;AAKA,SAAS,iBAAiB,KAAqB;AAC7C,SAAO,IAAI,SAAS,GAAG,IAAI,IAAI,MAAM,GAAG,EAAE,IAAI;AAChD;AAaO,IAAM,UAAU,oBAAoB;;;AC9C3C,IAAM,iBAAiB;AAShB,SAAS,mBACd,OACQ;AAGR,SAAO,OAAO,MAAM,eAAe,IAAI;AACzC;AAOO,SAAS,yBAAyB,MAGd;AACzB,QAAM,cAAc,KAAK;AAEzB,MAAI,CAAC,KAAK,OAAO;AACf,WAAO,EAAE,IAAI,OAAO,QAAQ,kBAAkB,YAAY;AAAA,EAC5D;AAEA,MAAI,CAAC,KAAK,MAAM,UAAU;AACxB,WAAO,EAAE,IAAI,OAAO,QAAQ,cAAc,YAAY;AAAA,EACxD;AAEA,MAAI,CAAC,KAAK,MAAM,aAAa;AAC3B,WAAO,EAAE,IAAI,OAAO,QAAQ,iBAAiB,YAAY;AAAA,EAC3D;AAEA,QAAM,cAAc,mBAAmB,KAAK,KAAK;AAEjD,MAAI,cAAc,aAAa;AAC7B,WAAO,EAAE,IAAI,OAAO,QAAQ,oBAAoB,aAAa,YAAY;AAAA,EAC3E;AAEA,SAAO,EAAE,IAAI,MAAM,aAAa,YAAY;AAC9C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/request.ts","../src/queries.ts","../src/domains/escrows.ts","../src/domains/agents.ts","../src/domains/protocol-stats.ts","../src/domains/transaction-logs.ts","../src/client.ts","../src/agents/eligibility.ts"],"sourcesContent":["/**\n * @zenland/sdk\n *\n * Official SDK for interacting with the Zenland escrow protocol indexer.\n *\n * @example\n * ```typescript\n * import { createZenlandClient, zenland } from '@zenland/sdk';\n *\n * // Use the default client (production API)\n * const escrows = await zenland.escrows.list();\n *\n * // Or create a custom client\n * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });\n * const agents = await client.agents.list({ onlyActive: true });\n * ```\n */\n\n// Main client\nexport { createZenlandClient, zenland } from \"./client\";\nexport type { ZenlandClient, ZenlandClientConfig } from \"./client\";\n\n// Domain modules (for advanced usage)\nexport {\n createEscrowsDomain,\n createAgentsDomain,\n createProtocolStatsDomain,\n createTransactionLogsDomain,\n STATE_GROUPS,\n} from \"./domains\";\nexport type {\n EscrowsDomain,\n AgentsDomain,\n ProtocolStatsDomain,\n TransactionLogsDomain,\n ListEscrowsArgs,\n ListAgentsArgs,\n ListTransactionLogsArgs,\n StateGroup,\n ProtocolStats,\n} from \"./domains\";\n\n// Types\nexport type {\n // GraphQL types\n GqlAgent,\n GqlAgentCase,\n GqlAgentCasePage,\n GqlAgentPage,\n GqlAgentFilter,\n GqlEscrow,\n GqlEscrowPage,\n GqlEscrowFilter,\n GqlProtocolStats,\n GqlTransactionLog,\n GqlTransactionLogPage,\n GqlTransactionLogFilter,\n GqlPageInfo,\n BigIntScalar,\n Maybe,\n InputMaybe,\n} from \"./generated/types\";\n\n// Protocol / business-logic utilities\nexport {\n computeAgentMavUsd,\n isAgentEligibleForEscrow,\n} from \"./agents/eligibility\";\nexport type {\n IndexerAgent,\n AgentEligibilityFailureReason,\n AgentEligibilityResult,\n} from \"./agents/eligibility\";\n\n// Errors\nexport { ZenlandGraphQLError, ZenlandRequestError } from \"./request\";\n","/**\n * GraphQL request utilities for the Zenland SDK\n */\n\ntype GraphQLErrorLike = {\n message?: string;\n [key: string]: unknown;\n};\n\ntype GraphQLResponse<TData> = {\n data?: TData;\n errors?: GraphQLErrorLike[];\n};\n\n/**\n * Error thrown when the indexer returns GraphQL errors\n */\nexport class ZenlandGraphQLError extends Error {\n public readonly errors: GraphQLErrorLike[];\n\n constructor(message: string, errors: GraphQLErrorLike[]) {\n super(message);\n this.name = \"ZenlandGraphQLError\";\n this.errors = errors;\n }\n}\n\n/**\n * Error thrown when the indexer request fails at the network/HTTP level\n */\nexport class ZenlandRequestError extends Error {\n public readonly status: number;\n public readonly statusText: string;\n\n constructor(message: string, status: number, statusText: string) {\n super(message);\n this.name = \"ZenlandRequestError\";\n this.status = status;\n this.statusText = statusText;\n }\n}\n\nexport interface GraphQLRequestOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Execute a GraphQL request against the Zenland indexer\n */\nexport async function graphqlRequest<TData, TVariables extends object | undefined>(\n baseUrl: string,\n document: string,\n variables?: TVariables,\n options?: GraphQLRequestOptions,\n): Promise<TData> {\n const endpoint = `${baseUrl}/graphql`;\n\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({ query: document, variables }),\n signal: options?.signal,\n cache: \"no-store\",\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ZenlandRequestError(\n `Zenland request failed (${res.status} ${res.statusText})${text ? `: ${text}` : \"\"}`,\n res.status,\n res.statusText,\n );\n }\n\n const json = (await res.json()) as GraphQLResponse<TData>;\n\n if (json.errors?.length) {\n throw new ZenlandGraphQLError(\n json.errors.map((e) => e.message ?? \"GraphQL error\").join(\"; \"),\n json.errors,\n );\n }\n\n if (!json.data) {\n throw new Error(\"Zenland response missing data.\");\n }\n\n return json.data;\n}\n","/**\n * GraphQL query strings for the Zenland indexer.\n * These are compiled into the SDK to avoid runtime parsing.\n */\n\nexport const AGENT_QUERY = `\nquery Agent($id: String!) {\n agent(id: $id) {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinToken\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n cases(limit: 5, orderBy: \"invitedAt\", orderDirection: \"desc\") {\n items {\n id\n escrow\n invitedAt\n resolvedAt\n timedOut\n escrowRef {\n id\n amount\n token\n state\n }\n }\n totalCount\n }\n }\n}\n`;\n\nexport const AGENTS_QUERY = `\nquery Agents($where: agentFilter, $orderBy: String, $orderDirection: String, $limit: Int, $offset: Int) {\n agents(where: $where, orderBy: $orderBy, orderDirection: $orderDirection, limit: $limit, offset: $offset) {\n totalCount\n items {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n }\n}\n`;\n\nexport const ESCROW_QUERY = `\nquery escrow($id: String!) {\n escrow(id: $id) {\n id\n chainId\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n sellerAcceptDeadline\n buyerProtectionTime\n termsHash\n version\n fundedAt\n fulfilledAt\n resolvedAt\n agentInvitedAt\n splitProposer\n proposedBuyerBps\n proposedSellerBps\n buyerApprovedSplit\n sellerApprovedSplit\n agentFeeReceived\n buyerReceived\n sellerReceived\n creationFee\n }\n}\n`;\n\nexport const ESCROWS_QUERY = `\nquery escrows(\n $limit: Int = 30\n $offset: Int = 0\n $orderBy: String = \"createdAt\"\n $orderDirection: String = \"desc\"\n $where: escrowFilter\n) {\n escrows(\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n items {\n id\n chainId\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n fundedAt\n fulfilledAt\n sellerAcceptDeadline\n agentInvitedAt\n buyerProtectionTime\n splitProposer\n buyerApprovedSplit\n sellerApprovedSplit\n proposedBuyerBps\n proposedSellerBps\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n totalCount\n }\n}\n`;\n\nexport const PROTOCOL_STATS_QUERY = `\nquery protocolStats($id: String! = \"mainnet\") {\n protocolStats(id: $id) {\n id\n chainId\n totalEscrowsCreated\n totalVolumeEscrowed\n totalFeesCollected\n currentTVL\n activeEscrowCount\n totalAgentsRegistered\n activeAgentsCount\n }\n}\n`;\n\nexport const RECENT_ESCROWS_QUERY = `\nquery recentEscrows($limit: Int = 5) {\n escrows(\n limit: $limit\n orderBy: \"createdAt\"\n orderDirection: \"desc\"\n ) {\n items {\n id\n amount\n token\n state\n createdAt\n }\n }\n}\n`;\n\nexport const TRANSACTION_LOGS_QUERY = `\nquery transactionLogs(\n $escrowAddress: String\n $limit: Int\n $offset: Int\n $orderBy: String\n $orderDirection: String\n) {\n transactionLogs(\n where: { escrowAddress: $escrowAddress }\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n items {\n id\n txHash\n blockNumber\n timestamp\n eventName\n contractAddress\n contractType\n escrowAddress\n agentAddress\n userAddress\n eventData\n }\n }\n}\n`;\n","/**\n * Escrow domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { ESCROW_QUERY, ESCROWS_QUERY } from \"../queries\";\nimport type {\n GqlEscrow,\n GqlEscrowPage,\n GqlEscrowFilter,\n EscrowQueryResponse,\n EscrowsQueryResponse,\n} from \"../generated/types\";\n\n/** State groups for filtering escrows */\nexport const STATE_GROUPS = {\n ACTIVE: [\"PENDING\", \"ACTIVE\", \"FULFILLED\"] as const,\n IN_DISPUTE: [\"DISPUTED\", \"AGENT_INVITED\"] as const,\n COMPLETED: [\"RELEASED\", \"AGENT_RESOLVED\", \"REFUNDED\", \"SPLIT\"] as const,\n} as const;\n\nexport type StateGroup = keyof typeof STATE_GROUPS;\n\nexport interface ListEscrowsArgs {\n limit?: number;\n offset?: number;\n buyer?: string;\n seller?: string;\n agent?: string;\n /** Search across buyer, seller, or agent roles */\n user?: string;\n state?: string;\n /** Multiple states for group filtering */\n states?: string[];\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates escrow domain functions bound to a base URL\n */\nexport function createEscrowsDomain(baseUrl: string) {\n /**\n * List escrows with filtering and pagination\n */\n async function list(args?: ListEscrowsArgs): Promise<GqlEscrowPage> {\n const where: GqlEscrowFilter = {};\n\n // Role-specific filters\n if (args?.buyer) where.buyer = args.buyer.toLowerCase();\n if (args?.seller) where.seller = args.seller.toLowerCase();\n if (args?.agent) where.agent = args.agent.toLowerCase();\n\n // State filters - single or multiple\n if (args?.states && args.states.length > 0) {\n where.state_in = args.states;\n } else if (args?.state) {\n where.state = args.state;\n }\n\n // User filter: search across buyer, seller, or agent roles\n if (args?.user) {\n const userLower = args.user.toLowerCase();\n where.OR = [{ buyer: userLower }, { seller: userLower }, { agent: userLower }];\n }\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"createdAt\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<EscrowsQueryResponse, typeof variables>(\n baseUrl,\n ESCROWS_QUERY,\n variables,\n );\n\n return response.escrows;\n }\n\n /**\n * Get a single escrow by ID (address)\n */\n async function getById(id: string): Promise<GqlEscrow | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<EscrowQueryResponse, typeof variables>(\n baseUrl,\n ESCROW_QUERY,\n variables,\n );\n\n return response.escrow;\n }\n\n /**\n * Get escrows for a specific user across all roles\n */\n async function getByUser(\n userAddress: string,\n args?: Omit<ListEscrowsArgs, \"user\" | \"buyer\" | \"seller\" | \"agent\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, user: userAddress });\n }\n\n /**\n * Get escrows by state group\n */\n async function getByStateGroup(\n stateGroup: StateGroup,\n args?: Omit<ListEscrowsArgs, \"state\" | \"states\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, states: [...STATE_GROUPS[stateGroup]] });\n }\n\n return {\n list,\n getById,\n getByUser,\n getByStateGroup,\n };\n}\n\nexport type EscrowsDomain = ReturnType<typeof createEscrowsDomain>;\n","/**\n * Agent domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { AGENT_QUERY, AGENTS_QUERY } from \"../queries\";\nimport type {\n GqlAgent,\n GqlAgentPage,\n GqlAgentFilter,\n AgentQueryResponse,\n AgentsQueryResponse,\n} from \"../generated/types\";\n\nexport interface ListAgentsArgs {\n limit?: number;\n offset?: number;\n onlyActive?: boolean;\n onlyAvailable?: boolean;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates agent domain functions bound to a base URL\n */\nexport function createAgentsDomain(baseUrl: string) {\n /**\n * List agents with filtering and pagination\n */\n async function list(args?: ListAgentsArgs): Promise<GqlAgentPage> {\n const where: GqlAgentFilter = {};\n\n if (args?.onlyActive) where.isActive = true;\n if (args?.onlyAvailable) where.isAvailable = true;\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"totalResolved\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<AgentsQueryResponse, typeof variables>(\n baseUrl,\n AGENTS_QUERY,\n variables,\n );\n\n return response.agents;\n }\n\n /**\n * Get a single agent by ID (address)\n */\n async function getById(id: string): Promise<GqlAgent | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<AgentQueryResponse, typeof variables>(\n baseUrl,\n AGENT_QUERY,\n variables,\n );\n\n return response.agent;\n }\n\n /**\n * Get all active and available agents\n */\n async function getAvailable(args?: Omit<ListAgentsArgs, \"onlyActive\" | \"onlyAvailable\">): Promise<GqlAgentPage> {\n return list({ ...args, onlyActive: true, onlyAvailable: true });\n }\n\n return {\n list,\n getById,\n getAvailable,\n };\n}\n\nexport type AgentsDomain = ReturnType<typeof createAgentsDomain>;\n","/**\n * Protocol Stats domain module for the Zenland SDK\n * \n * Stats are tracked per-chain. By default, mainnet stats are returned\n * for production UI. Use chainId parameter to query other networks.\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { PROTOCOL_STATS_QUERY } from \"../queries\";\nimport type { GqlProtocolStats, ProtocolStatsQueryResponse } from \"../generated/types\";\n\n/** Default stats ID for production (Ethereum mainnet) */\nconst DEFAULT_STATS_ID = \"mainnet\";\n\n/** Normalized protocol stats with BigInt values */\nexport interface ProtocolStats {\n id: string;\n chainId?: number;\n totalEscrowsCreated: number;\n totalVolumeEscrowed: bigint;\n totalFeesCollected: bigint;\n currentTVL: bigint;\n activeEscrowCount: number;\n totalAgentsRegistered: number;\n activeAgentsCount: number;\n}\n\n/**\n * Convert raw GraphQL response to normalized ProtocolStats\n */\nfunction normalizeProtocolStats(raw: GqlProtocolStats): ProtocolStats {\n return {\n id: raw.id,\n chainId: (raw as any).chainId,\n totalEscrowsCreated: raw.totalEscrowsCreated,\n totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),\n totalFeesCollected: BigInt(raw.totalFeesCollected),\n currentTVL: BigInt(raw.currentTVL),\n activeEscrowCount: raw.activeEscrowCount,\n totalAgentsRegistered: raw.totalAgentsRegistered,\n activeAgentsCount: raw.activeAgentsCount,\n };\n}\n\nexport interface GetProtocolStatsOptions {\n /** \n * Stats ID to query. Defaults to \"mainnet\".\n * Use \"sepolia\" for testnet stats.\n */\n statsId?: string;\n}\n\n/**\n * Creates protocol stats domain functions bound to a base URL\n */\nexport function createProtocolStatsDomain(baseUrl: string) {\n /**\n * Fetch protocol statistics for a specific chain.\n * Defaults to mainnet for production use.\n * \n * @param options - Optional parameters\n * @param options.statsId - Stats ID to query (default: \"mainnet\")\n */\n async function get(options?: GetProtocolStatsOptions): Promise<ProtocolStats | null> {\n const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n if (!response.protocolStats) {\n return null;\n }\n\n return normalizeProtocolStats(response.protocolStats);\n }\n\n /**\n * Fetch raw protocol statistics (without BigInt conversion)\n * \n * @param options - Optional parameters\n * @param options.statsId - Stats ID to query (default: \"mainnet\")\n */\n async function getRaw(options?: GetProtocolStatsOptions): Promise<GqlProtocolStats | null> {\n const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n return response.protocolStats;\n }\n\n return {\n get,\n getRaw,\n };\n}\n\nexport type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;\n","/**\n * Transaction Logs domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { TRANSACTION_LOGS_QUERY } from \"../queries\";\nimport type { GqlTransactionLog, TransactionLogsQueryResponse } from \"../generated/types\";\n\nexport interface ListTransactionLogsArgs {\n escrowAddress?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates transaction logs domain functions bound to a base URL\n */\nexport function createTransactionLogsDomain(baseUrl: string) {\n /**\n * List transaction logs with filtering and pagination\n */\n async function list(args?: ListTransactionLogsArgs): Promise<GqlTransactionLog[]> {\n const variables = {\n escrowAddress: args?.escrowAddress?.toLowerCase(),\n limit: args?.limit ?? 100,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"timestamp\",\n orderDirection: args?.orderDirection ?? \"asc\",\n };\n\n const response = await graphqlRequest<TransactionLogsQueryResponse, typeof variables>(\n baseUrl,\n TRANSACTION_LOGS_QUERY,\n variables,\n );\n\n return response.transactionLogs.items;\n }\n\n /**\n * Get transaction logs for a specific escrow\n */\n async function getByEscrow(\n escrowAddress: string,\n args?: Omit<ListTransactionLogsArgs, \"escrowAddress\">,\n ): Promise<GqlTransactionLog[]> {\n return list({ ...args, escrowAddress });\n }\n\n /**\n * Parse eventData JSON string from a transaction log\n */\n function parseEventData(eventData: string): Record<string, unknown> {\n try {\n return JSON.parse(eventData);\n } catch {\n return {};\n }\n }\n\n return {\n list,\n getByEscrow,\n parseEventData,\n };\n}\n\nexport type TransactionLogsDomain = ReturnType<typeof createTransactionLogsDomain>;\n","/**\n * Zenland SDK Client\n *\n * The main entry point for interacting with the Zenland indexer.\n */\n\nimport { createEscrowsDomain, type EscrowsDomain } from \"./domains/escrows\";\nimport { createAgentsDomain, type AgentsDomain } from \"./domains/agents\";\nimport { createProtocolStatsDomain, type ProtocolStatsDomain } from \"./domains/protocol-stats\";\nimport { createTransactionLogsDomain, type TransactionLogsDomain } from \"./domains/transaction-logs\";\n\n/** Default production indexer URL */\nconst DEFAULT_BASE_URL = \"https://api.zen.land\";\n\nexport interface ZenlandClientConfig {\n /** Base URL for the indexer API. Defaults to https://api.zen.land */\n baseUrl?: string;\n}\n\nexport interface ZenlandClient {\n /** The base URL being used by this client */\n readonly baseUrl: string;\n\n /** Escrow-related operations */\n readonly escrows: EscrowsDomain;\n\n /** Agent-related operations */\n readonly agents: AgentsDomain;\n\n /** Protocol statistics */\n readonly protocolStats: ProtocolStatsDomain;\n\n /** Transaction logs */\n readonly transactionLogs: TransactionLogsDomain;\n}\n\n/**\n * Create a new Zenland SDK client.\n *\n * @example\n * ```typescript\n * // Use production API (default)\n * const client = createZenlandClient();\n *\n * // Use custom endpoint (e.g., local development)\n * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });\n *\n * // Fetch escrows\n * const { items, totalCount } = await client.escrows.list({ limit: 10 });\n *\n * // Fetch a specific escrow\n * const escrow = await client.escrows.getById('0x...');\n *\n * // Fetch agents\n * const agents = await client.agents.list({ onlyActive: true });\n *\n * // Fetch protocol stats\n * const stats = await client.protocolStats.get();\n * ```\n */\nexport function createZenlandClient(config?: ZenlandClientConfig): ZenlandClient {\n const baseUrl = normalizeBaseUrl(config?.baseUrl ?? DEFAULT_BASE_URL);\n\n return {\n baseUrl,\n escrows: createEscrowsDomain(baseUrl),\n agents: createAgentsDomain(baseUrl),\n protocolStats: createProtocolStatsDomain(baseUrl),\n transactionLogs: createTransactionLogsDomain(baseUrl),\n };\n}\n\n/**\n * Normalize base URL by removing trailing slash\n */\nfunction normalizeBaseUrl(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\n/**\n * Default client instance using production API.\n * Use this for quick access without creating a new client.\n *\n * @example\n * ```typescript\n * import { zenland } from '@zenland/sdk';\n *\n * const escrows = await zenland.escrows.list();\n * ```\n */\nexport const zenland = createZenlandClient();\n","/**\n * Agent eligibility utilities.\n *\n * This is protocol/business logic (React-agnostic) and is safe to consume\n * from any app (interface, backend, bots, etc.).\n */\n\n/**\n * Minimal view of an Agent returned by the indexer.\n */\nexport type IndexerAgent = {\n id: string;\n isActive: boolean;\n isAvailable: boolean;\n stablecoinStake: bigint;\n stablecoinDecimals: number;\n registrationTime: bigint;\n activeCases: number;\n totalResolved: number;\n};\n\nexport type AgentEligibilityFailureReason =\n | \"NOT_REGISTERED\"\n | \"NOT_ACTIVE\"\n | \"NOT_AVAILABLE\"\n | \"INSUFFICIENT_MAV\";\n\nexport type AgentEligibilityResult =\n | {\n ok: true;\n agentMavUsd: bigint;\n requiredUsd: bigint;\n }\n | {\n ok: false;\n reason: AgentEligibilityFailureReason;\n agentMavUsd?: bigint;\n requiredUsd: bigint;\n };\n\n/**\n * MAV multiplier - how much MAV you get per dollar staked.\n * $1 stake * 20 = $20 MAV\n */\nconst MAV_MULTIPLIER = 20n;\n\n/**\n * Compute agent MAV from its stablecoin stake.\n *\n * Bigint-safe:\n * - stablecoinStake is in smallest units (stablecoinDecimals)\n * - return MAV in the same smallest units (stablecoinDecimals)\n */\nexport function computeAgentMavUsd(\n agent: Pick<IndexerAgent, \"stablecoinStake\" | \"stablecoinDecimals\">,\n): bigint {\n // decimals are not used in arithmetic; they’re carried for formatting.\n // MAV is a simple multiplier in the same units.\n return BigInt(agent.stablecoinStake) * MAV_MULTIPLIER;\n}\n\n/**\n * Evaluate whether an agent is eligible for a given escrow amount.\n *\n * NOTE: escrowAmount must be the escrow principal ONLY (fees excluded).\n */\nexport function isAgentEligibleForEscrow(args: {\n agent: IndexerAgent | null | undefined;\n escrowAmount: bigint;\n}): AgentEligibilityResult {\n const requiredUsd = args.escrowAmount;\n\n if (!args.agent) {\n return { ok: false, reason: \"NOT_REGISTERED\", requiredUsd };\n }\n\n if (!args.agent.isActive) {\n return { ok: false, reason: \"NOT_ACTIVE\", requiredUsd };\n }\n\n if (!args.agent.isAvailable) {\n return { ok: false, reason: \"NOT_AVAILABLE\", requiredUsd };\n }\n\n const agentMavUsd = computeAgentMavUsd(args.agent);\n\n if (agentMavUsd < requiredUsd) {\n return { ok: false, reason: \"INSUFFICIENT_MAV\", agentMavUsd, requiredUsd };\n }\n\n return { ok: true, agentMavUsd, requiredUsd };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EAEhB,YAAY,SAAiB,QAA4B;AACvD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAKO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,QAAgB,YAAoB;AAC/D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;AASA,eAAsB,eACpB,SACA,UACA,WACA,SACgB;AAChB,QAAM,WAAW,GAAG,OAAO;AAE3B,QAAM,MAAM,MAAM,MAAM,UAAU;AAAA,IAChC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,OAAO,UAAU,UAAU,CAAC;AAAA,IACnD,QAAQ,SAAS;AAAA,IACjB,OAAO;AAAA,EACT,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,OAAO,MAAM,IAAI,KAAK,E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BAAkB,YAAY;AAAA,EAC5D;AAEA,MAAI,CAAC,KAAK,MAAM,UAAU;AACxB,WAAO,EAAE,IAAI,OAAO,QAAQ,cAAc,YAAY;AAAA,EACxD;AAEA,MAAI,CAAC,KAAK,MAAM,aAAa;AAC3B,WAAO,EAAE,IAAI,OAAO,QAAQ,iBAAiB,YAAY;AAAA,EAC3D;AAEA,QAAM,cAAc,mBAAmB,KAAK,KAAK;AAEjD,MAAI,cAAc,aAAa;AAC7B,WAAO,EAAE,IAAI,OAAO,QAAQ,oBAAoB,aAAa,YAAY;AAAA,EAC3E;AAEA,SAAO,EAAE,IAAI,MAAM,aAAa,YAAY;AAC9C;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -63,6 +63,8 @@ interface GqlAgentFilter {
|
|
|
63
63
|
}
|
|
64
64
|
interface GqlEscrow {
|
|
65
65
|
id: string;
|
|
66
|
+
/** Chain ID where this escrow is deployed (1 for mainnet, 11155111 for sepolia) */
|
|
67
|
+
chainId: number;
|
|
66
68
|
buyer: string;
|
|
67
69
|
seller: string;
|
|
68
70
|
agent?: Maybe<string>;
|
|
@@ -110,6 +112,8 @@ interface GqlEscrowFilter {
|
|
|
110
112
|
}
|
|
111
113
|
interface GqlProtocolStats {
|
|
112
114
|
id: string;
|
|
115
|
+
/** Chain ID (1 for mainnet, 11155111 for sepolia) */
|
|
116
|
+
chainId: number;
|
|
113
117
|
totalEscrowsCreated: number;
|
|
114
118
|
totalVolumeEscrowed: BigIntScalar;
|
|
115
119
|
totalFeesCollected: BigIntScalar;
|
|
@@ -205,11 +209,15 @@ type AgentsDomain = ReturnType<typeof createAgentsDomain>;
|
|
|
205
209
|
|
|
206
210
|
/**
|
|
207
211
|
* Protocol Stats domain module for the Zenland SDK
|
|
212
|
+
*
|
|
213
|
+
* Stats are tracked per-chain. By default, mainnet stats are returned
|
|
214
|
+
* for production UI. Use chainId parameter to query other networks.
|
|
208
215
|
*/
|
|
209
216
|
|
|
210
217
|
/** Normalized protocol stats with BigInt values */
|
|
211
218
|
interface ProtocolStats {
|
|
212
219
|
id: string;
|
|
220
|
+
chainId?: number;
|
|
213
221
|
totalEscrowsCreated: number;
|
|
214
222
|
totalVolumeEscrowed: bigint;
|
|
215
223
|
totalFeesCollected: bigint;
|
|
@@ -218,12 +226,19 @@ interface ProtocolStats {
|
|
|
218
226
|
totalAgentsRegistered: number;
|
|
219
227
|
activeAgentsCount: number;
|
|
220
228
|
}
|
|
229
|
+
interface GetProtocolStatsOptions {
|
|
230
|
+
/**
|
|
231
|
+
* Stats ID to query. Defaults to "mainnet".
|
|
232
|
+
* Use "sepolia" for testnet stats.
|
|
233
|
+
*/
|
|
234
|
+
statsId?: string;
|
|
235
|
+
}
|
|
221
236
|
/**
|
|
222
237
|
* Creates protocol stats domain functions bound to a base URL
|
|
223
238
|
*/
|
|
224
239
|
declare function createProtocolStatsDomain(baseUrl: string): {
|
|
225
|
-
get: () => Promise<ProtocolStats | null>;
|
|
226
|
-
getRaw: () => Promise<GqlProtocolStats | null>;
|
|
240
|
+
get: (options?: GetProtocolStatsOptions) => Promise<ProtocolStats | null>;
|
|
241
|
+
getRaw: (options?: GetProtocolStatsOptions) => Promise<GqlProtocolStats | null>;
|
|
227
242
|
};
|
|
228
243
|
type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;
|
|
229
244
|
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ interface GqlAgentFilter {
|
|
|
63
63
|
}
|
|
64
64
|
interface GqlEscrow {
|
|
65
65
|
id: string;
|
|
66
|
+
/** Chain ID where this escrow is deployed (1 for mainnet, 11155111 for sepolia) */
|
|
67
|
+
chainId: number;
|
|
66
68
|
buyer: string;
|
|
67
69
|
seller: string;
|
|
68
70
|
agent?: Maybe<string>;
|
|
@@ -110,6 +112,8 @@ interface GqlEscrowFilter {
|
|
|
110
112
|
}
|
|
111
113
|
interface GqlProtocolStats {
|
|
112
114
|
id: string;
|
|
115
|
+
/** Chain ID (1 for mainnet, 11155111 for sepolia) */
|
|
116
|
+
chainId: number;
|
|
113
117
|
totalEscrowsCreated: number;
|
|
114
118
|
totalVolumeEscrowed: BigIntScalar;
|
|
115
119
|
totalFeesCollected: BigIntScalar;
|
|
@@ -205,11 +209,15 @@ type AgentsDomain = ReturnType<typeof createAgentsDomain>;
|
|
|
205
209
|
|
|
206
210
|
/**
|
|
207
211
|
* Protocol Stats domain module for the Zenland SDK
|
|
212
|
+
*
|
|
213
|
+
* Stats are tracked per-chain. By default, mainnet stats are returned
|
|
214
|
+
* for production UI. Use chainId parameter to query other networks.
|
|
208
215
|
*/
|
|
209
216
|
|
|
210
217
|
/** Normalized protocol stats with BigInt values */
|
|
211
218
|
interface ProtocolStats {
|
|
212
219
|
id: string;
|
|
220
|
+
chainId?: number;
|
|
213
221
|
totalEscrowsCreated: number;
|
|
214
222
|
totalVolumeEscrowed: bigint;
|
|
215
223
|
totalFeesCollected: bigint;
|
|
@@ -218,12 +226,19 @@ interface ProtocolStats {
|
|
|
218
226
|
totalAgentsRegistered: number;
|
|
219
227
|
activeAgentsCount: number;
|
|
220
228
|
}
|
|
229
|
+
interface GetProtocolStatsOptions {
|
|
230
|
+
/**
|
|
231
|
+
* Stats ID to query. Defaults to "mainnet".
|
|
232
|
+
* Use "sepolia" for testnet stats.
|
|
233
|
+
*/
|
|
234
|
+
statsId?: string;
|
|
235
|
+
}
|
|
221
236
|
/**
|
|
222
237
|
* Creates protocol stats domain functions bound to a base URL
|
|
223
238
|
*/
|
|
224
239
|
declare function createProtocolStatsDomain(baseUrl: string): {
|
|
225
|
-
get: () => Promise<ProtocolStats | null>;
|
|
226
|
-
getRaw: () => Promise<GqlProtocolStats | null>;
|
|
240
|
+
get: (options?: GetProtocolStatsOptions) => Promise<ProtocolStats | null>;
|
|
241
|
+
getRaw: (options?: GetProtocolStatsOptions) => Promise<GqlProtocolStats | null>;
|
|
227
242
|
};
|
|
228
243
|
type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;
|
|
229
244
|
|
package/dist/index.js
CHANGED
|
@@ -122,6 +122,7 @@ var ESCROW_QUERY = `
|
|
|
122
122
|
query escrow($id: String!) {
|
|
123
123
|
escrow(id: $id) {
|
|
124
124
|
id
|
|
125
|
+
chainId
|
|
125
126
|
buyer
|
|
126
127
|
seller
|
|
127
128
|
agent
|
|
@@ -166,6 +167,7 @@ query escrows(
|
|
|
166
167
|
) {
|
|
167
168
|
items {
|
|
168
169
|
id
|
|
170
|
+
chainId
|
|
169
171
|
buyer
|
|
170
172
|
seller
|
|
171
173
|
agent
|
|
@@ -193,9 +195,10 @@ query escrows(
|
|
|
193
195
|
}
|
|
194
196
|
`;
|
|
195
197
|
var PROTOCOL_STATS_QUERY = `
|
|
196
|
-
query protocolStats($id: String! = "
|
|
198
|
+
query protocolStats($id: String! = "mainnet") {
|
|
197
199
|
protocolStats(id: $id) {
|
|
198
200
|
id
|
|
201
|
+
chainId
|
|
199
202
|
totalEscrowsCreated
|
|
200
203
|
totalVolumeEscrowed
|
|
201
204
|
totalFeesCollected
|
|
@@ -336,9 +339,11 @@ function createAgentsDomain(baseUrl) {
|
|
|
336
339
|
}
|
|
337
340
|
|
|
338
341
|
// src/domains/protocol-stats.ts
|
|
342
|
+
var DEFAULT_STATS_ID = "mainnet";
|
|
339
343
|
function normalizeProtocolStats(raw) {
|
|
340
344
|
return {
|
|
341
345
|
id: raw.id,
|
|
346
|
+
chainId: raw.chainId,
|
|
342
347
|
totalEscrowsCreated: raw.totalEscrowsCreated,
|
|
343
348
|
totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),
|
|
344
349
|
totalFeesCollected: BigInt(raw.totalFeesCollected),
|
|
@@ -349,8 +354,8 @@ function normalizeProtocolStats(raw) {
|
|
|
349
354
|
};
|
|
350
355
|
}
|
|
351
356
|
function createProtocolStatsDomain(baseUrl) {
|
|
352
|
-
async function get() {
|
|
353
|
-
const variables = { id:
|
|
357
|
+
async function get(options) {
|
|
358
|
+
const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };
|
|
354
359
|
const response = await graphqlRequest(
|
|
355
360
|
baseUrl,
|
|
356
361
|
PROTOCOL_STATS_QUERY,
|
|
@@ -361,8 +366,8 @@ function createProtocolStatsDomain(baseUrl) {
|
|
|
361
366
|
}
|
|
362
367
|
return normalizeProtocolStats(response.protocolStats);
|
|
363
368
|
}
|
|
364
|
-
async function getRaw() {
|
|
365
|
-
const variables = { id:
|
|
369
|
+
async function getRaw(options) {
|
|
370
|
+
const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };
|
|
366
371
|
const response = await graphqlRequest(
|
|
367
372
|
baseUrl,
|
|
368
373
|
PROTOCOL_STATS_QUERY,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/request.ts","../src/queries.ts","../src/domains/escrows.ts","../src/domains/agents.ts","../src/domains/protocol-stats.ts","../src/domains/transaction-logs.ts","../src/client.ts","../src/agents/eligibility.ts"],"sourcesContent":["/**\n * GraphQL request utilities for the Zenland SDK\n */\n\ntype GraphQLErrorLike = {\n message?: string;\n [key: string]: unknown;\n};\n\ntype GraphQLResponse<TData> = {\n data?: TData;\n errors?: GraphQLErrorLike[];\n};\n\n/**\n * Error thrown when the indexer returns GraphQL errors\n */\nexport class ZenlandGraphQLError extends Error {\n public readonly errors: GraphQLErrorLike[];\n\n constructor(message: string, errors: GraphQLErrorLike[]) {\n super(message);\n this.name = \"ZenlandGraphQLError\";\n this.errors = errors;\n }\n}\n\n/**\n * Error thrown when the indexer request fails at the network/HTTP level\n */\nexport class ZenlandRequestError extends Error {\n public readonly status: number;\n public readonly statusText: string;\n\n constructor(message: string, status: number, statusText: string) {\n super(message);\n this.name = \"ZenlandRequestError\";\n this.status = status;\n this.statusText = statusText;\n }\n}\n\nexport interface GraphQLRequestOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Execute a GraphQL request against the Zenland indexer\n */\nexport async function graphqlRequest<TData, TVariables extends object | undefined>(\n baseUrl: string,\n document: string,\n variables?: TVariables,\n options?: GraphQLRequestOptions,\n): Promise<TData> {\n const endpoint = `${baseUrl}/graphql`;\n\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({ query: document, variables }),\n signal: options?.signal,\n cache: \"no-store\",\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ZenlandRequestError(\n `Zenland request failed (${res.status} ${res.statusText})${text ? `: ${text}` : \"\"}`,\n res.status,\n res.statusText,\n );\n }\n\n const json = (await res.json()) as GraphQLResponse<TData>;\n\n if (json.errors?.length) {\n throw new ZenlandGraphQLError(\n json.errors.map((e) => e.message ?? \"GraphQL error\").join(\"; \"),\n json.errors,\n );\n }\n\n if (!json.data) {\n throw new Error(\"Zenland response missing data.\");\n }\n\n return json.data;\n}\n","/**\n * GraphQL query strings for the Zenland indexer.\n * These are compiled into the SDK to avoid runtime parsing.\n */\n\nexport const AGENT_QUERY = `\nquery Agent($id: String!) {\n agent(id: $id) {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinToken\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n cases(limit: 5, orderBy: \"invitedAt\", orderDirection: \"desc\") {\n items {\n id\n escrow\n invitedAt\n resolvedAt\n timedOut\n escrowRef {\n id\n amount\n token\n state\n }\n }\n totalCount\n }\n }\n}\n`;\n\nexport const AGENTS_QUERY = `\nquery Agents($where: agentFilter, $orderBy: String, $orderDirection: String, $limit: Int, $offset: Int) {\n agents(where: $where, orderBy: $orderBy, orderDirection: $orderDirection, limit: $limit, offset: $offset) {\n totalCount\n items {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n }\n}\n`;\n\nexport const ESCROW_QUERY = `\nquery escrow($id: String!) {\n escrow(id: $id) {\n id\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n sellerAcceptDeadline\n buyerProtectionTime\n termsHash\n version\n fundedAt\n fulfilledAt\n resolvedAt\n agentInvitedAt\n splitProposer\n proposedBuyerBps\n proposedSellerBps\n buyerApprovedSplit\n sellerApprovedSplit\n agentFeeReceived\n buyerReceived\n sellerReceived\n creationFee\n }\n}\n`;\n\nexport const ESCROWS_QUERY = `\nquery escrows(\n $limit: Int = 30\n $offset: Int = 0\n $orderBy: String = \"createdAt\"\n $orderDirection: String = \"desc\"\n $where: escrowFilter\n) {\n escrows(\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n items {\n id\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n fundedAt\n fulfilledAt\n sellerAcceptDeadline\n agentInvitedAt\n buyerProtectionTime\n splitProposer\n buyerApprovedSplit\n sellerApprovedSplit\n proposedBuyerBps\n proposedSellerBps\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n totalCount\n }\n}\n`;\n\nexport const PROTOCOL_STATS_QUERY = `\nquery protocolStats($id: String! = \"global\") {\n protocolStats(id: $id) {\n id\n totalEscrowsCreated\n totalVolumeEscrowed\n totalFeesCollected\n currentTVL\n activeEscrowCount\n totalAgentsRegistered\n activeAgentsCount\n }\n}\n`;\n\nexport const RECENT_ESCROWS_QUERY = `\nquery recentEscrows($limit: Int = 5) {\n escrows(\n limit: $limit\n orderBy: \"createdAt\"\n orderDirection: \"desc\"\n ) {\n items {\n id\n amount\n token\n state\n createdAt\n }\n }\n}\n`;\n\nexport const TRANSACTION_LOGS_QUERY = `\nquery transactionLogs(\n $escrowAddress: String\n $limit: Int\n $offset: Int\n $orderBy: String\n $orderDirection: String\n) {\n transactionLogs(\n where: { escrowAddress: $escrowAddress }\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n items {\n id\n txHash\n blockNumber\n timestamp\n eventName\n contractAddress\n contractType\n escrowAddress\n agentAddress\n userAddress\n eventData\n }\n }\n}\n`;\n","/**\n * Escrow domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { ESCROW_QUERY, ESCROWS_QUERY } from \"../queries\";\nimport type {\n GqlEscrow,\n GqlEscrowPage,\n GqlEscrowFilter,\n EscrowQueryResponse,\n EscrowsQueryResponse,\n} from \"../generated/types\";\n\n/** State groups for filtering escrows */\nexport const STATE_GROUPS = {\n ACTIVE: [\"PENDING\", \"ACTIVE\", \"FULFILLED\"] as const,\n IN_DISPUTE: [\"DISPUTED\", \"AGENT_INVITED\"] as const,\n COMPLETED: [\"RELEASED\", \"AGENT_RESOLVED\", \"REFUNDED\", \"SPLIT\"] as const,\n} as const;\n\nexport type StateGroup = keyof typeof STATE_GROUPS;\n\nexport interface ListEscrowsArgs {\n limit?: number;\n offset?: number;\n buyer?: string;\n seller?: string;\n agent?: string;\n /** Search across buyer, seller, or agent roles */\n user?: string;\n state?: string;\n /** Multiple states for group filtering */\n states?: string[];\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates escrow domain functions bound to a base URL\n */\nexport function createEscrowsDomain(baseUrl: string) {\n /**\n * List escrows with filtering and pagination\n */\n async function list(args?: ListEscrowsArgs): Promise<GqlEscrowPage> {\n const where: GqlEscrowFilter = {};\n\n // Role-specific filters\n if (args?.buyer) where.buyer = args.buyer.toLowerCase();\n if (args?.seller) where.seller = args.seller.toLowerCase();\n if (args?.agent) where.agent = args.agent.toLowerCase();\n\n // State filters - single or multiple\n if (args?.states && args.states.length > 0) {\n where.state_in = args.states;\n } else if (args?.state) {\n where.state = args.state;\n }\n\n // User filter: search across buyer, seller, or agent roles\n if (args?.user) {\n const userLower = args.user.toLowerCase();\n where.OR = [{ buyer: userLower }, { seller: userLower }, { agent: userLower }];\n }\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"createdAt\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<EscrowsQueryResponse, typeof variables>(\n baseUrl,\n ESCROWS_QUERY,\n variables,\n );\n\n return response.escrows;\n }\n\n /**\n * Get a single escrow by ID (address)\n */\n async function getById(id: string): Promise<GqlEscrow | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<EscrowQueryResponse, typeof variables>(\n baseUrl,\n ESCROW_QUERY,\n variables,\n );\n\n return response.escrow;\n }\n\n /**\n * Get escrows for a specific user across all roles\n */\n async function getByUser(\n userAddress: string,\n args?: Omit<ListEscrowsArgs, \"user\" | \"buyer\" | \"seller\" | \"agent\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, user: userAddress });\n }\n\n /**\n * Get escrows by state group\n */\n async function getByStateGroup(\n stateGroup: StateGroup,\n args?: Omit<ListEscrowsArgs, \"state\" | \"states\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, states: [...STATE_GROUPS[stateGroup]] });\n }\n\n return {\n list,\n getById,\n getByUser,\n getByStateGroup,\n };\n}\n\nexport type EscrowsDomain = ReturnType<typeof createEscrowsDomain>;\n","/**\n * Agent domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { AGENT_QUERY, AGENTS_QUERY } from \"../queries\";\nimport type {\n GqlAgent,\n GqlAgentPage,\n GqlAgentFilter,\n AgentQueryResponse,\n AgentsQueryResponse,\n} from \"../generated/types\";\n\nexport interface ListAgentsArgs {\n limit?: number;\n offset?: number;\n onlyActive?: boolean;\n onlyAvailable?: boolean;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates agent domain functions bound to a base URL\n */\nexport function createAgentsDomain(baseUrl: string) {\n /**\n * List agents with filtering and pagination\n */\n async function list(args?: ListAgentsArgs): Promise<GqlAgentPage> {\n const where: GqlAgentFilter = {};\n\n if (args?.onlyActive) where.isActive = true;\n if (args?.onlyAvailable) where.isAvailable = true;\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"totalResolved\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<AgentsQueryResponse, typeof variables>(\n baseUrl,\n AGENTS_QUERY,\n variables,\n );\n\n return response.agents;\n }\n\n /**\n * Get a single agent by ID (address)\n */\n async function getById(id: string): Promise<GqlAgent | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<AgentQueryResponse, typeof variables>(\n baseUrl,\n AGENT_QUERY,\n variables,\n );\n\n return response.agent;\n }\n\n /**\n * Get all active and available agents\n */\n async function getAvailable(args?: Omit<ListAgentsArgs, \"onlyActive\" | \"onlyAvailable\">): Promise<GqlAgentPage> {\n return list({ ...args, onlyActive: true, onlyAvailable: true });\n }\n\n return {\n list,\n getById,\n getAvailable,\n };\n}\n\nexport type AgentsDomain = ReturnType<typeof createAgentsDomain>;\n","/**\n * Protocol Stats domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { PROTOCOL_STATS_QUERY } from \"../queries\";\nimport type { GqlProtocolStats, ProtocolStatsQueryResponse } from \"../generated/types\";\n\n/** Normalized protocol stats with BigInt values */\nexport interface ProtocolStats {\n id: string;\n totalEscrowsCreated: number;\n totalVolumeEscrowed: bigint;\n totalFeesCollected: bigint;\n currentTVL: bigint;\n activeEscrowCount: number;\n totalAgentsRegistered: number;\n activeAgentsCount: number;\n}\n\n/**\n * Convert raw GraphQL response to normalized ProtocolStats\n */\nfunction normalizeProtocolStats(raw: GqlProtocolStats): ProtocolStats {\n return {\n id: raw.id,\n totalEscrowsCreated: raw.totalEscrowsCreated,\n totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),\n totalFeesCollected: BigInt(raw.totalFeesCollected),\n currentTVL: BigInt(raw.currentTVL),\n activeEscrowCount: raw.activeEscrowCount,\n totalAgentsRegistered: raw.totalAgentsRegistered,\n activeAgentsCount: raw.activeAgentsCount,\n };\n}\n\n/**\n * Creates protocol stats domain functions bound to a base URL\n */\nexport function createProtocolStatsDomain(baseUrl: string) {\n /**\n * Fetch global protocol statistics\n */\n async function get(): Promise<ProtocolStats | null> {\n const variables = { id: \"global\" };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n if (!response.protocolStats) {\n return null;\n }\n\n return normalizeProtocolStats(response.protocolStats);\n }\n\n /**\n * Fetch raw protocol statistics (without BigInt conversion)\n */\n async function getRaw(): Promise<GqlProtocolStats | null> {\n const variables = { id: \"global\" };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n return response.protocolStats;\n }\n\n return {\n get,\n getRaw,\n };\n}\n\nexport type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;\n","/**\n * Transaction Logs domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { TRANSACTION_LOGS_QUERY } from \"../queries\";\nimport type { GqlTransactionLog, TransactionLogsQueryResponse } from \"../generated/types\";\n\nexport interface ListTransactionLogsArgs {\n escrowAddress?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates transaction logs domain functions bound to a base URL\n */\nexport function createTransactionLogsDomain(baseUrl: string) {\n /**\n * List transaction logs with filtering and pagination\n */\n async function list(args?: ListTransactionLogsArgs): Promise<GqlTransactionLog[]> {\n const variables = {\n escrowAddress: args?.escrowAddress?.toLowerCase(),\n limit: args?.limit ?? 100,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"timestamp\",\n orderDirection: args?.orderDirection ?? \"asc\",\n };\n\n const response = await graphqlRequest<TransactionLogsQueryResponse, typeof variables>(\n baseUrl,\n TRANSACTION_LOGS_QUERY,\n variables,\n );\n\n return response.transactionLogs.items;\n }\n\n /**\n * Get transaction logs for a specific escrow\n */\n async function getByEscrow(\n escrowAddress: string,\n args?: Omit<ListTransactionLogsArgs, \"escrowAddress\">,\n ): Promise<GqlTransactionLog[]> {\n return list({ ...args, escrowAddress });\n }\n\n /**\n * Parse eventData JSON string from a transaction log\n */\n function parseEventData(eventData: string): Record<string, unknown> {\n try {\n return JSON.parse(eventData);\n } catch {\n return {};\n }\n }\n\n return {\n list,\n getByEscrow,\n parseEventData,\n };\n}\n\nexport type TransactionLogsDomain = ReturnType<typeof createTransactionLogsDomain>;\n","/**\n * Zenland SDK Client\n *\n * The main entry point for interacting with the Zenland indexer.\n */\n\nimport { createEscrowsDomain, type EscrowsDomain } from \"./domains/escrows\";\nimport { createAgentsDomain, type AgentsDomain } from \"./domains/agents\";\nimport { createProtocolStatsDomain, type ProtocolStatsDomain } from \"./domains/protocol-stats\";\nimport { createTransactionLogsDomain, type TransactionLogsDomain } from \"./domains/transaction-logs\";\n\n/** Default production indexer URL */\nconst DEFAULT_BASE_URL = \"https://api.zen.land\";\n\nexport interface ZenlandClientConfig {\n /** Base URL for the indexer API. Defaults to https://api.zen.land */\n baseUrl?: string;\n}\n\nexport interface ZenlandClient {\n /** The base URL being used by this client */\n readonly baseUrl: string;\n\n /** Escrow-related operations */\n readonly escrows: EscrowsDomain;\n\n /** Agent-related operations */\n readonly agents: AgentsDomain;\n\n /** Protocol statistics */\n readonly protocolStats: ProtocolStatsDomain;\n\n /** Transaction logs */\n readonly transactionLogs: TransactionLogsDomain;\n}\n\n/**\n * Create a new Zenland SDK client.\n *\n * @example\n * ```typescript\n * // Use production API (default)\n * const client = createZenlandClient();\n *\n * // Use custom endpoint (e.g., local development)\n * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });\n *\n * // Fetch escrows\n * const { items, totalCount } = await client.escrows.list({ limit: 10 });\n *\n * // Fetch a specific escrow\n * const escrow = await client.escrows.getById('0x...');\n *\n * // Fetch agents\n * const agents = await client.agents.list({ onlyActive: true });\n *\n * // Fetch protocol stats\n * const stats = await client.protocolStats.get();\n * ```\n */\nexport function createZenlandClient(config?: ZenlandClientConfig): ZenlandClient {\n const baseUrl = normalizeBaseUrl(config?.baseUrl ?? DEFAULT_BASE_URL);\n\n return {\n baseUrl,\n escrows: createEscrowsDomain(baseUrl),\n agents: createAgentsDomain(baseUrl),\n protocolStats: createProtocolStatsDomain(baseUrl),\n transactionLogs: createTransactionLogsDomain(baseUrl),\n };\n}\n\n/**\n * Normalize base URL by removing trailing slash\n */\nfunction normalizeBaseUrl(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\n/**\n * Default client instance using production API.\n * Use this for quick access without creating a new client.\n *\n * @example\n * ```typescript\n * import { zenland } from '@zenland/sdk';\n *\n * const escrows = await zenland.escrows.list();\n * ```\n */\nexport const zenland = createZenlandClient();\n","/**\n * Agent eligibility utilities.\n *\n * This is protocol/business logic (React-agnostic) and is safe to consume\n * from any app (interface, backend, bots, etc.).\n */\n\n/**\n * Minimal view of an Agent returned by the indexer.\n */\nexport type IndexerAgent = {\n id: string;\n isActive: boolean;\n isAvailable: boolean;\n stablecoinStake: bigint;\n stablecoinDecimals: number;\n registrationTime: bigint;\n activeCases: number;\n totalResolved: number;\n};\n\nexport type AgentEligibilityFailureReason =\n | \"NOT_REGISTERED\"\n | \"NOT_ACTIVE\"\n | \"NOT_AVAILABLE\"\n | \"INSUFFICIENT_MAV\";\n\nexport type AgentEligibilityResult =\n | {\n ok: true;\n agentMavUsd: bigint;\n requiredUsd: bigint;\n }\n | {\n ok: false;\n reason: AgentEligibilityFailureReason;\n agentMavUsd?: bigint;\n requiredUsd: bigint;\n };\n\n/**\n * MAV multiplier - how much MAV you get per dollar staked.\n * $1 stake * 20 = $20 MAV\n */\nconst MAV_MULTIPLIER = 20n;\n\n/**\n * Compute agent MAV from its stablecoin stake.\n *\n * Bigint-safe:\n * - stablecoinStake is in smallest units (stablecoinDecimals)\n * - return MAV in the same smallest units (stablecoinDecimals)\n */\nexport function computeAgentMavUsd(\n agent: Pick<IndexerAgent, \"stablecoinStake\" | \"stablecoinDecimals\">,\n): bigint {\n // decimals are not used in arithmetic; they’re carried for formatting.\n // MAV is a simple multiplier in the same units.\n return BigInt(agent.stablecoinStake) * MAV_MULTIPLIER;\n}\n\n/**\n * Evaluate whether an agent is eligible for a given escrow amount.\n *\n * NOTE: escrowAmount must be the escrow principal ONLY (fees excluded).\n */\nexport function isAgentEligibleForEscrow(args: {\n agent: IndexerAgent | null | undefined;\n escrowAmount: bigint;\n}): AgentEligibilityResult {\n const requiredUsd = args.escrowAmount;\n\n if (!args.agent) {\n return { ok: false, reason: \"NOT_REGISTERED\", requiredUsd };\n }\n\n if (!args.agent.isActive) {\n return { ok: false, reason: \"NOT_ACTIVE\", requiredUsd };\n }\n\n if (!args.agent.isAvailable) {\n return { ok: false, reason: \"NOT_AVAILABLE\", requiredUsd };\n }\n\n const agentMavUsd = computeAgentMavUsd(args.agent);\n\n if (agentMavUsd < requiredUsd) {\n return { ok: false, reason: \"INSUFFICIENT_MAV\", agentMavUsd, requiredUsd };\n }\n\n return { ok: true, agentMavUsd, requiredUsd };\n}\n"],"mappings":";AAiBO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EAEhB,YAAY,SAAiB,QAA4B;AACvD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAKO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,QAAgB,YAAoB;AAC/D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;AASA,eAAsB,eACpB,SACA,UACA,WACA,SACgB;AAChB,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AC9C3C,IAAM,iBAAiB;AAShB,SAAS,mBACd,OACQ;AAGR,SAAO,OAAO,MAAM,eAAe,IAAI;AACzC;AAOO,SAAS,yBAAyB,MAGd;AACzB,QAAM,cAAc,KAAK;AAEzB,MAAI,CAAC,KAAK,OAAO;AACf,WAAO,EAAE,IAAI,OAAO,QAAQ,kBAAkB,YAAY;AAAA,EAC5D;AAEA,MAAI,CAAC,KAAK,MAAM,UAAU;AACxB,WAAO,EAAE,IAAI,OAAO,QAAQ,cAAc,YAAY;AAAA,EACxD;AAEA,MAAI,CAAC,KAAK,MAAM,aAAa;AAC3B,WAAO,EAAE,IAAI,OAAO,QAAQ,iBAAiB,YAAY;AAAA,EAC3D;AAEA,QAAM,cAAc,mBAAmB,KAAK,KAAK;AAEjD,MAAI,cAAc,aAAa;AAC7B,WAAO,EAAE,IAAI,OAAO,QAAQ,oBAAoB,aAAa,YAAY;AAAA,EAC3E;AAEA,SAAO,EAAE,IAAI,MAAM,aAAa,YAAY;AAC9C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/request.ts","../src/queries.ts","../src/domains/escrows.ts","../src/domains/agents.ts","../src/domains/protocol-stats.ts","../src/domains/transaction-logs.ts","../src/client.ts","../src/agents/eligibility.ts"],"sourcesContent":["/**\n * GraphQL request utilities for the Zenland SDK\n */\n\ntype GraphQLErrorLike = {\n message?: string;\n [key: string]: unknown;\n};\n\ntype GraphQLResponse<TData> = {\n data?: TData;\n errors?: GraphQLErrorLike[];\n};\n\n/**\n * Error thrown when the indexer returns GraphQL errors\n */\nexport class ZenlandGraphQLError extends Error {\n public readonly errors: GraphQLErrorLike[];\n\n constructor(message: string, errors: GraphQLErrorLike[]) {\n super(message);\n this.name = \"ZenlandGraphQLError\";\n this.errors = errors;\n }\n}\n\n/**\n * Error thrown when the indexer request fails at the network/HTTP level\n */\nexport class ZenlandRequestError extends Error {\n public readonly status: number;\n public readonly statusText: string;\n\n constructor(message: string, status: number, statusText: string) {\n super(message);\n this.name = \"ZenlandRequestError\";\n this.status = status;\n this.statusText = statusText;\n }\n}\n\nexport interface GraphQLRequestOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Execute a GraphQL request against the Zenland indexer\n */\nexport async function graphqlRequest<TData, TVariables extends object | undefined>(\n baseUrl: string,\n document: string,\n variables?: TVariables,\n options?: GraphQLRequestOptions,\n): Promise<TData> {\n const endpoint = `${baseUrl}/graphql`;\n\n const res = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({ query: document, variables }),\n signal: options?.signal,\n cache: \"no-store\",\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ZenlandRequestError(\n `Zenland request failed (${res.status} ${res.statusText})${text ? `: ${text}` : \"\"}`,\n res.status,\n res.statusText,\n );\n }\n\n const json = (await res.json()) as GraphQLResponse<TData>;\n\n if (json.errors?.length) {\n throw new ZenlandGraphQLError(\n json.errors.map((e) => e.message ?? \"GraphQL error\").join(\"; \"),\n json.errors,\n );\n }\n\n if (!json.data) {\n throw new Error(\"Zenland response missing data.\");\n }\n\n return json.data;\n}\n","/**\n * GraphQL query strings for the Zenland indexer.\n * These are compiled into the SDK to avoid runtime parsing.\n */\n\nexport const AGENT_QUERY = `\nquery Agent($id: String!) {\n agent(id: $id) {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinToken\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n cases(limit: 5, orderBy: \"invitedAt\", orderDirection: \"desc\") {\n items {\n id\n escrow\n invitedAt\n resolvedAt\n timedOut\n escrowRef {\n id\n amount\n token\n state\n }\n }\n totalCount\n }\n }\n}\n`;\n\nexport const AGENTS_QUERY = `\nquery Agents($where: agentFilter, $orderBy: String, $orderDirection: String, $limit: Int, $offset: Int) {\n agents(where: $where, orderBy: $orderBy, orderDirection: $orderDirection, limit: $limit, offset: $offset) {\n totalCount\n items {\n id\n isActive\n isAvailable\n stablecoinDecimals\n stablecoinStake\n daoTokenStake\n disputeFeeBps\n assignmentFeeBps\n description\n contact\n totalResolved\n activeCases\n registrationTime\n lastEngagementTimestamp\n totalEarnings\n totalSlashed\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n }\n}\n`;\n\nexport const ESCROW_QUERY = `\nquery escrow($id: String!) {\n escrow(id: $id) {\n id\n chainId\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n sellerAcceptDeadline\n buyerProtectionTime\n termsHash\n version\n fundedAt\n fulfilledAt\n resolvedAt\n agentInvitedAt\n splitProposer\n proposedBuyerBps\n proposedSellerBps\n buyerApprovedSplit\n sellerApprovedSplit\n agentFeeReceived\n buyerReceived\n sellerReceived\n creationFee\n }\n}\n`;\n\nexport const ESCROWS_QUERY = `\nquery escrows(\n $limit: Int = 30\n $offset: Int = 0\n $orderBy: String = \"createdAt\"\n $orderDirection: String = \"desc\"\n $where: escrowFilter\n) {\n escrows(\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n items {\n id\n chainId\n buyer\n seller\n agent\n amount\n token\n state\n createdAt\n fundedAt\n fulfilledAt\n sellerAcceptDeadline\n agentInvitedAt\n buyerProtectionTime\n splitProposer\n buyerApprovedSplit\n sellerApprovedSplit\n proposedBuyerBps\n proposedSellerBps\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n }\n totalCount\n }\n}\n`;\n\nexport const PROTOCOL_STATS_QUERY = `\nquery protocolStats($id: String! = \"mainnet\") {\n protocolStats(id: $id) {\n id\n chainId\n totalEscrowsCreated\n totalVolumeEscrowed\n totalFeesCollected\n currentTVL\n activeEscrowCount\n totalAgentsRegistered\n activeAgentsCount\n }\n}\n`;\n\nexport const RECENT_ESCROWS_QUERY = `\nquery recentEscrows($limit: Int = 5) {\n escrows(\n limit: $limit\n orderBy: \"createdAt\"\n orderDirection: \"desc\"\n ) {\n items {\n id\n amount\n token\n state\n createdAt\n }\n }\n}\n`;\n\nexport const TRANSACTION_LOGS_QUERY = `\nquery transactionLogs(\n $escrowAddress: String\n $limit: Int\n $offset: Int\n $orderBy: String\n $orderDirection: String\n) {\n transactionLogs(\n where: { escrowAddress: $escrowAddress }\n limit: $limit\n offset: $offset\n orderBy: $orderBy\n orderDirection: $orderDirection\n ) {\n items {\n id\n txHash\n blockNumber\n timestamp\n eventName\n contractAddress\n contractType\n escrowAddress\n agentAddress\n userAddress\n eventData\n }\n }\n}\n`;\n","/**\n * Escrow domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { ESCROW_QUERY, ESCROWS_QUERY } from \"../queries\";\nimport type {\n GqlEscrow,\n GqlEscrowPage,\n GqlEscrowFilter,\n EscrowQueryResponse,\n EscrowsQueryResponse,\n} from \"../generated/types\";\n\n/** State groups for filtering escrows */\nexport const STATE_GROUPS = {\n ACTIVE: [\"PENDING\", \"ACTIVE\", \"FULFILLED\"] as const,\n IN_DISPUTE: [\"DISPUTED\", \"AGENT_INVITED\"] as const,\n COMPLETED: [\"RELEASED\", \"AGENT_RESOLVED\", \"REFUNDED\", \"SPLIT\"] as const,\n} as const;\n\nexport type StateGroup = keyof typeof STATE_GROUPS;\n\nexport interface ListEscrowsArgs {\n limit?: number;\n offset?: number;\n buyer?: string;\n seller?: string;\n agent?: string;\n /** Search across buyer, seller, or agent roles */\n user?: string;\n state?: string;\n /** Multiple states for group filtering */\n states?: string[];\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates escrow domain functions bound to a base URL\n */\nexport function createEscrowsDomain(baseUrl: string) {\n /**\n * List escrows with filtering and pagination\n */\n async function list(args?: ListEscrowsArgs): Promise<GqlEscrowPage> {\n const where: GqlEscrowFilter = {};\n\n // Role-specific filters\n if (args?.buyer) where.buyer = args.buyer.toLowerCase();\n if (args?.seller) where.seller = args.seller.toLowerCase();\n if (args?.agent) where.agent = args.agent.toLowerCase();\n\n // State filters - single or multiple\n if (args?.states && args.states.length > 0) {\n where.state_in = args.states;\n } else if (args?.state) {\n where.state = args.state;\n }\n\n // User filter: search across buyer, seller, or agent roles\n if (args?.user) {\n const userLower = args.user.toLowerCase();\n where.OR = [{ buyer: userLower }, { seller: userLower }, { agent: userLower }];\n }\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"createdAt\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<EscrowsQueryResponse, typeof variables>(\n baseUrl,\n ESCROWS_QUERY,\n variables,\n );\n\n return response.escrows;\n }\n\n /**\n * Get a single escrow by ID (address)\n */\n async function getById(id: string): Promise<GqlEscrow | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<EscrowQueryResponse, typeof variables>(\n baseUrl,\n ESCROW_QUERY,\n variables,\n );\n\n return response.escrow;\n }\n\n /**\n * Get escrows for a specific user across all roles\n */\n async function getByUser(\n userAddress: string,\n args?: Omit<ListEscrowsArgs, \"user\" | \"buyer\" | \"seller\" | \"agent\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, user: userAddress });\n }\n\n /**\n * Get escrows by state group\n */\n async function getByStateGroup(\n stateGroup: StateGroup,\n args?: Omit<ListEscrowsArgs, \"state\" | \"states\">,\n ): Promise<GqlEscrowPage> {\n return list({ ...args, states: [...STATE_GROUPS[stateGroup]] });\n }\n\n return {\n list,\n getById,\n getByUser,\n getByStateGroup,\n };\n}\n\nexport type EscrowsDomain = ReturnType<typeof createEscrowsDomain>;\n","/**\n * Agent domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { AGENT_QUERY, AGENTS_QUERY } from \"../queries\";\nimport type {\n GqlAgent,\n GqlAgentPage,\n GqlAgentFilter,\n AgentQueryResponse,\n AgentsQueryResponse,\n} from \"../generated/types\";\n\nexport interface ListAgentsArgs {\n limit?: number;\n offset?: number;\n onlyActive?: boolean;\n onlyAvailable?: boolean;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates agent domain functions bound to a base URL\n */\nexport function createAgentsDomain(baseUrl: string) {\n /**\n * List agents with filtering and pagination\n */\n async function list(args?: ListAgentsArgs): Promise<GqlAgentPage> {\n const where: GqlAgentFilter = {};\n\n if (args?.onlyActive) where.isActive = true;\n if (args?.onlyAvailable) where.isAvailable = true;\n\n const variables = {\n limit: args?.limit ?? 30,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"totalResolved\",\n orderDirection: args?.orderDirection ?? \"desc\",\n where: Object.keys(where).length > 0 ? where : undefined,\n };\n\n const response = await graphqlRequest<AgentsQueryResponse, typeof variables>(\n baseUrl,\n AGENTS_QUERY,\n variables,\n );\n\n return response.agents;\n }\n\n /**\n * Get a single agent by ID (address)\n */\n async function getById(id: string): Promise<GqlAgent | null> {\n const variables = { id: id.toLowerCase() };\n\n const response = await graphqlRequest<AgentQueryResponse, typeof variables>(\n baseUrl,\n AGENT_QUERY,\n variables,\n );\n\n return response.agent;\n }\n\n /**\n * Get all active and available agents\n */\n async function getAvailable(args?: Omit<ListAgentsArgs, \"onlyActive\" | \"onlyAvailable\">): Promise<GqlAgentPage> {\n return list({ ...args, onlyActive: true, onlyAvailable: true });\n }\n\n return {\n list,\n getById,\n getAvailable,\n };\n}\n\nexport type AgentsDomain = ReturnType<typeof createAgentsDomain>;\n","/**\n * Protocol Stats domain module for the Zenland SDK\n * \n * Stats are tracked per-chain. By default, mainnet stats are returned\n * for production UI. Use chainId parameter to query other networks.\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { PROTOCOL_STATS_QUERY } from \"../queries\";\nimport type { GqlProtocolStats, ProtocolStatsQueryResponse } from \"../generated/types\";\n\n/** Default stats ID for production (Ethereum mainnet) */\nconst DEFAULT_STATS_ID = \"mainnet\";\n\n/** Normalized protocol stats with BigInt values */\nexport interface ProtocolStats {\n id: string;\n chainId?: number;\n totalEscrowsCreated: number;\n totalVolumeEscrowed: bigint;\n totalFeesCollected: bigint;\n currentTVL: bigint;\n activeEscrowCount: number;\n totalAgentsRegistered: number;\n activeAgentsCount: number;\n}\n\n/**\n * Convert raw GraphQL response to normalized ProtocolStats\n */\nfunction normalizeProtocolStats(raw: GqlProtocolStats): ProtocolStats {\n return {\n id: raw.id,\n chainId: (raw as any).chainId,\n totalEscrowsCreated: raw.totalEscrowsCreated,\n totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),\n totalFeesCollected: BigInt(raw.totalFeesCollected),\n currentTVL: BigInt(raw.currentTVL),\n activeEscrowCount: raw.activeEscrowCount,\n totalAgentsRegistered: raw.totalAgentsRegistered,\n activeAgentsCount: raw.activeAgentsCount,\n };\n}\n\nexport interface GetProtocolStatsOptions {\n /** \n * Stats ID to query. Defaults to \"mainnet\".\n * Use \"sepolia\" for testnet stats.\n */\n statsId?: string;\n}\n\n/**\n * Creates protocol stats domain functions bound to a base URL\n */\nexport function createProtocolStatsDomain(baseUrl: string) {\n /**\n * Fetch protocol statistics for a specific chain.\n * Defaults to mainnet for production use.\n * \n * @param options - Optional parameters\n * @param options.statsId - Stats ID to query (default: \"mainnet\")\n */\n async function get(options?: GetProtocolStatsOptions): Promise<ProtocolStats | null> {\n const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n if (!response.protocolStats) {\n return null;\n }\n\n return normalizeProtocolStats(response.protocolStats);\n }\n\n /**\n * Fetch raw protocol statistics (without BigInt conversion)\n * \n * @param options - Optional parameters\n * @param options.statsId - Stats ID to query (default: \"mainnet\")\n */\n async function getRaw(options?: GetProtocolStatsOptions): Promise<GqlProtocolStats | null> {\n const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };\n\n const response = await graphqlRequest<ProtocolStatsQueryResponse, typeof variables>(\n baseUrl,\n PROTOCOL_STATS_QUERY,\n variables,\n );\n\n return response.protocolStats;\n }\n\n return {\n get,\n getRaw,\n };\n}\n\nexport type ProtocolStatsDomain = ReturnType<typeof createProtocolStatsDomain>;\n","/**\n * Transaction Logs domain module for the Zenland SDK\n */\n\nimport { graphqlRequest } from \"../request\";\nimport { TRANSACTION_LOGS_QUERY } from \"../queries\";\nimport type { GqlTransactionLog, TransactionLogsQueryResponse } from \"../generated/types\";\n\nexport interface ListTransactionLogsArgs {\n escrowAddress?: string;\n limit?: number;\n offset?: number;\n orderBy?: string;\n orderDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * Creates transaction logs domain functions bound to a base URL\n */\nexport function createTransactionLogsDomain(baseUrl: string) {\n /**\n * List transaction logs with filtering and pagination\n */\n async function list(args?: ListTransactionLogsArgs): Promise<GqlTransactionLog[]> {\n const variables = {\n escrowAddress: args?.escrowAddress?.toLowerCase(),\n limit: args?.limit ?? 100,\n offset: args?.offset ?? 0,\n orderBy: args?.orderBy ?? \"timestamp\",\n orderDirection: args?.orderDirection ?? \"asc\",\n };\n\n const response = await graphqlRequest<TransactionLogsQueryResponse, typeof variables>(\n baseUrl,\n TRANSACTION_LOGS_QUERY,\n variables,\n );\n\n return response.transactionLogs.items;\n }\n\n /**\n * Get transaction logs for a specific escrow\n */\n async function getByEscrow(\n escrowAddress: string,\n args?: Omit<ListTransactionLogsArgs, \"escrowAddress\">,\n ): Promise<GqlTransactionLog[]> {\n return list({ ...args, escrowAddress });\n }\n\n /**\n * Parse eventData JSON string from a transaction log\n */\n function parseEventData(eventData: string): Record<string, unknown> {\n try {\n return JSON.parse(eventData);\n } catch {\n return {};\n }\n }\n\n return {\n list,\n getByEscrow,\n parseEventData,\n };\n}\n\nexport type TransactionLogsDomain = ReturnType<typeof createTransactionLogsDomain>;\n","/**\n * Zenland SDK Client\n *\n * The main entry point for interacting with the Zenland indexer.\n */\n\nimport { createEscrowsDomain, type EscrowsDomain } from \"./domains/escrows\";\nimport { createAgentsDomain, type AgentsDomain } from \"./domains/agents\";\nimport { createProtocolStatsDomain, type ProtocolStatsDomain } from \"./domains/protocol-stats\";\nimport { createTransactionLogsDomain, type TransactionLogsDomain } from \"./domains/transaction-logs\";\n\n/** Default production indexer URL */\nconst DEFAULT_BASE_URL = \"https://api.zen.land\";\n\nexport interface ZenlandClientConfig {\n /** Base URL for the indexer API. Defaults to https://api.zen.land */\n baseUrl?: string;\n}\n\nexport interface ZenlandClient {\n /** The base URL being used by this client */\n readonly baseUrl: string;\n\n /** Escrow-related operations */\n readonly escrows: EscrowsDomain;\n\n /** Agent-related operations */\n readonly agents: AgentsDomain;\n\n /** Protocol statistics */\n readonly protocolStats: ProtocolStatsDomain;\n\n /** Transaction logs */\n readonly transactionLogs: TransactionLogsDomain;\n}\n\n/**\n * Create a new Zenland SDK client.\n *\n * @example\n * ```typescript\n * // Use production API (default)\n * const client = createZenlandClient();\n *\n * // Use custom endpoint (e.g., local development)\n * const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });\n *\n * // Fetch escrows\n * const { items, totalCount } = await client.escrows.list({ limit: 10 });\n *\n * // Fetch a specific escrow\n * const escrow = await client.escrows.getById('0x...');\n *\n * // Fetch agents\n * const agents = await client.agents.list({ onlyActive: true });\n *\n * // Fetch protocol stats\n * const stats = await client.protocolStats.get();\n * ```\n */\nexport function createZenlandClient(config?: ZenlandClientConfig): ZenlandClient {\n const baseUrl = normalizeBaseUrl(config?.baseUrl ?? DEFAULT_BASE_URL);\n\n return {\n baseUrl,\n escrows: createEscrowsDomain(baseUrl),\n agents: createAgentsDomain(baseUrl),\n protocolStats: createProtocolStatsDomain(baseUrl),\n transactionLogs: createTransactionLogsDomain(baseUrl),\n };\n}\n\n/**\n * Normalize base URL by removing trailing slash\n */\nfunction normalizeBaseUrl(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\n/**\n * Default client instance using production API.\n * Use this for quick access without creating a new client.\n *\n * @example\n * ```typescript\n * import { zenland } from '@zenland/sdk';\n *\n * const escrows = await zenland.escrows.list();\n * ```\n */\nexport const zenland = createZenlandClient();\n","/**\n * Agent eligibility utilities.\n *\n * This is protocol/business logic (React-agnostic) and is safe to consume\n * from any app (interface, backend, bots, etc.).\n */\n\n/**\n * Minimal view of an Agent returned by the indexer.\n */\nexport type IndexerAgent = {\n id: string;\n isActive: boolean;\n isAvailable: boolean;\n stablecoinStake: bigint;\n stablecoinDecimals: number;\n registrationTime: bigint;\n activeCases: number;\n totalResolved: number;\n};\n\nexport type AgentEligibilityFailureReason =\n | \"NOT_REGISTERED\"\n | \"NOT_ACTIVE\"\n | \"NOT_AVAILABLE\"\n | \"INSUFFICIENT_MAV\";\n\nexport type AgentEligibilityResult =\n | {\n ok: true;\n agentMavUsd: bigint;\n requiredUsd: bigint;\n }\n | {\n ok: false;\n reason: AgentEligibilityFailureReason;\n agentMavUsd?: bigint;\n requiredUsd: bigint;\n };\n\n/**\n * MAV multiplier - how much MAV you get per dollar staked.\n * $1 stake * 20 = $20 MAV\n */\nconst MAV_MULTIPLIER = 20n;\n\n/**\n * Compute agent MAV from its stablecoin stake.\n *\n * Bigint-safe:\n * - stablecoinStake is in smallest units (stablecoinDecimals)\n * - return MAV in the same smallest units (stablecoinDecimals)\n */\nexport function computeAgentMavUsd(\n agent: Pick<IndexerAgent, \"stablecoinStake\" | \"stablecoinDecimals\">,\n): bigint {\n // decimals are not used in arithmetic; they’re carried for formatting.\n // MAV is a simple multiplier in the same units.\n return BigInt(agent.stablecoinStake) * MAV_MULTIPLIER;\n}\n\n/**\n * Evaluate whether an agent is eligible for a given escrow amount.\n *\n * NOTE: escrowAmount must be the escrow principal ONLY (fees excluded).\n */\nexport function isAgentEligibleForEscrow(args: {\n agent: IndexerAgent | null | undefined;\n escrowAmount: bigint;\n}): AgentEligibilityResult {\n const requiredUsd = args.escrowAmount;\n\n if (!args.agent) {\n return { ok: false, reason: \"NOT_REGISTERED\", requiredUsd };\n }\n\n if (!args.agent.isActive) {\n return { ok: false, reason: \"NOT_ACTIVE\", requiredUsd };\n }\n\n if (!args.agent.isAvailable) {\n return { ok: false, reason: \"NOT_AVAILABLE\", requiredUsd };\n }\n\n const agentMavUsd = computeAgentMavUsd(args.agent);\n\n if (agentMavUsd < requiredUsd) {\n return { ok: false, reason: \"INSUFFICIENT_MAV\", agentMavUsd, requiredUsd };\n }\n\n return { ok: true, agentMavUsd, requiredUsd };\n}\n"],"mappings":";AAiBO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EAEhB,YAAY,SAAiB,QAA4B;AACvD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAKO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7B;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,QAAgB,YAAoB;AAC/D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,aAAa;AAAA,EACpB;AACF;AASA,eAAsB,eACpB,SACA,UACA,WACA,SACgB;AAChB,QAAM,WAAW,GAAG,OAAO;AAE3B,QAAM,MAAM,MAAM,MAAM,UAAU;AAAA,IAChC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,OAAO,UAAU,UAAU,CAAC;AAAA,IACnD,QAAQ,SAAS;AAAA,IACjB,OAAO;AAAA,EACT,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,OAAO,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,EAAE;AAC5C,UAAM,IAAI;AAAA,MACR,2BAA2B,IAAI,MAAM,IAAI,IAAI,UAAU,IAAI,OAAO,KAAK,IAAI,KAAK,EAAE;AAAA,MAClF,IAAI;AAAA,MACJ,IAAI;AAAA,IACN;AAAA,EACF;AAEA,QAAM,OAAQ,MAAM,IAAI,KAAK;AAE7B,MAAI,KAAK,QAAQ,QAAQ;AACvB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AK;AAEjD,MAAI,cAAc,aAAa;AAC7B,WAAO,EAAE,IAAI,OAAO,QAAQ,oBAAoB,aAAa,YAAY;AAAA,EAC3E;AAEA,SAAO,EAAE,IAAI,MAAM,aAAa,YAAY;AAC9C;","names":[]}
|
package/dist/react.cjs
CHANGED
|
@@ -165,6 +165,7 @@ var ESCROW_QUERY = `
|
|
|
165
165
|
query escrow($id: String!) {
|
|
166
166
|
escrow(id: $id) {
|
|
167
167
|
id
|
|
168
|
+
chainId
|
|
168
169
|
buyer
|
|
169
170
|
seller
|
|
170
171
|
agent
|
|
@@ -209,6 +210,7 @@ query escrows(
|
|
|
209
210
|
) {
|
|
210
211
|
items {
|
|
211
212
|
id
|
|
213
|
+
chainId
|
|
212
214
|
buyer
|
|
213
215
|
seller
|
|
214
216
|
agent
|
|
@@ -236,9 +238,10 @@ query escrows(
|
|
|
236
238
|
}
|
|
237
239
|
`;
|
|
238
240
|
var PROTOCOL_STATS_QUERY = `
|
|
239
|
-
query protocolStats($id: String! = "
|
|
241
|
+
query protocolStats($id: String! = "mainnet") {
|
|
240
242
|
protocolStats(id: $id) {
|
|
241
243
|
id
|
|
244
|
+
chainId
|
|
242
245
|
totalEscrowsCreated
|
|
243
246
|
totalVolumeEscrowed
|
|
244
247
|
totalFeesCollected
|
|
@@ -379,9 +382,11 @@ function createAgentsDomain(baseUrl) {
|
|
|
379
382
|
}
|
|
380
383
|
|
|
381
384
|
// src/domains/protocol-stats.ts
|
|
385
|
+
var DEFAULT_STATS_ID = "mainnet";
|
|
382
386
|
function normalizeProtocolStats(raw) {
|
|
383
387
|
return {
|
|
384
388
|
id: raw.id,
|
|
389
|
+
chainId: raw.chainId,
|
|
385
390
|
totalEscrowsCreated: raw.totalEscrowsCreated,
|
|
386
391
|
totalVolumeEscrowed: BigInt(raw.totalVolumeEscrowed),
|
|
387
392
|
totalFeesCollected: BigInt(raw.totalFeesCollected),
|
|
@@ -392,8 +397,8 @@ function normalizeProtocolStats(raw) {
|
|
|
392
397
|
};
|
|
393
398
|
}
|
|
394
399
|
function createProtocolStatsDomain(baseUrl) {
|
|
395
|
-
async function get() {
|
|
396
|
-
const variables = { id:
|
|
400
|
+
async function get(options) {
|
|
401
|
+
const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };
|
|
397
402
|
const response = await graphqlRequest(
|
|
398
403
|
baseUrl,
|
|
399
404
|
PROTOCOL_STATS_QUERY,
|
|
@@ -404,8 +409,8 @@ function createProtocolStatsDomain(baseUrl) {
|
|
|
404
409
|
}
|
|
405
410
|
return normalizeProtocolStats(response.protocolStats);
|
|
406
411
|
}
|
|
407
|
-
async function getRaw() {
|
|
408
|
-
const variables = { id:
|
|
412
|
+
async function getRaw(options) {
|
|
413
|
+
const variables = { id: options?.statsId ?? DEFAULT_STATS_ID };
|
|
409
414
|
const response = await graphqlRequest(
|
|
410
415
|
baseUrl,
|
|
411
416
|
PROTOCOL_STATS_QUERY,
|