@chainlink/ccip-sdk 0.90.2 → 0.91.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 (202) hide show
  1. package/README.md +35 -26
  2. package/dist/aptos/exec.d.ts +4 -5
  3. package/dist/aptos/exec.d.ts.map +1 -1
  4. package/dist/aptos/exec.js +5 -14
  5. package/dist/aptos/exec.js.map +1 -1
  6. package/dist/aptos/hasher.d.ts +18 -0
  7. package/dist/aptos/hasher.d.ts.map +1 -1
  8. package/dist/aptos/hasher.js +18 -0
  9. package/dist/aptos/hasher.js.map +1 -1
  10. package/dist/aptos/index.d.ts +127 -28
  11. package/dist/aptos/index.d.ts.map +1 -1
  12. package/dist/aptos/index.js +199 -70
  13. package/dist/aptos/index.js.map +1 -1
  14. package/dist/aptos/logs.d.ts +18 -0
  15. package/dist/aptos/logs.d.ts.map +1 -1
  16. package/dist/aptos/logs.js +21 -3
  17. package/dist/aptos/logs.js.map +1 -1
  18. package/dist/aptos/send.d.ts +22 -5
  19. package/dist/aptos/send.d.ts.map +1 -1
  20. package/dist/aptos/send.js +23 -15
  21. package/dist/aptos/send.js.map +1 -1
  22. package/dist/aptos/token.d.ts +6 -0
  23. package/dist/aptos/token.d.ts.map +1 -1
  24. package/dist/aptos/token.js +6 -0
  25. package/dist/aptos/token.js.map +1 -1
  26. package/dist/aptos/types.d.ts +16 -1
  27. package/dist/aptos/types.d.ts.map +1 -1
  28. package/dist/aptos/types.js +13 -0
  29. package/dist/aptos/types.js.map +1 -1
  30. package/dist/aptos/utils.d.ts +1 -1
  31. package/dist/aptos/utils.js +1 -1
  32. package/dist/chain.d.ts +185 -99
  33. package/dist/chain.d.ts.map +1 -1
  34. package/dist/chain.js +38 -15
  35. package/dist/chain.js.map +1 -1
  36. package/dist/commits.d.ts +4 -10
  37. package/dist/commits.d.ts.map +1 -1
  38. package/dist/commits.js +2 -1
  39. package/dist/commits.js.map +1 -1
  40. package/dist/evm/const.d.ts +5 -0
  41. package/dist/evm/const.d.ts.map +1 -1
  42. package/dist/evm/const.js +5 -0
  43. package/dist/evm/const.js.map +1 -1
  44. package/dist/evm/errors.d.ts +5 -0
  45. package/dist/evm/errors.d.ts.map +1 -1
  46. package/dist/evm/errors.js +6 -1
  47. package/dist/evm/errors.js.map +1 -1
  48. package/dist/evm/hasher.d.ts +16 -2
  49. package/dist/evm/hasher.d.ts.map +1 -1
  50. package/dist/evm/hasher.js +17 -3
  51. package/dist/evm/hasher.js.map +1 -1
  52. package/dist/evm/index.d.ts +176 -31
  53. package/dist/evm/index.d.ts.map +1 -1
  54. package/dist/evm/index.js +312 -154
  55. package/dist/evm/index.js.map +1 -1
  56. package/dist/evm/logs.d.ts +20 -0
  57. package/dist/evm/logs.d.ts.map +1 -0
  58. package/dist/evm/logs.js +194 -0
  59. package/dist/evm/logs.js.map +1 -0
  60. package/dist/evm/messages.d.ts +11 -2
  61. package/dist/evm/messages.d.ts.map +1 -1
  62. package/dist/evm/messages.js +4 -2
  63. package/dist/evm/messages.js.map +1 -1
  64. package/dist/evm/offchain.d.ts +7 -2
  65. package/dist/evm/offchain.d.ts.map +1 -1
  66. package/dist/evm/offchain.js +12 -7
  67. package/dist/evm/offchain.js.map +1 -1
  68. package/dist/execution.d.ts +19 -62
  69. package/dist/execution.d.ts.map +1 -1
  70. package/dist/execution.js +28 -31
  71. package/dist/execution.js.map +1 -1
  72. package/dist/extra-args.d.ts +35 -5
  73. package/dist/extra-args.d.ts.map +1 -1
  74. package/dist/extra-args.js +10 -5
  75. package/dist/extra-args.js.map +1 -1
  76. package/dist/gas.d.ts +6 -8
  77. package/dist/gas.d.ts.map +1 -1
  78. package/dist/gas.js +7 -9
  79. package/dist/gas.js.map +1 -1
  80. package/dist/hasher/common.d.ts +3 -2
  81. package/dist/hasher/common.d.ts.map +1 -1
  82. package/dist/hasher/common.js +2 -2
  83. package/dist/hasher/common.js.map +1 -1
  84. package/dist/hasher/hasher.d.ts +8 -2
  85. package/dist/hasher/hasher.d.ts.map +1 -1
  86. package/dist/hasher/hasher.js +8 -3
  87. package/dist/hasher/hasher.js.map +1 -1
  88. package/dist/hasher/merklemulti.d.ts +11 -9
  89. package/dist/hasher/merklemulti.d.ts.map +1 -1
  90. package/dist/hasher/merklemulti.js +17 -16
  91. package/dist/hasher/merklemulti.js.map +1 -1
  92. package/dist/index.d.ts +16 -8
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +17 -7
  95. package/dist/index.js.map +1 -1
  96. package/dist/requests.d.ts +39 -25
  97. package/dist/requests.d.ts.map +1 -1
  98. package/dist/requests.js +42 -35
  99. package/dist/requests.js.map +1 -1
  100. package/dist/selectors.d.ts +1 -1
  101. package/dist/solana/cleanup.d.ts +14 -10
  102. package/dist/solana/cleanup.d.ts.map +1 -1
  103. package/dist/solana/cleanup.js +35 -33
  104. package/dist/solana/cleanup.js.map +1 -1
  105. package/dist/solana/exec.d.ts +19 -11
  106. package/dist/solana/exec.d.ts.map +1 -1
  107. package/dist/solana/exec.js +86 -163
  108. package/dist/solana/exec.js.map +1 -1
  109. package/dist/solana/hasher.d.ts +7 -2
  110. package/dist/solana/hasher.d.ts.map +1 -1
  111. package/dist/solana/hasher.js +7 -2
  112. package/dist/solana/hasher.js.map +1 -1
  113. package/dist/solana/index.d.ts +202 -84
  114. package/dist/solana/index.d.ts.map +1 -1
  115. package/dist/solana/index.js +367 -252
  116. package/dist/solana/index.js.map +1 -1
  117. package/dist/solana/offchain.d.ts +8 -18
  118. package/dist/solana/offchain.d.ts.map +1 -1
  119. package/dist/solana/offchain.js +29 -83
  120. package/dist/solana/offchain.js.map +1 -1
  121. package/dist/solana/patchBorsh.d.ts +5 -1
  122. package/dist/solana/patchBorsh.d.ts.map +1 -1
  123. package/dist/solana/patchBorsh.js +57 -46
  124. package/dist/solana/patchBorsh.js.map +1 -1
  125. package/dist/solana/send.d.ts +28 -10
  126. package/dist/solana/send.d.ts.map +1 -1
  127. package/dist/solana/send.js +44 -77
  128. package/dist/solana/send.js.map +1 -1
  129. package/dist/solana/types.d.ts +22 -1
  130. package/dist/solana/types.d.ts.map +1 -1
  131. package/dist/solana/types.js +12 -1
  132. package/dist/solana/types.js.map +1 -1
  133. package/dist/solana/utils.d.ts +58 -4
  134. package/dist/solana/utils.d.ts.map +1 -1
  135. package/dist/solana/utils.js +110 -7
  136. package/dist/solana/utils.js.map +1 -1
  137. package/dist/sui/hasher.d.ts +18 -0
  138. package/dist/sui/hasher.d.ts.map +1 -1
  139. package/dist/sui/hasher.js +18 -0
  140. package/dist/sui/hasher.js.map +1 -1
  141. package/dist/sui/index.d.ts +99 -12
  142. package/dist/sui/index.d.ts.map +1 -1
  143. package/dist/sui/index.js +108 -19
  144. package/dist/sui/index.js.map +1 -1
  145. package/dist/sui/types.d.ts +6 -0
  146. package/dist/sui/types.d.ts.map +1 -1
  147. package/dist/sui/types.js +5 -0
  148. package/dist/sui/types.js.map +1 -1
  149. package/dist/supported-chains.d.ts +2 -1
  150. package/dist/supported-chains.d.ts.map +1 -1
  151. package/dist/supported-chains.js.map +1 -1
  152. package/dist/types.d.ts +127 -16
  153. package/dist/types.d.ts.map +1 -1
  154. package/dist/types.js +18 -0
  155. package/dist/types.js.map +1 -1
  156. package/dist/utils.d.ts +67 -46
  157. package/dist/utils.d.ts.map +1 -1
  158. package/dist/utils.js +143 -21
  159. package/dist/utils.js.map +1 -1
  160. package/package.json +13 -9
  161. package/src/aptos/exec.ts +7 -18
  162. package/src/aptos/hasher.ts +18 -0
  163. package/src/aptos/index.ts +288 -110
  164. package/src/aptos/logs.ts +21 -3
  165. package/src/aptos/send.ts +25 -22
  166. package/src/aptos/token.ts +6 -0
  167. package/src/aptos/types.ts +26 -2
  168. package/src/aptos/utils.ts +1 -1
  169. package/src/chain.ts +243 -108
  170. package/src/commits.ts +6 -7
  171. package/src/evm/const.ts +5 -0
  172. package/src/evm/errors.ts +6 -1
  173. package/src/evm/hasher.ts +20 -4
  174. package/src/evm/index.ts +416 -214
  175. package/src/evm/logs.ts +255 -0
  176. package/src/evm/messages.ts +11 -5
  177. package/src/evm/offchain.ts +13 -4
  178. package/src/execution.ts +40 -32
  179. package/src/extra-args.ts +38 -6
  180. package/src/gas.ts +7 -9
  181. package/src/hasher/common.ts +3 -2
  182. package/src/hasher/hasher.ts +12 -4
  183. package/src/hasher/merklemulti.ts +17 -16
  184. package/src/index.ts +29 -23
  185. package/src/requests.ts +64 -46
  186. package/src/selectors.ts +1 -1
  187. package/src/solana/cleanup.ts +49 -34
  188. package/src/solana/exec.ts +128 -272
  189. package/src/solana/hasher.ts +13 -4
  190. package/src/solana/index.ts +483 -356
  191. package/src/solana/offchain.ts +32 -102
  192. package/src/solana/patchBorsh.ts +65 -50
  193. package/src/solana/send.ts +52 -111
  194. package/src/solana/types.ts +44 -3
  195. package/src/solana/utils.ts +143 -19
  196. package/src/sui/hasher.ts +18 -0
  197. package/src/sui/index.ts +143 -31
  198. package/src/sui/types.ts +6 -0
  199. package/src/supported-chains.ts +2 -1
  200. package/src/types.ts +130 -18
  201. package/src/utils.ts +168 -26
  202. package/tsconfig.json +2 -1
package/src/aptos/logs.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  TransactionResponseType,
6
6
  getAptosFullNode,
7
7
  } from '@aptos-labs/ts-sdk'
8
- import moize from 'moize'
8
+ import { memoize } from 'micro-memoize'
9
9
 
10
10
  import type { LogFilter } from '../chain.ts'
11
11
  import type { Log_ } from '../types.ts'
@@ -16,6 +16,12 @@ const eventToHandler = {
16
16
  ExecutionStateChanged: 'OffRampState/execution_state_changed_events',
17
17
  } as const
18
18
 
19
+ /**
20
+ * Fetches a user transaction by its version number.
21
+ * @param provider - Aptos provider instance.
22
+ * @param version - Transaction version number.
23
+ * @returns User transaction response.
24
+ */
19
25
  export async function getUserTxByVersion(
20
26
  provider: Aptos,
21
27
  version: number,
@@ -28,6 +34,12 @@ export async function getUserTxByVersion(
28
34
  return tx
29
35
  }
30
36
 
37
+ /**
38
+ * Gets the timestamp for a given transaction version.
39
+ * @param provider - Aptos provider instance.
40
+ * @param version - Version number or 'finalized'.
41
+ * @returns Timestamp in seconds.
42
+ */
31
43
  export async function getVersionTimestamp(
32
44
  provider: Aptos,
33
45
  version: number | 'finalized',
@@ -78,7 +90,7 @@ async function* fetchEventsForward(
78
90
  stateAddr: string,
79
91
  limit = 100,
80
92
  ): AsyncGenerator<ResEvent> {
81
- const fetchBatch = moize.default(
93
+ const fetchBatch = memoize(
82
94
  async (start?: number) => {
83
95
  const { data }: { data: ResEvent[] } = await getAptosFullNode({
84
96
  aptosConfig: provider.config,
@@ -86,7 +98,7 @@ async function* fetchEventsForward(
86
98
  path: `accounts/${stateAddr}/events/${opts.address}::${eventHandlerField}`,
87
99
  params: { start, limit },
88
100
  })
89
- if (!start) fetchBatch.set([+data[0].sequence_number], data)
101
+ if (!start) fetchBatch.cache.set([+data[0].sequence_number], Promise.resolve(data))
90
102
  return data
91
103
  },
92
104
  { maxArgs: 1, maxSize: 100 },
@@ -165,6 +177,12 @@ async function* fetchEventsBackward(
165
177
  } while (cont)
166
178
  }
167
179
 
180
+ /**
181
+ * Streams logs from the Aptos blockchain based on filter options.
182
+ * @param provider - Aptos provider instance.
183
+ * @param opts - Log filter options.
184
+ * @returns Async generator of log entries.
185
+ */
168
186
  export async function* streamAptosLogs(
169
187
  provider: Aptos,
170
188
  opts: LogFilter & { versionAsHash?: boolean },
package/src/aptos/send.ts CHANGED
@@ -1,11 +1,9 @@
1
- import type { Aptos } from '@aptos-labs/ts-sdk'
1
+ import { type Aptos, AccountAddress } from '@aptos-labs/ts-sdk'
2
2
  import { getBytes, zeroPadValue } from 'ethers'
3
3
 
4
- import { ChainFamily } from '../chain.ts'
5
4
  import { encodeExtraArgs } from '../extra-args.ts'
6
- import type { AnyMessage } from '../types.ts'
5
+ import { type AnyMessage, ChainFamily } from '../types.ts'
7
6
  import { getDataBytes } from '../utils.ts'
8
- import type { AptosAsyncAccount } from './types.ts'
9
7
 
10
8
  export const DEFAULT_FEE_TOKEN = '0xa'
11
9
 
@@ -52,6 +50,14 @@ function messageArgs(
52
50
  ]
53
51
  }
54
52
 
53
+ /**
54
+ * Gets the fee for sending a CCIP message on Aptos.
55
+ * @param provider - Aptos provider instance.
56
+ * @param router - Router module address.
57
+ * @param destChainSelector - Destination chain selector.
58
+ * @param message - CCIP message to send.
59
+ * @returns Fee amount in native tokens.
60
+ */
55
61
  export async function getFee(
56
62
  provider: Aptos,
57
63
  router: string,
@@ -72,14 +78,24 @@ export async function getFee(
72
78
  return BigInt(fee)
73
79
  }
74
80
 
75
- export async function ccipSend(
81
+ /**
82
+ * Generate an unsigned ccip_send tx to send a CCIP message through the Aptos router.
83
+ * @param provider - Aptos provider instance.
84
+ * @param sender - sender account address
85
+ * @param router - Router module address.
86
+ * @param destChainSelector - Destination chain selector.
87
+ * @param message - CCIP message with fee.
88
+ * @param _opts - Optional parameters.
89
+ * @returns Transaction hash.
90
+ */
91
+ export async function generateUnsignedCcipSend(
76
92
  provider: Aptos,
77
- account: AptosAsyncAccount,
93
+ sender: string,
78
94
  router: string,
79
95
  destChainSelector: bigint,
80
96
  message: AnyMessage & { fee: bigint },
81
97
  _opts?: { approveMax?: boolean },
82
- ): Promise<string> {
98
+ ): Promise<Uint8Array> {
83
99
  // Build and submit the transaction
84
100
  // Call ccip_send entry function with signature:
85
101
  // public entry fun ccip_send(
@@ -95,7 +111,7 @@ export async function ccipSend(
95
111
  // extra_args: vector<u8>
96
112
  // )
97
113
  const transaction = await provider.transaction.build.simple({
98
- sender: account.accountAddress,
114
+ sender: AccountAddress.fromString(sender),
99
115
  data: {
100
116
  function:
101
117
  `${router.includes('::') ? router : router + '::router'}::ccip_send` as `${string}::${string}::${string}`,
@@ -103,18 +119,5 @@ export async function ccipSend(
103
119
  },
104
120
  })
105
121
 
106
- // Sign and submit the transaction
107
- const signed = await account.signTransactionWithAuthenticator(transaction)
108
- const pendingTxn = await provider.transaction.submit.simple({
109
- transaction,
110
- senderAuthenticator: signed,
111
- })
112
-
113
- // Wait for the transaction to be confirmed
114
- const { hash } = await provider.waitForTransaction({
115
- transactionHash: pendingTxn.hash,
116
- })
117
-
118
- // Return the transaction hash
119
- return hash
122
+ return transaction.bcsToBytes()
120
123
  }
@@ -2,6 +2,12 @@ import type { Aptos } from '@aptos-labs/ts-sdk'
2
2
 
3
3
  import type { TokenInfo } from '../chain.ts'
4
4
 
5
+ /**
6
+ * Retrieves token metadata (symbol and decimals) from Aptos.
7
+ * @param provider - Aptos provider instance.
8
+ * @param token - Token address.
9
+ * @returns Token information with symbol and decimals.
10
+ */
5
11
  export async function getTokenInfo(provider: Aptos, token: string): Promise<TokenInfo> {
6
12
  let lastErr: Error | undefined
7
13
 
@@ -8,10 +8,10 @@ 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 { ExecutionReport } from '../types.ts'
11
+ import type { ChainFamily, ExecutionReport } from '../types.ts'
12
12
  import { getAddressBytes } from '../utils.ts'
13
13
 
14
- // Aptos Account is synchronous; this specialisation adds async signTransactionWithAuthenticator
14
+ /** Aptos account type with async transaction signing capability. */
15
15
  export type AptosAsyncAccount = {
16
16
  publicKey: AccountPublicKey
17
17
  accountAddress: AccountAddress
@@ -20,6 +20,17 @@ export type AptosAsyncAccount = {
20
20
  ) => Promise<AccountAuthenticator> | AccountAuthenticator
21
21
  }
22
22
 
23
+ /** Typeguard for an aptos-ts-sdk-like Account */
24
+ export function isAptosAccount(account: unknown): account is AptosAsyncAccount {
25
+ return (
26
+ typeof account === 'object' &&
27
+ account !== null &&
28
+ 'publicKey' in account &&
29
+ 'accountAddress' in account &&
30
+ 'signTransactionWithAuthenticator' in account
31
+ )
32
+ }
33
+
23
34
  export const EVMExtraArgsV2Codec = bcs.struct('EVMExtraArgsV2', {
24
35
  gasLimit: bcs.u256(),
25
36
  allowOutOfOrderExecution: bcs.bool(),
@@ -57,6 +68,11 @@ export const ExecutionReportCodec = bcs.struct('ExecutionReport', {
57
68
  proofs: bcs.vector(bcs.fixedArray(32, bcs.u8())),
58
69
  })
59
70
 
71
+ /**
72
+ * Serializes an execution report for Aptos using BCS encoding.
73
+ * @param execReport - Execution report to serialize.
74
+ * @returns BCS-encoded bytes.
75
+ */
60
76
  export function serializeExecutionReport(
61
77
  execReport: ExecutionReport<CCIPMessage_V1_6_EVM>,
62
78
  ): Uint8Array {
@@ -83,3 +99,11 @@ export function serializeExecutionReport(
83
99
  proofs: execReport.proofs.map((p) => getBytes(p)),
84
100
  }).toBytes()
85
101
  }
102
+
103
+ /**
104
+ * Unsigned Aptos transactions, BCS-serialized.
105
+ */
106
+ export type UnsignedAptosTx = {
107
+ family: typeof ChainFamily.Aptos
108
+ transactions: [Uint8Array]
109
+ }
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  /**
11
11
  * Encodes a numeric value as a 32-byte hex string.
12
- * @param value Numeric value to encode.
12
+ * @param value - Numeric value to encode.
13
13
  * @returns 32-byte hex string representation of the value.
14
14
  */
15
15
  export const encodeNumber = (value: BigNumberish): string => toBeHex(value, 32)