@chainlink/ccip-sdk 1.2.0 → 1.3.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/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +10 -20
- package/dist/api/index.js.map +1 -1
- package/dist/aptos/index.d.ts +2 -2
- package/dist/aptos/index.d.ts.map +1 -1
- package/dist/aptos/index.js +1 -1
- package/dist/aptos/index.js.map +1 -1
- package/dist/chain.d.ts +75 -2
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +20 -1
- package/dist/chain.js.map +1 -1
- package/dist/errors/codes.d.ts +1 -0
- package/dist/errors/codes.d.ts.map +1 -1
- package/dist/errors/codes.js +1 -0
- package/dist/errors/codes.js.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/recovery.d.ts.map +1 -1
- package/dist/errors/recovery.js +1 -0
- package/dist/errors/recovery.js.map +1 -1
- package/dist/errors/specialized.d.ts +8 -0
- package/dist/errors/specialized.d.ts.map +1 -1
- package/dist/errors/specialized.js +10 -0
- package/dist/errors/specialized.js.map +1 -1
- package/dist/evm/abi/CCTPVerifier_2_0.d.ts +1118 -0
- package/dist/evm/abi/CCTPVerifier_2_0.d.ts.map +1 -0
- package/dist/evm/abi/CCTPVerifier_2_0.js +1147 -0
- package/dist/evm/abi/CCTPVerifier_2_0.js.map +1 -0
- package/dist/evm/abi/USDCTokenPoolProxy_2_0.d.ts +825 -0
- package/dist/evm/abi/USDCTokenPoolProxy_2_0.d.ts.map +1 -0
- package/dist/evm/abi/USDCTokenPoolProxy_2_0.js +873 -0
- package/dist/evm/abi/USDCTokenPoolProxy_2_0.js.map +1 -0
- package/dist/evm/abi/VersionedVerifierResolver_2_0.d.ts +350 -0
- package/dist/evm/abi/VersionedVerifierResolver_2_0.d.ts.map +1 -0
- package/dist/evm/abi/VersionedVerifierResolver_2_0.js +370 -0
- package/dist/evm/abi/VersionedVerifierResolver_2_0.js.map +1 -0
- package/dist/evm/const.d.ts +3 -0
- package/dist/evm/const.d.ts.map +1 -1
- package/dist/evm/const.js +6 -0
- package/dist/evm/const.js.map +1 -1
- package/dist/evm/index.d.ts +24 -3
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +201 -8
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/types.d.ts +1 -1
- package/dist/evm/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/offchain.d.ts +27 -0
- package/dist/offchain.d.ts.map +1 -1
- package/dist/offchain.js +49 -7
- package/dist/offchain.js.map +1 -1
- package/dist/requests.d.ts +1 -25
- package/dist/requests.d.ts.map +1 -1
- package/dist/requests.js +2 -57
- package/dist/requests.js.map +1 -1
- package/dist/solana/index.d.ts +2 -2
- package/dist/solana/index.d.ts.map +1 -1
- package/dist/solana/index.js +2 -2
- package/dist/solana/index.js.map +1 -1
- package/dist/sui/index.d.ts +2 -2
- package/dist/sui/index.d.ts.map +1 -1
- package/dist/sui/index.js +2 -2
- package/dist/sui/index.js.map +1 -1
- package/dist/ton/index.d.ts +2 -2
- package/dist/ton/index.d.ts.map +1 -1
- package/dist/ton/index.js +28 -49
- package/dist/ton/index.js.map +1 -1
- package/dist/ton/send.d.ts +13 -1
- package/dist/ton/send.d.ts.map +1 -1
- package/dist/ton/send.js +16 -16
- package/dist/ton/send.js.map +1 -1
- package/dist/utils.d.ts +16 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -1
- package/dist/utils.js.map +1 -1
- package/package.json +7 -7
- package/src/api/index.ts +9 -23
- package/src/aptos/index.ts +5 -1
- package/src/chain.ts +86 -3
- package/src/errors/codes.ts +1 -0
- package/src/errors/index.ts +1 -0
- package/src/errors/recovery.ts +2 -0
- package/src/errors/specialized.ts +15 -0
- package/src/evm/abi/CCTPVerifier_2_0.ts +1146 -0
- package/src/evm/abi/USDCTokenPoolProxy_2_0.ts +872 -0
- package/src/evm/abi/VersionedVerifierResolver_2_0.ts +369 -0
- package/src/evm/const.ts +6 -0
- package/src/evm/index.ts +277 -10
- package/src/evm/types.ts +1 -1
- package/src/index.ts +6 -2
- package/src/offchain.ts +58 -8
- package/src/requests.ts +2 -59
- package/src/solana/index.ts +8 -2
- package/src/sui/index.ts +5 -2
- package/src/ton/index.ts +41 -56
- package/src/ton/send.ts +20 -21
- package/src/utils.ts +42 -0
package/src/ton/index.ts
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
import { Buffer } from 'buffer'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type Transaction,
|
|
5
|
+
Address,
|
|
6
|
+
BitReader,
|
|
7
|
+
BitString,
|
|
8
|
+
Cell,
|
|
9
|
+
Slice,
|
|
10
|
+
beginCell,
|
|
11
|
+
toNano,
|
|
12
|
+
} from '@ton/core'
|
|
4
13
|
import { TonClient } from '@ton/ton'
|
|
5
14
|
import { type AxiosAdapter, getAdapter } from 'axios'
|
|
6
15
|
import {
|
|
7
16
|
type BytesLike,
|
|
8
|
-
concat,
|
|
9
|
-
dataLength,
|
|
10
17
|
dataSlice,
|
|
11
18
|
hexlify,
|
|
12
19
|
isBytesLike,
|
|
13
20
|
isHexString,
|
|
14
21
|
toBeArray,
|
|
15
22
|
toBeHex,
|
|
16
|
-
toBigInt,
|
|
17
23
|
} from 'ethers'
|
|
18
24
|
import { type Memoized, memoize } from 'micro-memoize'
|
|
19
25
|
import type { PickDeep } from 'type-fest'
|
|
20
26
|
|
|
21
27
|
import { streamTransactionsForAddress } from './logs.ts'
|
|
22
|
-
import { generateUnsignedCcipSend, getFee as getFeeImpl } from './send.ts'
|
|
23
|
-
import {
|
|
28
|
+
import { encodeExtraArgsCell, generateUnsignedCcipSend, getFee as getFeeImpl } from './send.ts'
|
|
29
|
+
import {
|
|
30
|
+
type ChainContext,
|
|
31
|
+
type GetBalanceOpts,
|
|
32
|
+
type LogFilter,
|
|
33
|
+
type TokenTransferFeeOpts,
|
|
34
|
+
Chain,
|
|
35
|
+
} from '../chain.ts'
|
|
24
36
|
import {
|
|
25
37
|
CCIPArgumentInvalidError,
|
|
26
38
|
CCIPExecutionReportChainMismatchError,
|
|
@@ -56,7 +68,6 @@ import {
|
|
|
56
68
|
bytesToBuffer,
|
|
57
69
|
createRateLimitedFetch,
|
|
58
70
|
decodeAddress,
|
|
59
|
-
getDataBytes,
|
|
60
71
|
networkInfo,
|
|
61
72
|
parseTypeAndVersion,
|
|
62
73
|
sleep,
|
|
@@ -76,16 +87,6 @@ function isTvmError(error: unknown): error is Error & { exitCode: number } {
|
|
|
76
87
|
return error instanceof Error && 'exitCode' in error && typeof error.exitCode === 'number'
|
|
77
88
|
}
|
|
78
89
|
|
|
79
|
-
function bitsToBytes(bits: string): Uint8Array {
|
|
80
|
-
return Uint8Array.from(bits.match(/.{1,8}/g)!.map((byte) => parseInt(byte.padEnd(8, '0'), 2)))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function bytesToBits(bytes: Uint8Array): string {
|
|
84
|
-
return Array.from(bytes)
|
|
85
|
-
.map((B) => B.toString(2).padStart(8, '0'))
|
|
86
|
-
.join('')
|
|
87
|
-
}
|
|
88
|
-
|
|
89
90
|
/**
|
|
90
91
|
* TON chain implementation supporting TON networks.
|
|
91
92
|
*
|
|
@@ -668,24 +669,14 @@ export class TONChain extends Chain<typeof ChainFamily.TON> {
|
|
|
668
669
|
|
|
669
670
|
// Load extraArgs from ref 2
|
|
670
671
|
const extraArgsCell = bodySlice.loadRef()
|
|
671
|
-
const extraArgsSlice = extraArgsCell.beginParse()
|
|
672
|
-
|
|
673
|
-
// Read tag (32 bits)
|
|
674
|
-
const extraArgsTag = extraArgsSlice.loadUint(32)
|
|
675
|
-
if (extraArgsTag !== Number(EVMExtraArgsV2Tag)) return undefined
|
|
676
|
-
|
|
677
|
-
// Read gasLimit (maybe uint256): 1 bit flag + 256 bits if present
|
|
678
|
-
const hasGasLimit = extraArgsSlice.loadBit()
|
|
679
|
-
const gasLimit = hasGasLimit ? extraArgsSlice.loadUintBig(256) : 0n
|
|
680
|
-
|
|
681
|
-
// Read allowOutOfOrderExecution (1 bit)
|
|
682
|
-
const allowOutOfOrderExecution = extraArgsSlice.loadBit()
|
|
683
672
|
|
|
684
673
|
// Build extraArgs as raw hex matching reference format
|
|
685
|
-
const extraArgs = '0x' + extraArgsCell.
|
|
674
|
+
const extraArgs = '0x' + extraArgsCell.bits.toString().toLowerCase().replace('_', '0')
|
|
675
|
+
const parsed = this.decodeExtraArgs(extraArgs)
|
|
676
|
+
if (!parsed) return
|
|
677
|
+
const { _tag, ...extraArgsObj } = parsed
|
|
686
678
|
|
|
687
679
|
// Load tokenAmounts from ref 3
|
|
688
|
-
const _tokenAmountsCell = bodySlice.loadRef()
|
|
689
680
|
const tokenAmounts: CCIPMessage_V1_6_EVM['tokenAmounts'] = [] // TODO: FIXME: parse when implemented
|
|
690
681
|
|
|
691
682
|
// Load feeToken (inline address in body)
|
|
@@ -704,8 +695,7 @@ export class TONChain extends Chain<typeof ChainFamily.TON> {
|
|
|
704
695
|
feeTokenAmount,
|
|
705
696
|
feeValueJuels,
|
|
706
697
|
extraArgs,
|
|
707
|
-
|
|
708
|
-
allowOutOfOrderExecution,
|
|
698
|
+
...extraArgsObj,
|
|
709
699
|
}
|
|
710
700
|
} catch {
|
|
711
701
|
return undefined
|
|
@@ -723,17 +713,8 @@ export class TONChain extends Chain<typeof ChainFamily.TON> {
|
|
|
723
713
|
* @returns Hex string of BOC-encoded extra args (0x-prefixed)
|
|
724
714
|
*/
|
|
725
715
|
static encodeExtraArgs(args: ExtraArgs): string {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
EVMExtraArgsV2Tag,
|
|
729
|
-
bitsToBytes(
|
|
730
|
-
'1' +
|
|
731
|
-
bytesToBits(toBeArray(args.gasLimit, 32)) +
|
|
732
|
-
(args.allowOutOfOrderExecution ? '1' : '0'),
|
|
733
|
-
),
|
|
734
|
-
])
|
|
735
|
-
}
|
|
736
|
-
return '0x'
|
|
716
|
+
const cell = encodeExtraArgsCell(args)
|
|
717
|
+
return '0x' + cell.bits.toString().toLowerCase().replace('_', '0')
|
|
737
718
|
}
|
|
738
719
|
|
|
739
720
|
/**
|
|
@@ -751,19 +732,23 @@ export class TONChain extends Chain<typeof ChainFamily.TON> {
|
|
|
751
732
|
static decodeExtraArgs(
|
|
752
733
|
extraArgs: BytesLike,
|
|
753
734
|
): (EVMExtraArgsV2 & { _tag: 'EVMExtraArgsV2' }) | undefined {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
735
|
+
let bytes
|
|
736
|
+
try {
|
|
737
|
+
bytes = bytesToBuffer(extraArgs)
|
|
738
|
+
|
|
739
|
+
// If the data is BOC-wrapped (starts with TON BOC magic 0xb5ee9c72), extract bits
|
|
740
|
+
if (dataSlice(bytes, 0, 4) !== EVMExtraArgsV2Tag) {
|
|
741
|
+
const cell = Cell.fromBoc(bytes)[0]!
|
|
742
|
+
bytes = bytesToBuffer('0x' + cell.bits.toString().toLowerCase().replace('_', '0'))
|
|
743
|
+
}
|
|
744
|
+
if (dataSlice(bytes, 0, 4) !== EVMExtraArgsV2Tag) return
|
|
745
|
+
} catch {
|
|
746
|
+
return
|
|
764
747
|
}
|
|
765
748
|
|
|
766
|
-
const
|
|
749
|
+
const slice = new Slice(new BitReader(new BitString(bytes, 32, bytes.length * 8)), [])
|
|
750
|
+
const gasLimit = slice.loadMaybeUintBig(256) ?? 0n
|
|
751
|
+
const allowOutOfOrderExecution = slice.loadBit()
|
|
767
752
|
|
|
768
753
|
return {
|
|
769
754
|
_tag: 'EVMExtraArgsV2',
|
|
@@ -1226,7 +1211,7 @@ export class TONChain extends Chain<typeof ChainFamily.TON> {
|
|
|
1226
1211
|
* {@inheritDoc Chain.getTokenPoolConfig}
|
|
1227
1212
|
* @throws {@link CCIPNotImplementedError} always (not implemented for TON)
|
|
1228
1213
|
*/
|
|
1229
|
-
async getTokenPoolConfig(_tokenPool: string): Promise<never> {
|
|
1214
|
+
async getTokenPoolConfig(_tokenPool: string, _feeOpts?: TokenTransferFeeOpts): Promise<never> {
|
|
1230
1215
|
return Promise.reject(new CCIPNotImplementedError('getTokenPoolConfig'))
|
|
1231
1216
|
}
|
|
1232
1217
|
|
package/src/ton/send.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { type TonClient, Address } from '@ton/ton'
|
|
|
3
3
|
import { zeroPadValue } from 'ethers'
|
|
4
4
|
|
|
5
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
|
|
9
|
-
import { bytesToBuffer, getDataBytes } from '../utils.ts'
|
|
6
|
+
import { CCIPError, CCIPErrorCode, CCIPExtraArgsInvalidError } from '../errors/index.ts'
|
|
7
|
+
import { type ExtraArgs, EVMExtraArgsV2Tag } from '../extra-args.ts'
|
|
8
|
+
import { type AnyMessage, type WithLogger, ChainFamily } from '../types.ts'
|
|
9
|
+
import { bigIntReplacer, bytesToBuffer, getDataBytes } from '../utils.ts'
|
|
10
10
|
|
|
11
11
|
/** Opcode for Router ccipSend operation */
|
|
12
12
|
export const CCIP_SEND_OPCODE = 0x31768d95
|
|
@@ -51,28 +51,27 @@ function encodeTokenAmounts(
|
|
|
51
51
|
* Format per chainlink-ton TL-B:
|
|
52
52
|
* - tag: 32-bit opcode (0x181dcf10)
|
|
53
53
|
* - gasLimit: Maybe<uint256> (1 bit flag + 256 bits if present)
|
|
54
|
-
* - allowOutOfOrderExecution: 1 bit
|
|
54
|
+
* - allowOutOfOrderExecution: 1 bit
|
|
55
|
+
* @param extraArgs - Extra arguments for CCIP message
|
|
56
|
+
* @returns Cell encoding the extra arguments
|
|
55
57
|
*/
|
|
56
|
-
function encodeExtraArgsCell(extraArgs:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
export function encodeExtraArgsCell(extraArgs: ExtraArgs): Cell {
|
|
59
|
+
if (
|
|
60
|
+
Object.keys(extraArgs).filter((k) => k !== '_tag').length !== 2 ||
|
|
61
|
+
!('gasLimit' in extraArgs && 'allowOutOfOrderExecution' in extraArgs)
|
|
62
|
+
)
|
|
63
|
+
throw new CCIPExtraArgsInvalidError(ChainFamily.TON, JSON.stringify(extraArgs, bigIntReplacer))
|
|
64
|
+
|
|
65
|
+
let gasLimit: bigint | null = null
|
|
66
|
+
if (extraArgs.gasLimit > 0n) {
|
|
64
67
|
gasLimit = extraArgs.gasLimit
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
const builder = beginCell()
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (hasGasLimit) {
|
|
72
|
-
builder.storeUint(gasLimit, 256)
|
|
73
|
-
}
|
|
70
|
+
const builder = beginCell().storeUint(Number(EVMExtraArgsV2Tag), 32) // 0x181dcf10
|
|
71
|
+
builder.storeMaybeUint(gasLimit, 256)
|
|
72
|
+
builder.storeBit(extraArgs.allowOutOfOrderExecution)
|
|
74
73
|
|
|
75
|
-
return builder.
|
|
74
|
+
return builder.endCell()
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -16,12 +16,14 @@ import yaml from 'yaml'
|
|
|
16
16
|
|
|
17
17
|
import type { Chain, ChainStatic } from './chain.ts'
|
|
18
18
|
import {
|
|
19
|
+
CCIPAbortError,
|
|
19
20
|
CCIPBlockBeforeTimestampNotFoundError,
|
|
20
21
|
CCIPChainFamilyUnsupportedError,
|
|
21
22
|
CCIPChainNotFoundError,
|
|
22
23
|
CCIPDataFormatUnsupportedError,
|
|
23
24
|
CCIPError,
|
|
24
25
|
CCIPHttpError,
|
|
26
|
+
CCIPTimeoutError,
|
|
25
27
|
CCIPTypeVersionInvalidError,
|
|
26
28
|
HttpStatus,
|
|
27
29
|
} from './errors/index.ts'
|
|
@@ -815,6 +817,46 @@ export function createRateLimitedFetch(
|
|
|
815
817
|
}
|
|
816
818
|
}
|
|
817
819
|
|
|
820
|
+
/**
|
|
821
|
+
* Performs a fetch request with timeout and abort signal support.
|
|
822
|
+
*
|
|
823
|
+
* @param url - URL to fetch
|
|
824
|
+
* @param operation - Operation name for error context
|
|
825
|
+
* @param opts - Optional timeout, abort signal, fetch function, and extra RequestInit fields
|
|
826
|
+
* @returns Promise resolving to Response
|
|
827
|
+
* @throws CCIPTimeoutError if request times out
|
|
828
|
+
* @throws CCIPAbortError if request is aborted via signal
|
|
829
|
+
*/
|
|
830
|
+
export async function fetchWithTimeout(
|
|
831
|
+
url: string,
|
|
832
|
+
operation: string,
|
|
833
|
+
opts?: {
|
|
834
|
+
timeoutMs?: number
|
|
835
|
+
signal?: AbortSignal
|
|
836
|
+
fetch?: typeof globalThis.fetch
|
|
837
|
+
init?: RequestInit
|
|
838
|
+
},
|
|
839
|
+
): Promise<Response> {
|
|
840
|
+
const timeoutMs = opts?.timeoutMs ?? 30_000
|
|
841
|
+
const fetchFn = opts?.fetch ?? globalThis.fetch.bind(globalThis)
|
|
842
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs)
|
|
843
|
+
const combinedSignal = opts?.signal
|
|
844
|
+
? AbortSignal.any([timeoutSignal, opts.signal])
|
|
845
|
+
: timeoutSignal
|
|
846
|
+
|
|
847
|
+
try {
|
|
848
|
+
return await fetchFn(url, { ...opts?.init, signal: combinedSignal })
|
|
849
|
+
} catch (error) {
|
|
850
|
+
if (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) {
|
|
851
|
+
if (opts?.signal?.aborted) {
|
|
852
|
+
throw new CCIPAbortError(operation)
|
|
853
|
+
}
|
|
854
|
+
throw new CCIPTimeoutError(operation, timeoutMs)
|
|
855
|
+
}
|
|
856
|
+
throw error
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
818
860
|
// barebones `node:util` backfill, if needed
|
|
819
861
|
const util =
|
|
820
862
|
'util' in globalThis
|