@secondlayer/stacks 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shared/{stacks-3erxq8wh.js → stacks-43cxvnr7.js} +66 -3
- package/dist/shared/stacks-43cxvnr7.js.map +12 -0
- package/dist/shared/{stacks-8e4k5qnm.cjs → stacks-vk8fwz0t.cjs} +63 -2
- package/dist/shared/{stacks-8e4k5qnm.cjs.map → stacks-vk8fwz0t.cjs.map} +5 -4
- package/dist/src/bns/index.js +1 -1
- package/dist/src/clarity/index.d.cts +26 -1
- package/dist/src/clarity/index.d.ts +26 -1
- package/dist/src/clarity/index.js +8 -2
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/index.cjs.map +4 -4
- package/dist/src/index.d.cts +4 -4
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.js.map +4 -4
- package/dist/src/tools/index.cjs +246 -1
- package/dist/src/tools/index.cjs.map +5 -3
- package/dist/src/tools/index.js +246 -1
- package/dist/src/tools/index.js.map +5 -3
- package/package.json +1 -1
- package/dist/shared/stacks-3erxq8wh.js.map +0 -11
package/dist/src/index.d.ts
CHANGED
|
@@ -867,7 +867,7 @@ declare namespace exports_on {
|
|
|
867
867
|
* The user supplies which subgraph + table to bind against — these factories
|
|
868
868
|
* don't assume Foundation Datasets are subscribable. To watch FT transfers
|
|
869
869
|
* to an address, build a subgraph with a `transfers` table (see
|
|
870
|
-
* `sl subgraphs
|
|
870
|
+
* `sl subgraphs create --template sip-010-balances`) and bind here.
|
|
871
871
|
*/
|
|
872
872
|
/**
|
|
873
873
|
* What every factory takes as its first arg: which user-owned subgraph table
|
|
@@ -922,7 +922,7 @@ type BnsAction = "new-name" | "transfer-name" | "renew-name" | "burn-name" | "ne
|
|
|
922
922
|
*
|
|
923
923
|
* Bind against a subgraph table that mirrors the `bns_name_events` shape
|
|
924
924
|
* (topic, namespace, name, owner, ...). Easiest path: scaffold via
|
|
925
|
-
* `sl subgraphs
|
|
925
|
+
* `sl subgraphs create --template bns-names`.
|
|
926
926
|
*
|
|
927
927
|
* @param action restrict to one topic; omit to fire on every name event
|
|
928
928
|
*/
|
|
@@ -934,7 +934,7 @@ type PoxFunction = "stack-stx" | "stack-extend" | "stack-increase" | "delegate-s
|
|
|
934
934
|
/**
|
|
935
935
|
* Match PoX-4 stacking calls. Bind against a subgraph table mirroring
|
|
936
936
|
* `pox4_calls` (function_name, stacker, caller, ...). Scaffold via
|
|
937
|
-
* `sl subgraphs
|
|
937
|
+
* `sl subgraphs create --template pox-stacking`.
|
|
938
938
|
*
|
|
939
939
|
* @param fn restrict to one PoX-4 function; omit to fire on every call
|
|
940
940
|
*/
|
|
@@ -945,7 +945,7 @@ declare function poxStack(target: FactoryTarget, fn?: PoxFunction, opts?: {
|
|
|
945
945
|
/**
|
|
946
946
|
* Match sBTC deposit completion events. Bind against a subgraph table
|
|
947
947
|
* mirroring `sbtc_events` (topic, amount, sender, bitcoin_txid, ...).
|
|
948
|
-
* Scaffold via `sl subgraphs
|
|
948
|
+
* Scaffold via `sl subgraphs create --template sbtc-flows`.
|
|
949
949
|
*/
|
|
950
950
|
declare function sbtcDeposit(target: FactoryTarget, opts?: {
|
|
951
951
|
sender?: string
|
package/dist/src/index.js.map
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"import { createTransport } from \"./createTransport.ts\";\nimport type { RequestFn, TransportFactory } from \"./types.ts\";\n\n/** Create a transport backed by a user-provided request function. */\nexport function custom(params: { request: RequestFn }): TransportFactory {\n\treturn () => createTransport(\"custom\", { request: params.request });\n}\n",
|
|
15
15
|
"import { createTransport } from \"./createTransport.ts\";\nimport type { TransportFactory } from \"./types.ts\";\n\n/** Create a transport that tries each transport in order until one succeeds. */\nexport function fallback(transports: TransportFactory[]): TransportFactory {\n\treturn (params) => {\n\t\tconst resolved = transports.map((t) => t(params));\n\n\t\treturn createTransport(\"fallback\", {\n\t\t\trequest: async (path, options) => {\n\t\t\t\tlet lastError: Error | undefined;\n\t\t\t\tfor (const transport of resolved) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treturn await transport.request(path, options);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tlastError =\n\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow lastError ?? new Error(\"All transports failed\");\n\t\t\t},\n\t\t});\n\t};\n}\n",
|
|
16
16
|
"import { WebSocketError } from \"../errors/websocket.ts\";\nimport type {\n\tSubscription,\n\tWsSubscribeParams,\n} from \"../subscriptions/types.ts\";\nimport { buildRequestFn } from \"./createTransport.ts\";\nimport type { Transport, TransportConfig, TransportFactory } from \"./types.ts\";\n\n/** Configuration for the WebSocket transport, extending base {@link TransportConfig}. */\nexport type WebSocketTransportConfig = TransportConfig & {\n\t/** WebSocket URL (resolved from chain if omitted) */\n\turl?: string;\n\t/** Enable auto-reconnect (default: true) */\n\treconnect?: boolean;\n\t/** Max reconnect attempts (default: 10) */\n\treconnectMaxAttempts?: number;\n\t/** Base delay in ms for exponential backoff (default: 1000) */\n\treconnectBaseDelay?: number;\n};\n\n/** Transport with WebSocket subscription capabilities and auto-reconnect. */\nexport type WebSocketTransport = Transport & {\n\ttype: \"webSocket\";\n\tsubscribe: (\n\t\tparams: WsSubscribeParams,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\tcallback: (data: any) => void,\n\t) => Promise<Subscription>;\n\tdestroy: () => void;\n};\n\ntype JsonRpcRequest = {\n\tjsonrpc: \"2.0\";\n\tid: number;\n\tmethod: string;\n\tparams: Record<string, unknown>;\n};\n\ntype JsonRpcResponse = {\n\tjsonrpc: \"2.0\";\n\tid: number;\n\tresult?: unknown;\n\terror?: { code: number; message: string };\n};\n\ntype JsonRpcNotification = {\n\tjsonrpc: \"2.0\";\n\tmethod: string;\n\tparams: unknown;\n};\n\ntype SubEntry = {\n\tparams: WsSubscribeParams;\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tcallbacks: Set<(data: any) => void>;\n};\n\nfunction subKey(params: WsSubscribeParams): string {\n\tconst parts: string[] = [params.event];\n\tif (params.tx_id) parts.push(`tx_id:${params.tx_id}`);\n\tif (params.address) parts.push(`address:${params.address}`);\n\tif (params.asset_identifier) parts.push(`asset:${params.asset_identifier}`);\n\tif (params.value) parts.push(`value:${params.value}`);\n\treturn parts.join(\"|\");\n}\n\nexport class WebSocketChannel {\n\tprivate ws: WebSocket | null = null;\n\tprivate url: string;\n\tprivate nextId = 1;\n\tprivate pending = new Map<\n\t\tnumber,\n\t\t{ resolve: (v: unknown) => void; reject: (e: Error) => void }\n\t>();\n\tprivate subs = new Map<string, SubEntry>();\n\tprivate destroyed = false;\n\tprivate reconnecting = false;\n\tprivate reconnectAttempt = 0;\n\tprivate reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n\n\tprivate reconnect: boolean;\n\tprivate reconnectMaxAttempts: number;\n\tprivate reconnectBaseDelay: number;\n\n\tconstructor(url: string, config?: WebSocketTransportConfig) {\n\t\tthis.url = url;\n\t\tthis.reconnect = config?.reconnect ?? true;\n\t\tthis.reconnectMaxAttempts = config?.reconnectMaxAttempts ?? 10;\n\t\tthis.reconnectBaseDelay = config?.reconnectBaseDelay ?? 1000;\n\t}\n\n\tprivate connect(): Promise<void> {\n\t\tif (this.ws?.readyState === WebSocket.OPEN) return Promise.resolve();\n\t\tif (this.ws?.readyState === WebSocket.CONNECTING) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tconst onOpen = () => {\n\t\t\t\t\tthis.ws?.removeEventListener(\"error\", onError);\n\t\t\t\t\tresolve();\n\t\t\t\t};\n\t\t\t\tconst onError = (e: Event) => {\n\t\t\t\t\tthis.ws?.removeEventListener(\"open\", onOpen);\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew WebSocketError(\"WebSocket connection failed\", {\n\t\t\t\t\t\t\tdetails: String(e),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tthis.ws?.addEventListener(\"open\", onOpen, { once: true });\n\t\t\t\tthis.ws?.addEventListener(\"error\", onError, { once: true });\n\t\t\t});\n\t\t}\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.ws = new WebSocket(this.url);\n\n\t\t\tthis.ws.addEventListener(\n\t\t\t\t\"open\",\n\t\t\t\t() => {\n\t\t\t\t\tthis.reconnectAttempt = 0;\n\t\t\t\t\tthis.reconnecting = false;\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t);\n\n\t\t\tthis.ws.addEventListener(\n\t\t\t\t\"error\",\n\t\t\t\t(e) => {\n\t\t\t\t\treject(\n\t\t\t\t\t\tnew WebSocketError(\"WebSocket connection failed\", {\n\t\t\t\t\t\t\tdetails: String(e),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t);\n\n\t\t\tthis.ws.addEventListener(\"message\", (event) => {\n\t\t\t\tthis.handleMessage(event.data);\n\t\t\t});\n\n\t\t\tthis.ws.addEventListener(\"close\", () => {\n\t\t\t\tif (!this.destroyed) this.handleDisconnect();\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate handleMessage(raw: string | ArrayBuffer | Blob) {\n\t\tconst data =\n\t\t\ttypeof raw === \"string\"\n\t\t\t\t? raw\n\t\t\t\t: new TextDecoder().decode(raw as ArrayBuffer);\n\n\t\tlet msg: JsonRpcResponse | JsonRpcNotification;\n\t\ttry {\n\t\t\tmsg = JSON.parse(data);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\n\t\t// RPC response\n\t\tif (\"id\" in msg && msg.id != null) {\n\t\t\tconst rpc = msg as JsonRpcResponse;\n\t\t\tconst p = this.pending.get(rpc.id);\n\t\t\tif (!p) return;\n\t\t\tthis.pending.delete(rpc.id);\n\t\t\tif (rpc.error) {\n\t\t\t\tp.reject(\n\t\t\t\t\tnew WebSocketError(rpc.error.message, {\n\t\t\t\t\t\tdetails: `JSON-RPC error ${rpc.error.code}`,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tp.resolve(rpc.result);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Notification\n\t\tconst notif = msg as JsonRpcNotification;\n\t\tif (!notif.method) return;\n\n\t\tfor (const [, entry] of this.subs) {\n\t\t\tif (entry.params.event === notif.method) {\n\t\t\t\tfor (const cb of entry.callbacks) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcb(notif.params);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// subscriber error — don't crash channel\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleDisconnect() {\n\t\tthis.ws = null;\n\n\t\t// reject pending RPCs\n\t\tfor (const [, p] of this.pending) {\n\t\t\tp.reject(new WebSocketError(\"WebSocket disconnected\"));\n\t\t}\n\t\tthis.pending.clear();\n\n\t\tif (\n\t\t\tthis.reconnect &&\n\t\t\tthis.subs.size > 0 &&\n\t\t\tthis.reconnectAttempt < this.reconnectMaxAttempts\n\t\t) {\n\t\t\tthis.scheduleReconnect();\n\t\t}\n\t}\n\n\tprivate scheduleReconnect() {\n\t\tif (this.destroyed || this.reconnecting) return;\n\t\tthis.reconnecting = true;\n\t\tconst delay = this.reconnectBaseDelay * 2 ** this.reconnectAttempt;\n\t\tthis.reconnectAttempt++;\n\n\t\tthis.reconnectTimer = setTimeout(async () => {\n\t\t\tthis.reconnecting = false;\n\t\t\ttry {\n\t\t\t\tawait this.connect();\n\t\t\t\tawait this.resubscribeAll();\n\t\t\t} catch {\n\t\t\t\tif (!this.destroyed && this.subs.size > 0) {\n\t\t\t\t\tthis.handleDisconnect();\n\t\t\t\t}\n\t\t\t}\n\t\t}, delay);\n\t}\n\n\tprivate async resubscribeAll() {\n\t\tfor (const [, entry] of this.subs) {\n\t\t\tawait this.sendRpc(\"subscribe\", entry.params);\n\t\t}\n\t}\n\n\tprivate sendRpc(\n\t\tmethod: string,\n\t\tparams: Record<string, unknown>,\n\t): Promise<unknown> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tif (!this.ws || this.ws.readyState !== WebSocket.OPEN) {\n\t\t\t\treturn reject(new WebSocketError(\"WebSocket not connected\"));\n\t\t\t}\n\n\t\t\tconst id = this.nextId++;\n\t\t\tconst msg: JsonRpcRequest = {\n\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\tid,\n\t\t\t\tmethod,\n\t\t\t\tparams,\n\t\t\t};\n\n\t\t\tthis.pending.set(id, { resolve, reject });\n\t\t\tthis.ws.send(JSON.stringify(msg));\n\t\t});\n\t}\n\n\tasync subscribe(\n\t\tparams: WsSubscribeParams,\n\t\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\tcallback: (data: any) => void,\n\t): Promise<Subscription> {\n\t\tif (this.destroyed) {\n\t\t\tthrow new WebSocketError(\"WebSocket channel has been destroyed\");\n\t\t}\n\n\t\tawait this.connect();\n\n\t\tconst key = subKey(params);\n\t\tlet entry = this.subs.get(key);\n\n\t\tif (entry) {\n\t\t\t// Dedup: reuse existing WS subscription\n\t\t\tentry.callbacks.add(callback);\n\t\t} else {\n\t\t\t// New WS subscription\n\t\t\tentry = { params, callbacks: new Set([callback]) };\n\t\t\tthis.subs.set(key, entry);\n\t\t\tawait this.sendRpc(\"subscribe\", params);\n\t\t}\n\n\t\treturn {\n\t\t\tunsubscribe: () => {\n\t\t\t\tconst e = this.subs.get(key);\n\t\t\t\tif (!e) return;\n\t\t\t\te.callbacks.delete(callback);\n\t\t\t\tif (e.callbacks.size === 0) {\n\t\t\t\t\tthis.subs.delete(key);\n\t\t\t\t\t// Best-effort unsubscribe RPC\n\t\t\t\t\tif (this.ws?.readyState === WebSocket.OPEN) {\n\t\t\t\t\t\tthis.sendRpc(\"unsubscribe\", params).catch(() => {});\n\t\t\t\t\t}\n\t\t\t\t\t// Auto-close when no subscribers remain\n\t\t\t\t\tif (this.subs.size === 0) this.closeQuietly();\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate closeQuietly() {\n\t\tif (this.ws) {\n\t\t\tthis.ws.close();\n\t\t\tthis.ws = null;\n\t\t}\n\t}\n\n\tdestroy(): void {\n\t\tthis.destroyed = true;\n\t\tif (this.reconnectTimer) clearTimeout(this.reconnectTimer);\n\n\t\tfor (const [, p] of this.pending) {\n\t\t\tp.reject(new WebSocketError(\"WebSocket channel destroyed\"));\n\t\t}\n\t\tthis.pending.clear();\n\t\tthis.subs.clear();\n\n\t\tif (this.ws) {\n\t\t\tthis.ws.close();\n\t\t\tthis.ws = null;\n\t\t}\n\t}\n}\n\nfunction deriveWsUrl(httpUrl: string): string {\n\treturn `${httpUrl.replace(/^http/, \"ws\").replace(/\\/$/, \"\")}/extended/v1/ws`;\n}\n\n/**\n * Create a WebSocket transport for real-time Stacks event subscriptions.\n * HTTP requests use the resolved RPC URL; subscriptions use the WS endpoint.\n */\nexport function webSocket(\n\turl?: string,\n\tconfig?: WebSocketTransportConfig,\n): TransportFactory {\n\treturn (params) => {\n\t\tconst httpUrl =\n\t\t\tconfig?.url ??\n\t\t\tparams?.chain?.rpcUrls.default.http[0] ??\n\t\t\t\"http://localhost:3999\";\n\n\t\tconst wsUrl =\n\t\t\turl ?? params?.chain?.rpcUrls.default.ws?.[0] ?? deriveWsUrl(httpUrl);\n\n\t\tconst resolvedHttpConfig: TransportConfig = {\n\t\t\t...config,\n\t\t\turl: httpUrl,\n\t\t};\n\n\t\tconst channel = new WebSocketChannel(wsUrl, config);\n\n\t\tconst transport: WebSocketTransport = {\n\t\t\ttype: \"webSocket\",\n\t\t\trequest: buildRequestFn(httpUrl, resolvedHttpConfig),\n\t\t\tconfig: resolvedHttpConfig,\n\t\t\tsubscribe: (subParams, callback) =>\n\t\t\t\tchannel.subscribe(subParams, callback),\n\t\t\tdestroy: () => channel.destroy(),\n\t\t};\n\n\t\treturn transport;\n\t};\n}\n",
|
|
17
|
-
"/**\n * Filter specs for `@secondlayer/sdk` subscriptions.\n *\n * Each `on.*` factory in this directory binds typed filter clauses to a\n * known table shape and returns a `SubscriptionFilterSpec`. Spread it into\n * a full subscription input alongside `name`, `url`, `format`, etc:\n *\n * const spec = on.transferTo(\n * { subgraph: \"my-watcher\", table: \"transfers\" },\n * \"SP1ABC...\",\n * );\n * await sdk.subscriptions.create({\n * ...spec,\n * name: \"watch-incoming\",\n * url: \"https://my-app.com/webhook\",\n * });\n *\n * The user supplies which subgraph + table to bind against — these factories\n * don't assume Foundation Datasets are subscribable. To watch FT transfers\n * to an address, build a subgraph with a `transfers` table (see\n * `sl subgraphs
|
|
18
|
-
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\nexport type BnsAction =\n\t| \"new-name\"\n\t| \"transfer-name\"\n\t| \"renew-name\"\n\t| \"burn-name\"\n\t| \"new-airdrop\";\n\n/**\n * Match BNS-V2 name lifecycle events.\n *\n * Bind against a subgraph table that mirrors the `bns_name_events` shape\n * (topic, namespace, name, owner, ...). Easiest path: scaffold via\n * `sl subgraphs
|
|
19
|
-
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\nexport type PoxFunction =\n\t| \"stack-stx\"\n\t| \"stack-extend\"\n\t| \"stack-increase\"\n\t| \"delegate-stx\"\n\t| \"revoke-delegate-stx\"\n\t| \"delegate-stack-stx\"\n\t| \"delegate-stack-extend\"\n\t| \"delegate-stack-increase\"\n\t| \"stack-aggregation-commit\"\n\t| \"stack-aggregation-commit-indexed\"\n\t| \"stack-aggregation-increase\"\n\t| \"set-signer-key-authorization\";\n\n/**\n * Match PoX-4 stacking calls. Bind against a subgraph table mirroring\n * `pox4_calls` (function_name, stacker, caller, ...). Scaffold via\n * `sl subgraphs
|
|
20
|
-
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\n/**\n * Match sBTC deposit completion events. Bind against a subgraph table\n * mirroring `sbtc_events` (topic, amount, sender, bitcoin_txid, ...).\n * Scaffold via `sl subgraphs
|
|
17
|
+
"/**\n * Filter specs for `@secondlayer/sdk` subscriptions.\n *\n * Each `on.*` factory in this directory binds typed filter clauses to a\n * known table shape and returns a `SubscriptionFilterSpec`. Spread it into\n * a full subscription input alongside `name`, `url`, `format`, etc:\n *\n * const spec = on.transferTo(\n * { subgraph: \"my-watcher\", table: \"transfers\" },\n * \"SP1ABC...\",\n * );\n * await sdk.subscriptions.create({\n * ...spec,\n * name: \"watch-incoming\",\n * url: \"https://my-app.com/webhook\",\n * });\n *\n * The user supplies which subgraph + table to bind against — these factories\n * don't assume Foundation Datasets are subscribable. To watch FT transfers\n * to an address, build a subgraph with a `transfers` table (see\n * `sl subgraphs create --template sip-010-balances`) and bind here.\n */\n\n/**\n * What every factory takes as its first arg: which user-owned subgraph table\n * to filter against.\n */\nexport type FactoryTarget = {\n\tsubgraph: string;\n\ttable: string;\n};\n\n/**\n * A primitive value that can appear in a filter clause.\n * Mirrors `SubscriptionFilterPrimitive` in\n * `@secondlayer/shared/schemas/subscriptions` — duplicated here to keep\n * `@secondlayer/stacks` from importing the api/server schema package.\n */\nexport type FilterPrimitive = string | number | boolean;\n\n/** Operator forms a filter clause can take. */\nexport type FilterOperator =\n\t| { eq: FilterPrimitive }\n\t| { neq: FilterPrimitive }\n\t| { gt: string | number }\n\t| { gte: string | number }\n\t| { lt: string | number }\n\t| { lte: string | number }\n\t| { in: FilterPrimitive[] };\n\n/** A single column's filter: bare value (eq) or operator object. */\nexport type FilterClause = FilterPrimitive | FilterOperator;\n\n/** Map of column → filter clause. Empty `{}` matches every row. */\nexport type Filter = Record<string, FilterClause>;\n\n/**\n * Output of every `on.*` factory. Use directly as a partial input to\n * `sdk.subscriptions.create` — the SDK's existing `CreateSubscriptionRequest`\n * already accepts these three fields.\n */\nexport type SubscriptionFilterSpec = {\n\tsubgraphName: string;\n\ttableName: string;\n\tfilter: Filter;\n};\n\n/** Thin helper to build a spec without restating the field-name mapping. */\nexport function makeSpec(\n\ttarget: FactoryTarget,\n\tfilter: Filter,\n): SubscriptionFilterSpec {\n\treturn {\n\t\tsubgraphName: target.subgraph,\n\t\ttableName: target.table,\n\t\tfilter,\n\t};\n}\n",
|
|
18
|
+
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\nexport type BnsAction =\n\t| \"new-name\"\n\t| \"transfer-name\"\n\t| \"renew-name\"\n\t| \"burn-name\"\n\t| \"new-airdrop\";\n\n/**\n * Match BNS-V2 name lifecycle events.\n *\n * Bind against a subgraph table that mirrors the `bns_name_events` shape\n * (topic, namespace, name, owner, ...). Easiest path: scaffold via\n * `sl subgraphs create --template bns-names`.\n *\n * @param action restrict to one topic; omit to fire on every name event\n */\nexport function bnsName(\n\ttarget: FactoryTarget,\n\taction?: BnsAction,\n\topts?: { namespace?: string; owner?: string },\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\t...(action && { topic: action }),\n\t\t...(opts?.namespace && { namespace: opts.namespace }),\n\t\t...(opts?.owner && { owner: opts.owner }),\n\t});\n}\n",
|
|
19
|
+
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\nexport type PoxFunction =\n\t| \"stack-stx\"\n\t| \"stack-extend\"\n\t| \"stack-increase\"\n\t| \"delegate-stx\"\n\t| \"revoke-delegate-stx\"\n\t| \"delegate-stack-stx\"\n\t| \"delegate-stack-extend\"\n\t| \"delegate-stack-increase\"\n\t| \"stack-aggregation-commit\"\n\t| \"stack-aggregation-commit-indexed\"\n\t| \"stack-aggregation-increase\"\n\t| \"set-signer-key-authorization\";\n\n/**\n * Match PoX-4 stacking calls. Bind against a subgraph table mirroring\n * `pox4_calls` (function_name, stacker, caller, ...). Scaffold via\n * `sl subgraphs create --template pox-stacking`.\n *\n * @param fn restrict to one PoX-4 function; omit to fire on every call\n */\nexport function poxStack(\n\ttarget: FactoryTarget,\n\tfn?: PoxFunction,\n\topts?: { stacker?: string; signerKey?: string },\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\t...(fn && { function_name: fn }),\n\t\t...(opts?.stacker && { stacker: opts.stacker }),\n\t\t...(opts?.signerKey && { signer_key: opts.signerKey }),\n\t});\n}\n",
|
|
20
|
+
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\n/**\n * Match sBTC deposit completion events. Bind against a subgraph table\n * mirroring `sbtc_events` (topic, amount, sender, bitcoin_txid, ...).\n * Scaffold via `sl subgraphs create --template sbtc-flows`.\n */\nexport function sbtcDeposit(\n\ttarget: FactoryTarget,\n\topts?: { sender?: string; bitcoinTxid?: string },\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\ttopic: \"completed-deposit\",\n\t\t...(opts?.sender && { sender: opts.sender }),\n\t\t...(opts?.bitcoinTxid && { bitcoin_txid: opts.bitcoinTxid }),\n\t});\n}\n\n/**\n * Match sBTC withdrawal lifecycle events. Phase defaults to all three\n * (`create` / `accept` / `reject`); pass an explicit `phase` to narrow.\n */\nexport function sbtcWithdrawal(\n\ttarget: FactoryTarget,\n\topts?: {\n\t\tphase?: \"create\" | \"accept\" | \"reject\";\n\t\tsender?: string;\n\t\trequestId?: number;\n\t},\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\ttopic: opts?.phase\n\t\t\t? { eq: `withdrawal-${opts.phase}` }\n\t\t\t: { in: [\"withdrawal-create\", \"withdrawal-accept\", \"withdrawal-reject\"] },\n\t\t...(opts?.sender && { sender: opts.sender }),\n\t\t...(opts?.requestId !== undefined && { request_id: opts.requestId }),\n\t});\n}\n",
|
|
21
21
|
"import {\n\ttype FactoryTarget,\n\ttype SubscriptionFilterSpec,\n\tmakeSpec,\n} from \"./spec.ts\";\n\n/**\n * Match transfer events into a recipient address.\n *\n * Works against any subgraph table that has a `recipient` column (and\n * optionally `asset_identifier`). Templates that scaffold this shape:\n * `sip-010-balances`, `sbtc-flows`.\n *\n * @param target the user's subgraph + table to bind against\n * @param recipient stx principal that should receive the transfer\n * @param opts.asset optional asset identifier (e.g. `\"SP1...usdc::usdc-token\"`)\n * to filter to a specific FT/NFT contract\n */\nexport function transferTo(\n\ttarget: FactoryTarget,\n\trecipient: string,\n\topts?: { asset?: string },\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\trecipient,\n\t\t...(opts?.asset && { asset_identifier: opts.asset }),\n\t});\n}\n\n/**\n * SIP-010 (fungible token) transfer sugar — alias for `transferTo` that\n * makes the asset filter intent explicit at the call site. Same backing\n * filter; the `asset` param is optional (omit to match every SIP-010\n * transfer in the bound table).\n */\nexport function sip010Transfer(\n\ttarget: FactoryTarget,\n\tasset?: string,\n\topts?: { recipient?: string },\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\t...(asset && { asset_identifier: asset }),\n\t\t...(opts?.recipient && { recipient: opts.recipient }),\n\t});\n}\n\n/**\n * SIP-009 (non-fungible token) transfer sugar — same pattern as\n * `sip010Transfer`. Bind against an NFT-shaped table (see template\n * `nft-transfers` if/when published).\n */\nexport function sip009Transfer(\n\ttarget: FactoryTarget,\n\tasset?: string,\n\topts?: { recipient?: string; tokenId?: string | number },\n): SubscriptionFilterSpec {\n\treturn makeSpec(target, {\n\t\t...(asset && { asset_identifier: asset }),\n\t\t...(opts?.recipient && { recipient: opts.recipient }),\n\t\t...(opts?.tokenId !== undefined && { token_id: String(opts.tokenId) }),\n\t});\n}\n",
|
|
22
22
|
"import { BaseError } from \"./base.ts\";\n\nexport class ContractCallError extends BaseError {\n\toverride name = \"ContractCallError\";\n}\n\nexport class ReadOnlyCallError extends BaseError {\n\toverride name = \"ReadOnlyCallError\";\n}\n"
|
|
23
23
|
],
|
package/dist/src/tools/index.cjs
CHANGED
|
@@ -1576,6 +1576,251 @@ class ContractResponseError extends Error {
|
|
|
1576
1576
|
this.errorValue = errorValue;
|
|
1577
1577
|
}
|
|
1578
1578
|
}
|
|
1579
|
+
// src/clarity/abi/standards.ts
|
|
1580
|
+
var SIP010_ABI = {
|
|
1581
|
+
functions: [
|
|
1582
|
+
{
|
|
1583
|
+
name: "transfer",
|
|
1584
|
+
access: "public",
|
|
1585
|
+
args: [
|
|
1586
|
+
{ name: "amount", type: "uint128" },
|
|
1587
|
+
{ name: "sender", type: "principal" },
|
|
1588
|
+
{ name: "recipient", type: "principal" },
|
|
1589
|
+
{ name: "memo", type: { optional: { buff: { length: 34 } } } }
|
|
1590
|
+
],
|
|
1591
|
+
outputs: { response: { ok: "bool", error: "uint128" } }
|
|
1592
|
+
},
|
|
1593
|
+
{
|
|
1594
|
+
name: "get-balance",
|
|
1595
|
+
access: "read-only",
|
|
1596
|
+
args: [{ name: "account", type: "principal" }],
|
|
1597
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1598
|
+
},
|
|
1599
|
+
{
|
|
1600
|
+
name: "get-total-supply",
|
|
1601
|
+
access: "read-only",
|
|
1602
|
+
args: [],
|
|
1603
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1604
|
+
},
|
|
1605
|
+
{
|
|
1606
|
+
name: "get-name",
|
|
1607
|
+
access: "read-only",
|
|
1608
|
+
args: [],
|
|
1609
|
+
outputs: {
|
|
1610
|
+
response: {
|
|
1611
|
+
ok: { "string-ascii": { length: 32 } },
|
|
1612
|
+
error: "uint128"
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
name: "get-symbol",
|
|
1618
|
+
access: "read-only",
|
|
1619
|
+
args: [],
|
|
1620
|
+
outputs: {
|
|
1621
|
+
response: {
|
|
1622
|
+
ok: { "string-ascii": { length: 10 } },
|
|
1623
|
+
error: "uint128"
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
},
|
|
1627
|
+
{
|
|
1628
|
+
name: "get-decimals",
|
|
1629
|
+
access: "read-only",
|
|
1630
|
+
args: [],
|
|
1631
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1632
|
+
},
|
|
1633
|
+
{
|
|
1634
|
+
name: "get-token-uri",
|
|
1635
|
+
access: "read-only",
|
|
1636
|
+
args: [],
|
|
1637
|
+
outputs: {
|
|
1638
|
+
response: {
|
|
1639
|
+
ok: { optional: { "string-utf8": { length: 256 } } },
|
|
1640
|
+
error: "uint128"
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
],
|
|
1645
|
+
fungible_tokens: [{ name: "token" }]
|
|
1646
|
+
};
|
|
1647
|
+
var SIP009_ABI = {
|
|
1648
|
+
functions: [
|
|
1649
|
+
{
|
|
1650
|
+
name: "transfer",
|
|
1651
|
+
access: "public",
|
|
1652
|
+
args: [
|
|
1653
|
+
{ name: "id", type: "uint128" },
|
|
1654
|
+
{ name: "sender", type: "principal" },
|
|
1655
|
+
{ name: "recipient", type: "principal" }
|
|
1656
|
+
],
|
|
1657
|
+
outputs: { response: { ok: "bool", error: "uint128" } }
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
name: "get-owner",
|
|
1661
|
+
access: "read-only",
|
|
1662
|
+
args: [{ name: "id", type: "uint128" }],
|
|
1663
|
+
outputs: {
|
|
1664
|
+
response: { ok: { optional: "principal" }, error: "uint128" }
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
{
|
|
1668
|
+
name: "get-last-token-id",
|
|
1669
|
+
access: "read-only",
|
|
1670
|
+
args: [],
|
|
1671
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1672
|
+
},
|
|
1673
|
+
{
|
|
1674
|
+
name: "get-token-uri",
|
|
1675
|
+
access: "read-only",
|
|
1676
|
+
args: [{ name: "id", type: "uint128" }],
|
|
1677
|
+
outputs: {
|
|
1678
|
+
response: {
|
|
1679
|
+
ok: { optional: { "string-utf8": { length: 256 } } },
|
|
1680
|
+
error: "uint128"
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
],
|
|
1685
|
+
non_fungible_tokens: [{ name: "nft", type: "uint128" }]
|
|
1686
|
+
};
|
|
1687
|
+
var SIP013_ABI = {
|
|
1688
|
+
functions: [
|
|
1689
|
+
{
|
|
1690
|
+
name: "transfer",
|
|
1691
|
+
access: "public",
|
|
1692
|
+
args: [
|
|
1693
|
+
{ name: "token-id", type: "uint128" },
|
|
1694
|
+
{ name: "amount", type: "uint128" },
|
|
1695
|
+
{ name: "sender", type: "principal" },
|
|
1696
|
+
{ name: "recipient", type: "principal" }
|
|
1697
|
+
],
|
|
1698
|
+
outputs: { response: { ok: "bool", error: "uint128" } }
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
name: "transfer-memo",
|
|
1702
|
+
access: "public",
|
|
1703
|
+
args: [
|
|
1704
|
+
{ name: "token-id", type: "uint128" },
|
|
1705
|
+
{ name: "amount", type: "uint128" },
|
|
1706
|
+
{ name: "sender", type: "principal" },
|
|
1707
|
+
{ name: "recipient", type: "principal" },
|
|
1708
|
+
{ name: "memo", type: { buff: { length: 34 } } }
|
|
1709
|
+
],
|
|
1710
|
+
outputs: { response: { ok: "bool", error: "uint128" } }
|
|
1711
|
+
},
|
|
1712
|
+
{
|
|
1713
|
+
name: "transfer-many",
|
|
1714
|
+
access: "public",
|
|
1715
|
+
args: [
|
|
1716
|
+
{
|
|
1717
|
+
name: "transfers",
|
|
1718
|
+
type: {
|
|
1719
|
+
list: {
|
|
1720
|
+
type: {
|
|
1721
|
+
tuple: [
|
|
1722
|
+
{ name: "token-id", type: "uint128" },
|
|
1723
|
+
{ name: "amount", type: "uint128" },
|
|
1724
|
+
{ name: "sender", type: "principal" },
|
|
1725
|
+
{ name: "recipient", type: "principal" }
|
|
1726
|
+
]
|
|
1727
|
+
},
|
|
1728
|
+
length: 200
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
],
|
|
1733
|
+
outputs: { response: { ok: "bool", error: "uint128" } }
|
|
1734
|
+
},
|
|
1735
|
+
{
|
|
1736
|
+
name: "transfer-many-memo",
|
|
1737
|
+
access: "public",
|
|
1738
|
+
args: [
|
|
1739
|
+
{
|
|
1740
|
+
name: "transfers",
|
|
1741
|
+
type: {
|
|
1742
|
+
list: {
|
|
1743
|
+
type: {
|
|
1744
|
+
tuple: [
|
|
1745
|
+
{ name: "token-id", type: "uint128" },
|
|
1746
|
+
{ name: "amount", type: "uint128" },
|
|
1747
|
+
{ name: "sender", type: "principal" },
|
|
1748
|
+
{ name: "recipient", type: "principal" },
|
|
1749
|
+
{ name: "memo", type: { buff: { length: 34 } } }
|
|
1750
|
+
]
|
|
1751
|
+
},
|
|
1752
|
+
length: 200
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
],
|
|
1757
|
+
outputs: { response: { ok: "bool", error: "uint128" } }
|
|
1758
|
+
},
|
|
1759
|
+
{
|
|
1760
|
+
name: "get-balance",
|
|
1761
|
+
access: "read-only",
|
|
1762
|
+
args: [
|
|
1763
|
+
{ name: "token-id", type: "uint128" },
|
|
1764
|
+
{ name: "account", type: "principal" }
|
|
1765
|
+
],
|
|
1766
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1767
|
+
},
|
|
1768
|
+
{
|
|
1769
|
+
name: "get-overall-balance",
|
|
1770
|
+
access: "read-only",
|
|
1771
|
+
args: [{ name: "account", type: "principal" }],
|
|
1772
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1773
|
+
},
|
|
1774
|
+
{
|
|
1775
|
+
name: "get-total-supply",
|
|
1776
|
+
access: "read-only",
|
|
1777
|
+
args: [{ name: "token-id", type: "uint128" }],
|
|
1778
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
name: "get-overall-supply",
|
|
1782
|
+
access: "read-only",
|
|
1783
|
+
args: [],
|
|
1784
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1785
|
+
},
|
|
1786
|
+
{
|
|
1787
|
+
name: "get-decimals",
|
|
1788
|
+
access: "read-only",
|
|
1789
|
+
args: [{ name: "token-id", type: "uint128" }],
|
|
1790
|
+
outputs: { response: { ok: "uint128", error: "uint128" } }
|
|
1791
|
+
},
|
|
1792
|
+
{
|
|
1793
|
+
name: "get-token-uri",
|
|
1794
|
+
access: "read-only",
|
|
1795
|
+
args: [{ name: "token-id", type: "uint128" }],
|
|
1796
|
+
outputs: {
|
|
1797
|
+
response: {
|
|
1798
|
+
ok: { optional: { "string-utf8": { length: 256 } } },
|
|
1799
|
+
error: "uint128"
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
],
|
|
1804
|
+
fungible_tokens: [],
|
|
1805
|
+
non_fungible_tokens: []
|
|
1806
|
+
};
|
|
1807
|
+
// src/clarity/abi/classify.ts
|
|
1808
|
+
var STANDARDS = [
|
|
1809
|
+
{ id: "sip-010", abi: SIP010_ABI, optional: new Set(["get-token-uri"]) },
|
|
1810
|
+
{ id: "sip-009", abi: SIP009_ABI, optional: new Set(["get-token-uri"]) },
|
|
1811
|
+
{
|
|
1812
|
+
id: "sip-013",
|
|
1813
|
+
abi: SIP013_ABI,
|
|
1814
|
+
optional: new Set([
|
|
1815
|
+
"transfer-memo",
|
|
1816
|
+
"transfer-many",
|
|
1817
|
+
"transfer-many-memo",
|
|
1818
|
+
"get-token-uri",
|
|
1819
|
+
"get-overall-balance",
|
|
1820
|
+
"get-overall-supply"
|
|
1821
|
+
])
|
|
1822
|
+
}
|
|
1823
|
+
];
|
|
1579
1824
|
// src/bns/abi.ts
|
|
1580
1825
|
var BNS_ABI = {
|
|
1581
1826
|
functions: [
|
|
@@ -2465,5 +2710,5 @@ var getNftHoldings = import_ai.tool({
|
|
|
2465
2710
|
execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
|
|
2466
2711
|
});
|
|
2467
2712
|
|
|
2468
|
-
//# debugId=
|
|
2713
|
+
//# debugId=2C93FD5D1703F35064756E2164756E21
|
|
2469
2714
|
//# sourceMappingURL=index.cjs.map
|