@chainlink/ccip-sdk 0.95.0 → 0.97.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 (217) 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 +31 -19
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/index.js +46 -25
  9. package/dist/api/index.js.map +1 -1
  10. package/dist/api/types.d.ts +24 -30
  11. package/dist/api/types.d.ts.map +1 -1
  12. package/dist/aptos/exec.d.ts +2 -2
  13. package/dist/aptos/exec.d.ts.map +1 -1
  14. package/dist/aptos/exec.js.map +1 -1
  15. package/dist/aptos/hasher.d.ts.map +1 -1
  16. package/dist/aptos/hasher.js +1 -1
  17. package/dist/aptos/hasher.js.map +1 -1
  18. package/dist/aptos/index.d.ts +43 -15
  19. package/dist/aptos/index.d.ts.map +1 -1
  20. package/dist/aptos/index.js +112 -105
  21. package/dist/aptos/index.js.map +1 -1
  22. package/dist/aptos/types.d.ts +2 -19
  23. package/dist/aptos/types.d.ts.map +1 -1
  24. package/dist/aptos/types.js +0 -11
  25. package/dist/aptos/types.js.map +1 -1
  26. package/dist/chain.d.ts +734 -174
  27. package/dist/chain.d.ts.map +1 -1
  28. package/dist/chain.js +216 -31
  29. package/dist/chain.js.map +1 -1
  30. package/dist/commits.d.ts +4 -6
  31. package/dist/commits.d.ts.map +1 -1
  32. package/dist/commits.js +4 -4
  33. package/dist/commits.js.map +1 -1
  34. package/dist/errors/CCIPError.d.ts +33 -4
  35. package/dist/errors/CCIPError.d.ts.map +1 -1
  36. package/dist/errors/CCIPError.js +33 -4
  37. package/dist/errors/CCIPError.js.map +1 -1
  38. package/dist/errors/codes.d.ts +5 -0
  39. package/dist/errors/codes.d.ts.map +1 -1
  40. package/dist/errors/codes.js +5 -1
  41. package/dist/errors/codes.js.map +1 -1
  42. package/dist/errors/index.d.ts +2 -2
  43. package/dist/errors/index.d.ts.map +1 -1
  44. package/dist/errors/index.js +2 -2
  45. package/dist/errors/index.js.map +1 -1
  46. package/dist/errors/recovery.d.ts.map +1 -1
  47. package/dist/errors/recovery.js +6 -1
  48. package/dist/errors/recovery.js.map +1 -1
  49. package/dist/errors/specialized.d.ts +1702 -121
  50. package/dist/errors/specialized.d.ts.map +1 -1
  51. package/dist/errors/specialized.js +1729 -125
  52. package/dist/errors/specialized.js.map +1 -1
  53. package/dist/errors/utils.d.ts.map +1 -1
  54. package/dist/errors/utils.js +0 -1
  55. package/dist/errors/utils.js.map +1 -1
  56. package/dist/evm/abi/OffRamp_2_0.d.ts +764 -0
  57. package/dist/evm/abi/OffRamp_2_0.d.ts.map +1 -0
  58. package/dist/evm/abi/OffRamp_2_0.js +744 -0
  59. package/dist/evm/abi/OffRamp_2_0.js.map +1 -0
  60. package/dist/evm/abi/OnRamp_2_0.d.ts +925 -0
  61. package/dist/evm/abi/OnRamp_2_0.d.ts.map +1 -0
  62. package/dist/evm/abi/OnRamp_2_0.js +992 -0
  63. package/dist/evm/abi/OnRamp_2_0.js.map +1 -0
  64. package/dist/evm/const.d.ts +12 -2
  65. package/dist/evm/const.d.ts.map +1 -1
  66. package/dist/evm/const.js +8 -2
  67. package/dist/evm/const.js.map +1 -1
  68. package/dist/evm/errors.d.ts.map +1 -1
  69. package/dist/evm/errors.js +7 -2
  70. package/dist/evm/errors.js.map +1 -1
  71. package/dist/evm/extra-args.d.ts +25 -0
  72. package/dist/evm/extra-args.d.ts.map +1 -0
  73. package/dist/evm/extra-args.js +309 -0
  74. package/dist/evm/extra-args.js.map +1 -0
  75. package/dist/evm/gas.d.ts.map +1 -1
  76. package/dist/evm/gas.js +7 -12
  77. package/dist/evm/gas.js.map +1 -1
  78. package/dist/evm/hasher.d.ts.map +1 -1
  79. package/dist/evm/hasher.js +23 -13
  80. package/dist/evm/hasher.js.map +1 -1
  81. package/dist/evm/index.d.ts +140 -35
  82. package/dist/evm/index.d.ts.map +1 -1
  83. package/dist/evm/index.js +306 -226
  84. package/dist/evm/index.js.map +1 -1
  85. package/dist/evm/messages.d.ts +59 -5
  86. package/dist/evm/messages.d.ts.map +1 -1
  87. package/dist/evm/messages.js +210 -0
  88. package/dist/evm/messages.js.map +1 -1
  89. package/dist/evm/offchain.js.map +1 -1
  90. package/dist/evm/types.d.ts +7 -2
  91. package/dist/evm/types.d.ts.map +1 -1
  92. package/dist/evm/types.js +22 -1
  93. package/dist/evm/types.js.map +1 -1
  94. package/dist/execution.d.ts +62 -22
  95. package/dist/execution.d.ts.map +1 -1
  96. package/dist/execution.js +102 -51
  97. package/dist/execution.js.map +1 -1
  98. package/dist/extra-args.d.ts +113 -4
  99. package/dist/extra-args.d.ts.map +1 -1
  100. package/dist/extra-args.js +38 -3
  101. package/dist/extra-args.js.map +1 -1
  102. package/dist/gas.d.ts +31 -5
  103. package/dist/gas.d.ts.map +1 -1
  104. package/dist/gas.js +43 -9
  105. package/dist/gas.js.map +1 -1
  106. package/dist/index.d.ts +11 -10
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +8 -8
  109. package/dist/index.js.map +1 -1
  110. package/dist/requests.d.ts +101 -22
  111. package/dist/requests.d.ts.map +1 -1
  112. package/dist/requests.js +115 -24
  113. package/dist/requests.js.map +1 -1
  114. package/dist/selectors.d.ts.map +1 -1
  115. package/dist/selectors.js +24 -0
  116. package/dist/selectors.js.map +1 -1
  117. package/dist/shared/bcs-codecs.d.ts +61 -0
  118. package/dist/shared/bcs-codecs.d.ts.map +1 -0
  119. package/dist/shared/bcs-codecs.js +102 -0
  120. package/dist/shared/bcs-codecs.js.map +1 -0
  121. package/dist/shared/constants.d.ts +3 -0
  122. package/dist/shared/constants.d.ts.map +1 -0
  123. package/dist/shared/constants.js +3 -0
  124. package/dist/shared/constants.js.map +1 -0
  125. package/dist/solana/exec.d.ts +2 -2
  126. package/dist/solana/exec.d.ts.map +1 -1
  127. package/dist/solana/exec.js.map +1 -1
  128. package/dist/solana/index.d.ts +148 -30
  129. package/dist/solana/index.d.ts.map +1 -1
  130. package/dist/solana/index.js +137 -44
  131. package/dist/solana/index.js.map +1 -1
  132. package/dist/sui/hasher.d.ts.map +1 -1
  133. package/dist/sui/hasher.js +1 -1
  134. package/dist/sui/hasher.js.map +1 -1
  135. package/dist/sui/index.d.ts +49 -19
  136. package/dist/sui/index.d.ts.map +1 -1
  137. package/dist/sui/index.js +76 -43
  138. package/dist/sui/index.js.map +1 -1
  139. package/dist/sui/manuallyExec/encoder.d.ts +2 -2
  140. package/dist/sui/manuallyExec/encoder.d.ts.map +1 -1
  141. package/dist/sui/manuallyExec/encoder.js.map +1 -1
  142. package/dist/sui/manuallyExec/index.d.ts +2 -2
  143. package/dist/sui/manuallyExec/index.d.ts.map +1 -1
  144. package/dist/ton/exec.d.ts +2 -2
  145. package/dist/ton/exec.d.ts.map +1 -1
  146. package/dist/ton/exec.js.map +1 -1
  147. package/dist/ton/index.d.ts +66 -27
  148. package/dist/ton/index.d.ts.map +1 -1
  149. package/dist/ton/index.js +172 -47
  150. package/dist/ton/index.js.map +1 -1
  151. package/dist/ton/send.d.ts +52 -0
  152. package/dist/ton/send.d.ts.map +1 -0
  153. package/dist/ton/send.js +166 -0
  154. package/dist/ton/send.js.map +1 -0
  155. package/dist/ton/types.d.ts +2 -2
  156. package/dist/ton/types.d.ts.map +1 -1
  157. package/dist/ton/types.js.map +1 -1
  158. package/dist/types.d.ts +148 -12
  159. package/dist/types.d.ts.map +1 -1
  160. package/dist/types.js +6 -1
  161. package/dist/types.js.map +1 -1
  162. package/dist/utils.d.ts +79 -4
  163. package/dist/utils.d.ts.map +1 -1
  164. package/dist/utils.js +92 -7
  165. package/dist/utils.js.map +1 -1
  166. package/package.json +16 -11
  167. package/src/all-chains.ts +26 -0
  168. package/src/api/index.ts +58 -34
  169. package/src/api/types.ts +24 -31
  170. package/src/aptos/exec.ts +2 -2
  171. package/src/aptos/hasher.ts +1 -1
  172. package/src/aptos/index.ts +127 -129
  173. package/src/aptos/types.ts +2 -15
  174. package/src/chain.ts +837 -191
  175. package/src/commits.ts +9 -9
  176. package/src/errors/CCIPError.ts +33 -4
  177. package/src/errors/codes.ts +5 -1
  178. package/src/errors/index.ts +2 -1
  179. package/src/errors/recovery.ts +9 -1
  180. package/src/errors/specialized.ts +1745 -132
  181. package/src/errors/utils.ts +0 -1
  182. package/src/evm/abi/OffRamp_2_0.ts +743 -0
  183. package/src/evm/abi/OnRamp_2_0.ts +991 -0
  184. package/src/evm/const.ts +10 -3
  185. package/src/evm/errors.ts +6 -2
  186. package/src/evm/extra-args.ts +360 -0
  187. package/src/evm/gas.ts +14 -13
  188. package/src/evm/hasher.ts +30 -18
  189. package/src/evm/index.ts +376 -281
  190. package/src/evm/messages.ts +323 -11
  191. package/src/evm/offchain.ts +2 -2
  192. package/src/evm/types.ts +20 -2
  193. package/src/execution.ts +126 -71
  194. package/src/extra-args.ts +118 -4
  195. package/src/gas.ts +44 -11
  196. package/src/index.ts +14 -11
  197. package/src/requests.ts +128 -24
  198. package/src/selectors.ts +24 -0
  199. package/src/shared/bcs-codecs.ts +132 -0
  200. package/src/shared/constants.ts +2 -0
  201. package/src/solana/exec.ts +4 -4
  202. package/src/solana/index.ts +170 -82
  203. package/src/sui/hasher.ts +1 -1
  204. package/src/sui/index.ts +88 -56
  205. package/src/sui/manuallyExec/encoder.ts +2 -2
  206. package/src/sui/manuallyExec/index.ts +2 -2
  207. package/src/ton/exec.ts +2 -2
  208. package/src/ton/index.ts +220 -58
  209. package/src/ton/send.ts +222 -0
  210. package/src/ton/types.ts +2 -2
  211. package/src/types.ts +173 -30
  212. package/src/utils.ts +91 -7
  213. package/dist/aptos/utils.d.ts +0 -12
  214. package/dist/aptos/utils.d.ts.map +0 -1
  215. package/dist/aptos/utils.js +0 -15
  216. package/dist/aptos/utils.js.map +0 -1
  217. package/src/aptos/utils.ts +0 -24
@@ -1,21 +1,13 @@
1
1
  import {
2
2
  Aptos,
3
+ AptosApiError,
3
4
  AptosConfig,
4
5
  Deserializer,
5
6
  Network,
6
7
  SimpleTransaction,
7
8
  TransactionResponseType,
8
9
  } from '@aptos-labs/ts-sdk'
9
- import {
10
- type BytesLike,
11
- concat,
12
- dataSlice,
13
- getBytes,
14
- hexlify,
15
- isBytesLike,
16
- isHexString,
17
- zeroPadValue,
18
- } from 'ethers'
10
+ import { type BytesLike, concat, isBytesLike, isHexString } from 'ethers'
19
11
  import { memoize } from 'micro-memoize'
20
12
  import type { PickDeep } from 'type-fest'
21
13
 
@@ -27,9 +19,11 @@ import {
27
19
  type TokenPoolRemote,
28
20
  Chain,
29
21
  } from '../chain.ts'
22
+ import { generateUnsignedExecuteReport } from './exec.ts'
23
+ import { getAptosLeafHasher } from './hasher.ts'
24
+ import { getUserTxByVersion, getVersionTimestamp, streamAptosLogs } from './logs.ts'
30
25
  import { generateUnsignedCcipSend, getFee } from './send.ts'
31
26
  import {
32
- CCIPAptosAddressInvalidError,
33
27
  CCIPAptosExtraArgsEncodingError,
34
28
  CCIPAptosExtraArgsV2RequiredError,
35
29
  CCIPAptosLogInvalidError,
@@ -40,6 +34,7 @@ import {
40
34
  CCIPAptosTransactionTypeInvalidError,
41
35
  CCIPAptosWalletInvalidError,
42
36
  CCIPError,
37
+ CCIPTokenPoolChainConfigNotFoundError,
43
38
  } from '../errors/index.ts'
44
39
  import {
45
40
  type EVMExtraArgsV2,
@@ -48,13 +43,14 @@ import {
48
43
  EVMExtraArgsV2Tag,
49
44
  SVMExtraArgsV1Tag,
50
45
  } from '../extra-args.ts'
51
- import {
52
- type UnsignedAptosTx,
53
- EVMExtraArgsV2Codec,
54
- SVMExtraArgsV1Codec,
55
- isAptosAccount,
56
- } from './types.ts'
46
+ import { type UnsignedAptosTx, isAptosAccount } from './types.ts'
57
47
  import type { LeafHasher } from '../hasher/common.ts'
48
+ import {
49
+ BcsEVMExtraArgsV2Codec,
50
+ BcsSVMExtraArgsV1Codec,
51
+ decodeMoveExtraArgs,
52
+ getMoveAddress,
53
+ } from '../shared/bcs-codecs.ts'
58
54
  import { supportedChains } from '../supported-chains.ts'
59
55
  import {
60
56
  type CCIPExecution,
@@ -62,8 +58,8 @@ import {
62
58
  type CCIPRequest,
63
59
  type ChainTransaction,
64
60
  type CommitReport,
61
+ type ExecutionInput,
65
62
  type ExecutionReceipt,
66
- type ExecutionReport,
67
63
  type Lane,
68
64
  type Log_,
69
65
  type NetworkInfo,
@@ -76,14 +72,10 @@ import {
76
72
  decodeAddress,
77
73
  decodeOnRampAddress,
78
74
  getAddressBytes,
79
- getDataBytes,
80
75
  networkInfo,
81
76
  parseTypeAndVersion,
82
77
  util,
83
78
  } from '../utils.ts'
84
- import { generateUnsignedExecuteReport } from './exec.ts'
85
- import { getAptosLeafHasher } from './hasher.ts'
86
- import { getUserTxByVersion, getVersionTimestamp, streamAptosLogs } from './logs.ts'
87
79
  import { getTokenInfo } from './token.ts'
88
80
  import type { CCIPMessage_V1_6_EVM } from '../evm/messages.ts'
89
81
  import { buildMessageForDest, decodeMessage, getMessagesInBatch } from '../requests.ts'
@@ -96,13 +88,18 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
96
88
  static {
97
89
  supportedChains[ChainFamily.Aptos] = AptosChain
98
90
  }
91
+ /** Chain family identifier for Aptos networks. */
99
92
  static readonly family = ChainFamily.Aptos
93
+ /** Native token decimals (8 for APT). */
100
94
  static readonly decimals = 8
101
95
 
102
96
  readonly destroy$: Promise<void>
97
+ /** The Aptos SDK provider for blockchain interactions. */
103
98
  provider: Aptos
104
99
 
100
+ /** Retrieves token information for a given token address. */
105
101
  getTokenInfo: (token: string) => Promise<TokenInfo>
102
+ /** @internal */
106
103
  _getAccountModulesNames: (address: string) => Promise<string[]>
107
104
 
108
105
  /**
@@ -177,6 +174,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
177
174
  * @param url - RPC URL, Aptos Network enum value or [fullNodeUrl, Network] tuple.
178
175
  * @param ctx - context containing logger
179
176
  * @returns A new AptosChain instance.
177
+ * @throws {@link CCIPAptosNetworkUnknownError} if network cannot be determined from URL
180
178
  */
181
179
  static async fromUrl(
182
180
  url: string | Network | readonly [string, Network],
@@ -203,7 +201,11 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
203
201
  return getVersionTimestamp(this.provider, version)
204
202
  }
205
203
 
206
- /** {@inheritDoc Chain.getTransaction} */
204
+ /**
205
+ * {@inheritDoc Chain.getTransaction}
206
+ * @throws {@link CCIPAptosTransactionInvalidError} if hash/version format is invalid
207
+ * @throws {@link CCIPAptosTransactionTypeInvalidError} if transaction is not a user transaction
208
+ */
207
209
  async getTransaction(hashOrVersion: string | number): Promise<ChainTransaction> {
208
210
  let tx
209
211
  if (isHexString(hashOrVersion, 32)) {
@@ -239,17 +241,17 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
239
241
  }
240
242
 
241
243
  /** {@inheritDoc Chain.getMessagesInBatch} */
242
- async getMessagesInBatch<
244
+ override async getMessagesInBatch<
243
245
  R extends PickDeep<
244
246
  CCIPRequest,
245
247
  'lane' | `log.${'topics' | 'address' | 'blockNumber'}` | 'message.sequenceNumber'
246
248
  >,
247
249
  >(
248
250
  request: R,
249
- commit: Pick<CommitReport, 'minSeqNr' | 'maxSeqNr'>,
251
+ range: Pick<CommitReport, 'minSeqNr' | 'maxSeqNr'>,
250
252
  opts?: { page?: number },
251
253
  ): Promise<R['message'][]> {
252
- return getMessagesInBatch(this, request, commit, opts)
254
+ return getMessagesInBatch(this, request, range, opts)
253
255
  }
254
256
 
255
257
  /** {@inheritDoc Chain.typeAndVersion} */
@@ -289,8 +291,8 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
289
291
  return Promise.resolve(router.split('::')[0] + '::onramp')
290
292
  }
291
293
 
292
- /** {@inheritDoc Chain.getOnRampForOffRamp} */
293
- async getOnRampForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise<string> {
294
+ /** {@inheritDoc Chain.getOnRampsForOffRamp} */
295
+ async getOnRampsForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise<string[]> {
294
296
  const [sourceChainConfig] = await this.provider.view<[{ on_ramp: string }]>({
295
297
  payload: {
296
298
  function:
@@ -298,12 +300,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
298
300
  functionArguments: [sourceChainSelector],
299
301
  },
300
302
  })
301
- return decodeAddress(sourceChainConfig.on_ramp, networkInfo(sourceChainSelector).family)
302
- }
303
-
304
- /** {@inheritDoc Chain.getCommitStoreForOffRamp} */
305
- getCommitStoreForOffRamp(offRamp: string): Promise<string> {
306
- return Promise.resolve(offRamp.split('::')[0] + '::offramp')
303
+ return [decodeAddress(sourceChainConfig.on_ramp, networkInfo(sourceChainSelector).family)]
307
304
  }
308
305
 
309
306
  /** {@inheritDoc Chain.getTokenForTokenPool} */
@@ -339,7 +336,10 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
339
336
  return BigInt(balance)
340
337
  }
341
338
 
342
- /** {@inheritDoc Chain.getTokenAdminRegistryFor} */
339
+ /**
340
+ * {@inheritDoc Chain.getTokenAdminRegistryFor}
341
+ * @throws {@link CCIPAptosRegistryTypeInvalidError} if registry type is invalid
342
+ */
343
343
  async getTokenAdminRegistryFor(address: string): Promise<string> {
344
344
  const registry = address.split('::')[0] + '::token_admin_registry'
345
345
  const [type] = await this.typeAndVersion(registry)
@@ -353,6 +353,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
353
353
  * Decodes a CCIP message from an Aptos log event.
354
354
  * @param log - Log with data field.
355
355
  * @returns Decoded CCIPMessage or undefined if not valid.
356
+ * @throws {@link CCIPAptosLogInvalidError} if log data format is invalid
356
357
  */
357
358
  static decodeMessage(log: {
358
359
  data: BytesLike | Record<string, unknown>
@@ -382,47 +383,22 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
382
383
  | (EVMExtraArgsV2 & { _tag: 'EVMExtraArgsV2' })
383
384
  | (SVMExtraArgsV1 & { _tag: 'SVMExtraArgsV1' })
384
385
  | undefined {
385
- const data = getDataBytes(extraArgs),
386
- tag = dataSlice(data, 0, 4)
387
- switch (tag) {
388
- case EVMExtraArgsV2Tag: {
389
- const parsed = EVMExtraArgsV2Codec.parse(getBytes(dataSlice(data, 4)))
390
- // Aptos serialization of EVMExtraArgsV2: 37 bytes total: 4 tag + 32 LE gasLimit + 1 allowOOOE
391
- return {
392
- _tag: 'EVMExtraArgsV2',
393
- ...parsed,
394
- gasLimit: BigInt(parsed.gasLimit),
395
- }
396
- }
397
- case SVMExtraArgsV1Tag: {
398
- const parsed = SVMExtraArgsV1Codec.parse(getBytes(dataSlice(data, 4)))
399
- // Aptos serialization of SVMExtraArgsV1: 13 bytes total: 4 tag + 8 LE computeUnits
400
- return {
401
- _tag: 'SVMExtraArgsV1',
402
- ...parsed,
403
- computeUnits: BigInt(parsed.computeUnits),
404
- accountIsWritableBitmap: BigInt(parsed.accountIsWritableBitmap),
405
- tokenReceiver: decodeAddress(new Uint8Array(parsed.tokenReceiver), ChainFamily.Solana),
406
- accounts: parsed.accounts.map((account) =>
407
- decodeAddress(new Uint8Array(account), ChainFamily.Solana),
408
- ),
409
- }
410
- }
411
- }
386
+ return decodeMoveExtraArgs(extraArgs)
412
387
  }
413
388
 
414
389
  /**
415
390
  * Encodes extra arguments for Aptos CCIP messages.
416
391
  * @param extraArgs - Extra arguments to encode.
417
392
  * @returns Encoded extra arguments as hex string.
393
+ * @throws {@link CCIPAptosExtraArgsEncodingError} if extra args format is not supported
418
394
  */
419
395
  static encodeExtraArgs(extraArgs: ExtraArgs): string {
420
396
  if ('gasLimit' in extraArgs && 'allowOutOfOrderExecution' in extraArgs)
421
- return concat([EVMExtraArgsV2Tag, EVMExtraArgsV2Codec.serialize(extraArgs).toBytes()])
397
+ return concat([EVMExtraArgsV2Tag, BcsEVMExtraArgsV2Codec.serialize(extraArgs).toBytes()])
422
398
  else if ('computeUnits' in extraArgs)
423
399
  return concat([
424
400
  SVMExtraArgsV1Tag,
425
- SVMExtraArgsV1Codec.serialize({
401
+ BcsSVMExtraArgsV1Codec.serialize({
426
402
  ...extraArgs,
427
403
  computeUnits: Number(extraArgs.computeUnits),
428
404
  tokenReceiver: getAddressBytes(extraArgs.tokenReceiver),
@@ -437,6 +413,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
437
413
  * @param log - Log with data field.
438
414
  * @param lane - Lane info for filtering.
439
415
  * @returns Array of CommitReport or undefined if not valid.
416
+ * @throws {@link CCIPAptosLogInvalidError} if log data format is invalid
440
417
  */
441
418
  static decodeCommits({ data }: Pick<Log_, 'data'>, lane?: Lane): CommitReport[] | undefined {
442
419
  if (!data || typeof data != 'object') throw new CCIPAptosLogInvalidError(data)
@@ -470,6 +447,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
470
447
  * Decodes an execution receipt from an Aptos log event.
471
448
  * @param log - Log with data field.
472
449
  * @returns ExecutionReceipt or undefined if not valid.
450
+ * @throws {@link CCIPAptosLogInvalidError} if log data format is invalid
473
451
  */
474
452
  static decodeReceipt({ data }: Pick<Log_, 'data'>): ExecutionReceipt | undefined {
475
453
  if (!data || typeof data != 'object') throw new CCIPAptosLogInvalidError(data)
@@ -484,20 +462,10 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
484
462
  * Converts bytes to an Aptos address.
485
463
  * @param bytes - Bytes to convert.
486
464
  * @returns Aptos address (0x-prefixed hex, 32 bytes padded).
465
+ * @throws {@link CCIPDataFormatUnsupportedError} if bytes length exceeds 32
487
466
  */
488
467
  static getAddress(bytes: BytesLike | readonly number[]): string {
489
- let suffix = ''
490
- if (Array.isArray(bytes)) bytes = new Uint8Array(bytes)
491
- if (typeof bytes === 'string' && bytes.startsWith('0x')) {
492
- const idx = bytes.indexOf('::')
493
- if (idx > 0) {
494
- suffix = bytes.slice(idx)
495
- bytes = bytes.slice(0, idx)
496
- }
497
- }
498
- bytes = getDataBytes(bytes)
499
- if (bytes.length > 32) throw new CCIPAptosAddressInvalidError(hexlify(bytes))
500
- return zeroPadValue(bytes, 32) + suffix
468
+ return getMoveAddress(bytes)
501
469
  }
502
470
 
503
471
  /**
@@ -553,7 +521,10 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
553
521
  }
554
522
  }
555
523
 
556
- /** {@inheritDoc Chain.sendMessage} */
524
+ /**
525
+ * {@inheritDoc Chain.sendMessage}
526
+ * @throws {@link CCIPAptosWalletInvalidError} if wallet is not a valid Aptos account
527
+ */
557
528
  async sendMessage(opts: Parameters<Chain['sendMessage']>[0]): Promise<CCIPRequest> {
558
529
  const account = opts.wallet
559
530
  if (!isAptosAccount(account)) {
@@ -588,22 +559,30 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
588
559
  return Promise.resolve(request.message.tokenAmounts.map(() => undefined))
589
560
  }
590
561
 
591
- /** {@inheritDoc Chain.generateUnsignedExecuteReport} */
592
- async generateUnsignedExecuteReport({
562
+ /**
563
+ * {@inheritDoc Chain.generateUnsignedExecute}
564
+ * @throws {@link CCIPAptosExtraArgsV2RequiredError} if message missing EVMExtraArgsV2 fields
565
+ */
566
+ async generateUnsignedExecute({
593
567
  payer,
594
- offRamp,
595
- execReport,
596
568
  ...opts
597
- }: Parameters<Chain['generateUnsignedExecuteReport']>[0]): Promise<UnsignedAptosTx> {
598
- if (!('allowOutOfOrderExecution' in execReport.message && 'gasLimit' in execReport.message)) {
569
+ }: Parameters<Chain['generateUnsignedExecute']>[0]): Promise<UnsignedAptosTx> {
570
+ if (
571
+ !(
572
+ 'input' in opts &&
573
+ 'message' in opts.input &&
574
+ 'allowOutOfOrderExecution' in opts.input.message &&
575
+ 'gasLimit' in opts.input.message
576
+ )
577
+ ) {
599
578
  throw new CCIPAptosExtraArgsV2RequiredError()
600
579
  }
601
580
 
602
581
  const tx = await generateUnsignedExecuteReport(
603
582
  this.provider,
604
583
  payer,
605
- offRamp,
606
- execReport as ExecutionReport<CCIPMessage_V1_6_EVM>,
584
+ opts.offRamp,
585
+ opts.input as ExecutionInput<CCIPMessage_V1_6_EVM>,
607
586
  opts,
608
587
  )
609
588
  return {
@@ -612,14 +591,17 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
612
591
  }
613
592
  }
614
593
 
615
- /** {@inheritDoc Chain.executeReport} */
616
- async executeReport(opts: Parameters<Chain['executeReport']>[0]): Promise<CCIPExecution> {
594
+ /**
595
+ * {@inheritDoc Chain.execute}
596
+ * @throws {@link CCIPAptosWalletInvalidError} if wallet is not a valid Aptos account
597
+ */
598
+ async execute(opts: Parameters<Chain['execute']>[0]): Promise<CCIPExecution> {
617
599
  const account = opts.wallet
618
600
  if (!isAptosAccount(account)) {
619
601
  throw new CCIPAptosWalletInvalidError(this.constructor.name, util.inspect(opts.wallet))
620
602
  }
621
603
 
622
- const unsignedTx = await this.generateUnsignedExecuteReport({
604
+ const unsignedTx = await this.generateUnsignedExecute({
623
605
  ...opts,
624
606
  payer: account.accountAddress.toString(),
625
607
  })
@@ -646,9 +628,13 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
646
628
  * @returns Parsed data or undefined.
647
629
  */
648
630
  static parse(data: unknown) {
649
- if (isBytesLike(data)) {
650
- const parsedExtraArgs = this.decodeExtraArgs(data)
651
- if (parsedExtraArgs) return parsedExtraArgs
631
+ try {
632
+ if (isBytesLike(data)) {
633
+ const parsedExtraArgs = this.decodeExtraArgs(data)
634
+ if (parsedExtraArgs) return parsedExtraArgs
635
+ }
636
+ } catch {
637
+ // ignore
652
638
  }
653
639
  }
654
640
 
@@ -671,7 +657,10 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
671
657
  return page
672
658
  }
673
659
 
674
- /** {@inheritDoc Chain.getRegistryTokenConfig} */
660
+ /**
661
+ * {@inheritDoc Chain.getRegistryTokenConfig}
662
+ * @throws {@link CCIPAptosTokenNotRegisteredError} if token is not registered
663
+ */
675
664
  async getRegistryTokenConfig(
676
665
  registry: string,
677
666
  token: string,
@@ -697,8 +686,8 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
697
686
  }
698
687
  }
699
688
 
700
- /** {@inheritDoc Chain.getTokenPoolConfigs} */
701
- async getTokenPoolConfigs(tokenPool: string): Promise<{
689
+ /** {@inheritDoc Chain.getTokenPoolConfig} */
690
+ async getTokenPoolConfig(tokenPool: string): Promise<{
702
691
  token: string
703
692
  router: string
704
693
  typeAndVersion?: string
@@ -749,8 +738,8 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
749
738
  tokens: string
750
739
  }
751
740
  const modulesNames = (await this._getAccountModulesNames(tokenPool))
752
- .reverse()
753
741
  .filter((name) => name.endsWith('token_pool'))
742
+ .sort((a, b) => b.length - a.length)
754
743
  let firstErr
755
744
  for (const name of modulesNames) {
756
745
  try {
@@ -789,40 +778,49 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
789
778
  functionArguments: [chain.chainSelector],
790
779
  },
791
780
  })
792
- const [
793
- [remoteToken],
794
- [remotePools],
795
- [inboundRateLimiterState],
796
- [outboundRateLimiterState],
797
- ] = await Promise.all([
798
- remoteToken$,
799
- remotePools$,
800
- inboundRateLimiterState$,
801
- outboundRateLimiterState$,
802
- ])
803
- return [
804
- chain.name,
805
- {
806
- remoteToken: decodeAddress(remoteToken, chain.family),
807
- remotePools: remotePools.map((pool) => decodeAddress(pool, chain.family)),
808
- inboundRateLimiterState: inboundRateLimiterState.is_enabled
809
- ? {
810
- capacity: BigInt(inboundRateLimiterState.capacity),
811
- lastUpdated: Number(inboundRateLimiterState.last_updated),
812
- rate: BigInt(inboundRateLimiterState.rate),
813
- tokens: BigInt(inboundRateLimiterState.tokens),
814
- }
815
- : null,
816
- outboundRateLimiterState: outboundRateLimiterState.is_enabled
817
- ? {
818
- capacity: BigInt(outboundRateLimiterState.capacity),
819
- lastUpdated: Number(outboundRateLimiterState.last_updated),
820
- rate: BigInt(outboundRateLimiterState.rate),
821
- tokens: BigInt(outboundRateLimiterState.tokens),
822
- }
823
- : null,
824
- },
825
- ] as const
781
+ try {
782
+ const [
783
+ [remoteToken],
784
+ [remotePools],
785
+ [inboundRateLimiterState],
786
+ [outboundRateLimiterState],
787
+ ] = await Promise.all([
788
+ remoteToken$,
789
+ remotePools$,
790
+ inboundRateLimiterState$,
791
+ outboundRateLimiterState$,
792
+ ])
793
+ return [
794
+ chain.name,
795
+ {
796
+ remoteToken: decodeAddress(remoteToken, chain.family),
797
+ remotePools: remotePools.map((pool) => decodeAddress(pool, chain.family)),
798
+ inboundRateLimiterState: inboundRateLimiterState.is_enabled
799
+ ? {
800
+ capacity: BigInt(inboundRateLimiterState.capacity),
801
+ lastUpdated: Number(inboundRateLimiterState.last_updated),
802
+ rate: BigInt(inboundRateLimiterState.rate),
803
+ tokens: BigInt(inboundRateLimiterState.tokens),
804
+ }
805
+ : null,
806
+ outboundRateLimiterState: outboundRateLimiterState.is_enabled
807
+ ? {
808
+ capacity: BigInt(outboundRateLimiterState.capacity),
809
+ lastUpdated: Number(outboundRateLimiterState.last_updated),
810
+ rate: BigInt(outboundRateLimiterState.rate),
811
+ tokens: BigInt(outboundRateLimiterState.tokens),
812
+ }
813
+ : null,
814
+ },
815
+ ] as const
816
+ } catch (err) {
817
+ if (
818
+ err instanceof AptosApiError &&
819
+ err.message.includes('Key not found in the smart table')
820
+ )
821
+ throw new CCIPTokenPoolChainConfigNotFoundError(tokenPool, tokenPool, chain.name)
822
+ throw err
823
+ }
826
824
  }),
827
825
  ),
828
826
  )
@@ -8,7 +8,7 @@ import { bcs } from '@mysten/bcs'
8
8
  import { getBytes } from 'ethers'
9
9
 
10
10
  import type { CCIPMessage_V1_6_EVM } from '../evm/messages.ts'
11
- import type { ChainFamily, ExecutionReport } from '../types.ts'
11
+ import type { ChainFamily, ExecutionInput } from '../types.ts'
12
12
  import { getAddressBytes } from '../utils.ts'
13
13
 
14
14
  /** Aptos account type with async transaction signing capability. */
@@ -31,19 +31,6 @@ export function isAptosAccount(account: unknown): account is AptosAsyncAccount {
31
31
  )
32
32
  }
33
33
 
34
- export const EVMExtraArgsV2Codec = bcs.struct('EVMExtraArgsV2', {
35
- gasLimit: bcs.u256(),
36
- allowOutOfOrderExecution: bcs.bool(),
37
- })
38
-
39
- export const SVMExtraArgsV1Codec = bcs.struct('SVMExtraArgsV1', {
40
- computeUnits: bcs.u32(),
41
- accountIsWritableBitmap: bcs.u64(),
42
- allowOutOfOrderExecution: bcs.bool(),
43
- tokenReceiver: bcs.vector(bcs.u8()),
44
- accounts: bcs.vector(bcs.vector(bcs.u8())),
45
- })
46
-
47
34
  export const ExecutionReportCodec = bcs.struct('ExecutionReport', {
48
35
  sourceChainSelector: bcs.u64(),
49
36
  messageId: bcs.fixedArray(32, bcs.u8()),
@@ -74,7 +61,7 @@ export const ExecutionReportCodec = bcs.struct('ExecutionReport', {
74
61
  * @returns BCS-encoded bytes.
75
62
  */
76
63
  export function serializeExecutionReport(
77
- execReport: ExecutionReport<CCIPMessage_V1_6_EVM>,
64
+ execReport: ExecutionInput<CCIPMessage_V1_6_EVM>,
78
65
  ): Uint8Array {
79
66
  const message = execReport.message
80
67
  return ExecutionReportCodec.serialize({