@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.
Files changed (115) hide show
  1. package/README.md +2 -2
  2. package/dist/all-chains.d.ts +23 -0
  3. package/dist/all-chains.d.ts.map +1 -0
  4. package/dist/all-chains.js +24 -0
  5. package/dist/all-chains.js.map +1 -0
  6. package/dist/api/index.d.ts +15 -12
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/index.js +20 -16
  9. package/dist/api/index.js.map +1 -1
  10. package/dist/api/types.d.ts +25 -29
  11. package/dist/api/types.d.ts.map +1 -1
  12. package/dist/aptos/index.d.ts +33 -8
  13. package/dist/aptos/index.d.ts.map +1 -1
  14. package/dist/aptos/index.js +74 -41
  15. package/dist/aptos/index.js.map +1 -1
  16. package/dist/chain.d.ts +220 -41
  17. package/dist/chain.d.ts.map +1 -1
  18. package/dist/chain.js +105 -15
  19. package/dist/chain.js.map +1 -1
  20. package/dist/errors/codes.d.ts +2 -0
  21. package/dist/errors/codes.d.ts.map +1 -1
  22. package/dist/errors/codes.js +2 -0
  23. package/dist/errors/codes.js.map +1 -1
  24. package/dist/errors/index.d.ts +1 -1
  25. package/dist/errors/index.d.ts.map +1 -1
  26. package/dist/errors/index.js +1 -1
  27. package/dist/errors/index.js.map +1 -1
  28. package/dist/errors/recovery.d.ts.map +1 -1
  29. package/dist/errors/recovery.js +2 -0
  30. package/dist/errors/recovery.js.map +1 -1
  31. package/dist/errors/specialized.d.ts +12 -6
  32. package/dist/errors/specialized.d.ts.map +1 -1
  33. package/dist/errors/specialized.js +19 -7
  34. package/dist/errors/specialized.js.map +1 -1
  35. package/dist/evm/extra-args.d.ts +25 -0
  36. package/dist/evm/extra-args.d.ts.map +1 -0
  37. package/dist/evm/extra-args.js +328 -0
  38. package/dist/evm/extra-args.js.map +1 -0
  39. package/dist/evm/gas.d.ts.map +1 -1
  40. package/dist/evm/gas.js +7 -12
  41. package/dist/evm/gas.js.map +1 -1
  42. package/dist/evm/index.d.ts +70 -24
  43. package/dist/evm/index.d.ts.map +1 -1
  44. package/dist/evm/index.js +72 -91
  45. package/dist/evm/index.js.map +1 -1
  46. package/dist/execution.d.ts.map +1 -1
  47. package/dist/execution.js +16 -2
  48. package/dist/execution.js.map +1 -1
  49. package/dist/extra-args.d.ts +103 -4
  50. package/dist/extra-args.d.ts.map +1 -1
  51. package/dist/extra-args.js +28 -3
  52. package/dist/extra-args.js.map +1 -1
  53. package/dist/gas.d.ts +6 -3
  54. package/dist/gas.d.ts.map +1 -1
  55. package/dist/gas.js +14 -6
  56. package/dist/gas.js.map +1 -1
  57. package/dist/index.d.ts +10 -9
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +8 -8
  60. package/dist/index.js.map +1 -1
  61. package/dist/requests.d.ts +17 -9
  62. package/dist/requests.d.ts.map +1 -1
  63. package/dist/requests.js +17 -9
  64. package/dist/requests.js.map +1 -1
  65. package/dist/selectors.d.ts.map +1 -1
  66. package/dist/selectors.js +12 -0
  67. package/dist/selectors.js.map +1 -1
  68. package/dist/solana/index.d.ts +70 -15
  69. package/dist/solana/index.d.ts.map +1 -1
  70. package/dist/solana/index.js +72 -16
  71. package/dist/solana/index.js.map +1 -1
  72. package/dist/sui/index.d.ts +37 -9
  73. package/dist/sui/index.d.ts.map +1 -1
  74. package/dist/sui/index.js +40 -11
  75. package/dist/sui/index.js.map +1 -1
  76. package/dist/ton/index.d.ts +65 -19
  77. package/dist/ton/index.d.ts.map +1 -1
  78. package/dist/ton/index.js +155 -25
  79. package/dist/ton/index.js.map +1 -1
  80. package/dist/ton/send.d.ts +52 -0
  81. package/dist/ton/send.d.ts.map +1 -0
  82. package/dist/ton/send.js +166 -0
  83. package/dist/ton/send.js.map +1 -0
  84. package/dist/types.d.ts +102 -1
  85. package/dist/types.d.ts.map +1 -1
  86. package/dist/types.js.map +1 -1
  87. package/dist/utils.d.ts +15 -3
  88. package/dist/utils.d.ts.map +1 -1
  89. package/dist/utils.js +19 -6
  90. package/dist/utils.js.map +1 -1
  91. package/package.json +12 -7
  92. package/src/all-chains.ts +26 -0
  93. package/src/api/index.ts +26 -25
  94. package/src/api/types.ts +25 -30
  95. package/src/aptos/index.ts +79 -43
  96. package/src/chain.ts +274 -46
  97. package/src/errors/codes.ts +2 -0
  98. package/src/errors/index.ts +1 -1
  99. package/src/errors/recovery.ts +2 -0
  100. package/src/errors/specialized.ts +24 -7
  101. package/src/evm/extra-args.ts +377 -0
  102. package/src/evm/gas.ts +14 -13
  103. package/src/evm/index.ts +76 -125
  104. package/src/execution.ts +18 -2
  105. package/src/extra-args.ts +108 -4
  106. package/src/gas.ts +16 -9
  107. package/src/index.ts +12 -9
  108. package/src/requests.ts +17 -9
  109. package/src/selectors.ts +12 -0
  110. package/src/solana/index.ts +72 -16
  111. package/src/sui/index.ts +40 -11
  112. package/src/ton/index.ts +192 -27
  113. package/src/ton/send.ts +222 -0
  114. package/src/types.ts +103 -1
  115. 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 [[AnyMessage]], which populates default fields like `extraArgs` if needed
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
- * Checks if a chain is a testnet
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
- export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref())
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,