import { type Transaction } from '@ton/core'; import { TonClient } from '@ton/ton'; import { type BytesLike } from 'ethers'; import type { PickDeep } from 'type-fest'; import { type ChainContext, type ChainStatic, type GetBalanceOpts, type LogFilter, type TokenTransferFeeOpts, Chain } from '../chain.ts'; import type { EVMExtraArgsV2, ExtraArgs, SVMExtraArgsV1, SuiExtraArgsV1 } from '../extra-args.ts'; import type { LeafHasher } from '../hasher/common.ts'; import { type AnyMessage, type CCIPExecution, type CCIPMessage, type CCIPRequest, type ChainLog, type ChainTransaction, type CommitReport, type ExecutionReceipt, type Lane, type NetworkInfo, type WithLogger, CCIPVersion, ChainFamily } from '../types.ts'; import { type UnsignedTONTx } from './types.ts'; export type { TONWallet, UnsignedTONTx } from './types.ts'; /** * TON chain implementation supporting TON networks. * * TON uses two different ordering concepts: * - `seqno` (sequence number): The actual block number in the blockchain * - `lt` (logical time): A per-account transaction ordering timestamp * * This implementation uses `lt` for the `blockNumber` field in logs and transactions * because TON's transaction APIs are indexed by `lt`, not `seqno`. The `lt` is * monotonically increasing per account and suitable for pagination and ordering. */ export declare class TONChain extends Chain { static readonly family: "TON"; static readonly decimals = 9; static readonly extraArgGasLimitMin: bigint; readonly rateLimitedFetch: typeof fetch; readonly provider: TonClient; /** * Creates a new TONChain instance. * @param client - TonClient instance. * @param network - Network information for this chain. * @param ctx - Context containing logger. */ constructor(client: TonClient, network: NetworkInfo, ctx?: ChainContext & { fetchFn?: typeof fetch; }); /** * Detect client network and instantiate a TONChain instance. * @param client - TonClient instance connected to the TON network. * @param ctx - Optional chain context with logger, API client, and fetch function. * @returns TONChain instance configured for the detected network (mainnet or testnet). */ static fromClient(client: TonClient, ctx?: ChainContext & { fetchFn?: typeof fetch; }): Promise; /** * Creates a TONChain instance from an RPC URL. * Verifies the connection and detects the network. * * @param url - RPC endpoint URL for TonClient (v2). * @param ctx - Context containing logger. * @returns A new TONChain instance. * @throws {@link CCIPHttpError} if connection to the RPC endpoint fails */ static fromUrl(url: string, ctx?: ChainContext): Promise; /** * Fetch the timestamp for a given logical time (lt) or finalized block. * * Note: For TON, the `block` parameter represents logical time (lt), not block seqno. * This is because TON transaction APIs are indexed by lt. The lt must have been * previously cached via getLogs or getTransaction calls. * * @param block - Logical time (lt) as number, or 'finalized' for latest block timestamp * @returns Unix timestamp in seconds * @throws {@link CCIPNotImplementedError} if lt is not in cache */ getBlockTimestamp(block: number | 'finalized'): Promise; /** * Fetches a transaction by its hash. * * Supports two formats: * 1. Composite format: "workchain:address:lt:hash" (e.g., "0:abc123...def:12345:abc123...def") * 2. Raw hash format: 64-character hex string resolved via TonCenter V3 API * * Note: TonClient requires (address, lt, hash) for lookups. Raw hash lookups * use TonCenter's V3 index API to resolve the hash to a full identifier first. * * @param tx - Transaction identifier in either format * @returns ChainTransaction with transaction details * Note: `blockNumber` contains logical time (lt), not block seqno * @throws {@link CCIPArgumentInvalidError} if hash format is invalid * @throws {@link CCIPTransactionNotFoundError} if transaction not found */ getTransaction(tx: string | Transaction): Promise; /** * Async generator that yields logs from TON transactions. * * Note: For TON, `startBlock` and `endBlock` in opts represent logical time (lt), * not block sequence numbers. This is because TON transaction APIs are indexed by lt. * * @param opts - Log filter options (startBlock/endBlock are interpreted as lt values) * @throws {@link CCIPTopicsInvalidError} if topics format is invalid */ getLogs(opts: LogFilter): AsyncIterableIterator; /** {@inheritDoc Chain.getMessagesInBatch} */ getMessagesInBatch>(request: R, range: Pick, opts?: Pick): Promise; /** {@inheritDoc Chain.typeAndVersion} */ typeAndVersion(address: string): Promise<[type: string, version: string, typeAndVersion: string, suffix?: string | undefined]>; /** {@inheritDoc Chain.getRouterForOnRamp} */ getRouterForOnRamp(onRamp: string, destChainSelector: bigint): Promise; /** {@inheritDoc Chain.getRouterForOffRamp} */ getRouterForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise; /** * {@inheritDoc Chain.getNativeTokenForRouter} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getNativeTokenForRouter(_router: string): Promise; /** {@inheritDoc Chain.getOffRampsForRouter} */ getOffRampsForRouter(router: string, sourceChainSelector: bigint): Promise; /** {@inheritDoc Chain.getOnRampForRouter} */ getOnRampForRouter(router: string, destChainSelector: bigint): Promise; /** * {@inheritDoc Chain.getOnRampsForOffRamp} * @throws {@link CCIPSourceChainUnsupportedError} if source chain is not configured */ getOnRampsForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise; /** * {@inheritDoc Chain.getTokenForTokenPool} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getTokenForTokenPool(_tokenPool: string): Promise; /** {@inheritDoc Chain.getTokenInfo} */ getTokenInfo(token: string): Promise<{ symbol: string; decimals: number; }>; /** {@inheritDoc Chain.getBalance} */ getBalance(opts: GetBalanceOpts): Promise; /** * {@inheritDoc Chain.getTokenAdminRegistryFor} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getTokenAdminRegistryFor(_address: string): Promise; /** * Decodes a CCIP message from a TON log event. * @param log - Log with data field. * @returns Decoded CCIPMessage, or undefined if the data is not a valid CCIP message (parse errors are caught and silently return undefined). */ static decodeMessage({ data, topics, }: { data: unknown; topics?: readonly string[]; }): CCIPMessage | undefined; /** * Encodes TON extra args as a BOC-serialized cell. * * BOC serialization preserves nested refs, which is required for SVM and Sui * extra args that use snaked cells. * * @param args - Extra arguments containing gas limit and execution flags * @returns Hex string of BOC-encoded extra args (0x-prefixed) */ static encodeExtraArgs(args: ExtraArgs): string; /** * Decodes TON extra arguments. * Accepts BOC-serialized cells for all supported variants and legacy raw * GenericExtraArgsV2 bits for backward compatibility. * * @param extraArgs - Extra args as hex string or bytes * @returns Decoded TON extra args object or undefined if invalid */ static decodeExtraArgs(extraArgs: BytesLike): (EVMExtraArgsV2 & { _tag: 'EVMExtraArgsV2'; }) | (SVMExtraArgsV1 & { _tag: 'SVMExtraArgsV1'; }) | (SuiExtraArgsV1 & { _tag: 'SuiExtraArgsV1'; }) | undefined; /** * Decodes commit reports from a TON log event (CommitReportAccepted). * * @param log - Log with data field (base64-encoded BOC). * @param lane - Optional lane info for filtering. * @returns Array of CommitReport or undefined if not a valid commit event. */ static decodeCommits({ data, topics }: { data: unknown; topics?: readonly string[]; }, lane?: Lane): CommitReport[] | undefined; /** * Decodes an execution receipt from a TON log event. * * The ExecutionStateChanged event structure (topic is in message header, not body): * - sourceChainSelector: uint64 (8 bytes) * - sequenceNumber: uint64 (8 bytes) * - messageId: uint256 (32 bytes) * - state: uint8 (1 byte) - InProgress=1, Success=2, Failed=3 * * @param log - Log with data field (base64-encoded BOC). * @returns ExecutionReceipt or undefined if not valid. */ static decodeReceipt({ data, topics, }: { data: unknown; topics?: readonly string[]; }): ExecutionReceipt | undefined; /** * Converts bytes to a TON address. * Handles: * - 36-byte CCIP format: workchain(4 bytes, big-endian) + hash(32 bytes) * - 33-byte format: workchain(1 byte) + hash(32 bytes) * - 32-byte format: hash only (assumes workchain 0) * Also handles user-friendly format strings (e.g., "EQ...", "UQ...", "kQ...", "0Q...") * and raw format strings ("workchain:hash"). * @param bytes - Bytes or string to convert. * @returns TON raw address string in format "workchain:hash". * @throws {@link CCIPArgumentInvalidError} if bytes length is invalid */ static getAddress(bytes: BytesLike): string; /** * Formats a TON address for human-friendly display. * Converts raw format (workchain:hash) to user-friendly format (EQ..., UQ..., etc.) * @param address - Address in any recognized format * @returns User-friendly TON address string */ static formatAddress(address: string): string; /** * Formats a TON transaction hash for human-friendly display. * Extracts the raw 64-char hash from composite format for cleaner display. * @param hash - Transaction hash in composite or raw format * @returns The raw 64-char hex hash for display */ static formatTxHash(hash: string): string; /** * Validates a transaction hash format for TON. * Supports: * - Raw 64-char hex hash (with or without 0x prefix) * - Composite format: "workchain:address:lt:hash" */ static isTxHash(v: unknown): v is string; /** * Returns a copy of a message, populating missing fields like `extraArgs` with defaults. * Ensures TON-bound messages satisfy the minimum destination gas requirement. * * @param message - AnyMessage (from source), containing at least `receiver` * @returns A message suitable for `sendMessage` to a TON destination chain * @throws {@link CCIPArgumentInvalidError} if extraArgs.gasLimit is below the TON minimum */ static buildMessageForDest(message: Parameters[0]): AnyMessage; /** * Gets the leaf hasher for TON destination chains. * @param lane - Lane configuration. * @param _ctx - Context containing logger. * @returns Leaf hasher function. */ static getDestLeafHasher(lane: Lane, _ctx?: WithLogger): LeafHasher; /** {@inheritDoc Chain.getFee} */ getFee({ router, destChainSelector, message, }: Parameters[0]): Promise; /** {@inheritDoc Chain.generateUnsignedSendMessage} */ generateUnsignedSendMessage({ router, destChainSelector, message, sender, }: Parameters[0]): Promise; /** {@inheritDoc Chain.sendMessage} */ sendMessage({ router, destChainSelector, message, wallet, }: Parameters[0]): Promise; /** * {@inheritDoc Chain.generateUnsignedExecute} * @throws {@link CCIPExtraArgsInvalidError} if extra args are not EVMExtraArgsV2 format */ generateUnsignedExecute(opts: Parameters[0]): Promise; /** * {@inheritDoc Chain.execute} * @throws {@link CCIPWalletInvalidError} if wallet is not a valid TON wallet * @throws {@link CCIPReceiptNotFoundError} if execution receipt not found within timeout */ execute(opts: Parameters[0]): Promise; /** * Parses raw TON data into typed structures. * @param data - Raw data to parse. * @returns Parsed data or undefined. */ static parse(data: unknown): (SVMExtraArgsV1 & { _tag: "SVMExtraArgsV1"; }) | (import("../extra-args.ts").EVMExtraArgsV1 & { allowOutOfOrderExecution: boolean; } & { _tag: "EVMExtraArgsV2"; }) | (import("../extra-args.ts").EVMExtraArgsV1 & { allowOutOfOrderExecution: boolean; } & { tokenReceiver: string; receiverObjectIds: string[]; } & { _tag: "SuiExtraArgsV1"; }) | undefined; /** * {@inheritDoc Chain.getSupportedTokens} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getSupportedTokens(_address: string): Promise; /** * {@inheritDoc Chain.getRegistryTokenConfig} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getRegistryTokenConfig(_address: string, _tokenName: string): Promise; /** * {@inheritDoc Chain.getTokenPoolConfig} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getTokenPoolConfig(_tokenPool: string, _feeOpts?: TokenTransferFeeOpts): Promise; /** * {@inheritDoc Chain.getTokenPoolRemotes} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getTokenPoolRemotes(_tokenPool: string): Promise; /** * {@inheritDoc Chain.getFeeTokens} * @throws {@link CCIPNotImplementedError} always (not implemented for TON) */ getFeeTokens(_router: string): Promise; } //# sourceMappingURL=index.d.ts.map