import { type Transaction } from '@ton/core'; import { TonClient } from '@ton/ton'; import { type BytesLike } from 'ethers'; import { type BlockInfo, type ChainContext, type ChainStatic, type GetBalanceOpts, type LogFilter, type TokenTransferFeeOpts, Chain } from '../chain.ts'; import { type UnsignedTONTx } from './types.ts'; import type { EVMExtraArgsV2, ExtraArgs, SVMExtraArgsV1, SuiExtraArgsV1 } from '../extra-args.ts'; import type { LeafHasher } from '../hasher/common.ts'; import { type NetworkInfo, ChainFamily } from '../networks.ts'; import { type AnyMessage, type CCIPExecution, type CCIPMessage, type CCIPRequest, type ChainLog, type ChainTransaction, type CommitReport, type ExecutionReceipt, type Lane, type LeanNumbers, type WithLogger, CCIPVersion } 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 masterchain * - `lt` (logical time): A per-account transaction ordering timestamp * * This implementation uses the masterchain `seqno` for the `blockNumber` field and * the message's `lt` for the `logIndex` field. The `startBlock`/`endBlock` filter * parameters accept masterchain seqnos and are converted to lt ranges internally. */ 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); /** * 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): 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; /** * Fetches the block seqno (number) for a given logical time (lt). * @internal */ getMCSeqNoByLt(lt: number | bigint): Promise; /** * Fetches the masterchain block header by seqno. * @internal */ getMCBlockHeader(block: number | bigint): Promise<{ gen_utime: number; start_lt: string; end_lt: string; min_ref_mc_seqno: number; }>; /** * Fetch the timestamp for a given masterchain block or the latest finalized block. * * @param block - Masterchain block seqno, or 'finalized'/'latest' for the latest block * @returns Unix timestamp in seconds */ getBlockInfo(block: number | bigint | 'finalized' | 'latest'): 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 * `blockNumber` is the masterchain seqno; `logIndex` is the message's lt * @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. * * `startBlock`/`endBlock` are masterchain seqnos (public interface). Internally, * they are converted to lt ranges before being passed to `streamTransactionsForAddress`, * which uses lt for TON transaction API pagination. * * @param opts - Log filter options (startBlock/endBlock are masterchain seqnos) * @throws {@link CCIPTopicsInvalidError} if topics format is invalid */ getLogs(opts: LeanNumbers): AsyncIterableIterator; /** {@inheritDoc Chain.typeAndVersion} */ typeAndVersion(address: string): Promise<[type: string, version: string, typeAndVersion: string, suffix?: string | undefined]>; /** {@inheritDoc Chain.getOnRampConfig} */ getOnRampConfig(onRamp: string, destChainSelector: bigint): Promise<{ chainSelector: bigint; destChainSelector: bigint; feeQuoter: string; feeAggregator: string; allowlistAdmin: string; reserve: bigint; router: string; sequenceNumber: bigint; allowlistEnabled: boolean; typeAndVersion: string; feeQuoterConfig: { isEnabled: boolean; maxNumberOfTokensPerMsg: number; maxDataBytes: number; maxPerMsgGasLimit: number; destGasOverhead: number; destGasPerPayloadByteBase: number; destGasPerPayloadByteHigh: number; destGasPerPayloadByteThreshold: number; destDataAvailabilityOverheadGas: number; destGasPerDataAvailabilityByte: number; destDataAvailabilityMultiplierBps: number; chainFamilySelector: number; defaultTokenFeeUsdCents: number; defaultTokenDestGasOverhead: number; defaultTxGasLimit: number; gasMultiplierWeiPerEth: bigint; gasPriceStalenessThreshold: number; networkFeeUsdCents: number; maxFeeJuelsPerMsg: bigint; linkToken: string; tokenPriceStalenessThreshold: number; usdPerUnitGas: { executionGasPrice: bigint; dataAvailabilityGasPrice: bigint; timestamp: bigint; }; }; }>; /** * {@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.getOffRampConfig} */ getOffRampConfig(offRamp: string, sourceChainSelector: bigint): Promise<{ chainSelector: bigint; sourceChainSelector: bigint; feeQuoter: string; permissionlessExecutionThresholdSeconds: number; router: string; isEnabled: boolean; minSeqNr: bigint; isRMNVerificationDisabled: boolean; onRamps: string[]; typeAndVersion: string; }>; /** {@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(opts: 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