@secondlayer/stacks 6.0.0 → 6.1.1

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.
Files changed (217) hide show
  1. package/dist/shared/stacks-esm-0pc6tmf0.js +50 -0
  2. package/dist/shared/{stacks-qex691bh.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
  3. package/dist/shared/{stacks-qt8ehebn.js → stacks-esm-16d82wyc.js} +10 -10
  4. package/dist/shared/{stacks-qt8ehebn.js.map → stacks-esm-16d82wyc.js.map} +2 -2
  5. package/dist/shared/{stacks-qs5fzts5.js → stacks-esm-7a0ehykf.js} +43 -43
  6. package/dist/shared/{stacks-qs5fzts5.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
  7. package/dist/shared/{stacks-4hs8r4q2.js → stacks-esm-7v18h5dk.js} +4 -4
  8. package/dist/shared/{stacks-xjkn3en1.cjs.map → stacks-esm-7v18h5dk.js.map} +2 -2
  9. package/dist/shared/{stacks-71k0vmct.js → stacks-esm-8f5catbf.js} +126 -126
  10. package/dist/shared/{stacks-71k0vmct.js.map → stacks-esm-8f5catbf.js.map} +2 -2
  11. package/dist/shared/{stacks-wxfd6r4b.js → stacks-esm-8jt6k8p3.js} +13 -13
  12. package/dist/shared/{stacks-wxfd6r4b.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
  13. package/dist/shared/{stacks-x0qqwrev.js → stacks-esm-a20wyky3.js} +92 -92
  14. package/dist/shared/{stacks-agk106zs.cjs.map → stacks-esm-a20wyky3.js.map} +2 -2
  15. package/dist/shared/{stacks-gjz26k6b.js → stacks-esm-b54n1jdx.js} +102 -58
  16. package/dist/shared/stacks-esm-b54n1jdx.js.map +12 -0
  17. package/dist/shared/{stacks-9c1yam8b.js → stacks-esm-cmtj5vky.js} +162 -162
  18. package/dist/shared/{stacks-9c1yam8b.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
  19. package/dist/shared/{stacks-z90xdr1x.js → stacks-esm-e2qhfgke.js} +36 -36
  20. package/dist/shared/{stacks-z90xdr1x.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
  21. package/dist/shared/{stacks-v03zef3g.js → stacks-esm-ea4m4bk7.js} +117 -117
  22. package/dist/shared/{stacks-v03zef3g.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
  23. package/dist/shared/{stacks-69nq48jp.js → stacks-esm-hkw1kvd4.js} +140 -140
  24. package/dist/shared/{stacks-69nq48jp.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
  25. package/dist/shared/{stacks-qcae5852.js → stacks-esm-k108pemv.js} +4 -4
  26. package/dist/shared/{stacks-qcae5852.js.map → stacks-esm-k108pemv.js.map} +2 -2
  27. package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
  28. package/dist/shared/{stacks-4d7c3x27.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
  29. package/dist/shared/{stacks-kg1npstf.js → stacks-esm-mt1thm7k.js} +9 -9
  30. package/dist/shared/{stacks-kg1npstf.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
  31. package/dist/shared/{stacks-yvb7rvwk.js → stacks-esm-n1mekwnb.js} +9 -9
  32. package/dist/shared/{stacks-8vzxax5e.cjs.map → stacks-esm-n1mekwnb.js.map} +2 -2
  33. package/dist/shared/{stacks-mftyrc60.js → stacks-esm-nt5hf8ht.js} +34 -34
  34. package/dist/shared/{stacks-mftyrc60.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
  35. package/dist/shared/{stacks-51ybf135.js → stacks-esm-phgy8yqf.js} +210 -210
  36. package/dist/shared/{stacks-51ybf135.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
  37. package/dist/shared/{stacks-mbt36bzt.js → stacks-esm-pxv6ny92.js} +116 -116
  38. package/dist/shared/{stacks-mbt36bzt.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
  39. package/dist/shared/{stacks-8brgfvqx.js → stacks-esm-qfzxhdqz.js} +19 -19
  40. package/dist/shared/{stacks-8brgfvqx.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
  41. package/dist/shared/{stacks-fd4rx56e.js → stacks-esm-snj9s2q8.js} +43 -43
  42. package/dist/shared/{stacks-fd4rx56e.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
  43. package/dist/shared/{stacks-yajyej2y.js → stacks-esm-ss9ap75h.js} +28 -28
  44. package/dist/shared/{stacks-yajyej2y.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
  45. package/dist/shared/{stacks-1m3m1agc.js → stacks-esm-t88hc019.js} +18 -18
  46. package/dist/shared/{stacks-1m3m1agc.js.map → stacks-esm-t88hc019.js.map} +2 -2
  47. package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
  48. package/dist/shared/{stacks-enpj9krt.cjs.map → stacks-esm-tdrdye4y.js.map} +2 -2
  49. package/dist/src/accounts/index.cjs +565 -9
  50. package/dist/src/accounts/index.cjs.map +10 -4
  51. package/dist/src/accounts/index.d.cts +1 -1
  52. package/dist/src/accounts/index.d.ts +1 -1
  53. package/dist/src/accounts/index.js +26 -26
  54. package/dist/src/accounts/index.js.map +2 -2
  55. package/dist/src/actions/index.cjs +3860 -44
  56. package/dist/src/actions/index.cjs.map +65 -3
  57. package/dist/src/actions/index.d.cts +1 -1
  58. package/dist/src/actions/index.d.ts +1 -1
  59. package/dist/src/actions/index.js +102 -103
  60. package/dist/src/actions/index.js.map +1 -1
  61. package/dist/src/bitcoin/index.cjs +2506 -31
  62. package/dist/src/bitcoin/index.cjs.map +31 -3
  63. package/dist/src/bitcoin/index.d.cts +92 -92
  64. package/dist/src/bitcoin/index.d.ts +92 -92
  65. package/dist/src/bitcoin/index.js +88 -90
  66. package/dist/src/bitcoin/index.js.map +2 -2
  67. package/dist/src/bns/index.cjs +4435 -10
  68. package/dist/src/bns/index.cjs.map +50 -3
  69. package/dist/src/bns/index.d.cts +1 -1
  70. package/dist/src/bns/index.d.ts +1 -1
  71. package/dist/src/bns/index.js +39 -41
  72. package/dist/src/bns/index.js.map +2 -2
  73. package/dist/src/chains/index.cjs +141 -5
  74. package/dist/src/chains/index.cjs.map +5 -3
  75. package/dist/src/chains/index.d.cts +1 -1
  76. package/dist/src/chains/index.d.ts +1 -1
  77. package/dist/src/chains/index.js +12 -12
  78. package/dist/src/chains/index.js.map +1 -1
  79. package/dist/src/clarity/index.cjs +2021 -1
  80. package/dist/src/clarity/index.cjs.map +24 -3
  81. package/dist/src/clarity/index.d.cts +1 -1
  82. package/dist/src/clarity/index.d.ts +1 -1
  83. package/dist/src/clarity/index.js +170 -171
  84. package/dist/src/clarity/index.js.map +1 -1
  85. package/dist/src/connect/index.cjs +19 -19
  86. package/dist/src/connect/index.cjs.map +2 -2
  87. package/dist/src/connect/index.d.cts +1 -1
  88. package/dist/src/connect/index.d.ts +1 -1
  89. package/dist/src/connect/index.js +19 -19
  90. package/dist/src/connect/index.js.map +2 -2
  91. package/dist/src/connect/walletconnect/index.cjs +6 -46
  92. package/dist/src/connect/walletconnect/index.cjs.map +3 -4
  93. package/dist/src/connect/walletconnect/index.d.cts +1 -1
  94. package/dist/src/connect/walletconnect/index.d.ts +1 -1
  95. package/dist/src/connect/walletconnect/index.js +6 -46
  96. package/dist/src/connect/walletconnect/index.js.map +3 -4
  97. package/dist/src/filters/index.cjs +727 -1
  98. package/dist/src/filters/index.cjs.map +11 -3
  99. package/dist/src/filters/index.d.cts +76 -13
  100. package/dist/src/filters/index.d.ts +76 -13
  101. package/dist/src/filters/index.js +30 -26
  102. package/dist/src/filters/index.js.map +1 -1
  103. package/dist/src/index.cjs +4000 -126
  104. package/dist/src/index.cjs.map +69 -4
  105. package/dist/src/index.d.cts +658 -607
  106. package/dist/src/index.d.ts +658 -607
  107. package/dist/src/index.js +219 -219
  108. package/dist/src/index.js.map +2 -2
  109. package/dist/src/postconditions/index.cjs +1728 -1
  110. package/dist/src/postconditions/index.cjs.map +20 -3
  111. package/dist/src/postconditions/index.d.cts +1 -1
  112. package/dist/src/postconditions/index.d.ts +1 -1
  113. package/dist/src/postconditions/index.js +16 -17
  114. package/dist/src/postconditions/index.js.map +1 -1
  115. package/dist/src/pox/index.cjs +3866 -11
  116. package/dist/src/pox/index.cjs.map +48 -3
  117. package/dist/src/pox/index.d.cts +1 -1
  118. package/dist/src/pox/index.d.ts +1 -1
  119. package/dist/src/pox/index.js +40 -41
  120. package/dist/src/pox/index.js.map +2 -2
  121. package/dist/src/pox5/index.cjs +4124 -95
  122. package/dist/src/pox5/index.cjs.map +55 -4
  123. package/dist/src/pox5/index.d.cts +9 -1
  124. package/dist/src/pox5/index.d.ts +9 -1
  125. package/dist/src/pox5/index.js +210 -209
  126. package/dist/src/pox5/index.js.map +3 -3
  127. package/dist/src/sbtc/index.cjs +3719 -16
  128. package/dist/src/sbtc/index.cjs.map +47 -3
  129. package/dist/src/sbtc/index.d.cts +1 -1
  130. package/dist/src/sbtc/index.d.ts +1 -1
  131. package/dist/src/sbtc/index.js +39 -40
  132. package/dist/src/sbtc/index.js.map +2 -2
  133. package/dist/src/simnet/index.cjs +16 -16
  134. package/dist/src/simnet/index.cjs.map +2 -2
  135. package/dist/src/simnet/index.d.cts +1 -1
  136. package/dist/src/simnet/index.d.ts +1 -1
  137. package/dist/src/simnet/index.js +16 -16
  138. package/dist/src/simnet/index.js.map +2 -2
  139. package/dist/src/stackingdao/index.cjs +3747 -3
  140. package/dist/src/stackingdao/index.cjs.map +45 -3
  141. package/dist/src/stackingdao/index.d.cts +1 -1
  142. package/dist/src/stackingdao/index.d.ts +1 -1
  143. package/dist/src/stackingdao/index.js +26 -27
  144. package/dist/src/stackingdao/index.js.map +2 -2
  145. package/dist/src/subscriptions/index.cjs +160 -6
  146. package/dist/src/subscriptions/index.cjs.map +6 -3
  147. package/dist/src/subscriptions/index.d.cts +1 -1
  148. package/dist/src/subscriptions/index.d.ts +1 -1
  149. package/dist/src/subscriptions/index.js +14 -15
  150. package/dist/src/subscriptions/index.js.map +1 -1
  151. package/dist/src/transactions/index.cjs +2189 -49
  152. package/dist/src/transactions/index.cjs.map +23 -3
  153. package/dist/src/transactions/index.d.cts +1 -1
  154. package/dist/src/transactions/index.d.ts +1 -1
  155. package/dist/src/transactions/index.js +104 -105
  156. package/dist/src/transactions/index.js.map +1 -1
  157. package/dist/src/utils/index.cjs +503 -69
  158. package/dist/src/utils/index.cjs.map +9 -3
  159. package/dist/src/utils/index.d.cts +1 -1
  160. package/dist/src/utils/index.d.ts +1 -1
  161. package/dist/src/utils/index.js +131 -131
  162. package/dist/src/utils/index.js.map +2 -2
  163. package/package.json +1 -1
  164. package/dist/shared/stacks-02actsrx.cjs +0 -17
  165. package/dist/shared/stacks-02actsrx.cjs.map +0 -10
  166. package/dist/shared/stacks-03vfm21t.cjs +0 -222
  167. package/dist/shared/stacks-03vfm21t.cjs.map +0 -12
  168. package/dist/shared/stacks-24h5k94q.cjs +0 -74
  169. package/dist/shared/stacks-24h5k94q.cjs.map +0 -11
  170. package/dist/shared/stacks-37kz5t9f.cjs +0 -764
  171. package/dist/shared/stacks-37kz5t9f.cjs.map +0 -23
  172. package/dist/shared/stacks-3mt2q2na.cjs +0 -65
  173. package/dist/shared/stacks-3mt2q2na.cjs.map +0 -9
  174. package/dist/shared/stacks-4d7c3x27.js +0 -84
  175. package/dist/shared/stacks-4hs8r4q2.js.map +0 -10
  176. package/dist/shared/stacks-8vzxax5e.cjs +0 -45
  177. package/dist/shared/stacks-agk106zs.cjs +0 -267
  178. package/dist/shared/stacks-bdgh9n83.cjs +0 -212
  179. package/dist/shared/stacks-bdgh9n83.cjs.map +0 -11
  180. package/dist/shared/stacks-dpxnxhqb.cjs +0 -51
  181. package/dist/shared/stacks-dpxnxhqb.cjs.map +0 -11
  182. package/dist/shared/stacks-ee53k9j2.cjs +0 -651
  183. package/dist/shared/stacks-ee53k9j2.cjs.map +0 -13
  184. package/dist/shared/stacks-enpj9krt.cjs +0 -38
  185. package/dist/shared/stacks-f35mnrmg.cjs +0 -164
  186. package/dist/shared/stacks-f35mnrmg.cjs.map +0 -10
  187. package/dist/shared/stacks-fhzwsn5d.cjs +0 -261
  188. package/dist/shared/stacks-fhzwsn5d.cjs.map +0 -12
  189. package/dist/shared/stacks-gjz26k6b.js.map +0 -12
  190. package/dist/shared/stacks-gza2n1zs.cjs +0 -73
  191. package/dist/shared/stacks-gza2n1zs.cjs.map +0 -11
  192. package/dist/shared/stacks-kem68d80.cjs +0 -156
  193. package/dist/shared/stacks-kem68d80.cjs.map +0 -10
  194. package/dist/shared/stacks-n98w7g57.cjs +0 -234
  195. package/dist/shared/stacks-n98w7g57.cjs.map +0 -10
  196. package/dist/shared/stacks-p337hp6m.cjs +0 -336
  197. package/dist/shared/stacks-p337hp6m.cjs.map +0 -25
  198. package/dist/shared/stacks-q34k4vnc.cjs +0 -286
  199. package/dist/shared/stacks-q34k4vnc.cjs.map +0 -12
  200. package/dist/shared/stacks-qex691bh.js +0 -50
  201. package/dist/shared/stacks-rryme9bv.cjs +0 -569
  202. package/dist/shared/stacks-rryme9bv.cjs.map +0 -13
  203. package/dist/shared/stacks-s5vej5z6.cjs +0 -410
  204. package/dist/shared/stacks-s5vej5z6.cjs.map +0 -15
  205. package/dist/shared/stacks-sdqkapct.cjs +0 -67
  206. package/dist/shared/stacks-sdqkapct.cjs.map +0 -12
  207. package/dist/shared/stacks-v2rfr46a.js +0 -48
  208. package/dist/shared/stacks-v2rfr46a.js.map +0 -10
  209. package/dist/shared/stacks-vea7nde7.cjs +0 -731
  210. package/dist/shared/stacks-vea7nde7.cjs.map +0 -13
  211. package/dist/shared/stacks-wk8yp13j.cjs +0 -33
  212. package/dist/shared/stacks-wk8yp13j.cjs.map +0 -11
  213. package/dist/shared/stacks-x0qqwrev.js.map +0 -12
  214. package/dist/shared/stacks-xjkn3en1.cjs +0 -42
  215. package/dist/shared/stacks-xnrywjf1.cjs +0 -131
  216. package/dist/shared/stacks-xnrywjf1.cjs.map +0 -11
  217. package/dist/shared/stacks-yvb7rvwk.js.map +0 -10
@@ -1,471 +1,43 @@
1
- declare const DECODED_EVENT_TYPES: readonly ["stx_transfer", "stx_mint", "stx_burn", "stx_lock", "ft_transfer", "ft_mint", "ft_burn", "nft_transfer", "nft_mint", "nft_burn", "print"];
2
- type DecodedEventType = (typeof DECODED_EVENT_TYPES)[number];
3
- /** Every chain-event filter member across all four surfaces: the 10 decoded
4
- * token/STX types, the three contract-shaped types (spelled as subgraphs and
5
- * triggers spell them — Index/Streams project `print_event` → `print`), and
6
- * the five sBTC lifecycle types (Subscriptions-only). */
7
- declare const CHAIN_EVENT_FILTER_TYPES: readonly ["stx_transfer", "stx_mint", "stx_burn", "stx_lock", "ft_transfer", "ft_mint", "ft_burn", "nft_transfer", "nft_mint", "nft_burn", "contract_call", "contract_deploy", "print_event", "sbtc_deposit", "sbtc_withdrawal_create", "sbtc_withdrawal_accept", "sbtc_withdrawal_reject", "sbtc_withdrawal_swept_confirmed"];
8
- type ChainEventFilterType = (typeof CHAIN_EVENT_FILTER_TYPES)[number];
9
- /** C32-encoded address version bytes for single-sig and multi-sig on each network. */
10
- declare const AddressVersion: {
11
- readonly MainnetSingleSig: 22
12
- readonly MainnetMultiSig: 20
13
- readonly TestnetSingleSig: 26
14
- readonly TestnetMultiSig: 21
1
+ /** Account derived from a local private key (mnemonic or raw key). */
2
+ type LocalAccount = {
3
+ type: "local"
4
+ address: string
5
+ /** Compressed public key (hex) */
6
+ publicKey: string
7
+ /** Raw ECDSA sign over a hash */
8
+ sign(hash: Uint8Array): Uint8Array
9
+ /** Sign a raw UTF-8 / byte message (`sha256(bytes)`). Not SIP-018. */
10
+ signMessage(message: string | Uint8Array): string
15
11
  };
16
- type AddressVersion = (typeof AddressVersion)[keyof typeof AddressVersion];
17
- /** Mainnet burn address (all-zero hash160). */
18
- declare const ZERO_ADDRESS = "SP000000000000000000002Q6VF78";
19
- /** Testnet burn address (all-zero hash160). */
20
- declare const TESTNET_ZERO_ADDRESS = "ST000000000000000000002AMW42H";
21
- /** Number of microSTX per 1 STX (10^6). */
22
- declare const MICROSTX_PER_STX = 1000000n;
23
- /** Alias for validateStacksAddress — matches future.md naming. */
24
- declare const isValidAddress: (address: string) => boolean;
25
- /**
26
- * Compare two Stacks addresses for equality (case-insensitive, version-aware).
27
- * Throws if either address is invalid.
28
- */
29
- declare function isAddressEqual(a: string, b: string): boolean;
30
- /**
31
- * Build a contract address from deployer + contract name.
32
- * Validates both parts; returns `deployer.contractName`.
33
- */
34
- declare function getContractAddress(deployer: string, contractName: string): string;
35
- type AbiUInt128 = "uint128";
36
- type AbiInt128 = "int128";
37
- type AbiBool = "bool";
38
- type AbiPrincipal = "principal";
39
- type AbiTraitReference = "trait_reference";
40
- type AbiNone = "none";
41
- type AbiStringAscii<L extends number = number> = {
42
- "string-ascii": {
43
- length: L
44
- }
12
+ /** Account with a user-provided signing function (sync or async). */
13
+ type CustomAccount = {
14
+ type: "custom"
15
+ address: string
16
+ publicKey: string
17
+ sign(hash: Uint8Array): Promise<Uint8Array> | Uint8Array
45
18
  };
46
- type AbiStringUtf8<L extends number = number> = {
47
- "string-utf8": {
48
- length: L
49
- }
19
+ /** Browser wallet provider interface (e.g. Leather, Xverse). */
20
+ type StacksProvider = {
21
+ request(method: string, params?: any): Promise<any>
50
22
  };
51
- type AbiBuffer<L extends number = number> = {
52
- buff: {
53
- length: L
54
- }
23
+ /** Account backed by a browser wallet {@link StacksProvider}. */
24
+ type ProviderAccount = {
25
+ type: "provider"
26
+ address: string
27
+ publicKey: string
28
+ provider: StacksProvider
55
29
  };
56
- type AbiPrimitiveType = AbiUInt128 | AbiInt128 | AbiBool | AbiPrincipal | AbiTraitReference | AbiNone | AbiStringAscii | AbiStringUtf8 | AbiBuffer;
57
- interface AbiListType {
58
- list: {
59
- type: AbiType
60
- length: number
61
- };
62
- }
63
- interface AbiTupleType {
64
- tuple: ReadonlyArray<{
65
- name: string
66
- type: AbiType
67
- }>;
68
- }
69
- interface AbiOptionalType {
70
- optional: AbiType;
71
- }
72
- interface AbiResponseType {
73
- response: {
74
- ok: AbiType
75
- error: AbiType
76
- };
77
- }
78
- /** Discriminated union of all Clarity value types (primitives, buffers, lists, tuples, optionals, responses). */
79
- type AbiType = AbiPrimitiveType | AbiListType | AbiTupleType | AbiOptionalType | AbiResponseType;
80
- type FunctionAccess = "public" | "read-only" | "private";
81
- interface FunctionArg {
82
- name: string;
83
- type: AbiType;
84
- }
85
- /** A single Clarity function definition with name, access level, arguments, and return type. */
86
- interface AbiFunction {
87
- name: string;
88
- access: FunctionAccess;
89
- args: ReadonlyArray<FunctionArg>;
90
- outputs: AbiType;
91
- }
92
- type VariableAccess = "constant" | "variable";
93
- interface AbiVariable {
94
- name: string;
95
- type: AbiType;
96
- access: VariableAccess;
97
- }
98
- interface AbiMap {
99
- name: string;
100
- key: AbiType;
101
- value: AbiType;
102
- }
103
- interface AbiFungibleToken {
104
- name: string;
105
- }
106
- interface AbiNonFungibleToken {
107
- name: string;
108
- type: AbiType;
109
- }
110
- type TraitFunctionAccess = Exclude<FunctionAccess, "private">;
111
- interface AbiTraitFunction {
112
- name: string;
113
- access: TraitFunctionAccess;
114
- args: ReadonlyArray<FunctionArg>;
115
- outputs: AbiType;
116
- }
117
- interface AbiTraitDefinition {
118
- name: string;
119
- functions: ReadonlyArray<AbiTraitFunction>;
120
- }
121
- /** Full Clarity contract ABI including functions, maps, variables, and token definitions. */
122
- interface AbiContract {
123
- functions: ReadonlyArray<AbiFunction>;
124
- maps?: ReadonlyArray<AbiMap>;
125
- variables?: ReadonlyArray<AbiVariable>;
126
- fungible_tokens?: ReadonlyArray<AbiFungibleToken>;
127
- non_fungible_tokens?: ReadonlyArray<AbiNonFungibleToken>;
128
- implemented_traits?: ReadonlyArray<string>;
129
- defined_traits?: ReadonlyArray<AbiTraitDefinition>;
130
- }
131
- /**
132
- * `<contract>::<asset-name>` — the shape a fungible/non-fungible asset filter
133
- * takes, expressed so the compiler can check it.
134
- *
135
- * The most common mistake in this API is passing a CONTRACT ID
136
- * (`SP….sbtc-token`) where an asset identifier (`SP….sbtc-token::sbtc-token`)
137
- * belongs, and the failure mode is a query that quietly returns zero rows. The
138
- * two differ structurally by `::`, so a template-literal type catches it at the
139
- * call site — no brand, no cast, literals just work.
140
- *
141
- * A value that is only known at runtime (config, env) is not narrow enough on
142
- * purpose; run it through {@link assetId} once, which validates and narrows.
143
- *
144
- * Wildcard patterns (Subscriptions/Subgraphs-only) are admitted by the second arm — they
145
- * are legitimately not full identifiers (`SPB.*`), and the runtime validator
146
- * short-circuits on them for the same reason.
147
- */
148
- type AssetIdentifier = `${string}::${string}` | `${string}*${string}`;
149
- /** Scalar print field types (structural mirror of the subgraphs `ColumnType`). */
150
- type PrintScalarType = "uint" | "int" | "text" | "principal" | "boolean" | "timestamp" | "jsonb";
151
- /**
152
- * One declared print field — structural mirror of `PrintField` in
153
- * `@secondlayer/subgraphs`. Composite forms exist because real print payloads
154
- * nest: a vocabulary that could only say `"jsonb"` is what let a flat-field
155
- * declaration type-check while every event decoded to null.
156
- *
157
- * Kept literal through `toSubgraphSource()` so handler narrowing survives.
158
- */
159
- type PrintFieldType = PrintScalarType | {
160
- type: PrintFieldType
161
- optional: true
162
- } | {
163
- tuple: Record<string, PrintFieldType>
164
- } | {
165
- list: PrintFieldType
30
+ type IntCV = {
31
+ readonly type: "int"
32
+ readonly value: bigint
166
33
  };
167
- interface StxTransferSpec {
168
- type: "stx_transfer";
169
- sender?: string;
170
- recipient?: string;
171
- minAmount?: bigint;
172
- maxAmount?: bigint;
173
- }
174
- interface StxMintSpec {
175
- type: "stx_mint";
176
- recipient?: string;
177
- minAmount?: bigint;
178
- }
179
- interface StxBurnSpec {
180
- type: "stx_burn";
181
- sender?: string;
182
- minAmount?: bigint;
183
- }
184
- interface StxLockSpec {
185
- type: "stx_lock";
186
- lockedAddress?: string;
187
- minAmount?: bigint;
188
- }
189
- /** Scope to contracts conforming to a trait/standard (e.g. "sip-010") instead
190
- * of a fixed contract. Index + Subgraphs + Webhooks; Streams has no
191
- * trait resolution — `toStreamsParams()` throws if set. */
192
- type TraitScope = {
193
- trait?: string
34
+ type UIntCV = {
35
+ readonly type: "uint"
36
+ readonly value: bigint
194
37
  };
195
- /** Scope to a DYNAMIC address set discovered from another source's events —
196
- * a Subgraphs-only concept (`toSubgraphSource()` keeps it; every other
197
- * projection throws). Structural mirror of the subgraphs `FactoryScope`:
198
- * `stacks` is the dependency-graph leaf and cannot import it. */
199
- type FactoryScope = {
200
- factory?: {
201
- /** Source name whose events reveal the addresses. */
202
- from: string
203
- /** Dotted path to the address on that source's payload (e.g. "data.pool"). */
204
- field: string
205
- }
206
- };
207
- interface FtTransferSpec extends TraitScope {
208
- type: "ft_transfer";
209
- assetIdentifier?: AssetIdentifier;
210
- sender?: string;
211
- recipient?: string;
212
- minAmount?: bigint;
213
- }
214
- interface FtMintSpec extends TraitScope {
215
- type: "ft_mint";
216
- assetIdentifier?: AssetIdentifier;
217
- recipient?: string;
218
- minAmount?: bigint;
219
- }
220
- interface FtBurnSpec extends TraitScope {
221
- type: "ft_burn";
222
- assetIdentifier?: AssetIdentifier;
223
- sender?: string;
224
- minAmount?: bigint;
225
- }
226
- interface NftTransferSpec extends TraitScope {
227
- type: "nft_transfer";
228
- assetIdentifier?: AssetIdentifier;
229
- sender?: string;
230
- recipient?: string;
231
- }
232
- interface NftMintSpec extends TraitScope {
233
- type: "nft_mint";
234
- assetIdentifier?: AssetIdentifier;
235
- recipient?: string;
236
- }
237
- interface NftBurnSpec extends TraitScope {
238
- type: "nft_burn";
239
- assetIdentifier?: AssetIdentifier;
240
- sender?: string;
241
- }
242
- interface ContractCallSpec extends TraitScope, FactoryScope {
243
- type: "contract_call";
244
- /** One contract id, or a set of them (max 20). Mirrors the subgraphs
245
- * filter — a router plus its pools is one source, not N. */
246
- contractId?: string | readonly string[];
247
- functionName?: string;
248
- caller?: string;
249
- /** Contract ABI (`as const`) — preserved literally so `toSubgraphSource()`
250
- * keeps typing `event.input` in `defineSubgraph`. */
251
- abi?: AbiContract;
252
- }
253
- interface ContractDeploySpec {
254
- type: "contract_deploy";
255
- deployer?: string;
256
- contractName?: string;
257
- }
258
- interface PrintEventSpec extends TraitScope, FactoryScope {
259
- type: "print_event";
260
- /** One contract id, or a set of them (max 20). */
261
- contractId?: string | readonly string[];
262
- topic?: string;
263
- /** Per-topic field schema — preserved literally so `toSubgraphSource()`
264
- * keeps the discriminated-union narrowing of `event.data`. */
265
- prints?: Record<string, Record<string, PrintFieldType>>;
266
- }
267
- interface SbtcDepositSpec {
268
- type: "sbtc_deposit";
269
- sender?: string;
270
- minAmount?: bigint;
271
- maxAmount?: bigint;
272
- bitcoinTxid?: string;
273
- requestId?: number;
274
- }
275
- interface SbtcWithdrawalCreateSpec {
276
- type: "sbtc_withdrawal_create";
277
- sender?: string;
278
- minAmount?: bigint;
279
- maxAmount?: bigint;
280
- requestId?: number;
281
- }
282
- interface SbtcWithdrawalAcceptSpec {
283
- type: "sbtc_withdrawal_accept";
284
- requestId?: number;
285
- sweepTxid?: string;
286
- }
287
- interface SbtcWithdrawalRejectSpec {
288
- type: "sbtc_withdrawal_reject";
289
- requestId?: number;
290
- }
291
- interface SbtcWithdrawalSweptConfirmedSpec {
292
- type: "sbtc_withdrawal_swept_confirmed";
293
- requestId?: number;
294
- sweepTxid?: string;
295
- }
296
- type ChainEventFilterSpec = StxTransferSpec | StxMintSpec | StxBurnSpec | StxLockSpec | FtTransferSpec | FtMintSpec | FtBurnSpec | NftTransferSpec | NftMintSpec | NftBurnSpec | ContractCallSpec | ContractDeploySpec | PrintEventSpec | SbtcDepositSpec | SbtcWithdrawalCreateSpec | SbtcWithdrawalAcceptSpec | SbtcWithdrawalRejectSpec | SbtcWithdrawalSweptConfirmedSpec;
297
- type SpecFor<T extends ChainEventFilterType> = Extract<ChainEventFilterSpec, {
298
- type: T
299
- }>;
300
- /** Wire shape of a chain trigger (Webhooks), derived per member from
301
- * the spec: same fields, with `bigint` amounts stringified (uint128 exceeds
302
- * JS safe integers) and the type-only `abi`/`prints` decorations dropped.
303
- * Structurally assignable to the SDK's `ChainTrigger` union. */
304
- type ChainTriggerOf<S> = { [K in keyof Omit<S, "abi" | "prints" | "factory">] : Exclude<S[K], bigint | readonly string[]> | (bigint extends S[K] ? string : never) };
305
- /** Params fragment for `index.events.*` (spread into list/walk/consume). */
306
- type IndexEventsParamsShape = {
307
- eventType: DecodedEventType
308
- /** A spec's contract set passes through verbatim (the API takes up to 20). */
309
- contractId?: string | readonly string[]
310
- assetIdentifier?: AssetIdentifier
311
- sender?: string
312
- recipient?: string
313
- trait?: string
314
- };
315
- /** Params fragment for `index.contractCalls.*`. */
316
- type ContractCallsParamsShape = {
317
- /** A spec's contract set passes through verbatim (the API takes up to 20). */
318
- contractId?: string | readonly string[]
319
- functionName?: string
320
- /** Populated from the spec's `caller` — the endpoint filters by tx sender,
321
- * which is the caller. */
322
- sender?: string
323
- trait?: string
324
- };
325
- /** Params fragment for `streams.events.*`. */
326
- type StreamsParamsShape = {
327
- types: readonly DecodedEventType[]
328
- contractId?: string | readonly string[]
329
- sender?: string
330
- recipient?: string
331
- assetIdentifier?: AssetIdentifier
332
- };
333
- type DecodedMember = "stx_transfer" | "stx_mint" | "stx_burn" | "stx_lock" | "ft_transfer" | "ft_mint" | "ft_burn" | "nft_transfer" | "nft_mint" | "nft_burn" | "print_event";
334
- type ProjectionsFor<
335
- T extends ChainEventFilterType,
336
- S
337
- > = {
338
- /** Wire trigger for `subscriptions.create({ triggers: [...] })`. BigInt
339
- * amounts become strings here — the one sanctioned boundary. */
340
- toChainTrigger(): ChainTriggerOf<S>
341
- } & (T extends DecodedMember ? {
342
- /** Params for `index.events.list/walk/consume` (merge your own
343
- * `limit`/`fromHeight`/`txContext` etc. on top). */
344
- toIndexParams<Extra extends Record<string, unknown>>(extra?: Extra): IndexEventsParamsShape & Extra
345
- /** Params for `streams.events.list/consume/stream`. Throws if the
346
- * filter uses `trait` (Streams has no trait resolution) or a
347
- * min/max amount (Streams filters have no amount predicates). */
348
- toStreamsParams<Extra extends Record<string, unknown>>(extra?: Extra): StreamsParamsShape & Extra
349
- } : {}) & (T extends "contract_call" ? {
350
- /** Params for `index.contractCalls.list/walk/consume`. */
351
- toContractCallsParams<Extra extends Record<string, unknown>>(extra?: Extra): ContractCallsParamsShape & Extra
352
- } : {}) & (T extends Exclude<ChainEventFilterType, `sbtc_${string}`> ? {
353
- /** The `sources` entry for `defineSubgraph` — literal `prints`/`abi`
354
- * types are preserved, so handler narrowing survives. */
355
- toSubgraphSource(): S
356
- } : {});
357
- /**
358
- * A canonical chain-event filter: the spec fields plus the projections its
359
- * member supports. Write the filter once; project it to a query
360
- * (`toIndexParams`), a stream (`toStreamsParams`), a webhook trigger
361
- * (`toChainTrigger`), or a subgraph source (`toSubgraphSource`).
362
- */
363
- type ChainEventFilter<
364
- T extends ChainEventFilterType = ChainEventFilterType,
365
- S extends {
366
- type: T
367
- } = SpecFor<T>
368
- > = S & ProjectionsFor<T, S>;
369
- type Fields<T extends ChainEventFilterType> = Omit<SpecFor<T>, "type">;
370
- /** The `on.*` namespace, annotated explicitly — bunup's dts emitter needs an
371
- * annotation on exported values (an inferred object of generic factories
372
- * collapses to `{}` in the emitted declarations). */
373
- interface OnNamespace {
374
- stxTransfer(fields?: Fields<"stx_transfer">): ChainEventFilter<"stx_transfer">;
375
- stxMint(fields?: Fields<"stx_mint">): ChainEventFilter<"stx_mint">;
376
- stxBurn(fields?: Fields<"stx_burn">): ChainEventFilter<"stx_burn">;
377
- stxLock(fields?: Fields<"stx_lock">): ChainEventFilter<"stx_lock">;
378
- ftTransfer(fields?: Fields<"ft_transfer">): ChainEventFilter<"ft_transfer">;
379
- ftMint(fields?: Fields<"ft_mint">): ChainEventFilter<"ft_mint">;
380
- ftBurn(fields?: Fields<"ft_burn">): ChainEventFilter<"ft_burn">;
381
- nftTransfer(fields?: Fields<"nft_transfer">): ChainEventFilter<"nft_transfer">;
382
- nftMint(fields?: Fields<"nft_mint">): ChainEventFilter<"nft_mint">;
383
- nftBurn(fields?: Fields<"nft_burn">): ChainEventFilter<"nft_burn">;
384
- /** `abi` literals are preserved (`const A`) so `toSubgraphSource()` keeps
385
- * typing `event.input` inside `defineSubgraph`. */
386
- contractCall<const A extends AbiContract | undefined = undefined>(fields?: Omit<SpecFor<"contract_call">, "type" | "abi"> & {
387
- abi?: A
388
- }): ChainEventFilter<"contract_call", {
389
- type: "contract_call"
390
- } & Omit<SpecFor<"contract_call">, "type" | "abi"> & {
391
- abi?: A
392
- }>;
393
- contractDeploy(fields?: Fields<"contract_deploy">): ChainEventFilter<"contract_deploy">;
394
- /** Canonical member is `print_event` (as Subgraphs and Subscriptions spell
395
- * it); `toIndexParams`/`toStreamsParams` project to `print`. `prints`
396
- * literals are preserved (`const P`) for per-topic `event.data` narrowing. */
397
- print<const P extends Record<string, Record<string, PrintFieldType>> | undefined = undefined>(fields?: Omit<SpecFor<"print_event">, "type" | "prints"> & {
398
- prints?: P
399
- }): ChainEventFilter<"print_event", {
400
- type: "print_event"
401
- } & Omit<SpecFor<"print_event">, "type" | "prints"> & {
402
- prints?: P
403
- }>;
404
- sbtcDeposit(fields?: Fields<"sbtc_deposit">): ChainEventFilter<"sbtc_deposit">;
405
- sbtcWithdrawalCreate(fields?: Fields<"sbtc_withdrawal_create">): ChainEventFilter<"sbtc_withdrawal_create">;
406
- sbtcWithdrawalAccept(fields?: Fields<"sbtc_withdrawal_accept">): ChainEventFilter<"sbtc_withdrawal_accept">;
407
- sbtcWithdrawalReject(fields?: Fields<"sbtc_withdrawal_reject">): ChainEventFilter<"sbtc_withdrawal_reject">;
408
- sbtcWithdrawalSweptConfirmed(fields?: Fields<"sbtc_withdrawal_swept_confirmed">): ChainEventFilter<"sbtc_withdrawal_swept_confirmed">;
409
- }
410
- /**
411
- * `on.*` — one filter vocabulary for every surface.
412
- *
413
- * ```ts
414
- * import { on } from "@secondlayer/stacks/filters";
415
- *
416
- * const usdc = on.ftTransfer({ assetIdentifier: USDC, minAmount: 1_000_000n });
417
- *
418
- * sl.index.events.list(usdc.toIndexParams({ limit: 100 })); // pull
419
- * sl.streams.events.consume({ ...usdc.toStreamsParams(), onBatch });
420
- * sl.subscriptions.create({ name, url, triggers: [usdc.toChainTrigger()] });
421
- * defineSubgraph({ sources: { usdc: usdc.toSubgraphSource() }, schema, handlers });
422
- * ```
423
- *
424
- * A surface a member can't reach is a missing method (compile error), and a
425
- * field a surface can't express throws at projection time — never a silent
426
- * zero-row or over-wide match.
427
- */
428
- declare const on: OnNamespace;
429
- /** Account derived from a local private key (mnemonic or raw key). */
430
- type LocalAccount = {
431
- type: "local"
432
- address: string
433
- /** Compressed public key (hex) */
434
- publicKey: string
435
- /** Raw ECDSA sign over a hash */
436
- sign(hash: Uint8Array): Uint8Array
437
- /** Sign a raw UTF-8 / byte message (`sha256(bytes)`). Not SIP-018. */
438
- signMessage(message: string | Uint8Array): string
439
- };
440
- /** Account with a user-provided signing function (sync or async). */
441
- type CustomAccount = {
442
- type: "custom"
443
- address: string
444
- publicKey: string
445
- sign(hash: Uint8Array): Promise<Uint8Array> | Uint8Array
446
- };
447
- /** Browser wallet provider interface (e.g. Leather, Xverse). */
448
- type StacksProvider = {
449
- request(method: string, params?: any): Promise<any>
450
- };
451
- /** Account backed by a browser wallet {@link StacksProvider}. */
452
- type ProviderAccount = {
453
- type: "provider"
454
- address: string
455
- publicKey: string
456
- provider: StacksProvider
457
- };
458
- type IntCV = {
459
- readonly type: "int"
460
- readonly value: bigint
461
- };
462
- type UIntCV = {
463
- readonly type: "uint"
464
- readonly value: bigint
465
- };
466
- type BooleanCV = TrueCV | FalseCV;
467
- type TrueCV = {
468
- readonly type: "true"
38
+ type BooleanCV = TrueCV | FalseCV;
39
+ type TrueCV = {
40
+ readonly type: "true"
469
41
  };
470
42
  type FalseCV = {
471
43
  readonly type: "false"
@@ -1729,159 +1301,638 @@ declare function createMultiSigClient(config: MultiSigClientConfig): MultiSigCli
1729
1301
  type RedisLike = {
1730
1302
  send(command: string, args: string[]): Promise<unknown>
1731
1303
  };
1732
- type RedisStoreParams = {
1733
- redis: RedisLike
1734
- /** Key prefix for stored nonce counters. Default `"stacks:nonce:"`. */
1735
- prefix?: string
1304
+ type RedisStoreParams = {
1305
+ redis: RedisLike
1306
+ /** Key prefix for stored nonce counters. Default `"stacks:nonce:"`. */
1307
+ prefix?: string
1308
+ };
1309
+ /**
1310
+ * Redis-backed nonce store. The atomic reserve lives in a Lua `EVAL`, so it is
1311
+ * safe across processes sharing one Redis. The confirmed floor (`getFloor`) is
1312
+ * read only once per key, on cold start.
1313
+ */
1314
+ declare function redisStore(params: RedisStoreParams): NonceStore;
1315
+ /** Minimal structural shape of a `Bun.sql` tagged-template client. */
1316
+ type SqlLike = (strings: TemplateStringsArray, ...values: unknown[]) => Promise<Array<Record<string, unknown>>>;
1317
+ type PostgresStoreParams = {
1318
+ sql: SqlLike
1319
+ /**
1320
+ * Run `CREATE TABLE IF NOT EXISTS stacks_nonce_state` lazily on first use.
1321
+ * Default `true`. Set `false` if you manage the schema via migrations.
1322
+ */
1323
+ ensureTable?: boolean
1324
+ };
1325
+ /**
1326
+ * Postgres-backed nonce store. Each reserve is a single atomic statement under
1327
+ * a row lock, so concurrent reservers on the same key serialize and never
1328
+ * collide across processes. State is durable — survives restarts.
1329
+ *
1330
+ * Uses a fixed table `stacks_nonce_state (key text primary key, next numeric)`.
1331
+ */
1332
+ declare function postgresStore(params: PostgresStoreParams): NonceStore;
1333
+ /**
1334
+ * Mempool-aware {@link NonceManagerSource}s.
1335
+ *
1336
+ * The default {@link jsonRpcSource} reads only the confirmed nonce, so a tx
1337
+ * sitting in the mempool is invisible — broadcasting many quickly forces manual
1338
+ * tracking. These sources fold pending (mempool) txs into the next-nonce
1339
+ * computation. The gap-filling core is generic; where the pending set comes from
1340
+ * is pluggable, so you are never locked to any one provider:
1341
+ *
1342
+ * - {@link mempoolAwareSource} — bring your own `getPending`.
1343
+ * - {@link indexSource}: prebuilt over a Secondlayer instance's `/v1/index/mempool`.
1344
+ * - {@link hiroNonceSource} — prebuilt over Hiro's `/extended` nonces endpoint.
1345
+ */
1346
+ type FetchImpl = typeof globalThis.fetch;
1347
+ /**
1348
+ * The next free nonce ≥ `confirmed` not already taken by a pending tx.
1349
+ *
1350
+ * Unlike Hiro's `possible_next_nonce` (which is `max(pending) + 1` and strands
1351
+ * higher txs when a lower nonce is missing), this FILLS gaps: it returns the
1352
+ * lowest unused slot, so a dropped-tx hole is reused instead of stranding the
1353
+ * chain.
1354
+ */
1355
+ declare function nextFreeNonce(confirmed: bigint, pending: bigint[]): bigint;
1356
+ type MempoolAwareSourceParams = {
1357
+ /** Pending (mempool) nonces for an address. */
1358
+ getPending: (args: {
1359
+ client: Client
1360
+ address: string
1361
+ }) => Promise<bigint[]>
1362
+ /**
1363
+ * Confirmed-nonce floor. Defaults to the node's `/v2/accounts` read — the
1364
+ * user's own node via the client transport, no provider dependency.
1365
+ */
1366
+ getConfirmed?: (args: {
1367
+ client: Client
1368
+ address: string
1369
+ }) => Promise<bigint>
1370
+ };
1371
+ /**
1372
+ * Build a gap-filling, mempool-aware source from any `getPending`. The confirmed
1373
+ * floor defaults to the node read; if `getPending` throws, the source degrades
1374
+ * to confirmed-only rather than blocking a broadcast. A misconfigured pending
1375
+ * feed ({@link IndexSourceConfigError}) is rethrown: it would fail on every
1376
+ * read, and degrading silently would hide that the mempool is never consulted.
1377
+ */
1378
+ declare function mempoolAwareSource(params: MempoolAwareSourceParams): NonceManagerSource;
1379
+ type IndexSourceParams = {
1380
+ /**
1381
+ * URL of your Secondlayer instance. Without it the client's transport
1382
+ * URL is assumed to be the instance: a transport on a Hiro host throws
1383
+ * up front, and a host that answers `/v1/index` with a non-JSON 404
1384
+ * (a bare stacks-node) throws on the first read. Neither is degraded
1385
+ * to the confirmed floor. Pass it whenever the transport is not the
1386
+ * instance.
1387
+ */
1388
+ baseUrl?: string
1389
+ /** Instance token, sent as `Authorization: Bearer`. */
1390
+ apiKey?: string
1391
+ /** Max mempool pages to read per address. Default 10 (×200 = 2000 txs). */
1392
+ maxPages?: number
1393
+ /** Override the confirmed floor (defaults to the node read). */
1394
+ getConfirmed?: (args: {
1395
+ client: Client
1396
+ address: string
1397
+ }) => Promise<bigint>
1398
+ };
1399
+ /**
1400
+ * Mempool-aware source backed by a Secondlayer instance's `/v1/index/mempool`.
1401
+ * Requests go through the transport layer (retries, timeout, typed errors).
1402
+ * The instance's mempool is a go-forward view observed by its own node, so
1403
+ * it can lag or miss transactions that node never saw; the manager's local
1404
+ * increment still prevents same-process collisions. Past `maxPages` the
1405
+ * pending set is truncated and the next free nonce may already be taken;
1406
+ * a nonce conflict at broadcast then resets the manager. Transient failures
1407
+ * (5xx, timeout) degrade to the confirmed floor; a missing or wrong instance
1408
+ * URL throws so the misconfiguration is visible on the first read.
1409
+ */
1410
+ declare function indexSource(params?: IndexSourceParams): NonceManagerSource;
1411
+ type HiroNonceSourceParams = {
1412
+ /** Hiro API base URL, e.g. `https://api.hiro.so` or `https://api.testnet.hiro.so`. */
1413
+ baseUrl: string
1414
+ apiKey?: string
1415
+ fetchImpl?: FetchImpl
1416
+ };
1417
+ /**
1418
+ * Off-the-shelf, non-Secondlayer mempool-aware source over Hiro's
1419
+ * `/extended/v1/address/{address}/nonces`. Fills the lowest detected gap first,
1420
+ * then falls back to `possible_next_nonce`. Requires a host that serves Hiro's
1421
+ * extended API (a bare stacks-node does not).
1422
+ */
1423
+ declare function hiroNonceSource(params: HiroNonceSourceParams): NonceManagerSource;
1424
+ /**
1425
+ * Create an HTTP transport for Stacks node RPC calls.
1426
+ * Falls back to the chain's default RPC URL, then `localhost:3999`.
1427
+ */
1428
+ declare function http(url?: string, config?: TransportConfig): TransportFactory;
1429
+ /** Create a transport backed by a user-provided request function. */
1430
+ declare function custom(params: {
1431
+ request: RequestFn
1432
+ }): TransportFactory;
1433
+ /** Create a transport that tries each transport in order until one succeeds. */
1434
+ declare function fallback(transports: TransportFactory[]): TransportFactory;
1435
+ /** Configuration for the WebSocket transport, extending base {@link TransportConfig}. */
1436
+ type WebSocketTransportConfig = TransportConfig & {
1437
+ /** WebSocket URL (resolved from chain if omitted) */
1438
+ url?: string
1439
+ /** Enable auto-reconnect (default: true) */
1440
+ reconnect?: boolean
1441
+ /** Max reconnect attempts (default: 10) */
1442
+ reconnectMaxAttempts?: number
1443
+ /** Base delay in ms for exponential backoff (default: 1000) */
1444
+ reconnectBaseDelay?: number
1445
+ };
1446
+ /** Transport with WebSocket subscription capabilities and auto-reconnect. */
1447
+ type WebSocketTransport = Transport & {
1448
+ type: "webSocket"
1449
+ subscribe: (params: WsSubscribeParams, callback: (data: any) => void) => Promise<Subscription>
1450
+ destroy: () => void
1451
+ };
1452
+ /**
1453
+ * Create a WebSocket transport for real-time Stacks event subscriptions.
1454
+ * HTTP requests use the resolved RPC URL; subscriptions use the WS endpoint.
1455
+ */
1456
+ declare function webSocket(url?: string, config?: WebSocketTransportConfig): TransportFactory;
1457
+ declare const DECODED_EVENT_TYPES: readonly ["stx_transfer", "stx_mint", "stx_burn", "stx_lock", "ft_transfer", "ft_mint", "ft_burn", "nft_transfer", "nft_mint", "nft_burn", "print"];
1458
+ type DecodedEventType = (typeof DECODED_EVENT_TYPES)[number];
1459
+ /** Opt-in node vm_events, stored names. Parallel to DECODED_EVENT_TYPES — not
1460
+ * the decoded_events / Streams 1.0 vocab. Cursor second component is
1461
+ * ordinal. Inner calls are never `contract_call`. */
1462
+ declare const VM_EVENT_TYPES: readonly ["nested_contract_call", "var_set", "map_set", "map_insert", "map_delete"];
1463
+ type VmEventType = (typeof VM_EVENT_TYPES)[number];
1464
+ /** Every chain-event filter member across all four surfaces: the 10 decoded
1465
+ * token/STX types, the three contract-shaped types (spelled as subgraphs and
1466
+ * triggers spell them — Index/Streams project `print_event` → `print`), and
1467
+ * the five sBTC lifecycle types (Webhooks-only). */
1468
+ declare const CHAIN_EVENT_FILTER_TYPES: readonly ["stx_transfer", "stx_mint", "stx_burn", "stx_lock", "ft_transfer", "ft_mint", "ft_burn", "nft_transfer", "nft_mint", "nft_burn", "contract_call", "contract_deploy", "print_event", "nested_contract_call", "var_set", "map_set", "map_insert", "map_delete", "sbtc_deposit", "sbtc_withdrawal_create", "sbtc_withdrawal_accept", "sbtc_withdrawal_reject", "sbtc_withdrawal_swept_confirmed"];
1469
+ type ChainEventFilterType = (typeof CHAIN_EVENT_FILTER_TYPES)[number];
1470
+ /** C32-encoded address version bytes for single-sig and multi-sig on each network. */
1471
+ declare const AddressVersion: {
1472
+ readonly MainnetSingleSig: 22
1473
+ readonly MainnetMultiSig: 20
1474
+ readonly TestnetSingleSig: 26
1475
+ readonly TestnetMultiSig: 21
1476
+ };
1477
+ type AddressVersion = (typeof AddressVersion)[keyof typeof AddressVersion];
1478
+ /** Mainnet burn address (all-zero hash160). */
1479
+ declare const ZERO_ADDRESS = "SP000000000000000000002Q6VF78";
1480
+ /** Testnet burn address (all-zero hash160). */
1481
+ declare const TESTNET_ZERO_ADDRESS = "ST000000000000000000002AMW42H";
1482
+ /** Number of microSTX per 1 STX (10^6). */
1483
+ declare const MICROSTX_PER_STX = 1000000n;
1484
+ /** Alias for validateStacksAddress — matches future.md naming. */
1485
+ declare const isValidAddress: (address: string) => boolean;
1486
+ /**
1487
+ * Compare two Stacks addresses for equality (case-insensitive, version-aware).
1488
+ * Throws if either address is invalid.
1489
+ */
1490
+ declare function isAddressEqual(a: string, b: string): boolean;
1491
+ /**
1492
+ * Build a contract address from deployer + contract name.
1493
+ * Validates both parts; returns `deployer.contractName`.
1494
+ */
1495
+ declare function getContractAddress(deployer: string, contractName: string): string;
1496
+ type AbiUInt128 = "uint128";
1497
+ type AbiInt128 = "int128";
1498
+ type AbiBool = "bool";
1499
+ type AbiPrincipal = "principal";
1500
+ type AbiTraitReference = "trait_reference";
1501
+ type AbiNone = "none";
1502
+ type AbiStringAscii<L extends number = number> = {
1503
+ "string-ascii": {
1504
+ length: L
1505
+ }
1506
+ };
1507
+ type AbiStringUtf8<L extends number = number> = {
1508
+ "string-utf8": {
1509
+ length: L
1510
+ }
1511
+ };
1512
+ type AbiBuffer<L extends number = number> = {
1513
+ buff: {
1514
+ length: L
1515
+ }
1516
+ };
1517
+ type AbiPrimitiveType = AbiUInt128 | AbiInt128 | AbiBool | AbiPrincipal | AbiTraitReference | AbiNone | AbiStringAscii | AbiStringUtf8 | AbiBuffer;
1518
+ interface AbiListType {
1519
+ list: {
1520
+ type: AbiType
1521
+ length: number
1522
+ };
1523
+ }
1524
+ interface AbiTupleType {
1525
+ tuple: ReadonlyArray<{
1526
+ name: string
1527
+ type: AbiType
1528
+ }>;
1529
+ }
1530
+ interface AbiOptionalType {
1531
+ optional: AbiType;
1532
+ }
1533
+ interface AbiResponseType {
1534
+ response: {
1535
+ ok: AbiType
1536
+ error: AbiType
1537
+ };
1538
+ }
1539
+ /** Discriminated union of all Clarity value types (primitives, buffers, lists, tuples, optionals, responses). */
1540
+ type AbiType = AbiPrimitiveType | AbiListType | AbiTupleType | AbiOptionalType | AbiResponseType;
1541
+ type FunctionAccess = "public" | "read-only" | "private";
1542
+ interface FunctionArg {
1543
+ name: string;
1544
+ type: AbiType;
1545
+ }
1546
+ /** A single Clarity function definition with name, access level, arguments, and return type. */
1547
+ interface AbiFunction {
1548
+ name: string;
1549
+ access: FunctionAccess;
1550
+ args: ReadonlyArray<FunctionArg>;
1551
+ outputs: AbiType;
1552
+ }
1553
+ type VariableAccess = "constant" | "variable";
1554
+ interface AbiVariable {
1555
+ name: string;
1556
+ type: AbiType;
1557
+ access: VariableAccess;
1558
+ }
1559
+ interface AbiMap {
1560
+ name: string;
1561
+ key: AbiType;
1562
+ value: AbiType;
1563
+ }
1564
+ interface AbiFungibleToken {
1565
+ name: string;
1566
+ }
1567
+ interface AbiNonFungibleToken {
1568
+ name: string;
1569
+ type: AbiType;
1570
+ }
1571
+ type TraitFunctionAccess = Exclude<FunctionAccess, "private">;
1572
+ interface AbiTraitFunction {
1573
+ name: string;
1574
+ access: TraitFunctionAccess;
1575
+ args: ReadonlyArray<FunctionArg>;
1576
+ outputs: AbiType;
1577
+ }
1578
+ interface AbiTraitDefinition {
1579
+ name: string;
1580
+ functions: ReadonlyArray<AbiTraitFunction>;
1581
+ }
1582
+ /** Full Clarity contract ABI including functions, maps, variables, and token definitions. */
1583
+ interface AbiContract {
1584
+ functions: ReadonlyArray<AbiFunction>;
1585
+ maps?: ReadonlyArray<AbiMap>;
1586
+ variables?: ReadonlyArray<AbiVariable>;
1587
+ fungible_tokens?: ReadonlyArray<AbiFungibleToken>;
1588
+ non_fungible_tokens?: ReadonlyArray<AbiNonFungibleToken>;
1589
+ implemented_traits?: ReadonlyArray<string>;
1590
+ defined_traits?: ReadonlyArray<AbiTraitDefinition>;
1591
+ }
1592
+ /**
1593
+ * `<contract>::<asset-name>` — the shape a fungible/non-fungible asset filter
1594
+ * takes, expressed so the compiler can check it.
1595
+ *
1596
+ * The most common mistake in this API is passing a CONTRACT ID
1597
+ * (`SP….sbtc-token`) where an asset identifier (`SP….sbtc-token::sbtc-token`)
1598
+ * belongs, and the failure mode is a query that quietly returns zero rows. The
1599
+ * two differ structurally by `::`, so a template-literal type catches it at the
1600
+ * call site — no brand, no cast, literals just work.
1601
+ *
1602
+ * A value that is only known at runtime (config, env) is not narrow enough on
1603
+ * purpose; run it through {@link assetId} once, which validates and narrows.
1604
+ *
1605
+ * Wildcard patterns (Webhooks/Subgraphs-only) are admitted by the second arm — they
1606
+ * are legitimately not full identifiers (`SPB.*`), and the runtime validator
1607
+ * short-circuits on them for the same reason.
1608
+ */
1609
+ type AssetIdentifier = `${string}::${string}` | `${string}*${string}`;
1610
+ /** Scalar print field types (structural mirror of the subgraphs `ColumnType`). */
1611
+ type PrintScalarType = "uint" | "int" | "text" | "principal" | "boolean" | "timestamp" | "jsonb";
1612
+ /**
1613
+ * One declared print field — structural mirror of `PrintField` in
1614
+ * `@secondlayer/subgraphs`. Composite forms exist because real print payloads
1615
+ * nest: a vocabulary that could only say `"jsonb"` is what let a flat-field
1616
+ * declaration type-check while every event decoded to null.
1617
+ *
1618
+ * Kept literal through `toSubgraphSource()` so handler narrowing survives.
1619
+ */
1620
+ type PrintFieldType = PrintScalarType | {
1621
+ type: PrintFieldType
1622
+ optional: true
1623
+ } | {
1624
+ tuple: Record<string, PrintFieldType>
1625
+ } | {
1626
+ list: PrintFieldType
1627
+ };
1628
+ interface StxTransferSpec {
1629
+ type: "stx_transfer";
1630
+ sender?: string;
1631
+ recipient?: string;
1632
+ minAmount?: bigint;
1633
+ maxAmount?: bigint;
1634
+ }
1635
+ interface StxMintSpec {
1636
+ type: "stx_mint";
1637
+ recipient?: string;
1638
+ minAmount?: bigint;
1639
+ }
1640
+ interface StxBurnSpec {
1641
+ type: "stx_burn";
1642
+ sender?: string;
1643
+ minAmount?: bigint;
1644
+ }
1645
+ interface StxLockSpec {
1646
+ type: "stx_lock";
1647
+ lockedAddress?: string;
1648
+ minAmount?: bigint;
1649
+ }
1650
+ /** Scope to contracts conforming to a trait/standard (e.g. "sip-010") instead
1651
+ * of a fixed contract. Index + Subgraphs + Webhooks; Streams has no
1652
+ * trait resolution — `toStreamsParams()` throws if set. */
1653
+ type TraitScope = {
1654
+ trait?: string
1655
+ };
1656
+ /** Scope to a DYNAMIC address set discovered from another source's events —
1657
+ * a Subgraphs-only concept (`toSubgraphSource()` keeps it; every other
1658
+ * projection throws). Structural mirror of the subgraphs `FactoryScope`:
1659
+ * `stacks` is the dependency-graph leaf and cannot import it. */
1660
+ type FactoryScope = {
1661
+ factory?: {
1662
+ /** Source name whose events reveal the addresses. */
1663
+ from: string
1664
+ /** Dotted path to the address on that source's payload (e.g. "data.pool"). */
1665
+ field: string
1666
+ }
1667
+ };
1668
+ interface FtTransferSpec extends TraitScope {
1669
+ type: "ft_transfer";
1670
+ assetIdentifier?: AssetIdentifier;
1671
+ sender?: string;
1672
+ recipient?: string;
1673
+ minAmount?: bigint;
1674
+ }
1675
+ interface FtMintSpec extends TraitScope {
1676
+ type: "ft_mint";
1677
+ assetIdentifier?: AssetIdentifier;
1678
+ recipient?: string;
1679
+ minAmount?: bigint;
1680
+ }
1681
+ interface FtBurnSpec extends TraitScope {
1682
+ type: "ft_burn";
1683
+ assetIdentifier?: AssetIdentifier;
1684
+ sender?: string;
1685
+ minAmount?: bigint;
1686
+ }
1687
+ interface NftTransferSpec extends TraitScope {
1688
+ type: "nft_transfer";
1689
+ assetIdentifier?: AssetIdentifier;
1690
+ sender?: string;
1691
+ recipient?: string;
1692
+ }
1693
+ interface NftMintSpec extends TraitScope {
1694
+ type: "nft_mint";
1695
+ assetIdentifier?: AssetIdentifier;
1696
+ recipient?: string;
1697
+ }
1698
+ interface NftBurnSpec extends TraitScope {
1699
+ type: "nft_burn";
1700
+ assetIdentifier?: AssetIdentifier;
1701
+ sender?: string;
1702
+ }
1703
+ interface ContractCallSpec extends TraitScope, FactoryScope {
1704
+ type: "contract_call";
1705
+ /** One contract id, or a set of them (max 20). Mirrors the subgraphs
1706
+ * filter — a router plus its pools is one source, not N. */
1707
+ contractId?: string | readonly string[];
1708
+ functionName?: string;
1709
+ caller?: string;
1710
+ /** Contract ABI (`as const`) — preserved literally so `toSubgraphSource()`
1711
+ * keeps typing `event.input` in `defineSubgraph`. */
1712
+ abi?: AbiContract;
1713
+ }
1714
+ interface ContractDeploySpec {
1715
+ type: "contract_deploy";
1716
+ deployer?: string;
1717
+ contractName?: string;
1718
+ }
1719
+ interface NestedContractCallSpec extends TraitScope, FactoryScope {
1720
+ type: "nested_contract_call";
1721
+ contractId?: string | readonly string[];
1722
+ functionName?: string;
1723
+ caller?: string;
1724
+ sender?: string;
1725
+ }
1726
+ interface VarSetSpec extends TraitScope, FactoryScope {
1727
+ type: "var_set";
1728
+ contractId?: string | readonly string[];
1729
+ varName?: string;
1730
+ }
1731
+ interface MapSetSpec extends TraitScope, FactoryScope {
1732
+ type: "map_set";
1733
+ contractId?: string | readonly string[];
1734
+ map?: string;
1735
+ }
1736
+ interface MapInsertSpec extends TraitScope, FactoryScope {
1737
+ type: "map_insert";
1738
+ contractId?: string | readonly string[];
1739
+ map?: string;
1740
+ }
1741
+ interface MapDeleteSpec extends TraitScope, FactoryScope {
1742
+ type: "map_delete";
1743
+ contractId?: string | readonly string[];
1744
+ map?: string;
1745
+ }
1746
+ interface PrintEventSpec extends TraitScope, FactoryScope {
1747
+ type: "print_event";
1748
+ /** One contract id, or a set of them (max 20). */
1749
+ contractId?: string | readonly string[];
1750
+ topic?: string;
1751
+ /** Per-topic field schema — preserved literally so `toSubgraphSource()`
1752
+ * keeps the discriminated-union narrowing of `event.data`. */
1753
+ prints?: Record<string, Record<string, PrintFieldType>>;
1754
+ }
1755
+ interface SbtcDepositSpec {
1756
+ type: "sbtc_deposit";
1757
+ sender?: string;
1758
+ minAmount?: bigint;
1759
+ maxAmount?: bigint;
1760
+ bitcoinTxid?: string;
1761
+ requestId?: number;
1762
+ }
1763
+ interface SbtcWithdrawalCreateSpec {
1764
+ type: "sbtc_withdrawal_create";
1765
+ sender?: string;
1766
+ minAmount?: bigint;
1767
+ maxAmount?: bigint;
1768
+ requestId?: number;
1769
+ }
1770
+ interface SbtcWithdrawalAcceptSpec {
1771
+ type: "sbtc_withdrawal_accept";
1772
+ requestId?: number;
1773
+ sweepTxid?: string;
1774
+ }
1775
+ interface SbtcWithdrawalRejectSpec {
1776
+ type: "sbtc_withdrawal_reject";
1777
+ requestId?: number;
1778
+ }
1779
+ interface SbtcWithdrawalSweptConfirmedSpec {
1780
+ type: "sbtc_withdrawal_swept_confirmed";
1781
+ requestId?: number;
1782
+ sweepTxid?: string;
1783
+ }
1784
+ type ChainEventFilterSpec = StxTransferSpec | StxMintSpec | StxBurnSpec | StxLockSpec | FtTransferSpec | FtMintSpec | FtBurnSpec | NftTransferSpec | NftMintSpec | NftBurnSpec | ContractCallSpec | ContractDeploySpec | NestedContractCallSpec | VarSetSpec | MapSetSpec | MapInsertSpec | MapDeleteSpec | PrintEventSpec | SbtcDepositSpec | SbtcWithdrawalCreateSpec | SbtcWithdrawalAcceptSpec | SbtcWithdrawalRejectSpec | SbtcWithdrawalSweptConfirmedSpec;
1785
+ type SpecFor<T extends ChainEventFilterType> = Extract<ChainEventFilterSpec, {
1786
+ type: T
1787
+ }>;
1788
+ /** Wire shape of a chain trigger (Webhooks), derived per member from
1789
+ * the spec: same fields, with `bigint` amounts stringified (uint128 exceeds
1790
+ * JS safe integers) and the type-only `abi`/`prints` decorations dropped.
1791
+ * Structurally assignable to the SDK's `ChainTrigger` union. */
1792
+ type ChainTriggerOf<S> = { [K in keyof Omit<S, "abi" | "prints" | "factory">] : Exclude<S[K], bigint | readonly string[]> | (bigint extends S[K] ? string : never) };
1793
+ /** Params fragment for `index.events.*` (spread into list/walk/consume). */
1794
+ type IndexEventsParamsShape = {
1795
+ eventType: DecodedEventType | VmEventType
1796
+ /** A spec's contract set passes through verbatim (the API takes up to 20). */
1797
+ contractId?: string | readonly string[]
1798
+ assetIdentifier?: AssetIdentifier
1799
+ sender?: string
1800
+ recipient?: string
1801
+ functionName?: string
1802
+ caller?: string
1803
+ map?: string
1804
+ varName?: string
1805
+ trait?: string
1806
+ };
1807
+ /** Params fragment for `index.contractCalls.*`. */
1808
+ type ContractCallsParamsShape = {
1809
+ /** A spec's contract set passes through verbatim (the API takes up to 20). */
1810
+ contractId?: string | readonly string[]
1811
+ functionName?: string
1812
+ /** Populated from the spec's `caller` — the endpoint filters by tx sender,
1813
+ * which is the caller. */
1814
+ sender?: string
1815
+ trait?: string
1736
1816
  };
1737
- /**
1738
- * Redis-backed nonce store. The atomic reserve lives in a Lua `EVAL`, so it is
1739
- * safe across processes sharing one Redis. The confirmed floor (`getFloor`) is
1740
- * read only once per key, on cold start.
1741
- */
1742
- declare function redisStore(params: RedisStoreParams): NonceStore;
1743
- /** Minimal structural shape of a `Bun.sql` tagged-template client. */
1744
- type SqlLike = (strings: TemplateStringsArray, ...values: unknown[]) => Promise<Array<Record<string, unknown>>>;
1745
- type PostgresStoreParams = {
1746
- sql: SqlLike
1747
- /**
1748
- * Run `CREATE TABLE IF NOT EXISTS stacks_nonce_state` lazily on first use.
1749
- * Default `true`. Set `false` if you manage the schema via migrations.
1750
- */
1751
- ensureTable?: boolean
1817
+ type VmMember = "nested_contract_call" | "var_set" | "map_set" | "map_insert" | "map_delete";
1818
+ /** Params fragment for classic `streams.events.*` (Streams 1.0). VM members
1819
+ * project to {@link StreamsVmParamsShape} instead — mixing the vocabularies
1820
+ * here makes `events.consume({ ...on.ftTransfer().toStreamsParams(), onBatch })`
1821
+ * fail type-check. */
1822
+ type StreamsParamsShape = {
1823
+ types: readonly DecodedEventType[]
1824
+ contractId?: string | readonly string[]
1825
+ sender?: string
1826
+ recipient?: string
1827
+ assetIdentifier?: AssetIdentifier
1828
+ };
1829
+ /** VM member projection: `clock` is the `"vm"` literal so SDK overload 1 matches. */
1830
+ type StreamsVmParamsShape<T extends VmMember = VmMember> = {
1831
+ types: readonly [T]
1832
+ clock: "vm"
1833
+ contractId?: string | readonly string[]
1752
1834
  };
1835
+ type DecodedMember = "stx_transfer" | "stx_mint" | "stx_burn" | "stx_lock" | "ft_transfer" | "ft_mint" | "ft_burn" | "nft_transfer" | "nft_mint" | "nft_burn" | "print_event";
1836
+ type ProjectionsFor<
1837
+ T extends ChainEventFilterType,
1838
+ S
1839
+ > = {
1840
+ /** Wire trigger for `webhooks.create({ triggers: [...] })`. BigInt
1841
+ * amounts become strings here — the one sanctioned boundary. */
1842
+ toChainTrigger(): ChainTriggerOf<S>
1843
+ } & (T extends DecodedMember | VmMember ? {
1844
+ /** Params for `index.events.list/walk/consume` (merge your own
1845
+ * `limit`/`fromHeight`/`txContext` etc. on top). */
1846
+ toIndexParams<Extra extends Record<string, unknown>>(extra?: Extra): IndexEventsParamsShape & Extra
1847
+ /** Params for `streams.events.list/consume/stream`. Throws if the
1848
+ * filter uses `trait` (Streams has no trait resolution) or a
1849
+ * min/max amount (Streams filters have no amount predicates). */
1850
+ toStreamsParams<Extra extends Record<string, unknown> = Record<string, never>>(extra?: Extra): T extends VmMember ? StreamsVmParamsShape<T> & Extra : StreamsParamsShape & Extra
1851
+ } : {}) & (T extends "contract_call" ? {
1852
+ /** Params for `index.contractCalls.list/walk/consume`. */
1853
+ toContractCallsParams<Extra extends Record<string, unknown>>(extra?: Extra): ContractCallsParamsShape & Extra
1854
+ } : {}) & (T extends Exclude<ChainEventFilterType, `sbtc_${string}`> ? {
1855
+ /** The `sources` entry for `defineSubgraph` — literal `prints`/`abi`
1856
+ * types are preserved, so handler narrowing survives. */
1857
+ toSubgraphSource(): S
1858
+ } : {});
1753
1859
  /**
1754
- * Postgres-backed nonce store. Each reserve is a single atomic statement under
1755
- * a row lock, so concurrent reservers on the same key serialize and never
1756
- * collide across processes. State is durable — survives restarts.
1757
- *
1758
- * Uses a fixed table `stacks_nonce_state (key text primary key, next numeric)`.
1860
+ * A canonical chain-event filter: the spec fields plus the projections its
1861
+ * member supports. Write the filter once; project it to a query
1862
+ * (`toIndexParams`), a stream (`toStreamsParams`), a webhook trigger
1863
+ * (`toChainTrigger`), or a subgraph source (`toSubgraphSource`).
1759
1864
  */
1760
- declare function postgresStore(params: PostgresStoreParams): NonceStore;
1865
+ type ChainEventFilter<
1866
+ T extends ChainEventFilterType = ChainEventFilterType,
1867
+ S extends {
1868
+ type: T
1869
+ } = SpecFor<T>
1870
+ > = S & ProjectionsFor<T, S>;
1871
+ type Fields<T extends ChainEventFilterType> = Omit<SpecFor<T>, "type">;
1872
+ /** The `on.*` namespace, annotated explicitly — bunup's dts emitter needs an
1873
+ * annotation on exported values (an inferred object of generic factories
1874
+ * collapses to `{}` in the emitted declarations). */
1875
+ interface OnNamespace {
1876
+ stxTransfer(fields?: Fields<"stx_transfer">): ChainEventFilter<"stx_transfer">;
1877
+ stxMint(fields?: Fields<"stx_mint">): ChainEventFilter<"stx_mint">;
1878
+ stxBurn(fields?: Fields<"stx_burn">): ChainEventFilter<"stx_burn">;
1879
+ stxLock(fields?: Fields<"stx_lock">): ChainEventFilter<"stx_lock">;
1880
+ ftTransfer(fields?: Fields<"ft_transfer">): ChainEventFilter<"ft_transfer">;
1881
+ ftMint(fields?: Fields<"ft_mint">): ChainEventFilter<"ft_mint">;
1882
+ ftBurn(fields?: Fields<"ft_burn">): ChainEventFilter<"ft_burn">;
1883
+ nftTransfer(fields?: Fields<"nft_transfer">): ChainEventFilter<"nft_transfer">;
1884
+ nftMint(fields?: Fields<"nft_mint">): ChainEventFilter<"nft_mint">;
1885
+ nftBurn(fields?: Fields<"nft_burn">): ChainEventFilter<"nft_burn">;
1886
+ /** `abi` literals are preserved (`const A`) so `toSubgraphSource()` keeps
1887
+ * typing `event.input` inside `defineSubgraph`. */
1888
+ contractCall<const A extends AbiContract | undefined = undefined>(fields?: Omit<SpecFor<"contract_call">, "type" | "abi"> & {
1889
+ abi?: A
1890
+ }): ChainEventFilter<"contract_call", {
1891
+ type: "contract_call"
1892
+ } & Omit<SpecFor<"contract_call">, "type" | "abi"> & {
1893
+ abi?: A
1894
+ }>;
1895
+ contractDeploy(fields?: Fields<"contract_deploy">): ChainEventFilter<"contract_deploy">;
1896
+ /** Canonical member is `print_event` (as Subgraphs and Webhooks spell
1897
+ * it); `toIndexParams`/`toStreamsParams` project to `print`. `prints`
1898
+ * literals are preserved (`const P`) for per-topic `event.data` narrowing. */
1899
+ print<const P extends Record<string, Record<string, PrintFieldType>> | undefined = undefined>(fields?: Omit<SpecFor<"print_event">, "type" | "prints"> & {
1900
+ prints?: P
1901
+ }): ChainEventFilter<"print_event", {
1902
+ type: "print_event"
1903
+ } & Omit<SpecFor<"print_event">, "type" | "prints"> & {
1904
+ prints?: P
1905
+ }>;
1906
+ nestedCall(fields?: Fields<"nested_contract_call">): ChainEventFilter<"nested_contract_call">;
1907
+ varSet(fields?: Fields<"var_set">): ChainEventFilter<"var_set">;
1908
+ mapSet(fields?: Fields<"map_set">): ChainEventFilter<"map_set">;
1909
+ mapInsert(fields?: Fields<"map_insert">): ChainEventFilter<"map_insert">;
1910
+ mapDelete(fields?: Fields<"map_delete">): ChainEventFilter<"map_delete">;
1911
+ sbtcDeposit(fields?: Fields<"sbtc_deposit">): ChainEventFilter<"sbtc_deposit">;
1912
+ sbtcWithdrawalCreate(fields?: Fields<"sbtc_withdrawal_create">): ChainEventFilter<"sbtc_withdrawal_create">;
1913
+ sbtcWithdrawalAccept(fields?: Fields<"sbtc_withdrawal_accept">): ChainEventFilter<"sbtc_withdrawal_accept">;
1914
+ sbtcWithdrawalReject(fields?: Fields<"sbtc_withdrawal_reject">): ChainEventFilter<"sbtc_withdrawal_reject">;
1915
+ sbtcWithdrawalSweptConfirmed(fields?: Fields<"sbtc_withdrawal_swept_confirmed">): ChainEventFilter<"sbtc_withdrawal_swept_confirmed">;
1916
+ }
1761
1917
  /**
1762
- * Mempool-aware {@link NonceManagerSource}s.
1918
+ * `on.*` — one filter vocabulary for every surface.
1763
1919
  *
1764
- * The default {@link jsonRpcSource} reads only the confirmed nonce, so a tx
1765
- * sitting in the mempool is invisible — broadcasting many quickly forces manual
1766
- * tracking. These sources fold pending (mempool) txs into the next-nonce
1767
- * computation. The gap-filling core is generic; where the pending set comes from
1768
- * is pluggable, so you are never locked to any one provider:
1920
+ * ```ts
1921
+ * import { on } from "@secondlayer/stacks/filters";
1769
1922
  *
1770
- * - {@link mempoolAwareSource} — bring your own `getPending`.
1771
- * - {@link indexSource}: prebuilt over a Secondlayer instance's `/v1/index/mempool`.
1772
- * - {@link hiroNonceSource} — prebuilt over Hiro's `/extended` nonces endpoint.
1773
- */
1774
- type FetchImpl = typeof globalThis.fetch;
1775
- /**
1776
- * The next free nonce ≥ `confirmed` not already taken by a pending tx.
1923
+ * const usdc = on.ftTransfer({ assetIdentifier: USDC, minAmount: 1_000_000n });
1777
1924
  *
1778
- * Unlike Hiro's `possible_next_nonce` (which is `max(pending) + 1` and strands
1779
- * higher txs when a lower nonce is missing), this FILLS gaps: it returns the
1780
- * lowest unused slot, so a dropped-tx hole is reused instead of stranding the
1781
- * chain.
1782
- */
1783
- declare function nextFreeNonce(confirmed: bigint, pending: bigint[]): bigint;
1784
- type MempoolAwareSourceParams = {
1785
- /** Pending (mempool) nonces for an address. */
1786
- getPending: (args: {
1787
- client: Client
1788
- address: string
1789
- }) => Promise<bigint[]>
1790
- /**
1791
- * Confirmed-nonce floor. Defaults to the node's `/v2/accounts` read — the
1792
- * user's own node via the client transport, no provider dependency.
1793
- */
1794
- getConfirmed?: (args: {
1795
- client: Client
1796
- address: string
1797
- }) => Promise<bigint>
1798
- };
1799
- /**
1800
- * Build a gap-filling, mempool-aware source from any `getPending`. The confirmed
1801
- * floor defaults to the node read; if `getPending` throws, the source degrades
1802
- * to confirmed-only rather than blocking a broadcast. A misconfigured pending
1803
- * feed ({@link IndexSourceConfigError}) is rethrown: it would fail on every
1804
- * read, and degrading silently would hide that the mempool is never consulted.
1805
- */
1806
- declare function mempoolAwareSource(params: MempoolAwareSourceParams): NonceManagerSource;
1807
- type IndexSourceParams = {
1808
- /**
1809
- * URL of your Secondlayer instance. Without it the client's transport
1810
- * URL is assumed to be the instance: a transport on a Hiro host throws
1811
- * up front, and a host that answers `/v1/index` with a non-JSON 404
1812
- * (a bare stacks-node) throws on the first read. Neither is degraded
1813
- * to the confirmed floor. Pass it whenever the transport is not the
1814
- * instance.
1815
- */
1816
- baseUrl?: string
1817
- /** Instance token, sent as `Authorization: Bearer`. */
1818
- apiKey?: string
1819
- /** Max mempool pages to read per address. Default 10 (×200 = 2000 txs). */
1820
- maxPages?: number
1821
- /** Override the confirmed floor (defaults to the node read). */
1822
- getConfirmed?: (args: {
1823
- client: Client
1824
- address: string
1825
- }) => Promise<bigint>
1826
- };
1827
- /**
1828
- * Mempool-aware source backed by a Secondlayer instance's `/v1/index/mempool`.
1829
- * Requests go through the transport layer (retries, timeout, typed errors).
1830
- * The instance's mempool is a go-forward view observed by its own node, so
1831
- * it can lag or miss transactions that node never saw; the manager's local
1832
- * increment still prevents same-process collisions. Past `maxPages` the
1833
- * pending set is truncated and the next free nonce may already be taken;
1834
- * a nonce conflict at broadcast then resets the manager. Transient failures
1835
- * (5xx, timeout) degrade to the confirmed floor; a missing or wrong instance
1836
- * URL throws so the misconfiguration is visible on the first read.
1837
- */
1838
- declare function indexSource(params?: IndexSourceParams): NonceManagerSource;
1839
- type HiroNonceSourceParams = {
1840
- /** Hiro API base URL, e.g. `https://api.hiro.so` or `https://api.testnet.hiro.so`. */
1841
- baseUrl: string
1842
- apiKey?: string
1843
- fetchImpl?: FetchImpl
1844
- };
1845
- /**
1846
- * Off-the-shelf, non-Secondlayer mempool-aware source over Hiro's
1847
- * `/extended/v1/address/{address}/nonces`. Fills the lowest detected gap first,
1848
- * then falls back to `possible_next_nonce`. Requires a host that serves Hiro's
1849
- * extended API (a bare stacks-node does not).
1850
- */
1851
- declare function hiroNonceSource(params: HiroNonceSourceParams): NonceManagerSource;
1852
- /**
1853
- * Create an HTTP transport for Stacks node RPC calls.
1854
- * Falls back to the chain's default RPC URL, then `localhost:3999`.
1855
- */
1856
- declare function http(url?: string, config?: TransportConfig): TransportFactory;
1857
- /** Create a transport backed by a user-provided request function. */
1858
- declare function custom(params: {
1859
- request: RequestFn
1860
- }): TransportFactory;
1861
- /** Create a transport that tries each transport in order until one succeeds. */
1862
- declare function fallback(transports: TransportFactory[]): TransportFactory;
1863
- /** Configuration for the WebSocket transport, extending base {@link TransportConfig}. */
1864
- type WebSocketTransportConfig = TransportConfig & {
1865
- /** WebSocket URL (resolved from chain if omitted) */
1866
- url?: string
1867
- /** Enable auto-reconnect (default: true) */
1868
- reconnect?: boolean
1869
- /** Max reconnect attempts (default: 10) */
1870
- reconnectMaxAttempts?: number
1871
- /** Base delay in ms for exponential backoff (default: 1000) */
1872
- reconnectBaseDelay?: number
1873
- };
1874
- /** Transport with WebSocket subscription capabilities and auto-reconnect. */
1875
- type WebSocketTransport = Transport & {
1876
- type: "webSocket"
1877
- subscribe: (params: WsSubscribeParams, callback: (data: any) => void) => Promise<Subscription>
1878
- destroy: () => void
1879
- };
1880
- /**
1881
- * Create a WebSocket transport for real-time Stacks event subscriptions.
1882
- * HTTP requests use the resolved RPC URL; subscriptions use the WS endpoint.
1925
+ * sl.index.events.list(usdc.toIndexParams({ limit: 100 })); // pull
1926
+ * sl.streams.events.consume({ ...usdc.toStreamsParams(), onBatch });
1927
+ * sl.webhooks.create({ name, url, triggers: [usdc.toChainTrigger()] });
1928
+ * defineSubgraph({ sources: { usdc: usdc.toSubgraphSource() }, schema, handlers });
1929
+ * ```
1930
+ *
1931
+ * A surface a member can't reach is a missing method (compile error), and a
1932
+ * field a surface can't express throws at projection time — never a silent
1933
+ * zero-row or over-wide match.
1883
1934
  */
1884
- declare function webSocket(url?: string, config?: WebSocketTransportConfig): TransportFactory;
1935
+ declare const on: OnNamespace;
1885
1936
  /** Create a ProviderAccount by querying the wallet for addresses */
1886
1937
  declare function providerToAccount(provider: StacksProvider): Promise<ProviderAccount>;
1887
1938
  /** Stacks mainnet chain definition (Hiro API). */
@@ -1991,4 +2042,4 @@ declare class ReadContractError extends BaseError {
1991
2042
  declare class WebSocketError extends BaseError {
1992
2043
  name: string;
1993
2044
  }
1994
- export { webSocket, walletActions, waitForTransactionReceipt2 as waitForTransactionReceipt, testnet, startNonceReconciler, resolveNonce, redisStore, reconcileNonce, publicActions, providerToAccount, postgresStore, parseStx, on, nextFreeNonce, multisigActions, mocknet, mempoolAwareSource, memoryStore, mainnet, jsonRpcSource, isValidAddress, isNonceConflictError, isAddressEqual, indexTxSource, indexSource, http, hiroNonceSource, getTransaction2 as getTransaction, getContractAddress, formatStx, fallback, extendedApiSource, devnet, defineChain, custom, createWalletClient, createPublicClient, createNonceManager, createMultiSigClient, createClient, broadcastWithNonceReset, ZERO_ADDRESS, WebSocketTransportConfig, WebSocketTransport, WebSocketError, WalletClientConfig, WalletClient, WalletActions, WaitForTransactionTimeoutError, WaitForTransactionReceiptParams, TxRejectionReason, TransportFactory, TransportConfig, Transport, TransactionStatusSource, TransactionStatus, TransactionSnapshot, TransactionReceipt, TransactionError, TransactionDroppedError, TransactionAbortedError, TimeoutError, TESTNET_ZERO_ADDRESS, Subscription, StartNonceReconcilerParams, StacksProvider, StacksChain, SqlLike, SimulationError, SigningError, SerializationError, RequestOptions, RequestFn, RedisStoreParams, RedisLike, ReconcileNonceResult, ReconcileNonceParams, ReadContractError, PublicClientConfig, PublicClient, PublicActions, ProviderAccount, PostgresStoreParams, NonceStore, NonceManagerSource, NonceManager, MultiSigClientConfig, MultiSigClient, MultiSigActions, MempoolAwareSourceParams, MalformedResponseError, MICROSTX_PER_STX, LocalAccount, IndexTxSourceParams, IndexSourceParams, IndexSourceConfigError, HttpRequestError, HiroNonceSourceParams, GetTransactionParams, CustomAccount, CreateNonceManagerParams, ClientConfig, Client, ChainTriggerOf, ChainEventFilterType, ChainEventFilterSpec, ChainEventFilter, BroadcastError, BaseError, AddressVersion, Account };
2045
+ export { Account, AddressVersion, BaseError, BroadcastError, ChainEventFilter, ChainEventFilterSpec, ChainEventFilterType, ChainTriggerOf, Client, ClientConfig, CreateNonceManagerParams, CustomAccount, GetTransactionParams, HiroNonceSourceParams, HttpRequestError, IndexSourceConfigError, IndexSourceParams, IndexTxSourceParams, LocalAccount, MICROSTX_PER_STX, MalformedResponseError, MempoolAwareSourceParams, MultiSigActions, MultiSigClient, MultiSigClientConfig, NonceManager, NonceManagerSource, NonceStore, PostgresStoreParams, ProviderAccount, PublicActions, PublicClient, PublicClientConfig, ReadContractError, ReconcileNonceParams, ReconcileNonceResult, RedisLike, RedisStoreParams, RequestFn, RequestOptions, SerializationError, SigningError, SimulationError, SqlLike, StacksChain, StacksProvider, StartNonceReconcilerParams, Subscription, TESTNET_ZERO_ADDRESS, TimeoutError, TransactionAbortedError, TransactionDroppedError, TransactionError, TransactionReceipt, TransactionSnapshot, TransactionStatus, TransactionStatusSource, Transport, TransportConfig, TransportFactory, TxRejectionReason, WaitForTransactionReceiptParams, WaitForTransactionTimeoutError, WalletActions, WalletClient, WalletClientConfig, WebSocketError, WebSocketTransport, WebSocketTransportConfig, ZERO_ADDRESS, broadcastWithNonceReset, createClient, createMultiSigClient, createNonceManager, createPublicClient, createWalletClient, custom, defineChain, devnet, extendedApiSource, fallback, formatStx, getContractAddress, getTransaction2 as getTransaction, hiroNonceSource, http, indexSource, indexTxSource, isAddressEqual, isNonceConflictError, isValidAddress, jsonRpcSource, mainnet, memoryStore, mempoolAwareSource, mocknet, multisigActions, nextFreeNonce, on, parseStx, postgresStore, providerToAccount, publicActions, reconcileNonce, redisStore, resolveNonce, startNonceReconciler, testnet, waitForTransactionReceipt2 as waitForTransactionReceipt, walletActions, webSocket };