@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/ton/send.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { type Cell, beginCell, toNano } from '@ton/core'
|
|
2
|
+
import { type TonClient, Address } from '@ton/ton'
|
|
3
|
+
import { zeroPadValue } from 'ethers'
|
|
4
|
+
|
|
5
|
+
import type { UnsignedTONTx } from './types.ts'
|
|
6
|
+
import { CCIPError, CCIPErrorCode } from '../errors/index.ts'
|
|
7
|
+
import { EVMExtraArgsV2Tag } from '../extra-args.ts'
|
|
8
|
+
import type { AnyMessage, WithLogger } from '../types.ts'
|
|
9
|
+
import { bytesToBuffer, getDataBytes } from '../utils.ts'
|
|
10
|
+
|
|
11
|
+
/** Opcode for Router ccipSend operation */
|
|
12
|
+
export const CCIP_SEND_OPCODE = 0x31768d95
|
|
13
|
+
|
|
14
|
+
/** Default gas buffer to add to fee for transaction execution */
|
|
15
|
+
export const DEFAULT_GAS_BUFFER = toNano('0.5')
|
|
16
|
+
|
|
17
|
+
/** Default gas limit for destination chain execution */
|
|
18
|
+
export const DEFAULT_GAS_LIMIT = 200_000n
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* WRAPPED_NATIVE address for TON - sentinel address representing native TON.
|
|
22
|
+
* Used as feeToken for native TON payments in FeeQuoter calls.
|
|
23
|
+
*/
|
|
24
|
+
export const WRAPPED_NATIVE = Address.parse(
|
|
25
|
+
'0:0000000000000000000000000000000000000000000000000000000000000001',
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Encodes token amounts as a snaked cell.
|
|
30
|
+
* Empty cell for no tokens.
|
|
31
|
+
*/
|
|
32
|
+
function encodeTokenAmounts(
|
|
33
|
+
tokenAmounts: readonly { token: string; amount: bigint }[] | undefined,
|
|
34
|
+
): Cell {
|
|
35
|
+
if (!tokenAmounts || tokenAmounts.length === 0) {
|
|
36
|
+
return beginCell().endCell()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const builder = beginCell()
|
|
40
|
+
for (const ta of tokenAmounts) {
|
|
41
|
+
builder.storeRef(
|
|
42
|
+
beginCell().storeAddress(Address.parse(ta.token)).storeUint(ta.amount, 256).endCell(),
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
return builder.endCell()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Encodes extraArgs as a Cell using the GenericExtraArgsV2 (EVMExtraArgsV2) format.
|
|
50
|
+
*
|
|
51
|
+
* Format per chainlink-ton TL-B:
|
|
52
|
+
* - tag: 32-bit opcode (0x181dcf10)
|
|
53
|
+
* - gasLimit: Maybe<uint256> (1 bit flag + 256 bits if present)
|
|
54
|
+
* - allowOutOfOrderExecution: 1 bit (must be true)
|
|
55
|
+
*/
|
|
56
|
+
function encodeExtraArgsCell(extraArgs: AnyMessage['extraArgs']): Cell {
|
|
57
|
+
const allowOutOfOrderExecution = true
|
|
58
|
+
|
|
59
|
+
let gasLimit = 0n
|
|
60
|
+
let hasGasLimit = false
|
|
61
|
+
|
|
62
|
+
if ('gasLimit' in extraArgs && extraArgs.gasLimit > 0n) {
|
|
63
|
+
hasGasLimit = true
|
|
64
|
+
gasLimit = extraArgs.gasLimit
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const builder = beginCell()
|
|
68
|
+
.storeUint(Number(EVMExtraArgsV2Tag), 32) // 0x181dcf10
|
|
69
|
+
.storeBit(hasGasLimit)
|
|
70
|
+
|
|
71
|
+
if (hasGasLimit) {
|
|
72
|
+
builder.storeUint(gasLimit, 256)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return builder.storeBit(allowOutOfOrderExecution).endCell()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Builds the Router ccipSend message cell.
|
|
80
|
+
*
|
|
81
|
+
* Relies on TL-B structure (Router_CCIPSend) from chainlink-ton repo.
|
|
82
|
+
*/
|
|
83
|
+
export function buildCcipSendCell(
|
|
84
|
+
destChainSelector: bigint,
|
|
85
|
+
message: AnyMessage,
|
|
86
|
+
feeTokenAddress: Address | null = null,
|
|
87
|
+
queryId = 0n,
|
|
88
|
+
): Cell {
|
|
89
|
+
// Get receiver bytes and pad to 32 bytes for cross-chain encoding
|
|
90
|
+
const paddedReceiver = bytesToBuffer(zeroPadValue(getDataBytes(message.receiver), 32))
|
|
91
|
+
|
|
92
|
+
// Data cell (ref 0)
|
|
93
|
+
const dataCell = beginCell()
|
|
94
|
+
.storeBuffer(bytesToBuffer(message.data || '0x'))
|
|
95
|
+
.endCell()
|
|
96
|
+
|
|
97
|
+
// Token amounts snaked cell (ref 1)
|
|
98
|
+
const tokenAmountsCell = encodeTokenAmounts(message.tokenAmounts)
|
|
99
|
+
|
|
100
|
+
// ExtraArgs cell (ref 2)
|
|
101
|
+
const extraArgsCell = encodeExtraArgsCell(message.extraArgs)
|
|
102
|
+
|
|
103
|
+
return beginCell()
|
|
104
|
+
.storeUint(CCIP_SEND_OPCODE, 32) // opcode
|
|
105
|
+
.storeUint(Number(queryId), 64) // queryID
|
|
106
|
+
.storeUint(destChainSelector, 64) // destChainSelector
|
|
107
|
+
.storeUint(paddedReceiver.length, 8) // receiver length in bytes
|
|
108
|
+
.storeBuffer(paddedReceiver) // receiver bytes (32 bytes, left-padded)
|
|
109
|
+
.storeRef(dataCell) // ref 0: data
|
|
110
|
+
.storeRef(tokenAmountsCell) // ref 1: tokenAmounts
|
|
111
|
+
.storeAddress(feeTokenAddress) // null = addr_none for native TON
|
|
112
|
+
.storeRef(extraArgsCell) // ref 2: extraArgs
|
|
113
|
+
.endCell()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Gets the fee for sending a CCIP message by calling FeeQuoter.validatedFee.
|
|
118
|
+
*
|
|
119
|
+
* @param ctx - Context with TonClient provider and logger
|
|
120
|
+
* @param router - Router contract address
|
|
121
|
+
* @param destChainSelector - Destination chain selector
|
|
122
|
+
* @param message - CCIP message to quote
|
|
123
|
+
* @returns Fee amount in nanotons
|
|
124
|
+
*/
|
|
125
|
+
export async function getFee(
|
|
126
|
+
ctx: { provider: TonClient } & WithLogger,
|
|
127
|
+
router: string,
|
|
128
|
+
destChainSelector: bigint,
|
|
129
|
+
message: AnyMessage,
|
|
130
|
+
): Promise<bigint> {
|
|
131
|
+
const { provider, logger = console } = ctx
|
|
132
|
+
const routerAddress = Address.parse(router)
|
|
133
|
+
|
|
134
|
+
// FeeQuoter requires WRAPPED_NATIVE for native TON
|
|
135
|
+
const feeTokenAddress = message.feeToken ? Address.parse(message.feeToken) : WRAPPED_NATIVE
|
|
136
|
+
|
|
137
|
+
// Get FeeQuoter address via OnRamp
|
|
138
|
+
let feeQuoterAddress: Address
|
|
139
|
+
try {
|
|
140
|
+
const { stack: onRampStack } = await provider.runMethod(routerAddress, 'onRamp', [
|
|
141
|
+
{ type: 'int', value: destChainSelector },
|
|
142
|
+
])
|
|
143
|
+
const onRampAddress = onRampStack.readAddress()
|
|
144
|
+
logger.debug('OnRamp:', onRampAddress.toString())
|
|
145
|
+
|
|
146
|
+
const { stack: feeQuoterStack } = await provider.runMethod(onRampAddress, 'feeQuoter', [
|
|
147
|
+
{ type: 'int', value: destChainSelector },
|
|
148
|
+
])
|
|
149
|
+
feeQuoterAddress = feeQuoterStack.readAddress()
|
|
150
|
+
logger.debug('FeeQuoter:', feeQuoterAddress.toString())
|
|
151
|
+
} catch (e) {
|
|
152
|
+
throw new CCIPError(
|
|
153
|
+
CCIPErrorCode.CONTRACT_TYPE_INVALID,
|
|
154
|
+
`Could not get FeeQuoter address: ${e instanceof Error ? e.message : String(e)}`,
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Build stack parameters for validatedFee call
|
|
159
|
+
const paddedReceiver = bytesToBuffer(zeroPadValue(getDataBytes(message.receiver), 32))
|
|
160
|
+
const receiverSlice = beginCell().storeBuffer(paddedReceiver).endCell()
|
|
161
|
+
const dataCell = beginCell()
|
|
162
|
+
.storeBuffer(bytesToBuffer(message.data || '0x'))
|
|
163
|
+
.endCell()
|
|
164
|
+
const tokenAmountsCell = encodeTokenAmounts(message.tokenAmounts)
|
|
165
|
+
const extraArgsCell = encodeExtraArgsCell(message.extraArgs)
|
|
166
|
+
const feeTokenSlice = beginCell().storeAddress(feeTokenAddress).endCell()
|
|
167
|
+
|
|
168
|
+
const { stack: feeStack } = await provider.runMethod(feeQuoterAddress, 'validatedFee', [
|
|
169
|
+
{ type: 'int', value: 0n },
|
|
170
|
+
{ type: 'int', value: destChainSelector },
|
|
171
|
+
{ type: 'slice', cell: receiverSlice },
|
|
172
|
+
{ type: 'cell', cell: dataCell },
|
|
173
|
+
{ type: 'cell', cell: tokenAmountsCell },
|
|
174
|
+
{ type: 'slice', cell: feeTokenSlice },
|
|
175
|
+
{ type: 'cell', cell: extraArgsCell },
|
|
176
|
+
])
|
|
177
|
+
|
|
178
|
+
const fee = feeStack.readBigNumber()
|
|
179
|
+
if (fee < 0n) {
|
|
180
|
+
throw new CCIPError(CCIPErrorCode.MESSAGE_INVALID, `Invalid fee: ${fee}`)
|
|
181
|
+
}
|
|
182
|
+
logger.debug('CCIP fee:', fee.toString(), 'nanotons')
|
|
183
|
+
return fee
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Generates an unsigned CCIP send transaction for the Router.
|
|
188
|
+
*
|
|
189
|
+
* @param ctx - Context with TonClient provider and logger
|
|
190
|
+
* @param _sender - Sender address (unused, for interface compatibility)
|
|
191
|
+
* @param router - Router contract address
|
|
192
|
+
* @param destChainSelector - Destination chain selector
|
|
193
|
+
* @param message - CCIP message with fee included
|
|
194
|
+
* @param opts - Optional gas buffer override
|
|
195
|
+
* @returns Unsigned transaction ready for signing
|
|
196
|
+
*/
|
|
197
|
+
export function generateUnsignedCcipSend(
|
|
198
|
+
ctx: { provider: TonClient } & WithLogger,
|
|
199
|
+
_sender: string,
|
|
200
|
+
router: string,
|
|
201
|
+
destChainSelector: bigint,
|
|
202
|
+
message: AnyMessage & { fee: bigint },
|
|
203
|
+
opts?: { gasBuffer?: bigint },
|
|
204
|
+
): Omit<UnsignedTONTx, 'family'> {
|
|
205
|
+
const { logger = console } = ctx
|
|
206
|
+
const gasBuffer = opts?.gasBuffer ?? DEFAULT_GAS_BUFFER
|
|
207
|
+
|
|
208
|
+
// Router accepts addr_none for native TON (unlike FeeQuoter which needs WRAPPED_NATIVE)
|
|
209
|
+
const feeTokenAddress = message.feeToken ? Address.parse(message.feeToken) : null
|
|
210
|
+
|
|
211
|
+
const ccipSendCell = buildCcipSendCell(destChainSelector, message, feeTokenAddress)
|
|
212
|
+
const totalValue = message.fee + gasBuffer
|
|
213
|
+
|
|
214
|
+
logger.debug('Generating ccipSend tx to router:', router)
|
|
215
|
+
logger.debug('Total value:', totalValue.toString(), 'nanotons')
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
to: router,
|
|
219
|
+
body: ccipSendCell,
|
|
220
|
+
value: totalValue,
|
|
221
|
+
}
|
|
222
|
+
}
|
package/src/ton/types.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { toBigInt } from 'ethers'
|
|
|
3
3
|
|
|
4
4
|
import { CCIPDataFormatUnsupportedError } from '../errors/specialized.ts'
|
|
5
5
|
import type { EVMExtraArgsV2 } from '../extra-args.ts'
|
|
6
|
-
import type { CCIPMessage_V1_6, ChainFamily,
|
|
6
|
+
import type { CCIPMessage_V1_6, ChainFamily, ExecutionInput } from '../types.ts'
|
|
7
7
|
import { bytesToBuffer } from '../utils.ts'
|
|
8
8
|
|
|
9
9
|
/** TON-specific CCIP v1.6 message type with EVMExtraArgsV2 (GenericExtraArgsV2) */
|
|
@@ -83,7 +83,7 @@ function asSnakeData<T>(array: T[], builderFn: (item: T) => Builder): Cell {
|
|
|
83
83
|
* @returns BOC-serialized Cell containing the execution report.
|
|
84
84
|
*/
|
|
85
85
|
export function serializeExecutionReport(
|
|
86
|
-
execReport:
|
|
86
|
+
execReport: ExecutionInput<CCIPMessage_V1_6_TON>,
|
|
87
87
|
): Builder {
|
|
88
88
|
return beginCell()
|
|
89
89
|
.storeUint(execReport.message.sourceChainSelector, 64)
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AbiParametersToPrimitiveTypes, ExtractAbiEvent } from 'abitype'
|
|
2
2
|
import type { BytesLike, Log } from 'ethers'
|
|
3
3
|
|
|
4
|
+
import type { APICCIPRequestMetadata } from './api/types.ts'
|
|
4
5
|
import type OffRamp_1_6_ABI from './evm/abi/OffRamp_1_6.ts'
|
|
5
|
-
import type { CCIPMessage_EVM, CCIPMessage_V1_6_EVM } from './evm/messages.ts'
|
|
6
|
+
import type { CCIPMessage_EVM, CCIPMessage_V1_6_EVM, CCIPMessage_V2_0 } from './evm/messages.ts'
|
|
6
7
|
import type { ExtraArgs } from './extra-args.ts'
|
|
7
8
|
import type { CCIPMessage_V1_6_Solana } from './solana/types.ts'
|
|
8
9
|
import type { CCIPMessage_V1_6_Sui } from './sui/types.ts'
|
|
@@ -87,6 +88,7 @@ export const CCIPVersion = {
|
|
|
87
88
|
V1_2: '1.2.0',
|
|
88
89
|
V1_5: '1.5.0',
|
|
89
90
|
V1_6: '1.6.0',
|
|
91
|
+
V2_0: '2.0.0',
|
|
90
92
|
} as const
|
|
91
93
|
/** Type representing one of the supported CCIP versions. */
|
|
92
94
|
export type CCIPVersion = (typeof CCIPVersion)[keyof typeof CCIPVersion]
|
|
@@ -104,6 +106,17 @@ type ChainFamilyWithId<F extends ChainFamily> = F extends
|
|
|
104
106
|
|
|
105
107
|
/**
|
|
106
108
|
* Network information including chain selector and metadata.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const info: NetworkInfo = {
|
|
113
|
+
* chainSelector: 16015286601757825753n,
|
|
114
|
+
* name: 'ethereum-testnet-sepolia',
|
|
115
|
+
* networkType: 'TESTNET',
|
|
116
|
+
* family: 'EVM',
|
|
117
|
+
* chainId: 11155111,
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
107
120
|
*/
|
|
108
121
|
export type NetworkInfo<F extends ChainFamily = ChainFamily> = {
|
|
109
122
|
/** Unique chain selector used by CCIP. */
|
|
@@ -116,6 +129,16 @@ export type NetworkInfo<F extends ChainFamily = ChainFamily> = {
|
|
|
116
129
|
|
|
117
130
|
/**
|
|
118
131
|
* CCIP lane configuration connecting source and destination chains.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const lane: Lane = {
|
|
136
|
+
* sourceChainSelector: 16015286601757825753n, // Ethereum Sepolia
|
|
137
|
+
* destChainSelector: 12532609583862916517n, // Polygon Mumbai
|
|
138
|
+
* onRamp: '0x1234...abcd',
|
|
139
|
+
* version: '1.6.0',
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
119
142
|
*/
|
|
120
143
|
export interface Lane<V extends CCIPVersion = CCIPVersion> {
|
|
121
144
|
/** Source chain selector. */
|
|
@@ -131,11 +154,11 @@ export interface Lane<V extends CCIPVersion = CCIPVersion> {
|
|
|
131
154
|
/**
|
|
132
155
|
* Union type representing a CCIP message across different versions and chain families.
|
|
133
156
|
*/
|
|
134
|
-
export type CCIPMessage<V extends CCIPVersion = CCIPVersion> = V extends
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
157
|
+
export type CCIPMessage<V extends CCIPVersion = CCIPVersion> = V extends typeof CCIPVersion.V2_0
|
|
158
|
+
? CCIPMessage_V2_0
|
|
159
|
+
: V extends typeof CCIPVersion.V1_6
|
|
160
|
+
? CCIPMessage_V1_6_EVM | CCIPMessage_V1_6_Solana | CCIPMessage_V1_6_Sui | CCIPMessage_V1_6_TON
|
|
161
|
+
: CCIPMessage_EVM<V>
|
|
139
162
|
|
|
140
163
|
/**
|
|
141
164
|
* Generic log structure compatible across chain families.
|
|
@@ -149,6 +172,17 @@ export type Log_ = Pick<Log, 'topics' | 'index' | 'address' | 'blockNumber' | 't
|
|
|
149
172
|
|
|
150
173
|
/**
|
|
151
174
|
* Generic transaction structure compatible across chain families.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const tx: ChainTransaction = {
|
|
179
|
+
* hash: '0xabc123...',
|
|
180
|
+
* logs: [],
|
|
181
|
+
* blockNumber: 12345678,
|
|
182
|
+
* timestamp: 1704067200,
|
|
183
|
+
* from: '0x1234...abcd',
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
152
186
|
*/
|
|
153
187
|
export type ChainTransaction = {
|
|
154
188
|
/** Transaction hash. */
|
|
@@ -171,31 +205,77 @@ export type ChainTransaction = {
|
|
|
171
205
|
export interface CCIPRequest<V extends CCIPVersion = CCIPVersion> {
|
|
172
206
|
/** Lane configuration for this request. */
|
|
173
207
|
lane: Lane<V>
|
|
174
|
-
/** The CCIP message being sent. */
|
|
175
208
|
message: CCIPMessage<V>
|
|
176
|
-
/** Log event from the OnRamp. */
|
|
177
209
|
log: Log_
|
|
178
210
|
/** Transaction that emitted the request. */
|
|
179
211
|
tx: Pick<ChainTransaction, 'hash' | 'logs' | 'blockNumber' | 'timestamp' | 'from' | 'error'>
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* API-enriched metadata. Present only when fetched via CCIP API.
|
|
215
|
+
*
|
|
216
|
+
* @remarks
|
|
217
|
+
* When a request is fetched using {@link Chain.getMessageById} or as a fallback
|
|
218
|
+
* in {@link Chain.getMessagesInTx}, this field contains additional information
|
|
219
|
+
* including message status, execution details, and network info.
|
|
220
|
+
*
|
|
221
|
+
* When constructed from on-chain data only, this field is `undefined`.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const request = await chain.getMessageById(messageId)
|
|
226
|
+
* if (request.metadata) {
|
|
227
|
+
* console.log('Status:', request.metadata.status)
|
|
228
|
+
* console.log('Delivery time:', request.metadata.deliveryTime)
|
|
229
|
+
* }
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @see {@link APICCIPRequestMetadata}
|
|
233
|
+
*/
|
|
234
|
+
metadata?: APICCIPRequestMetadata
|
|
180
235
|
}
|
|
181
236
|
|
|
182
237
|
/**
|
|
183
|
-
* Commit report structure from the OffRamp CommitReportAccepted event.
|
|
238
|
+
* OnChain Commit report structure from the OffRamp CommitReportAccepted event.
|
|
184
239
|
*/
|
|
185
240
|
export type CommitReport = AbiParametersToPrimitiveTypes<
|
|
186
241
|
ExtractAbiEvent<typeof OffRamp_1_6_ABI, 'CommitReportAccepted'>['inputs']
|
|
187
242
|
>[0][number]
|
|
188
243
|
|
|
189
244
|
/**
|
|
190
|
-
* CCIP
|
|
245
|
+
* OffChain Verification result for a CCIP v2.0 message, returned by the indexer API.
|
|
191
246
|
*/
|
|
192
|
-
export
|
|
193
|
-
/**
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
|
|
247
|
+
export type VerifierResult = {
|
|
248
|
+
/** Verification data required for destination execution (e.g. signatures). */
|
|
249
|
+
ccvData: BytesLike
|
|
250
|
+
/** Source CCV contract address. */
|
|
251
|
+
sourceAddress: string
|
|
252
|
+
/** Destination CCV contract address. */
|
|
253
|
+
destAddress: string
|
|
254
|
+
/** Timestamp of the attestation (Unix seconds). */
|
|
255
|
+
timestamp?: number
|
|
197
256
|
}
|
|
198
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Verification data for a ccip message (onchain CommitReport, or offchain Verifications)
|
|
260
|
+
*/
|
|
261
|
+
export type CCIPVerifications =
|
|
262
|
+
| {
|
|
263
|
+
/** The commit report data. */
|
|
264
|
+
report: CommitReport
|
|
265
|
+
/** Log event from the commit. */
|
|
266
|
+
log: Log_
|
|
267
|
+
}
|
|
268
|
+
| {
|
|
269
|
+
/** Policy for this request */
|
|
270
|
+
verificationPolicy: {
|
|
271
|
+
optionalCCVs: readonly string[]
|
|
272
|
+
requiredCCVs: readonly string[]
|
|
273
|
+
optionalThreshold: number
|
|
274
|
+
}
|
|
275
|
+
/** Verifications array; one for each requiredCCV is needed for exec */
|
|
276
|
+
verifications: VerifierResult[]
|
|
277
|
+
}
|
|
278
|
+
|
|
199
279
|
/**
|
|
200
280
|
* Enumeration of possible execution states for a CCIP message.
|
|
201
281
|
*/
|
|
@@ -231,7 +311,11 @@ export const MessageStatus = {
|
|
|
231
311
|
Verifying: 'VERIFYING',
|
|
232
312
|
/** Message has been verified by the CCIP network */
|
|
233
313
|
Verified: 'VERIFIED',
|
|
234
|
-
/**
|
|
314
|
+
/**
|
|
315
|
+
* API returned an unrecognized status value.
|
|
316
|
+
* This typically means the CCIP API has new status values that this SDK version
|
|
317
|
+
* doesn't recognize. Consider updating to the latest SDK version.
|
|
318
|
+
*/
|
|
235
319
|
Unknown: 'UNKNOWN',
|
|
236
320
|
} as const
|
|
237
321
|
/** Type representing a CCIP message lifecycle status. */
|
|
@@ -254,6 +338,16 @@ export type IntentStatus = (typeof IntentStatus)[keyof typeof IntentStatus]
|
|
|
254
338
|
|
|
255
339
|
/**
|
|
256
340
|
* Receipt of a CCIP message execution on the destination chain.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const receipt: ExecutionReceipt = {
|
|
345
|
+
* messageId: '0xabc123...',
|
|
346
|
+
* sequenceNumber: 42n,
|
|
347
|
+
* state: ExecutionState.Success,
|
|
348
|
+
* sourceChainSelector: 16015286601757825753n,
|
|
349
|
+
* }
|
|
350
|
+
* ```
|
|
257
351
|
*/
|
|
258
352
|
export type ExecutionReceipt = {
|
|
259
353
|
/** Unique message identifier. */
|
|
@@ -291,25 +385,59 @@ export type OffchainTokenData = { _tag: string; [k: string]: BytesLike } | undef
|
|
|
291
385
|
|
|
292
386
|
/**
|
|
293
387
|
* Execution report containing message, proofs, and offchain token data.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const report: ExecutionReport = {
|
|
392
|
+
* message: { messageId: '0x...', ... },
|
|
393
|
+
* proofs: ['0xproof1...', '0xproof2...'],
|
|
394
|
+
* proofFlagBits: 0n,
|
|
395
|
+
* merkleRoot: '0xroot...',
|
|
396
|
+
* offchainTokenData: [],
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
294
399
|
*/
|
|
295
|
-
export type
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
400
|
+
export type ExecutionInput<M extends CCIPMessage = CCIPMessage> =
|
|
401
|
+
M extends CCIPMessage<typeof CCIPVersion.V2_0>
|
|
402
|
+
? {
|
|
403
|
+
/** encodedMessage as per CCIPv2 codec */
|
|
404
|
+
encodedMessage: M['encodedMessage']
|
|
405
|
+
/** Off-Chain verifications containing verifierResults' ccvData and ccvs addresses */
|
|
406
|
+
verifications: Pick<VerifierResult, 'ccvData' | 'destAddress'>[]
|
|
407
|
+
}
|
|
408
|
+
: {
|
|
409
|
+
/** The CCIP message to execute. */
|
|
410
|
+
message: M
|
|
411
|
+
/** Merkle proofs for the message. */
|
|
412
|
+
proofs: readonly BytesLike[]
|
|
413
|
+
/** Bit flags for proof verification. */
|
|
414
|
+
proofFlagBits: bigint
|
|
415
|
+
/** Merkle root for verification. */
|
|
416
|
+
merkleRoot: string
|
|
417
|
+
/** Offchain token data for each token transfer. */
|
|
418
|
+
offchainTokenData: readonly OffchainTokenData[]
|
|
419
|
+
}
|
|
307
420
|
|
|
308
421
|
/**
|
|
309
422
|
* A message to be sent to another network.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* const message: AnyMessage = {
|
|
427
|
+
* receiver: '0x1234...abcd',
|
|
428
|
+
* extraArgs: { gasLimit: 200_000n, allowOutOfOrderExecution: true },
|
|
429
|
+
* data: '0xdeadbeef',
|
|
430
|
+
* tokenAmounts: [{ token: '0xtoken...', amount: 1000000n }],
|
|
431
|
+
* }
|
|
432
|
+
* ```
|
|
310
433
|
*/
|
|
311
434
|
export type AnyMessage = {
|
|
312
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* Receiver address on the destination chain.
|
|
437
|
+
* Must be a valid address for the destination chain family. For instance:
|
|
438
|
+
* - EVM: 20-byte hex (e.g., `0x6d1af98d635d3121286ddda1a0c2d7078b1523ed`)
|
|
439
|
+
* - Solana: Base58 public key (e.g., `7EcDhSYGxXyscszYEp35KHN8vvw3svAuLKTzXwCFLtV`)
|
|
440
|
+
*/
|
|
313
441
|
receiver: BytesLike
|
|
314
442
|
/** Extra arguments for gas limits and other settings. */
|
|
315
443
|
extraArgs: ExtraArgs
|
|
@@ -322,7 +450,22 @@ export type AnyMessage = {
|
|
|
322
450
|
}
|
|
323
451
|
|
|
324
452
|
/**
|
|
325
|
-
* Partial
|
|
453
|
+
* Partial {@link AnyMessage}, which populates default fields like `extraArgs` if needed.
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
* ```typescript
|
|
457
|
+
* // Minimal input - only receiver required, defaults applied for extraArgs
|
|
458
|
+
* const input: MessageInput = {
|
|
459
|
+
* receiver: '0x1234...abcd',
|
|
460
|
+
* }
|
|
461
|
+
*
|
|
462
|
+
* // With custom gas limit
|
|
463
|
+
* const inputWithGas: MessageInput = {
|
|
464
|
+
* receiver: '0x1234...abcd',
|
|
465
|
+
* extraArgs: { gasLimit: 500_000n },
|
|
466
|
+
* data: '0xdeadbeef',
|
|
467
|
+
* }
|
|
468
|
+
* ```
|
|
326
469
|
*/
|
|
327
470
|
export type MessageInput = Partial<AnyMessage> & {
|
|
328
471
|
receiver: AnyMessage['receiver']
|