@tuwaio/pulsar-core 0.0.4 → 0.0.5

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,88 +128,118 @@ 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
136
  /**
139
- * Represents the parameters required to initiate a new transaction.
137
+ * A registry of functions that can be re-executed, keyed by `actionKey`.
138
+ * Used for implementing "Retry" functionality.
139
+ */
140
+ type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;
141
+ /**
142
+ * Represents the parameters required to initiate a new transaction tracking flow.
140
143
  */
141
144
  type InitialTransactionParams = {
142
- /** The transaction adapter type. */
143
145
  adapter: TransactionAdapter;
144
- /** A key identifying the retry logic from the actions registry. */
146
+ /** A key to identify the re-executable action from the `TxActions` registry. */
145
147
  actionKey?: string;
146
- /** A description for the transaction, with states for [pending, success, error, replaced]. */
148
+ /** A user-facing description for the transaction. */
147
149
  description?: string | [string, string, string, string];
148
- /** The ID of the desired blockchain network. */
150
+ /** The target chain ID for the transaction. */
149
151
  desiredChainID: number | string;
150
- /** Any additional data to be associated with the transaction. */
152
+ /** Any custom data to associate with the transaction. */
151
153
  payload?: object;
152
- /** A title for the transaction, with states for [pending, success, error, replaced]. */
154
+ /** A user-facing title for the transaction. */
153
155
  title?: string | [string, string, string, string];
154
- /** The type or category of the transaction (e.g., 'increment', 'approve'). */
156
+ /** The application-specific type of the transaction. */
155
157
  type: string;
156
- /** If true, the detailed tracking modal will open automatically for this transaction. */
158
+ /** If true, the detailed tracking modal will open automatically upon initiation. */
157
159
  withTrackedModal?: boolean;
158
160
  };
159
161
  /**
160
- * Represents a transaction in its initial, pre-submission state within the store.
162
+ * Represents a transaction in its temporary, pre-submission state.
161
163
  * This is used for UI feedback while the transaction is being signed and sent.
162
164
  */
163
165
  type InitialTransaction = InitialTransactionParams & {
164
- /** 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). */
165
167
  errorMessage?: string;
166
- /** 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). */
167
169
  isInitializing: boolean;
168
- /** 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. */
169
171
  lastTxKey?: string;
170
172
  /** The local timestamp when the user initiated the action. */
171
173
  localTimestamp: number;
172
174
  };
175
+ /**
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).
180
+ */
173
181
  type TxAdapter<TR, T extends Transaction<TR>, A> = {
182
+ /** The unique key identifying this adapter. */
174
183
  key: TransactionAdapter;
184
+ /** Returns information about the currently connected wallet. */
175
185
  getWalletInfo: () => {
176
- /** Wallet address. */
177
186
  walletAddress: string;
178
- /** Type of the wallet. (injected, wallet connect, etc.) */
179
187
  walletType: string;
180
188
  };
189
+ /** Ensures the connected wallet is on the correct network for the transaction. */
181
190
  checkChainForTx: (chainId: string | number) => Promise<void>;
191
+ /** Determines the appropriate tracker and final `txKey` based on the result of an action. */
182
192
  checkTransactionsTracker: (actionTxKey: A, walletType: string) => {
183
193
  txKey: string;
184
194
  tracker: TR;
185
195
  };
186
- checkAndInitializeTrackerInStore: ({ tx, ...rest }: {
196
+ /** Initializes the correct background tracker for a given transaction. */
197
+ checkAndInitializeTrackerInStore: (params: {
187
198
  tx: T;
188
199
  } & Pick<ITxTrackingStore<TR, T, A>, 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'>) => Promise<void>;
200
+ /** Returns the base URL for the blockchain explorer. */
201
+ getExplorerUrl: () => string | undefined;
202
+ /** Optional: Fetches a name from a chain-specific name service (e.g., ENS). */
203
+ getName?: (address: string) => Promise<string | null>;
204
+ /** Optional: Fetches an avatar URL from a chain-specific name service. */
205
+ getAvatar?: (name: string) => Promise<string | null>;
206
+ /** Optional: Logic to cancel a pending EVM transaction. */
207
+ cancelTxAction?: (tx: T) => Promise<string>;
208
+ /** Optional: Logic to speed up a pending EVM transaction. */
209
+ speedUpTxAction?: (tx: T) => Promise<string>;
210
+ /** Optional: Logic to retry a failed transaction. */
211
+ retryTxAction?: (params: {
212
+ txKey: string;
213
+ tx: InitialTransactionParams;
214
+ actions?: TxActions;
215
+ onClose: (txKey?: string) => void;
216
+ } & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;
217
+ /** Optional: Constructs a full explorer URL for a specific transaction. */
218
+ getExplorerTxUrl?: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;
189
219
  };
190
220
  /**
191
- * Interface for the complete transaction tracking store.
192
- * @template TR The type of the tracker identifier.
193
- * @template T The transaction type.
194
- * @template C The configuration object type (e.g., wagmi config).
195
- * @template A The return type of the action function being wrapped.
221
+ * The complete interface for the Pulsar transaction tracking store.
222
+ * @template TR - The type of the tracker identifier.
223
+ * @template T - The transaction type.
224
+ * @template A - The return type of the `actionFunction`.
196
225
  */
197
226
  type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {
198
227
  /**
199
- * A wrapper function that handles the entire lifecycle of a transaction.
200
- * It creates an `InitialTransaction`, executes the on-chain action, and tracks its status.
228
+ * The core function that handles the entire lifecycle of a new transaction.
229
+ * It manages UI state, executes the on-chain action, and initiates background tracking.
201
230
  * @param params - The parameters for handling the transaction.
202
231
  */
203
232
  handleTransaction: (params: {
204
- /** The async function to execute (e.g., a smart contract write call). */
233
+ /** The async function to execute (e.g., a smart contract write call). Must return a unique key or undefined. */
205
234
  actionFunction: () => Promise<A | undefined>;
206
- /** The metadata for the transaction to be created, of type `InitialTransactionParams`. */
235
+ /** The metadata for the transaction. */
207
236
  params: InitialTransactionParams;
237
+ /** The default tracker to use if it cannot be determined automatically. */
208
238
  defaultTracker?: TR;
209
239
  }) => Promise<void>;
210
240
  /**
211
- * Initializes all active trackers for pending transactions in the pool.
212
- * This is useful for resuming tracking after a page reload.
241
+ * Initializes trackers for all pending transactions in the pool.
242
+ * This is essential for resuming tracking after a page reload.
213
243
  */
214
244
  initializeTransactionsPool: () => Promise<void>;
215
245
  };
@@ -230,14 +260,14 @@ type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;
230
260
  * that are updatable via the `updateTxParams` action.
231
261
  * @template TR - The type of the tracker identifier.
232
262
  */
233
- type UpdatedParamsFields<TR> = Pick<EvmTransaction<TR>, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'errorMessage' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>;
263
+ type UpdatableTransactionFields<TR> = Partial<Pick<EvmTransaction<TR>, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'errorMessage' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>>;
234
264
  /**
235
265
  * Defines the interface for the base transaction tracking store slice.
236
266
  * It includes the state and actions for managing transactions.
237
267
  * @template TR - The type of the tracker identifier.
238
268
  * @template T - The transaction type.
239
269
  */
240
- type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {
270
+ interface IInitializeTxTrackingStore<TR, T extends Transaction<TR>> {
241
271
  /** An optional callback function to be executed when a transaction successfully completes. */
242
272
  onSucceedCallbacks?: (tx: T) => Promise<void> | void;
243
273
  /** A pool of all transactions currently being tracked, indexed by their `txKey`. */
@@ -247,18 +277,16 @@ type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {
247
277
  /** The state of a transaction that is currently being initiated but not yet submitted. */
248
278
  initialTx?: InitialTransaction;
249
279
  /** Adds a new transaction to the tracking pool. */
250
- addTxToPool: ({ tx }: {
251
- tx: T;
252
- }) => void;
280
+ addTxToPool: (tx: T) => void;
253
281
  /** Updates one or more parameters of an existing transaction in the pool. */
254
- updateTxParams: (fields: UpdatedParamsFields<TR>) => void;
282
+ updateTxParams: (txKey: string, fields: UpdatableTransactionFields<TR>) => void;
255
283
  /** Removes a transaction from the tracking pool using its key. */
256
284
  removeTxFromPool: (txKey: string) => void;
257
285
  /** Closes the tracking modal for a specific transaction. */
258
286
  closeTxTrackedModal: (txKey?: string) => void;
259
287
  /** Returns the key of the last transaction that was added to the pool. */
260
288
  getLastTxKey: () => string | undefined;
261
- };
289
+ }
262
290
  /**
263
291
  * Creates a Zustand store slice containing the core logic for transaction tracking.
264
292
  * This function is a slice creator and is meant to be used within `createStore` from Zustand.
@@ -272,91 +300,118 @@ declare function initializeTxTrackingStore<TR, T extends Transaction<TR>>({ onSu
272
300
 
273
301
  /**
274
302
  * @file This file contains selector functions for deriving state from the transaction tracking store.
275
- * Selectors help abstract away the shape of the state and provide memoized, efficient access to computed data.
303
+ * Selectors help abstract the state's shape and provide efficient, memoized access to computed data.
276
304
  */
277
305
 
278
306
  /**
279
- * Selects all transactions from the pool and sorts them by their creation timestamp.
307
+ * Selects all transactions from the pool and sorts them by their creation timestamp in ascending order.
280
308
  * @template TR - The type of the tracker identifier.
281
309
  * @template T - The transaction type.
282
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
310
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
283
311
  * @returns {T[]} An array of all transactions, sorted chronologically.
284
312
  */
285
313
  declare const selectAllTransactions: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>) => T[];
286
314
  /**
287
- * Selects all transactions that are currently in a pending state.
315
+ * Selects all transactions that are currently in a pending state, sorted chronologically.
288
316
  * @template TR - The type of the tracker identifier.
289
317
  * @template T - The transaction type.
290
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
318
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
291
319
  * @returns {T[]} An array of pending transactions.
292
320
  */
293
321
  declare const selectPendingTransactions: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>) => T[];
294
322
  /**
295
- * Selects a single transaction from the pool by its unique transaction key (`txKey`).
296
- * This is the most direct way to retrieve a transaction.
323
+ * Selects a single transaction from the pool by its unique key (`txKey`).
297
324
  * @template TR - The type of the tracker identifier.
298
325
  * @template T - The transaction type.
299
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
326
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
300
327
  * @param {string} key - The `txKey` of the transaction to retrieve.
301
328
  * @returns {T | undefined} The transaction object if found, otherwise undefined.
302
329
  */
303
- declare const selectTXByKey: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, key: string) => T | undefined;
330
+ declare const selectTxByKey: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, key: string) => T | undefined;
304
331
  /**
305
- * Selects all transactions initiated by a specific wallet address.
332
+ * Selects all transactions initiated by a specific wallet address, sorted chronologically.
306
333
  * @template TR - The type of the tracker identifier.
307
334
  * @template T - The transaction type.
308
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
335
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
309
336
  * @param {string} from - The wallet address (`from` address) to filter transactions by.
310
337
  * @returns {T[]} An array of transactions associated with the given wallet.
311
338
  */
312
339
  declare const selectAllTransactionsByActiveWallet: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, from: string) => T[];
313
340
  /**
314
- * Selects all pending transactions initiated by a specific wallet address.
341
+ * Selects all pending transactions for a specific wallet address, sorted chronologically.
315
342
  * @template TR - The type of the tracker identifier.
316
343
  * @template T - The transaction type.
317
- * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.
344
+ * @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
318
345
  * @param {string} from - The wallet address (`from` address) to filter transactions by.
319
- * @returns {T[]} An array of pending transactions associated with the given wallet.
346
+ * @returns {T[]} An array of pending transactions for the given wallet.
320
347
  */
321
348
  declare const selectPendingTransactionsByActiveWallet: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, from: string) => T[];
322
349
 
350
+ /**
351
+ * Creates the main Pulsar store for transaction tracking.
352
+ *
353
+ * This function sets up a Zustand store with persistence, combining the core
354
+ * transaction slice with adapter-specific logic to handle the entire lifecycle
355
+ * of a transaction.
356
+ *
357
+ * @template TR - The type of the tracker identifier (e.g., a string enum).
358
+ * @template T - The specific transaction type, extending the base `Transaction`.
359
+ * @template A - The type for the adapter-specific context or API.
360
+ *
361
+ * @param {object} config - Configuration object for creating the store.
362
+ * @param {function} [config.onSucceedCallbacks] - Optional async callback executed on transaction success.
363
+ * @param {TxAdapter<TR, T, A>[]} config.adapters - An array of adapters for different transaction types or chains.
364
+ * @param {PersistOptions<ITxTrackingStore<TR, T, A>>} [options] - Configuration for the Zustand persist middleware.
365
+ * @returns A fully configured Zustand store instance.
366
+ */
323
367
  declare function createPulsarStore<TR, T extends Transaction<TR>, A>({ onSucceedCallbacks, adapters, ...options }: {
324
368
  onSucceedCallbacks?: (tx: T) => Promise<void> | void;
325
369
  adapters: TxAdapter<TR, T, A>[];
326
- } & PersistOptions<ITxTrackingStore<TR, T, A>>): Omit<zustand.StoreApi<ITxTrackingStore<TR, T, A>>, "persist"> & {
370
+ } & PersistOptions<ITxTrackingStore<TR, T, A>>): Omit<zustand.StoreApi<ITxTrackingStore<TR, T, A>>, "setState" | "persist"> & {
371
+ 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;
372
+ setState(state: ITxTrackingStore<TR, T, A> | ((state: ITxTrackingStore<TR, T, A>) => ITxTrackingStore<TR, T, A>), replace: true): unknown;
327
373
  persist: {
328
- setOptions: (options: Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>>>) => void;
374
+ setOptions: (options: Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>, unknown>>) => void;
329
375
  clearStorage: () => void;
330
376
  rehydrate: () => Promise<void> | void;
331
377
  hasHydrated: () => boolean;
332
378
  onHydrate: (fn: (state: ITxTrackingStore<TR, T, A>) => void) => () => void;
333
379
  onFinishHydration: (fn: (state: ITxTrackingStore<TR, T, A>) => void) => () => void;
334
- getOptions: () => Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>>>;
380
+ getOptions: () => Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>, unknown>>;
335
381
  };
336
382
  };
337
383
 
338
384
  /**
339
- * @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.
340
- * This is a recommended pattern for using vanilla stores with React to ensure full type safety.
385
+ * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
386
+ * This pattern is recommended by the official Zustand documentation to ensure full type
387
+ * safety when integrating vanilla stores with React.
341
388
  *
342
- * @see https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
389
+ * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
343
390
  */
344
391
 
345
392
  /**
346
- * A utility type to infer the state shape from a Zustand store type.
347
- * @template S The type of the Zustand store (`StoreApi`).
393
+ * A utility type that infers the state shape from a Zustand `StoreApi`.
394
+ * It extracts the return type of the `getState` method.
395
+ * @template S - The type of the Zustand store (`StoreApi`).
348
396
  */
349
397
  type ExtractState<S> = S extends {
350
- getState: () => infer X;
351
- } ? X : never;
398
+ getState: () => infer T;
399
+ } ? T : never;
352
400
  /**
353
- * Creates a bounded `useStore` hook from a vanilla Zustand store instance.
354
- * The returned hook is fully typed and can be used with or without a selector.
401
+ * Creates a bounded `useStore` hook from a vanilla Zustand store.
402
+ *
403
+ * This function takes a vanilla Zustand store instance and returns a React hook
404
+ * that is pre-bound to that store. This approach provides a cleaner API and
405
+ * enhances type inference, eliminating the need to pass the store instance
406
+ * on every use.
355
407
  *
356
- * @template S The type of the Zustand store (`StoreApi`).
357
- * @param {S} store - The vanilla Zustand store instance.
358
- * @returns {function} A hook that can be called with an optional selector function.
359
- * - When called with a selector (`useBoundedStore(state => state.someValue)`), it returns the selected slice of the state.
408
+ * The returned hook supports two signatures:
409
+ * 1. `useBoundedStore()`: Selects the entire state.
410
+ * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
411
+ *
412
+ * @template S - The type of the Zustand store (`StoreApi`).
413
+ * @param {S} store - The vanilla Zustand store instance to bind the hook to.
414
+ * @returns {function} A fully typed React hook for accessing the store's state.
360
415
  */
361
416
  declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
362
417
  (): ExtractState<S>;
@@ -364,63 +419,99 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
364
419
  };
365
420
 
366
421
  /**
367
- * @file This file contains a generic utility for creating a polling mechanism to track asynchronous tasks,
368
- * such as API-based transaction status checks (e.g., for Gelato or Safe).
422
+ * @file This file provides a generic utility for creating a polling mechanism to track
423
+ * asynchronous tasks, such as API-based transaction status checks (e.g., for Gelato or Safe).
369
424
  */
370
425
 
426
+ /**
427
+ * Defines the parameters for the fetcher function used within the polling tracker.
428
+ * The fetcher is the core logic that performs the actual API call.
429
+ * @template R - The expected type of the successful API response.
430
+ * @template T - The type of the transaction object being tracked.
431
+ */
432
+ type PollingFetcherParams<R, T> = {
433
+ /** The transaction object being tracked. */
434
+ tx: T;
435
+ /** A callback to stop the polling mechanism, typically called on success or terminal failure. */
436
+ stopPolling: (options?: {
437
+ withoutRemoving?: boolean;
438
+ }) => void;
439
+ /** Callback to be invoked when the fetcher determines the transaction has succeeded. */
440
+ onSuccess: (response: R) => void;
441
+ /** Callback to be invoked when the fetcher determines the transaction has failed. */
442
+ onFailure: (response?: R) => void;
443
+ /** Optional callback for each successful poll, useful for updating UI with intermediate states. */
444
+ onIntervalTick?: (response: R) => void;
445
+ /** Optional callback for when a transaction is replaced (e.g., speed-up). */
446
+ onReplaced?: (response: R) => void;
447
+ };
371
448
  /**
372
449
  * Defines the configuration object for the `initializePollingTracker` function.
373
- * @template R The expected type of the successful API response from the fetcher.
374
- * @template T The type of the transaction object being tracked.
375
- * @template TR The type of the tracker identifier used in the `Transaction` type.
376
- */
377
- type InitializePollingTracker<R, T, TR> = {
378
- /** The transaction object to be tracked. It must include `txKey` and an optional `pending` status. */
379
- tx: T & Pick<Transaction<TR>, 'txKey'> & {
380
- pending?: boolean;
381
- };
382
- /** The function that performs the actual data fetching (e.g., an API call). */
383
- fetcher: (params: {
384
- /** The transaction object being tracked. */
385
- tx: T;
386
- /** A callback to stop the polling mechanism, typically called on success or terminal failure. */
387
- clearWatch: (withoutRemoving?: boolean) => void;
388
- /** Callback to be invoked when the fetcher determines the transaction has succeeded. */
389
- onSucceed: (response: R) => void;
390
- /** Callback to be invoked when the fetcher determines the transaction has failed. */
391
- onFailed: (response: R) => void;
392
- /** Optional callback for each successful poll, useful for updating UI with intermediate states. */
393
- onIntervalTick?: (response: R) => void;
394
- /** Optional callback for when a transaction is replaced by another. */
395
- onReplaced?: (response: R) => void;
396
- }) => Promise<Response>;
450
+ * @template R - The expected type of the successful API response.
451
+ * @template T - The type of the transaction object.
452
+ * @template TR - The type of the tracker identifier.
453
+ */
454
+ type PollingTrackerConfig<R, T, TR> = {
455
+ /** The transaction object to be tracked. It must include `txKey` and `pending` status. */
456
+ tx: T & Pick<Transaction<TR>, 'txKey' | 'pending'>;
457
+ /** The function that performs the data fetching (e.g., an API call) on each interval. */
458
+ fetcher: (params: PollingFetcherParams<R, T>) => Promise<void>;
459
+ /** Callback to be invoked when the transaction successfully completes. */
460
+ onSuccess: (response: R) => void;
461
+ /** Callback to be invoked when the transaction fails. */
462
+ onFailure: (response?: R) => void;
397
463
  /** Optional callback executed once when the tracker is initialized. */
398
464
  onInitialize?: () => void;
399
- /** Callback to be invoked when the transaction has succeeded. */
400
- onSucceed: (response: R) => void;
401
- /** Callback to be invoked when the transaction has failed. */
402
- onFailed: (response: R) => void;
403
465
  /** Optional callback for each successful poll. */
404
466
  onIntervalTick?: (response: R) => void;
405
467
  /** Optional callback for when a transaction is replaced. */
406
468
  onReplaced?: (response: R) => void;
407
469
  /** Optional function to remove the transaction from the main pool, typically after polling stops. */
408
- removeTxFromPool?: (taskId: string) => void;
470
+ removeTxFromPool?: (txKey: string) => void;
409
471
  /** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */
410
472
  pollingInterval?: number;
411
473
  /** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */
412
- retryCount?: number;
474
+ maxRetries?: number;
413
475
  };
414
476
  /**
415
477
  * Initializes a generic polling tracker that repeatedly calls a fetcher function
416
- * to monitor the status of a transaction or any asynchronous task.
478
+ * to monitor the status of an asynchronous task.
417
479
  *
418
- * @template R The expected type of the successful API response.
480
+ * This function handles the lifecycle of polling, including starting, stopping,
481
+ * and automatic termination after a certain number of failed attempts.
482
+ *
483
+ * @template R The expected type of the API response.
419
484
  * @template T The type of the transaction object.
420
485
  * @template TR The type of the tracker identifier.
421
- * @param {InitializePollingTracker<R, T, TR>} params - The configuration object for the tracker.
422
- * @returns {Promise<void>} A promise that resolves when the tracker is set up (note: polling happens asynchronously).
486
+ * @param {PollingTrackerConfig<R, T, TR>} config - The configuration for the tracker.
487
+ */
488
+ declare function initializePollingTracker<R, T, TR>(config: PollingTrackerConfig<R, T, TR>): void;
489
+
490
+ /**
491
+ * @file This file contains a utility function for selecting a specific transaction adapter from a list.
423
492
  */
424
- declare function initializePollingTracker<R, T, TR>({ onInitialize, tx, removeTxFromPool, fetcher, onFailed, onIntervalTick, onSucceed, pollingInterval, retryCount, onReplaced, }: InitializePollingTracker<R, T, TR>): Promise<void>;
425
493
 
426
- 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 TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTXByKey };
494
+ /**
495
+ * Selects a transaction adapter from a list based on a provided key.
496
+ *
497
+ * This function searches through an array of `TxAdapter` instances and returns the one
498
+ * that matches the given `adapterKey`. If no specific adapter is found, it logs a warning
499
+ * and returns the first adapter in the array as a fallback. This fallback mechanism
500
+ * ensures that the system can still function, but it highlights a potential configuration issue.
501
+ *
502
+ * @template TR - The type of the tracker identifier.
503
+ * @template T - The transaction type, extending the base `Transaction`.
504
+ * @template A - The type for the adapter-specific context or API.
505
+ *
506
+ * @param {object} params - The parameters for the selection.
507
+ * @param {TransactionAdapter} params.adapterKey - The key of the desired adapter.
508
+ * @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.
509
+ *
510
+ * @returns {TxAdapter<TR, T, A> | undefined} The found transaction adapter, the fallback adapter, or undefined if the adapters array is empty.
511
+ */
512
+ declare const selectAdapterByKey: <TR, T extends Transaction<TR>, A>({ adapterKey, adapters, }: {
513
+ adapterKey: TransactionAdapter;
514
+ adapters: TxAdapter<TR, T, A>[];
515
+ }) => TxAdapter<TR, T, A> | undefined;
516
+
517
+ 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 };