@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.
- package/README.md +2 -2
- package/dist/all-chains.d.ts +23 -0
- package/dist/all-chains.d.ts.map +1 -0
- package/dist/all-chains.js +24 -0
- package/dist/all-chains.js.map +1 -0
- package/dist/api/index.d.ts +31 -19
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +46 -25
- package/dist/api/index.js.map +1 -1
- package/dist/api/types.d.ts +24 -30
- package/dist/api/types.d.ts.map +1 -1
- package/dist/aptos/exec.d.ts +2 -2
- package/dist/aptos/exec.d.ts.map +1 -1
- package/dist/aptos/exec.js.map +1 -1
- package/dist/aptos/hasher.d.ts.map +1 -1
- package/dist/aptos/hasher.js +1 -1
- package/dist/aptos/hasher.js.map +1 -1
- package/dist/aptos/index.d.ts +43 -15
- package/dist/aptos/index.d.ts.map +1 -1
- package/dist/aptos/index.js +112 -105
- package/dist/aptos/index.js.map +1 -1
- package/dist/aptos/types.d.ts +2 -19
- package/dist/aptos/types.d.ts.map +1 -1
- package/dist/aptos/types.js +0 -11
- package/dist/aptos/types.js.map +1 -1
- package/dist/chain.d.ts +734 -174
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +216 -31
- package/dist/chain.js.map +1 -1
- package/dist/commits.d.ts +4 -6
- package/dist/commits.d.ts.map +1 -1
- package/dist/commits.js +4 -4
- package/dist/commits.js.map +1 -1
- package/dist/errors/CCIPError.d.ts +33 -4
- package/dist/errors/CCIPError.d.ts.map +1 -1
- package/dist/errors/CCIPError.js +33 -4
- package/dist/errors/CCIPError.js.map +1 -1
- package/dist/errors/codes.d.ts +5 -0
- package/dist/errors/codes.d.ts.map +1 -1
- package/dist/errors/codes.js +5 -1
- package/dist/errors/codes.js.map +1 -1
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +2 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/recovery.d.ts.map +1 -1
- package/dist/errors/recovery.js +6 -1
- package/dist/errors/recovery.js.map +1 -1
- package/dist/errors/specialized.d.ts +1702 -121
- package/dist/errors/specialized.d.ts.map +1 -1
- package/dist/errors/specialized.js +1729 -125
- package/dist/errors/specialized.js.map +1 -1
- package/dist/errors/utils.d.ts.map +1 -1
- package/dist/errors/utils.js +0 -1
- package/dist/errors/utils.js.map +1 -1
- package/dist/evm/abi/OffRamp_2_0.d.ts +764 -0
- package/dist/evm/abi/OffRamp_2_0.d.ts.map +1 -0
- package/dist/evm/abi/OffRamp_2_0.js +744 -0
- package/dist/evm/abi/OffRamp_2_0.js.map +1 -0
- package/dist/evm/abi/OnRamp_2_0.d.ts +925 -0
- package/dist/evm/abi/OnRamp_2_0.d.ts.map +1 -0
- package/dist/evm/abi/OnRamp_2_0.js +992 -0
- package/dist/evm/abi/OnRamp_2_0.js.map +1 -0
- package/dist/evm/const.d.ts +12 -2
- package/dist/evm/const.d.ts.map +1 -1
- package/dist/evm/const.js +8 -2
- package/dist/evm/const.js.map +1 -1
- package/dist/evm/errors.d.ts.map +1 -1
- package/dist/evm/errors.js +7 -2
- package/dist/evm/errors.js.map +1 -1
- package/dist/evm/extra-args.d.ts +25 -0
- package/dist/evm/extra-args.d.ts.map +1 -0
- package/dist/evm/extra-args.js +309 -0
- package/dist/evm/extra-args.js.map +1 -0
- package/dist/evm/gas.d.ts.map +1 -1
- package/dist/evm/gas.js +7 -12
- package/dist/evm/gas.js.map +1 -1
- package/dist/evm/hasher.d.ts.map +1 -1
- package/dist/evm/hasher.js +23 -13
- package/dist/evm/hasher.js.map +1 -1
- package/dist/evm/index.d.ts +140 -35
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +306 -226
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/messages.d.ts +59 -5
- package/dist/evm/messages.d.ts.map +1 -1
- package/dist/evm/messages.js +210 -0
- package/dist/evm/messages.js.map +1 -1
- package/dist/evm/offchain.js.map +1 -1
- package/dist/evm/types.d.ts +7 -2
- package/dist/evm/types.d.ts.map +1 -1
- package/dist/evm/types.js +22 -1
- package/dist/evm/types.js.map +1 -1
- package/dist/execution.d.ts +62 -22
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +102 -51
- package/dist/execution.js.map +1 -1
- package/dist/extra-args.d.ts +113 -4
- package/dist/extra-args.d.ts.map +1 -1
- package/dist/extra-args.js +38 -3
- package/dist/extra-args.js.map +1 -1
- package/dist/gas.d.ts +31 -5
- package/dist/gas.d.ts.map +1 -1
- package/dist/gas.js +43 -9
- package/dist/gas.js.map +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/requests.d.ts +101 -22
- package/dist/requests.d.ts.map +1 -1
- package/dist/requests.js +115 -24
- package/dist/requests.js.map +1 -1
- package/dist/selectors.d.ts.map +1 -1
- package/dist/selectors.js +24 -0
- package/dist/selectors.js.map +1 -1
- package/dist/shared/bcs-codecs.d.ts +61 -0
- package/dist/shared/bcs-codecs.d.ts.map +1 -0
- package/dist/shared/bcs-codecs.js +102 -0
- package/dist/shared/bcs-codecs.js.map +1 -0
- package/dist/shared/constants.d.ts +3 -0
- package/dist/shared/constants.d.ts.map +1 -0
- package/dist/shared/constants.js +3 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/solana/exec.d.ts +2 -2
- package/dist/solana/exec.d.ts.map +1 -1
- package/dist/solana/exec.js.map +1 -1
- package/dist/solana/index.d.ts +148 -30
- package/dist/solana/index.d.ts.map +1 -1
- package/dist/solana/index.js +137 -44
- package/dist/solana/index.js.map +1 -1
- package/dist/sui/hasher.d.ts.map +1 -1
- package/dist/sui/hasher.js +1 -1
- package/dist/sui/hasher.js.map +1 -1
- package/dist/sui/index.d.ts +49 -19
- package/dist/sui/index.d.ts.map +1 -1
- package/dist/sui/index.js +76 -43
- package/dist/sui/index.js.map +1 -1
- package/dist/sui/manuallyExec/encoder.d.ts +2 -2
- package/dist/sui/manuallyExec/encoder.d.ts.map +1 -1
- package/dist/sui/manuallyExec/encoder.js.map +1 -1
- package/dist/sui/manuallyExec/index.d.ts +2 -2
- package/dist/sui/manuallyExec/index.d.ts.map +1 -1
- package/dist/ton/exec.d.ts +2 -2
- package/dist/ton/exec.d.ts.map +1 -1
- package/dist/ton/exec.js.map +1 -1
- package/dist/ton/index.d.ts +66 -27
- package/dist/ton/index.d.ts.map +1 -1
- package/dist/ton/index.js +172 -47
- package/dist/ton/index.js.map +1 -1
- package/dist/ton/send.d.ts +52 -0
- package/dist/ton/send.d.ts.map +1 -0
- package/dist/ton/send.js +166 -0
- package/dist/ton/send.js.map +1 -0
- package/dist/ton/types.d.ts +2 -2
- package/dist/ton/types.d.ts.map +1 -1
- package/dist/ton/types.js.map +1 -1
- package/dist/types.d.ts +148 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +79 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +92 -7
- package/dist/utils.js.map +1 -1
- package/package.json +16 -11
- package/src/all-chains.ts +26 -0
- package/src/api/index.ts +58 -34
- package/src/api/types.ts +24 -31
- package/src/aptos/exec.ts +2 -2
- package/src/aptos/hasher.ts +1 -1
- package/src/aptos/index.ts +127 -129
- package/src/aptos/types.ts +2 -15
- package/src/chain.ts +837 -191
- package/src/commits.ts +9 -9
- package/src/errors/CCIPError.ts +33 -4
- package/src/errors/codes.ts +5 -1
- package/src/errors/index.ts +2 -1
- package/src/errors/recovery.ts +9 -1
- package/src/errors/specialized.ts +1745 -132
- package/src/errors/utils.ts +0 -1
- package/src/evm/abi/OffRamp_2_0.ts +743 -0
- package/src/evm/abi/OnRamp_2_0.ts +991 -0
- package/src/evm/const.ts +10 -3
- package/src/evm/errors.ts +6 -2
- package/src/evm/extra-args.ts +360 -0
- package/src/evm/gas.ts +14 -13
- package/src/evm/hasher.ts +30 -18
- package/src/evm/index.ts +376 -281
- package/src/evm/messages.ts +323 -11
- package/src/evm/offchain.ts +2 -2
- package/src/evm/types.ts +20 -2
- package/src/execution.ts +126 -71
- package/src/extra-args.ts +118 -4
- package/src/gas.ts +44 -11
- package/src/index.ts +14 -11
- package/src/requests.ts +128 -24
- package/src/selectors.ts +24 -0
- package/src/shared/bcs-codecs.ts +132 -0
- package/src/shared/constants.ts +2 -0
- package/src/solana/exec.ts +4 -4
- package/src/solana/index.ts +170 -82
- package/src/sui/hasher.ts +1 -1
- package/src/sui/index.ts +88 -56
- package/src/sui/manuallyExec/encoder.ts +2 -2
- package/src/sui/manuallyExec/index.ts +2 -2
- package/src/ton/exec.ts +2 -2
- package/src/ton/index.ts +220 -58
- package/src/ton/send.ts +222 -0
- package/src/ton/types.ts +2 -2
- package/src/types.ts +173 -30
- package/src/utils.ts +91 -7
- package/dist/aptos/utils.d.ts +0 -12
- package/dist/aptos/utils.d.ts.map +0 -1
- package/dist/aptos/utils.js +0 -15
- package/dist/aptos/utils.js.map +0 -1
- package/src/aptos/utils.ts +0 -24
package/src/aptos/index.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
251
|
+
range: Pick<CommitReport, 'minSeqNr' | 'maxSeqNr'>,
|
|
250
252
|
opts?: { page?: number },
|
|
251
253
|
): Promise<R['message'][]> {
|
|
252
|
-
return getMessagesInBatch(this, request,
|
|
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.
|
|
293
|
-
async
|
|
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
|
-
/**
|
|
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
|
-
|
|
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,
|
|
397
|
+
return concat([EVMExtraArgsV2Tag, BcsEVMExtraArgsV2Codec.serialize(extraArgs).toBytes()])
|
|
422
398
|
else if ('computeUnits' in extraArgs)
|
|
423
399
|
return concat([
|
|
424
400
|
SVMExtraArgsV1Tag,
|
|
425
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
592
|
-
|
|
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['
|
|
598
|
-
if (
|
|
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
|
-
|
|
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
|
-
/**
|
|
616
|
-
|
|
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.
|
|
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
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
-
/**
|
|
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.
|
|
701
|
-
async
|
|
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
|
-
|
|
793
|
-
[
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
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
|
)
|
package/src/aptos/types.ts
CHANGED
|
@@ -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,
|
|
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:
|
|
64
|
+
execReport: ExecutionInput<CCIPMessage_V1_6_EVM>,
|
|
78
65
|
): Uint8Array {
|
|
79
66
|
const message = execReport.message
|
|
80
67
|
return ExecutionReportCodec.serialize({
|