@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
@@ -1,11 +1,9 @@
1
- import util from 'util'
2
-
3
1
  import {
4
- Account,
5
2
  Aptos,
6
3
  AptosConfig,
7
- Ed25519PrivateKey,
4
+ Deserializer,
8
5
  Network,
6
+ SimpleTransaction,
9
7
  TransactionResponseType,
10
8
  } from '@aptos-labs/ts-sdk'
11
9
  import {
@@ -20,17 +18,11 @@ import {
20
18
  isHexString,
21
19
  zeroPadValue,
22
20
  } from 'ethers'
23
- import moize from 'moize'
21
+ import { memoize } from 'micro-memoize'
22
+ import type { PickDeep, SetRequired } from 'type-fest'
24
23
 
25
- import { ccipSend, getFee } from './send.ts'
26
- import {
27
- type ChainTransaction,
28
- type LogFilter,
29
- type TokenInfo,
30
- type TokenPoolRemote,
31
- Chain,
32
- ChainFamily,
33
- } from '../chain.ts'
24
+ import { generateUnsignedCcipSend, getFee } from './send.ts'
25
+ import { type LogFilter, type TokenInfo, type TokenPoolRemote, Chain } from '../chain.ts'
34
26
  import {
35
27
  type EVMExtraArgsV2,
36
28
  type ExtraArgs,
@@ -40,17 +32,20 @@ import {
40
32
  } from '../extra-args.ts'
41
33
  import type { LeafHasher } from '../hasher/common.ts'
42
34
  import { supportedChains } from '../supported-chains.ts'
43
- import type {
44
- AnyMessage,
45
- CCIPMessage,
46
- CCIPRequest,
47
- CommitReport,
48
- ExecutionReceipt,
49
- ExecutionReport,
50
- Lane,
51
- Log_,
52
- NetworkInfo,
53
- OffchainTokenData,
35
+ import {
36
+ type AnyMessage,
37
+ type CCIPMessage,
38
+ type CCIPRequest,
39
+ type ChainTransaction,
40
+ type CommitReport,
41
+ type ExecutionReceipt,
42
+ type ExecutionReport,
43
+ type Lane,
44
+ type Log_,
45
+ type NetworkInfo,
46
+ type OffchainTokenData,
47
+ type WithLogger,
48
+ ChainFamily,
54
49
  } from '../types.ts'
55
50
  import {
56
51
  convertKeysToCamelCase,
@@ -60,102 +55,138 @@ import {
60
55
  getDataBytes,
61
56
  networkInfo,
62
57
  parseTypeAndVersion,
58
+ util,
63
59
  } from '../utils.ts'
64
- import { executeReport } from './exec.ts'
60
+ import { generateUnsignedExecuteReport } from './exec.ts'
65
61
  import { getAptosLeafHasher } from './hasher.ts'
66
62
  import { getUserTxByVersion, getVersionTimestamp, streamAptosLogs } from './logs.ts'
67
63
  import { getTokenInfo } from './token.ts'
68
- import { type AptosAsyncAccount, EVMExtraArgsV2Codec, SVMExtraArgsV1Codec } from './types.ts'
64
+ import {
65
+ type UnsignedAptosTx,
66
+ EVMExtraArgsV2Codec,
67
+ SVMExtraArgsV1Codec,
68
+ isAptosAccount,
69
+ } from './types.ts'
69
70
  import type { CCIPMessage_V1_6_EVM } from '../evm/messages.ts'
70
- import { decodeMessage } from '../requests.ts'
71
-
71
+ import {
72
+ decodeMessage,
73
+ fetchAllMessagesInBatch,
74
+ fetchCCIPRequestById,
75
+ fetchCCIPRequestsInTx,
76
+ } from '../requests.ts'
77
+
78
+ /**
79
+ * Aptos chain implementation supporting Aptos networks.
80
+ */
72
81
  export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
82
+ static {
83
+ supportedChains[ChainFamily.Aptos] = AptosChain
84
+ }
73
85
  static readonly family = ChainFamily.Aptos
74
86
  static readonly decimals = 8
75
87
 
76
- readonly network: NetworkInfo<typeof ChainFamily.Aptos>
77
- readonly provider: Aptos
88
+ provider: Aptos
78
89
 
79
90
  getTokenInfo: (token: string) => Promise<TokenInfo>
80
91
  _getAccountModulesNames: (address: string) => Promise<string[]>
81
92
 
82
- constructor(provider: Aptos, network: NetworkInfo) {
83
- if (network.family !== ChainFamily.Aptos) {
84
- throw new Error(`Invalid network family: ${network.family}, expected ${ChainFamily.Aptos}`)
85
- }
86
- super()
93
+ /**
94
+ * Creates a new AptosChain instance.
95
+ * @param provider - Aptos SDK provider instance.
96
+ * @param network - Network information for this chain.
97
+ */
98
+ constructor(provider: Aptos, network: NetworkInfo, ctx?: WithLogger) {
99
+ super(network, ctx)
87
100
 
88
101
  this.provider = provider
89
- this.network = network
90
- this.typeAndVersion = moize.default(this.typeAndVersion.bind(this), {
102
+ this.typeAndVersion = memoize(this.typeAndVersion.bind(this), {
91
103
  maxSize: 100,
92
104
  maxArgs: 1,
93
- maxAge: 60e3, // 1min
105
+ expires: 60e3, // 1min
94
106
  })
95
- this.getTransaction = moize.default(this.getTransaction.bind(this), {
107
+ this.getTransaction = memoize(this.getTransaction.bind(this), {
96
108
  maxSize: 100,
97
109
  maxArgs: 1,
98
110
  })
99
- this.getTokenForTokenPool = moize.default(this.getTokenForTokenPool.bind(this), {
111
+ this.getTokenForTokenPool = memoize(this.getTokenForTokenPool.bind(this), {
100
112
  maxSize: 100,
101
113
  maxArgs: 1,
102
114
  })
103
- this.getTokenInfo = moize.default((token) => getTokenInfo(this.provider, token), {
115
+ this.getTokenInfo = memoize((token) => getTokenInfo(this.provider, token), {
104
116
  maxSize: 100,
105
117
  maxArgs: 1,
106
118
  })
107
119
 
108
- this._getAccountModulesNames = moize.default(
120
+ this._getAccountModulesNames = memoize(
109
121
  (address) =>
110
122
  this.provider
111
123
  .getAccountModules({ accountAddress: address })
112
124
  .then((modules) => modules.map(({ abi }) => abi!.name)),
113
125
  { maxSize: 100, maxArgs: 1 },
114
126
  )
115
- this.getWallet = moize.default(this.getWallet.bind(this), { maxSize: 1, maxArgs: 0 })
116
- this.provider.getTransactionByVersion = moize.default(
127
+ this.provider.getTransactionByVersion = memoize(
117
128
  this.provider.getTransactionByVersion.bind(this.provider),
118
129
  {
119
130
  maxSize: 100,
120
- isPromise: true,
121
- transformArgs: ([arg]) => [(arg as { ledgerVersion: number }).ledgerVersion],
131
+ async: true,
132
+ transformKey: ([arg]) => [(arg as { ledgerVersion: number }).ledgerVersion],
122
133
  },
123
134
  )
124
135
  }
125
136
 
126
- static async fromProvider(provider: Aptos): Promise<AptosChain> {
127
- return new AptosChain(provider, networkInfo(`aptos:${await provider.getChainId()}`))
137
+ /**
138
+ * Creates an AptosChain instance from an existing Aptos provider.
139
+ * @param provider - Aptos SDK provider instance.
140
+ * @param ctx - context containing logger.
141
+ * @returns A new AptosChain instance.
142
+ */
143
+ static async fromProvider(provider: Aptos, ctx?: WithLogger): Promise<AptosChain> {
144
+ return new AptosChain(provider, networkInfo(`aptos:${await provider.getChainId()}`), ctx)
128
145
  }
129
146
 
130
- static async fromAptosConfig(config: AptosConfig): Promise<AptosChain> {
147
+ /**
148
+ * Creates an AptosChain instance from an Aptos configuration.
149
+ * @param config - Aptos configuration object.
150
+ * @param ctx - context containing logger.
151
+ * @returns A new AptosChain instance.
152
+ */
153
+ static async fromAptosConfig(config: AptosConfig, ctx?: WithLogger): Promise<AptosChain> {
131
154
  const provider = new Aptos(config)
132
- return this.fromProvider(provider)
133
- }
134
-
135
- static async fromUrl(url: string | Network, network?: Network): Promise<AptosChain> {
136
- if (network) {
137
- // pass
155
+ return this.fromProvider(provider, ctx)
156
+ }
157
+
158
+ /**
159
+ * Creates an AptosChain instance from a URL or network identifier.
160
+ * @param url - RPC URL, Aptos Network enum value or [fullNodeUrl, Network] tuple.
161
+ * @param ctx - context containing logger
162
+ * @returns A new AptosChain instance.
163
+ */
164
+ static async fromUrl(
165
+ url: string | Network | readonly [string, Network],
166
+ ctx?: WithLogger,
167
+ ): Promise<AptosChain> {
168
+ let network: Network
169
+ if (Array.isArray(url)) {
170
+ ;[url, network] = url
138
171
  } else if (Object.values(Network).includes(url as Network)) network = url as Network
139
172
  else if (url.includes('mainnet')) network = Network.MAINNET
140
173
  else if (url.includes('testnet')) network = Network.TESTNET
141
174
  else if (url.includes('local')) network = Network.LOCAL
142
- else throw new Error(`Unknown Aptos network: ${url}`)
175
+ else throw new Error(`Unknown Aptos network: ${util.inspect(url)}`)
143
176
  const config: AptosConfig = new AptosConfig({
144
177
  network,
145
- fullnode: url.includes('://') ? url : undefined,
178
+ fullnode: typeof url === 'string' && url.includes('://') ? url : undefined,
146
179
  // indexer: url.includes('://') ? `${url}/v1/graphql` : undefined,
147
180
  })
148
- return this.fromAptosConfig(config)
149
- }
150
-
151
- async destroy(): Promise<void> {
152
- // Nothing to cleanup for Aptos implementation
181
+ return this.fromAptosConfig(config, ctx)
153
182
  }
154
183
 
184
+ /** {@inheritDoc Chain.getBlockTimestamp} */
155
185
  async getBlockTimestamp(version: number | 'finalized'): Promise<number> {
156
186
  return getVersionTimestamp(this.provider, version)
157
187
  }
158
188
 
189
+ /** {@inheritDoc Chain.getTransaction} */
159
190
  async getTransaction(hashOrVersion: string | number): Promise<ChainTransaction> {
160
191
  let tx
161
192
  if (isHexString(hashOrVersion, 32)) {
@@ -170,7 +201,6 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
170
201
  if (tx.type !== TransactionResponseType.User) throw new Error('Invalid transaction type')
171
202
 
172
203
  return {
173
- chain: this,
174
204
  hash: tx.hash,
175
205
  blockNumber: +tx.version,
176
206
  from: tx.sender,
@@ -186,46 +216,81 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
186
216
  }
187
217
  }
188
218
 
219
+ /** {@inheritDoc Chain.getLogs} */
189
220
  async *getLogs(opts: LogFilter & { versionAsHash?: boolean }): AsyncIterableIterator<Log_> {
190
221
  yield* streamAptosLogs(this.provider, opts)
191
222
  }
192
223
 
193
- async typeAndVersion(
194
- address: string,
195
- ): Promise<
196
- | [type_: string, version: string, typeAndVersion: string]
197
- | [type_: string, version: string, typeAndVersion: string, suffix: string]
198
- > {
224
+ /** {@inheritDoc Chain.fetchRequestsInTx} */
225
+ async fetchRequestsInTx(tx: string | ChainTransaction): Promise<CCIPRequest[]> {
226
+ return fetchCCIPRequestsInTx(this, typeof tx === 'string' ? await this.getTransaction(tx) : tx)
227
+ }
228
+
229
+ /** {@inheritDoc Chain.fetchRequestById} */
230
+ override async fetchRequestById(
231
+ messageId: string,
232
+ onRamp?: string,
233
+ opts?: { page?: number },
234
+ ): Promise<CCIPRequest> {
235
+ if (!onRamp) throw new Error('onRamp is required')
236
+ return fetchCCIPRequestById(this, messageId, {
237
+ address: await this.getOnRampForRouter(onRamp, 0n),
238
+ ...opts,
239
+ })
240
+ }
241
+
242
+ /** {@inheritDoc Chain.fetchAllMessagesInBatch} */
243
+ async fetchAllMessagesInBatch<
244
+ R extends PickDeep<
245
+ CCIPRequest,
246
+ 'lane' | `log.${'topics' | 'address' | 'blockNumber'}` | 'message.header.sequenceNumber'
247
+ >,
248
+ >(
249
+ request: R,
250
+ commit: Pick<CommitReport, 'minSeqNr' | 'maxSeqNr'>,
251
+ opts?: { page?: number },
252
+ ): Promise<R['message'][]> {
253
+ return fetchAllMessagesInBatch(this, request, commit, opts)
254
+ }
255
+
256
+ /** {@inheritDoc Chain.typeAndVersion} */
257
+ async typeAndVersion(address: string) {
258
+ // requires address with `::<module>` suffix
199
259
  const [typeAndVersion] = await this.provider.view<[string]>({
200
260
  payload: {
201
261
  function: `${address}::type_and_version` as `${string}::${string}::type_and_version`,
202
262
  },
203
263
  })
204
-
205
264
  return parseTypeAndVersion(typeAndVersion)
206
265
  }
207
266
 
267
+ /** {@inheritDoc Chain.getRouterForOnRamp} */
208
268
  getRouterForOnRamp(onRamp: string, _destChainSelector: bigint): Promise<string> {
209
269
  // router is same package as onramp, changing only module
210
270
  return Promise.resolve(onRamp.split('::')[0] + '::router')
211
271
  }
212
272
 
273
+ /** {@inheritDoc Chain.getRouterForOffRamp} */
213
274
  getRouterForOffRamp(offRamp: string, _sourceChainSelector: bigint): Promise<string> {
214
275
  return Promise.resolve(offRamp.split('::')[0] + '::router')
215
276
  }
216
277
 
278
+ /** {@inheritDoc Chain.getNativeTokenForRouter} */
217
279
  getNativeTokenForRouter(_router: string): Promise<string> {
218
280
  return Promise.resolve('0xa')
219
281
  }
220
282
 
283
+ /** {@inheritDoc Chain.getOffRampsForRouter} */
221
284
  getOffRampsForRouter(router: string, _sourceChainSelector: bigint): Promise<string[]> {
222
285
  return Promise.resolve([router.split('::')[0] + '::offramp'])
223
286
  }
224
287
 
288
+ /** {@inheritDoc Chain.getOnRampForRouter} */
225
289
  getOnRampForRouter(router: string, _destChainSelector: bigint): Promise<string> {
226
290
  return Promise.resolve(router.split('::')[0] + '::onramp')
227
291
  }
228
292
 
293
+ /** {@inheritDoc Chain.getOnRampForOffRamp} */
229
294
  async getOnRampForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise<string> {
230
295
  const [sourceChainConfig] = await this.provider.view<[{ on_ramp: string }]>({
231
296
  payload: {
@@ -237,10 +302,12 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
237
302
  return decodeAddress(sourceChainConfig.on_ramp, networkInfo(sourceChainSelector).family)
238
303
  }
239
304
 
305
+ /** {@inheritDoc Chain.getCommitStoreForOffRamp} */
240
306
  getCommitStoreForOffRamp(offRamp: string): Promise<string> {
241
307
  return Promise.resolve(offRamp.split('::')[0] + '::offramp')
242
308
  }
243
309
 
310
+ /** {@inheritDoc Chain.getTokenForTokenPool} */
244
311
  async getTokenForTokenPool(tokenPool: string): Promise<string> {
245
312
  const modulesNames = (await this._getAccountModulesNames(tokenPool))
246
313
  .reverse()
@@ -261,6 +328,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
261
328
  throw firstErr ?? new Error(`Could not view 'get_token' in ${tokenPool}`)
262
329
  }
263
330
 
331
+ /** {@inheritDoc Chain.getTokenAdminRegistryFor} */
264
332
  async getTokenAdminRegistryFor(address: string): Promise<string> {
265
333
  const registry = address.split('::')[0] + '::token_admin_registry'
266
334
  const [type] = await this.typeAndVersion(registry)
@@ -270,25 +338,11 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
270
338
  return registry
271
339
  }
272
340
 
273
- static getWallet(_opts: { wallet?: unknown } = {}): Promise<AptosAsyncAccount> {
274
- return Promise.reject(new Error('TODO according to your environment'))
275
- }
276
-
277
- // cached
278
- async getWallet(opts: { wallet?: unknown } = {}): Promise<AptosAsyncAccount> {
279
- if (isBytesLike(opts.wallet)) {
280
- return Account.fromPrivateKey({
281
- privateKey: new Ed25519PrivateKey(opts.wallet, false),
282
- })
283
- }
284
- return (this.constructor as typeof AptosChain).getWallet(opts)
285
- }
286
-
287
- async getWalletAddress(opts?: { wallet?: unknown }): Promise<string> {
288
- return (await this.getWallet(opts)).accountAddress.toString()
289
- }
290
-
291
- // Static methods for decoding
341
+ /**
342
+ * Decodes a CCIP message from an Aptos log event.
343
+ * @param log - Log with data field.
344
+ * @returns Decoded CCIPMessage or undefined if not valid.
345
+ */
292
346
  static decodeMessage(log: {
293
347
  data: BytesLike | Record<string, unknown>
294
348
  }): CCIPMessage | undefined {
@@ -306,7 +360,11 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
306
360
  }
307
361
  }
308
362
 
309
- // decodes an Aptos-generated extraArgs, destinated *to* other chains (EVM, Solana, etc)
363
+ /**
364
+ * Decodes extra arguments from Aptos CCIP messages.
365
+ * @param extraArgs - Encoded extra arguments bytes.
366
+ * @returns Decoded extra arguments or undefined if unknown format.
367
+ */
310
368
  static decodeExtraArgs(
311
369
  extraArgs: BytesLike,
312
370
  ):
@@ -342,7 +400,11 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
342
400
  }
343
401
  }
344
402
 
345
- // encodes extraArgs destinated *to other* chains (EVM, Solana, etc), using Aptos-specific encoding (i.e. *from* Aptos)
403
+ /**
404
+ * Encodes extra arguments for Aptos CCIP messages.
405
+ * @param extraArgs - Extra arguments to encode.
406
+ * @returns Encoded extra arguments as hex string.
407
+ */
346
408
  static encodeExtraArgs(extraArgs: ExtraArgs): string {
347
409
  if ('gasLimit' in extraArgs && 'allowOutOfOrderExecution' in extraArgs)
348
410
  return concat([EVMExtraArgsV2Tag, EVMExtraArgsV2Codec.serialize(extraArgs).toBytes()])
@@ -359,6 +421,12 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
359
421
  throw new Error('Aptos can only encode EVMExtraArgsV2 & SVMExtraArgsV1')
360
422
  }
361
423
 
424
+ /**
425
+ * Decodes commit reports from an Aptos log event.
426
+ * @param log - Log with data field.
427
+ * @param lane - Lane info for filtering.
428
+ * @returns Array of CommitReport or undefined if not valid.
429
+ */
362
430
  static decodeCommits({ data }: Pick<Log_, 'data'>, lane?: Lane): CommitReport[] | undefined {
363
431
  if (!data || typeof data != 'object') throw new Error('invalid aptos log')
364
432
  const data_ = data as { blessed_merkle_roots: unknown[]; unblessed_merkle_roots: unknown[] }
@@ -384,6 +452,11 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
384
452
  return commits
385
453
  }
386
454
 
455
+ /**
456
+ * Decodes an execution receipt from an Aptos log event.
457
+ * @param log - Log with data field.
458
+ * @returns ExecutionReceipt or undefined if not valid.
459
+ */
387
460
  static decodeReceipt({ data }: Pick<Log_, 'data'>): ExecutionReceipt | undefined {
388
461
  if (!data || typeof data != 'object') throw new Error('invalid aptos log')
389
462
  const data_ = data as { message_id: string; state: number }
@@ -393,6 +466,11 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
393
466
  ) as ExecutionReceipt
394
467
  }
395
468
 
469
+ /**
470
+ * Converts bytes to an Aptos address.
471
+ * @param bytes - Bytes to convert.
472
+ * @returns Aptos address (0x-prefixed hex, 32 bytes padded).
473
+ */
396
474
  static getAddress(bytes: BytesLike): string {
397
475
  let suffix = ''
398
476
  if (typeof bytes === 'string' && !bytes.startsWith('0x')) {
@@ -408,55 +486,152 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
408
486
  return zeroPadValue(bytes, 32) + suffix
409
487
  }
410
488
 
411
- static getDestLeafHasher(lane: Lane): LeafHasher {
489
+ /**
490
+ * Gets the leaf hasher for Aptos destination chains.
491
+ * @param lane - Lane configuration.
492
+ * @returns Leaf hasher function.
493
+ */
494
+ static getDestLeafHasher(lane: Lane, _ctx?: WithLogger): LeafHasher {
412
495
  return getAptosLeafHasher(lane)
413
496
  }
414
497
 
498
+ /** {@inheritDoc Chain.getFee} */
415
499
  async getFee(router: string, destChainSelector: bigint, message: AnyMessage): Promise<bigint> {
416
500
  return getFee(this.provider, router, destChainSelector, message)
417
501
  }
418
502
 
503
+ /** generate raw/unsigned `ccip_send` transaction */
504
+ async generateUnsignedSendMessage(
505
+ sender: string,
506
+ router: string,
507
+ destChainSelector: bigint,
508
+ message: AnyMessage & { fee?: bigint },
509
+ opts: { approveMax?: boolean },
510
+ ): Promise<UnsignedAptosTx> {
511
+ if (!message.fee) message.fee = await this.getFee(router, destChainSelector, message)
512
+ const tx = await generateUnsignedCcipSend(
513
+ this.provider,
514
+ sender,
515
+ router,
516
+ destChainSelector,
517
+ message as SetRequired<typeof message, 'fee'>,
518
+ opts,
519
+ )
520
+ return {
521
+ family: ChainFamily.Aptos,
522
+ transactions: [tx],
523
+ }
524
+ }
525
+
526
+ /** {@inheritDoc Chain.sendMessage} */
419
527
  async sendMessage(
420
528
  router: string,
421
529
  destChainSelector: bigint,
422
- message: AnyMessage & { fee: bigint },
423
- opts?: { wallet?: unknown; approveMax?: boolean },
424
- ): Promise<ChainTransaction> {
425
- const account = await this.getWallet(opts)
530
+ message: AnyMessage & { fee?: bigint },
531
+ opts: { wallet: unknown; approveMax?: boolean },
532
+ ): Promise<CCIPRequest> {
533
+ const account = opts.wallet
534
+ if (!isAptosAccount(account)) {
535
+ throw new Error(
536
+ `${this.constructor.name}.sendMessage requires an Aptos account wallet, got=${util.inspect(opts.wallet)}`,
537
+ )
538
+ }
539
+
540
+ const unsignedTx = await this.generateUnsignedSendMessage(
541
+ account.accountAddress.toString(),
542
+ router,
543
+ destChainSelector,
544
+ message,
545
+ opts,
546
+ )
547
+ const unsigned = SimpleTransaction.deserialize(new Deserializer(unsignedTx.transactions[0]))
426
548
 
427
- const hash = await ccipSend(this.provider, account, router, destChainSelector, message)
549
+ // Sign and submit the transaction
550
+ const signed = await account.signTransactionWithAuthenticator(unsigned)
551
+ const pendingTxn = await this.provider.transaction.submit.simple({
552
+ transaction: unsigned,
553
+ senderAuthenticator: signed,
554
+ })
428
555
 
429
- // Return the ChainTransaction by fetching it
430
- return this.getTransaction(hash)
556
+ // Wait for the transaction to be confirmed
557
+ const { hash } = await this.provider.waitForTransaction({
558
+ transactionHash: pendingTxn.hash,
559
+ })
560
+
561
+ // Return the CCIPRequest by fetching it
562
+ return (await this.fetchRequestsInTx(await this.getTransaction(hash)))[0]
431
563
  }
432
564
 
565
+ /** {@inheritDoc Chain.fetchOffchainTokenData} */
433
566
  fetchOffchainTokenData(request: CCIPRequest): Promise<OffchainTokenData[]> {
434
567
  // default offchain token data
435
568
  return Promise.resolve(request.message.tokenAmounts.map(() => undefined))
436
569
  }
437
570
 
438
- async executeReport(
571
+ /** generate raw/unsigned `manually_execute` transaction data */
572
+ async generateUnsignedExecuteReport(
573
+ payer: string,
439
574
  offRamp: string,
440
575
  execReport: ExecutionReport,
441
- opts?: { wallet?: unknown; gasLimit?: number },
442
- ): Promise<ChainTransaction> {
443
- const account = await this.getWallet(opts)
444
-
576
+ opts: { gasLimit?: number },
577
+ ): Promise<UnsignedAptosTx> {
445
578
  if (!('allowOutOfOrderExecution' in execReport.message && 'gasLimit' in execReport.message)) {
446
579
  throw new Error('Aptos expects EVMExtraArgsV2 reports')
447
580
  }
448
581
 
449
- const hash = await executeReport(
582
+ const tx = await generateUnsignedExecuteReport(
450
583
  this.provider,
451
- account,
584
+ payer,
452
585
  offRamp,
453
586
  execReport as ExecutionReport<CCIPMessage_V1_6_EVM>,
454
587
  opts,
455
588
  )
589
+ return {
590
+ family: ChainFamily.Aptos,
591
+ transactions: [tx],
592
+ }
593
+ }
594
+
595
+ /** {@inheritDoc Chain.executeReport} */
596
+ async executeReport(
597
+ offRamp: string,
598
+ execReport: ExecutionReport,
599
+ opts: { wallet: unknown; gasLimit?: number },
600
+ ): Promise<ChainTransaction> {
601
+ const account = opts.wallet
602
+ if (!isAptosAccount(account)) {
603
+ throw new Error(
604
+ `${this.constructor.name}.sendMessage requires an Aptos account wallet, got=${util.inspect(opts.wallet)}`,
605
+ )
606
+ }
607
+
608
+ const unsignedTx = await this.generateUnsignedExecuteReport(
609
+ account.accountAddress.toString(),
610
+ offRamp,
611
+ execReport,
612
+ opts,
613
+ )
614
+ const unsigned = SimpleTransaction.deserialize(new Deserializer(unsignedTx.transactions[0]))
456
615
 
616
+ // Sign and submit the transaction
617
+ const signed = await account.signTransactionWithAuthenticator(unsigned)
618
+ const pendingTxn = await this.provider.transaction.submit.simple({
619
+ transaction: unsigned,
620
+ senderAuthenticator: signed,
621
+ })
622
+
623
+ // Wait for the transaction to be confirmed
624
+ const { hash } = await this.provider.waitForTransaction({
625
+ transactionHash: pendingTxn.hash,
626
+ })
457
627
  return this.getTransaction(hash)
458
628
  }
459
629
 
630
+ /**
631
+ * Parses raw Aptos data into typed structures.
632
+ * @param data - Raw data to parse.
633
+ * @returns Parsed data or undefined.
634
+ */
460
635
  static parse(data: unknown) {
461
636
  if (isBytesLike(data)) {
462
637
  const parsedExtraArgs = this.decodeExtraArgs(data)
@@ -464,6 +639,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
464
639
  }
465
640
  }
466
641
 
642
+ /** {@inheritDoc Chain.getSupportedTokens} */
467
643
  async getSupportedTokens(address: string, opts?: { page?: number }): Promise<string[]> {
468
644
  const res = []
469
645
  let page,
@@ -482,6 +658,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
482
658
  return page
483
659
  }
484
660
 
661
+ /** {@inheritDoc Chain.getRegistryTokenConfig} */
485
662
  async getRegistryTokenConfig(
486
663
  registry: string,
487
664
  token: string,
@@ -508,6 +685,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
508
685
  }
509
686
  }
510
687
 
688
+ /** {@inheritDoc Chain.getTokenPoolConfigs} */
511
689
  async getTokenPoolConfigs(tokenPool: string): Promise<{
512
690
  token: string
513
691
  router: string
@@ -546,6 +724,7 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
546
724
  throw firstErr ?? new Error(`Could not get tokenPool configs from ${tokenPool}`)
547
725
  }
548
726
 
727
+ /** {@inheritDoc Chain.getTokenPoolRemotes} */
549
728
  async getTokenPoolRemotes(
550
729
  tokenPool: string,
551
730
  remoteChainSelector?: bigint,
@@ -642,7 +821,8 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
642
821
  throw firstErr ?? new Error(`Could not view 'get_remote_token' in ${tokenPool}`)
643
822
  }
644
823
 
645
- async listFeeTokens(router: string): Promise<Record<string, TokenInfo>> {
824
+ /** {@inheritDoc Chain.getFeeTokens} */
825
+ async getFeeTokens(router: string): Promise<Record<string, TokenInfo>> {
646
826
  const [feeTokens] = await this.provider.view<[string[]]>({
647
827
  payload: {
648
828
  function:
@@ -656,5 +836,3 @@ export class AptosChain extends Chain<typeof ChainFamily.Aptos> {
656
836
  )
657
837
  }
658
838
  }
659
-
660
- supportedChains[ChainFamily.Aptos] = AptosChain