@chainlink/ccip-sdk 0.92.1 → 0.94.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 +20 -18
- package/dist/api/index.d.ts +103 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +141 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/types.d.ts +38 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/aptos/index.d.ts +20 -33
- package/dist/aptos/index.d.ts.map +1 -1
- package/dist/aptos/index.js +41 -29
- package/dist/aptos/index.js.map +1 -1
- package/dist/aptos/logs.js +1 -1
- package/dist/aptos/logs.js.map +1 -1
- package/dist/aptos/send.js +1 -1
- package/dist/aptos/send.js.map +1 -1
- package/dist/aptos/token.js.map +1 -1
- package/dist/chain.d.ts +215 -73
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +103 -20
- package/dist/chain.js.map +1 -1
- package/dist/commits.d.ts +2 -2
- package/dist/commits.d.ts.map +1 -1
- package/dist/commits.js +4 -4
- package/dist/commits.js.map +1 -1
- package/dist/errors/CCIPError.d.ts.map +1 -1
- package/dist/errors/CCIPError.js +3 -2
- package/dist/errors/CCIPError.js.map +1 -1
- package/dist/errors/codes.d.ts +4 -1
- package/dist/errors/codes.d.ts.map +1 -1
- package/dist/errors/codes.js +6 -1
- package/dist/errors/codes.js.map +1 -1
- package/dist/errors/index.d.ts +5 -2
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +8 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/recovery.d.ts.map +1 -1
- package/dist/errors/recovery.js +4 -1
- package/dist/errors/recovery.js.map +1 -1
- package/dist/errors/specialized.d.ts +29 -4
- package/dist/errors/specialized.d.ts.map +1 -1
- package/dist/errors/specialized.js +48 -6
- package/dist/errors/specialized.js.map +1 -1
- package/dist/evm/errors.js.map +1 -1
- package/dist/evm/index.d.ts +24 -48
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +82 -66
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/logs.js.map +1 -1
- package/dist/evm/offchain.js +3 -2
- package/dist/evm/offchain.js.map +1 -1
- package/dist/evm/viem/client-adapter.d.ts +68 -0
- package/dist/evm/viem/client-adapter.d.ts.map +1 -0
- package/dist/evm/viem/client-adapter.js +104 -0
- package/dist/evm/viem/client-adapter.js.map +1 -0
- package/dist/evm/viem/index.d.ts +29 -0
- package/dist/evm/viem/index.d.ts.map +1 -0
- package/dist/evm/viem/index.js +28 -0
- package/dist/evm/viem/index.js.map +1 -0
- package/dist/evm/viem/types.d.ts +13 -0
- package/dist/evm/viem/types.d.ts.map +1 -0
- package/dist/evm/viem/types.js +2 -0
- package/dist/evm/viem/types.js.map +1 -0
- package/dist/evm/viem/wallet-adapter.d.ts +58 -0
- package/dist/evm/viem/wallet-adapter.d.ts.map +1 -0
- package/dist/evm/viem/wallet-adapter.js +197 -0
- package/dist/evm/viem/wallet-adapter.js.map +1 -0
- package/dist/execution.d.ts +1 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +2 -2
- package/dist/execution.js.map +1 -1
- package/dist/explorer.d.ts +74 -0
- package/dist/explorer.d.ts.map +1 -0
- package/dist/explorer.js +67 -0
- package/dist/explorer.js.map +1 -0
- package/dist/gas.js.map +1 -1
- package/dist/hasher/merklemulti.js.map +1 -1
- package/dist/http-status.d.ts +20 -0
- package/dist/http-status.d.ts.map +1 -0
- package/dist/http-status.js +25 -0
- package/dist/http-status.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/offchain.js.map +1 -1
- package/dist/requests.d.ts +12 -6
- package/dist/requests.d.ts.map +1 -1
- package/dist/requests.js +16 -6
- package/dist/requests.js.map +1 -1
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +20 -0
- package/dist/selectors.js.map +1 -1
- package/dist/solana/cleanup.js +2 -2
- package/dist/solana/cleanup.js.map +1 -1
- package/dist/solana/exec.js +1 -5
- package/dist/solana/exec.js.map +1 -1
- package/dist/solana/index.d.ts +33 -58
- package/dist/solana/index.d.ts.map +1 -1
- package/dist/solana/index.js +126 -73
- package/dist/solana/index.js.map +1 -1
- package/dist/solana/logs.js +2 -2
- package/dist/solana/logs.js.map +1 -1
- package/dist/solana/offchain.js +3 -3
- package/dist/solana/offchain.js.map +1 -1
- package/dist/solana/send.js +1 -1
- package/dist/solana/send.js.map +1 -1
- package/dist/solana/utils.js +1 -1
- package/dist/solana/utils.js.map +1 -1
- package/dist/sui/discovery.d.ts.map +1 -1
- package/dist/sui/discovery.js +2 -5
- package/dist/sui/discovery.js.map +1 -1
- package/dist/sui/events.d.ts.map +1 -1
- package/dist/sui/events.js +1 -4
- package/dist/sui/events.js.map +1 -1
- package/dist/sui/index.d.ts +29 -35
- package/dist/sui/index.d.ts.map +1 -1
- package/dist/sui/index.js +71 -45
- package/dist/sui/index.js.map +1 -1
- package/dist/sui/manuallyExec/encoder.d.ts.map +1 -1
- package/dist/sui/manuallyExec/encoder.js +1 -3
- package/dist/sui/manuallyExec/encoder.js.map +1 -1
- package/dist/sui/manuallyExec/index.d.ts.map +1 -1
- package/dist/sui/manuallyExec/index.js +2 -2
- package/dist/sui/manuallyExec/index.js.map +1 -1
- package/dist/sui/objects.d.ts.map +1 -1
- package/dist/sui/objects.js +6 -5
- package/dist/sui/objects.js.map +1 -1
- package/dist/ton/exec.d.ts +2 -2
- package/dist/ton/exec.d.ts.map +1 -1
- package/dist/ton/exec.js.map +1 -1
- package/dist/ton/hasher.d.ts.map +1 -1
- package/dist/ton/hasher.js +6 -5
- package/dist/ton/hasher.js.map +1 -1
- package/dist/ton/index.d.ts +54 -49
- package/dist/ton/index.d.ts.map +1 -1
- package/dist/ton/index.js +332 -236
- package/dist/ton/index.js.map +1 -1
- package/dist/ton/logs.d.ts +11 -22
- package/dist/ton/logs.d.ts.map +1 -1
- package/dist/ton/logs.js +95 -118
- package/dist/ton/logs.js.map +1 -1
- package/dist/ton/types.d.ts +9 -9
- package/dist/ton/types.d.ts.map +1 -1
- package/dist/ton/types.js +5 -9
- package/dist/ton/types.js.map +1 -1
- package/dist/ton/utils.d.ts +8 -27
- package/dist/ton/utils.d.ts.map +1 -1
- package/dist/ton/utils.js +31 -111
- package/dist/ton/utils.js.map +1 -1
- package/dist/types.d.ts +44 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +30 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +7 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +77 -52
- package/dist/utils.js.map +1 -1
- package/dist/viem.d.ts +6 -0
- package/dist/viem.d.ts.map +1 -0
- package/dist/viem.js +6 -0
- package/dist/viem.js.map +1 -0
- package/package.json +30 -9
- package/src/api/index.ts +167 -0
- package/src/api/types.ts +39 -0
- package/src/aptos/index.ts +71 -64
- package/src/aptos/logs.ts +10 -10
- package/src/aptos/send.ts +1 -1
- package/src/aptos/token.ts +1 -1
- package/src/chain.ts +299 -98
- package/src/commits.ts +5 -5
- package/src/errors/CCIPError.ts +5 -2
- package/src/errors/codes.ts +8 -1
- package/src/errors/index.ts +15 -2
- package/src/errors/recovery.ts +9 -1
- package/src/errors/specialized.ts +61 -6
- package/src/evm/errors.ts +2 -2
- package/src/evm/index.ts +127 -124
- package/src/evm/logs.ts +4 -4
- package/src/evm/offchain.ts +5 -4
- package/src/evm/viem/client-adapter.ts +124 -0
- package/src/evm/viem/index.ts +29 -0
- package/src/evm/viem/types.ts +14 -0
- package/src/evm/viem/wallet-adapter.ts +233 -0
- package/src/execution.ts +9 -9
- package/src/explorer.ts +90 -0
- package/src/gas.ts +2 -2
- package/src/hasher/merklemulti.ts +7 -7
- package/src/http-status.ts +31 -0
- package/src/index.ts +19 -2
- package/src/offchain.ts +1 -1
- package/src/requests.ts +22 -13
- package/src/selectors.ts +20 -0
- package/src/solana/cleanup.ts +4 -4
- package/src/solana/exec.ts +13 -18
- package/src/solana/index.ts +185 -118
- package/src/solana/logs.ts +8 -8
- package/src/solana/offchain.ts +3 -3
- package/src/solana/send.ts +20 -20
- package/src/solana/utils.ts +4 -4
- package/src/sui/discovery.ts +4 -10
- package/src/sui/events.ts +4 -8
- package/src/sui/index.ts +94 -73
- package/src/sui/manuallyExec/encoder.ts +2 -4
- package/src/sui/manuallyExec/index.ts +3 -3
- package/src/sui/objects.ts +17 -15
- package/src/ton/exec.ts +2 -5
- package/src/ton/hasher.ts +7 -5
- package/src/ton/index.ts +394 -316
- package/src/ton/logs.ts +122 -143
- package/src/ton/types.ts +17 -21
- package/src/ton/utils.ts +39 -145
- package/src/types.ts +47 -2
- package/src/utils.ts +98 -66
- package/src/viem.ts +5 -0
- package/tsconfig.json +3 -2
- package/dist/ton/bindings/offramp.d.ts +0 -48
- package/dist/ton/bindings/offramp.d.ts.map +0 -1
- package/dist/ton/bindings/offramp.js +0 -63
- package/dist/ton/bindings/offramp.js.map +0 -1
- package/dist/ton/bindings/onramp.d.ts +0 -40
- package/dist/ton/bindings/onramp.d.ts.map +0 -1
- package/dist/ton/bindings/onramp.js +0 -51
- package/dist/ton/bindings/onramp.js.map +0 -1
- package/dist/ton/bindings/router.d.ts +0 -47
- package/dist/ton/bindings/router.d.ts.map +0 -1
- package/dist/ton/bindings/router.js +0 -51
- package/dist/ton/bindings/router.js.map +0 -1
- package/src/ton/bindings/offramp.ts +0 -96
- package/src/ton/bindings/onramp.ts +0 -72
- package/src/ton/bindings/router.ts +0 -65
package/dist/chain.d.ts
CHANGED
|
@@ -1,13 +1,49 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BytesLike } from 'ethers';
|
|
2
2
|
import type { PickDeep, SetOptional } from 'type-fest';
|
|
3
|
+
import { type LaneLatencyResponse, CCIPAPIClient } from './api/index.ts';
|
|
3
4
|
import type { UnsignedAptosTx } from './aptos/types.ts';
|
|
4
5
|
import type { UnsignedEVMTx } from './evm/types.ts';
|
|
5
6
|
import type { EVMExtraArgsV1, EVMExtraArgsV2, ExtraArgs, SVMExtraArgsV1, SuiExtraArgsV1 } from './extra-args.ts';
|
|
6
7
|
import type { LeafHasher } from './hasher/common.ts';
|
|
7
8
|
import type { UnsignedSolanaTx } from './solana/types.ts';
|
|
8
9
|
import type { UnsignedTONTx } from './ton/types.ts';
|
|
9
|
-
import { type AnyMessage, type CCIPCommit, type CCIPExecution, type CCIPMessage, type CCIPRequest, type ChainFamily, type ChainTransaction, type CommitReport, type ExecutionReceipt, type ExecutionReport, type Lane, type Log_, type Logger, type NetworkInfo, type OffchainTokenData, type WithLogger } from './types.ts';
|
|
10
|
+
import { type AnyMessage, type CCIPCommit, type CCIPExecution, type CCIPMessage, type CCIPRequest, type ChainFamily, type ChainTransaction, type CommitReport, type ExecutionReceipt, type ExecutionReport, type Lane, type Log_, type Logger, type NetworkInfo, type OffchainTokenData, type MessageInput, type WithLogger } from './types.ts';
|
|
10
11
|
import { util } from './utils.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Context for Chain class initialization.
|
|
14
|
+
* Extends WithLogger with optional API client configuration.
|
|
15
|
+
*
|
|
16
|
+
* @example Default behavior (auto-create API client)
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const chain = await EVMChain.fromUrl(rpcUrl, { logger })
|
|
19
|
+
* await chain.getLaneLatency(destSelector) // Works - uses production API
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Custom API endpoint
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const api = new CCIPAPIClient('https://staging-api.example.com', { logger })
|
|
25
|
+
* const chain = await EVMChain.fromUrl(rpcUrl, { apiClient: api, logger })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Explicit opt-out (decentralized mode)
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const chain = await EVMChain.fromUrl(rpcUrl, { apiClient: null, logger })
|
|
31
|
+
* await chain.getLaneLatency(destSelector) // Throws CCIPApiClientNotAvailableError
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export type ChainContext = WithLogger & {
|
|
35
|
+
/**
|
|
36
|
+
* CCIP API client instance for lane information queries.
|
|
37
|
+
*
|
|
38
|
+
* - `undefined` (default): Creates CCIPAPIClient with production endpoint
|
|
39
|
+
* (https://api.ccip.chain.link)
|
|
40
|
+
* - `CCIPAPIClient`: Uses provided instance (allows custom URL, fetch, etc.)
|
|
41
|
+
* - `null`: Disables API client entirely (getLaneLatency() will throw)
|
|
42
|
+
*
|
|
43
|
+
* Default: `undefined` (auto-create with production endpoint)
|
|
44
|
+
*/
|
|
45
|
+
apiClient?: CCIPAPIClient | null;
|
|
46
|
+
};
|
|
11
47
|
/**
|
|
12
48
|
* Filter options for getLogs queries across chains.
|
|
13
49
|
*/
|
|
@@ -77,6 +113,36 @@ export type UnsignedTx = {
|
|
|
77
113
|
[ChainFamily.TON]: UnsignedTONTx;
|
|
78
114
|
[ChainFamily.Sui]: never;
|
|
79
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* Common options for [[getFee]], [[generateUnsignedSendMessage]] and [[sendMessage]] Chain methods
|
|
118
|
+
*/
|
|
119
|
+
export type SendMessageOpts = {
|
|
120
|
+
/** Router address on this chain */
|
|
121
|
+
router: string;
|
|
122
|
+
/** Destination network selector. */
|
|
123
|
+
destChainSelector: bigint;
|
|
124
|
+
/** Message to send. If `fee` is omitted, it'll be calculated */
|
|
125
|
+
message: MessageInput;
|
|
126
|
+
/** Approve the maximum amount of tokens to transfer */
|
|
127
|
+
approveMax?: boolean;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Common options for [[generateUnsignedExecuteReport]] and [[executeReport]] Chain methods
|
|
131
|
+
*/
|
|
132
|
+
export type ExecuteReportOpts = {
|
|
133
|
+
/** address of the OffRamp contract */
|
|
134
|
+
offRamp: string;
|
|
135
|
+
/** execution report */
|
|
136
|
+
execReport: ExecutionReport;
|
|
137
|
+
/** gasLimit or computeUnits limit override for the ccipReceive call */
|
|
138
|
+
gasLimit?: number;
|
|
139
|
+
/** For EVM, overrides gasLimit on tokenPool call */
|
|
140
|
+
tokensGasLimit?: number;
|
|
141
|
+
/** For Solana, send report in chunks to OffRamp, to later execute */
|
|
142
|
+
forceBuffer?: boolean;
|
|
143
|
+
/** For Solana, create and extend addresses in a lookup table before executing */
|
|
144
|
+
forceLookupTable?: boolean;
|
|
145
|
+
};
|
|
80
146
|
/**
|
|
81
147
|
* Works like an interface for a base Chain class, but provides implementation (which can be
|
|
82
148
|
* specialized) for some basic methods
|
|
@@ -86,11 +152,14 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
86
152
|
[util.inspect.custom]: () => string;
|
|
87
153
|
readonly network: NetworkInfo<F>;
|
|
88
154
|
logger: Logger;
|
|
155
|
+
/** CCIP API client (null if opted out) */
|
|
156
|
+
readonly apiClient: CCIPAPIClient | null;
|
|
89
157
|
/**
|
|
90
158
|
* Base constructor for Chain class.
|
|
91
159
|
* @param network - NetworkInfo object for the Chain instance
|
|
160
|
+
* @param ctx - Optional context with logger and API client configuration
|
|
92
161
|
*/
|
|
93
|
-
constructor(network: NetworkInfo,
|
|
162
|
+
constructor(network: NetworkInfo, ctx?: ChainContext);
|
|
94
163
|
/** Cleanup method to release resources (e.g., close connections). */
|
|
95
164
|
destroy?(): void | Promise<void>;
|
|
96
165
|
/**
|
|
@@ -109,14 +178,21 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
109
178
|
* Confirm a log tx is finalized or wait for it to be finalized
|
|
110
179
|
* Throws if it isn't included (e.g. a reorg)
|
|
111
180
|
*/
|
|
112
|
-
waitFinalized({ log, tx
|
|
181
|
+
waitFinalized({ request: { log, tx }, finality, cancel$, }: {
|
|
182
|
+
request: SetOptional<PickDeep<CCIPRequest, `log.${'address' | 'blockNumber' | 'transactionHash' | 'topics' | 'tx.timestamp'}` | 'tx.timestamp'>, 'tx'>;
|
|
183
|
+
finality?: number | 'finalized';
|
|
184
|
+
cancel$?: Promise<unknown>;
|
|
185
|
+
}): Promise<true>;
|
|
113
186
|
/**
|
|
114
187
|
* An async generator that yields logs based on the provided options.
|
|
115
188
|
* @param opts - Options object containing:
|
|
116
189
|
* - `startBlock`: if provided, fetch and generate logs forward starting from this block;
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* - `
|
|
190
|
+
* otherwise, returns logs backwards in time from endBlock;
|
|
191
|
+
* optionally, startTime may be provided to fetch logs forward starting from this time
|
|
192
|
+
* - `startTime`: instead of a startBlock, a start timestamp may be provided;
|
|
193
|
+
* if either is provided, fetch logs forward from this starting point; otherwise, backwards
|
|
194
|
+
* - `endBlock`: if omitted, use latest block; can be a block number, 'latest', 'finalized' or
|
|
195
|
+
* negative finality block depth
|
|
120
196
|
* - `endBefore`: optional hint signature for end of iteration, instead of endBlock
|
|
121
197
|
* - `address`: if provided, fetch logs for this address only (may be required in some
|
|
122
198
|
* networks/implementations)
|
|
@@ -125,6 +201,7 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
125
201
|
* some networks/implementations may not be able to filter topics other than topic0s, so one may
|
|
126
202
|
* want to assume those are optimization hints, instead of hard filters, and verify results
|
|
127
203
|
* - `page`: if provided, try to use this page/range for batches
|
|
204
|
+
* - `watch`: true or cancellation promise, getLogs continuously after initial fetch
|
|
128
205
|
* @returns An async iterable iterator of logs.
|
|
129
206
|
*/
|
|
130
207
|
abstract getLogs(opts: LogFilter): AsyncIterableIterator<Log_>;
|
|
@@ -133,14 +210,14 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
133
210
|
* @param tx - ChainTransaction or txHash to fetch requests from
|
|
134
211
|
* @returns CCIP messages in the transaction (at least one)
|
|
135
212
|
**/
|
|
136
|
-
abstract
|
|
213
|
+
abstract getMessagesInTx(tx: string | ChainTransaction): Promise<CCIPRequest[]>;
|
|
137
214
|
/**
|
|
138
215
|
* Scan for a CCIP request by message ID
|
|
139
216
|
* @param messageId - message ID to fetch request for
|
|
140
217
|
* @param onRamp - address may be required in some implementations, and throw if missing
|
|
141
218
|
* @returns CCIPRequest
|
|
142
219
|
**/
|
|
143
|
-
|
|
220
|
+
getMessageById?(messageId: string, onRamp?: string, opts?: {
|
|
144
221
|
page?: number;
|
|
145
222
|
}): Promise<CCIPRequest>;
|
|
146
223
|
/**
|
|
@@ -149,7 +226,7 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
149
226
|
* @param commit - CommitReport range (min, max).
|
|
150
227
|
* @param opts - Optional parameters (e.g., `page` for pagination width).
|
|
151
228
|
*/
|
|
152
|
-
abstract
|
|
229
|
+
abstract getMessagesInBatch<R extends PickDeep<CCIPRequest, 'lane' | `log.${'topics' | 'address' | 'blockNumber'}` | 'message.sequenceNumber'>>(request: R, commit: Pick<CommitReport, 'minSeqNr' | 'maxSeqNr'>, opts?: {
|
|
153
230
|
page?: number;
|
|
154
231
|
}): Promise<R['message'][]>;
|
|
155
232
|
/**
|
|
@@ -232,99 +309,154 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
232
309
|
abstract getTokenAdminRegistryFor(address: string): Promise<string>;
|
|
233
310
|
/**
|
|
234
311
|
* Fetch the current fee for a given intended message
|
|
235
|
-
* @param
|
|
236
|
-
* @param destChainSelector - dest network selector
|
|
237
|
-
* @param message - message to send
|
|
312
|
+
* @param opts - {@link SendMessageOpts} without approveMax
|
|
238
313
|
*/
|
|
239
|
-
abstract getFee(
|
|
314
|
+
abstract getFee(opts: Omit<SendMessageOpts, 'approveMax'>): Promise<bigint>;
|
|
240
315
|
/**
|
|
241
316
|
* Generate unsigned txs for ccipSend'ing a message
|
|
242
|
-
* @param
|
|
243
|
-
* @param router - address of the Router contract
|
|
244
|
-
* @param destChainSelector - chainSelector of destination chain
|
|
245
|
-
* @param message - AnyMessage to send; if `fee` is not present, it'll be calculated
|
|
246
|
-
* @param approveMax - if tokens approvals are needed, opt into approving maximum allowance
|
|
317
|
+
* @param opts - {@link SendMessageOpts} with sender address
|
|
247
318
|
* @returns chain-family specific unsigned txs
|
|
248
319
|
*/
|
|
249
|
-
abstract generateUnsignedSendMessage(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
approveMax?: boolean;
|
|
320
|
+
abstract generateUnsignedSendMessage(opts: SendMessageOpts & {
|
|
321
|
+
/** Sender address (address of wallet which will send the message) */
|
|
322
|
+
sender: string;
|
|
253
323
|
}): Promise<UnsignedTx[F]>;
|
|
254
324
|
/**
|
|
255
325
|
* Send a CCIP message through a router using provided wallet.
|
|
256
|
-
* @param
|
|
257
|
-
* @
|
|
258
|
-
*
|
|
259
|
-
* @
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
326
|
+
* @param opts - {@link SendMessageOpts} with chain-specific wallet for signing
|
|
327
|
+
* @returns CCIP request
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* const request = await chain.sendMessage({
|
|
332
|
+
* router: '0x...',
|
|
333
|
+
* destChainSelector: 4949039107694359620n,
|
|
334
|
+
* message: {
|
|
335
|
+
* receiver: '0x...',
|
|
336
|
+
* data: '0x1337',
|
|
337
|
+
* tokenAmounts: [{ token: '0x...', amount: 100n }],
|
|
338
|
+
* feeToken: '0xLinkToken',
|
|
339
|
+
* },
|
|
340
|
+
* wallet: signer,
|
|
341
|
+
* })
|
|
342
|
+
* console.log(`Message ID: ${request.message.messageId}`)
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
abstract sendMessage(opts: SendMessageOpts & {
|
|
346
|
+
/** Signer instance (chain-dependent) */
|
|
266
347
|
wallet: unknown;
|
|
267
|
-
approveMax?: boolean;
|
|
268
348
|
}): Promise<CCIPRequest>;
|
|
269
349
|
/**
|
|
270
350
|
* Fetch supported offchain token data for a request from this network
|
|
271
351
|
* @param request - CCIP request, with tx, logs and message
|
|
272
352
|
* @returns array with one offchain token data for each token transfer in request
|
|
273
353
|
*/
|
|
274
|
-
abstract
|
|
354
|
+
abstract getOffchainTokenData(request: CCIPRequest): Promise<OffchainTokenData[]>;
|
|
275
355
|
/**
|
|
276
356
|
* Generate unsigned tx to manuallyExecute a message
|
|
277
|
-
* @param
|
|
278
|
-
* @param offRamp - address of the OffRamp contract
|
|
279
|
-
* @param execReport - execution report
|
|
280
|
-
* @param gasLimit - gasLimit or computeUnits limit override for the ccipReceive call
|
|
281
|
-
* @param tokensGasLimit - For EVM, overrides gasLimit on tokenpPool call
|
|
282
|
-
* @param forceBuffer - For Solana, send report in chunks to OffRamp, to later execute
|
|
283
|
-
* @param forceLookupTable - For Solana, create and extend addresses in a lookup table before executing
|
|
357
|
+
* @param opts - {@link ExecuteReportOpts} with payer address which will send the exec tx
|
|
284
358
|
* @returns chain-family specific unsigned txs
|
|
285
359
|
*/
|
|
286
|
-
abstract generateUnsignedExecuteReport(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
forceBuffer?: boolean;
|
|
290
|
-
forceLookupTable?: boolean;
|
|
360
|
+
abstract generateUnsignedExecuteReport(opts: ExecuteReportOpts & {
|
|
361
|
+
/** address which will be used to send the report tx */
|
|
362
|
+
payer: string;
|
|
291
363
|
}): Promise<UnsignedTx[F]>;
|
|
292
364
|
/**
|
|
293
365
|
* Execute messages in report in an offRamp
|
|
294
|
-
* @param
|
|
295
|
-
* @param execReport - execution report containing messages to execute, proofs and offchainTokenData
|
|
296
|
-
* @param opts - general options for execution (see [[generateUnsignedExecuteReport]])
|
|
297
|
-
* @param wallet - chain-specific wallet or signer instance, to sign transactions
|
|
366
|
+
* @param opts - {@link ExecuteReportOpts} with chain-specific wallet to sign and send tx
|
|
298
367
|
* @returns transaction of the execution
|
|
299
|
-
|
|
300
|
-
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const execReportProof = calculateManualExecProof(
|
|
372
|
+
* messagesInBatch: await source.getMessagesInBatch(request, commit.report),
|
|
373
|
+
* request.lane,
|
|
374
|
+
* request.message.messageId,
|
|
375
|
+
* commit.report.merkleRoot,
|
|
376
|
+
* dest,
|
|
377
|
+
* )
|
|
378
|
+
* const receipt = await dest.executeReport({
|
|
379
|
+
* offRamp,
|
|
380
|
+
* execReport: {
|
|
381
|
+
* ...execReportProof,
|
|
382
|
+
* message: request.message,
|
|
383
|
+
* offchainTokenData: await source.getOffchainTokenData(request),
|
|
384
|
+
* },
|
|
385
|
+
* wallet,
|
|
386
|
+
* })
|
|
387
|
+
* console.log(`Message ID: ${request.message.messageId}`)
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
abstract executeReport(opts: ExecuteReportOpts & {
|
|
301
391
|
wallet: unknown;
|
|
302
|
-
|
|
303
|
-
tokensGasLimit?: number;
|
|
304
|
-
forceBuffer?: boolean;
|
|
305
|
-
forceLookupTable?: boolean;
|
|
306
|
-
}): Promise<ChainTransaction>;
|
|
392
|
+
}): Promise<CCIPExecution>;
|
|
307
393
|
/**
|
|
308
394
|
* Look for a CommitReport at dest for given CCIP request
|
|
309
395
|
* May be specialized by some subclasses
|
|
310
|
-
*
|
|
311
|
-
* @param commitStore - Commit store address
|
|
312
|
-
* @param request - CCIPRequest to get commit info for
|
|
313
|
-
* @param hints - Additional filtering hints
|
|
396
|
+
* @param opts - getCommitReport options
|
|
314
397
|
* @returns CCIPCommit info, or reject if none found
|
|
315
398
|
**/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
*
|
|
324
|
-
*
|
|
399
|
+
getCommitReport({ commitStore, request, ...hints }: {
|
|
400
|
+
/** address of commitStore (OffRamp in \>=v1.6) */
|
|
401
|
+
commitStore: string;
|
|
402
|
+
/** CCIPRequest subset object */
|
|
403
|
+
request: PickDeep<CCIPRequest, 'lane' | 'message.sequenceNumber' | 'tx.timestamp'>;
|
|
404
|
+
} & Pick<LogFilter, 'page' | 'watch' | 'startBlock'>): Promise<CCIPCommit>;
|
|
405
|
+
/**
|
|
406
|
+
* Fetches estimated lane latency to a destination chain.
|
|
407
|
+
* Uses this chain's selector as the source.
|
|
408
|
+
*
|
|
409
|
+
* @param destChainSelector - Destination CCIP chain selector (bigint)
|
|
410
|
+
* @returns Promise resolving to {@link LaneLatencyResponse} containing:
|
|
411
|
+
* - `lane.sourceNetworkInfo` - Source chain metadata (name, selector, chainId)
|
|
412
|
+
* - `lane.destNetworkInfo` - Destination chain metadata
|
|
413
|
+
* - `lane.routerAddress` - Router contract address on source chain
|
|
414
|
+
* - `totalMs` - Estimated delivery time in milliseconds
|
|
415
|
+
*
|
|
416
|
+
* @throws {@link CCIPApiClientNotAvailableError} if apiClient was disabled (set to `null`)
|
|
417
|
+
* @throws {@link CCIPHttpError} if API request fails (network error, 4xx, 5xx status)
|
|
418
|
+
*
|
|
419
|
+
* @remarks
|
|
420
|
+
* Each call makes a fresh API request. Consider caching results if making
|
|
421
|
+
* frequent calls for the same lane.
|
|
422
|
+
*
|
|
423
|
+
* @example Get estimated delivery time
|
|
424
|
+
* ```typescript
|
|
425
|
+
* const chain = await EVMChain.fromUrl('https://eth-mainnet.example.com')
|
|
426
|
+
* try {
|
|
427
|
+
* const latency = await chain.getLaneLatency(4949039107694359620n) // Arbitrum
|
|
428
|
+
* console.log(`Estimated delivery: ${Math.round(latency.totalMs / 60000)} minutes`)
|
|
429
|
+
* console.log(`Router: ${latency.lane.routerAddress}`)
|
|
430
|
+
* } catch (err) {
|
|
431
|
+
* if (err instanceof CCIPHttpError) {
|
|
432
|
+
* console.error(`API error: ${err.context.apiErrorCode}`)
|
|
433
|
+
* }
|
|
434
|
+
* }
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
getLaneLatency(destChainSelector: bigint): Promise<LaneLatencyResponse>;
|
|
438
|
+
/**
|
|
439
|
+
* Default/generic implementation of getExecutionReceipts
|
|
440
|
+
* @param opts - getExecutionReceipts options
|
|
325
441
|
* @returns Async generator of CCIPExecution receipts
|
|
326
442
|
*/
|
|
327
|
-
|
|
443
|
+
getExecutionReceipts({ offRamp, messageId, sourceChainSelector, commit, ...hints }: {
|
|
444
|
+
/** address of OffRamp contract */
|
|
445
|
+
offRamp: string;
|
|
446
|
+
/** filter: yield only executions for this message */
|
|
447
|
+
messageId?: string;
|
|
448
|
+
/** filter: yield only executions for this source chain */
|
|
449
|
+
sourceChainSelector?: bigint;
|
|
450
|
+
/** optional commit associated with the request, can be used for optimizations in some families */
|
|
451
|
+
commit?: CCIPCommit;
|
|
452
|
+
} & Pick<LogFilter, 'page' | 'watch' | 'startBlock' | 'startTime'>): AsyncIterableIterator<CCIPExecution>;
|
|
453
|
+
/**
|
|
454
|
+
* Fetch first execution receipt inside a transaction.
|
|
455
|
+
* @internal
|
|
456
|
+
* @param tx - transaction hash or transaction object
|
|
457
|
+
* @returns CCIP execution object
|
|
458
|
+
*/
|
|
459
|
+
getExecutionReceiptInTx(tx: string | ChainTransaction): Promise<CCIPExecution>;
|
|
328
460
|
/**
|
|
329
461
|
* List tokens supported by given TokenAdminRegistry contract.
|
|
330
462
|
* @param address - Usually TokenAdminRegistry, but chain may support receiving Router, OnRamp, etc.
|
|
@@ -366,6 +498,8 @@ export declare abstract class Chain<F extends ChainFamily = ChainFamily> {
|
|
|
366
498
|
* @returns Mapping of token addresses to respective TokenInfo objects.
|
|
367
499
|
*/
|
|
368
500
|
abstract getFeeTokens(router: string): Promise<Record<string, TokenInfo>>;
|
|
501
|
+
/** {@inheritDoc ChainStatic.buildMessageForDest} */
|
|
502
|
+
static buildMessageForDest(message: Parameters<ChainStatic['buildMessageForDest']>[0]): AnyMessage;
|
|
369
503
|
}
|
|
370
504
|
/** Static methods and properties available on Chain class constructors. */
|
|
371
505
|
export type ChainStatic<F extends ChainFamily = ChainFamily> = Function & {
|
|
@@ -374,8 +508,9 @@ export type ChainStatic<F extends ChainFamily = ChainFamily> = Function & {
|
|
|
374
508
|
/**
|
|
375
509
|
* async constructor: builds a Chain from a rpc endpoint url
|
|
376
510
|
* @param url - rpc endpoint url
|
|
511
|
+
* @param ctx - optional context with logger and API client configuration
|
|
377
512
|
*/
|
|
378
|
-
fromUrl(url: string, ctx?:
|
|
513
|
+
fromUrl(url: string, ctx?: ChainContext): Promise<Chain<F>>;
|
|
379
514
|
/**
|
|
380
515
|
* Try to decode a CCIP message *from* a log/event *originated* from this *source* chain,
|
|
381
516
|
* but which may *target* other dest chain families
|
|
@@ -449,6 +584,13 @@ export type ChainStatic<F extends ChainFamily = ChainFamily> = Function & {
|
|
|
449
584
|
* @returns Ordered record with messages/properties, or undefined if not a recognized error
|
|
450
585
|
*/
|
|
451
586
|
parse?(data: unknown): Record<string, unknown> | undefined | null;
|
|
587
|
+
/**
|
|
588
|
+
* Returns a copy of a message, populating missing fields like `extraArgs` with defaults
|
|
589
|
+
* It's expected to return a message suitable at least for basic token transfers
|
|
590
|
+
* @param message - AnyMessage (from source), containing at least `receiver`
|
|
591
|
+
* @returns A message suitable for `sendMessage` to this destination chain family
|
|
592
|
+
*/
|
|
593
|
+
buildMessageForDest(message: MessageInput): AnyMessage;
|
|
452
594
|
};
|
|
453
595
|
/** Function type for getting a Chain instance by ID, selector, or name. */
|
|
454
596
|
export type ChainGetter = (idOrSelectorOrName: number | string | bigint) => Promise<Chain>;
|
package/dist/chain.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,QAAQ,CAAA;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEtD,O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ain.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { dataLength } from 'ethers';
|
|
2
|
+
import { CCIPAPIClient } from "./api/index.js";
|
|
3
|
+
import { getCommitReport } from "./commits.js";
|
|
4
|
+
import { CCIPApiClientNotAvailableError, CCIPChainFamilyMismatchError, CCIPExecTxRevertedError, CCIPTransactionNotFinalizedError, } from "./errors/index.js";
|
|
5
|
+
import { DEFAULT_GAS_LIMIT } from "./evm/const.js";
|
|
3
6
|
import { ExecutionState, } from "./types.js";
|
|
4
7
|
import { util } from "./utils.js";
|
|
5
8
|
/**
|
|
@@ -9,15 +12,29 @@ import { util } from "./utils.js";
|
|
|
9
12
|
export class Chain {
|
|
10
13
|
network;
|
|
11
14
|
logger;
|
|
15
|
+
/** CCIP API client (null if opted out) */
|
|
16
|
+
apiClient;
|
|
12
17
|
/**
|
|
13
18
|
* Base constructor for Chain class.
|
|
14
19
|
* @param network - NetworkInfo object for the Chain instance
|
|
20
|
+
* @param ctx - Optional context with logger and API client configuration
|
|
15
21
|
*/
|
|
16
|
-
constructor(network,
|
|
22
|
+
constructor(network, ctx) {
|
|
23
|
+
const { logger = console, apiClient } = ctx ?? {};
|
|
17
24
|
if (network.family !== this.constructor.family)
|
|
18
25
|
throw new CCIPChainFamilyMismatchError(this.constructor.name, this.constructor.family, network.family);
|
|
19
26
|
this.network = network;
|
|
20
27
|
this.logger = logger;
|
|
28
|
+
// API client initialization: default enabled, null = explicit opt-out
|
|
29
|
+
if (apiClient === null) {
|
|
30
|
+
this.apiClient = null; // Explicit opt-out
|
|
31
|
+
}
|
|
32
|
+
else if (apiClient !== undefined) {
|
|
33
|
+
this.apiClient = apiClient; // Use provided instance
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.apiClient = new CCIPAPIClient(undefined, { logger }); // Default
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
/** Custom inspector for Node.js util.inspect. */
|
|
23
40
|
[util.inspect.custom]() {
|
|
@@ -27,7 +44,7 @@ export class Chain {
|
|
|
27
44
|
* Confirm a log tx is finalized or wait for it to be finalized
|
|
28
45
|
* Throws if it isn't included (e.g. a reorg)
|
|
29
46
|
*/
|
|
30
|
-
async waitFinalized({ log, tx
|
|
47
|
+
async waitFinalized({ request: { log, tx }, finality = 'finalized', cancel$, }) {
|
|
31
48
|
const timestamp = log.tx?.timestamp ?? tx?.timestamp;
|
|
32
49
|
if (!timestamp || Date.now() / 1e3 - timestamp > 60) {
|
|
33
50
|
// only try to fetch tx if request is old enough (>60s)
|
|
@@ -57,34 +74,70 @@ export class Chain {
|
|
|
57
74
|
/**
|
|
58
75
|
* Look for a CommitReport at dest for given CCIP request
|
|
59
76
|
* May be specialized by some subclasses
|
|
60
|
-
*
|
|
61
|
-
* @param commitStore - Commit store address
|
|
62
|
-
* @param request - CCIPRequest to get commit info for
|
|
63
|
-
* @param hints - Additional filtering hints
|
|
77
|
+
* @param opts - getCommitReport options
|
|
64
78
|
* @returns CCIPCommit info, or reject if none found
|
|
65
79
|
**/
|
|
66
|
-
async
|
|
67
|
-
return
|
|
80
|
+
async getCommitReport({ commitStore, request, ...hints }) {
|
|
81
|
+
return getCommitReport(this, commitStore, request, hints);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Fetches estimated lane latency to a destination chain.
|
|
85
|
+
* Uses this chain's selector as the source.
|
|
86
|
+
*
|
|
87
|
+
* @param destChainSelector - Destination CCIP chain selector (bigint)
|
|
88
|
+
* @returns Promise resolving to {@link LaneLatencyResponse} containing:
|
|
89
|
+
* - `lane.sourceNetworkInfo` - Source chain metadata (name, selector, chainId)
|
|
90
|
+
* - `lane.destNetworkInfo` - Destination chain metadata
|
|
91
|
+
* - `lane.routerAddress` - Router contract address on source chain
|
|
92
|
+
* - `totalMs` - Estimated delivery time in milliseconds
|
|
93
|
+
*
|
|
94
|
+
* @throws {@link CCIPApiClientNotAvailableError} if apiClient was disabled (set to `null`)
|
|
95
|
+
* @throws {@link CCIPHttpError} if API request fails (network error, 4xx, 5xx status)
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Each call makes a fresh API request. Consider caching results if making
|
|
99
|
+
* frequent calls for the same lane.
|
|
100
|
+
*
|
|
101
|
+
* @example Get estimated delivery time
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const chain = await EVMChain.fromUrl('https://eth-mainnet.example.com')
|
|
104
|
+
* try {
|
|
105
|
+
* const latency = await chain.getLaneLatency(4949039107694359620n) // Arbitrum
|
|
106
|
+
* console.log(`Estimated delivery: ${Math.round(latency.totalMs / 60000)} minutes`)
|
|
107
|
+
* console.log(`Router: ${latency.lane.routerAddress}`)
|
|
108
|
+
* } catch (err) {
|
|
109
|
+
* if (err instanceof CCIPHttpError) {
|
|
110
|
+
* console.error(`API error: ${err.context.apiErrorCode}`)
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
async getLaneLatency(destChainSelector) {
|
|
116
|
+
if (!this.apiClient) {
|
|
117
|
+
throw new CCIPApiClientNotAvailableError();
|
|
118
|
+
}
|
|
119
|
+
return this.apiClient.getLaneLatency(this.network.chainSelector, destChainSelector);
|
|
68
120
|
}
|
|
69
121
|
/**
|
|
70
|
-
* Default/generic implementation of
|
|
71
|
-
* @param
|
|
72
|
-
* @param request - CCIPRequest to get execution receipts for
|
|
73
|
-
* @param commit - CCIPCommit info to help narrowing search for executions
|
|
74
|
-
* @param hints - Additional filtering hints
|
|
122
|
+
* Default/generic implementation of getExecutionReceipts
|
|
123
|
+
* @param opts - getExecutionReceipts options
|
|
75
124
|
* @returns Async generator of CCIPExecution receipts
|
|
76
125
|
*/
|
|
77
|
-
async *
|
|
78
|
-
|
|
126
|
+
async *getExecutionReceipts({ offRamp, messageId, sourceChainSelector, commit, ...hints }) {
|
|
127
|
+
hints.startBlock ??= commit?.log.blockNumber;
|
|
128
|
+
const onlyLast = !hints.startTime && !hints.startBlock; // backwards
|
|
79
129
|
for await (const log of this.getLogs({
|
|
80
|
-
startBlock: commit?.log.blockNumber,
|
|
81
|
-
startTime: request.tx.timestamp,
|
|
82
130
|
address: offRamp,
|
|
83
131
|
topics: ['ExecutionStateChanged'],
|
|
84
132
|
...hints,
|
|
85
133
|
})) {
|
|
86
134
|
const receipt = this.constructor.decodeReceipt(log);
|
|
87
|
-
|
|
135
|
+
// filters
|
|
136
|
+
if (!receipt ||
|
|
137
|
+
(messageId && receipt.messageId !== messageId) ||
|
|
138
|
+
(sourceChainSelector &&
|
|
139
|
+
receipt.sourceChainSelector &&
|
|
140
|
+
receipt.sourceChainSelector !== sourceChainSelector))
|
|
88
141
|
continue;
|
|
89
142
|
const timestamp = log.tx?.timestamp ?? (await this.getBlockTimestamp(log.blockNumber));
|
|
90
143
|
yield { receipt, log, timestamp };
|
|
@@ -92,5 +145,35 @@ export class Chain {
|
|
|
92
145
|
break;
|
|
93
146
|
}
|
|
94
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Fetch first execution receipt inside a transaction.
|
|
150
|
+
* @internal
|
|
151
|
+
* @param tx - transaction hash or transaction object
|
|
152
|
+
* @returns CCIP execution object
|
|
153
|
+
*/
|
|
154
|
+
async getExecutionReceiptInTx(tx) {
|
|
155
|
+
if (typeof tx === 'string')
|
|
156
|
+
tx = await this.getTransaction(tx);
|
|
157
|
+
for (const log of tx.logs) {
|
|
158
|
+
const rcpt = this.constructor.decodeReceipt(log);
|
|
159
|
+
if (!rcpt)
|
|
160
|
+
continue;
|
|
161
|
+
const timestamp = tx.timestamp;
|
|
162
|
+
return { receipt: rcpt, log, timestamp };
|
|
163
|
+
}
|
|
164
|
+
throw new CCIPExecTxRevertedError(tx.hash);
|
|
165
|
+
}
|
|
166
|
+
/** {@inheritDoc ChainStatic.buildMessageForDest} */
|
|
167
|
+
static buildMessageForDest(message) {
|
|
168
|
+
// default to GenericExtraArgsV2, aka EVMExtraArgsV2
|
|
169
|
+
return {
|
|
170
|
+
...message,
|
|
171
|
+
extraArgs: {
|
|
172
|
+
gasLimit: message.data && dataLength(message.data) ? DEFAULT_GAS_LIMIT : 0n,
|
|
173
|
+
allowOutOfOrderExecution: true,
|
|
174
|
+
...message.extraArgs,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
95
178
|
}
|
|
96
179
|
//# sourceMappingURL=chain.js.map
|