@ryanrfox/sdk 0.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -29
- package/package.json +84 -8
- package/src/_esm/actions/index.d.ts +8 -0
- package/src/_esm/actions/index.d.ts.map +1 -0
- package/src/_esm/actions/index.js +8 -0
- package/src/_esm/actions/index.js.map +1 -0
- package/src/_esm/actions/sendTransactionBatch.d.ts +77 -0
- package/src/_esm/actions/sendTransactionBatch.d.ts.map +1 -0
- package/src/_esm/actions/sendTransactionBatch.js +245 -0
- package/src/_esm/actions/sendTransactionBatch.js.map +1 -0
- package/src/_esm/chains/chainConfig.d.ts +30 -0
- package/src/_esm/chains/chainConfig.d.ts.map +1 -0
- package/src/_esm/chains/chainConfig.js +30 -0
- package/src/_esm/chains/chainConfig.js.map +1 -0
- package/src/_esm/chains/index.d.ts +4 -0
- package/src/_esm/chains/index.d.ts.map +1 -0
- package/src/_esm/chains/index.js +4 -0
- package/src/_esm/chains/index.js.map +1 -0
- package/src/_esm/chains/radius.d.ts +64 -0
- package/src/_esm/chains/radius.d.ts.map +1 -0
- package/src/_esm/chains/radius.js +39 -0
- package/src/_esm/chains/radius.js.map +1 -0
- package/src/_esm/chains/radiusTestnet.d.ts +61 -0
- package/src/_esm/chains/radiusTestnet.d.ts.map +1 -0
- package/src/_esm/chains/radiusTestnet.js +45 -0
- package/src/_esm/chains/radiusTestnet.js.map +1 -0
- package/src/_esm/decorators/index.d.ts +8 -0
- package/src/_esm/decorators/index.d.ts.map +1 -0
- package/src/_esm/decorators/index.js +8 -0
- package/src/_esm/decorators/index.js.map +1 -0
- package/src/_esm/decorators/radius.d.ts +66 -0
- package/src/_esm/decorators/radius.d.ts.map +1 -0
- package/src/_esm/decorators/radius.js +36 -0
- package/src/_esm/decorators/radius.js.map +1 -0
- package/src/_esm/errors/account.d.ts +78 -0
- package/src/_esm/errors/account.d.ts.map +1 -0
- package/src/_esm/errors/account.js +97 -0
- package/src/_esm/errors/account.js.map +1 -0
- package/src/_esm/errors/base.d.ts +56 -0
- package/src/_esm/errors/base.d.ts.map +1 -0
- package/src/_esm/errors/base.js +51 -0
- package/src/_esm/errors/base.js.map +1 -0
- package/src/_esm/errors/contract.d.ts +51 -0
- package/src/_esm/errors/contract.d.ts.map +1 -0
- package/src/_esm/errors/contract.js +65 -0
- package/src/_esm/errors/contract.js.map +1 -0
- package/src/_esm/errors/index.d.ts +63 -0
- package/src/_esm/errors/index.d.ts.map +1 -0
- package/src/_esm/errors/index.js +40 -0
- package/src/_esm/errors/index.js.map +1 -0
- package/src/_esm/errors/transaction.d.ts +132 -0
- package/src/_esm/errors/transaction.d.ts.map +1 -0
- package/src/_esm/errors/transaction.js +143 -0
- package/src/_esm/errors/transaction.js.map +1 -0
- package/src/_esm/events/decodeEventLogs.d.ts +136 -0
- package/src/_esm/events/decodeEventLogs.d.ts.map +1 -0
- package/src/_esm/events/decodeEventLogs.js +93 -0
- package/src/_esm/events/decodeEventLogs.js.map +1 -0
- package/src/_esm/events/getLogs.d.ts +137 -0
- package/src/_esm/events/getLogs.d.ts.map +1 -0
- package/src/_esm/events/getLogs.js +171 -0
- package/src/_esm/events/getLogs.js.map +1 -0
- package/src/_esm/events/index.d.ts +17 -0
- package/src/_esm/events/index.d.ts.map +1 -0
- package/src/_esm/events/index.js +24 -0
- package/src/_esm/events/index.js.map +1 -0
- package/src/_esm/events/watchApproval.d.ts +184 -0
- package/src/_esm/events/watchApproval.d.ts.map +1 -0
- package/src/_esm/events/watchApproval.js +254 -0
- package/src/_esm/events/watchApproval.js.map +1 -0
- package/src/_esm/events/watchBlock.d.ts +192 -0
- package/src/_esm/events/watchBlock.d.ts.map +1 -0
- package/src/_esm/events/watchBlock.js +162 -0
- package/src/_esm/events/watchBlock.js.map +1 -0
- package/src/_esm/events/watchLogs.d.ts +128 -0
- package/src/_esm/events/watchLogs.d.ts.map +1 -0
- package/src/_esm/events/watchLogs.js +100 -0
- package/src/_esm/events/watchLogs.js.map +1 -0
- package/src/_esm/events/watchTransfer.d.ts +164 -0
- package/src/_esm/events/watchTransfer.d.ts.map +1 -0
- package/src/_esm/events/watchTransfer.js +234 -0
- package/src/_esm/events/watchTransfer.js.map +1 -0
- package/src/_esm/index.d.ts +16 -0
- package/src/_esm/index.d.ts.map +1 -0
- package/src/_esm/index.js +22 -0
- package/src/_esm/index.js.map +1 -0
- package/src/_esm/package.json +1 -0
- package/src/_esm/transport/index.d.ts +9 -0
- package/src/_esm/transport/index.d.ts.map +1 -0
- package/src/_esm/transport/index.js +9 -0
- package/src/_esm/transport/index.js.map +1 -0
- package/src/_esm/transport/interceptor.d.ts +48 -0
- package/src/_esm/transport/interceptor.d.ts.map +1 -0
- package/src/_esm/transport/interceptor.js +209 -0
- package/src/_esm/transport/interceptor.js.map +1 -0
- package/src/_esm/transport/types.d.ts +29 -0
- package/src/_esm/transport/types.d.ts.map +1 -0
- package/src/_esm/transport/types.js +2 -0
- package/src/_esm/transport/types.js.map +1 -0
- package/src/_esm/transport/websocket.d.ts +51 -0
- package/src/_esm/transport/websocket.d.ts.map +1 -0
- package/src/_esm/transport/websocket.js +70 -0
- package/src/_esm/transport/websocket.js.map +1 -0
- package/src/_types/actions/index.d.ts +8 -0
- package/src/_types/actions/index.d.ts.map +1 -0
- package/src/_types/actions/sendTransactionBatch.d.ts +77 -0
- package/src/_types/actions/sendTransactionBatch.d.ts.map +1 -0
- package/src/_types/chains/chainConfig.d.ts +30 -0
- package/src/_types/chains/chainConfig.d.ts.map +1 -0
- package/src/_types/chains/index.d.ts +4 -0
- package/src/_types/chains/index.d.ts.map +1 -0
- package/src/_types/chains/radius.d.ts +64 -0
- package/src/_types/chains/radius.d.ts.map +1 -0
- package/src/_types/chains/radiusTestnet.d.ts +61 -0
- package/src/_types/chains/radiusTestnet.d.ts.map +1 -0
- package/src/_types/decorators/index.d.ts +8 -0
- package/src/_types/decorators/index.d.ts.map +1 -0
- package/src/_types/decorators/radius.d.ts +66 -0
- package/src/_types/decorators/radius.d.ts.map +1 -0
- package/src/_types/errors/account.d.ts +78 -0
- package/src/_types/errors/account.d.ts.map +1 -0
- package/src/_types/errors/base.d.ts +56 -0
- package/src/_types/errors/base.d.ts.map +1 -0
- package/src/_types/errors/contract.d.ts +51 -0
- package/src/_types/errors/contract.d.ts.map +1 -0
- package/src/_types/errors/index.d.ts +63 -0
- package/src/_types/errors/index.d.ts.map +1 -0
- package/src/_types/errors/transaction.d.ts +132 -0
- package/src/_types/errors/transaction.d.ts.map +1 -0
- package/src/_types/events/decodeEventLogs.d.ts +136 -0
- package/src/_types/events/decodeEventLogs.d.ts.map +1 -0
- package/src/_types/events/getLogs.d.ts +137 -0
- package/src/_types/events/getLogs.d.ts.map +1 -0
- package/src/_types/events/index.d.ts +17 -0
- package/src/_types/events/index.d.ts.map +1 -0
- package/src/_types/events/watchApproval.d.ts +184 -0
- package/src/_types/events/watchApproval.d.ts.map +1 -0
- package/src/_types/events/watchBlock.d.ts +192 -0
- package/src/_types/events/watchBlock.d.ts.map +1 -0
- package/src/_types/events/watchLogs.d.ts +128 -0
- package/src/_types/events/watchLogs.d.ts.map +1 -0
- package/src/_types/events/watchTransfer.d.ts +164 -0
- package/src/_types/events/watchTransfer.d.ts.map +1 -0
- package/src/_types/index.d.ts +16 -0
- package/src/_types/index.d.ts.map +1 -0
- package/src/_types/transport/index.d.ts +9 -0
- package/src/_types/transport/index.d.ts.map +1 -0
- package/src/_types/transport/interceptor.d.ts +48 -0
- package/src/_types/transport/interceptor.d.ts.map +1 -0
- package/src/_types/transport/types.d.ts +29 -0
- package/src/_types/transport/types.d.ts.map +1 -0
- package/src/_types/transport/websocket.d.ts +51 -0
- package/src/_types/transport/websocket.d.ts.map +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event log decoding utilities for Radius SDK.
|
|
3
|
+
* Provides convenient wrappers around viem's decodeEventLog.
|
|
4
|
+
*/
|
|
5
|
+
import { type Abi, type DecodeEventLogReturnType, type Log } from 'viem';
|
|
6
|
+
/**
|
|
7
|
+
* A decoded event log with the original log data preserved.
|
|
8
|
+
*/
|
|
9
|
+
export interface DecodedEventLog<TAbi extends Abi = Abi> {
|
|
10
|
+
/** The decoded event name */
|
|
11
|
+
eventName: string;
|
|
12
|
+
/** The decoded event arguments */
|
|
13
|
+
args: DecodeEventLogReturnType<TAbi>['args'];
|
|
14
|
+
/** The original raw log */
|
|
15
|
+
log: Log;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for decodeEventLogs.
|
|
19
|
+
*/
|
|
20
|
+
export interface DecodeEventLogsParameters<TAbi extends Abi = Abi> {
|
|
21
|
+
/** The contract ABI containing event definitions */
|
|
22
|
+
abi: TAbi;
|
|
23
|
+
/** The logs to decode */
|
|
24
|
+
logs: Log[];
|
|
25
|
+
/** If true, skip logs that fail to decode instead of throwing (default: false) */
|
|
26
|
+
strict?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Result when strict mode is disabled and some logs fail to decode.
|
|
30
|
+
*/
|
|
31
|
+
export interface DecodeEventLogsResult<TAbi extends Abi = Abi> {
|
|
32
|
+
/** Successfully decoded logs */
|
|
33
|
+
decoded: DecodedEventLog<TAbi>[];
|
|
34
|
+
/** Logs that failed to decode (only present when strict: false) */
|
|
35
|
+
failed?: Array<{
|
|
36
|
+
log: Log;
|
|
37
|
+
error: Error;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decodes an array of event logs using the provided ABI.
|
|
42
|
+
*
|
|
43
|
+
* This is a convenience wrapper around viem's `decodeEventLog` that handles
|
|
44
|
+
* multiple logs at once and provides options for error handling.
|
|
45
|
+
*
|
|
46
|
+
* @param params - The parameters for decoding
|
|
47
|
+
* @returns Array of decoded event logs (or result object if strict: false)
|
|
48
|
+
* @throws Error if any log fails to decode and strict mode is enabled (default)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { decodeEventLogs } from '@radiustechsystems/sdk/events';
|
|
53
|
+
*
|
|
54
|
+
* const erc20Abi = [
|
|
55
|
+
* {
|
|
56
|
+
* type: 'event',
|
|
57
|
+
* name: 'Transfer',
|
|
58
|
+
* inputs: [
|
|
59
|
+
* { indexed: true, name: 'from', type: 'address' },
|
|
60
|
+
* { indexed: true, name: 'to', type: 'address' },
|
|
61
|
+
* { indexed: false, name: 'value', type: 'uint256' },
|
|
62
|
+
* ],
|
|
63
|
+
* },
|
|
64
|
+
* ] as const;
|
|
65
|
+
*
|
|
66
|
+
* // Decode logs from a transaction receipt
|
|
67
|
+
* const decoded = decodeEventLogs({
|
|
68
|
+
* abi: erc20Abi,
|
|
69
|
+
* logs: receipt.logs,
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* for (const event of decoded) {
|
|
73
|
+
* if (event.eventName === 'Transfer') {
|
|
74
|
+
* console.log(`Transfer: ${event.args.from} -> ${event.args.to}: ${event.args.value}`);
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // With strict: false to handle mixed logs from multiple contracts
|
|
82
|
+
* const result = decodeEventLogs({
|
|
83
|
+
* abi: erc20Abi,
|
|
84
|
+
* logs: mixedLogs,
|
|
85
|
+
* strict: false,
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* console.log(`Decoded ${result.decoded.length} logs`);
|
|
89
|
+
* console.log(`Failed to decode ${result.failed?.length ?? 0} logs`);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function decodeEventLogs<TAbi extends Abi>(params: DecodeEventLogsParameters<TAbi> & {
|
|
93
|
+
strict: false;
|
|
94
|
+
}): DecodeEventLogsResult<TAbi>;
|
|
95
|
+
export declare function decodeEventLogs<TAbi extends Abi>(params: DecodeEventLogsParameters<TAbi> & {
|
|
96
|
+
strict?: true;
|
|
97
|
+
}): DecodedEventLog<TAbi>[];
|
|
98
|
+
export declare function decodeEventLogs<TAbi extends Abi>(params: DecodeEventLogsParameters<TAbi>): DecodedEventLog<TAbi>[] | DecodeEventLogsResult<TAbi>;
|
|
99
|
+
/**
|
|
100
|
+
* Parameters for filterEventLogs.
|
|
101
|
+
*/
|
|
102
|
+
export interface FilterEventLogsParameters<TAbi extends Abi = Abi, TEventName extends string = string> {
|
|
103
|
+
/** The contract ABI containing event definitions */
|
|
104
|
+
abi: TAbi;
|
|
105
|
+
/** The logs to filter and decode */
|
|
106
|
+
logs: Log[];
|
|
107
|
+
/** The event name to filter for */
|
|
108
|
+
eventName: TEventName;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Filters and decodes logs for a specific event type.
|
|
112
|
+
*
|
|
113
|
+
* This is useful when you only care about a specific event from a receipt
|
|
114
|
+
* or log array that may contain multiple event types.
|
|
115
|
+
*
|
|
116
|
+
* @param params - The parameters for filtering
|
|
117
|
+
* @returns Array of decoded logs matching the event name
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* import { filterEventLogs } from '@radiustechsystems/sdk/events';
|
|
122
|
+
*
|
|
123
|
+
* // Get only Transfer events from a receipt
|
|
124
|
+
* const transfers = filterEventLogs({
|
|
125
|
+
* abi: erc20Abi,
|
|
126
|
+
* logs: receipt.logs,
|
|
127
|
+
* eventName: 'Transfer',
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* for (const transfer of transfers) {
|
|
131
|
+
* console.log(`${transfer.args.from} sent ${transfer.args.value} to ${transfer.args.to}`);
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function filterEventLogs<TAbi extends Abi, TEventName extends string>(params: FilterEventLogsParameters<TAbi, TEventName>): DecodedEventLog<TAbi>[];
|
|
136
|
+
//# sourceMappingURL=decodeEventLogs.d.ts.map
|
|
@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AAC,IAAI,SAAS,GAAG,EAC/C,MAAM,EAAE,yBAAyB,CAAC,IAAI,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,IAAI,CAAA;CAAE,GACzD,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3B,wBAAgB,eAAe,CAAC,IAAI,SAAS,GAAG,EAC/C,MAAM,EAAE,yBAAyB,CAAC,IAAI,CAAC,GACrC,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;AA2CzD;;GAEG;AACH,MAAM,WAAW,yBAAyB,CACzC,IAAI,SAAS,GAAG,GAAG,GAAG,EACtB,UAAU,SAAS,MAAM,GAAG,MAAM;IAElC,oDAAoD;IACpD,GAAG,EAAE,IAAI,CAAC;IACV,oCAAoC;IACpC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,mCAAmC;IACnC,SAAS,EAAE,UAAU,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,IAAI,SAAS,GAAG,EAAE,UAAU,SAAS,MAAM,EAC1E,MAAM,EAAE,yBAAyB,CAAC,IAAI,EAAE,UAAU,CAAC,GACjD,eAAe,CAAC,IAAI,CAAC,EAAE,CAiCzB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event log decoding utilities for Radius SDK.
|
|
3
|
+
* Provides convenient wrappers around viem's decodeEventLog.
|
|
4
|
+
*/
|
|
5
|
+
import { decodeEventLog, } from 'viem';
|
|
6
|
+
export function decodeEventLogs(params) {
|
|
7
|
+
const { abi, logs, strict = true } = params;
|
|
8
|
+
const decoded = [];
|
|
9
|
+
const failed = [];
|
|
10
|
+
for (const log of logs) {
|
|
11
|
+
try {
|
|
12
|
+
const result = decodeEventLog({
|
|
13
|
+
abi,
|
|
14
|
+
data: log.data,
|
|
15
|
+
topics: log.topics,
|
|
16
|
+
});
|
|
17
|
+
decoded.push({
|
|
18
|
+
eventName: result.eventName,
|
|
19
|
+
args: result.args,
|
|
20
|
+
log,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (strict) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
failed.push({
|
|
28
|
+
log,
|
|
29
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (strict) {
|
|
34
|
+
return decoded;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
decoded,
|
|
38
|
+
failed: failed.length > 0 ? failed : undefined,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Filters and decodes logs for a specific event type.
|
|
43
|
+
*
|
|
44
|
+
* This is useful when you only care about a specific event from a receipt
|
|
45
|
+
* or log array that may contain multiple event types.
|
|
46
|
+
*
|
|
47
|
+
* @param params - The parameters for filtering
|
|
48
|
+
* @returns Array of decoded logs matching the event name
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { filterEventLogs } from '@radiustechsystems/sdk/events';
|
|
53
|
+
*
|
|
54
|
+
* // Get only Transfer events from a receipt
|
|
55
|
+
* const transfers = filterEventLogs({
|
|
56
|
+
* abi: erc20Abi,
|
|
57
|
+
* logs: receipt.logs,
|
|
58
|
+
* eventName: 'Transfer',
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* for (const transfer of transfers) {
|
|
62
|
+
* console.log(`${transfer.args.from} sent ${transfer.args.value} to ${transfer.args.to}`);
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function filterEventLogs(params) {
|
|
67
|
+
const { abi, logs, eventName } = params;
|
|
68
|
+
// Find the event in the ABI to get its signature
|
|
69
|
+
const eventAbi = abi.find((item) => item.type === 'event' && item.name === eventName);
|
|
70
|
+
if (!eventAbi) {
|
|
71
|
+
throw new Error(`Event "${eventName}" not found in ABI`);
|
|
72
|
+
}
|
|
73
|
+
const result = [];
|
|
74
|
+
for (const log of logs) {
|
|
75
|
+
try {
|
|
76
|
+
const decoded = decodeEventLog({
|
|
77
|
+
abi,
|
|
78
|
+
data: log.data,
|
|
79
|
+
topics: log.topics,
|
|
80
|
+
});
|
|
81
|
+
if (decoded.eventName === eventName) {
|
|
82
|
+
result.push({
|
|
83
|
+
eventName: decoded.eventName,
|
|
84
|
+
args: decoded.args,
|
|
85
|
+
log,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=decodeEventLogs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeEventLogs.js","sourceRoot":"","sources":["../../events/decodeEventLogs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAIN,cAAc,GAEd,MAAM,MAAM,CAAC;AAiGd,MAAM,UAAU,eAAe,CAC9B,MAAuC;IAEvC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAE5C,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAsC,EAAE,CAAC;IAErD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,cAAc,CAAC;gBAC7B,GAAG;gBACH,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,MAAM,EAAE,GAAG,CAAC,MAAM;aAClB,CAAC,CAAC;YAEH,OAAO,CAAC,IAAI,CAAC;gBACZ,SAAS,EAAE,MAAM,CAAC,SAAmB;gBACrC,IAAI,EAAE,MAAM,CAAC,IAA8C;gBAC3D,GAAG;aACH,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EA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C,MAAM,CAAC,IAAI,CAAC;oBACX,SAAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,IAAI,EAAE,OAAO,CAAC,IAA8C;oBAC5D,GAAG;iBACH,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Historical log querying utilities for Radius SDK.
|
|
3
|
+
* Provides pagination helpers for eth_getLogs with Radius-specific block range handling.
|
|
4
|
+
*/
|
|
5
|
+
import type { Address, Log, PublicClient } from 'viem';
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for paginated log retrieval.
|
|
8
|
+
*/
|
|
9
|
+
export interface GetLogsParams {
|
|
10
|
+
/** The contract address(es) to query logs from (required on Radius) */
|
|
11
|
+
address: Address | Address[];
|
|
12
|
+
/** Starting block number (inclusive) */
|
|
13
|
+
fromBlock: bigint;
|
|
14
|
+
/** Ending block number (inclusive) */
|
|
15
|
+
toBlock: bigint;
|
|
16
|
+
/** Maximum number of blocks to query per request (default: 1000) */
|
|
17
|
+
chunkSize?: number;
|
|
18
|
+
/** Callback invoked after each chunk is fetched (for progress tracking) */
|
|
19
|
+
onProgress?: (params: {
|
|
20
|
+
/** Current block being processed */
|
|
21
|
+
currentBlock: bigint;
|
|
22
|
+
/** Total blocks to process */
|
|
23
|
+
totalBlocks: bigint;
|
|
24
|
+
/** Number of chunks processed so far */
|
|
25
|
+
chunksProcessed: number;
|
|
26
|
+
/** Logs fetched so far */
|
|
27
|
+
logsFetched: number;
|
|
28
|
+
}) => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fetches historical logs from Radius with automatic pagination.
|
|
32
|
+
* Handles Radius's block range restrictions by splitting large queries into smaller chunks.
|
|
33
|
+
*
|
|
34
|
+
* @param client - The PublicClient to use
|
|
35
|
+
* @param params - Log query parameters with pagination
|
|
36
|
+
* @returns Array of all logs matching the query
|
|
37
|
+
* @throws Error if any chunk request fails
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { createPublicClient, http } from 'viem';
|
|
42
|
+
* import { getLogs } from '@radiustechsystems/sdk/events';
|
|
43
|
+
* import { radiusTestnet } from '@radiustechsystems/sdk/chains';
|
|
44
|
+
*
|
|
45
|
+
* const client = createPublicClient({
|
|
46
|
+
* chain: radiusTestnet,
|
|
47
|
+
* transport: http(),
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Fetch logs for a large block range
|
|
51
|
+
* const logs = await getLogs(client, {
|
|
52
|
+
* address: '0x...', // Contract address (required)
|
|
53
|
+
* fromBlock: 1000000n,
|
|
54
|
+
* toBlock: 1010000n, // 10,000 blocks
|
|
55
|
+
* chunkSize: 1000, // Query 1000 blocks at a time
|
|
56
|
+
* onProgress: ({ currentBlock, totalBlocks, logsFetched }) => {
|
|
57
|
+
* const percent = (Number(currentBlock) / Number(totalBlocks) * 100).toFixed(1);
|
|
58
|
+
* console.log(`Progress: ${percent}% (${logsFetched} logs)`);
|
|
59
|
+
* },
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* console.log(`Found ${logs.length} total logs`);
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* - Radius requires the address parameter (cannot query all contracts)
|
|
67
|
+
* - Radius restricts eth_getLogs to narrow block ranges
|
|
68
|
+
* - This function automatically splits large queries into smaller chunks
|
|
69
|
+
* - Default chunk size is 1000 blocks (adjust based on your needs)
|
|
70
|
+
* - If you get "block range is too wide" errors, reduce chunkSize
|
|
71
|
+
* - Progress callback is optional but useful for long-running queries
|
|
72
|
+
* - All requests are sequential to avoid rate limiting
|
|
73
|
+
* - Consider using WebSocket subscriptions for real-time monitoring instead
|
|
74
|
+
*/
|
|
75
|
+
export declare function getLogs(client: PublicClient, params: GetLogsParams): Promise<Log[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Parameters for fetching logs with automatic chunk size detection.
|
|
78
|
+
*/
|
|
79
|
+
export interface GetLogsAdaptiveParams {
|
|
80
|
+
/** The contract address(es) to query logs from (required on Radius) */
|
|
81
|
+
address: Address | Address[];
|
|
82
|
+
/** Starting block number (inclusive) */
|
|
83
|
+
fromBlock: bigint;
|
|
84
|
+
/** Ending block number (inclusive) */
|
|
85
|
+
toBlock: bigint;
|
|
86
|
+
/** Initial chunk size to try (default: 1000) */
|
|
87
|
+
initialChunkSize?: number;
|
|
88
|
+
/** Minimum chunk size (default: 10) */
|
|
89
|
+
minChunkSize?: number;
|
|
90
|
+
/** Callback invoked after each chunk is fetched (for progress tracking) */
|
|
91
|
+
onProgress?: (params: {
|
|
92
|
+
currentBlock: bigint;
|
|
93
|
+
totalBlocks: bigint;
|
|
94
|
+
chunksProcessed: number;
|
|
95
|
+
logsFetched: number;
|
|
96
|
+
currentChunkSize: number;
|
|
97
|
+
}) => void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Fetches historical logs with adaptive chunk sizing.
|
|
101
|
+
* Automatically reduces chunk size if "block range too wide" errors occur.
|
|
102
|
+
*
|
|
103
|
+
* @param client - The PublicClient to use
|
|
104
|
+
* @param params - Log query parameters with adaptive sizing
|
|
105
|
+
* @returns Array of all logs matching the query
|
|
106
|
+
* @throws Error if minimum chunk size is reached or other errors occur
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* import { createPublicClient, http } from 'viem';
|
|
111
|
+
* import { getLogsAdaptive } from '@radiustechsystems/sdk/events';
|
|
112
|
+
* import { radiusTestnet } from '@radiustechsystems/sdk/chains';
|
|
113
|
+
*
|
|
114
|
+
* const client = createPublicClient({
|
|
115
|
+
* chain: radiusTestnet,
|
|
116
|
+
* transport: http(),
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Fetch logs with automatic chunk size adjustment
|
|
120
|
+
* const logs = await getLogsAdaptive(client, {
|
|
121
|
+
* address: '0x...',
|
|
122
|
+
* fromBlock: 1000000n,
|
|
123
|
+
* toBlock: 1010000n,
|
|
124
|
+
* onProgress: ({ currentBlock, totalBlocks, currentChunkSize }) => {
|
|
125
|
+
* console.log(`Block ${currentBlock}/${totalBlocks} (chunk: ${currentChunkSize})`);
|
|
126
|
+
* },
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* - Starts with a large chunk size and reduces it if errors occur
|
|
132
|
+
* - Useful when you don't know the optimal chunk size for a network
|
|
133
|
+
* - Slower than getLogs with a known good chunk size
|
|
134
|
+
* - Use getLogs directly if you know a reliable chunk size
|
|
135
|
+
*/
|
|
136
|
+
export declare function getLogsAdaptive(client: PublicClient, params: GetLogsAdaptiveParams): Promise<Log[]>;
|
|
137
|
+
//# sourceMappingURL=getLogs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLogs.d.ts","sourceRoot":"","sources":["../../events/getLogs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,OAAO,EAAqB,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,uEAAuE;IACvE,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAC7B,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE;QACrB,oCAAoC;QACpC,YAAY,EAAE,MAAM,CAAC;QACrB,8BAA8B;QAC9B,WAAW,EAAE,MAAM,CAAC;QACpB,wCAAwC;QACxC,eAAe,EAAE,MAAM,CAAC;QACxB,0BAA0B;QAC1B,WAAW,EAAE,MAAM,CAAC;KACpB,KAAK,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAgEzF;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,uEAAuE;IACvE,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAC7B,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;KACzB,KAAK,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,eAAe,CACpC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,qBAAqB,GAC3B,OAAO,CAAC,GAAG,EAAE,CAAC,CA8ChB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches historical logs from Radius with automatic pagination.
|
|
3
|
+
* Handles Radius's block range restrictions by splitting large queries into smaller chunks.
|
|
4
|
+
*
|
|
5
|
+
* @param client - The PublicClient to use
|
|
6
|
+
* @param params - Log query parameters with pagination
|
|
7
|
+
* @returns Array of all logs matching the query
|
|
8
|
+
* @throws Error if any chunk request fails
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createPublicClient, http } from 'viem';
|
|
13
|
+
* import { getLogs } from '@radiustechsystems/sdk/events';
|
|
14
|
+
* import { radiusTestnet } from '@radiustechsystems/sdk/chains';
|
|
15
|
+
*
|
|
16
|
+
* const client = createPublicClient({
|
|
17
|
+
* chain: radiusTestnet,
|
|
18
|
+
* transport: http(),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Fetch logs for a large block range
|
|
22
|
+
* const logs = await getLogs(client, {
|
|
23
|
+
* address: '0x...', // Contract address (required)
|
|
24
|
+
* fromBlock: 1000000n,
|
|
25
|
+
* toBlock: 1010000n, // 10,000 blocks
|
|
26
|
+
* chunkSize: 1000, // Query 1000 blocks at a time
|
|
27
|
+
* onProgress: ({ currentBlock, totalBlocks, logsFetched }) => {
|
|
28
|
+
* const percent = (Number(currentBlock) / Number(totalBlocks) * 100).toFixed(1);
|
|
29
|
+
* console.log(`Progress: ${percent}% (${logsFetched} logs)`);
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* console.log(`Found ${logs.length} total logs`);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* - Radius requires the address parameter (cannot query all contracts)
|
|
38
|
+
* - Radius restricts eth_getLogs to narrow block ranges
|
|
39
|
+
* - This function automatically splits large queries into smaller chunks
|
|
40
|
+
* - Default chunk size is 1000 blocks (adjust based on your needs)
|
|
41
|
+
* - If you get "block range is too wide" errors, reduce chunkSize
|
|
42
|
+
* - Progress callback is optional but useful for long-running queries
|
|
43
|
+
* - All requests are sequential to avoid rate limiting
|
|
44
|
+
* - Consider using WebSocket subscriptions for real-time monitoring instead
|
|
45
|
+
*/
|
|
46
|
+
export async function getLogs(client, params) {
|
|
47
|
+
const { address, fromBlock, toBlock, chunkSize = 1000, onProgress } = params;
|
|
48
|
+
// Validate parameters
|
|
49
|
+
if (fromBlock > toBlock) {
|
|
50
|
+
throw new Error('fromBlock must be less than or equal to toBlock');
|
|
51
|
+
}
|
|
52
|
+
if (chunkSize <= 0) {
|
|
53
|
+
throw new Error('chunkSize must be greater than 0');
|
|
54
|
+
}
|
|
55
|
+
const allLogs = [];
|
|
56
|
+
const totalBlocks = toBlock - fromBlock + 1n;
|
|
57
|
+
let chunksProcessed = 0;
|
|
58
|
+
// Process in chunks
|
|
59
|
+
for (let currentFrom = fromBlock; currentFrom <= toBlock; currentFrom += BigInt(chunkSize)) {
|
|
60
|
+
const currentTo = currentFrom + BigInt(chunkSize) - 1n > toBlock
|
|
61
|
+
? toBlock
|
|
62
|
+
: currentFrom + BigInt(chunkSize) - 1n;
|
|
63
|
+
// Build filter parameters
|
|
64
|
+
const filterParams = {
|
|
65
|
+
address,
|
|
66
|
+
fromBlock: currentFrom,
|
|
67
|
+
toBlock: currentTo,
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
// Fetch logs for this chunk
|
|
71
|
+
const chunkLogs = await client.getLogs(filterParams);
|
|
72
|
+
allLogs.push(...chunkLogs);
|
|
73
|
+
chunksProcessed++;
|
|
74
|
+
// Report progress
|
|
75
|
+
if (onProgress) {
|
|
76
|
+
onProgress({
|
|
77
|
+
currentBlock: currentTo,
|
|
78
|
+
totalBlocks,
|
|
79
|
+
chunksProcessed,
|
|
80
|
+
logsFetched: allLogs.length,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Provide helpful error message
|
|
86
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
87
|
+
if (errorMessage.includes('block range is too wide')) {
|
|
88
|
+
throw new Error(`Block range too wide. Current chunk size: ${chunkSize}. ` +
|
|
89
|
+
`Try reducing chunkSize. Range: ${currentFrom}-${currentTo}`);
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Failed to fetch logs for blocks ${currentFrom}-${currentTo}: ${errorMessage}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return allLogs;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Fetches historical logs with adaptive chunk sizing.
|
|
98
|
+
* Automatically reduces chunk size if "block range too wide" errors occur.
|
|
99
|
+
*
|
|
100
|
+
* @param client - The PublicClient to use
|
|
101
|
+
* @param params - Log query parameters with adaptive sizing
|
|
102
|
+
* @returns Array of all logs matching the query
|
|
103
|
+
* @throws Error if minimum chunk size is reached or other errors occur
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import { createPublicClient, http } from 'viem';
|
|
108
|
+
* import { getLogsAdaptive } from '@radiustechsystems/sdk/events';
|
|
109
|
+
* import { radiusTestnet } from '@radiustechsystems/sdk/chains';
|
|
110
|
+
*
|
|
111
|
+
* const client = createPublicClient({
|
|
112
|
+
* chain: radiusTestnet,
|
|
113
|
+
* transport: http(),
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // Fetch logs with automatic chunk size adjustment
|
|
117
|
+
* const logs = await getLogsAdaptive(client, {
|
|
118
|
+
* address: '0x...',
|
|
119
|
+
* fromBlock: 1000000n,
|
|
120
|
+
* toBlock: 1010000n,
|
|
121
|
+
* onProgress: ({ currentBlock, totalBlocks, currentChunkSize }) => {
|
|
122
|
+
* console.log(`Block ${currentBlock}/${totalBlocks} (chunk: ${currentChunkSize})`);
|
|
123
|
+
* },
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* - Starts with a large chunk size and reduces it if errors occur
|
|
129
|
+
* - Useful when you don't know the optimal chunk size for a network
|
|
130
|
+
* - Slower than getLogs with a known good chunk size
|
|
131
|
+
* - Use getLogs directly if you know a reliable chunk size
|
|
132
|
+
*/
|
|
133
|
+
export async function getLogsAdaptive(client, params) {
|
|
134
|
+
let currentChunkSize = params.initialChunkSize ?? 1000;
|
|
135
|
+
const minChunkSize = params.minChunkSize ?? 10;
|
|
136
|
+
while (currentChunkSize >= minChunkSize) {
|
|
137
|
+
try {
|
|
138
|
+
return await getLogs(client, {
|
|
139
|
+
address: params.address,
|
|
140
|
+
fromBlock: params.fromBlock,
|
|
141
|
+
toBlock: params.toBlock,
|
|
142
|
+
chunkSize: currentChunkSize,
|
|
143
|
+
onProgress: params.onProgress
|
|
144
|
+
? (progress) => {
|
|
145
|
+
params.onProgress?.({
|
|
146
|
+
...progress,
|
|
147
|
+
currentChunkSize,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
: undefined,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
const errorMessage = error instanceof Error ? error.message : '';
|
|
155
|
+
if (errorMessage.includes('block range is too wide') ||
|
|
156
|
+
errorMessage.includes('Try reducing chunkSize')) {
|
|
157
|
+
// Reduce chunk size and retry
|
|
158
|
+
currentChunkSize = Math.floor(currentChunkSize / 2);
|
|
159
|
+
if (currentChunkSize < minChunkSize) {
|
|
160
|
+
throw new Error(`Cannot fetch logs: minimum chunk size (${minChunkSize}) reached. Network requires smaller block ranges than supported.`);
|
|
161
|
+
}
|
|
162
|
+
// Continue loop with smaller chunk size
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
// Re-throw non-range-related errors
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
throw new Error('Failed to fetch logs: minimum chunk size reached');
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=getLogs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLogs.js","sourceRoot":"","sources":["../../events/getLogs.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAAoB,EAAE,MAAqB;IACxE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,G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G,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAEjE,IACC,YAAY,CAAC,QAAQ,CAAC,yBAAyB,CAAC;gBAChD,YAAY,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAC9C,CAAC;gBACF,8BAA8B;gBAC9B,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;gBAEpD,IAAI,gBAAgB,GAAG,YAAY,EAAE,CAAC;oBACrC,MAAM,IAAI,KAAK,CACd,0CAA0C,YAAY,kEAAkE,CACxH,CAAC;gBACH,CAAC;gBAED,wCAAwC;gBACxC,SAAS;YACV,CAAC;YAED,oCAAoC;YACpC,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event subscription and log querying utilities for Radius SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides WebSocket-based event subscriptions and historical log queries
|
|
5
|
+
* with Radius-specific optimizations and limitations handling.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module events
|
|
9
|
+
*/
|
|
10
|
+
export { createWebSocketTransport, type WebSocketTransportConfig, } from '../transport/websocket.js';
|
|
11
|
+
export { type DecodedEventLog, type DecodeEventLogsParameters, type DecodeEventLogsResult, decodeEventLogs, type FilterEventLogsParameters, filterEventLogs, } from './decodeEventLogs.js';
|
|
12
|
+
export { type GetLogsAdaptiveParams, type GetLogsParams, getLogs, getLogsAdaptive, } from './getLogs.js';
|
|
13
|
+
export { type ApprovalEvent, type WatchApprovalForAddressParameters, type WatchApprovalParameters, watchApproval, watchApprovalForAddress, } from './watchApproval.js';
|
|
14
|
+
export { DEFAULT_POLLING_INTERVAL_MS, type WatchBlockNumberParams, type WatchBlocksParams, type WatchPendingTransactionsParams, watchBlockNumber, watchBlocks, watchPendingTransactions, } from './watchBlock.js';
|
|
15
|
+
export { type WatchRawLogsParameters, watchLogs, watchRawLogs, } from './watchLogs.js';
|
|
16
|
+
export { type TransferEvent, type WatchTransferForAddressParameters, type WatchTransferParameters, watchTransfer, watchTransferForAddress, } from './watchTransfer.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACN,wBAAwB,EACxB,KAAK,wBAAwB,GAC7B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,eAAe,EACf,KAAK,yBAAyB,EAC9B,eAAe,GACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,OAAO,EACP,eAAe,GACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,iCAAiC,EACtC,KAAK,uBAAuB,EAC5B,aAAa,EACb,uBAAuB,GACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACN,2BAA2B,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,8BAA8B,EACnC,gBAAgB,EAChB,WAAW,EACX,wBAAwB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,KAAK,sBAAsB,EAC3B,SAAS,EACT,YAAY,GACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,iCAAiC,EACtC,KAAK,uBAAuB,EAC5B,aAAa,EACb,uBAAuB,GACvB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event subscription and log querying utilities for Radius SDK.
|
|
3
|
+
*
|
|
4
|
+
* This module provides WebSocket-based event subscriptions and historical log queries
|
|
5
|
+
* with Radius-specific optimizations and limitations handling.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module events
|
|
9
|
+
*/
|
|
10
|
+
// WebSocket transport
|
|
11
|
+
export { createWebSocketTransport, } from '../transport/websocket.js';
|
|
12
|
+
// Event decoding utilities
|
|
13
|
+
export { decodeEventLogs, filterEventLogs, } from './decodeEventLogs.js';
|
|
14
|
+
// Historical log queries
|
|
15
|
+
export { getLogs, getLogsAdaptive, } from './getLogs.js';
|
|
16
|
+
// ERC-20 Approval events
|
|
17
|
+
export { watchApproval, watchApprovalForAddress, } from './watchApproval.js';
|
|
18
|
+
// Block watching
|
|
19
|
+
export { DEFAULT_POLLING_INTERVAL_MS, watchBlockNumber, watchBlocks, watchPendingTransactions, } from './watchBlock.js';
|
|
20
|
+
// Generic log watching
|
|
21
|
+
export { watchLogs, watchRawLogs, } from './watchLogs.js';
|
|
22
|
+
// ERC-20 Transfer events
|
|
23
|
+
export { watchTransfer, watchTransferForAddress, } from './watchTransfer.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,sBAAsB;AACtB,OAAO,EACN,wBAAwB,GAExB,MAAM,2BAA2B,CAAC;AACnC,2BAA2B;AAC3B,OAAO,EAIN,eAAe,EAEf,eAAe,GACf,MAAM,sBAAsB,CAAC;AAC9B,yBAAyB;AACzB,OAAO,EAGN,OAAO,EACP,eAAe,GACf,MAAM,cAAc,CAAC;AACtB,yBAAyB;AACzB,OAAO,EAIN,aAAa,EACb,uBAAuB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,iBAAiB;AACjB,OAAO,EACN,2BAA2B,EAI3B,gBAAgB,EAChB,WAAW,EACX,wBAAwB,GACxB,MAAM,iBAAiB,CAAC;AACzB,uBAAuB;AACvB,OAAO,EAEN,SAAS,EACT,YAAY,GACZ,MAAM,gBAAgB,CAAC;AACxB,yBAAyB;AACzB,OAAO,EAIN,aAAa,EACb,uBAAuB,GACvB,MAAM,oBAAoB,CAAC"}
|