@tuwaio/pulsar-evm 0.0.19 → 0.1.0

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 CHANGED
@@ -35,13 +35,13 @@ This package is designed to be used as part of the Pulsar stack and requires `@w
35
35
 
36
36
  ```bash
37
37
  # Using pnpm
38
- pnpm add @tuwaio/pulsar-evm @tuwaio/pulsar-core @wagmi/core viem zustand immer dayjs
38
+ pnpm add @tuwaio/pulsar-evm @tuwaio/pulsar-core @tuwaio/orbit-core @tuwaio/orbit-evm @wagmi/core viem zustand immer dayjs
39
39
 
40
40
  # Using npm
41
- npm install @tuwaio/pulsar-evm @tuwaio/pulsar-core @wagmi/core viem zustand immer dayjs
41
+ npm install @tuwaio/pulsar-evm @tuwaio/pulsar-core @tuwaio/orbit-core @tuwaio/orbit-evm @wagmi/core viem zustand immer dayjs
42
42
 
43
43
  # Using yarn
44
- yarn add @tuwaio/pulsar-evm @tuwaio/pulsar-core @wagmi/core viem zustand immer dayjs
44
+ yarn add @tuwaio/pulsar-evm @tuwaio/pulsar-core @tuwaio/orbit-core @tuwaio/orbit-evm @wagmi/core viem zustand immer dayjs
45
45
  ```
46
46
 
47
47
  ---
@@ -53,18 +53,33 @@ yarn add @tuwaio/pulsar-evm @tuwaio/pulsar-core @wagmi/core viem zustand immer d
53
53
  For most applications, you'll only need to import the `evmAdapter` and pass it to your `createPulsarStore` configuration.
54
54
 
55
55
  ```ts
56
- // src/store/pulsarStore.ts
57
- import { createPulsarStore } from '@tuwaio/pulsar-core';
56
+ // src/hooks/txTrackingHooks.ts
57
+ import { createBoundedUseStore, createPulsarStore, Transaction } from '@tuwaio/pulsar-core';
58
58
  import { evmAdapter } from '@tuwaio/pulsar-evm';
59
- import { wagmiConfig, chains } from '../configs/wagmi'; // Your wagmi config
60
-
61
- // Create the Pulsar store and plug in the EVM adapter
62
- export const pulsarStore = createPulsarStore({
63
- // A unique name for localStorage persistence
64
- name: 'my-dapp-transactions',
65
- // Provide the evmAdapter with your wagmi config and supported chains
66
- adapter: evmAdapter(wagmiConfig, chains),
67
- });
59
+
60
+ import { appChains, config } from '@/configs/wagmiConfig';
61
+
62
+ const storageName = 'transactions-tracking-storage';
63
+
64
+ export enum TxType {
65
+ example = 'example',
66
+ }
67
+
68
+ type ExampleTx = Transaction & {
69
+ type: TxType.example;
70
+ payload: {
71
+ value: number;
72
+ };
73
+ };
74
+
75
+ export type TransactionUnion = ExampleTx;
76
+
77
+ export const usePulsarStore = createBoundedUseStore(
78
+ createPulsarStore<TransactionUnion>({
79
+ name: storageName,
80
+ adapter: evmAdapter(config, appChains),
81
+ }),
82
+ );
68
83
  ```
69
84
 
70
85
  ### 2. Using Standalone Actions
@@ -76,11 +91,11 @@ This package also exports utility actions that you can wire up to your UI for fe
76
91
  ```tsx
77
92
  // src/components/SpeedUpButton.tsx
78
93
  import { speedUpTxAction } from '@tuwaio/pulsar-evm';
79
- import { usePulsar } from '@tuwaio/pulsar-react'; // Or your custom hook
94
+ import { usePulsarStore } from '../hooks/txTrackingHooks'; // Or your custom hook
80
95
  import { wagmiConfig } from '../configs/wagmi'; // Your wagmi config
81
96
 
82
97
  function SpeedUpButton({ txKey }) {
83
- const { transactionsPool } = usePulsar();
98
+ const transactionsPool = usePulsarStore((state) => state.transactionsPool);
84
99
  const stuckTransaction = transactionsPool[txKey];
85
100
 
86
101
  // Only show the button if the transaction is pending and is a standard EVM tx
@@ -115,7 +130,6 @@ You can use exported utilities, like selectors, to get derived data for your UI.
115
130
  ```tsx
116
131
  // src/components/ExplorerLink.tsx
117
132
  import { selectEvmTxExplorerLink } from '@tuwaio/pulsar-evm';
118
- import { usePulsar } from '@tuwaio/pulsar-react';
119
133
  import { chains } from '../configs/wagmi'; // Your wagmi config
120
134
 
121
135
  function ExplorerLink({ tx }) {
package/dist/index.d.mts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Transaction, TxAdapter, ITxTrackingStore, OnSuccessCallback, ActionTxKey, GelatoTxKey, PollingTrackerConfig, TransactionTracker } from '@tuwaio/pulsar-core';
2
- import { Config, GetAccountReturnType, GetClientReturnType } from '@wagmi/core';
3
- import * as viem from 'viem';
4
- import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex, Address } from 'viem';
5
- import { Chain as Chain$1 } from 'viem/chains';
2
+ import { Config } from '@wagmi/core';
3
+ import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex } from 'viem';
6
4
 
7
5
  /**
8
6
  * @file This file contains the factory function for creating the EVM (Ethereum Virtual Machine) transaction adapter.
@@ -24,7 +22,7 @@ import { Chain as Chain$1 } from 'viem/chains';
24
22
  *
25
23
  * @throws {Error} Throws an error if the wagmi `config` is not provided.
26
24
  */
27
- declare function evmAdapter<T extends Transaction>(config: Config, appChains: Chain[]): TxAdapter<T>;
25
+ declare function pulsarEvmAdapter<T extends Transaction>(config: Config, appChains: readonly [Chain, ...Chain[]]): TxAdapter<T>;
28
26
 
29
27
  /**
30
28
  * @file This file contains the tracker implementation for standard EVM transactions.
@@ -37,7 +35,7 @@ declare function evmAdapter<T extends Transaction>(config: Config, appChains: Ch
37
35
  */
38
36
  type EVMTrackerParams = {
39
37
  tx: Pick<Transaction, 'chainId' | 'txKey'>;
40
- chains: Chain[];
38
+ config: Config;
41
39
  onTxDetailsFetched: (txDetails: GetTransactionReturnType) => void;
42
40
  onSuccess: (txDetails: GetTransactionReturnType, receipt: TransactionReceipt, client: Client) => Promise<void>;
43
41
  onReplaced: (replacement: ReplacementReturnType) => void;
@@ -60,7 +58,7 @@ declare function evmTracker(params: EVMTrackerParams): Promise<void>;
60
58
  *
61
59
  * @template T - The application-specific transaction type.
62
60
  */
63
- declare function evmTrackerForStore<T extends Transaction>(params: Pick<EVMTrackerParams, 'chains'> & Pick<ITxTrackingStore<T>, 'updateTxParams' | 'transactionsPool'> & {
61
+ declare function evmTrackerForStore<T extends Transaction>(params: Pick<EVMTrackerParams, 'config'> & Pick<ITxTrackingStore<T>, 'updateTxParams' | 'transactionsPool'> & {
64
62
  tx: T;
65
63
  } & OnSuccessCallback<T>): Promise<void>;
66
64
 
@@ -205,7 +203,7 @@ declare function cancelTxAction<T extends Transaction>({ config, tx }: {
205
203
  * @template T - The application-specific transaction type.
206
204
  */
207
205
  type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>, 'updateTxParams' | 'removeTxFromPool' | 'transactionsPool'> & {
208
- chains: Chain[];
206
+ config: Config;
209
207
  tx: T;
210
208
  tracker: TransactionTracker;
211
209
  } & OnSuccessCallback<T>;
@@ -218,26 +216,7 @@ type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>,
218
216
  * @param {InitializeTrackerParams<T>} params - The parameters for initializing the tracker.
219
217
  * @returns {Promise<void>} A promise that resolves once the tracking process has been successfully initiated.
220
218
  */
221
- declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, chains, transactionsPool, onSuccessCallback, ...rest }: InitializeTrackerParams<T>): Promise<void>;
222
-
223
- /**
224
- * @file This file contains a utility to ensure the user's wallet is connected to the correct chain before proceeding with a transaction.
225
- */
226
-
227
- /**
228
- * Checks if the user's wallet is connected to the specified chain. If not, it prompts
229
- * the user to switch to the correct chain.
230
- *
231
- * This function is a crucial prerequisite for any action that requires a specific network.
232
- *
233
- * @param {number} chainId - The ID of the desired blockchain network.
234
- * @param {Config} config - The wagmi configuration object.
235
- * @returns {Promise<void>} A promise that resolves when the wallet is on the correct chain.
236
- * It rejects if the user cancels the switch or if another error occurs.
237
- *
238
- * @throws {Error} Throws a specific error if the user rejects the chain switch or if the switch fails for other reasons.
239
- */
240
- declare function checkChainForTx(chainId: number, config: Config): Promise<void>;
219
+ declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, config, transactionsPool, onSuccessCallback, ...rest }: InitializeTrackerParams<T>): Promise<void>;
241
220
 
242
221
  /**
243
222
  * @file This file contains a utility to check if the Gelato Relay service is available for a specific chain.
@@ -280,86 +259,6 @@ declare function checkTransactionsTracker(actionTxKey: ActionTxKey, walletType:
280
259
  txKey: string;
281
260
  };
282
261
 
283
- /**
284
- * Creates a viem Public Client for a specific chain.
285
- *
286
- * This client is used for read-only interactions with the blockchain, such as fetching
287
- * transaction receipts or reading contract state, without needing a wallet connection.
288
- *
289
- * @param {number} chainId - The ID of the chain for which to create the client.
290
- * @param {Chain[]} chains - An array of supported viem Chain objects.
291
- *
292
- * @returns {import('viem').PublicClient | undefined} A viem PublicClient instance if a matching chain is found, otherwise undefined.
293
- * It will also log a warning to the console if the chain is not configured.
294
- */
295
- declare function createViemClient(chainId: number, chains: Chain$1[]): viem.PublicClient | undefined;
296
-
297
- /**
298
- * @file This file contains utility functions for interacting with the Ethereum Name Service (ENS).
299
- * It provides methods for resolving names to addresses, addresses to names, and fetching avatars,
300
- * all specifically targeting the Ethereum Mainnet where ENS is deployed.
301
- */
302
-
303
- /**
304
- * Fetches the primary ENS name for a given Ethereum address from the Ethereum Mainnet.
305
- *
306
- * @param {Hex} address - The Ethereum address to look up.
307
- * @returns {Promise<string | null>} The ENS name if found, otherwise null.
308
- */
309
- declare const getName: (address: Hex) => Promise<string | null>;
310
- /**
311
- * Fetches the avatar URL for a given ENS name from the Ethereum Mainnet.
312
- *
313
- * @param {string} name - The ENS name (e.g., 'vitalik.eth').
314
- * @returns {Promise<string | null>} The URL of the avatar image if found, otherwise null.
315
- */
316
- declare const getAvatar: (name: string) => Promise<string | null>;
317
- /**
318
- * Fetches the Ethereum address associated with a given ENS name from the Ethereum Mainnet.
319
- *
320
- * @param {string} name - The ENS name to resolve (e.g., 'vitalik.eth').
321
- * @returns {Promise<Address | null>} The associated Ethereum address (lowercase) or null if not found.
322
- */
323
- declare const getAddress: (name: string) => Promise<Address | null>;
324
- /**
325
- * A heuristic to check if a string is likely an ENS name.
326
- *
327
- * This is not a foolproof validation but a quick check. A valid ENS name
328
- * must contain at least one dot and should not be a valid Ethereum address.
329
- *
330
- * @param {string} nameOrAddress - The string to check.
331
- * @returns {boolean} True if the string is likely an ENS name.
332
- *
333
- * @example
334
- * isEnsName('vitalik.eth') // true
335
- * isEnsName('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') // false
336
- * isEnsName('notanaddress') // false (doesn't contain a dot)
337
- */
338
- declare const isEnsName: (nameOrAddress: string) => boolean;
339
-
340
- /**
341
- * @file This file contains a utility for safely retrieving the active wallet account and the viem wallet client from wagmi.
342
- */
343
-
344
- /**
345
- * Retrieves the active wallet account and the viem Wallet Client from the wagmi config.
346
- * This function acts as a safeguard, ensuring that a wallet is connected before
347
- * attempting any on-chain actions.
348
- *
349
- * @param {Config} config - The wagmi configuration object.
350
- *
351
- * @returns {{ activeWallet: GetAccountReturnType; walletClient: NonNullable<GetClientReturnType> }}
352
- * An object containing the connected account details and the viem Wallet Client.
353
- * The return types are guaranteed to be non-nullable.
354
- *
355
- * @throws {Error} Throws an error if the wallet is not connected, the address is missing,
356
- * or the viem client is unavailable.
357
- */
358
- declare function getActiveWalletAndClient(config: Config): {
359
- activeWallet: GetAccountReturnType;
360
- walletClient: NonNullable<GetClientReturnType>;
361
- };
362
-
363
262
  /**
364
263
  * @file This file contains constants related to Safe (formerly Gnosis Safe) configuration,
365
264
  * including SDK options, web app URLs, and transaction service API endpoints for various chains.
@@ -405,8 +304,8 @@ declare const SafeTransactionServiceUrls: Record<number, string>;
405
304
  * @returns {string} The full URL to the transaction on the corresponding block explorer or Safe app,
406
305
  * or an empty string if the transaction or required chain configuration is not found.
407
306
  */
408
- declare const selectEvmTxExplorerLink: <T extends Transaction>({ chains, tx }: {
409
- chains: Chain[];
307
+ declare const selectEvmTxExplorerLink: <T extends Transaction>({ chains, tx, }: {
308
+ chains: readonly [Chain, ...Chain[]];
410
309
  tx: T;
411
310
  }) => string;
412
311
 
@@ -454,4 +353,4 @@ declare function speedUpTxAction<T extends Transaction>({ config, tx }: {
454
353
  tx: T;
455
354
  }): Promise<Hex>;
456
355
 
457
- export { type EVMTrackerParams, GelatoTaskState, type GelatoTaskStatusResponse, SafeTransactionServiceUrls, type SafeTxStatusResponse, cancelTxAction, checkAndInitializeTrackerInStore, checkChainForTx, checkIsGelatoAvailable, checkTransactionsTracker, createViemClient, evmAdapter, evmTracker, evmTrackerForStore, gelatoFetcher, gelatoTrackerForStore, getActiveWalletAndClient, getAddress, getAvatar, getName, gnosisSafeLinksHelper, isEnsName, isGelatoTxKey, safeFetcher, safeSdkOptions, safeTrackerForStore, selectEvmTxExplorerLink, speedUpTxAction };
356
+ export { type EVMTrackerParams, GelatoTaskState, type GelatoTaskStatusResponse, SafeTransactionServiceUrls, type SafeTxStatusResponse, cancelTxAction, checkAndInitializeTrackerInStore, checkIsGelatoAvailable, checkTransactionsTracker, evmTracker, evmTrackerForStore, gelatoFetcher, gelatoTrackerForStore, gnosisSafeLinksHelper, isGelatoTxKey, pulsarEvmAdapter, safeFetcher, safeSdkOptions, safeTrackerForStore, selectEvmTxExplorerLink, speedUpTxAction };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Transaction, TxAdapter, ITxTrackingStore, OnSuccessCallback, ActionTxKey, GelatoTxKey, PollingTrackerConfig, TransactionTracker } from '@tuwaio/pulsar-core';
2
- import { Config, GetAccountReturnType, GetClientReturnType } from '@wagmi/core';
3
- import * as viem from 'viem';
4
- import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex, Address } from 'viem';
5
- import { Chain as Chain$1 } from 'viem/chains';
2
+ import { Config } from '@wagmi/core';
3
+ import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex } from 'viem';
6
4
 
7
5
  /**
8
6
  * @file This file contains the factory function for creating the EVM (Ethereum Virtual Machine) transaction adapter.
@@ -24,7 +22,7 @@ import { Chain as Chain$1 } from 'viem/chains';
24
22
  *
25
23
  * @throws {Error} Throws an error if the wagmi `config` is not provided.
26
24
  */
27
- declare function evmAdapter<T extends Transaction>(config: Config, appChains: Chain[]): TxAdapter<T>;
25
+ declare function pulsarEvmAdapter<T extends Transaction>(config: Config, appChains: readonly [Chain, ...Chain[]]): TxAdapter<T>;
28
26
 
29
27
  /**
30
28
  * @file This file contains the tracker implementation for standard EVM transactions.
@@ -37,7 +35,7 @@ declare function evmAdapter<T extends Transaction>(config: Config, appChains: Ch
37
35
  */
38
36
  type EVMTrackerParams = {
39
37
  tx: Pick<Transaction, 'chainId' | 'txKey'>;
40
- chains: Chain[];
38
+ config: Config;
41
39
  onTxDetailsFetched: (txDetails: GetTransactionReturnType) => void;
42
40
  onSuccess: (txDetails: GetTransactionReturnType, receipt: TransactionReceipt, client: Client) => Promise<void>;
43
41
  onReplaced: (replacement: ReplacementReturnType) => void;
@@ -60,7 +58,7 @@ declare function evmTracker(params: EVMTrackerParams): Promise<void>;
60
58
  *
61
59
  * @template T - The application-specific transaction type.
62
60
  */
63
- declare function evmTrackerForStore<T extends Transaction>(params: Pick<EVMTrackerParams, 'chains'> & Pick<ITxTrackingStore<T>, 'updateTxParams' | 'transactionsPool'> & {
61
+ declare function evmTrackerForStore<T extends Transaction>(params: Pick<EVMTrackerParams, 'config'> & Pick<ITxTrackingStore<T>, 'updateTxParams' | 'transactionsPool'> & {
64
62
  tx: T;
65
63
  } & OnSuccessCallback<T>): Promise<void>;
66
64
 
@@ -205,7 +203,7 @@ declare function cancelTxAction<T extends Transaction>({ config, tx }: {
205
203
  * @template T - The application-specific transaction type.
206
204
  */
207
205
  type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>, 'updateTxParams' | 'removeTxFromPool' | 'transactionsPool'> & {
208
- chains: Chain[];
206
+ config: Config;
209
207
  tx: T;
210
208
  tracker: TransactionTracker;
211
209
  } & OnSuccessCallback<T>;
@@ -218,26 +216,7 @@ type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>,
218
216
  * @param {InitializeTrackerParams<T>} params - The parameters for initializing the tracker.
219
217
  * @returns {Promise<void>} A promise that resolves once the tracking process has been successfully initiated.
220
218
  */
221
- declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, chains, transactionsPool, onSuccessCallback, ...rest }: InitializeTrackerParams<T>): Promise<void>;
222
-
223
- /**
224
- * @file This file contains a utility to ensure the user's wallet is connected to the correct chain before proceeding with a transaction.
225
- */
226
-
227
- /**
228
- * Checks if the user's wallet is connected to the specified chain. If not, it prompts
229
- * the user to switch to the correct chain.
230
- *
231
- * This function is a crucial prerequisite for any action that requires a specific network.
232
- *
233
- * @param {number} chainId - The ID of the desired blockchain network.
234
- * @param {Config} config - The wagmi configuration object.
235
- * @returns {Promise<void>} A promise that resolves when the wallet is on the correct chain.
236
- * It rejects if the user cancels the switch or if another error occurs.
237
- *
238
- * @throws {Error} Throws a specific error if the user rejects the chain switch or if the switch fails for other reasons.
239
- */
240
- declare function checkChainForTx(chainId: number, config: Config): Promise<void>;
219
+ declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, config, transactionsPool, onSuccessCallback, ...rest }: InitializeTrackerParams<T>): Promise<void>;
241
220
 
242
221
  /**
243
222
  * @file This file contains a utility to check if the Gelato Relay service is available for a specific chain.
@@ -280,86 +259,6 @@ declare function checkTransactionsTracker(actionTxKey: ActionTxKey, walletType:
280
259
  txKey: string;
281
260
  };
282
261
 
283
- /**
284
- * Creates a viem Public Client for a specific chain.
285
- *
286
- * This client is used for read-only interactions with the blockchain, such as fetching
287
- * transaction receipts or reading contract state, without needing a wallet connection.
288
- *
289
- * @param {number} chainId - The ID of the chain for which to create the client.
290
- * @param {Chain[]} chains - An array of supported viem Chain objects.
291
- *
292
- * @returns {import('viem').PublicClient | undefined} A viem PublicClient instance if a matching chain is found, otherwise undefined.
293
- * It will also log a warning to the console if the chain is not configured.
294
- */
295
- declare function createViemClient(chainId: number, chains: Chain$1[]): viem.PublicClient | undefined;
296
-
297
- /**
298
- * @file This file contains utility functions for interacting with the Ethereum Name Service (ENS).
299
- * It provides methods for resolving names to addresses, addresses to names, and fetching avatars,
300
- * all specifically targeting the Ethereum Mainnet where ENS is deployed.
301
- */
302
-
303
- /**
304
- * Fetches the primary ENS name for a given Ethereum address from the Ethereum Mainnet.
305
- *
306
- * @param {Hex} address - The Ethereum address to look up.
307
- * @returns {Promise<string | null>} The ENS name if found, otherwise null.
308
- */
309
- declare const getName: (address: Hex) => Promise<string | null>;
310
- /**
311
- * Fetches the avatar URL for a given ENS name from the Ethereum Mainnet.
312
- *
313
- * @param {string} name - The ENS name (e.g., 'vitalik.eth').
314
- * @returns {Promise<string | null>} The URL of the avatar image if found, otherwise null.
315
- */
316
- declare const getAvatar: (name: string) => Promise<string | null>;
317
- /**
318
- * Fetches the Ethereum address associated with a given ENS name from the Ethereum Mainnet.
319
- *
320
- * @param {string} name - The ENS name to resolve (e.g., 'vitalik.eth').
321
- * @returns {Promise<Address | null>} The associated Ethereum address (lowercase) or null if not found.
322
- */
323
- declare const getAddress: (name: string) => Promise<Address | null>;
324
- /**
325
- * A heuristic to check if a string is likely an ENS name.
326
- *
327
- * This is not a foolproof validation but a quick check. A valid ENS name
328
- * must contain at least one dot and should not be a valid Ethereum address.
329
- *
330
- * @param {string} nameOrAddress - The string to check.
331
- * @returns {boolean} True if the string is likely an ENS name.
332
- *
333
- * @example
334
- * isEnsName('vitalik.eth') // true
335
- * isEnsName('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') // false
336
- * isEnsName('notanaddress') // false (doesn't contain a dot)
337
- */
338
- declare const isEnsName: (nameOrAddress: string) => boolean;
339
-
340
- /**
341
- * @file This file contains a utility for safely retrieving the active wallet account and the viem wallet client from wagmi.
342
- */
343
-
344
- /**
345
- * Retrieves the active wallet account and the viem Wallet Client from the wagmi config.
346
- * This function acts as a safeguard, ensuring that a wallet is connected before
347
- * attempting any on-chain actions.
348
- *
349
- * @param {Config} config - The wagmi configuration object.
350
- *
351
- * @returns {{ activeWallet: GetAccountReturnType; walletClient: NonNullable<GetClientReturnType> }}
352
- * An object containing the connected account details and the viem Wallet Client.
353
- * The return types are guaranteed to be non-nullable.
354
- *
355
- * @throws {Error} Throws an error if the wallet is not connected, the address is missing,
356
- * or the viem client is unavailable.
357
- */
358
- declare function getActiveWalletAndClient(config: Config): {
359
- activeWallet: GetAccountReturnType;
360
- walletClient: NonNullable<GetClientReturnType>;
361
- };
362
-
363
262
  /**
364
263
  * @file This file contains constants related to Safe (formerly Gnosis Safe) configuration,
365
264
  * including SDK options, web app URLs, and transaction service API endpoints for various chains.
@@ -405,8 +304,8 @@ declare const SafeTransactionServiceUrls: Record<number, string>;
405
304
  * @returns {string} The full URL to the transaction on the corresponding block explorer or Safe app,
406
305
  * or an empty string if the transaction or required chain configuration is not found.
407
306
  */
408
- declare const selectEvmTxExplorerLink: <T extends Transaction>({ chains, tx }: {
409
- chains: Chain[];
307
+ declare const selectEvmTxExplorerLink: <T extends Transaction>({ chains, tx, }: {
308
+ chains: readonly [Chain, ...Chain[]];
410
309
  tx: T;
411
310
  }) => string;
412
311
 
@@ -454,4 +353,4 @@ declare function speedUpTxAction<T extends Transaction>({ config, tx }: {
454
353
  tx: T;
455
354
  }): Promise<Hex>;
456
355
 
457
- export { type EVMTrackerParams, GelatoTaskState, type GelatoTaskStatusResponse, SafeTransactionServiceUrls, type SafeTxStatusResponse, cancelTxAction, checkAndInitializeTrackerInStore, checkChainForTx, checkIsGelatoAvailable, checkTransactionsTracker, createViemClient, evmAdapter, evmTracker, evmTrackerForStore, gelatoFetcher, gelatoTrackerForStore, getActiveWalletAndClient, getAddress, getAvatar, getName, gnosisSafeLinksHelper, isEnsName, isGelatoTxKey, safeFetcher, safeSdkOptions, safeTrackerForStore, selectEvmTxExplorerLink, speedUpTxAction };
356
+ export { type EVMTrackerParams, GelatoTaskState, type GelatoTaskStatusResponse, SafeTransactionServiceUrls, type SafeTxStatusResponse, cancelTxAction, checkAndInitializeTrackerInStore, checkIsGelatoAvailable, checkTransactionsTracker, evmTracker, evmTrackerForStore, gelatoFetcher, gelatoTrackerForStore, gnosisSafeLinksHelper, isGelatoTxKey, pulsarEvmAdapter, safeFetcher, safeSdkOptions, safeTrackerForStore, selectEvmTxExplorerLink, speedUpTxAction };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var pulsarCore=require('@tuwaio/pulsar-core'),core=require('@wagmi/core'),viem=require('viem'),actions=require('viem/actions'),h=require('dayjs'),chains=require('viem/chains'),ens=require('viem/ens');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var h__default=/*#__PURE__*/_interopDefault(h);var A=1.15;async function P({config:t,tx:e}){if(e.adapter!==pulsarCore.TransactionAdapter.EVM)throw new Error(`Cancellation is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:a,maxFeePerGas:n,maxPriorityFeePerGas:i,chainId:r}=e;if(a===void 0||!n||!i)throw new Error("Transaction is missing required fields for cancellation (nonce, maxFeePerGas, maxPriorityFeePerGas).");try{if(!t)throw new Error("Wagmi config is not provided.");let o=core.getAccount(t);if(!o.address)throw new Error("No connected account found.");let s=BigInt(Math.ceil(Number(i)*A)),c=BigInt(Math.ceil(Number(n)*A));return await core.sendTransaction(t,{to:o.address,value:0n,chainId:r,nonce:a,maxFeePerGas:c,maxPriorityFeePerGas:s})}catch(o){let s=o instanceof Error?o.message:String(o);throw new Error(`Failed to cancel transaction: ${s}`)}}function x(t,e){let a=e.find(n=>n.id===t);if(a)return viem.createPublicClient({chain:a,transport:viem.http()});console.warn(`createViemClient: No chain configuration found for chainId ${t}. A client could not be created.`);}var ke=10,be=3e3;async function we(t){let{tx:e,chains:a,onInitialize:n,onTxDetailsFetched:i,onSuccess:r,onFailure:o,onReplaced:s,retryCount:c=ke,retryTimeout:f=be,waitForTransactionReceiptParams:d}=t;if(n?.(),e.txKey===viem.zeroHash)return o(new Error("Transaction hash cannot be the zero hash."));let l=x(e.chainId,a);if(!l)return o(new Error(`Could not create a viem client for chainId: ${e.chainId}`));let u=null;for(let p=0;p<c;p++)try{u=await actions.getTransaction(l,{hash:e.txKey}),i(u);break}catch(T){if(p===c-1)return console.error(`EVM tracker failed to fetch tx ${e.txKey} after ${c} retries:`,T),o(T);await new Promise(y=>setTimeout(y,f));}if(!u)return o(new Error("Transaction details could not be fetched."));try{let p=!1,T=await actions.waitForTransactionReceipt(l,{hash:u.hash,onReplaced:y=>{p=!0,s(y);},...d});if(p)return;await r(u,T,l);}catch(p){console.error(`Error waiting for receipt for tx ${e.txKey}:`,p),o(p);}}async function E(t){let{tx:e,chains:a,updateTxParams:n,transactionsPool:i,onSuccessCallback:r}=t;return we({tx:e,chains:a,onInitialize:()=>{n(e.txKey,{hash:e.txKey});},onTxDetailsFetched:o=>{n(e.txKey,{to:o.to??void 0,input:o.input,value:o.value?.toString(),nonce:o.nonce,maxFeePerGas:o.maxFeePerGas?.toString(),maxPriorityFeePerGas:o.maxPriorityFeePerGas?.toString()});},onSuccess:async(o,s,c)=>{let f=await actions.getBlock(c,{blockNumber:s.blockNumber}),d=Number(f.timestamp),l=s.status==="success";n(e.txKey,{status:l?pulsarCore.TransactionStatus.Success:pulsarCore.TransactionStatus.Failed,isError:!l,pending:false,finishedTimestamp:d});let u=i[e.txKey];l&&r&&u&&r(u);},onReplaced:o=>{n(e.txKey,{status:pulsarCore.TransactionStatus.Replaced,replacedTxHash:o.transaction.hash,pending:false});},onFailure:o=>{n(e.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,errorMessage:o instanceof Error?o.message:"Transaction failed or could not be tracked."});}})}function F(t){return typeof t=="object"&&t!==null&&"taskId"in t}var Ee=(s=>(s.CheckPending="CheckPending",s.ExecPending="ExecPending",s.WaitingForConfirmation="WaitingForConfirmation",s.ExecSuccess="ExecSuccess",s.ExecReverted="ExecReverted",s.Cancelled="Cancelled",s.NotFound="NotFound",s))(Ee||{}),Se="https://api.gelato.digital/tasks/status/",I=new Set(["ExecReverted","Cancelled","NotFound"]);function ve(t){return t!=="ExecSuccess"&&!I.has(t)}var Ce=async({tx:t,stopPolling:e,onSuccess:a,onFailure:n,onIntervalTick:i})=>{let r=await fetch(`${Se}${t.txKey}`);if(!r.ok){if(r.status===404){n(),e();return}throw new Error(`Gelato API responded with status: ${r.status}`)}let o=await r.json(),{taskState:s,creationDate:c}=o.task;if(i?.(o),c&&h__default.default().diff(h__default.default(c),"day")>=1&&ve(s)){e();return}s==="ExecSuccess"?(a(o),e({withoutRemoving:true})):I.has(s)&&(n(o),e({withoutRemoving:true}));};function G({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:n,onSuccessCallback:i}){return pulsarCore.initializePollingTracker({tx:t,fetcher:Ce,removeTxFromPool:a,onSuccess:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:r.task.transactionHash,finishedTimestamp:r.task.executionDate?h__default.default(r.task.executionDate).unix():void 0});let o=n[t.txKey];i&&o&&i(o);},onIntervalTick:r=>{e(t.txKey,{hash:r.task.transactionHash});},onFailure:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:r?.task.transactionHash,errorMessage:r?.task.lastCheckMessage??"Transaction failed or was not found.",finishedTimestamp:r?.task.executionDate?h__default.default(r.task.executionDate).unix():void 0});}})}var Ct={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},q={[chains.mainnet.id]:"https://app.safe.global/eth:",[chains.goerli.id]:"https://app.safe.global/gor:",[chains.sepolia.id]:"https://app.safe.global/sep:",[chains.polygon.id]:"https://app.safe.global/matic:",[chains.arbitrum.id]:"https://app.safe.global/arb1:",[chains.aurora.id]:"https://app.safe.global/aurora:",[chains.avalanche.id]:"https://app.safe.global/avax:",[chains.base.id]:"https://app.safe.global/base:",[chains.boba.id]:"https://app.safe.global/boba:",[chains.bsc.id]:"https://app.safe.global/bnb:",[chains.celo.id]:"https://app.safe.global/celo:",[chains.gnosis.id]:"https://app.safe.global/gno:",[chains.optimism.id]:"https://app.safe.global/oeth:",[chains.polygonZkEvm.id]:"https://app.safe.global/zkevm:",[chains.zksync.id]:"https://app.safe.global/zksync:"},Y={[chains.mainnet.id]:"https://safe-transaction-mainnet.safe.global/api/v1",[chains.goerli.id]:"https://safe-transaction-goerli.safe.global/api/v1",[chains.sepolia.id]:"https://safe-transaction-sepolia.safe.global/api/v1",[chains.polygon.id]:"https://safe-transaction-polygon.safe.global/api/v1",[chains.arbitrum.id]:"https://safe-transaction-arbitrum.safe.global/api/v1",[chains.aurora.id]:"https://safe-transaction-aurora.safe.global/api/v1",[chains.avalanche.id]:"https://safe-transaction-avalanche.safe.global/api/v1",[chains.base.id]:"https://safe-transaction-base.safe.global/api/v1",[chains.boba.id]:"https://safe-transaction-boba.safe.global/api/v1",[chains.bsc.id]:"https://safe-transaction-bsc.safe.global/api/v1",[chains.celo.id]:"https://safe-transaction-celo.safe.global/api/v1",[chains.gnosis.id]:"https://safe-transaction-gnosis-chain.safe.global/api/v1",[chains.optimism.id]:"https://safe-transaction-optimism.safe.global/api/v1",[chains.polygonZkEvm.id]:"https://safe-transaction-zkevm.safe.global/api/v1",[chains.zksync.id]:"https://safe-transaction-zksync.safe.global/api/v1"};var Re=async({tx:t,stopPolling:e,onSuccess:a,onFailure:n,onReplaced:i,onIntervalTick:r})=>{let o=Y[t.chainId];if(!o)throw new Error(`Safe Transaction Service URL not found for chainId: ${t.chainId}`);let s=await fetch(`${o}/multisig-transactions/${t.txKey}/`);if(!s.ok)throw s.status===404&&(n(),e()),new Error(`Safe API responded with status: ${s.status}`);let c=await s.json();if(r?.(c),c.isExecuted){c.isSuccessful?a(c):n(c),e({withoutRemoving:true});return}let f=await fetch(`${o}/safes/${t.from}/multisig-transactions/?nonce=${c.nonce}`);if(!f.ok)throw new Error(`Safe API (nonce check) responded with status: ${f.status}`);let l=(await f.json()).results.find(u=>u.isExecuted);if(l){i?.(l),e({withoutRemoving:true});return}h__default.default().diff(h__default.default(c.submissionDate),"day")>=1&&e();};function Z({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:n,onSuccessCallback:i}){return pulsarCore.initializePollingTracker({tx:t,fetcher:Re,removeTxFromPool:a,onSuccess:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:r.transactionHash??void 0,finishedTimestamp:r.executionDate?h__default.default(r.executionDate).unix():void 0});let o=n[t.txKey];i&&o&&i(o);},onIntervalTick:r=>{e(t.txKey,{hash:r.transactionHash??void 0});},onFailure:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:r?.transactionHash??void 0,errorMessage:r?"Safe transaction failed or was rejected.":"Transaction not found.",finishedTimestamp:r?.executionDate?h__default.default(r.executionDate).unix():void 0});},onReplaced:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Replaced,pending:false,hash:t.adapter===pulsarCore.TransactionAdapter.EVM?t.hash:viem.zeroHash,replacedTxHash:r.safeTxHash??viem.zeroHash,finishedTimestamp:r.executionDate?h__default.default(r.executionDate).unix():void 0});}})}async function Q({tracker:t,tx:e,chains:a,transactionsPool:n,onSuccessCallback:i,...r}){switch(t){case pulsarCore.TransactionTracker.Ethereum:return E({tx:e,chains:a,transactionsPool:n,onSuccessCallback:i,...r});case pulsarCore.TransactionTracker.Gelato:return G({tx:e,transactionsPool:n,onSuccessCallback:i,...r});case pulsarCore.TransactionTracker.Safe:return Z({tx:e,transactionsPool:n,onSuccessCallback:i,...r});default:return console.warn(`Unknown tracker type: '${t}'. Falling back to default EVM tracker.`),E({tx:e,chains:a,transactionsPool:n,onSuccessCallback:i,...r})}}async function X(t,e){let{connector:a,chainId:n}=core.getAccount(e);if(a&&n!==t)try{await core.switchChain(e,{chainId:t});}catch(i){throw i.cause?.name==="UserRejectedRequestError"?new Error("User rejected the request to switch network."):(console.error("Failed to switch network:",i),new Error("An error occurred while switching the network."))}}function ee(t,e){if(F(t))return {tracker:pulsarCore.TransactionTracker.Gelato,txKey:t.taskId};if(!viem.isHex(t))throw new Error(`Invalid transaction key format. Expected a Hex string or a GelatoTxKey object, but received: ${JSON.stringify(t)}`);return e?.toLowerCase()==="safe"?{tracker:pulsarCore.TransactionTracker.Safe,txKey:t}:{tracker:pulsarCore.TransactionTracker.Ethereum,txKey:t}}var m=x(chains.mainnet.id,[chains.mainnet]),re=async t=>{if(!m)return null;try{return await ens.getEnsName(m,{address:t})}catch(e){return console.error(`ENS name lookup failed for address ${t}:`,e),null}},ne=async t=>{if(!m)return null;try{return await ens.getEnsAvatar(m,{name:ens.normalize(t)})}catch(e){return console.error(`ENS avatar lookup failed for name ${t}:`,e),null}},ia=async t=>{if(!m)return null;try{let e=await ens.getEnsAddress(m,{name:ens.normalize(t)});return e?e.toLowerCase():null}catch(e){return console.error(`ENS address lookup failed for name ${t}:`,e),null}},sa=t=>t.includes(".")&&!viem.isAddress(t);var ie=({chains:t,tx:e})=>{if(e.tracker===pulsarCore.TransactionTracker.Safe){let r=q[e.chainId];return r?`${r}${e.from}/transactions/tx?id=multisig_${e.from}_${e.txKey}`:""}let n=t.find(r=>r.id===e.chainId)?.blockExplorers?.default.url;if(!n)return "";let i=(e.adapter===pulsarCore.TransactionAdapter.EVM?e.replacedTxHash:e.txKey)||(e.adapter===pulsarCore.TransactionAdapter.EVM?e.hash:e.txKey);return i?`${n}/tx/${i}`:""};var se=1.15;async function ce({config:t,tx:e}){if(e.adapter!==pulsarCore.TransactionAdapter.EVM)throw new Error(`Speed up is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:a,from:n,to:i,value:r,input:o,maxFeePerGas:s,maxPriorityFeePerGas:c,chainId:f}=e;if(a===void 0||!n||!i||!r||!s||!c)throw new Error("Transaction is missing required fields for speed-up.");try{if(!t)throw new Error("Wagmi config is not provided.");if(!core.getAccount(t).address)throw new Error("No connected account found.");let l=BigInt(Math.ceil(Number(c)*se)),u=BigInt(Math.ceil(Number(s)*se));return await core.sendTransaction(t,{to:i,value:BigInt(r),data:o||"0x",chainId:f,nonce:a,maxFeePerGas:u,maxPriorityFeePerGas:l})}catch(d){let l=d instanceof Error?d.message:String(d);throw new Error(`Failed to speed up transaction: ${l}`)}}function Ga(t,e){if(!t)throw new Error("EVM adapter requires a wagmi config object.");return {key:pulsarCore.TransactionAdapter.EVM,getWalletInfo:()=>{let a=core.getAccount(t);return {walletAddress:a.address??viem.zeroAddress,walletType:a.connector?.name?.toLowerCase()??"unknown"}},checkChainForTx:a=>X(a,t),checkTransactionsTracker:(a,n)=>ee(a,n),checkAndInitializeTrackerInStore:({tx:a,...n})=>Q({tracker:a.tracker,tx:a,chains:e,...n}),getExplorerUrl:a=>{let{chain:n}=core.getAccount(t),i=n?.blockExplorers?.default.url;return a?`${i}/${a}`:i},getExplorerTxUrl:a=>ie({chains:e,tx:a}),getName:a=>re(a),getAvatar:a=>ne(a),cancelTxAction:a=>P({config:t,tx:a}),speedUpTxAction:a=>ce({config:t,tx:a}),retryTxAction:async({onClose:a,txKey:n,handleTransaction:i,tx:r})=>{if(a(n),!i){console.error("Retry failed: handleTransaction function is not provided.");return}await i({actionFunction:()=>r.actionFunction({config:t,...r.payload}),params:r,defaultTracker:pulsarCore.TransactionTracker.Ethereum});}}}var b=null,w=null,Oe=300*1e3,We="https://relay.gelato.digital/relays/v2/supported-chains";async function $a(t){let e=Date.now();if(b&&w&&e-w<Oe)return b.includes(t);try{let a=await fetch(We);if(!a.ok)throw new Error(`Gelato API responded with status: ${a.status}`);let i=(await a.json()).chains.map(Number);return b=i,w=e,i.includes(t)}catch(a){return console.error("Failed to fetch Gelato supported chains:",a),b=null,w=null,false}}function za(t){let e=core.getAccount(t),a=core.getClient(t);if(!e.address)throw new Error("getActiveWalletAndClient failed: No connected wallet address found.");if(!a)throw new Error("getActiveWalletAndClient failed: Wallet client is unavailable.");return {activeWallet:e,walletClient:a}}
2
- exports.GelatoTaskState=Ee;exports.SafeTransactionServiceUrls=Y;exports.cancelTxAction=P;exports.checkAndInitializeTrackerInStore=Q;exports.checkChainForTx=X;exports.checkIsGelatoAvailable=$a;exports.checkTransactionsTracker=ee;exports.createViemClient=x;exports.evmAdapter=Ga;exports.evmTracker=we;exports.evmTrackerForStore=E;exports.gelatoFetcher=Ce;exports.gelatoTrackerForStore=G;exports.getActiveWalletAndClient=za;exports.getAddress=ia;exports.getAvatar=ne;exports.getName=re;exports.gnosisSafeLinksHelper=q;exports.isEnsName=sa;exports.isGelatoTxKey=F;exports.safeFetcher=Re;exports.safeSdkOptions=Ct;exports.safeTrackerForStore=Z;exports.selectEvmTxExplorerLink=ie;exports.speedUpTxAction=ce;//# sourceMappingURL=index.js.map
1
+ 'use strict';var orbitCore=require('@tuwaio/orbit-core'),orbitEvm=require('@tuwaio/orbit-evm'),pulsarCore=require('@tuwaio/pulsar-core'),core=require('@wagmi/core'),viem=require('viem'),actions=require('viem/actions'),m=require('dayjs'),chains=require('viem/chains');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var m__default=/*#__PURE__*/_interopDefault(m);var v=1.15;async function P({config:t,tx:e}){if(e.adapter!==orbitCore.OrbitAdapter.EVM)throw new Error(`Cancellation is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:r,maxFeePerGas:o,maxPriorityFeePerGas:s,chainId:a}=e;if(r===void 0||!o||!s)throw new Error("Transaction is missing required fields for cancellation (nonce, maxFeePerGas, maxPriorityFeePerGas).");try{if(!t)throw new Error("Wagmi config is not provided.");let n=core.getAccount(t);if(!n.address)throw new Error("No connected account found.");let i=BigInt(Math.ceil(Number(s)*v)),c=BigInt(Math.ceil(Number(o)*v));return await core.sendTransaction(t,{to:n.address,value:0n,chainId:a,nonce:r,maxFeePerGas:c,maxPriorityFeePerGas:i})}catch(n){let i=n instanceof Error?n.message:String(n);throw new Error(`Failed to cancel transaction: ${i}`)}}var de=10,ue=3e3;async function me(t){let{tx:e,config:r,onInitialize:o,onTxDetailsFetched:s,onSuccess:a,onFailure:n,onReplaced:i,retryCount:c=de,retryTimeout:p=ue,waitForTransactionReceiptParams:d}=t;if(o?.(),e.txKey===viem.zeroHash)return n(new Error("Transaction hash cannot be the zero hash."));let l=core.getClient(r,{chainId:e.chainId});if(!l)return n(new Error(`Could not create a viem client for chainId: ${e.chainId}`));let f=null;for(let u=0;u<c;u++)try{f=await actions.getTransaction(l,{hash:e.txKey}),s(f);break}catch(T){if(u===c-1)return console.error(`EVM tracker failed to fetch tx ${e.txKey} after ${c} retries:`,T),n(T);await new Promise(b=>setTimeout(b,p));}if(!f)return n(new Error("Transaction details could not be fetched."));try{let u=!1,T=await actions.waitForTransactionReceipt(l,{hash:f.hash,onReplaced:b=>{u=!0,i(b);},...d});if(u)return;await a(f,T,l);}catch(u){console.error(`Error waiting for receipt for tx ${e.txKey}:`,u),n(u);}}async function y(t){let{tx:e,config:r,updateTxParams:o,transactionsPool:s,onSuccessCallback:a}=t;return me({tx:e,config:r,onInitialize:()=>{o(e.txKey,{hash:e.txKey});},onTxDetailsFetched:n=>{o(e.txKey,{to:n.to??void 0,input:n.input,value:n.value?.toString(),nonce:n.nonce,maxFeePerGas:n.maxFeePerGas?.toString(),maxPriorityFeePerGas:n.maxPriorityFeePerGas?.toString()});},onSuccess:async(n,i,c)=>{let p=await actions.getBlock(c,{blockNumber:i.blockNumber}),d=Number(p.timestamp),l=i.status==="success";o(e.txKey,{status:l?pulsarCore.TransactionStatus.Success:pulsarCore.TransactionStatus.Failed,isError:!l,pending:false,finishedTimestamp:d});let f=s[e.txKey];l&&a&&f&&a(f);},onReplaced:n=>{o(e.txKey,{status:pulsarCore.TransactionStatus.Replaced,replacedTxHash:n.transaction.hash,pending:false});},onFailure:n=>{o(e.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,errorMessage:n instanceof Error?n.message:"Transaction failed or could not be tracked."});}})}function F(t){return typeof t=="object"&&t!==null&&"taskId"in t}var he=(i=>(i.CheckPending="CheckPending",i.ExecPending="ExecPending",i.WaitingForConfirmation="WaitingForConfirmation",i.ExecSuccess="ExecSuccess",i.ExecReverted="ExecReverted",i.Cancelled="Cancelled",i.NotFound="NotFound",i))(he||{}),xe="https://api.gelato.digital/tasks/status/",I=new Set(["ExecReverted","Cancelled","NotFound"]);function ge(t){return t!=="ExecSuccess"&&!I.has(t)}var ke=async({tx:t,stopPolling:e,onSuccess:r,onFailure:o,onIntervalTick:s})=>{let a=await fetch(`${xe}${t.txKey}`);if(!a.ok){if(a.status===404){o(),e();return}throw new Error(`Gelato API responded with status: ${a.status}`)}let n=await a.json(),{taskState:i,creationDate:c}=n.task;if(s?.(n),c&&m__default.default().diff(m__default.default(c),"hour")>=1&&ge(i)){e();return}i==="ExecSuccess"?(r(n),e({withoutRemoving:true})):I.has(i)&&(o(n),e({withoutRemoving:true}));};function C({tx:t,updateTxParams:e,removeTxFromPool:r,transactionsPool:o,onSuccessCallback:s}){return pulsarCore.initializePollingTracker({tx:t,fetcher:ke,removeTxFromPool:r,onSuccess:a=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:a.task.transactionHash,finishedTimestamp:a.task.executionDate?m__default.default(a.task.executionDate).unix():void 0});let n=o[t.txKey];s&&n&&s(n);},onIntervalTick:a=>{e(t.txKey,{hash:a.task.transactionHash});},onFailure:a=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:a?.task.transactionHash,errorMessage:a?.task.lastCheckMessage??"Transaction failed or was not found.",finishedTimestamp:a?.task.executionDate?m__default.default(a.task.executionDate).unix():void 0});}})}var ft={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},j={[chains.mainnet.id]:"https://app.safe.global/eth:",[chains.goerli.id]:"https://app.safe.global/gor:",[chains.sepolia.id]:"https://app.safe.global/sep:",[chains.polygon.id]:"https://app.safe.global/matic:",[chains.arbitrum.id]:"https://app.safe.global/arb1:",[chains.aurora.id]:"https://app.safe.global/aurora:",[chains.avalanche.id]:"https://app.safe.global/avax:",[chains.base.id]:"https://app.safe.global/base:",[chains.boba.id]:"https://app.safe.global/boba:",[chains.bsc.id]:"https://app.safe.global/bnb:",[chains.celo.id]:"https://app.safe.global/celo:",[chains.gnosis.id]:"https://app.safe.global/gno:",[chains.optimism.id]:"https://app.safe.global/oeth:",[chains.polygonZkEvm.id]:"https://app.safe.global/zkevm:",[chains.zksync.id]:"https://app.safe.global/zksync:"},B={[chains.mainnet.id]:"https://safe-transaction-mainnet.safe.global/api/v1",[chains.goerli.id]:"https://safe-transaction-goerli.safe.global/api/v1",[chains.sepolia.id]:"https://safe-transaction-sepolia.safe.global/api/v1",[chains.polygon.id]:"https://safe-transaction-polygon.safe.global/api/v1",[chains.arbitrum.id]:"https://safe-transaction-arbitrum.safe.global/api/v1",[chains.aurora.id]:"https://safe-transaction-aurora.safe.global/api/v1",[chains.avalanche.id]:"https://safe-transaction-avalanche.safe.global/api/v1",[chains.base.id]:"https://safe-transaction-base.safe.global/api/v1",[chains.boba.id]:"https://safe-transaction-boba.safe.global/api/v1",[chains.bsc.id]:"https://safe-transaction-bsc.safe.global/api/v1",[chains.celo.id]:"https://safe-transaction-celo.safe.global/api/v1",[chains.gnosis.id]:"https://safe-transaction-gnosis-chain.safe.global/api/v1",[chains.optimism.id]:"https://safe-transaction-optimism.safe.global/api/v1",[chains.polygonZkEvm.id]:"https://safe-transaction-zkevm.safe.global/api/v1",[chains.zksync.id]:"https://safe-transaction-zksync.safe.global/api/v1"};var Ee=async({tx:t,stopPolling:e,onSuccess:r,onFailure:o,onReplaced:s,onIntervalTick:a})=>{let n=B[t.chainId];if(!n)throw new Error(`Safe Transaction Service URL not found for chainId: ${t.chainId}`);let i=await fetch(`${n}/multisig-transactions/${t.txKey}/`);if(!i.ok)throw i.status===404&&(o(),e()),new Error(`Safe API responded with status: ${i.status}`);let c=await i.json();if(a?.(c),c.isExecuted){c.isSuccessful?r(c):o(c),e({withoutRemoving:true});return}let p=await fetch(`${n}/safes/${t.from}/multisig-transactions/?nonce=${c.nonce}`);if(!p.ok)throw new Error(`Safe API (nonce check) responded with status: ${p.status}`);let l=(await p.json()).results.find(f=>f.isExecuted);if(l){s?.(l),e({withoutRemoving:true});return}m__default.default().diff(m__default.default(c.submissionDate),"day")>=1&&e();};function Y({tx:t,updateTxParams:e,removeTxFromPool:r,transactionsPool:o,onSuccessCallback:s}){return pulsarCore.initializePollingTracker({tx:t,fetcher:Ee,removeTxFromPool:r,onSuccess:a=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:a.transactionHash??void 0,finishedTimestamp:a.executionDate?m__default.default(a.executionDate).unix():void 0});let n=o[t.txKey];s&&n&&s(n);},onIntervalTick:a=>{e(t.txKey,{hash:a.transactionHash??void 0});},onFailure:a=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:a?.transactionHash??void 0,errorMessage:a?"Safe transaction failed or was rejected.":"Transaction not found.",finishedTimestamp:a?.executionDate?m__default.default(a.executionDate).unix():void 0});},onReplaced:a=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Replaced,pending:false,hash:t.adapter===orbitCore.OrbitAdapter.EVM?t.hash:viem.zeroHash,replacedTxHash:a.safeTxHash??viem.zeroHash,finishedTimestamp:a.executionDate?m__default.default(a.executionDate).unix():void 0});}})}async function J({tracker:t,tx:e,config:r,transactionsPool:o,onSuccessCallback:s,...a}){switch(t){case pulsarCore.TransactionTracker.Ethereum:return y({tx:e,config:r,transactionsPool:o,onSuccessCallback:s,...a});case pulsarCore.TransactionTracker.Gelato:return C({tx:e,transactionsPool:o,onSuccessCallback:s,...a});case pulsarCore.TransactionTracker.Safe:return Y({tx:e,transactionsPool:o,onSuccessCallback:s,...a});default:return console.warn(`Unknown tracker type: '${t}'. Falling back to default EVM tracker.`),y({tx:e,config:r,transactionsPool:o,onSuccessCallback:s,...a})}}function Z(t,e){if(F(t))return {tracker:pulsarCore.TransactionTracker.Gelato,txKey:t.taskId};if(!viem.isHex(t))throw new Error(`Invalid transaction key format. Expected a Hex string or a GelatoTxKey object, but received: ${JSON.stringify(t)}`);let r=e.split(":");return (r.length>1?r[r.length-1]==="safe"||r[r.length-1]==="safewallet":e?.toLowerCase()==="safe")?{tracker:pulsarCore.TransactionTracker.Safe,txKey:t}:{tracker:pulsarCore.TransactionTracker.Ethereum,txKey:t}}var X=({chains:t,tx:e})=>{if(e.tracker===pulsarCore.TransactionTracker.Safe){let a=j[e.chainId];return a?`${a}${e.from}/transactions/tx?id=multisig_${e.from}_${e.txKey}`:""}let o=t.find(a=>a.id===e.chainId)?.blockExplorers?.default.url;if(!o)return "";let s=(e.adapter===orbitCore.OrbitAdapter.EVM?e.replacedTxHash:e.txKey)||(e.adapter===orbitCore.OrbitAdapter.EVM?e.hash:e.txKey);return s?`${o}/tx/${s}`:""};var ee=1.15;async function te({config:t,tx:e}){if(e.adapter!==orbitCore.OrbitAdapter.EVM)throw new Error(`Speed up is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:r,from:o,to:s,value:a,input:n,maxFeePerGas:i,maxPriorityFeePerGas:c,chainId:p}=e;if(r===void 0||!o||!s||!a||!i||!c)throw new Error("Transaction is missing required fields for speed-up.");try{if(!t)throw new Error("Wagmi config is not provided.");if(!core.getAccount(t).address)throw new Error("No connected account found.");let l=BigInt(Math.ceil(Number(c)*ee)),f=BigInt(Math.ceil(Number(i)*ee));return await core.sendTransaction(t,{to:s,value:BigInt(a),data:n||"0x",chainId:p,nonce:r,maxFeePerGas:f,maxPriorityFeePerGas:l})}catch(d){let l=d instanceof Error?d.message:String(d);throw new Error(`Failed to speed up transaction: ${l}`)}}function oa(t,e){if(!t)throw new Error("EVM adapter requires a wagmi config object.");return {key:orbitCore.OrbitAdapter.EVM,getWalletInfo:()=>{let r=core.getAccount(t),o=orbitCore.lastConnectedWalletHelpers.getLastConnectedWallet();return {walletAddress:r.address??o?.address??viem.zeroAddress,walletType:orbitCore.getWalletTypeFromConnectorName(orbitCore.OrbitAdapter.EVM,r.connector?.name?.toLowerCase()??"unknown")}},checkChainForTx:r=>orbitEvm.checkAndSwitchChain(r,t),checkTransactionsTracker:(r,o)=>Z(r,o),checkAndInitializeTrackerInStore:({tx:r,...o})=>J({tracker:r.tracker,tx:r,config:t,...o}),getExplorerUrl:r=>{let{chain:o}=core.getAccount(t),s=o?.blockExplorers?.default.url;return r?`${s}/${r}`:s},getExplorerTxUrl:r=>X({chains:e,tx:r}),cancelTxAction:r=>P({config:t,tx:r}),speedUpTxAction:r=>te({config:t,tx:r}),retryTxAction:async({onClose:r,txKey:o,executeTxAction:s,tx:a})=>{if(r(o),!s){console.error("Retry failed: executeTxAction function is not provided.");return}await s({actionFunction:()=>a.actionFunction({config:t,...a.payload}),params:a,defaultTracker:pulsarCore.TransactionTracker.Ethereum});}}}var g=null,k=null,He=300*1e3,Ke="https://relay.gelato.digital/relays/v2/supported-chains";async function ia(t){let e=Date.now();if(g&&k&&e-k<He)return g.includes(t);try{let r=await fetch(Ke);if(!r.ok)throw new Error(`Gelato API responded with status: ${r.status}`);let s=(await r.json()).chains.map(Number);return g=s,k=e,s.includes(t)}catch(r){return console.error("Failed to fetch Gelato supported chains:",r),g=null,k=null,false}}
2
+ exports.GelatoTaskState=he;exports.SafeTransactionServiceUrls=B;exports.cancelTxAction=P;exports.checkAndInitializeTrackerInStore=J;exports.checkIsGelatoAvailable=ia;exports.checkTransactionsTracker=Z;exports.evmTracker=me;exports.evmTrackerForStore=y;exports.gelatoFetcher=ke;exports.gelatoTrackerForStore=C;exports.gnosisSafeLinksHelper=j;exports.isGelatoTxKey=F;exports.pulsarEvmAdapter=oa;exports.safeFetcher=Ee;exports.safeSdkOptions=ft;exports.safeTrackerForStore=Y;exports.selectEvmTxExplorerLink=X;exports.speedUpTxAction=te;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map