@ryanrfox/sdk 0.0.2 → 2.0.3

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 (153) hide show
  1. package/README.md +145 -29
  2. package/package.json +84 -8
  3. package/src/_esm/actions/index.d.ts +8 -0
  4. package/src/_esm/actions/index.d.ts.map +1 -0
  5. package/src/_esm/actions/index.js +8 -0
  6. package/src/_esm/actions/index.js.map +1 -0
  7. package/src/_esm/actions/sendTransactionBatch.d.ts +77 -0
  8. package/src/_esm/actions/sendTransactionBatch.d.ts.map +1 -0
  9. package/src/_esm/actions/sendTransactionBatch.js +245 -0
  10. package/src/_esm/actions/sendTransactionBatch.js.map +1 -0
  11. package/src/_esm/chains/chainConfig.d.ts +30 -0
  12. package/src/_esm/chains/chainConfig.d.ts.map +1 -0
  13. package/src/_esm/chains/chainConfig.js +30 -0
  14. package/src/_esm/chains/chainConfig.js.map +1 -0
  15. package/src/_esm/chains/index.d.ts +4 -0
  16. package/src/_esm/chains/index.d.ts.map +1 -0
  17. package/src/_esm/chains/index.js +4 -0
  18. package/src/_esm/chains/index.js.map +1 -0
  19. package/src/_esm/chains/radius.d.ts +64 -0
  20. package/src/_esm/chains/radius.d.ts.map +1 -0
  21. package/src/_esm/chains/radius.js +39 -0
  22. package/src/_esm/chains/radius.js.map +1 -0
  23. package/src/_esm/chains/radiusTestnet.d.ts +61 -0
  24. package/src/_esm/chains/radiusTestnet.d.ts.map +1 -0
  25. package/src/_esm/chains/radiusTestnet.js +45 -0
  26. package/src/_esm/chains/radiusTestnet.js.map +1 -0
  27. package/src/_esm/decorators/index.d.ts +8 -0
  28. package/src/_esm/decorators/index.d.ts.map +1 -0
  29. package/src/_esm/decorators/index.js +8 -0
  30. package/src/_esm/decorators/index.js.map +1 -0
  31. package/src/_esm/decorators/radius.d.ts +66 -0
  32. package/src/_esm/decorators/radius.d.ts.map +1 -0
  33. package/src/_esm/decorators/radius.js +36 -0
  34. package/src/_esm/decorators/radius.js.map +1 -0
  35. package/src/_esm/errors/account.d.ts +78 -0
  36. package/src/_esm/errors/account.d.ts.map +1 -0
  37. package/src/_esm/errors/account.js +97 -0
  38. package/src/_esm/errors/account.js.map +1 -0
  39. package/src/_esm/errors/base.d.ts +56 -0
  40. package/src/_esm/errors/base.d.ts.map +1 -0
  41. package/src/_esm/errors/base.js +51 -0
  42. package/src/_esm/errors/base.js.map +1 -0
  43. package/src/_esm/errors/contract.d.ts +51 -0
  44. package/src/_esm/errors/contract.d.ts.map +1 -0
  45. package/src/_esm/errors/contract.js +65 -0
  46. package/src/_esm/errors/contract.js.map +1 -0
  47. package/src/_esm/errors/index.d.ts +63 -0
  48. package/src/_esm/errors/index.d.ts.map +1 -0
  49. package/src/_esm/errors/index.js +40 -0
  50. package/src/_esm/errors/index.js.map +1 -0
  51. package/src/_esm/errors/transaction.d.ts +132 -0
  52. package/src/_esm/errors/transaction.d.ts.map +1 -0
  53. package/src/_esm/errors/transaction.js +143 -0
  54. package/src/_esm/errors/transaction.js.map +1 -0
  55. package/src/_esm/events/decodeEventLogs.d.ts +136 -0
  56. package/src/_esm/events/decodeEventLogs.d.ts.map +1 -0
  57. package/src/_esm/events/decodeEventLogs.js +93 -0
  58. package/src/_esm/events/decodeEventLogs.js.map +1 -0
  59. package/src/_esm/events/getLogs.d.ts +137 -0
  60. package/src/_esm/events/getLogs.d.ts.map +1 -0
  61. package/src/_esm/events/getLogs.js +171 -0
  62. package/src/_esm/events/getLogs.js.map +1 -0
  63. package/src/_esm/events/index.d.ts +17 -0
  64. package/src/_esm/events/index.d.ts.map +1 -0
  65. package/src/_esm/events/index.js +24 -0
  66. package/src/_esm/events/index.js.map +1 -0
  67. package/src/_esm/events/watchApproval.d.ts +184 -0
  68. package/src/_esm/events/watchApproval.d.ts.map +1 -0
  69. package/src/_esm/events/watchApproval.js +254 -0
  70. package/src/_esm/events/watchApproval.js.map +1 -0
  71. package/src/_esm/events/watchBlock.d.ts +192 -0
  72. package/src/_esm/events/watchBlock.d.ts.map +1 -0
  73. package/src/_esm/events/watchBlock.js +162 -0
  74. package/src/_esm/events/watchBlock.js.map +1 -0
  75. package/src/_esm/events/watchLogs.d.ts +128 -0
  76. package/src/_esm/events/watchLogs.d.ts.map +1 -0
  77. package/src/_esm/events/watchLogs.js +100 -0
  78. package/src/_esm/events/watchLogs.js.map +1 -0
  79. package/src/_esm/events/watchTransfer.d.ts +164 -0
  80. package/src/_esm/events/watchTransfer.d.ts.map +1 -0
  81. package/src/_esm/events/watchTransfer.js +234 -0
  82. package/src/_esm/events/watchTransfer.js.map +1 -0
  83. package/src/_esm/index.d.ts +16 -0
  84. package/src/_esm/index.d.ts.map +1 -0
  85. package/src/_esm/index.js +22 -0
  86. package/src/_esm/index.js.map +1 -0
  87. package/src/_esm/package.json +1 -0
  88. package/src/_esm/transport/index.d.ts +9 -0
  89. package/src/_esm/transport/index.d.ts.map +1 -0
  90. package/src/_esm/transport/index.js +9 -0
  91. package/src/_esm/transport/index.js.map +1 -0
  92. package/src/_esm/transport/interceptor.d.ts +48 -0
  93. package/src/_esm/transport/interceptor.d.ts.map +1 -0
  94. package/src/_esm/transport/interceptor.js +209 -0
  95. package/src/_esm/transport/interceptor.js.map +1 -0
  96. package/src/_esm/transport/types.d.ts +29 -0
  97. package/src/_esm/transport/types.d.ts.map +1 -0
  98. package/src/_esm/transport/types.js +2 -0
  99. package/src/_esm/transport/types.js.map +1 -0
  100. package/src/_esm/transport/websocket.d.ts +51 -0
  101. package/src/_esm/transport/websocket.d.ts.map +1 -0
  102. package/src/_esm/transport/websocket.js +70 -0
  103. package/src/_esm/transport/websocket.js.map +1 -0
  104. package/src/_types/actions/index.d.ts +8 -0
  105. package/src/_types/actions/index.d.ts.map +1 -0
  106. package/src/_types/actions/sendTransactionBatch.d.ts +77 -0
  107. package/src/_types/actions/sendTransactionBatch.d.ts.map +1 -0
  108. package/src/_types/chains/chainConfig.d.ts +30 -0
  109. package/src/_types/chains/chainConfig.d.ts.map +1 -0
  110. package/src/_types/chains/index.d.ts +4 -0
  111. package/src/_types/chains/index.d.ts.map +1 -0
  112. package/src/_types/chains/radius.d.ts +64 -0
  113. package/src/_types/chains/radius.d.ts.map +1 -0
  114. package/src/_types/chains/radiusTestnet.d.ts +61 -0
  115. package/src/_types/chains/radiusTestnet.d.ts.map +1 -0
  116. package/src/_types/decorators/index.d.ts +8 -0
  117. package/src/_types/decorators/index.d.ts.map +1 -0
  118. package/src/_types/decorators/radius.d.ts +66 -0
  119. package/src/_types/decorators/radius.d.ts.map +1 -0
  120. package/src/_types/errors/account.d.ts +78 -0
  121. package/src/_types/errors/account.d.ts.map +1 -0
  122. package/src/_types/errors/base.d.ts +56 -0
  123. package/src/_types/errors/base.d.ts.map +1 -0
  124. package/src/_types/errors/contract.d.ts +51 -0
  125. package/src/_types/errors/contract.d.ts.map +1 -0
  126. package/src/_types/errors/index.d.ts +63 -0
  127. package/src/_types/errors/index.d.ts.map +1 -0
  128. package/src/_types/errors/transaction.d.ts +132 -0
  129. package/src/_types/errors/transaction.d.ts.map +1 -0
  130. package/src/_types/events/decodeEventLogs.d.ts +136 -0
  131. package/src/_types/events/decodeEventLogs.d.ts.map +1 -0
  132. package/src/_types/events/getLogs.d.ts +137 -0
  133. package/src/_types/events/getLogs.d.ts.map +1 -0
  134. package/src/_types/events/index.d.ts +17 -0
  135. package/src/_types/events/index.d.ts.map +1 -0
  136. package/src/_types/events/watchApproval.d.ts +184 -0
  137. package/src/_types/events/watchApproval.d.ts.map +1 -0
  138. package/src/_types/events/watchBlock.d.ts +192 -0
  139. package/src/_types/events/watchBlock.d.ts.map +1 -0
  140. package/src/_types/events/watchLogs.d.ts +128 -0
  141. package/src/_types/events/watchLogs.d.ts.map +1 -0
  142. package/src/_types/events/watchTransfer.d.ts +164 -0
  143. package/src/_types/events/watchTransfer.d.ts.map +1 -0
  144. package/src/_types/index.d.ts +16 -0
  145. package/src/_types/index.d.ts.map +1 -0
  146. package/src/_types/transport/index.d.ts +9 -0
  147. package/src/_types/transport/index.d.ts.map +1 -0
  148. package/src/_types/transport/interceptor.d.ts +48 -0
  149. package/src/_types/transport/interceptor.d.ts.map +1 -0
  150. package/src/_types/transport/types.d.ts +29 -0
  151. package/src/_types/transport/types.d.ts.map +1 -0
  152. package/src/_types/transport/websocket.d.ts +51 -0
  153. package/src/_types/transport/websocket.d.ts.map +1 -0
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Default polling interval for block watching in milliseconds.
3
+ * Used when polling is required (e.g., HTTP transport fallback).
4
+ * Can be overridden per watch call via pollingInterval parameter.
5
+ */
6
+ export const DEFAULT_POLLING_INTERVAL_MS = 1000;
7
+ /**
8
+ * Watches for new block numbers.
9
+ * Uses WebSocket subscriptions when available, falls back to polling for HTTP transport.
10
+ *
11
+ * @param client - The PublicClient to use
12
+ * @param params - Block number watching parameters
13
+ * @returns An unwatch function to stop watching
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { createPublicClient } from 'viem';
18
+ * import { createWebSocketTransport, watchBlockNumber } from '@radiustechsystems/sdk/events';
19
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
20
+ *
21
+ * const client = createPublicClient({
22
+ * chain: radiusTestnet,
23
+ * transport: createWebSocketTransport(radiusTestnet),
24
+ * });
25
+ *
26
+ * // Watch for new blocks
27
+ * const unwatch = watchBlockNumber(client, {
28
+ * onBlockNumber: (blockNumber) => {
29
+ * console.log('New block:', blockNumber);
30
+ * },
31
+ * onError: (error) => {
32
+ * console.error('Error:', error);
33
+ * },
34
+ * });
35
+ *
36
+ * // Stop watching
37
+ * unwatch();
38
+ * ```
39
+ *
40
+ * @remarks
41
+ * - WebSocket transport provides real-time block notifications
42
+ * - HTTP transport falls back to polling (default 1s interval)
43
+ * - Radius does not support eth_newBlockFilter (traditional filter API)
44
+ * - WebSocket subscriptions are more efficient than polling
45
+ * - For HTTP clients, consider increasing pollingInterval to reduce load
46
+ */
47
+ export function watchBlockNumber(client, params) {
48
+ const watchParams = {
49
+ onBlockNumber: params.onBlockNumber,
50
+ onError: params.onError,
51
+ emitOnBegin: params.emitOnBegin,
52
+ pollingInterval: params.pollingInterval ?? DEFAULT_POLLING_INTERVAL_MS,
53
+ };
54
+ return client.watchBlockNumber(watchParams);
55
+ }
56
+ /**
57
+ * Watches for new blocks with full block data.
58
+ * Uses WebSocket subscriptions when available, falls back to polling for HTTP transport.
59
+ *
60
+ * @param client - The PublicClient to use
61
+ * @param params - Block watching parameters
62
+ * @returns An unwatch function to stop watching
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * import { createPublicClient } from 'viem';
67
+ * import { createWebSocketTransport, watchBlocks } from '@radiustechsystems/sdk/events';
68
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
69
+ *
70
+ * const client = createPublicClient({
71
+ * chain: radiusTestnet,
72
+ * transport: createWebSocketTransport(radiusTestnet),
73
+ * });
74
+ *
75
+ * // Watch for new blocks
76
+ * const unwatch = watchBlocks(client, {
77
+ * onBlock: (block) => {
78
+ * console.log('New block:', block.number);
79
+ * console.log('Timestamp:', block.timestamp);
80
+ * console.log('Transactions:', block.transactions.length);
81
+ * },
82
+ * });
83
+ *
84
+ * // Watch blocks with full transaction data
85
+ * const unwatchWithTxs = watchBlocks(client, {
86
+ * includeTransactions: true,
87
+ * onBlock: (block) => {
88
+ * console.log('New block with', block.transactions.length, 'transactions');
89
+ * // block.transactions contains full transaction objects
90
+ * },
91
+ * });
92
+ *
93
+ * // Stop watching
94
+ * unwatch();
95
+ * ```
96
+ *
97
+ * @remarks
98
+ * - WebSocket transport provides real-time block notifications
99
+ * - HTTP transport falls back to polling (default 1s interval)
100
+ * - includeTransactions=true fetches full transaction data (slower)
101
+ * - includeTransactions=false only includes transaction hashes (faster, default)
102
+ * - WebSocket is recommended for real-time block monitoring
103
+ * - Polling with includeTransactions=true can be expensive
104
+ */
105
+ export function watchBlocks(client, params) {
106
+ // Only pass includeTransactions if explicitly set to true
107
+ const watchParams = {
108
+ onBlock: params.onBlock,
109
+ onError: params.onError,
110
+ emitOnBegin: params.emitOnBegin,
111
+ pollingInterval: params.pollingInterval ?? DEFAULT_POLLING_INTERVAL_MS,
112
+ };
113
+ // Type assertion needed because viem's type is very strict about false vs undefined
114
+ if (params.includeTransactions === true) {
115
+ watchParams.includeTransactions = true;
116
+ }
117
+ return client.watchBlocks(watchParams);
118
+ }
119
+ /**
120
+ * Watches for pending transactions in the mempool.
121
+ *
122
+ * @param client - The PublicClient to use
123
+ * @param params - Pending transaction watching parameters
124
+ * @returns An unwatch function to stop watching
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { createPublicClient } from 'viem';
129
+ * import { createWebSocketTransport, watchPendingTransactions } from '@radiustechsystems/sdk/events';
130
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
131
+ *
132
+ * const client = createPublicClient({
133
+ * chain: radiusTestnet,
134
+ * transport: createWebSocketTransport(radiusTestnet),
135
+ * });
136
+ *
137
+ * // Watch for pending transactions
138
+ * const unwatch = watchPendingTransactions(client, {
139
+ * onTransactions: (hashes) => {
140
+ * console.log('New pending transactions:', hashes);
141
+ * },
142
+ * });
143
+ *
144
+ * // Stop watching
145
+ * unwatch();
146
+ * ```
147
+ *
148
+ * @remarks
149
+ * - LIMITATION: Radius does not support eth_newPendingTransactionFilter
150
+ * - This function may not work as expected on Radius
151
+ * - WebSocket transport with "pendingTransactions" subscription is not supported
152
+ * - Consider using block watching and filtering confirmed transactions instead
153
+ * - This is provided for API completeness but may have limited functionality
154
+ */
155
+ export function watchPendingTransactions(client, params) {
156
+ return client.watchPendingTransactions({
157
+ onTransactions: params.onTransactions,
158
+ onError: params.onError,
159
+ pollingInterval: params.pollingInterval,
160
+ });
161
+ }
162
+ //# sourceMappingURL=watchBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchBlock.js","sourceRoot":"","sources":["../../events/watchBlock.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAgBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB,EAAE,MAA8B;IACpF,MAAM,WAAW,GAA+B;QAC/C,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,2BAA2B;KACtE,CAAC;IAEF,OAAO,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;AAC7C,CAAC;AAkBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,WAAW,CAAC,MAAoB,EAAE,MAAyB;IAC1E,0DAA0D;IAC1D,MAAM,WAAW,GAA0B;QAC1C,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,2BAA2B;KACtE,CAAC;IAEF,oFAAoF;IACpF,IAAI,MAAM,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;QACxC,WAAiD,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAC/E,CAAC;IAED,OAAO,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;AACxC,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,wBAAwB,CACvC,MAAoB,EACpB,MAAsC;IAEtC,OAAO,MAAM,CAAC,wBAAwB,CAAC;QACtC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,eAAe,EAAE,MAAM,CAAC,eAAe;KACvC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Generic log watching utilities for Radius SDK.
3
+ * Provides real-time event subscription capabilities using WebSocket.
4
+ *
5
+ * @remarks Radius-Specific Limitations and Requirements
6
+ *
7
+ * **WebSocket Subscriptions (eth_subscribe)**:
8
+ * - BOTH address AND topics are mandatory when using `eth_subscribe` with "logs" type
9
+ * - Partial filtering (address-only or topics-only) may not work as expected
10
+ * - Currently supported only via WebSocket transport (not HTTP)
11
+ * - WebSocket is NOT currently enabled on Radius testnet
12
+ *
13
+ * **Recommended Approach**:
14
+ * - For now, use HTTP polling with eth_getLogs (see watchLogs and watchRawLogs functions)
15
+ * - HTTP polling is the most reliable approach until WebSocket is enabled
16
+ * - When WebSocket becomes available on testnet, these functions can leverage native subscriptions
17
+ *
18
+ * **Important Note**:
19
+ * - The address parameter is mandatory in all log filters on Radius
20
+ * - Filters without address will fail with error "Filters without addresses are not supported"
21
+ */
22
+ import type { Address, Hash, Log, PublicClient, WatchContractEventReturnType } from 'viem';
23
+ import { watchContractEvent } from 'viem/actions';
24
+ /**
25
+ * Watches for contract events in real-time using WebSocket subscriptions.
26
+ * Uses viem's watchContractEvent under the hood, which leverages eth_subscribe for "logs".
27
+ *
28
+ * @param client - The PublicClient to use (must be configured with WebSocket transport)
29
+ * @param params - Event watching parameters including address, ABI, event name, and callback
30
+ * @returns An unwatch function to stop the subscription
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { createPublicClient } from 'viem';
35
+ * import { createWebSocketTransport, watchLogs } from '@radiustechsystems/sdk/events';
36
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
37
+ *
38
+ * // Create client with WebSocket transport
39
+ * const client = createPublicClient({
40
+ * chain: radiusTestnet,
41
+ * transport: createWebSocketTransport(radiusTestnet),
42
+ * });
43
+ *
44
+ * // Watch for events
45
+ * const unwatch = watchLogs(client, {
46
+ * address: '0x...',
47
+ * abi: contractAbi,
48
+ * eventName: 'Transfer',
49
+ * onLogs: (logs) => {
50
+ * console.log('Transfer events:', logs);
51
+ * },
52
+ * });
53
+ *
54
+ * // Stop watching
55
+ * unwatch();
56
+ * ```
57
+ *
58
+ * @remarks
59
+ * - Requires WebSocket transport for real-time subscriptions
60
+ * - Radius supports eth_subscribe with type "logs" only
61
+ * - Address parameter is mandatory on Radius
62
+ * - Subscriptions consume gas from your RPC key (10 GAS/sec)
63
+ * - Automatically cleaned up on disconnect
64
+ * - For HTTP transport, consider using getLogs with polling instead
65
+ */
66
+ export declare function watchLogs(client: PublicClient, params: Parameters<typeof watchContractEvent>[1]): WatchContractEventReturnType;
67
+ /**
68
+ * Parameters for watching raw logs without ABI decoding.
69
+ */
70
+ export interface WatchRawLogsParameters {
71
+ /** The contract address to watch */
72
+ address: Address | Address[];
73
+ /** Optional event signature hashes to filter by */
74
+ topics?: Hash[][];
75
+ /** Callback function invoked when logs are received */
76
+ onLogs: (logs: Log[]) => void;
77
+ /** Callback function invoked when an error occurs */
78
+ onError?: (error: Error) => void;
79
+ /** Whether to emit logs from the latest block on subscription start */
80
+ sync?: boolean;
81
+ /** Polling interval in milliseconds (for HTTP transport fallback) */
82
+ pollingInterval?: number;
83
+ }
84
+ /**
85
+ * Watches for raw logs without ABI decoding.
86
+ * Useful when you want to receive raw log data or watch multiple event types.
87
+ *
88
+ * @param client - The PublicClient to use (WebSocket transport recommended)
89
+ * @param params - Raw log watching parameters
90
+ * @returns An unwatch function to stop the subscription
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { createPublicClient } from 'viem';
95
+ * import { createWebSocketTransport, watchRawLogs } from '@radiustechsystems/sdk/events';
96
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
97
+ *
98
+ * const client = createPublicClient({
99
+ * chain: radiusTestnet,
100
+ * transport: createWebSocketTransport(radiusTestnet),
101
+ * });
102
+ *
103
+ * // Watch for all events from a contract
104
+ * const unwatch = watchRawLogs(client, {
105
+ * address: '0x...',
106
+ * onLogs: (logs) => {
107
+ * logs.forEach(log => {
108
+ * console.log('Log:', log.topics, log.data);
109
+ * });
110
+ * },
111
+ * onError: (error) => {
112
+ * console.error('Subscription error:', error);
113
+ * },
114
+ * });
115
+ *
116
+ * // Stop watching
117
+ * unwatch();
118
+ * ```
119
+ *
120
+ * @remarks
121
+ * - Does not decode log data; returns raw topics and data
122
+ * - Useful for monitoring multiple event types from same contract
123
+ * - Requires address parameter (mandatory on Radius)
124
+ * - WebSocket transport provides real-time updates
125
+ * - HTTP transport falls back to polling (less efficient)
126
+ */
127
+ export declare function watchRawLogs(client: PublicClient, params: WatchRawLogsParameters): WatchContractEventReturnType;
128
+ //# sourceMappingURL=watchLogs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchLogs.d.ts","sourceRoot":"","sources":["../../events/watchLogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,MAAM,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAC9C,4BAA4B,CAE9B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,oCAAoC;IACpC,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAC7B,mDAAmD;IACnD,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;IAClB,uDAAuD;IACvD,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,qDAAqD;IACrD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,uEAAuE;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,sBAAsB,GAC5B,4BAA4B,CAS9B"}
@@ -0,0 +1,100 @@
1
+ import { watchContractEvent } from 'viem/actions';
2
+ /**
3
+ * Watches for contract events in real-time using WebSocket subscriptions.
4
+ * Uses viem's watchContractEvent under the hood, which leverages eth_subscribe for "logs".
5
+ *
6
+ * @param client - The PublicClient to use (must be configured with WebSocket transport)
7
+ * @param params - Event watching parameters including address, ABI, event name, and callback
8
+ * @returns An unwatch function to stop the subscription
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { createPublicClient } from 'viem';
13
+ * import { createWebSocketTransport, watchLogs } from '@radiustechsystems/sdk/events';
14
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
15
+ *
16
+ * // Create client with WebSocket transport
17
+ * const client = createPublicClient({
18
+ * chain: radiusTestnet,
19
+ * transport: createWebSocketTransport(radiusTestnet),
20
+ * });
21
+ *
22
+ * // Watch for events
23
+ * const unwatch = watchLogs(client, {
24
+ * address: '0x...',
25
+ * abi: contractAbi,
26
+ * eventName: 'Transfer',
27
+ * onLogs: (logs) => {
28
+ * console.log('Transfer events:', logs);
29
+ * },
30
+ * });
31
+ *
32
+ * // Stop watching
33
+ * unwatch();
34
+ * ```
35
+ *
36
+ * @remarks
37
+ * - Requires WebSocket transport for real-time subscriptions
38
+ * - Radius supports eth_subscribe with type "logs" only
39
+ * - Address parameter is mandatory on Radius
40
+ * - Subscriptions consume gas from your RPC key (10 GAS/sec)
41
+ * - Automatically cleaned up on disconnect
42
+ * - For HTTP transport, consider using getLogs with polling instead
43
+ */
44
+ export function watchLogs(client, params) {
45
+ return watchContractEvent(client, params);
46
+ }
47
+ /**
48
+ * Watches for raw logs without ABI decoding.
49
+ * Useful when you want to receive raw log data or watch multiple event types.
50
+ *
51
+ * @param client - The PublicClient to use (WebSocket transport recommended)
52
+ * @param params - Raw log watching parameters
53
+ * @returns An unwatch function to stop the subscription
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * import { createPublicClient } from 'viem';
58
+ * import { createWebSocketTransport, watchRawLogs } from '@radiustechsystems/sdk/events';
59
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
60
+ *
61
+ * const client = createPublicClient({
62
+ * chain: radiusTestnet,
63
+ * transport: createWebSocketTransport(radiusTestnet),
64
+ * });
65
+ *
66
+ * // Watch for all events from a contract
67
+ * const unwatch = watchRawLogs(client, {
68
+ * address: '0x...',
69
+ * onLogs: (logs) => {
70
+ * logs.forEach(log => {
71
+ * console.log('Log:', log.topics, log.data);
72
+ * });
73
+ * },
74
+ * onError: (error) => {
75
+ * console.error('Subscription error:', error);
76
+ * },
77
+ * });
78
+ *
79
+ * // Stop watching
80
+ * unwatch();
81
+ * ```
82
+ *
83
+ * @remarks
84
+ * - Does not decode log data; returns raw topics and data
85
+ * - Useful for monitoring multiple event types from same contract
86
+ * - Requires address parameter (mandatory on Radius)
87
+ * - WebSocket transport provides real-time updates
88
+ * - HTTP transport falls back to polling (less efficient)
89
+ */
90
+ export function watchRawLogs(client, params) {
91
+ // Use viem's watchEvent action for raw logs
92
+ // This will use eth_subscribe for WebSocket or polling for HTTP
93
+ return client.watchEvent({
94
+ address: params.address,
95
+ onLogs: params.onLogs,
96
+ onError: params.onError,
97
+ pollingInterval: params.pollingInterval,
98
+ });
99
+ }
100
+ //# sourceMappingURL=watchLogs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchLogs.js","sourceRoot":"","sources":["../../events/watchLogs.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,SAAS,CACxB,MAAoB,EACpB,MAAgD;IAEhD,OAAO,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAoBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU,YAAY,CAC3B,MAAoB,EACpB,MAA8B;IAE9B,4CAA4C;IAC5C,gEAAgE;IAChE,OAAO,MAAM,CAAC,UAAU,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,eAAe,EAAE,MAAM,CAAC,eAAe;KACvC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * ERC-20 Transfer event watching utilities for Radius SDK.
3
+ * Provides convenient wrappers for watching Transfer events in real-time.
4
+ */
5
+ import type { Address, Log, PublicClient, WatchContractEventReturnType } from 'viem';
6
+ /**
7
+ * Decoded Transfer event data.
8
+ */
9
+ export interface TransferEvent {
10
+ /** The address that sent the tokens */
11
+ from: Address;
12
+ /** The address that received the tokens */
13
+ to: Address;
14
+ /** The amount of tokens transferred (in smallest unit) */
15
+ value: bigint;
16
+ /** The raw log data */
17
+ log: Log;
18
+ }
19
+ /**
20
+ * Parameters for watching Transfer events.
21
+ */
22
+ export interface WatchTransferParameters {
23
+ /** The ERC-20 token contract address to watch */
24
+ address: Address;
25
+ /** Optional: Filter by sender address */
26
+ from?: Address;
27
+ /** Optional: Filter by recipient address */
28
+ to?: Address;
29
+ /** Callback function invoked when Transfer events are received */
30
+ onTransfer: (events: TransferEvent[]) => void;
31
+ /** Callback function invoked when an error occurs */
32
+ onError?: (error: Error) => void;
33
+ /** Whether to emit logs from the latest block on subscription start */
34
+ sync?: boolean;
35
+ /** Polling interval in milliseconds (for HTTP transport fallback) */
36
+ pollingInterval?: number;
37
+ }
38
+ /**
39
+ * Watches for ERC-20 Transfer events in real-time.
40
+ * Automatically decodes Transfer events and provides type-safe callbacks.
41
+ *
42
+ * @param client - The PublicClient to use (WebSocket transport recommended)
43
+ * @param params - Transfer event watching parameters
44
+ * @returns An unwatch function to stop the subscription
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * import { createPublicClient } from 'viem';
49
+ * import { createWebSocketTransport, watchTransfer } from '@radiustechsystems/sdk/events';
50
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
51
+ *
52
+ * const client = createPublicClient({
53
+ * chain: radiusTestnet,
54
+ * transport: createWebSocketTransport(radiusTestnet),
55
+ * });
56
+ *
57
+ * // Watch all transfers for a token
58
+ * const unwatch = watchTransfer(client, {
59
+ * address: '0x...', // Token address
60
+ * onTransfer: (events) => {
61
+ * events.forEach(event => {
62
+ * console.log(`Transfer: ${event.value} from ${event.from} to ${event.to}`);
63
+ * });
64
+ * },
65
+ * });
66
+ *
67
+ * // Watch transfers to a specific address
68
+ * const unwatchToAddress = watchTransfer(client, {
69
+ * address: '0x...', // Token address
70
+ * to: '0x...', // Recipient address
71
+ * onTransfer: (events) => {
72
+ * console.log(`Received ${events.length} transfers`);
73
+ * },
74
+ * });
75
+ *
76
+ * // Stop watching
77
+ * unwatch();
78
+ * ```
79
+ *
80
+ * @remarks
81
+ * - Requires WebSocket transport for real-time subscriptions
82
+ * - Automatically decodes Transfer events using ERC-20 ABI
83
+ * - Filters by from/to addresses if provided
84
+ * - Event signature: Transfer(address indexed from, address indexed to, uint256 value)
85
+ * - Subscriptions consume gas from your RPC key on Radius (10 GAS/sec)
86
+ */
87
+ export declare function watchTransfer(client: PublicClient, params: WatchTransferParameters): WatchContractEventReturnType;
88
+ /**
89
+ * Parameters for watching Transfer events for a specific address (as sender or receiver).
90
+ */
91
+ export interface WatchTransferForAddressParameters {
92
+ /** The ERC-20 token contract address to watch */
93
+ tokenAddress: Address;
94
+ /** The address to watch (as sender or receiver) */
95
+ watchAddress: Address;
96
+ /** Whether to watch as sender only (default: false, watches both sender and receiver) */
97
+ senderOnly?: boolean;
98
+ /** Whether to watch as receiver only (default: false, watches both sender and receiver) */
99
+ receiverOnly?: boolean;
100
+ /** Callback function invoked when Transfer events are received */
101
+ onTransfer: (events: TransferEvent[]) => void;
102
+ /** Callback function invoked when an error occurs */
103
+ onError?: (error: Error) => void;
104
+ /** Whether to emit logs from the latest block on subscription start */
105
+ sync?: boolean;
106
+ /** Polling interval in milliseconds (for HTTP transport fallback) */
107
+ pollingInterval?: number;
108
+ }
109
+ /**
110
+ * Watches for Transfer events involving a specific address (as sender or receiver).
111
+ * Convenience wrapper around watchTransfer for monitoring a single address.
112
+ *
113
+ * @param client - The PublicClient to use (WebSocket transport recommended)
114
+ * @param params - Transfer watching parameters for specific address
115
+ * @returns An unwatch function to stop the subscription
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * import { createPublicClient } from 'viem';
120
+ * import { createWebSocketTransport, watchTransferForAddress } from '@radiustechsystems/sdk/events';
121
+ * import { radiusTestnet } from '@radiustechsystems/sdk/chains';
122
+ *
123
+ * const client = createPublicClient({
124
+ * chain: radiusTestnet,
125
+ * transport: createWebSocketTransport(radiusTestnet),
126
+ * });
127
+ *
128
+ * // Watch all transfers involving an address (sent or received)
129
+ * const unwatch = watchTransferForAddress(client, {
130
+ * tokenAddress: '0x...', // Token address
131
+ * watchAddress: '0x...', // Address to monitor
132
+ * onTransfer: (events) => {
133
+ * events.forEach(event => {
134
+ * if (event.from === watchAddress) {
135
+ * console.log(`Sent ${event.value} to ${event.to}`);
136
+ * } else {
137
+ * console.log(`Received ${event.value} from ${event.from}`);
138
+ * }
139
+ * });
140
+ * },
141
+ * });
142
+ *
143
+ * // Watch only transfers sent from an address
144
+ * const unwatchSent = watchTransferForAddress(client, {
145
+ * tokenAddress: '0x...',
146
+ * watchAddress: '0x...',
147
+ * senderOnly: true,
148
+ * onTransfer: (events) => {
149
+ * console.log(`Sent ${events.length} transfers`);
150
+ * },
151
+ * });
152
+ *
153
+ * // Stop watching
154
+ * unwatch();
155
+ * ```
156
+ *
157
+ * @remarks
158
+ * - If neither senderOnly nor receiverOnly is set, watches both directions
159
+ * - Cannot set both senderOnly and receiverOnly to true
160
+ * - More efficient than watching all transfers and filtering client-side
161
+ * - Server-side filtering reduces network traffic and processing
162
+ */
163
+ export declare function watchTransferForAddress(client: PublicClient, params: WatchTransferForAddressParameters): WatchContractEventReturnType;
164
+ //# sourceMappingURL=watchTransfer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchTransfer.d.ts","sourceRoot":"","sources":["../../events/watchTransfer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,MAAM,CAAC;AAGrF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,uCAAuC;IACvC,IAAI,EAAE,OAAO,CAAC;IACd,2CAA2C;IAC3C,EAAE,EAAE,OAAO,CAAC;IACZ,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,GAAG,EAAE,GAAG,CAAC;CACT;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4CAA4C;IAC5C,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,kEAAkE;IAClE,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,IAAI,CAAC;IAC9C,qDAAqD;IACrD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,uEAAuE;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,uBAAuB,GAC7B,4BAA4B,CA+C9B;AAED;;GAEG;AACH,MAAM,WAAW,iCAAiC;IACjD,iDAAiD;IACjD,YAAY,EAAE,OAAO,CAAC;IACtB,mDAAmD;IACnD,YAAY,EAAE,OAAO,CAAC;IACtB,yFAAyF;IACzF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2FAA2F;IAC3F,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,kEAAkE;IAClE,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,IAAI,CAAC;IAC9C,qDAAqD;IACrD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,uEAAuE;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,iCAAiC,GACvC,4BAA4B,CAyF9B"}