@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.
- package/README.md +35 -26
- package/dist/aptos/exec.d.ts +4 -5
- package/dist/aptos/exec.d.ts.map +1 -1
- package/dist/aptos/exec.js +5 -14
- package/dist/aptos/exec.js.map +1 -1
- package/dist/aptos/hasher.d.ts +18 -0
- package/dist/aptos/hasher.d.ts.map +1 -1
- package/dist/aptos/hasher.js +18 -0
- package/dist/aptos/hasher.js.map +1 -1
- package/dist/aptos/index.d.ts +127 -28
- package/dist/aptos/index.d.ts.map +1 -1
- package/dist/aptos/index.js +199 -70
- package/dist/aptos/index.js.map +1 -1
- package/dist/aptos/logs.d.ts +18 -0
- package/dist/aptos/logs.d.ts.map +1 -1
- package/dist/aptos/logs.js +21 -3
- package/dist/aptos/logs.js.map +1 -1
- package/dist/aptos/send.d.ts +22 -5
- package/dist/aptos/send.d.ts.map +1 -1
- package/dist/aptos/send.js +23 -15
- package/dist/aptos/send.js.map +1 -1
- package/dist/aptos/token.d.ts +6 -0
- package/dist/aptos/token.d.ts.map +1 -1
- package/dist/aptos/token.js +6 -0
- package/dist/aptos/token.js.map +1 -1
- package/dist/aptos/types.d.ts +16 -1
- package/dist/aptos/types.d.ts.map +1 -1
- package/dist/aptos/types.js +13 -0
- package/dist/aptos/types.js.map +1 -1
- package/dist/aptos/utils.d.ts +1 -1
- package/dist/aptos/utils.js +1 -1
- package/dist/chain.d.ts +185 -99
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +38 -15
- package/dist/chain.js.map +1 -1
- package/dist/commits.d.ts +4 -10
- package/dist/commits.d.ts.map +1 -1
- package/dist/commits.js +2 -1
- package/dist/commits.js.map +1 -1
- package/dist/evm/const.d.ts +5 -0
- package/dist/evm/const.d.ts.map +1 -1
- package/dist/evm/const.js +5 -0
- package/dist/evm/const.js.map +1 -1
- package/dist/evm/errors.d.ts +5 -0
- package/dist/evm/errors.d.ts.map +1 -1
- package/dist/evm/errors.js +6 -1
- package/dist/evm/errors.js.map +1 -1
- package/dist/evm/hasher.d.ts +16 -2
- package/dist/evm/hasher.d.ts.map +1 -1
- package/dist/evm/hasher.js +17 -3
- package/dist/evm/hasher.js.map +1 -1
- package/dist/evm/index.d.ts +176 -31
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +312 -154
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/logs.d.ts +20 -0
- package/dist/evm/logs.d.ts.map +1 -0
- package/dist/evm/logs.js +194 -0
- package/dist/evm/logs.js.map +1 -0
- package/dist/evm/messages.d.ts +11 -2
- package/dist/evm/messages.d.ts.map +1 -1
- package/dist/evm/messages.js +4 -2
- package/dist/evm/messages.js.map +1 -1
- package/dist/evm/offchain.d.ts +7 -2
- package/dist/evm/offchain.d.ts.map +1 -1
- package/dist/evm/offchain.js +12 -7
- package/dist/evm/offchain.js.map +1 -1
- package/dist/execution.d.ts +19 -62
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +28 -31
- package/dist/execution.js.map +1 -1
- package/dist/extra-args.d.ts +35 -5
- package/dist/extra-args.d.ts.map +1 -1
- package/dist/extra-args.js +10 -5
- package/dist/extra-args.js.map +1 -1
- package/dist/gas.d.ts +6 -8
- package/dist/gas.d.ts.map +1 -1
- package/dist/gas.js +7 -9
- package/dist/gas.js.map +1 -1
- package/dist/hasher/common.d.ts +3 -2
- package/dist/hasher/common.d.ts.map +1 -1
- package/dist/hasher/common.js +2 -2
- package/dist/hasher/common.js.map +1 -1
- package/dist/hasher/hasher.d.ts +8 -2
- package/dist/hasher/hasher.d.ts.map +1 -1
- package/dist/hasher/hasher.js +8 -3
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/merklemulti.d.ts +11 -9
- package/dist/hasher/merklemulti.d.ts.map +1 -1
- package/dist/hasher/merklemulti.js +17 -16
- package/dist/hasher/merklemulti.js.map +1 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/requests.d.ts +39 -25
- package/dist/requests.d.ts.map +1 -1
- package/dist/requests.js +42 -35
- package/dist/requests.js.map +1 -1
- package/dist/selectors.d.ts +1 -1
- package/dist/solana/cleanup.d.ts +14 -10
- package/dist/solana/cleanup.d.ts.map +1 -1
- package/dist/solana/cleanup.js +35 -33
- package/dist/solana/cleanup.js.map +1 -1
- package/dist/solana/exec.d.ts +19 -11
- package/dist/solana/exec.d.ts.map +1 -1
- package/dist/solana/exec.js +86 -163
- package/dist/solana/exec.js.map +1 -1
- package/dist/solana/hasher.d.ts +7 -2
- package/dist/solana/hasher.d.ts.map +1 -1
- package/dist/solana/hasher.js +7 -2
- package/dist/solana/hasher.js.map +1 -1
- package/dist/solana/index.d.ts +202 -84
- package/dist/solana/index.d.ts.map +1 -1
- package/dist/solana/index.js +367 -252
- package/dist/solana/index.js.map +1 -1
- package/dist/solana/offchain.d.ts +8 -18
- package/dist/solana/offchain.d.ts.map +1 -1
- package/dist/solana/offchain.js +29 -83
- package/dist/solana/offchain.js.map +1 -1
- package/dist/solana/patchBorsh.d.ts +5 -1
- package/dist/solana/patchBorsh.d.ts.map +1 -1
- package/dist/solana/patchBorsh.js +57 -46
- package/dist/solana/patchBorsh.js.map +1 -1
- package/dist/solana/send.d.ts +28 -10
- package/dist/solana/send.d.ts.map +1 -1
- package/dist/solana/send.js +44 -77
- package/dist/solana/send.js.map +1 -1
- package/dist/solana/types.d.ts +22 -1
- package/dist/solana/types.d.ts.map +1 -1
- package/dist/solana/types.js +12 -1
- package/dist/solana/types.js.map +1 -1
- package/dist/solana/utils.d.ts +58 -4
- package/dist/solana/utils.d.ts.map +1 -1
- package/dist/solana/utils.js +110 -7
- package/dist/solana/utils.js.map +1 -1
- package/dist/sui/hasher.d.ts +18 -0
- package/dist/sui/hasher.d.ts.map +1 -1
- package/dist/sui/hasher.js +18 -0
- package/dist/sui/hasher.js.map +1 -1
- package/dist/sui/index.d.ts +99 -12
- package/dist/sui/index.d.ts.map +1 -1
- package/dist/sui/index.js +108 -19
- package/dist/sui/index.js.map +1 -1
- package/dist/sui/types.d.ts +6 -0
- package/dist/sui/types.d.ts.map +1 -1
- package/dist/sui/types.js +5 -0
- package/dist/sui/types.js.map +1 -1
- package/dist/supported-chains.d.ts +2 -1
- package/dist/supported-chains.d.ts.map +1 -1
- package/dist/supported-chains.js.map +1 -1
- package/dist/types.d.ts +127 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +67 -46
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +143 -21
- package/dist/utils.js.map +1 -1
- package/package.json +13 -9
- package/src/aptos/exec.ts +7 -18
- package/src/aptos/hasher.ts +18 -0
- package/src/aptos/index.ts +288 -110
- package/src/aptos/logs.ts +21 -3
- package/src/aptos/send.ts +25 -22
- package/src/aptos/token.ts +6 -0
- package/src/aptos/types.ts +26 -2
- package/src/aptos/utils.ts +1 -1
- package/src/chain.ts +243 -108
- package/src/commits.ts +6 -7
- package/src/evm/const.ts +5 -0
- package/src/evm/errors.ts +6 -1
- package/src/evm/hasher.ts +20 -4
- package/src/evm/index.ts +416 -214
- package/src/evm/logs.ts +255 -0
- package/src/evm/messages.ts +11 -5
- package/src/evm/offchain.ts +13 -4
- package/src/execution.ts +40 -32
- package/src/extra-args.ts +38 -6
- package/src/gas.ts +7 -9
- package/src/hasher/common.ts +3 -2
- package/src/hasher/hasher.ts +12 -4
- package/src/hasher/merklemulti.ts +17 -16
- package/src/index.ts +29 -23
- package/src/requests.ts +64 -46
- package/src/selectors.ts +1 -1
- package/src/solana/cleanup.ts +49 -34
- package/src/solana/exec.ts +128 -272
- package/src/solana/hasher.ts +13 -4
- package/src/solana/index.ts +483 -356
- package/src/solana/offchain.ts +32 -102
- package/src/solana/patchBorsh.ts +65 -50
- package/src/solana/send.ts +52 -111
- package/src/solana/types.ts +44 -3
- package/src/solana/utils.ts +143 -19
- package/src/sui/hasher.ts +18 -0
- package/src/sui/index.ts +143 -31
- package/src/sui/types.ts +6 -0
- package/src/supported-chains.ts +2 -1
- package/src/types.ts +130 -18
- package/src/utils.ts +168 -26
- 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
|
|
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 =
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
93
|
+
sender: string,
|
|
78
94
|
router: string,
|
|
79
95
|
destChainSelector: bigint,
|
|
80
96
|
message: AnyMessage & { fee: bigint },
|
|
81
97
|
_opts?: { approveMax?: boolean },
|
|
82
|
-
): Promise<
|
|
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:
|
|
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
|
-
|
|
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
|
}
|
package/src/aptos/token.ts
CHANGED
|
@@ -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
|
|
package/src/aptos/types.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|
package/src/aptos/utils.ts
CHANGED
|
@@ -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)
|