@tuwaio/pulsar-evm 0.3.1 → 0.4.1
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.mts +149 -45
- package/dist/index.d.ts +149 -45
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +13 -12
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Transaction, TxAdapter, ITxTrackingStore, TrackerCallbacks, PollingTrackerConfig,
|
|
1
|
+
import { Transaction, TxAdapter, ITxTrackingStore, TrackerCallbacks, PollingTrackerConfig, TransactionTracker, CheckTxTracker } from '@tuwaio/pulsar-core';
|
|
2
2
|
import { Config } from '@wagmi/core';
|
|
3
|
-
import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex } from 'viem';
|
|
3
|
+
import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex, Transport, HttpTransportConfig } from 'viem';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file This file contains the factory function for creating the EVM (Ethereum Virtual Machine) transaction adapter.
|
|
@@ -64,56 +64,97 @@ declare function evmTrackerForStore<T extends Transaction>(params: Pick<EVMTrack
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* @file This file implements the transaction tracking logic for meta-transactions relayed via the Gelato Network.
|
|
67
|
-
* It uses a polling mechanism to check the status of a Gelato
|
|
67
|
+
* It uses a polling mechanism to check the status of a Gelato task via the authenticated Gelato RPC client.
|
|
68
|
+
*
|
|
69
|
+
* The fetcher calls `relayer_getStatus` on the Gelato RPC endpoint and interprets the numeric
|
|
70
|
+
* status codes to determine whether a task is still pending, succeeded, was rejected, or reverted.
|
|
68
71
|
*/
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
*/
|
|
75
|
-
declare
|
|
74
|
+
* Numeric status codes returned by the Gelato `relayer_getStatus` RPC method.
|
|
75
|
+
*
|
|
76
|
+
* @see https://docs.gelato.cloud/
|
|
77
|
+
*/
|
|
78
|
+
declare enum GelatoStatusCode {
|
|
79
|
+
/** The task has been received and is awaiting execution. */
|
|
80
|
+
Pending = 100,
|
|
81
|
+
/** The task has been submitted to the mempool and has a transaction hash. */
|
|
82
|
+
Submitted = 110,
|
|
83
|
+
/** The task was successfully executed and mined. */
|
|
84
|
+
Success = 200,
|
|
85
|
+
/** The task was rejected by the relayer before execution (e.g., validation failure). */
|
|
86
|
+
Rejected = 400,
|
|
87
|
+
/** The task was submitted but the transaction reverted on-chain. */
|
|
88
|
+
Reverted = 500
|
|
89
|
+
}
|
|
76
90
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @see https://docs.gelato.network/developer-services/relay/api/get-task-status
|
|
91
|
+
* Common fields shared by all Gelato task status responses.
|
|
79
92
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
93
|
+
type GelatoBaseStatus = {
|
|
94
|
+
/** The chain ID on which the task was submitted. */
|
|
95
|
+
chainId: number;
|
|
96
|
+
/** Unix timestamp (in seconds) when the task was created. */
|
|
97
|
+
createdAt: number;
|
|
98
|
+
/** The unique Gelato task identifier. */
|
|
99
|
+
id: string;
|
|
100
|
+
};
|
|
89
101
|
/**
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
* Discriminated union representing all possible Gelato task status responses.
|
|
103
|
+
* Each variant corresponds to a specific {@link GelatoStatusCode}.
|
|
104
|
+
*/
|
|
105
|
+
type GelatoTaskStatus = (GelatoBaseStatus & {
|
|
106
|
+
status: GelatoStatusCode.Pending;
|
|
107
|
+
}) | (GelatoBaseStatus & {
|
|
108
|
+
status: GelatoStatusCode.Submitted;
|
|
109
|
+
hash: Hex;
|
|
110
|
+
}) | (GelatoBaseStatus & {
|
|
111
|
+
status: GelatoStatusCode.Success;
|
|
112
|
+
receipt: {
|
|
113
|
+
transactionHash: Hex;
|
|
102
114
|
};
|
|
103
|
-
}
|
|
115
|
+
}) | (GelatoBaseStatus & {
|
|
116
|
+
status: GelatoStatusCode.Rejected;
|
|
117
|
+
message: string;
|
|
118
|
+
data?: unknown;
|
|
119
|
+
}) | (GelatoBaseStatus & {
|
|
120
|
+
status: GelatoStatusCode.Reverted;
|
|
121
|
+
message?: string;
|
|
122
|
+
data: string;
|
|
123
|
+
receipt: {
|
|
124
|
+
transactionHash: Hex;
|
|
125
|
+
};
|
|
126
|
+
});
|
|
104
127
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
128
|
+
* Creates a reusable fetcher function for `initializePollingTracker` that queries the
|
|
129
|
+
* Gelato RPC endpoint (`relayer_getStatus`) for a task's status using an authenticated client.
|
|
130
|
+
*
|
|
131
|
+
* The fetcher interprets the numeric status codes and calls the appropriate polling callbacks:
|
|
132
|
+
* - {@link GelatoStatusCode.Success} → `onSuccess`
|
|
133
|
+
* - {@link GelatoStatusCode.Rejected} / {@link GelatoStatusCode.Reverted} → `onFailure`
|
|
134
|
+
* - {@link GelatoStatusCode.Submitted} → `onIntervalTick` (to update the tx hash)
|
|
135
|
+
*
|
|
136
|
+
* @param {ReturnType<Transport>} client - A viem transport client configured for the Gelato API.
|
|
137
|
+
* @returns {PollingTrackerConfig<GelatoTaskStatus, Transaction>['fetcher']} The fetcher function.
|
|
107
138
|
*/
|
|
108
|
-
declare
|
|
139
|
+
declare function gelatoFetcher(client: ReturnType<Transport>): PollingTrackerConfig<GelatoTaskStatus, Transaction>['fetcher'];
|
|
109
140
|
/**
|
|
110
141
|
* A higher-level wrapper that integrates the Gelato polling logic with the Pulsar store.
|
|
111
|
-
* It
|
|
142
|
+
* It creates an authenticated Gelato RPC client and uses {@link gelatoFetcher} to
|
|
143
|
+
* build the fetcher, then delegates to `initializePollingTracker` with store-specific callbacks.
|
|
112
144
|
*
|
|
113
145
|
* @template T - The application-specific transaction type.
|
|
114
|
-
|
|
115
|
-
|
|
146
|
+
*
|
|
147
|
+
* @param params.tx - The transaction to track.
|
|
148
|
+
* @param params.gelatoApiKey - The Gelato API key for authenticating RPC requests.
|
|
149
|
+
* @param params.updateTxParams - Store action to update transaction fields.
|
|
150
|
+
* @param params.removeTxFromPool - Store action to remove a transaction from the pool.
|
|
151
|
+
* @param params.transactionsPool - The current pool of tracked transactions.
|
|
152
|
+
* @param params.onSuccess - Optional callback invoked when the transaction succeeds.
|
|
153
|
+
* @param params.onError - Optional callback invoked when the transaction fails.
|
|
154
|
+
*/
|
|
155
|
+
declare function gelatoTrackerForStore<T extends Transaction>({ tx, gelatoApiKey, updateTxParams, removeTxFromPool, transactionsPool, onSuccess, onError, }: Pick<ITxTrackingStore<T>, 'updateTxParams' | 'removeTxFromPool' | 'transactionsPool'> & {
|
|
116
156
|
tx: T;
|
|
157
|
+
gelatoApiKey: string;
|
|
117
158
|
} & TrackerCallbacks<T>): void;
|
|
118
159
|
|
|
119
160
|
/**
|
|
@@ -206,6 +247,7 @@ type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>,
|
|
|
206
247
|
config: Config;
|
|
207
248
|
tx: T;
|
|
208
249
|
tracker: TransactionTracker;
|
|
250
|
+
gelatoApiKey?: string;
|
|
209
251
|
} & TrackerCallbacks<T>;
|
|
210
252
|
/**
|
|
211
253
|
* Initializes the appropriate tracker for a given transaction based on its `tracker` type.
|
|
@@ -216,21 +258,48 @@ type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>,
|
|
|
216
258
|
* @param {InitializeTrackerParams<T>} params - The parameters for initializing the tracker.
|
|
217
259
|
* @returns {Promise<void>} A promise that resolves once the tracking process has been successfully initiated.
|
|
218
260
|
*/
|
|
219
|
-
declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, config, transactionsPool, onSuccess, onError, onReplaced, ...rest }: InitializeTrackerParams<T>): Promise<void>;
|
|
261
|
+
declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, config, transactionsPool, onSuccess, onError, onReplaced, gelatoApiKey, ...rest }: InitializeTrackerParams<T>): Promise<void>;
|
|
220
262
|
|
|
221
263
|
/**
|
|
222
264
|
* @file This file contains a utility to check if the Gelato Relay service is available for a specific chain.
|
|
265
|
+
* It uses the authenticated Gelato RPC client to fetch relay capabilities and caches the result.
|
|
223
266
|
*/
|
|
267
|
+
/**
|
|
268
|
+
* Represents the per-chain capabilities returned by the Gelato `relayer_getCapabilities` RPC method.
|
|
269
|
+
*
|
|
270
|
+
* @property {string} feeCollector - The address of the fee collector contract on this chain.
|
|
271
|
+
* @property {GelatoToken[]} tokens - The list of ERC-20 tokens accepted for fee payment on this chain.
|
|
272
|
+
*/
|
|
273
|
+
type GelatoCapabilitiesByChain = {
|
|
274
|
+
feeCollector: string;
|
|
275
|
+
tokens: GelatoToken[];
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Represents a token accepted for fee payment by the Gelato Relay on a given chain.
|
|
279
|
+
*
|
|
280
|
+
* @property {string} address - The ERC-20 token contract address.
|
|
281
|
+
* @property {number} decimals - The number of decimals for the token.
|
|
282
|
+
*/
|
|
283
|
+
type GelatoToken = {
|
|
284
|
+
address: string;
|
|
285
|
+
decimals: number;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* A record of Gelato relay capabilities keyed by numeric chain ID.
|
|
289
|
+
*/
|
|
290
|
+
type GelatoCapabilities = Record<number, GelatoCapabilitiesByChain>;
|
|
224
291
|
/**
|
|
225
292
|
* Checks if the Gelato Relay service supports a given chain ID.
|
|
226
293
|
*
|
|
227
|
-
* This function fetches the
|
|
228
|
-
*
|
|
294
|
+
* This function fetches the relay capabilities via the authenticated Gelato RPC client
|
|
295
|
+
* (`relayer_getCapabilities`) and checks whether the specified chain is present in the response.
|
|
296
|
+
* Results are cached in memory per API key for the lifetime of the application to minimize network requests.
|
|
229
297
|
*
|
|
230
298
|
* @param {number} chainId - The chain identifier to check.
|
|
299
|
+
* @param {string} gelatoApiKey - The Gelato API key used for authentication.
|
|
231
300
|
* @returns {Promise<boolean>} A promise that resolves to `true` if Gelato supports the chain, `false` otherwise.
|
|
232
301
|
*/
|
|
233
|
-
declare function checkIsGelatoAvailable(chainId: number): Promise<boolean>;
|
|
302
|
+
declare function checkIsGelatoAvailable(chainId: number, gelatoApiKey: string): Promise<boolean>;
|
|
234
303
|
|
|
235
304
|
/**
|
|
236
305
|
* @file This file contains a utility function to determine the correct tracker for a transaction
|
|
@@ -249,16 +318,51 @@ declare function checkIsGelatoAvailable(chainId: number): Promise<boolean>;
|
|
|
249
318
|
*
|
|
250
319
|
* @param {ActionTxKey} actionTxKey - The key returned from the transaction submission function (e.g., a hash or a Gelato task object).
|
|
251
320
|
* @param {string} connectorType - The type of the connector that initiated the action (e.g., 'safe', 'injected').
|
|
252
|
-
*
|
|
321
|
+
* @param {TransactionTracker} tracker - The type of transaction tracker to use.
|
|
322
|
+
* @param {string} gelatoApiKey - Gelato API key for Gelato relayer integration.
|
|
253
323
|
* @returns {{ tracker: TransactionTracker; txKey: string }} An object containing the determined tracker type and the final string-based transaction key.
|
|
254
324
|
*
|
|
255
325
|
* @throws {Error} Throws an error if the `actionTxKey` is not a valid Hex string after failing the Gelato check.
|
|
256
326
|
*/
|
|
257
|
-
declare function checkTransactionsTracker(actionTxKey
|
|
327
|
+
declare function checkTransactionsTracker({ actionTxKey, connectorType, tracker, gelatoApiKey }: CheckTxTracker): {
|
|
258
328
|
tracker: TransactionTracker;
|
|
259
329
|
txKey: string;
|
|
260
330
|
};
|
|
261
331
|
|
|
332
|
+
/**
|
|
333
|
+
* @file This file contains a utility function for creating a cached viem HTTP transport
|
|
334
|
+
* client configured for the Gelato Relay API.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Configuration options for creating a Gelato API client.
|
|
339
|
+
*
|
|
340
|
+
* @property {string} apiKey - The Gelato API key used for authentication.
|
|
341
|
+
* @property {number} [timeout] - Optional custom HTTP timeout in milliseconds. Defaults to 15000ms.
|
|
342
|
+
* @property {string} [baseUrl] - Optional custom base URL for the Gelato API. Defaults to `https://api.gelato.cloud/rpc`.
|
|
343
|
+
* @property {HttpTransportConfig} [httpTransportConfig] - Optional additional viem HTTP transport configuration overrides.
|
|
344
|
+
*/
|
|
345
|
+
type GelatoClientConfig = {
|
|
346
|
+
apiKey: string;
|
|
347
|
+
timeout?: number;
|
|
348
|
+
baseUrl?: string;
|
|
349
|
+
httpTransportConfig?: HttpTransportConfig;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Creates or retrieves a cached viem HTTP transport client configured for the Gelato Relay API.
|
|
353
|
+
*
|
|
354
|
+
* The client is cached by a composite key of `apiKey` and `baseUrl` to avoid
|
|
355
|
+
* creating redundant transport instances for identical configurations.
|
|
356
|
+
*
|
|
357
|
+
* The default HTTP timeout is set to 15 seconds (instead of viem's default) because
|
|
358
|
+
* Gelato's synchronous relay methods may take up to 10 seconds on the server side,
|
|
359
|
+
* and the client should not time out before the server does.
|
|
360
|
+
*
|
|
361
|
+
* @param {GelatoClientConfig} parameters - The configuration for the Gelato client.
|
|
362
|
+
* @returns {ReturnType<Transport>} A viem transport instance configured for the Gelato API.
|
|
363
|
+
*/
|
|
364
|
+
declare const createGelatoClient: (parameters: GelatoClientConfig) => ReturnType<Transport>;
|
|
365
|
+
|
|
262
366
|
/**
|
|
263
367
|
* @file This file contains constants related to Safe (formerly Gnosis Safe) configuration,
|
|
264
368
|
* including SDK options, web app URLs, and transaction service API endpoints for various chains.
|
|
@@ -353,4 +457,4 @@ declare function speedUpTxAction<T extends Transaction>({ config, tx }: {
|
|
|
353
457
|
tx: T;
|
|
354
458
|
}): Promise<Hex>;
|
|
355
459
|
|
|
356
|
-
export { type EVMTrackerParams,
|
|
460
|
+
export { type EVMTrackerParams, type GelatoCapabilities, type GelatoCapabilitiesByChain, type GelatoClientConfig, GelatoStatusCode, type GelatoTaskStatus, type GelatoToken, SafeTransactionServiceUrls, type SafeTxStatusResponse, cancelTxAction, checkAndInitializeTrackerInStore, checkIsGelatoAvailable, checkTransactionsTracker, createGelatoClient, evmTracker, evmTrackerForStore, gelatoFetcher, gelatoTrackerForStore, gnosisSafeLinksHelper, pulsarEvmAdapter, safeFetcher, safeSdkOptions, safeTrackerForStore, selectEvmTxExplorerLink, speedUpTxAction };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Transaction, TxAdapter, ITxTrackingStore, TrackerCallbacks, PollingTrackerConfig,
|
|
1
|
+
import { Transaction, TxAdapter, ITxTrackingStore, TrackerCallbacks, PollingTrackerConfig, TransactionTracker, CheckTxTracker } from '@tuwaio/pulsar-core';
|
|
2
2
|
import { Config } from '@wagmi/core';
|
|
3
|
-
import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex } from 'viem';
|
|
3
|
+
import { Chain, GetTransactionReturnType, TransactionReceipt, Client, ReplacementReturnType, WaitForTransactionReceiptParameters, Hex, Transport, HttpTransportConfig } from 'viem';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file This file contains the factory function for creating the EVM (Ethereum Virtual Machine) transaction adapter.
|
|
@@ -64,56 +64,97 @@ declare function evmTrackerForStore<T extends Transaction>(params: Pick<EVMTrack
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* @file This file implements the transaction tracking logic for meta-transactions relayed via the Gelato Network.
|
|
67
|
-
* It uses a polling mechanism to check the status of a Gelato
|
|
67
|
+
* It uses a polling mechanism to check the status of a Gelato task via the authenticated Gelato RPC client.
|
|
68
|
+
*
|
|
69
|
+
* The fetcher calls `relayer_getStatus` on the Gelato RPC endpoint and interprets the numeric
|
|
70
|
+
* status codes to determine whether a task is still pending, succeeded, was rejected, or reverted.
|
|
68
71
|
*/
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
*/
|
|
75
|
-
declare
|
|
74
|
+
* Numeric status codes returned by the Gelato `relayer_getStatus` RPC method.
|
|
75
|
+
*
|
|
76
|
+
* @see https://docs.gelato.cloud/
|
|
77
|
+
*/
|
|
78
|
+
declare enum GelatoStatusCode {
|
|
79
|
+
/** The task has been received and is awaiting execution. */
|
|
80
|
+
Pending = 100,
|
|
81
|
+
/** The task has been submitted to the mempool and has a transaction hash. */
|
|
82
|
+
Submitted = 110,
|
|
83
|
+
/** The task was successfully executed and mined. */
|
|
84
|
+
Success = 200,
|
|
85
|
+
/** The task was rejected by the relayer before execution (e.g., validation failure). */
|
|
86
|
+
Rejected = 400,
|
|
87
|
+
/** The task was submitted but the transaction reverted on-chain. */
|
|
88
|
+
Reverted = 500
|
|
89
|
+
}
|
|
76
90
|
/**
|
|
77
|
-
*
|
|
78
|
-
* @see https://docs.gelato.network/developer-services/relay/api/get-task-status
|
|
91
|
+
* Common fields shared by all Gelato task status responses.
|
|
79
92
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
93
|
+
type GelatoBaseStatus = {
|
|
94
|
+
/** The chain ID on which the task was submitted. */
|
|
95
|
+
chainId: number;
|
|
96
|
+
/** Unix timestamp (in seconds) when the task was created. */
|
|
97
|
+
createdAt: number;
|
|
98
|
+
/** The unique Gelato task identifier. */
|
|
99
|
+
id: string;
|
|
100
|
+
};
|
|
89
101
|
/**
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
* Discriminated union representing all possible Gelato task status responses.
|
|
103
|
+
* Each variant corresponds to a specific {@link GelatoStatusCode}.
|
|
104
|
+
*/
|
|
105
|
+
type GelatoTaskStatus = (GelatoBaseStatus & {
|
|
106
|
+
status: GelatoStatusCode.Pending;
|
|
107
|
+
}) | (GelatoBaseStatus & {
|
|
108
|
+
status: GelatoStatusCode.Submitted;
|
|
109
|
+
hash: Hex;
|
|
110
|
+
}) | (GelatoBaseStatus & {
|
|
111
|
+
status: GelatoStatusCode.Success;
|
|
112
|
+
receipt: {
|
|
113
|
+
transactionHash: Hex;
|
|
102
114
|
};
|
|
103
|
-
}
|
|
115
|
+
}) | (GelatoBaseStatus & {
|
|
116
|
+
status: GelatoStatusCode.Rejected;
|
|
117
|
+
message: string;
|
|
118
|
+
data?: unknown;
|
|
119
|
+
}) | (GelatoBaseStatus & {
|
|
120
|
+
status: GelatoStatusCode.Reverted;
|
|
121
|
+
message?: string;
|
|
122
|
+
data: string;
|
|
123
|
+
receipt: {
|
|
124
|
+
transactionHash: Hex;
|
|
125
|
+
};
|
|
126
|
+
});
|
|
104
127
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
128
|
+
* Creates a reusable fetcher function for `initializePollingTracker` that queries the
|
|
129
|
+
* Gelato RPC endpoint (`relayer_getStatus`) for a task's status using an authenticated client.
|
|
130
|
+
*
|
|
131
|
+
* The fetcher interprets the numeric status codes and calls the appropriate polling callbacks:
|
|
132
|
+
* - {@link GelatoStatusCode.Success} → `onSuccess`
|
|
133
|
+
* - {@link GelatoStatusCode.Rejected} / {@link GelatoStatusCode.Reverted} → `onFailure`
|
|
134
|
+
* - {@link GelatoStatusCode.Submitted} → `onIntervalTick` (to update the tx hash)
|
|
135
|
+
*
|
|
136
|
+
* @param {ReturnType<Transport>} client - A viem transport client configured for the Gelato API.
|
|
137
|
+
* @returns {PollingTrackerConfig<GelatoTaskStatus, Transaction>['fetcher']} The fetcher function.
|
|
107
138
|
*/
|
|
108
|
-
declare
|
|
139
|
+
declare function gelatoFetcher(client: ReturnType<Transport>): PollingTrackerConfig<GelatoTaskStatus, Transaction>['fetcher'];
|
|
109
140
|
/**
|
|
110
141
|
* A higher-level wrapper that integrates the Gelato polling logic with the Pulsar store.
|
|
111
|
-
* It
|
|
142
|
+
* It creates an authenticated Gelato RPC client and uses {@link gelatoFetcher} to
|
|
143
|
+
* build the fetcher, then delegates to `initializePollingTracker` with store-specific callbacks.
|
|
112
144
|
*
|
|
113
145
|
* @template T - The application-specific transaction type.
|
|
114
|
-
|
|
115
|
-
|
|
146
|
+
*
|
|
147
|
+
* @param params.tx - The transaction to track.
|
|
148
|
+
* @param params.gelatoApiKey - The Gelato API key for authenticating RPC requests.
|
|
149
|
+
* @param params.updateTxParams - Store action to update transaction fields.
|
|
150
|
+
* @param params.removeTxFromPool - Store action to remove a transaction from the pool.
|
|
151
|
+
* @param params.transactionsPool - The current pool of tracked transactions.
|
|
152
|
+
* @param params.onSuccess - Optional callback invoked when the transaction succeeds.
|
|
153
|
+
* @param params.onError - Optional callback invoked when the transaction fails.
|
|
154
|
+
*/
|
|
155
|
+
declare function gelatoTrackerForStore<T extends Transaction>({ tx, gelatoApiKey, updateTxParams, removeTxFromPool, transactionsPool, onSuccess, onError, }: Pick<ITxTrackingStore<T>, 'updateTxParams' | 'removeTxFromPool' | 'transactionsPool'> & {
|
|
116
156
|
tx: T;
|
|
157
|
+
gelatoApiKey: string;
|
|
117
158
|
} & TrackerCallbacks<T>): void;
|
|
118
159
|
|
|
119
160
|
/**
|
|
@@ -206,6 +247,7 @@ type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>,
|
|
|
206
247
|
config: Config;
|
|
207
248
|
tx: T;
|
|
208
249
|
tracker: TransactionTracker;
|
|
250
|
+
gelatoApiKey?: string;
|
|
209
251
|
} & TrackerCallbacks<T>;
|
|
210
252
|
/**
|
|
211
253
|
* Initializes the appropriate tracker for a given transaction based on its `tracker` type.
|
|
@@ -216,21 +258,48 @@ type InitializeTrackerParams<T extends Transaction> = Pick<ITxTrackingStore<T>,
|
|
|
216
258
|
* @param {InitializeTrackerParams<T>} params - The parameters for initializing the tracker.
|
|
217
259
|
* @returns {Promise<void>} A promise that resolves once the tracking process has been successfully initiated.
|
|
218
260
|
*/
|
|
219
|
-
declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, config, transactionsPool, onSuccess, onError, onReplaced, ...rest }: InitializeTrackerParams<T>): Promise<void>;
|
|
261
|
+
declare function checkAndInitializeTrackerInStore<T extends Transaction>({ tracker, tx, config, transactionsPool, onSuccess, onError, onReplaced, gelatoApiKey, ...rest }: InitializeTrackerParams<T>): Promise<void>;
|
|
220
262
|
|
|
221
263
|
/**
|
|
222
264
|
* @file This file contains a utility to check if the Gelato Relay service is available for a specific chain.
|
|
265
|
+
* It uses the authenticated Gelato RPC client to fetch relay capabilities and caches the result.
|
|
223
266
|
*/
|
|
267
|
+
/**
|
|
268
|
+
* Represents the per-chain capabilities returned by the Gelato `relayer_getCapabilities` RPC method.
|
|
269
|
+
*
|
|
270
|
+
* @property {string} feeCollector - The address of the fee collector contract on this chain.
|
|
271
|
+
* @property {GelatoToken[]} tokens - The list of ERC-20 tokens accepted for fee payment on this chain.
|
|
272
|
+
*/
|
|
273
|
+
type GelatoCapabilitiesByChain = {
|
|
274
|
+
feeCollector: string;
|
|
275
|
+
tokens: GelatoToken[];
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Represents a token accepted for fee payment by the Gelato Relay on a given chain.
|
|
279
|
+
*
|
|
280
|
+
* @property {string} address - The ERC-20 token contract address.
|
|
281
|
+
* @property {number} decimals - The number of decimals for the token.
|
|
282
|
+
*/
|
|
283
|
+
type GelatoToken = {
|
|
284
|
+
address: string;
|
|
285
|
+
decimals: number;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* A record of Gelato relay capabilities keyed by numeric chain ID.
|
|
289
|
+
*/
|
|
290
|
+
type GelatoCapabilities = Record<number, GelatoCapabilitiesByChain>;
|
|
224
291
|
/**
|
|
225
292
|
* Checks if the Gelato Relay service supports a given chain ID.
|
|
226
293
|
*
|
|
227
|
-
* This function fetches the
|
|
228
|
-
*
|
|
294
|
+
* This function fetches the relay capabilities via the authenticated Gelato RPC client
|
|
295
|
+
* (`relayer_getCapabilities`) and checks whether the specified chain is present in the response.
|
|
296
|
+
* Results are cached in memory per API key for the lifetime of the application to minimize network requests.
|
|
229
297
|
*
|
|
230
298
|
* @param {number} chainId - The chain identifier to check.
|
|
299
|
+
* @param {string} gelatoApiKey - The Gelato API key used for authentication.
|
|
231
300
|
* @returns {Promise<boolean>} A promise that resolves to `true` if Gelato supports the chain, `false` otherwise.
|
|
232
301
|
*/
|
|
233
|
-
declare function checkIsGelatoAvailable(chainId: number): Promise<boolean>;
|
|
302
|
+
declare function checkIsGelatoAvailable(chainId: number, gelatoApiKey: string): Promise<boolean>;
|
|
234
303
|
|
|
235
304
|
/**
|
|
236
305
|
* @file This file contains a utility function to determine the correct tracker for a transaction
|
|
@@ -249,16 +318,51 @@ declare function checkIsGelatoAvailable(chainId: number): Promise<boolean>;
|
|
|
249
318
|
*
|
|
250
319
|
* @param {ActionTxKey} actionTxKey - The key returned from the transaction submission function (e.g., a hash or a Gelato task object).
|
|
251
320
|
* @param {string} connectorType - The type of the connector that initiated the action (e.g., 'safe', 'injected').
|
|
252
|
-
*
|
|
321
|
+
* @param {TransactionTracker} tracker - The type of transaction tracker to use.
|
|
322
|
+
* @param {string} gelatoApiKey - Gelato API key for Gelato relayer integration.
|
|
253
323
|
* @returns {{ tracker: TransactionTracker; txKey: string }} An object containing the determined tracker type and the final string-based transaction key.
|
|
254
324
|
*
|
|
255
325
|
* @throws {Error} Throws an error if the `actionTxKey` is not a valid Hex string after failing the Gelato check.
|
|
256
326
|
*/
|
|
257
|
-
declare function checkTransactionsTracker(actionTxKey
|
|
327
|
+
declare function checkTransactionsTracker({ actionTxKey, connectorType, tracker, gelatoApiKey }: CheckTxTracker): {
|
|
258
328
|
tracker: TransactionTracker;
|
|
259
329
|
txKey: string;
|
|
260
330
|
};
|
|
261
331
|
|
|
332
|
+
/**
|
|
333
|
+
* @file This file contains a utility function for creating a cached viem HTTP transport
|
|
334
|
+
* client configured for the Gelato Relay API.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Configuration options for creating a Gelato API client.
|
|
339
|
+
*
|
|
340
|
+
* @property {string} apiKey - The Gelato API key used for authentication.
|
|
341
|
+
* @property {number} [timeout] - Optional custom HTTP timeout in milliseconds. Defaults to 15000ms.
|
|
342
|
+
* @property {string} [baseUrl] - Optional custom base URL for the Gelato API. Defaults to `https://api.gelato.cloud/rpc`.
|
|
343
|
+
* @property {HttpTransportConfig} [httpTransportConfig] - Optional additional viem HTTP transport configuration overrides.
|
|
344
|
+
*/
|
|
345
|
+
type GelatoClientConfig = {
|
|
346
|
+
apiKey: string;
|
|
347
|
+
timeout?: number;
|
|
348
|
+
baseUrl?: string;
|
|
349
|
+
httpTransportConfig?: HttpTransportConfig;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* Creates or retrieves a cached viem HTTP transport client configured for the Gelato Relay API.
|
|
353
|
+
*
|
|
354
|
+
* The client is cached by a composite key of `apiKey` and `baseUrl` to avoid
|
|
355
|
+
* creating redundant transport instances for identical configurations.
|
|
356
|
+
*
|
|
357
|
+
* The default HTTP timeout is set to 15 seconds (instead of viem's default) because
|
|
358
|
+
* Gelato's synchronous relay methods may take up to 10 seconds on the server side,
|
|
359
|
+
* and the client should not time out before the server does.
|
|
360
|
+
*
|
|
361
|
+
* @param {GelatoClientConfig} parameters - The configuration for the Gelato client.
|
|
362
|
+
* @returns {ReturnType<Transport>} A viem transport instance configured for the Gelato API.
|
|
363
|
+
*/
|
|
364
|
+
declare const createGelatoClient: (parameters: GelatoClientConfig) => ReturnType<Transport>;
|
|
365
|
+
|
|
262
366
|
/**
|
|
263
367
|
* @file This file contains constants related to Safe (formerly Gnosis Safe) configuration,
|
|
264
368
|
* including SDK options, web app URLs, and transaction service API endpoints for various chains.
|
|
@@ -353,4 +457,4 @@ declare function speedUpTxAction<T extends Transaction>({ config, tx }: {
|
|
|
353
457
|
tx: T;
|
|
354
458
|
}): Promise<Hex>;
|
|
355
459
|
|
|
356
|
-
export { type EVMTrackerParams,
|
|
460
|
+
export { type EVMTrackerParams, type GelatoCapabilities, type GelatoCapabilitiesByChain, type GelatoClientConfig, GelatoStatusCode, type GelatoTaskStatus, type GelatoToken, SafeTransactionServiceUrls, type SafeTxStatusResponse, cancelTxAction, checkAndInitializeTrackerInStore, checkIsGelatoAvailable, checkTransactionsTracker, createGelatoClient, evmTracker, evmTrackerForStore, gelatoFetcher, gelatoTrackerForStore, gnosisSafeLinksHelper, pulsarEvmAdapter, safeFetcher, safeSdkOptions, safeTrackerForStore, selectEvmTxExplorerLink, speedUpTxAction };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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'),T=require('dayjs'),chains=require('viem/chains');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var T__default=/*#__PURE__*/_interopDefault(T);var v=1.15;async function C({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:a,maxFeePerGas:s,maxPriorityFeePerGas:i,chainId:c}=e;if(a===void 0||!s||!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 n=core.getAccount(t);if(!n.address)throw new Error("No connected account found.");let r=BigInt(Math.ceil(Number(i)*v)),o=BigInt(Math.ceil(Number(s)*v));return await core.sendTransaction(t,{to:n.address,value:0n,chainId:c,nonce:a,maxFeePerGas:o,maxPriorityFeePerGas:r})}catch(n){let r=n instanceof Error?n.message:String(n);throw new Error(`Failed to cancel transaction: ${r}`)}}var de=10,ue=3e3;async function me(t){let{tx:e,config:a,onInitialize:s,onTxDetailsFetched:i,onSuccess:c,onFailure:n,onReplaced:r,retryCount:o=de,retryTimeout:l=ue,waitForTransactionReceiptParams:u}=t;if(s?.(),e.txKey===viem.zeroHash)return n(new Error("Transaction hash cannot be the zero hash."));let p=core.getClient(a,{chainId:e.chainId});if(!p)return n(new Error(`Could not create a viem client for chainId: ${e.chainId}`));let d=null;for(let f=0;f<o;f++)try{d=await actions.getTransaction(p,{hash:e.txKey}),i(d);break}catch(m){if(f===o-1)return console.error(`EVM tracker failed to fetch tx ${e.txKey} after ${o} retries:`,m),n(m);await new Promise(b=>setTimeout(b,l));}if(!d)return n(new Error("Transaction details could not be fetched."));try{let f=!1,m=await actions.waitForTransactionReceipt(p,{hash:d.hash,onReplaced:b=>{f=!0,r(b);},...u});if(f)return;await c(d,m,p);}catch(f){console.error(`Error waiting for receipt for tx ${e.txKey}:`,f),n(f);}}async function y(t){let{tx:e,config:a,updateTxParams:s,transactionsPool:i,onSuccess:c,onError:n,onReplaced:r}=t;return me({tx:e,config:a,onInitialize:()=>{s(e.txKey,{hash:e.txKey});},onTxDetailsFetched:o=>{s(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,l,u)=>{let p=await actions.getBlock(u,{blockNumber:l.blockNumber}),d=Number(p.timestamp),f=l.status==="success";s(e.txKey,{status:f?pulsarCore.TransactionStatus.Success:pulsarCore.TransactionStatus.Failed,isError:!f,pending:false,finishedTimestamp:d});let m=i[e.txKey];f&&c&&m&&c(m),!f&&n&&m&&n(new Error("Transaction reverted"),m);},onReplaced:o=>{s(e.txKey,{status:pulsarCore.TransactionStatus.Replaced,replacedTxHash:o.transaction.hash,pending:false});let l=i[e.txKey];r&&l&&r(l,e);},onFailure:o=>{s(e.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,errorMessage:o instanceof Error?o.message:"Transaction failed or could not be tracked."});let l=i[e.txKey];n&&l&&n(o,l);}})}function F(t){return typeof t=="object"&&t!==null&&"taskId"in t}var he=(r=>(r.CheckPending="CheckPending",r.ExecPending="ExecPending",r.WaitingForConfirmation="WaitingForConfirmation",r.ExecSuccess="ExecSuccess",r.ExecReverted="ExecReverted",r.Cancelled="Cancelled",r.NotFound="NotFound",r))(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:a,onFailure:s,onIntervalTick:i})=>{let c=await fetch(`${xe}${t.txKey}`);if(!c.ok){if(c.status===404){s(),e();return}throw new Error(`Gelato API responded with status: ${c.status}`)}let n=await c.json(),{taskState:r,creationDate:o}=n.task;if(i?.(n),o&&T__default.default().diff(T__default.default(o),"hour")>=1&&ge(r)){e();return}r==="ExecSuccess"?(a(n),e({withoutRemoving:true})):I.has(r)&&(s(n),e({withoutRemoving:true}));};function P({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:s,onSuccess:i,onError:c}){return pulsarCore.initializePollingTracker({tx:t,fetcher:ke,removeTxFromPool:a,onSuccess:n=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:n.task.transactionHash,finishedTimestamp:n.task.executionDate?T__default.default(n.task.executionDate).unix():void 0});let r=s[t.txKey];i&&r&&i(r);},onIntervalTick:n=>{e(t.txKey,{hash:n.task.transactionHash});},onFailure:n=>{let r=n?.task.lastCheckMessage??"Transaction failed or was not found.";e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:n?.task.transactionHash,errorMessage:r,finishedTimestamp:n?.task.executionDate?T__default.default(n.task.executionDate).unix():void 0});let o=s[t.txKey];c&&o&&c(new Error(r),o);}})}var ft={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},B={[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:"},W={[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:a,onFailure:s,onReplaced:i,onIntervalTick:c})=>{let n=W[t.chainId];if(!n)throw new Error(`Safe Transaction Service URL not found for chainId: ${t.chainId}`);let r=await fetch(`${n}/multisig-transactions/${t.txKey}/`);if(!r.ok)throw r.status===404&&(s(),e()),new Error(`Safe API responded with status: ${r.status}`);let o=await r.json();if(c?.(o),o.isExecuted){o.isSuccessful?a(o):s(o),e({withoutRemoving:true});return}let l=await fetch(`${n}/safes/${t.from}/multisig-transactions/?nonce=${o.nonce}`);if(!l.ok)throw new Error(`Safe API (nonce check) responded with status: ${l.status}`);let p=(await l.json()).results.find(d=>d.isExecuted);if(p){i?.(p),e({withoutRemoving:true});return}T__default.default().diff(T__default.default(o.submissionDate),"day")>=1&&e();};function Y({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n}){return pulsarCore.initializePollingTracker({tx:t,fetcher:Ee,removeTxFromPool:a,onSuccess:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:r.transactionHash??void 0,finishedTimestamp:r.executionDate?T__default.default(r.executionDate).unix():void 0});let o=s[t.txKey];i&&o&&i(o);},onIntervalTick:r=>{e(t.txKey,{hash:r.transactionHash??void 0});},onFailure:r=>{let o=r?"Safe transaction failed or was rejected.":"Transaction not found.";e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:r?.transactionHash??void 0,errorMessage:o,finishedTimestamp:r?.executionDate?T__default.default(r.executionDate).unix():void 0});let l=s[t.txKey];c&&l&&c(new Error(o),l);},onReplaced:r=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Replaced,pending:false,hash:t.adapter===orbitCore.OrbitAdapter.EVM?t.hash:viem.zeroHash,replacedTxHash:r.safeTxHash??viem.zeroHash,finishedTimestamp:r.executionDate?T__default.default(r.executionDate).unix():void 0});let o=s[t.txKey];n&&o&&n(o,t);}})}async function J({tracker:t,tx:e,config:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r}){switch(t){case pulsarCore.TransactionTracker.Ethereum:return y({tx:e,config:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r});case pulsarCore.TransactionTracker.Gelato:return P({tx:e,transactionsPool:s,onSuccess:i,onError:c,...r});case pulsarCore.TransactionTracker.Safe:return Y({tx:e,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r});default:return console.warn(`Unknown tracker type: '${t}'. Falling back to default EVM tracker.`),y({tx:e,config:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r})}}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 a=e.split(":");return (a.length>1?a[a.length-1]==="safe"||a[a.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 c=B[e.chainId];return c?`${c}${e.from}/transactions/tx?id=multisig_${e.from}_${e.txKey}`:""}let s=t.find(c=>c.id===e.chainId)?.blockExplorers?.default.url;if(!s)return "";let i=(e.adapter===orbitCore.OrbitAdapter.EVM?e.replacedTxHash:e.txKey)||(e.adapter===orbitCore.OrbitAdapter.EVM?e.hash:e.txKey);return i?`${s}/tx/${i}`:""};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:a,from:s,to:i,value:c,input:n,maxFeePerGas:r,maxPriorityFeePerGas:o,chainId:l}=e;if(a===void 0||!s||!i||!c||!r||!o)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 p=BigInt(Math.ceil(Number(o)*ee)),d=BigInt(Math.ceil(Number(r)*ee));return await core.sendTransaction(t,{to:i,value:BigInt(c),data:n||"0x",chainId:l,nonce:a,maxFeePerGas:d,maxPriorityFeePerGas:p})}catch(u){let p=u instanceof Error?u.message:String(u);throw new Error(`Failed to speed up transaction: ${p}`)}}function oa(t,e){if(!t)throw new Error("EVM adapter requires a wagmi config object.");return {key:orbitCore.OrbitAdapter.EVM,getConnectorInfo:()=>{let a=core.getConnection(t),s=orbitCore.lastConnectedConnectorHelpers.getLastConnectedConnector();return {walletAddress:a.address??s?.address??viem.zeroAddress,connectorType:orbitCore.getConnectorTypeFromName(orbitCore.OrbitAdapter.EVM,a.connector?.name?.toLowerCase()??"unknown")}},checkChainForTx:a=>orbitEvm.checkAndSwitchChain(a,t),checkTransactionsTracker:(a,s)=>Z(a,s),checkAndInitializeTrackerInStore:({tx:a,...s})=>J({tracker:a.tracker,tx:a,config:t,...s}),getExplorerUrl:a=>{let{chain:s}=core.getConnection(t),i=s?.blockExplorers?.default.url;return a?`${i}/${a}`:i},getExplorerTxUrl:a=>X({chains:e,tx:a}),cancelTxAction:a=>C({config:t,tx:a}),speedUpTxAction:a=>te({config:t,tx:a}),retryTxAction:async({onClose:a,txKey:s,executeTxAction:i,tx:c})=>{if(a(s),!i){console.error("Retry failed: executeTxAction function is not provided.");return}await i({actionFunction:()=>c.actionFunction({config:t,...c.payload}),params:c,defaultTracker:pulsarCore.TransactionTracker.Ethereum});}}}var g=null,k=null,Ke=300*1e3,He="https://relay.gelato.digital/relays/v2/supported-chains";async function ia(t){let e=Date.now();if(g&&k&&e-k<Ke)return g.includes(t);try{let a=await fetch(He);if(!a.ok)throw new Error(`Gelato API responded with status: ${a.status}`);let i=(await a.json()).chains.map(Number);return g=i,k=e,i.includes(t)}catch(a){return console.error("Failed to fetch Gelato supported chains:",a),g=null,k=null,false}}
|
|
2
|
-
exports.
|
|
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'),T=require('dayjs'),chains=require('viem/chains');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var T__default=/*#__PURE__*/_interopDefault(T);var E=1.15;async function v({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:a,maxFeePerGas:n,maxPriorityFeePerGas:i,chainId:o}=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 c=core.getAccount(t);if(!c.address)throw new Error("No connected account found.");let s=BigInt(Math.ceil(Number(i)*E)),r=BigInt(Math.ceil(Number(n)*E));return await core.sendTransaction(t,{to:c.address,value:0n,chainId:o,nonce:a,maxFeePerGas:r,maxPriorityFeePerGas:s})}catch(c){let s=c instanceof Error?c.message:String(c);throw new Error(`Failed to cancel transaction: ${s}`)}}var ue=10,de=3e3;async function me(t){let{tx:e,config:a,onInitialize:n,onTxDetailsFetched:i,onSuccess:o,onFailure:c,onReplaced:s,retryCount:r=ue,retryTimeout:l=de,waitForTransactionReceiptParams:u}=t;if(n?.(),e.txKey===viem.zeroHash)return c(new Error("Transaction hash cannot be the zero hash."));let p=core.getClient(a,{chainId:e.chainId});if(!p)return c(new Error(`Could not create a viem client for chainId: ${e.chainId}`));let d=null;for(let f=0;f<r;f++)try{d=await actions.getTransaction(p,{hash:e.txKey}),i(d);break}catch(m){if(f===r-1)return console.error(`EVM tracker failed to fetch tx ${e.txKey} after ${r} retries:`,m),c(m);await new Promise(y=>setTimeout(y,l));}if(!d)return c(new Error("Transaction details could not be fetched."));try{let f=!1,m=await actions.waitForTransactionReceipt(p,{hash:d.hash,onReplaced:y=>{f=!0,s(y);},...u});if(f)return;await o(d,m,p);}catch(f){console.error(`Error waiting for receipt for tx ${e.txKey}:`,f),c(f);}}async function x(t){let{tx:e,config:a,updateTxParams:n,transactionsPool:i,onSuccess:o,onError:c,onReplaced:s}=t;return me({tx:e,config:a,onInitialize:()=>{n(e.txKey,{hash:e.txKey});},onTxDetailsFetched:r=>{n(e.txKey,{to:r.to??void 0,input:r.input,value:r.value?.toString(),nonce:r.nonce,maxFeePerGas:r.maxFeePerGas?.toString(),maxPriorityFeePerGas:r.maxPriorityFeePerGas?.toString()});},onSuccess:async(r,l,u)=>{let p=await actions.getBlock(u,{blockNumber:l.blockNumber}),d=Number(p.timestamp),f=l.status==="success";n(e.txKey,{status:f?pulsarCore.TransactionStatus.Success:pulsarCore.TransactionStatus.Failed,isError:!f,pending:false,finishedTimestamp:d});let m=i[e.txKey];f&&o&&m&&o(m),!f&&c&&m&&c(new Error("Transaction reverted"),m);},onReplaced:r=>{n(e.txKey,{status:pulsarCore.TransactionStatus.Replaced,replacedTxHash:r.transaction.hash,pending:false});let l=i[e.txKey];s&&l&&s(l,e);},onFailure:r=>{n(e.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,error:orbitCore.normalizeError(r)});let l=i[e.txKey];c&&l&&c(r,l);}})}var R=new Map,g=t=>{let{apiKey:e,baseUrl:a,timeout:n}=t,i=a||"https://api.gelato.cloud",o=`${e}:${i}`,c=R.get(o);if(c)return c;let s={timeout:n??15e3,...t.httpTransportConfig,fetchOptions:{headers:{Authorization:`Bearer ${e}`,...t.httpTransportConfig?.fetchOptions?.headers},...t.httpTransportConfig?.fetchOptions}},r=viem.http(`${i}/rpc`,s)({});return R.set(o,r),r};var ge=(o=>(o[o.Pending=100]="Pending",o[o.Submitted=110]="Submitted",o[o.Success=200]="Success",o[o.Rejected=400]="Rejected",o[o.Reverted=500]="Reverted",o))(ge||{}),be=new Set([200,400,500]);function ke(t){return !be.has(t)}function ye(t){return async({tx:e,stopPolling:a,onSuccess:n,onFailure:i,onIntervalTick:o})=>{let c=await t.request({method:"relayer_getStatus",params:{id:e.txKey,logs:false}});o?.(c);let{status:s,createdAt:r}=c;if(r&&T__default.default().diff(T__default.default.unix(r),"hour")>=1&&ke(s)){a();return}s===200?(n(c),a({withoutRemoving:true})):(s===400||s===500)&&(i(c),a({withoutRemoving:true}));}}function F({tx:t,gelatoApiKey:e,updateTxParams:a,removeTxFromPool:n,transactionsPool:i,onSuccess:o,onError:c}){let s=g({apiKey:e}),r=ye(s);return pulsarCore.initializePollingTracker({tx:t,fetcher:r,removeTxFromPool:n,onSuccess:l=>{let u=l.status===200?l.receipt.transactionHash:void 0;a(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:u,finishedTimestamp:T__default.default().unix()});let p=i[t.txKey];o&&p&&o(p);},onIntervalTick:l=>{l.status===110&&a(t.txKey,{hash:l.hash});},onFailure:l=>{let u="Transaction failed or was not found.",p;l&&(l.status===400?u=l.message||"Transaction was rejected by Gelato Relay.":l.status===500&&(u=l.message||"Transaction reverted on-chain.",p=l.receipt.transactionHash));let d=new Error(u);a(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:p,error:orbitCore.normalizeError(d),finishedTimestamp:T__default.default().unix()});let f=i[t.txKey];c&&f&&c(d,f);}})}var gt={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},O={[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:"},L={[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:a,onFailure:n,onReplaced:i,onIntervalTick:o})=>{let c=L[t.chainId];if(!c)throw new Error(`Safe Transaction Service URL not found for chainId: ${t.chainId}`);let s=await fetch(`${c}/multisig-transactions/${t.txKey}/`);if(!s.ok)throw s.status===404&&(n(),e()),new Error(`Safe API responded with status: ${s.status}`);let r=await s.json();if(o?.(r),r.isExecuted){r.isSuccessful?a(r):n(r),e({withoutRemoving:true});return}let l=await fetch(`${c}/safes/${t.from}/multisig-transactions/?nonce=${r.nonce}`);if(!l.ok)throw new Error(`Safe API (nonce check) responded with status: ${l.status}`);let p=(await l.json()).results.find(d=>d.isExecuted);if(p){i?.(p),e({withoutRemoving:true});return}T__default.default().diff(T__default.default(r.submissionDate),"day")>=1&&e();};function W({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c}){return pulsarCore.initializePollingTracker({tx:t,fetcher:Ee,removeTxFromPool:a,onSuccess:s=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Success,pending:false,isError:false,hash:s.transactionHash??void 0,finishedTimestamp:s.executionDate?T__default.default(s.executionDate).unix():void 0});let r=n[t.txKey];i&&r&&i(r);},onIntervalTick:s=>{e(t.txKey,{hash:s.transactionHash??void 0});},onFailure:s=>{let r=s?new Error("Safe transaction failed or was rejected."):new Error("Transaction not found.");e(t.txKey,{status:pulsarCore.TransactionStatus.Failed,pending:false,isError:true,hash:s?.transactionHash??void 0,error:orbitCore.normalizeError(r),finishedTimestamp:s?.executionDate?T__default.default(s.executionDate).unix():void 0});let l=n[t.txKey];o&&l&&o(r,l);},onReplaced:s=>{e(t.txKey,{status:pulsarCore.TransactionStatus.Replaced,pending:false,hash:t.adapter===orbitCore.OrbitAdapter.EVM?t.hash:viem.zeroHash,replacedTxHash:s.safeTxHash??viem.zeroHash,finishedTimestamp:s.executionDate?T__default.default(s.executionDate).unix():void 0});let r=n[t.txKey];c&&r&&c(r,t);}})}async function Y({tracker:t,tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,gelatoApiKey:s,...r}){switch(t){case pulsarCore.TransactionTracker.Ethereum:return x({tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r});case pulsarCore.TransactionTracker.Gelato:return s?F({tx:e,transactionsPool:n,onSuccess:i,onError:o,gelatoApiKey:s,...r}):(console.warn(`Gelato tracker requested for tx '${e.txKey}', but no 'gelatoApiKey' was provided. Falling back to default EVM tracker.`),x({tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r}));case pulsarCore.TransactionTracker.Safe:return W({tx:e,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r});default:return console.warn(`Unknown tracker type: '${t}'. Falling back to default EVM tracker.`),x({tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r})}}function J({actionTxKey:t,connectorType:e,tracker:a,gelatoApiKey:n}){if(a&&a===pulsarCore.TransactionTracker.Gelato&&n)return {tracker:pulsarCore.TransactionTracker.Gelato,txKey:t};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 i=e.split(":");return (i.length>1?i[i.length-1]==="safe"||i[i.length-1]==="safewallet":e?.toLowerCase()==="safe")?{tracker:pulsarCore.TransactionTracker.Safe,txKey:t}:{tracker:pulsarCore.TransactionTracker.Ethereum,txKey:t}}var Q=({chains:t,tx:e})=>{if(e.tracker===pulsarCore.TransactionTracker.Safe){let o=O[e.chainId];return o?`${o}${e.from}/transactions/tx?id=multisig_${e.from}_${e.txKey}`:""}let n=t.find(o=>o.id===e.chainId)?.blockExplorers?.default.url;if(!n)return "";let i=(e.adapter===orbitCore.OrbitAdapter.EVM?e.replacedTxHash:e.txKey)||(e.adapter===orbitCore.OrbitAdapter.EVM?e.hash:e.txKey);return i?`${n}/tx/${i}`:""};var X=1.15;async function ee({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:a,from:n,to:i,value:o,input:c,maxFeePerGas:s,maxPriorityFeePerGas:r,chainId:l}=e;if(a===void 0||!n||!i||!o||!s||!r)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 p=BigInt(Math.ceil(Number(r)*X)),d=BigInt(Math.ceil(Number(s)*X));return await core.sendTransaction(t,{to:i,value:BigInt(o),data:c||"0x",chainId:l,nonce:a,maxFeePerGas:d,maxPriorityFeePerGas:p})}catch(u){let p=u instanceof Error?u.message:String(u);throw new Error(`Failed to speed up transaction: ${p}`)}}function ua(t,e){if(!t)throw new Error("EVM adapter requires a wagmi config object.");return {key:orbitCore.OrbitAdapter.EVM,getConnectorInfo:()=>{let a=core.getConnection(t),n=orbitCore.lastConnectedConnectorHelpers.getLastConnectedConnector();return {walletAddress:a.address??n?.address??viem.zeroAddress,connectorType:orbitCore.getConnectorTypeFromName(orbitCore.OrbitAdapter.EVM,a.connector?.name?.toLowerCase()??"unknown")}},checkChainForTx:a=>orbitEvm.checkAndSwitchChain(a,t),checkTransactionsTracker:a=>J(a),checkAndInitializeTrackerInStore:({tx:a,...n})=>Y({tracker:a.tracker,tx:a,config:t,...n}),getExplorerUrl:a=>{let{chain:n}=core.getConnection(t),i=n?.blockExplorers?.default.url;return a?`${i}/${a}`:i},getExplorerTxUrl:a=>Q({chains:e,tx:a}),cancelTxAction:a=>v({config:t,tx:a}),speedUpTxAction:a=>ee({config:t,tx:a}),retryTxAction:async({onClose:a,txKey:n,executeTxAction:i,tx:o})=>{if(a(n),!i){console.error("Retry failed: executeTxAction function is not provided.");return}await i({actionFunction:()=>o.actionFunction({config:t,...o.payload}),params:o,defaultTracker:pulsarCore.TransactionTracker.Ethereum});}}}var w=new Map;async function Me(t){let e=await t.request({method:"relayer_getCapabilities",params:[]}),a={};for(let[n,i]of Object.entries(e))a[Number(n)]=i;return a}async function ze(t){let e=w.get(t);if(e)return e;let a=g({apiKey:t}),n=await Me(a);return w.set(t,n),n}async function Ta(t,e){try{let a=await ze(e);return t in a}catch(a){return console.error("Failed to fetch Gelato relay capabilities:",a),w.delete(e),false}}
|
|
2
|
+
exports.GelatoStatusCode=ge;exports.SafeTransactionServiceUrls=L;exports.cancelTxAction=v;exports.checkAndInitializeTrackerInStore=Y;exports.checkIsGelatoAvailable=Ta;exports.checkTransactionsTracker=J;exports.createGelatoClient=g;exports.evmTracker=me;exports.evmTrackerForStore=x;exports.gelatoFetcher=ye;exports.gelatoTrackerForStore=F;exports.gnosisSafeLinksHelper=O;exports.pulsarEvmAdapter=ua;exports.safeFetcher=Ee;exports.safeSdkOptions=gt;exports.safeTrackerForStore=W;exports.selectEvmTxExplorerLink=Q;exports.speedUpTxAction=ee;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {OrbitAdapter,lastConnectedConnectorHelpers,getConnectorTypeFromName}from'@tuwaio/orbit-core';import {checkAndSwitchChain}from'@tuwaio/orbit-evm';import {TransactionStatus,initializePollingTracker,TransactionTracker}from'@tuwaio/pulsar-core';import {getAccount,sendTransaction,getClient,getConnection}from'@wagmi/core';import {zeroHash,isHex,zeroAddress}from'viem';import {getTransaction,waitForTransactionReceipt,getBlock}from'viem/actions';import T from'dayjs';import {zksync,polygonZkEvm,optimism,gnosis,celo,bsc,boba,base,avalanche,aurora,arbitrum,polygon,sepolia,goerli,mainnet}from'viem/chains';var v=1.15;async function C({config:t,tx:e}){if(e.adapter!==OrbitAdapter.EVM)throw new Error(`Cancellation is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:a,maxFeePerGas:s,maxPriorityFeePerGas:i,chainId:c}=e;if(a===void 0||!s||!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 n=getAccount(t);if(!n.address)throw new Error("No connected account found.");let r=BigInt(Math.ceil(Number(i)*v)),o=BigInt(Math.ceil(Number(s)*v));return await sendTransaction(t,{to:n.address,value:0n,chainId:c,nonce:a,maxFeePerGas:o,maxPriorityFeePerGas:r})}catch(n){let r=n instanceof Error?n.message:String(n);throw new Error(`Failed to cancel transaction: ${r}`)}}var de=10,ue=3e3;async function me(t){let{tx:e,config:a,onInitialize:s,onTxDetailsFetched:i,onSuccess:c,onFailure:n,onReplaced:r,retryCount:o=de,retryTimeout:l=ue,waitForTransactionReceiptParams:u}=t;if(s?.(),e.txKey===zeroHash)return n(new Error("Transaction hash cannot be the zero hash."));let p=getClient(a,{chainId:e.chainId});if(!p)return n(new Error(`Could not create a viem client for chainId: ${e.chainId}`));let d=null;for(let f=0;f<o;f++)try{d=await getTransaction(p,{hash:e.txKey}),i(d);break}catch(m){if(f===o-1)return console.error(`EVM tracker failed to fetch tx ${e.txKey} after ${o} retries:`,m),n(m);await new Promise(b=>setTimeout(b,l));}if(!d)return n(new Error("Transaction details could not be fetched."));try{let f=!1,m=await waitForTransactionReceipt(p,{hash:d.hash,onReplaced:b=>{f=!0,r(b);},...u});if(f)return;await c(d,m,p);}catch(f){console.error(`Error waiting for receipt for tx ${e.txKey}:`,f),n(f);}}async function y(t){let{tx:e,config:a,updateTxParams:s,transactionsPool:i,onSuccess:c,onError:n,onReplaced:r}=t;return me({tx:e,config:a,onInitialize:()=>{s(e.txKey,{hash:e.txKey});},onTxDetailsFetched:o=>{s(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,l,u)=>{let p=await getBlock(u,{blockNumber:l.blockNumber}),d=Number(p.timestamp),f=l.status==="success";s(e.txKey,{status:f?TransactionStatus.Success:TransactionStatus.Failed,isError:!f,pending:false,finishedTimestamp:d});let m=i[e.txKey];f&&c&&m&&c(m),!f&&n&&m&&n(new Error("Transaction reverted"),m);},onReplaced:o=>{s(e.txKey,{status:TransactionStatus.Replaced,replacedTxHash:o.transaction.hash,pending:false});let l=i[e.txKey];r&&l&&r(l,e);},onFailure:o=>{s(e.txKey,{status:TransactionStatus.Failed,pending:false,isError:true,errorMessage:o instanceof Error?o.message:"Transaction failed or could not be tracked."});let l=i[e.txKey];n&&l&&n(o,l);}})}function F(t){return typeof t=="object"&&t!==null&&"taskId"in t}var he=(r=>(r.CheckPending="CheckPending",r.ExecPending="ExecPending",r.WaitingForConfirmation="WaitingForConfirmation",r.ExecSuccess="ExecSuccess",r.ExecReverted="ExecReverted",r.Cancelled="Cancelled",r.NotFound="NotFound",r))(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:a,onFailure:s,onIntervalTick:i})=>{let c=await fetch(`${xe}${t.txKey}`);if(!c.ok){if(c.status===404){s(),e();return}throw new Error(`Gelato API responded with status: ${c.status}`)}let n=await c.json(),{taskState:r,creationDate:o}=n.task;if(i?.(n),o&&T().diff(T(o),"hour")>=1&&ge(r)){e();return}r==="ExecSuccess"?(a(n),e({withoutRemoving:true})):I.has(r)&&(s(n),e({withoutRemoving:true}));};function P({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:s,onSuccess:i,onError:c}){return initializePollingTracker({tx:t,fetcher:ke,removeTxFromPool:a,onSuccess:n=>{e(t.txKey,{status:TransactionStatus.Success,pending:false,isError:false,hash:n.task.transactionHash,finishedTimestamp:n.task.executionDate?T(n.task.executionDate).unix():void 0});let r=s[t.txKey];i&&r&&i(r);},onIntervalTick:n=>{e(t.txKey,{hash:n.task.transactionHash});},onFailure:n=>{let r=n?.task.lastCheckMessage??"Transaction failed or was not found.";e(t.txKey,{status:TransactionStatus.Failed,pending:false,isError:true,hash:n?.task.transactionHash,errorMessage:r,finishedTimestamp:n?.task.executionDate?T(n.task.executionDate).unix():void 0});let o=s[t.txKey];c&&o&&c(new Error(r),o);}})}var ft={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},B={[mainnet.id]:"https://app.safe.global/eth:",[goerli.id]:"https://app.safe.global/gor:",[sepolia.id]:"https://app.safe.global/sep:",[polygon.id]:"https://app.safe.global/matic:",[arbitrum.id]:"https://app.safe.global/arb1:",[aurora.id]:"https://app.safe.global/aurora:",[avalanche.id]:"https://app.safe.global/avax:",[base.id]:"https://app.safe.global/base:",[boba.id]:"https://app.safe.global/boba:",[bsc.id]:"https://app.safe.global/bnb:",[celo.id]:"https://app.safe.global/celo:",[gnosis.id]:"https://app.safe.global/gno:",[optimism.id]:"https://app.safe.global/oeth:",[polygonZkEvm.id]:"https://app.safe.global/zkevm:",[zksync.id]:"https://app.safe.global/zksync:"},W={[mainnet.id]:"https://safe-transaction-mainnet.safe.global/api/v1",[goerli.id]:"https://safe-transaction-goerli.safe.global/api/v1",[sepolia.id]:"https://safe-transaction-sepolia.safe.global/api/v1",[polygon.id]:"https://safe-transaction-polygon.safe.global/api/v1",[arbitrum.id]:"https://safe-transaction-arbitrum.safe.global/api/v1",[aurora.id]:"https://safe-transaction-aurora.safe.global/api/v1",[avalanche.id]:"https://safe-transaction-avalanche.safe.global/api/v1",[base.id]:"https://safe-transaction-base.safe.global/api/v1",[boba.id]:"https://safe-transaction-boba.safe.global/api/v1",[bsc.id]:"https://safe-transaction-bsc.safe.global/api/v1",[celo.id]:"https://safe-transaction-celo.safe.global/api/v1",[gnosis.id]:"https://safe-transaction-gnosis-chain.safe.global/api/v1",[optimism.id]:"https://safe-transaction-optimism.safe.global/api/v1",[polygonZkEvm.id]:"https://safe-transaction-zkevm.safe.global/api/v1",[zksync.id]:"https://safe-transaction-zksync.safe.global/api/v1"};var Ee=async({tx:t,stopPolling:e,onSuccess:a,onFailure:s,onReplaced:i,onIntervalTick:c})=>{let n=W[t.chainId];if(!n)throw new Error(`Safe Transaction Service URL not found for chainId: ${t.chainId}`);let r=await fetch(`${n}/multisig-transactions/${t.txKey}/`);if(!r.ok)throw r.status===404&&(s(),e()),new Error(`Safe API responded with status: ${r.status}`);let o=await r.json();if(c?.(o),o.isExecuted){o.isSuccessful?a(o):s(o),e({withoutRemoving:true});return}let l=await fetch(`${n}/safes/${t.from}/multisig-transactions/?nonce=${o.nonce}`);if(!l.ok)throw new Error(`Safe API (nonce check) responded with status: ${l.status}`);let p=(await l.json()).results.find(d=>d.isExecuted);if(p){i?.(p),e({withoutRemoving:true});return}T().diff(T(o.submissionDate),"day")>=1&&e();};function Y({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n}){return initializePollingTracker({tx:t,fetcher:Ee,removeTxFromPool:a,onSuccess:r=>{e(t.txKey,{status:TransactionStatus.Success,pending:false,isError:false,hash:r.transactionHash??void 0,finishedTimestamp:r.executionDate?T(r.executionDate).unix():void 0});let o=s[t.txKey];i&&o&&i(o);},onIntervalTick:r=>{e(t.txKey,{hash:r.transactionHash??void 0});},onFailure:r=>{let o=r?"Safe transaction failed or was rejected.":"Transaction not found.";e(t.txKey,{status:TransactionStatus.Failed,pending:false,isError:true,hash:r?.transactionHash??void 0,errorMessage:o,finishedTimestamp:r?.executionDate?T(r.executionDate).unix():void 0});let l=s[t.txKey];c&&l&&c(new Error(o),l);},onReplaced:r=>{e(t.txKey,{status:TransactionStatus.Replaced,pending:false,hash:t.adapter===OrbitAdapter.EVM?t.hash:zeroHash,replacedTxHash:r.safeTxHash??zeroHash,finishedTimestamp:r.executionDate?T(r.executionDate).unix():void 0});let o=s[t.txKey];n&&o&&n(o,t);}})}async function J({tracker:t,tx:e,config:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r}){switch(t){case TransactionTracker.Ethereum:return y({tx:e,config:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r});case TransactionTracker.Gelato:return P({tx:e,transactionsPool:s,onSuccess:i,onError:c,...r});case TransactionTracker.Safe:return Y({tx:e,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r});default:return console.warn(`Unknown tracker type: '${t}'. Falling back to default EVM tracker.`),y({tx:e,config:a,transactionsPool:s,onSuccess:i,onError:c,onReplaced:n,...r})}}function Z(t,e){if(F(t))return {tracker:TransactionTracker.Gelato,txKey:t.taskId};if(!isHex(t))throw new Error(`Invalid transaction key format. Expected a Hex string or a GelatoTxKey object, but received: ${JSON.stringify(t)}`);let a=e.split(":");return (a.length>1?a[a.length-1]==="safe"||a[a.length-1]==="safewallet":e?.toLowerCase()==="safe")?{tracker:TransactionTracker.Safe,txKey:t}:{tracker:TransactionTracker.Ethereum,txKey:t}}var X=({chains:t,tx:e})=>{if(e.tracker===TransactionTracker.Safe){let c=B[e.chainId];return c?`${c}${e.from}/transactions/tx?id=multisig_${e.from}_${e.txKey}`:""}let s=t.find(c=>c.id===e.chainId)?.blockExplorers?.default.url;if(!s)return "";let i=(e.adapter===OrbitAdapter.EVM?e.replacedTxHash:e.txKey)||(e.adapter===OrbitAdapter.EVM?e.hash:e.txKey);return i?`${s}/tx/${i}`:""};var ee=1.15;async function te({config:t,tx:e}){if(e.adapter!==OrbitAdapter.EVM)throw new Error(`Speed up is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:a,from:s,to:i,value:c,input:n,maxFeePerGas:r,maxPriorityFeePerGas:o,chainId:l}=e;if(a===void 0||!s||!i||!c||!r||!o)throw new Error("Transaction is missing required fields for speed-up.");try{if(!t)throw new Error("Wagmi config is not provided.");if(!getAccount(t).address)throw new Error("No connected account found.");let p=BigInt(Math.ceil(Number(o)*ee)),d=BigInt(Math.ceil(Number(r)*ee));return await sendTransaction(t,{to:i,value:BigInt(c),data:n||"0x",chainId:l,nonce:a,maxFeePerGas:d,maxPriorityFeePerGas:p})}catch(u){let p=u instanceof Error?u.message:String(u);throw new Error(`Failed to speed up transaction: ${p}`)}}function oa(t,e){if(!t)throw new Error("EVM adapter requires a wagmi config object.");return {key:OrbitAdapter.EVM,getConnectorInfo:()=>{let a=getConnection(t),s=lastConnectedConnectorHelpers.getLastConnectedConnector();return {walletAddress:a.address??s?.address??zeroAddress,connectorType:getConnectorTypeFromName(OrbitAdapter.EVM,a.connector?.name?.toLowerCase()??"unknown")}},checkChainForTx:a=>checkAndSwitchChain(a,t),checkTransactionsTracker:(a,s)=>Z(a,s),checkAndInitializeTrackerInStore:({tx:a,...s})=>J({tracker:a.tracker,tx:a,config:t,...s}),getExplorerUrl:a=>{let{chain:s}=getConnection(t),i=s?.blockExplorers?.default.url;return a?`${i}/${a}`:i},getExplorerTxUrl:a=>X({chains:e,tx:a}),cancelTxAction:a=>C({config:t,tx:a}),speedUpTxAction:a=>te({config:t,tx:a}),retryTxAction:async({onClose:a,txKey:s,executeTxAction:i,tx:c})=>{if(a(s),!i){console.error("Retry failed: executeTxAction function is not provided.");return}await i({actionFunction:()=>c.actionFunction({config:t,...c.payload}),params:c,defaultTracker:TransactionTracker.Ethereum});}}}var g=null,k=null,Ke=300*1e3,He="https://relay.gelato.digital/relays/v2/supported-chains";async function ia(t){let e=Date.now();if(g&&k&&e-k<Ke)return g.includes(t);try{let a=await fetch(He);if(!a.ok)throw new Error(`Gelato API responded with status: ${a.status}`);let i=(await a.json()).chains.map(Number);return g=i,k=e,i.includes(t)}catch(a){return console.error("Failed to fetch Gelato supported chains:",a),g=null,k=null,false}}
|
|
2
|
-
export{
|
|
1
|
+
import {OrbitAdapter,normalizeError,lastConnectedConnectorHelpers,getConnectorTypeFromName}from'@tuwaio/orbit-core';import {checkAndSwitchChain}from'@tuwaio/orbit-evm';import {TransactionStatus,initializePollingTracker,TransactionTracker}from'@tuwaio/pulsar-core';import {getAccount,sendTransaction,getClient,getConnection}from'@wagmi/core';import {zeroHash,http,isHex,zeroAddress}from'viem';import {getTransaction,waitForTransactionReceipt,getBlock}from'viem/actions';import T from'dayjs';import {zksync,polygonZkEvm,optimism,gnosis,celo,bsc,boba,base,avalanche,aurora,arbitrum,polygon,sepolia,goerli,mainnet}from'viem/chains';var E=1.15;async function v({config:t,tx:e}){if(e.adapter!==OrbitAdapter.EVM)throw new Error(`Cancellation is only available for EVM transactions. Received adapter type: '${e.adapter}'.`);let{nonce:a,maxFeePerGas:n,maxPriorityFeePerGas:i,chainId:o}=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 c=getAccount(t);if(!c.address)throw new Error("No connected account found.");let s=BigInt(Math.ceil(Number(i)*E)),r=BigInt(Math.ceil(Number(n)*E));return await sendTransaction(t,{to:c.address,value:0n,chainId:o,nonce:a,maxFeePerGas:r,maxPriorityFeePerGas:s})}catch(c){let s=c instanceof Error?c.message:String(c);throw new Error(`Failed to cancel transaction: ${s}`)}}var ue=10,de=3e3;async function me(t){let{tx:e,config:a,onInitialize:n,onTxDetailsFetched:i,onSuccess:o,onFailure:c,onReplaced:s,retryCount:r=ue,retryTimeout:l=de,waitForTransactionReceiptParams:u}=t;if(n?.(),e.txKey===zeroHash)return c(new Error("Transaction hash cannot be the zero hash."));let p=getClient(a,{chainId:e.chainId});if(!p)return c(new Error(`Could not create a viem client for chainId: ${e.chainId}`));let d=null;for(let f=0;f<r;f++)try{d=await getTransaction(p,{hash:e.txKey}),i(d);break}catch(m){if(f===r-1)return console.error(`EVM tracker failed to fetch tx ${e.txKey} after ${r} retries:`,m),c(m);await new Promise(y=>setTimeout(y,l));}if(!d)return c(new Error("Transaction details could not be fetched."));try{let f=!1,m=await waitForTransactionReceipt(p,{hash:d.hash,onReplaced:y=>{f=!0,s(y);},...u});if(f)return;await o(d,m,p);}catch(f){console.error(`Error waiting for receipt for tx ${e.txKey}:`,f),c(f);}}async function x(t){let{tx:e,config:a,updateTxParams:n,transactionsPool:i,onSuccess:o,onError:c,onReplaced:s}=t;return me({tx:e,config:a,onInitialize:()=>{n(e.txKey,{hash:e.txKey});},onTxDetailsFetched:r=>{n(e.txKey,{to:r.to??void 0,input:r.input,value:r.value?.toString(),nonce:r.nonce,maxFeePerGas:r.maxFeePerGas?.toString(),maxPriorityFeePerGas:r.maxPriorityFeePerGas?.toString()});},onSuccess:async(r,l,u)=>{let p=await getBlock(u,{blockNumber:l.blockNumber}),d=Number(p.timestamp),f=l.status==="success";n(e.txKey,{status:f?TransactionStatus.Success:TransactionStatus.Failed,isError:!f,pending:false,finishedTimestamp:d});let m=i[e.txKey];f&&o&&m&&o(m),!f&&c&&m&&c(new Error("Transaction reverted"),m);},onReplaced:r=>{n(e.txKey,{status:TransactionStatus.Replaced,replacedTxHash:r.transaction.hash,pending:false});let l=i[e.txKey];s&&l&&s(l,e);},onFailure:r=>{n(e.txKey,{status:TransactionStatus.Failed,pending:false,isError:true,error:normalizeError(r)});let l=i[e.txKey];c&&l&&c(r,l);}})}var R=new Map,g=t=>{let{apiKey:e,baseUrl:a,timeout:n}=t,i=a||"https://api.gelato.cloud",o=`${e}:${i}`,c=R.get(o);if(c)return c;let s={timeout:n??15e3,...t.httpTransportConfig,fetchOptions:{headers:{Authorization:`Bearer ${e}`,...t.httpTransportConfig?.fetchOptions?.headers},...t.httpTransportConfig?.fetchOptions}},r=http(`${i}/rpc`,s)({});return R.set(o,r),r};var ge=(o=>(o[o.Pending=100]="Pending",o[o.Submitted=110]="Submitted",o[o.Success=200]="Success",o[o.Rejected=400]="Rejected",o[o.Reverted=500]="Reverted",o))(ge||{}),be=new Set([200,400,500]);function ke(t){return !be.has(t)}function ye(t){return async({tx:e,stopPolling:a,onSuccess:n,onFailure:i,onIntervalTick:o})=>{let c=await t.request({method:"relayer_getStatus",params:{id:e.txKey,logs:false}});o?.(c);let{status:s,createdAt:r}=c;if(r&&T().diff(T.unix(r),"hour")>=1&&ke(s)){a();return}s===200?(n(c),a({withoutRemoving:true})):(s===400||s===500)&&(i(c),a({withoutRemoving:true}));}}function F({tx:t,gelatoApiKey:e,updateTxParams:a,removeTxFromPool:n,transactionsPool:i,onSuccess:o,onError:c}){let s=g({apiKey:e}),r=ye(s);return initializePollingTracker({tx:t,fetcher:r,removeTxFromPool:n,onSuccess:l=>{let u=l.status===200?l.receipt.transactionHash:void 0;a(t.txKey,{status:TransactionStatus.Success,pending:false,isError:false,hash:u,finishedTimestamp:T().unix()});let p=i[t.txKey];o&&p&&o(p);},onIntervalTick:l=>{l.status===110&&a(t.txKey,{hash:l.hash});},onFailure:l=>{let u="Transaction failed or was not found.",p;l&&(l.status===400?u=l.message||"Transaction was rejected by Gelato Relay.":l.status===500&&(u=l.message||"Transaction reverted on-chain.",p=l.receipt.transactionHash));let d=new Error(u);a(t.txKey,{status:TransactionStatus.Failed,pending:false,isError:true,hash:p,error:normalizeError(d),finishedTimestamp:T().unix()});let f=i[t.txKey];c&&f&&c(d,f);}})}var gt={allowedDomains:[/gnosis-safe.io$/,/app.safe.global$/,/metissafe.tech$/],debug:false},O={[mainnet.id]:"https://app.safe.global/eth:",[goerli.id]:"https://app.safe.global/gor:",[sepolia.id]:"https://app.safe.global/sep:",[polygon.id]:"https://app.safe.global/matic:",[arbitrum.id]:"https://app.safe.global/arb1:",[aurora.id]:"https://app.safe.global/aurora:",[avalanche.id]:"https://app.safe.global/avax:",[base.id]:"https://app.safe.global/base:",[boba.id]:"https://app.safe.global/boba:",[bsc.id]:"https://app.safe.global/bnb:",[celo.id]:"https://app.safe.global/celo:",[gnosis.id]:"https://app.safe.global/gno:",[optimism.id]:"https://app.safe.global/oeth:",[polygonZkEvm.id]:"https://app.safe.global/zkevm:",[zksync.id]:"https://app.safe.global/zksync:"},L={[mainnet.id]:"https://safe-transaction-mainnet.safe.global/api/v1",[goerli.id]:"https://safe-transaction-goerli.safe.global/api/v1",[sepolia.id]:"https://safe-transaction-sepolia.safe.global/api/v1",[polygon.id]:"https://safe-transaction-polygon.safe.global/api/v1",[arbitrum.id]:"https://safe-transaction-arbitrum.safe.global/api/v1",[aurora.id]:"https://safe-transaction-aurora.safe.global/api/v1",[avalanche.id]:"https://safe-transaction-avalanche.safe.global/api/v1",[base.id]:"https://safe-transaction-base.safe.global/api/v1",[boba.id]:"https://safe-transaction-boba.safe.global/api/v1",[bsc.id]:"https://safe-transaction-bsc.safe.global/api/v1",[celo.id]:"https://safe-transaction-celo.safe.global/api/v1",[gnosis.id]:"https://safe-transaction-gnosis-chain.safe.global/api/v1",[optimism.id]:"https://safe-transaction-optimism.safe.global/api/v1",[polygonZkEvm.id]:"https://safe-transaction-zkevm.safe.global/api/v1",[zksync.id]:"https://safe-transaction-zksync.safe.global/api/v1"};var Ee=async({tx:t,stopPolling:e,onSuccess:a,onFailure:n,onReplaced:i,onIntervalTick:o})=>{let c=L[t.chainId];if(!c)throw new Error(`Safe Transaction Service URL not found for chainId: ${t.chainId}`);let s=await fetch(`${c}/multisig-transactions/${t.txKey}/`);if(!s.ok)throw s.status===404&&(n(),e()),new Error(`Safe API responded with status: ${s.status}`);let r=await s.json();if(o?.(r),r.isExecuted){r.isSuccessful?a(r):n(r),e({withoutRemoving:true});return}let l=await fetch(`${c}/safes/${t.from}/multisig-transactions/?nonce=${r.nonce}`);if(!l.ok)throw new Error(`Safe API (nonce check) responded with status: ${l.status}`);let p=(await l.json()).results.find(d=>d.isExecuted);if(p){i?.(p),e({withoutRemoving:true});return}T().diff(T(r.submissionDate),"day")>=1&&e();};function W({tx:t,updateTxParams:e,removeTxFromPool:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c}){return initializePollingTracker({tx:t,fetcher:Ee,removeTxFromPool:a,onSuccess:s=>{e(t.txKey,{status:TransactionStatus.Success,pending:false,isError:false,hash:s.transactionHash??void 0,finishedTimestamp:s.executionDate?T(s.executionDate).unix():void 0});let r=n[t.txKey];i&&r&&i(r);},onIntervalTick:s=>{e(t.txKey,{hash:s.transactionHash??void 0});},onFailure:s=>{let r=s?new Error("Safe transaction failed or was rejected."):new Error("Transaction not found.");e(t.txKey,{status:TransactionStatus.Failed,pending:false,isError:true,hash:s?.transactionHash??void 0,error:normalizeError(r),finishedTimestamp:s?.executionDate?T(s.executionDate).unix():void 0});let l=n[t.txKey];o&&l&&o(r,l);},onReplaced:s=>{e(t.txKey,{status:TransactionStatus.Replaced,pending:false,hash:t.adapter===OrbitAdapter.EVM?t.hash:zeroHash,replacedTxHash:s.safeTxHash??zeroHash,finishedTimestamp:s.executionDate?T(s.executionDate).unix():void 0});let r=n[t.txKey];c&&r&&c(r,t);}})}async function Y({tracker:t,tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,gelatoApiKey:s,...r}){switch(t){case TransactionTracker.Ethereum:return x({tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r});case TransactionTracker.Gelato:return s?F({tx:e,transactionsPool:n,onSuccess:i,onError:o,gelatoApiKey:s,...r}):(console.warn(`Gelato tracker requested for tx '${e.txKey}', but no 'gelatoApiKey' was provided. Falling back to default EVM tracker.`),x({tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r}));case TransactionTracker.Safe:return W({tx:e,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r});default:return console.warn(`Unknown tracker type: '${t}'. Falling back to default EVM tracker.`),x({tx:e,config:a,transactionsPool:n,onSuccess:i,onError:o,onReplaced:c,...r})}}function J({actionTxKey:t,connectorType:e,tracker:a,gelatoApiKey:n}){if(a&&a===TransactionTracker.Gelato&&n)return {tracker:TransactionTracker.Gelato,txKey:t};if(!isHex(t))throw new Error(`Invalid transaction key format. Expected a Hex string or a GelatoTxKey object, but received: ${JSON.stringify(t)}`);let i=e.split(":");return (i.length>1?i[i.length-1]==="safe"||i[i.length-1]==="safewallet":e?.toLowerCase()==="safe")?{tracker:TransactionTracker.Safe,txKey:t}:{tracker:TransactionTracker.Ethereum,txKey:t}}var Q=({chains:t,tx:e})=>{if(e.tracker===TransactionTracker.Safe){let o=O[e.chainId];return o?`${o}${e.from}/transactions/tx?id=multisig_${e.from}_${e.txKey}`:""}let n=t.find(o=>o.id===e.chainId)?.blockExplorers?.default.url;if(!n)return "";let i=(e.adapter===OrbitAdapter.EVM?e.replacedTxHash:e.txKey)||(e.adapter===OrbitAdapter.EVM?e.hash:e.txKey);return i?`${n}/tx/${i}`:""};var X=1.15;async function ee({config:t,tx:e}){if(e.adapter!==OrbitAdapter.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:o,input:c,maxFeePerGas:s,maxPriorityFeePerGas:r,chainId:l}=e;if(a===void 0||!n||!i||!o||!s||!r)throw new Error("Transaction is missing required fields for speed-up.");try{if(!t)throw new Error("Wagmi config is not provided.");if(!getAccount(t).address)throw new Error("No connected account found.");let p=BigInt(Math.ceil(Number(r)*X)),d=BigInt(Math.ceil(Number(s)*X));return await sendTransaction(t,{to:i,value:BigInt(o),data:c||"0x",chainId:l,nonce:a,maxFeePerGas:d,maxPriorityFeePerGas:p})}catch(u){let p=u instanceof Error?u.message:String(u);throw new Error(`Failed to speed up transaction: ${p}`)}}function ua(t,e){if(!t)throw new Error("EVM adapter requires a wagmi config object.");return {key:OrbitAdapter.EVM,getConnectorInfo:()=>{let a=getConnection(t),n=lastConnectedConnectorHelpers.getLastConnectedConnector();return {walletAddress:a.address??n?.address??zeroAddress,connectorType:getConnectorTypeFromName(OrbitAdapter.EVM,a.connector?.name?.toLowerCase()??"unknown")}},checkChainForTx:a=>checkAndSwitchChain(a,t),checkTransactionsTracker:a=>J(a),checkAndInitializeTrackerInStore:({tx:a,...n})=>Y({tracker:a.tracker,tx:a,config:t,...n}),getExplorerUrl:a=>{let{chain:n}=getConnection(t),i=n?.blockExplorers?.default.url;return a?`${i}/${a}`:i},getExplorerTxUrl:a=>Q({chains:e,tx:a}),cancelTxAction:a=>v({config:t,tx:a}),speedUpTxAction:a=>ee({config:t,tx:a}),retryTxAction:async({onClose:a,txKey:n,executeTxAction:i,tx:o})=>{if(a(n),!i){console.error("Retry failed: executeTxAction function is not provided.");return}await i({actionFunction:()=>o.actionFunction({config:t,...o.payload}),params:o,defaultTracker:TransactionTracker.Ethereum});}}}var w=new Map;async function Me(t){let e=await t.request({method:"relayer_getCapabilities",params:[]}),a={};for(let[n,i]of Object.entries(e))a[Number(n)]=i;return a}async function ze(t){let e=w.get(t);if(e)return e;let a=g({apiKey:t}),n=await Me(a);return w.set(t,n),n}async function Ta(t,e){try{let a=await ze(e);return t in a}catch(a){return console.error("Failed to fetch Gelato relay capabilities:",a),w.delete(e),false}}
|
|
2
|
+
export{ge as GelatoStatusCode,L as SafeTransactionServiceUrls,v as cancelTxAction,Y as checkAndInitializeTrackerInStore,Ta as checkIsGelatoAvailable,J as checkTransactionsTracker,g as createGelatoClient,me as evmTracker,x as evmTrackerForStore,ye as gelatoFetcher,F as gelatoTrackerForStore,O as gnosisSafeLinksHelper,ua as pulsarEvmAdapter,Ee as safeFetcher,gt as safeSdkOptions,W as safeTrackerForStore,Q as selectEvmTxExplorerLink,ee as speedUpTxAction};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/pulsar-evm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
}
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@tuwaio/pulsar-core": ">=0.
|
|
43
|
-
"@tuwaio/orbit-core": ">=0.2",
|
|
44
|
-
"@tuwaio/orbit-evm": ">=0.2",
|
|
42
|
+
"@tuwaio/pulsar-core": ">=0.5",
|
|
43
|
+
"@tuwaio/orbit-core": ">=0.2.7",
|
|
44
|
+
"@tuwaio/orbit-evm": ">=0.2.9",
|
|
45
45
|
"@wagmi/core": "3.x.x",
|
|
46
46
|
"dayjs": "1.x.x",
|
|
47
47
|
"immer": "11.x.x",
|
|
@@ -49,18 +49,19 @@
|
|
|
49
49
|
"zustand": "5.x.x"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@tuwaio/orbit-core": "^0.2.
|
|
53
|
-
"@tuwaio/orbit-evm": "^0.2.
|
|
54
|
-
"@wagmi/core": "^3.
|
|
52
|
+
"@tuwaio/orbit-core": "^0.2.7",
|
|
53
|
+
"@tuwaio/orbit-evm": "^0.2.10",
|
|
54
|
+
"@wagmi/core": "^3.4.0",
|
|
55
55
|
"dayjs": "^1.11.19",
|
|
56
|
-
"immer": "^11.1.
|
|
57
|
-
"jsdom": "^
|
|
56
|
+
"immer": "^11.1.4",
|
|
57
|
+
"jsdom": "^28.1.0",
|
|
58
58
|
"tsup": "^8.5.1",
|
|
59
59
|
"typescript": "^5.9.3",
|
|
60
|
-
"viem": "^2.
|
|
60
|
+
"viem": "^2.46.3",
|
|
61
61
|
"vitest": "^4.0.18",
|
|
62
|
-
"zustand": "^5.0.
|
|
63
|
-
"
|
|
62
|
+
"zustand": "^5.0.11",
|
|
63
|
+
"dotenv": "^17.3.1",
|
|
64
|
+
"@tuwaio/pulsar-core": "^0.5.1"
|
|
64
65
|
},
|
|
65
66
|
"scripts": {
|
|
66
67
|
"start": "tsup src/index.ts --watch",
|