@chainlink/ccip-sdk 0.95.0 → 0.96.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 +2 -2
- package/dist/all-chains.d.ts +23 -0
- package/dist/all-chains.d.ts.map +1 -0
- package/dist/all-chains.js +24 -0
- package/dist/all-chains.js.map +1 -0
- package/dist/api/index.d.ts +15 -12
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +20 -16
- package/dist/api/index.js.map +1 -1
- package/dist/api/types.d.ts +25 -29
- package/dist/api/types.d.ts.map +1 -1
- package/dist/aptos/index.d.ts +33 -8
- package/dist/aptos/index.d.ts.map +1 -1
- package/dist/aptos/index.js +74 -41
- package/dist/aptos/index.js.map +1 -1
- package/dist/chain.d.ts +220 -41
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +105 -15
- package/dist/chain.js.map +1 -1
- package/dist/errors/codes.d.ts +2 -0
- package/dist/errors/codes.d.ts.map +1 -1
- package/dist/errors/codes.js +2 -0
- package/dist/errors/codes.js.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/recovery.d.ts.map +1 -1
- package/dist/errors/recovery.js +2 -0
- package/dist/errors/recovery.js.map +1 -1
- package/dist/errors/specialized.d.ts +12 -6
- package/dist/errors/specialized.d.ts.map +1 -1
- package/dist/errors/specialized.js +19 -7
- package/dist/errors/specialized.js.map +1 -1
- package/dist/evm/extra-args.d.ts +25 -0
- package/dist/evm/extra-args.d.ts.map +1 -0
- package/dist/evm/extra-args.js +328 -0
- package/dist/evm/extra-args.js.map +1 -0
- package/dist/evm/gas.d.ts.map +1 -1
- package/dist/evm/gas.js +7 -12
- package/dist/evm/gas.js.map +1 -1
- package/dist/evm/index.d.ts +70 -24
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +72 -91
- package/dist/evm/index.js.map +1 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +16 -2
- package/dist/execution.js.map +1 -1
- package/dist/extra-args.d.ts +103 -4
- package/dist/extra-args.d.ts.map +1 -1
- package/dist/extra-args.js +28 -3
- package/dist/extra-args.js.map +1 -1
- package/dist/gas.d.ts +6 -3
- package/dist/gas.d.ts.map +1 -1
- package/dist/gas.js +14 -6
- package/dist/gas.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/requests.d.ts +17 -9
- package/dist/requests.d.ts.map +1 -1
- package/dist/requests.js +17 -9
- package/dist/requests.js.map +1 -1
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +12 -0
- package/dist/selectors.js.map +1 -1
- package/dist/solana/index.d.ts +70 -15
- package/dist/solana/index.d.ts.map +1 -1
- package/dist/solana/index.js +72 -16
- package/dist/solana/index.js.map +1 -1
- package/dist/sui/index.d.ts +37 -9
- package/dist/sui/index.d.ts.map +1 -1
- package/dist/sui/index.js +40 -11
- package/dist/sui/index.js.map +1 -1
- package/dist/ton/index.d.ts +65 -19
- package/dist/ton/index.d.ts.map +1 -1
- package/dist/ton/index.js +155 -25
- package/dist/ton/index.js.map +1 -1
- package/dist/ton/send.d.ts +52 -0
- package/dist/ton/send.d.ts.map +1 -0
- package/dist/ton/send.js +166 -0
- package/dist/ton/send.js.map +1 -0
- package/dist/types.d.ts +102 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +15 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -6
- package/dist/utils.js.map +1 -1
- package/package.json +12 -7
- package/src/all-chains.ts +26 -0
- package/src/api/index.ts +26 -25
- package/src/api/types.ts +25 -30
- package/src/aptos/index.ts +79 -43
- package/src/chain.ts +274 -46
- package/src/errors/codes.ts +2 -0
- package/src/errors/index.ts +1 -1
- package/src/errors/recovery.ts +2 -0
- package/src/errors/specialized.ts +24 -7
- package/src/evm/extra-args.ts +377 -0
- package/src/evm/gas.ts +14 -13
- package/src/evm/index.ts +76 -125
- package/src/execution.ts +18 -2
- package/src/extra-args.ts +108 -4
- package/src/gas.ts +16 -9
- package/src/index.ts +12 -9
- package/src/requests.ts +17 -9
- package/src/selectors.ts +12 -0
- package/src/solana/index.ts +72 -16
- package/src/sui/index.ts +40 -11
- package/src/ton/index.ts +192 -27
- package/src/ton/send.ts +222 -0
- package/src/types.ts +103 -1
- package/src/utils.ts +19 -6
package/src/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbiParametersToPrimitiveTypes, ExtractAbiEvent } from 'abitype'
|
|
2
2
|
import type { BytesLike, Log } from 'ethers'
|
|
3
3
|
|
|
4
|
+
import type { APICCIPRequestMetadata } from './api/types.ts'
|
|
4
5
|
import type OffRamp_1_6_ABI from './evm/abi/OffRamp_1_6.ts'
|
|
5
6
|
import type { CCIPMessage_EVM, CCIPMessage_V1_6_EVM } from './evm/messages.ts'
|
|
6
7
|
import type { ExtraArgs } from './extra-args.ts'
|
|
@@ -104,6 +105,17 @@ type ChainFamilyWithId<F extends ChainFamily> = F extends
|
|
|
104
105
|
|
|
105
106
|
/**
|
|
106
107
|
* Network information including chain selector and metadata.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const info: NetworkInfo = {
|
|
112
|
+
* chainSelector: 16015286601757825753n,
|
|
113
|
+
* name: 'ethereum-testnet-sepolia',
|
|
114
|
+
* networkType: 'TESTNET',
|
|
115
|
+
* family: 'EVM',
|
|
116
|
+
* chainId: 11155111,
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
107
119
|
*/
|
|
108
120
|
export type NetworkInfo<F extends ChainFamily = ChainFamily> = {
|
|
109
121
|
/** Unique chain selector used by CCIP. */
|
|
@@ -116,6 +128,16 @@ export type NetworkInfo<F extends ChainFamily = ChainFamily> = {
|
|
|
116
128
|
|
|
117
129
|
/**
|
|
118
130
|
* CCIP lane configuration connecting source and destination chains.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const lane: Lane = {
|
|
135
|
+
* sourceChainSelector: 16015286601757825753n, // Ethereum Sepolia
|
|
136
|
+
* destChainSelector: 12532609583862916517n, // Polygon Mumbai
|
|
137
|
+
* onRamp: '0x1234...abcd',
|
|
138
|
+
* version: '1.6.0',
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
119
141
|
*/
|
|
120
142
|
export interface Lane<V extends CCIPVersion = CCIPVersion> {
|
|
121
143
|
/** Source chain selector. */
|
|
@@ -149,6 +171,17 @@ export type Log_ = Pick<Log, 'topics' | 'index' | 'address' | 'blockNumber' | 't
|
|
|
149
171
|
|
|
150
172
|
/**
|
|
151
173
|
* Generic transaction structure compatible across chain families.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const tx: ChainTransaction = {
|
|
178
|
+
* hash: '0xabc123...',
|
|
179
|
+
* logs: [],
|
|
180
|
+
* blockNumber: 12345678,
|
|
181
|
+
* timestamp: 1704067200,
|
|
182
|
+
* from: '0x1234...abcd',
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
152
185
|
*/
|
|
153
186
|
export type ChainTransaction = {
|
|
154
187
|
/** Transaction hash. */
|
|
@@ -177,6 +210,29 @@ export interface CCIPRequest<V extends CCIPVersion = CCIPVersion> {
|
|
|
177
210
|
log: Log_
|
|
178
211
|
/** Transaction that emitted the request. */
|
|
179
212
|
tx: Pick<ChainTransaction, 'hash' | 'logs' | 'blockNumber' | 'timestamp' | 'from' | 'error'>
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* API-enriched metadata. Present only when fetched via CCIP API.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* When a request is fetched using {@link Chain.getMessageById} or as a fallback
|
|
219
|
+
* in {@link Chain.getMessagesInTx}, this field contains additional information
|
|
220
|
+
* including message status, execution details, and network info.
|
|
221
|
+
*
|
|
222
|
+
* When constructed from on-chain data only, this field is `undefined`.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const request = await chain.getMessageById(messageId)
|
|
227
|
+
* if (request.metadata) {
|
|
228
|
+
* console.log('Status:', request.metadata.status)
|
|
229
|
+
* console.log('Delivery time:', request.metadata.deliveryTime)
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @see {@link APICCIPRequestMetadata}
|
|
234
|
+
*/
|
|
235
|
+
metadata?: APICCIPRequestMetadata
|
|
180
236
|
}
|
|
181
237
|
|
|
182
238
|
/**
|
|
@@ -254,6 +310,16 @@ export type IntentStatus = (typeof IntentStatus)[keyof typeof IntentStatus]
|
|
|
254
310
|
|
|
255
311
|
/**
|
|
256
312
|
* Receipt of a CCIP message execution on the destination chain.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* const receipt: ExecutionReceipt = {
|
|
317
|
+
* messageId: '0xabc123...',
|
|
318
|
+
* sequenceNumber: 42n,
|
|
319
|
+
* state: ExecutionState.Success,
|
|
320
|
+
* sourceChainSelector: 16015286601757825753n,
|
|
321
|
+
* }
|
|
322
|
+
* ```
|
|
257
323
|
*/
|
|
258
324
|
export type ExecutionReceipt = {
|
|
259
325
|
/** Unique message identifier. */
|
|
@@ -291,6 +357,17 @@ export type OffchainTokenData = { _tag: string; [k: string]: BytesLike } | undef
|
|
|
291
357
|
|
|
292
358
|
/**
|
|
293
359
|
* Execution report containing message, proofs, and offchain token data.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const report: ExecutionReport = {
|
|
364
|
+
* message: { messageId: '0x...', ... },
|
|
365
|
+
* proofs: ['0xproof1...', '0xproof2...'],
|
|
366
|
+
* proofFlagBits: 0n,
|
|
367
|
+
* merkleRoot: '0xroot...',
|
|
368
|
+
* offchainTokenData: [],
|
|
369
|
+
* }
|
|
370
|
+
* ```
|
|
294
371
|
*/
|
|
295
372
|
export type ExecutionReport<M extends CCIPMessage = CCIPMessage> = {
|
|
296
373
|
/** The CCIP message to execute. */
|
|
@@ -307,6 +384,16 @@ export type ExecutionReport<M extends CCIPMessage = CCIPMessage> = {
|
|
|
307
384
|
|
|
308
385
|
/**
|
|
309
386
|
* A message to be sent to another network.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* const message: AnyMessage = {
|
|
391
|
+
* receiver: '0x1234...abcd',
|
|
392
|
+
* extraArgs: { gasLimit: 200_000n, allowOutOfOrderExecution: true },
|
|
393
|
+
* data: '0xdeadbeef',
|
|
394
|
+
* tokenAmounts: [{ token: '0xtoken...', amount: 1000000n }],
|
|
395
|
+
* }
|
|
396
|
+
* ```
|
|
310
397
|
*/
|
|
311
398
|
export type AnyMessage = {
|
|
312
399
|
/** Receiver address on the destination chain. */
|
|
@@ -322,7 +409,22 @@ export type AnyMessage = {
|
|
|
322
409
|
}
|
|
323
410
|
|
|
324
411
|
/**
|
|
325
|
-
* Partial
|
|
412
|
+
* Partial {@link AnyMessage}, which populates default fields like `extraArgs` if needed.
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* // Minimal input - only receiver required, defaults applied for extraArgs
|
|
417
|
+
* const input: MessageInput = {
|
|
418
|
+
* receiver: '0x1234...abcd',
|
|
419
|
+
* }
|
|
420
|
+
*
|
|
421
|
+
* // With custom gas limit
|
|
422
|
+
* const inputWithGas: MessageInput = {
|
|
423
|
+
* receiver: '0x1234...abcd',
|
|
424
|
+
* extraArgs: { gasLimit: 500_000n },
|
|
425
|
+
* data: '0xdeadbeef',
|
|
426
|
+
* }
|
|
427
|
+
* ```
|
|
326
428
|
*/
|
|
327
429
|
export type MessageInput = Partial<AnyMessage> & {
|
|
328
430
|
receiver: AnyMessage['receiver']
|
package/src/utils.ts
CHANGED
|
@@ -38,7 +38,8 @@ import { type NetworkInfo, type WithLogger, ChainFamily } from './types.ts'
|
|
|
38
38
|
* @param timestamp - target timestamp
|
|
39
39
|
* @param precision - returned blockNumber should be within this many blocks before timestamp
|
|
40
40
|
* @returns blockNumber of a block at provider which is close but before target timestamp
|
|
41
|
-
|
|
41
|
+
* @throws {@link CCIPBlockBeforeTimestampNotFoundError} if no block exists before the given timestamp
|
|
42
|
+
*/
|
|
42
43
|
export async function getSomeBlockNumberBefore(
|
|
43
44
|
getBlockTimestamp: (blockNumber: number) => Promise<number>,
|
|
44
45
|
recentBlockNumber: number,
|
|
@@ -106,9 +107,9 @@ export async function getSomeBlockNumberBefore(
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
|
-
*
|
|
110
|
+
* Converts a chain ID to complete NetworkInfo.
|
|
111
|
+
* Memoized to return the same object reference for a given chainId.
|
|
110
112
|
*/
|
|
111
|
-
// memoized so we always output the same object for a given chainId
|
|
112
113
|
const networkInfoFromChainId = memoize((chainId: NetworkInfo['chainId']): NetworkInfo => {
|
|
113
114
|
const sel = SELECTORS[chainId]
|
|
114
115
|
if (!sel?.name) throw new CCIPChainNotFoundError(chainId)
|
|
@@ -129,6 +130,7 @@ const networkInfoFromChainId = memoize((chainId: NetworkInfo['chainId']): Networ
|
|
|
129
130
|
* - Chain ID as number, bigint or string (EVM: "1", Aptos: "aptos:1", Solana: genesisHash)
|
|
130
131
|
* - Chain name as string ("ethereum-mainnet")
|
|
131
132
|
* @returns Complete NetworkInfo object
|
|
133
|
+
* @throws {@link CCIPChainNotFoundError} if chain is not found
|
|
132
134
|
*/
|
|
133
135
|
export const networkInfo = memoize(function networkInfo_(
|
|
134
136
|
selectorOrIdOrName: bigint | number | string,
|
|
@@ -237,7 +239,11 @@ export function parseJson<T = unknown>(text: string): T {
|
|
|
237
239
|
|
|
238
240
|
/**
|
|
239
241
|
* Decode address from a 32-byte hex string
|
|
240
|
-
|
|
242
|
+
* @param address - Address bytes to decode
|
|
243
|
+
* @param family - Chain family for address format (defaults to EVM)
|
|
244
|
+
* @returns Decoded address string
|
|
245
|
+
* @throws {@link CCIPChainFamilyUnsupportedError} if chain family is not supported
|
|
246
|
+
*/
|
|
241
247
|
export function decodeAddress(address: BytesLike, family: ChainFamily = ChainFamily.EVM): string {
|
|
242
248
|
const chain = supportedChains[family]
|
|
243
249
|
if (!chain) throw new CCIPChainFamilyUnsupportedError(family)
|
|
@@ -246,7 +252,11 @@ export function decodeAddress(address: BytesLike, family: ChainFamily = ChainFam
|
|
|
246
252
|
|
|
247
253
|
/**
|
|
248
254
|
* Validate a value is a txHash string in some supported chain family
|
|
249
|
-
|
|
255
|
+
* @param txHash - Value to check
|
|
256
|
+
* @param family - Optional chain family to validate against
|
|
257
|
+
* @returns true if value is a valid transaction hash
|
|
258
|
+
* @throws {@link CCIPChainFamilyUnsupportedError} if specified chain family is not supported
|
|
259
|
+
*/
|
|
250
260
|
export function isSupportedTxHash(txHash: unknown, family?: ChainFamily): txHash is string {
|
|
251
261
|
let chains: ChainStatic[]
|
|
252
262
|
if (!family) chains = Object.values(supportedChains)
|
|
@@ -309,6 +319,7 @@ export function isBase64(data: unknown): data is string {
|
|
|
309
319
|
* Converts various data formats to Uint8Array.
|
|
310
320
|
* @param data - Bytes, number array, or Base64 string.
|
|
311
321
|
* @returns Uint8Array representation.
|
|
322
|
+
* @throws {@link CCIPDataFormatUnsupportedError} if data format is not recognized
|
|
312
323
|
*/
|
|
313
324
|
export function getDataBytes(data: BytesLike | readonly number[]): Uint8Array {
|
|
314
325
|
if (Array.isArray(data)) return new Uint8Array(data)
|
|
@@ -409,7 +420,8 @@ export function convertKeysToCamelCase(
|
|
|
409
420
|
* @param ms - Duration in milliseconds.
|
|
410
421
|
* @returns Promise that resolves after the specified duration.
|
|
411
422
|
*/
|
|
412
|
-
|
|
423
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unref is Node.js-only; browsers return number
|
|
424
|
+
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref?.())
|
|
413
425
|
|
|
414
426
|
/**
|
|
415
427
|
* Configuration for the withRetry utility.
|
|
@@ -518,6 +530,7 @@ export async function withRetry<T>(
|
|
|
518
530
|
* Parses a typeAndVersion string into its components.
|
|
519
531
|
* @param typeAndVersion - String in format "TypeName vX.Y.Z".
|
|
520
532
|
* @returns Tuple of [type, version, original, suffix?].
|
|
533
|
+
* @throws {@link CCIPTypeVersionInvalidError} if string format is invalid
|
|
521
534
|
*/
|
|
522
535
|
export function parseTypeAndVersion(
|
|
523
536
|
typeAndVersion: string,
|