@tuwaio/pulsar-core 1.0.0-alpha.4.815bc21.acc55b8.30fab03 → 1.0.0-alpha.6.815bc21.acc55b8.ff59e86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -9,108 +9,107 @@ import { PersistOptions } from 'zustand/middleware';
9
9
  */
10
10
 
11
11
  /**
12
- * A utility type for creating modular Zustand store slices.
13
- * @template T The state slice type.
14
- * @template E The full store state type, defaults to T.
12
+ * A utility type for creating modular Zustand store slices, enabling composable state management.
13
+ * @template T - The type of the state slice.
14
+ * @template S - The type of the full store state, defaulting to T.
15
15
  */
16
- type StoreSlice<T extends object, E extends object = T> = (set: StoreApi<E extends T ? E : E & T>['setState'], get: StoreApi<E extends T ? E : E & T>['getState']) => T;
16
+ type StoreSlice<T extends object, S extends object = T> = (set: StoreApi<S extends T ? S : S & T>['setState'], get: StoreApi<S extends T ? S : S & T>['getState']) => T;
17
17
  /**
18
- * Represents the blockchain adapter for a transaction.
18
+ * Defines the supported blockchain adapters. Each adapter corresponds to a specific chain architecture.
19
19
  */
20
20
  declare enum TransactionAdapter {
21
- /** EVM adapter. */
21
+ /** For Ethereum Virtual Machine (EVM) compatible chains like Ethereum, Polygon, etc. */
22
22
  EVM = "evm",
23
- /** Solana adapter. */
23
+ /** For the Solana blockchain. */
24
24
  SOLANA = "solana",
25
- /** Starknet adapter. */
26
- Starknet = "Starknet"
25
+ /** For the Starknet L2 network. */
26
+ Starknet = "starknet"
27
27
  }
28
28
  /**
29
- * Represents the final status of a transaction.
29
+ * Represents the terminal status of a transaction after it has been processed.
30
30
  */
31
31
  declare enum TransactionStatus {
32
- /** The transaction failed to execute. */
32
+ /** The transaction failed to execute due to an on-chain error or rejection. */
33
33
  Failed = "Failed",
34
34
  /** The transaction was successfully mined and executed. */
35
35
  Success = "Success",
36
- /** The transaction was replaced by another (e.g., speed-up). */
36
+ /** The transaction was replaced by another with the same nonce (e.g., a speed-up or cancel). */
37
37
  Replaced = "Replaced"
38
38
  }
39
39
  /**
40
- * The base structure for any transaction being tracked.
41
- * @template T The type of the tracker identifier (e.g., 'evm', 'safe').
40
+ * The fundamental structure for any transaction being tracked by Pulsar.
41
+ * This forms the base upon which chain-specific transaction types are built.
42
+ * @template T - The type of the tracker identifier (e.g., 'ethereum', 'gelato', 'safe').
42
43
  */
43
44
  type BaseTransaction<T> = {
44
- /** A key identifying the retry logic for this transaction from the actions registry. */
45
+ /** A unique key identifying a re-executable action from the `TxActions` registry. */
45
46
  actionKey?: string;
46
47
  /** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */
47
48
  chainId: number | string;
48
- /** A description for the transaction, with states for [pending, success, error, replaced]. */
49
+ /** A user-facing description. Can be a single string or an array for [pending, success, error, replaced] states. */
49
50
  description?: string | [string, string, string, string];
50
- /** An error message if the transaction failed. */
51
+ /** The error message if the transaction failed. */
51
52
  errorMessage?: string;
52
- /** The timestamp (in seconds) when the transaction was finalized on-chain. */
53
+ /** The on-chain timestamp (in seconds) when the transaction was finalized. */
53
54
  finishedTimestamp?: number;
54
- /** The sender's address. */
55
+ /** The sender's wallet address. */
55
56
  from: string;
56
57
  /** A flag indicating if the transaction is in a failed state. */
57
58
  isError?: boolean;
58
- /** A flag indicating if the detailed tracking modal should be open for this transaction. For UI purposes. */
59
+ /** A UI flag to control the visibility of a detailed tracking modal for this transaction. */
59
60
  isTrackedModalOpen?: boolean;
60
- /** The local timestamp (in seconds) when the transaction was initiated. */
61
+ /** The local timestamp (in seconds) when the transaction was initiated by the user. */
61
62
  localTimestamp: number;
62
- /** Any additional data associated with the transaction. */
63
+ /** Any additional, custom data associated with the transaction. */
63
64
  payload?: object;
64
- /** Indicates if the transaction is still pending confirmation. */
65
+ /** A flag indicating if the transaction is still awaiting on-chain confirmation. */
65
66
  pending: boolean;
66
- /** The final status of the transaction. */
67
+ /** The final on-chain status of the transaction. */
67
68
  status?: TransactionStatus;
68
- /** A title for the transaction, with states for [pending, success, error, replaced]. */
69
+ /** A user-facing title. Can be a single string or an array for [pending, success, error, replaced] states. */
69
70
  title?: string | [string, string, string, string];
70
- /** The specific tracker responsible for monitoring this transaction (e.g., 'evm', 'safe', 'gelato', etc.). */
71
+ /** The specific tracker responsible for monitoring this transaction's status. */
71
72
  tracker: T;
72
- /** The unique key for the transaction within its tracker (e.g., EVM hash, Gelato task ID). */
73
+ /** The unique identifier for the transaction (e.g., EVM hash, Gelato task ID). */
73
74
  txKey: string;
74
- /** The type or category of the transaction (e.g., 'increment', 'approve'). */
75
+ /** The application-specific type or category of the transaction (e.g., 'SWAP', 'APPROVE'). */
75
76
  type: string;
76
- /** The type of wallet used for the transaction. */
77
+ /** The type of wallet used to sign the transaction (e.g., 'injected', 'walletConnect'). */
77
78
  walletType: string;
78
79
  };
79
80
  /**
80
- * Represents an EVM-specific transaction, extending the base properties.
81
- * @template T The type of the tracker identifier.
81
+ * Represents an EVM-specific transaction, extending the base properties with EVM fields.
82
+ * @template T - The type of the tracker identifier.
82
83
  */
83
84
  type EvmTransaction<T> = BaseTransaction<T> & {
84
- /** The transaction adapter type. */
85
85
  adapter: TransactionAdapter.EVM;
86
86
  /** The on-chain transaction hash, available after submission. */
87
- hash?: string;
88
- /** The data payload for the transaction, typically for contract interactions. */
89
- input?: string;
90
- /** The maximum fee per gas for the transaction (EIP-1559). */
87
+ hash?: `0x${string}`;
88
+ /** The data payload for the transaction, typically for smart contract interactions. */
89
+ input?: `0x${string}`;
90
+ /** The maximum fee per gas for an EIP-1559 transaction (in wei). */
91
91
  maxFeePerGas?: string;
92
- /** The maximum priority fee per gas for the transaction (EIP-1559). */
92
+ /** The maximum priority fee per gas for an EIP-1559 transaction (in wei). */
93
93
  maxPriorityFeePerGas?: string;
94
- /** The transaction nonce. */
94
+ /** The transaction nonce, a sequential number for the sender's account. */
95
95
  nonce?: number;
96
- /** The hash of a transaction that this one replaced (e.g., for speed-up). */
97
- replacedTxHash?: string;
98
- /** The recipient's address. */
99
- to?: string;
100
- /** The value (in wei) being sent with the transaction. */
96
+ /** The hash of a transaction that this one replaced. */
97
+ replacedTxHash?: `0x${string}`;
98
+ /** The recipient's address or contract address. */
99
+ to?: `0x${string}`;
100
+ /** The amount of native currency (in wei) being sent. */
101
101
  value?: string;
102
102
  };
103
103
  /**
104
104
  * Represents a Solana-specific transaction, extending the base properties.
105
- * @template T The type of the tracker identifier.
105
+ * @template T - The type of the tracker identifier.
106
106
  */
107
107
  type SolanaTransaction<T> = BaseTransaction<T> & {
108
- /** The transaction adapter type. */
109
108
  adapter: TransactionAdapter.SOLANA;
110
- /** The transaction fee. */
109
+ /** The transaction fee in lamports. */
111
110
  fee?: number;
112
111
  /** The instructions included in the transaction. */
113
- instructions?: any[];
112
+ instructions?: unknown[];
114
113
  /** The recent blockhash used for the transaction. */
115
114
  recentBlockhash?: string;
116
115
  /** The slot in which the transaction was processed. */
@@ -118,9 +117,10 @@ type SolanaTransaction<T> = BaseTransaction<T> & {
118
117
  };
119
118
  /**
120
119
  * Represents a Starknet-specific transaction, extending the base properties.
121
- * @template T The type of the tracker identifier.
120
+ * @template T - The type of the tracker identifier.
122
121
  */
123
122
  type StarknetTransaction<T> = BaseTransaction<T> & {
123
+ adapter: TransactionAdapter.Starknet;
124
124
  /** The actual fee paid for the transaction. */
125
125
  actualFee?: {
126
126
  amount: string;
@@ -128,107 +128,114 @@ type StarknetTransaction<T> = BaseTransaction<T> & {
128
128
  };
129
129
  /** The address of the contract being interacted with. */
130
130
  contractAddress?: string;
131
- /** The transaction adapter type. */
132
- adapter: TransactionAdapter.Starknet;
133
131
  /** The reason for transaction failure, if applicable. */
134
132
  revertReason?: string;
135
133
  };
136
- /** A union type representing any possible transaction structure. */
134
+ /** A union type representing any possible transaction structure that Pulsar can handle. */
137
135
  type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;
138
- /** A registry of functions that can be re-executed via the 'Retry' button. The key should match `actionKey` on a transaction. */
136
+ /**
137
+ * A registry of functions that can be re-executed, keyed by `actionKey`.
138
+ * Used for implementing "Retry" functionality.
139
+ */
139
140
  type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;
140
141
  /**
141
- * Represents the parameters required to initiate a new transaction.
142
+ * Represents the parameters required to initiate a new transaction tracking flow.
142
143
  */
143
144
  type InitialTransactionParams = {
144
- /** The transaction adapter type. */
145
145
  adapter: TransactionAdapter;
146
- /** A key identifying the retry logic from the actions registry. */
146
+ /** A key to identify the re-executable action from the `TxActions` registry. */
147
147
  actionKey?: string;
148
- /** A description for the transaction, with states for [pending, success, error, replaced]. */
148
+ /** A user-facing description for the transaction. */
149
149
  description?: string | [string, string, string, string];
150
- /** The ID of the desired blockchain network. */
150
+ /** The target chain ID for the transaction. */
151
151
  desiredChainID: number | string;
152
- /** Any additional data to be associated with the transaction. */
152
+ /** Any custom data to associate with the transaction. */
153
153
  payload?: object;
154
- /** A title for the transaction, with states for [pending, success, error, replaced]. */
154
+ /** A user-facing title for the transaction. */
155
155
  title?: string | [string, string, string, string];
156
- /** The type or category of the transaction (e.g., 'increment', 'approve'). */
156
+ /** The application-specific type of the transaction. */
157
157
  type: string;
158
- /** If true, the detailed tracking modal will open automatically for this transaction. */
158
+ /** If true, the detailed tracking modal will open automatically upon initiation. */
159
159
  withTrackedModal?: boolean;
160
160
  };
161
161
  /**
162
- * Represents a transaction in its initial, pre-submission state within the store.
162
+ * Represents a transaction in its temporary, pre-submission state.
163
163
  * This is used for UI feedback while the transaction is being signed and sent.
164
164
  */
165
165
  type InitialTransaction = InitialTransactionParams & {
166
- /** An error message if the initialization process fails (e.g., user rejects signature). */
166
+ /** An error message if the initialization fails (e.g., user rejects signature). */
167
167
  errorMessage?: string;
168
- /** True if the transaction is currently being processed (e.g., waiting for user signature). */
168
+ /** A flag indicating if the transaction is being processed (e.g., waiting for signature). */
169
169
  isInitializing: boolean;
170
- /** The key of the on-chain transaction that this action produced, used for linking. */
170
+ /** The `txKey` of the on-chain transaction that this action produced, used for linking the states. */
171
171
  lastTxKey?: string;
172
172
  /** The local timestamp when the user initiated the action. */
173
173
  localTimestamp: number;
174
174
  };
175
175
  /**
176
- * Represents the type for a transaction adapter which provides utilities for handling transaction-related operations.
177
- *
178
- * @template TR - Represents the transaction tracker type.
179
- * @template T - Represents the type of the transaction, extending the base Transaction<TR>.
180
- * @template A - Represents the type for the action transaction key.
176
+ * Defines the interface for a transaction adapter, which provides chain-specific logic and utilities.
177
+ * @template TR - The type of the tracker identifier (e.g., a string enum).
178
+ * @template T - The specific transaction type, extending `Transaction<TR>`.
179
+ * @template A - The type of the key returned by the `actionFunction` (e.g., a transaction hash).
181
180
  */
182
181
  type TxAdapter<TR, T extends Transaction<TR>, A> = {
182
+ /** The unique key identifying this adapter. */
183
183
  key: TransactionAdapter;
184
+ /** Returns information about the currently connected wallet. */
184
185
  getWalletInfo: () => {
185
- /** Wallet address. */
186
186
  walletAddress: string;
187
- /** Type of the wallet. (injected, wallet connect, etc.) */
188
187
  walletType: string;
189
188
  };
189
+ /** Ensures the connected wallet is on the correct network for the transaction. */
190
190
  checkChainForTx: (chainId: string | number) => Promise<void>;
191
+ /** Determines the appropriate tracker and final `txKey` based on the result of an action. */
191
192
  checkTransactionsTracker: (actionTxKey: A, walletType: string) => {
192
193
  txKey: string;
193
194
  tracker: TR;
194
195
  };
195
- checkAndInitializeTrackerInStore: ({ tx, ...rest }: {
196
+ /** Initializes the correct background tracker for a given transaction. */
197
+ checkAndInitializeTrackerInStore: (params: {
196
198
  tx: T;
197
199
  } & Pick<ITxTrackingStore<TR, T, A>, 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'>) => Promise<void>;
200
+ /** Returns the base URL for the blockchain explorer. */
198
201
  getExplorerUrl: () => string | undefined;
202
+ /** Optional: Logic to cancel a pending EVM transaction. */
199
203
  cancelTxAction?: (tx: T) => Promise<string>;
204
+ /** Optional: Logic to speed up a pending EVM transaction. */
200
205
  speedUpTxAction?: (tx: T) => Promise<string>;
201
- retryTxAction?: ({ tx, actions, onClose, handleTransaction, }: {
206
+ /** Optional: Logic to retry a failed transaction. */
207
+ retryTxAction?: (params: {
202
208
  txKey: string;
203
209
  tx: InitialTransactionParams;
204
210
  actions?: TxActions;
205
211
  onClose: (txKey?: string) => void;
206
212
  } & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;
213
+ /** Optional: Constructs a full explorer URL for a specific transaction. */
207
214
  getExplorerTxUrl?: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;
208
215
  };
209
216
  /**
210
- * Interface for the complete transaction tracking store.
211
- * @template TR The type of the tracker identifier.
212
- * @template T The transaction type.
213
- * @template C The configuration object type (e.g., wagmi config).
214
- * @template A The return type of the action function being wrapped.
217
+ * The complete interface for the Pulsar transaction tracking store.
218
+ * @template TR - The type of the tracker identifier.
219
+ * @template T - The transaction type.
220
+ * @template A - The return type of the `actionFunction`.
215
221
  */
216
222
  type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {
217
223
  /**
218
- * A wrapper function that handles the entire lifecycle of a transaction.
219
- * It creates an `InitialTransaction`, executes the on-chain action, and tracks its status.
224
+ * The core function that handles the entire lifecycle of a new transaction.
225
+ * It manages UI state, executes the on-chain action, and initiates background tracking.
220
226
  * @param params - The parameters for handling the transaction.
221
227
  */
222
228
  handleTransaction: (params: {
223
- /** The async function to execute (e.g., a smart contract write call). */
229
+ /** The async function to execute (e.g., a smart contract write call). Must return a unique key or undefined. */
224
230
  actionFunction: () => Promise<A | undefined>;
225
- /** The metadata for the transaction to be created, of type `InitialTransactionParams`. */
231
+ /** The metadata for the transaction. */
226
232
  params: InitialTransactionParams;
233
+ /** The default tracker to use if it cannot be determined automatically. */
227
234
  defaultTracker?: TR;
228
235
  }) => Promise<void>;
229
236
  /**
230
- * Initializes all active trackers for pending transactions in the pool.
231
- * This is useful for resuming tracking after a page reload.
237
+ * Initializes trackers for all pending transactions in the pool.
238
+ * This is essential for resuming tracking after a page reload.
232
239
  */
233
240
  initializeTransactionsPool: () => Promise<void>;
234
241
  };
@@ -249,14 +256,14 @@ type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;
249
256
  * that are updatable via the `updateTxParams` action.
250
257
  * @template TR - The type of the tracker identifier.
251
258
  */
252
- type UpdatedParamsFields<TR> = Pick<EvmTransaction<TR>, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'errorMessage' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>;
259
+ type UpdatableTransactionFields<TR> = Partial<Pick<EvmTransaction<TR>, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'errorMessage' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>>;
253
260
  /**
254
261
  * Defines the interface for the base transaction tracking store slice.
255
262
  * It includes the state and actions for managing transactions.
256
263
  * @template TR - The type of the tracker identifier.
257
264
  * @template T - The transaction type.
258
265
  */
259
- type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {
266
+ interface IInitializeTxTrackingStore<TR, T extends Transaction<TR>> {
260
267
  /** An optional callback function to be executed when a transaction successfully completes. */
261
268
  onSucceedCallbacks?: (tx: T) => Promise<void> | void;
262
269
  /** A pool of all transactions currently being tracked, indexed by their `txKey`. */
@@ -266,18 +273,16 @@ type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {
266
273
  /** The state of a transaction that is currently being initiated but not yet submitted. */
267
274
  initialTx?: InitialTransaction;
268
275
  /** Adds a new transaction to the tracking pool. */
269
- addTxToPool: ({ tx }: {
270
- tx: T;
271
- }) => void;
276
+ addTxToPool: (tx: T) => void;
272
277
  /** Updates one or more parameters of an existing transaction in the pool. */
273
- updateTxParams: (fields: UpdatedParamsFields<TR>) => void;
278
+ updateTxParams: (txKey: string, fields: UpdatableTransactionFields<TR>) => void;
274
279
  /** Removes a transaction from the tracking pool using its key. */
275
280
  removeTxFromPool: (txKey: string) => void;
276
281
  /** Closes the tracking modal for a specific transaction. */
277
282
  closeTxTrackedModal: (txKey?: string) => void;
278
283
  /** Returns the key of the last transaction that was added to the pool. */
279
284
  getLastTxKey: () => string | undefined;
280
- };
285
+ }
281
286
  /**
282
287
  * Creates a Zustand store slice containing the core logic for transaction tracking.
283
288
  * This function is a slice creator and is meant to be used within `createStore` from Zustand.
@@ -291,91 +296,118 @@ declare function initializeTxTrackingStore<TR, T extends Transaction<TR>>({ onSu
291
296
 
292
297
  /**
293
298
  * @file This file contains selector functions for deriving state from the transaction tracking store.
294
- * Selectors help abstract away the shape of the state and provide memoized, efficient access to computed data.
299
+ * Selectors help abstract the state's shape and provide efficient, memoized access to computed data.
295
300
  */
296
301
 
297
302
  /**
298
- * Selects all transactions from the pool and sorts them by their creation timestamp.
303
+ * Selects all transactions from the pool and sorts them by their creation timestamp in ascending order.
299
304
  * @template TR - The type of the tracker identifier.
300
305
  * @template T - The transaction type.
301
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
306
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
302
307
  * @returns {T[]} An array of all transactions, sorted chronologically.
303
308
  */
304
309
  declare const selectAllTransactions: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>) => T[];
305
310
  /**
306
- * Selects all transactions that are currently in a pending state.
311
+ * Selects all transactions that are currently in a pending state, sorted chronologically.
307
312
  * @template TR - The type of the tracker identifier.
308
313
  * @template T - The transaction type.
309
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
314
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
310
315
  * @returns {T[]} An array of pending transactions.
311
316
  */
312
317
  declare const selectPendingTransactions: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>) => T[];
313
318
  /**
314
- * Selects a single transaction from the pool by its unique transaction key (`txKey`).
315
- * This is the most direct way to retrieve a transaction.
319
+ * Selects a single transaction from the pool by its unique key (`txKey`).
316
320
  * @template TR - The type of the tracker identifier.
317
321
  * @template T - The transaction type.
318
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
322
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
319
323
  * @param {string} key - The `txKey` of the transaction to retrieve.
320
324
  * @returns {T | undefined} The transaction object if found, otherwise undefined.
321
325
  */
322
- declare const selectTXByKey: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, key: string) => T | undefined;
326
+ declare const selectTxByKey: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, key: string) => T | undefined;
323
327
  /**
324
- * Selects all transactions initiated by a specific wallet address.
328
+ * Selects all transactions initiated by a specific wallet address, sorted chronologically.
325
329
  * @template TR - The type of the tracker identifier.
326
330
  * @template T - The transaction type.
327
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
331
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
328
332
  * @param {string} from - The wallet address (`from` address) to filter transactions by.
329
333
  * @returns {T[]} An array of transactions associated with the given wallet.
330
334
  */
331
335
  declare const selectAllTransactionsByActiveWallet: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, from: string) => T[];
332
336
  /**
333
- * Selects all pending transactions initiated by a specific wallet address.
337
+ * Selects all pending transactions for a specific wallet address, sorted chronologically.
334
338
  * @template TR - The type of the tracker identifier.
335
339
  * @template T - The transaction type.
336
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
340
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
337
341
  * @param {string} from - The wallet address (`from` address) to filter transactions by.
338
- * @returns {T[]} An array of pending transactions associated with the given wallet.
342
+ * @returns {T[]} An array of pending transactions for the given wallet.
339
343
  */
340
344
  declare const selectPendingTransactionsByActiveWallet: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, from: string) => T[];
341
345
 
346
+ /**
347
+ * Creates the main Pulsar store for transaction tracking.
348
+ *
349
+ * This function sets up a Zustand store with persistence, combining the core
350
+ * transaction slice with adapter-specific logic to handle the entire lifecycle
351
+ * of a transaction.
352
+ *
353
+ * @template TR - The type of the tracker identifier (e.g., a string enum).
354
+ * @template T - The specific transaction type, extending the base `Transaction`.
355
+ * @template A - The type for the adapter-specific context or API.
356
+ *
357
+ * @param {object} config - Configuration object for creating the store.
358
+ * @param {function} [config.onSucceedCallbacks] - Optional async callback executed on transaction success.
359
+ * @param {TxAdapter<TR, T, A>[]} config.adapters - An array of adapters for different transaction types or chains.
360
+ * @param {PersistOptions<ITxTrackingStore<TR, T, A>>} [options] - Configuration for the Zustand persist middleware.
361
+ * @returns A fully configured Zustand store instance.
362
+ */
342
363
  declare function createPulsarStore<TR, T extends Transaction<TR>, A>({ onSucceedCallbacks, adapters, ...options }: {
343
364
  onSucceedCallbacks?: (tx: T) => Promise<void> | void;
344
365
  adapters: TxAdapter<TR, T, A>[];
345
- } & PersistOptions<ITxTrackingStore<TR, T, A>>): Omit<zustand.StoreApi<ITxTrackingStore<TR, T, A>>, "persist"> & {
366
+ } & PersistOptions<ITxTrackingStore<TR, T, A>>): Omit<zustand.StoreApi<ITxTrackingStore<TR, T, A>>, "setState" | "persist"> & {
367
+ setState(partial: ITxTrackingStore<TR, T, A> | Partial<ITxTrackingStore<TR, T, A>> | ((state: ITxTrackingStore<TR, T, A>) => ITxTrackingStore<TR, T, A> | Partial<ITxTrackingStore<TR, T, A>>), replace?: false | undefined): unknown;
368
+ setState(state: ITxTrackingStore<TR, T, A> | ((state: ITxTrackingStore<TR, T, A>) => ITxTrackingStore<TR, T, A>), replace: true): unknown;
346
369
  persist: {
347
- setOptions: (options: Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>>>) => void;
370
+ setOptions: (options: Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>, unknown>>) => void;
348
371
  clearStorage: () => void;
349
372
  rehydrate: () => Promise<void> | void;
350
373
  hasHydrated: () => boolean;
351
374
  onHydrate: (fn: (state: ITxTrackingStore<TR, T, A>) => void) => () => void;
352
375
  onFinishHydration: (fn: (state: ITxTrackingStore<TR, T, A>) => void) => () => void;
353
- getOptions: () => Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>>>;
376
+ getOptions: () => Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>, unknown>>;
354
377
  };
355
378
  };
356
379
 
357
380
  /**
358
- * @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.
359
- * This is a recommended pattern for using vanilla stores with React to ensure full type safety.
381
+ * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
382
+ * This pattern is recommended by the official Zustand documentation to ensure full type
383
+ * safety when integrating vanilla stores with React.
360
384
  *
361
- * @see https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
385
+ * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
362
386
  */
363
387
 
364
388
  /**
365
- * A utility type to infer the state shape from a Zustand store type.
366
- * @template S The type of the Zustand store (`StoreApi`).
389
+ * A utility type that infers the state shape from a Zustand `StoreApi`.
390
+ * It extracts the return type of the `getState` method.
391
+ * @template S - The type of the Zustand store (`StoreApi`).
367
392
  */
368
393
  type ExtractState<S> = S extends {
369
- getState: () => infer X;
370
- } ? X : never;
394
+ getState: () => infer T;
395
+ } ? T : never;
371
396
  /**
372
- * Creates a bounded `useStore` hook from a vanilla Zustand store instance.
373
- * The returned hook is fully typed and can be used with or without a selector.
397
+ * Creates a bounded `useStore` hook from a vanilla Zustand store.
398
+ *
399
+ * This function takes a vanilla Zustand store instance and returns a React hook
400
+ * that is pre-bound to that store. This approach provides a cleaner API and
401
+ * enhances type inference, eliminating the need to pass the store instance
402
+ * on every use.
374
403
  *
375
- * @template S The type of the Zustand store (`StoreApi`).
376
- * @param {S} store - The vanilla Zustand store instance.
377
- * @returns {function} A hook that can be called with an optional selector function.
378
- * - When called with a selector (`useBoundedStore(state => state.someValue)`), it returns the selected slice of the state.
404
+ * The returned hook supports two signatures:
405
+ * 1. `useBoundedStore()`: Selects the entire state.
406
+ * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
407
+ *
408
+ * @template S - The type of the Zustand store (`StoreApi`).
409
+ * @param {S} store - The vanilla Zustand store instance to bind the hook to.
410
+ * @returns {function} A fully typed React hook for accessing the store's state.
379
411
  */
380
412
  declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
381
413
  (): ExtractState<S>;
@@ -383,82 +415,99 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
383
415
  };
384
416
 
385
417
  /**
386
- * @file This file contains a generic utility for creating a polling mechanism to track asynchronous tasks,
387
- * such as API-based transaction status checks (e.g., for Gelato or Safe).
418
+ * @file This file provides a generic utility for creating a polling mechanism to track
419
+ * asynchronous tasks, such as API-based transaction status checks (e.g., for Gelato or Safe).
388
420
  */
389
421
 
422
+ /**
423
+ * Defines the parameters for the fetcher function used within the polling tracker.
424
+ * The fetcher is the core logic that performs the actual API call.
425
+ * @template R - The expected type of the successful API response.
426
+ * @template T - The type of the transaction object being tracked.
427
+ */
428
+ type PollingFetcherParams<R, T> = {
429
+ /** The transaction object being tracked. */
430
+ tx: T;
431
+ /** A callback to stop the polling mechanism, typically called on success or terminal failure. */
432
+ stopPolling: (options?: {
433
+ withoutRemoving?: boolean;
434
+ }) => void;
435
+ /** Callback to be invoked when the fetcher determines the transaction has succeeded. */
436
+ onSuccess: (response: R) => void;
437
+ /** Callback to be invoked when the fetcher determines the transaction has failed. */
438
+ onFailure: (response?: R) => void;
439
+ /** Optional callback for each successful poll, useful for updating UI with intermediate states. */
440
+ onIntervalTick?: (response: R) => void;
441
+ /** Optional callback for when a transaction is replaced (e.g., speed-up). */
442
+ onReplaced?: (response: R) => void;
443
+ };
390
444
  /**
391
445
  * Defines the configuration object for the `initializePollingTracker` function.
392
- * @template R The expected type of the successful API response from the fetcher.
393
- * @template T The type of the transaction object being tracked.
394
- * @template TR The type of the tracker identifier used in the `Transaction` type.
395
- */
396
- type InitializePollingTracker<R, T, TR> = {
397
- /** The transaction object to be tracked. It must include `txKey` and an optional `pending` status. */
398
- tx: T & Pick<Transaction<TR>, 'txKey'> & {
399
- pending?: boolean;
400
- };
401
- /** The function that performs the actual data fetching (e.g., an API call). */
402
- fetcher: (params: {
403
- /** The transaction object being tracked. */
404
- tx: T;
405
- /** A callback to stop the polling mechanism, typically called on success or terminal failure. */
406
- clearWatch: (withoutRemoving?: boolean) => void;
407
- /** Callback to be invoked when the fetcher determines the transaction has succeeded. */
408
- onSucceed: (response: R) => void;
409
- /** Callback to be invoked when the fetcher determines the transaction has failed. */
410
- onFailed: (response: R) => void;
411
- /** Optional callback for each successful poll, useful for updating UI with intermediate states. */
412
- onIntervalTick?: (response: R) => void;
413
- /** Optional callback for when a transaction is replaced by another. */
414
- onReplaced?: (response: R) => void;
415
- }) => Promise<Response>;
446
+ * @template R - The expected type of the successful API response.
447
+ * @template T - The type of the transaction object.
448
+ * @template TR - The type of the tracker identifier.
449
+ */
450
+ type PollingTrackerConfig<R, T, TR> = {
451
+ /** The transaction object to be tracked. It must include `txKey` and `pending` status. */
452
+ tx: T & Pick<Transaction<TR>, 'txKey' | 'pending'>;
453
+ /** The function that performs the data fetching (e.g., an API call) on each interval. */
454
+ fetcher: (params: PollingFetcherParams<R, T>) => Promise<void>;
455
+ /** Callback to be invoked when the transaction successfully completes. */
456
+ onSuccess: (response: R) => void;
457
+ /** Callback to be invoked when the transaction fails. */
458
+ onFailure: (response?: R) => void;
416
459
  /** Optional callback executed once when the tracker is initialized. */
417
460
  onInitialize?: () => void;
418
- /** Callback to be invoked when the transaction has succeeded. */
419
- onSucceed: (response: R) => void;
420
- /** Callback to be invoked when the transaction has failed. */
421
- onFailed: (response: R) => void;
422
461
  /** Optional callback for each successful poll. */
423
462
  onIntervalTick?: (response: R) => void;
424
463
  /** Optional callback for when a transaction is replaced. */
425
464
  onReplaced?: (response: R) => void;
426
465
  /** Optional function to remove the transaction from the main pool, typically after polling stops. */
427
- removeTxFromPool?: (taskId: string) => void;
466
+ removeTxFromPool?: (txKey: string) => void;
428
467
  /** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */
429
468
  pollingInterval?: number;
430
469
  /** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */
431
- retryCount?: number;
470
+ maxRetries?: number;
432
471
  };
433
472
  /**
434
473
  * Initializes a generic polling tracker that repeatedly calls a fetcher function
435
- * to monitor the status of a transaction or any asynchronous task.
474
+ * to monitor the status of an asynchronous task.
436
475
  *
437
- * @template R The expected type of the successful API response.
476
+ * This function handles the lifecycle of polling, including starting, stopping,
477
+ * and automatic termination after a certain number of failed attempts.
478
+ *
479
+ * @template R The expected type of the API response.
438
480
  * @template T The type of the transaction object.
439
481
  * @template TR The type of the tracker identifier.
440
- * @param {InitializePollingTracker<R, T, TR>} params - The configuration object for the tracker.
441
- * @returns {Promise<void>} A promise that resolves when the tracker is set up (note: polling happens asynchronously).
482
+ * @param {PollingTrackerConfig<R, T, TR>} config - The configuration for the tracker.
483
+ */
484
+ declare function initializePollingTracker<R, T, TR>(config: PollingTrackerConfig<R, T, TR>): void;
485
+
486
+ /**
487
+ * @file This file contains a utility function for selecting a specific transaction adapter from a list.
442
488
  */
443
- declare function initializePollingTracker<R, T, TR>({ onInitialize, tx, removeTxFromPool, fetcher, onFailed, onIntervalTick, onSucceed, pollingInterval, retryCount, onReplaced, }: InitializePollingTracker<R, T, TR>): Promise<void>;
444
489
 
445
490
  /**
446
- * Selects and returns a transaction adapter from a list of adapters based on the provided adapter key.
447
- * If no matching adapter is found, the first adapter in the list is returned as a fallback.
491
+ * Selects a transaction adapter from a list based on a provided key.
448
492
  *
449
- * @template TR - Represents the transaction response type.
450
- * @template T - Extends the Transaction type and represents the transaction entity.
451
- * @template A - Represents the adapter type.
493
+ * This function searches through an array of `TxAdapter` instances and returns the one
494
+ * that matches the given `adapterKey`. If no specific adapter is found, it logs a warning
495
+ * and returns the first adapter in the array as a fallback. This fallback mechanism
496
+ * ensures that the system can still function, but it highlights a potential configuration issue.
497
+ *
498
+ * @template TR - The type of the tracker identifier.
499
+ * @template T - The transaction type, extending the base `Transaction`.
500
+ * @template A - The type for the adapter-specific context or API.
452
501
  *
453
- * @param {Object} params - Configuration object for selecting the adapter.
454
- * @param {TransactionAdapter} params.adapterKey - The key used to identify the desired transaction adapter.
502
+ * @param {object} params - The parameters for the selection.
503
+ * @param {TransactionAdapter} params.adapterKey - The key of the desired adapter.
455
504
  * @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.
456
505
  *
457
- * @returns {TxAdapter<TR, T, A>} The transaction adapter corresponding to the provided key, or the first adapter in the list.
506
+ * @returns {TxAdapter<TR, T, A> | undefined} The found transaction adapter, the fallback adapter, or undefined if the adapters array is empty.
458
507
  */
459
508
  declare const selectAdapterByKey: <TR, T extends Transaction<TR>, A>({ adapterKey, adapters, }: {
460
509
  adapterKey: TransactionAdapter;
461
510
  adapters: TxAdapter<TR, T, A>[];
462
- }) => TxAdapter<TR, T, A>;
511
+ }) => TxAdapter<TR, T, A> | undefined;
463
512
 
464
- export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type InitializePollingTracker, type SolanaTransaction, type StarknetTransaction, type StoreSlice, type Transaction, TransactionAdapter, type TransactionPool, TransactionStatus, type TxActions, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAdapterByKey, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTXByKey };
513
+ export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type PollingTrackerConfig, type SolanaTransaction, type StarknetTransaction, type StoreSlice, type Transaction, TransactionAdapter, type TransactionPool, TransactionStatus, type TxActions, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAdapterByKey, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTxByKey };