import { pino } from 'pino'; import { KeyPair } from '@ton/crypto'; import { WalletContractV4 } from '@ton/ton'; import { ChainType, EndpointVersion, Network, Chain, EndpointId } from '@layerzerolabs/lz-definitions'; import { ethers } from 'ethers'; import { Options } from 'memoizee'; type Logger = pino.Logger; /** * Creates a replacer function for handling circular references in JSON.stringify. * details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value * * @returns {(key: string, value: unknown) => unknown} The replacer function. */ declare function getCircularReplacer(): (key: string, value: unknown) => unknown; /** * Initializes the logger with the specified log level. * * @param {string} level - The log level. */ declare function initLogger(level: string): void; /** * Creates a new logger with the specified log level. * * @param {string} level - The log level. * @returns {Logger} The created logger. */ declare function createLogger(level: string): pino.Logger; /** * Gets the current logger instance. * * @returns {Logger} The current logger instance. * @throws {Error} If the logger is not initialized. */ declare function getLogger(): Logger; /** * Interface representing an account mnemonic. */ interface AccountMnemonic { /** * The mnemonic phrase. */ mnemonic: string; /** * The derivation path. */ path: string; /** * The private key (optional). */ privateKey?: string; /** * The address (optional). */ address?: string; } /** * Gets the BIP-0044 derivation path for a given chain type. * * @param {ChainType} chainType - The chain type. * @param {number} account - The account index. * @param {number} change - The change index. * @param {number} index - The address index. * @returns {string} The BIP-0044 derivation path. * @throws {Error} If the chain type is unsupported. */ declare function getBIP044Path(chainType: ChainType, account: number, change: number, index: number): string; /** * Gets an EVM account from a mnemonic phrase. * * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path="m/44'/60'/0'/0/0"] - The derivation path. * @returns {AccountMnemonic} The EVM account mnemonic. */ declare function getEvmAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic; /** * Gets an Aptos account from a mnemonic phrase. * * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path="m/44'/637'/0'/0'/0'"] - The derivation path. * @returns {AccountMnemonic} The Aptos account mnemonic. * @throws {Error} If the derivation path is invalid. */ declare function getAptosAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic; /** * Gets an Initia account from a mnemonic phrase. * * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path="m/44'/118'/0'/0/0"] - The derivation path. * @returns {AccountMnemonic} The Initia account mnemonic. */ declare function getInitiaAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic; /** * Gets a Solana account from a mnemonic phrase. * * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path="m/44'/501'/0'/0'"] - The derivation path. * @returns {AccountMnemonic} The Solana account mnemonic. */ declare function getSolanaAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic; declare function getSuiAccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic; declare function getIotaL1AccountFromMnemonic(mnemonic: string, path?: string): AccountMnemonic; /** * Gets a TON account from a mnemonic phrase. * * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path="m/44'/607'/0'/0'/0'"] - The derivation path. * @param {number} [workchain=0] - The workChain ID. * @returns {Promise} A promise that resolves to the TON account mnemonic. */ declare function getTonAccountFromMnemonic(mnemonic: string, path?: string, workchain?: number): Promise; /** * Gets a key pair from a mnemonic phrase for a given chain type. * * @param {ChainType} chainType - The chain type. * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path] - The derivation path. * @returns {Promise} A promise that resolves to the account mnemonic. * @throws {Error} If the chain type is unsupported. */ declare function getKeypairFromMnemonic(chainType: ChainType, mnemonic: string, path?: string): Promise; /** * Gets a TON wallet from a mnemonic phrase. * * @param {string} mnemonic - The mnemonic phrase. * @param {string} [path="m/44'/607'/0'/0'/0'"] - The derivation path. * @param {number} [workchain=0] - The workChain ID. * @returns {Promise<{ wallet: WalletContractV4; keyPair: KeyPair }>} A promise that resolves to the TON wallet and key pair. */ declare function getTonWalletFromMnemonic(mnemonic: string, path?: string, workchain?: number): Promise<{ wallet: WalletContractV4; keyPair: KeyPair; }>; /** * Interface representing a contract deployment. */ interface Deployment { /** Name of the contract deployment. */ name: string; /** Optional endpoint identifier. */ compatibleVersions: EndpointVersion[]; /** Network of deployment. */ network: Network; /** Optional contract source. */ source?: string; /** Address of deployed contract. */ address: string; /** Optional contract ABI. */ abi?: string; /** Optional contract bytecode. */ bytecode?: string; } /** * Finds the matching deployment based on the given options. * @todo Use Partial instead of options * * @param {Deployment[]} deployments - List of deployments. * @param {string} nameOrAddress - Contract name or address. * @param {object} options - Options to match against. * @param {Chain} [options.chain] - The chain to match. * @param {string} [options.source] - The source to match. * @param {Network} [options.network] - The network to match. * @param {EndpointId} [options.endpointId] - The endpoint ID to match. * @returns {Deployment} The matching deployment. * @throws {Error} If the deployment is not found. */ declare function findDeployment(deployments: Deployment[], nameOrAddress: string, options: { chain?: Chain; source?: string; network?: Network; endpointId?: EndpointId; }): Deployment; /** * Tries to find the matching deployment based on the given options. * * @param {Deployment[]} deployments - List of deployments. * @param {string} nameOrAddress - Contract name or address. * @param {object} options - Options to match against. * @param {Chain} [options.chain] - The chain to match. * @param {string} [options.source] - The source to match. * @param {Network} [options.network] - The network to match. * @param {EndpointId} [options.endpointId] - The endpoint ID to match. * @returns {Deployment | undefined} The matching deployment, or undefined if not found. */ declare function tryFindDeployment(deployments: Deployment[], nameOrAddress: string, options: { chain?: Chain; source?: string; network?: Network; endpointId?: EndpointId; }): Deployment | undefined; /** * Converts a deployment to an EVM contract. * * @param {Deployment} deployment - The deployment to convert. * @param {ethers.providers.Provider} [provider] - The provider to use. * @returns {T} The EVM contract. * @throws {Error} If the deployment does not have ABI or bytecode. */ declare function deploymentToEvmContract(deployment: Deployment, provider?: ethers.providers.Provider): T; /** * Finds a contract based on the given options. * * @param {ethers.providers.Provider | undefined} provider - The provider to use. * @param {Deployment[]} deployments - List of deployments. * @param {string} nameOrAddress - Contract name or address. * @param {object} options - Options to match against. * @param {Chain} [options.chain] - The chain to match. * @param {string} [options.source] - The source to match. * @param {Network} [options.network] - The network to match. * @param {EndpointId} [options.endpointId] - The endpoint ID to match. * @returns {T} The matching contract. * @throws {Error} If the deployment is not found. */ declare function findContract(provider: ethers.providers.Provider | undefined, deployments: Deployment[], nameOrAddress: string, options: { chain?: Chain; source?: string; network?: Network; endpointId?: EndpointId; }): T; /** * Returns the directory name of a path. * * @param {string} path - The path to get the directory name from. * @returns {string} The directory name of the path. */ declare function dirname(path: string): string; /** * Returns the root path of a package. * * @param {string} packageName - The name of the package. * @param {string} [relativeToPath] - The path to resolve the package root relative to. * @returns {string} The root path of the package. */ declare function pkgroot(packageName: string, relativeToPath?: string): string; /** * Generic type for a hybrid (sync / async) factory * that generates an instance of `TOutput` based on arguments of type `TInput` * * `TInput` represents the list of all function arguments that need to be passed to the factory: * * ```typescript * const mySyncFactory: Factory<[number, boolean], string> = (num: number, bool: boolean): string => "hello" * * const mySyncFactory: Factory<[], string> = async () => "hello" * ``` * * The hybrid aspect just makes it easier for implementers - if the logic is synchronous, * this type will not force any extra `async`. */ type Factory = (...input: TInput) => TOutput | Promise; /** * Helper type for argumentless factories a.k.a. tasks */ type Task = Factory<[], T>; /** * Executes tasks in sequence, waiting for each one to finish before starting the next one * * Will resolve with the output of all tasks or reject with the first rejection. * * @param {Task[]} tasks * @returns {Promise} */ declare const sequence: (tasks: Task[]) => Promise; /** * Executes tasks in parallel * * Will resolve with the output of all tasks or reject with the any rejection. * * @param {Task[]} tasks * @returns {Promise} */ declare const parallel: (tasks: Task[]) => Promise; /** * Executes tasks in a sequence until one resolves. * * Will resolve with the output of the first task that resolves * or reject with the last rejection. * * Will reject immediatelly if no tasks have been passed * * @param {Task[]} tasks * @returns {Promise} */ declare const first: (tasks: Task[]) => Promise; /** * Helper utility for currying first() - creating a function * that behaves like first() but accepts arguments that will be passed to the factory functions * * @param {Factory[]} factories * @returns {Factory} */ declare const firstFactory: (...factories: Factory[]) => Factory; /** * Represents a type that excludes promises. * If the input type is a promise, the resulting type is `never`. * Otherwise, it is the same as the input type. */ type NonPromise = T extends Promise ? never : T; /** * Type representing a hexadecimal string prefixed with '0x'. */ type Hex = `0x${string}`; /** * Type representing a hash string prefixed with '0x'. */ type Hash = `0x${string}`; /** * Checks if a given string is a valid hexadecimal string. * @param value - The string to check. * @returns True if the string is a valid hexadecimal string, false otherwise. */ declare function isHex(value: string): value is Hex; /** * Checks if a given string is a valid hash string. * @param value - The string to check. * @returns True if the string is a valid hash string, false otherwise. */ declare function isHash(value: string): value is Hash; /** * Represents a byte array. */ type Bytes = Uint8Array; /** * Asserts that a condition is true. If the condition is false, throws an error with the provided message. * * @param {boolean} condition - The condition to assert. * @param {string} [message] - The error message to throw if the condition is false. * @throws {Error} If the condition is false. */ declare function assert(condition: boolean, message?: string): asserts condition; type Constructor = new (...args: any[]) => T; type TypeGuard = (v: unknown) => v is M; /** * Asserts that a value is of a certain type, using a type guard function. * assertType can be used to assert that a value is of a certain type, and without naming a new variable explicitly. * * @param {T} value - The value to assert the type of. * @param {(v: unknown) => v is M} fn - The type guard function. * @param {string} [message] - The error message to throw if the value is not of the expected type. * @throws {Error} If the value is not of the expected type. */ declare function assertType(value: T, typeOrGuard: TypeGuard | Constructor, message?: string): asserts value is T & M; /** * Asserts that a value is defined (not undefined or null). * * @param {T} [value] - The value to assert is defined. * @param {string} [message] - The error message to throw if the value is undefined or null. * @throws {Error} If the value is undefined or null. */ declare function assertDefined(value?: T, message?: string): asserts value is NonNullable; /** * Asserts that a value is of a certain type, using a type guard function, and returns the value. * * @param {T} value - The value to assert the type of. * @param {(v: unknown) => v is M} fn - The type guard function. * @param {string} [message] - The error message to throw if the value is not of the expected type. * @returns {M} The value, asserted to be of the expected type. * @throws {Error} If the value is not of the expected type. */ declare function asType(value: T, fn: (v: unknown) => v is M, message?: string): M; /** * Assumes that a value is of a certain type. This function does not perform any runtime checks. * * @param {unknown} value - The value to assume the type of. */ declare function assumeType(value: unknown): asserts value is T; /** * Calls a defined callback function on each element of an array, and returns an array that contains the results. * If an error occurs during the execution of the callback function, the function returns the results up to that point and the error. * * @param {T[]} elements - The array to map over. * @param {(item: T, index: number) => R} callbackfn - A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. * @returns {[R[], Error | undefined]} A tuple containing the array of results and an optional error. */ declare function safeMap(elements: T[], callbackfn: (item: T, index: number) => R): [R[], Error | undefined]; /** * Converts a string or number value to a corresponding enum value. * * @param {T} enumType - The enum object. * @param {string | number} value - The value to convert. * @returns {T[keyof T]} The converted enum value. * @throws {Error} If the value is not a valid enum value. * @example * // Usage * enum Color { * Red = 'red', * Green = 'green', * Blue = 'blue' * } * * const color: Color = asEnum(Color, 'red'); * expect(color).toBe(Color.Red); * * enum Direction { * Up = 1, * Down, * } * * const direction: Direction = asEnum(Direction, 1); * expect(direction).toBe(Direction.Up); */ declare function asEnum(enumType: T, value: string | number): T[keyof T]; /** * Interface representing the options for padding. */ interface PadOptions { /** * The direction of the padding. Defaults to undefined. */ dir?: 'left' | 'right' | undefined; /** * The size to pad to. Defaults to 32. */ size?: number | null | undefined; } /** * Type representing the return type of the padify function. */ type PadReturnType = value extends Hex ? Hex : Bytes; /** * Type representing an error when the size exceeds the padding size. */ type SizeExceedsPaddingSizeErrorType = SizeExceedsPaddingSizeError & { name: 'SizeExceedsPaddingSizeError'; }; /** * Class representing an error when the size exceeds the padding size. */ declare class SizeExceedsPaddingSizeError extends Error { name: string; constructor({ size, targetSize, type }: { size: number; targetSize: number; type: 'hex' | 'bytes'; }); } /** * Pads a hexadecimal string or byte array to a specified size. * * @param {Bytes | Hex} hexOrBytes - The hexadecimal string or byte array to pad. * @param {PadOptions} [options] - The padding options. * @param {'left' | 'right'} [options.dir] - The direction of the padding. Defaults to undefined. * @param {number} [options.size=32] - The size to pad to. Defaults to 32. * @returns {PadReturnType} The padded hexadecimal string or byte array. * @throws {SizeExceedsPaddingSizeError} If the size exceeds the padding size. */ declare function padify(hexOrBytes: value, { dir, size }?: PadOptions): PadReturnType; /** * A function to convert Uint8Array to hex string. * @deprecated use `hexlify` instead. * @param {Uint8Array} bytes - The bytes to convert. * @returns {string} Hex string without 0x prefix, e.g., '0102030405'. */ declare function bytesToHex(bytes: Uint8Array): string; /** * A function to convert hex string to Uint8Array. * @deprecated use `arrayify` instead. * @param {string} hex - Hex string, e.g., '0x0102030405' or '0102030405'. * @returns {Uint8Array} The converted Uint8Array. */ declare function hexToBytes(hex: string): Uint8Array; /** * A function to trim the prefix 0x from a hex string. * @param {string} hex - Hex string. * @returns {string} Hex string without 0x prefix. */ declare function trim0x(hex: string): string; /** * A function to ensure the prefix 0x from a hex string. * @param {string} hex - Hex string. * @returns {Hex} Hex string with 0x prefix. * @throws {Error} If the input is not a valid hex string. */ declare function ensure0x(hex: string): Hex; /** * A function to check if a string is a hex string. * @deprecated use `isHex` instead. * @param {string} value - The string to check. * @returns {boolean} True if the string is a hex string, false otherwise. */ declare function isHexString(value: string): boolean; /** * A function to convert a string|number|Uint8Array|Buffer|BigInt to Uint8Array. * @param {string | number | Uint8Array | Buffer | bigint} value - The value to convert. * @param {number} [size] - The size of the Uint8Array to return, if not specified, the size of the input will be returned. * @returns {Uint8Array} The converted Uint8Array. * @throws {Error} If the input type is unsupported. */ declare function arrayify(value: string | number | Uint8Array | Buffer | bigint, size?: number): Uint8Array; /** * A function to convert a string|number|Uint8Array|Buffer|BigInt to hex string. * @param {string | number | Uint8Array | Buffer | bigint} value - The value to convert. * @returns {Hex} The converted hex string. * @throws {Error} If the input type is unsupported. */ declare function hexlify(value: string | number | Uint8Array | Buffer | bigint): Hex; /** * Represents a type that allows partial modification of all properties in a given object type. * This type is similar to the built-in `Partial` type in TypeScript. * However, it supports deep partial modification, allowing partial modification of nested object properties. * * @typeparam T - The object type to be partially modified. */ type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; /** * Represents a type that makes all properties of the given type required deeply. * * This utility type recursively makes all properties of the given type required, including nested properties. * If a property is already required, it remains unchanged. * * @typeParam T - The type to make all properties required. * @returns A new type with all properties required. * * @example * ```typescript * type Person = { * name?: string; * age?: number; * address?: { * street?: string; * city?: string; * }; * }; * * type RequiredPerson = DeepRequired; * // Result: { * // name: string; * // age: number; * // address: { * // street: string; * // city: string; * // }; * // } * ``` */ type DeepRequired = { [P in keyof T]-?: T[P] extends object ? DeepRequired : T[P]; }; /** * Checks if an object has all the required properties specified by the given paths. * * @template T - The type of the object. * @param {DeepPartial} obj - The object to check. * @param {string[]} paths - The paths of the required properties. * @returns {boolean} - Returns true if the object has all the required properties, otherwise returns false. */ declare function hasRequiredProperties(obj: DeepPartial, paths: string[]): boolean; /** * Retrieves the nested keys of an object type. * * @typeParam T - The object type. * @returns The union of all nested keys in the object type. * * @example * // Given the following object type: * type Person = { * name: string; * age: number; * address: { * street: string; * city: string; * }; * }; * * // The `NestedKeys` type will return the following union type: * // "name" | "age" | "address" | "address.street" | "address.city" * type AllKeys = NestedKeys; */ type NestedKeys = { [K in keyof T]: T[K] extends object ? K | `${K & string}.${NestedKeys & string}` : K; }[keyof T]; /** * Creates a new type that includes only the properties from the input type `T` that are required and not nullable. * * @typeParam T - The input type. * @returns A new type that includes only the required and non-nullable properties from `T`. * * @example * // Define a type with optional and nullable properties * type Person = { * name?: string; * age?: number | null; * email: string; * }; * * // Create a new type with only the required and non-nullable properties from `Person` * type RequiredPerson = RequiredOnly; * * // `RequiredPerson` will be: * // { * // email: string; * // } */ type RequiredOnly = { [K in keyof T as Required[K] extends NonNullable[K]> ? K : never]: T[K]; }; /** * `AtLeast` ensures that at least the specified keys `K` of the type `T` are required, * while the rest of the properties are optional. * * @template T - The original type. * @template K - The keys of `T` that should be required. * * @example * interface User { * id: string; * name: string; * email?: string; * age?: number; * } * * // At least 'id' and 'name' are required, the rest are optional * const user: AtLeast = { * id: '123', * name: 'Alice', * email: 'alice@example.com' * // age are optional * }; */ type AtLeast = Partial & RequiredOnly & Required>; /** * RequireAtLeastOne helps create a type where at least one of the properties of an interface (can be any property) is required to exist. * https://learn.microsoft.com/en-us/javascript/api/@azure/keyvault-certificates/requireatleastone?view=azure-node-latest */ type RequireAtLeastOne = { [K in keyof T]-?: Required> & Partial>>; }[keyof T]; type FindUpReturnType = T extends string ? string | undefined : string[]; /** * Finds files in the current directory and its parent directories. * * @param {string | string[]} expectations - The expected file names. * @param {object} options - Options for the search. * @param {string} [options.cwd] - The current working directory. * @returns {FindUpReturnType} An array of file paths that match the expectations or a single file path or undefined. */ declare function findUp(expectations: T, options?: { cwd?: string; }): FindUpReturnType; /** * Enables TypeScript support for the specified file or module. * * @param relativeToPath - The path relative to which the TypeScript module should be resolved. * @returns void * * @remarks * This function enables TypeScript support by registering the 'ts-node' module and configuring it with the provided options. * The 'ts-node' module allows for on-the-fly TypeScript transpilation without the need for a separate build step. * * @example * enableTS(process.cwd()); */ declare function enableTS(relativeToPath: string): void; /** * Loads a JavaScript or TypeScript module. * * @param fileName - The name of the file to load. * @param relativeToPath - The path relative to which the file should be resolved. * @returns The loaded module. * * @example * // Load a JavaScript module * const myModule = await loadJSorTS('myModule.js', '/path/to/file.js'); * * // Load a TypeScript module * const myModule = await loadJSorTS('myModule.ts', '/path/to/file.js'); */ declare function loadJSorTS(fileName: string, relativeToPath: string): Promise; declare function Memoizee any>(options?: Options): MethodDecorator; /** * Extracts the element type from an array type, or returns the type itself if not an array * @template T The input type to extract from * @example * type A = ElementOf // number * type B = ElementOf // string */ type ElementOf = T extends (infer U)[] ? U : T; /** * Takes multiple inputs and returns their cartesian product as an array of tuples. * Each input can be either a single value or an array of values. * @template T Array of input types * @param inputs Rest parameter of inputs, where each input can be a single value or array * @returns Array of tuples containing all possible combinations of input elements * @example * cartesianProduct(1, ['a', 'b'], [true]) * // Returns: [[1, 'a', true], [1, 'b', true]] * * cartesianProduct(['x', 'y'], [1, 2]) * // Returns: [['x', 1], ['x', 2], ['y', 1], ['y', 2]] * * cartesianProduct() * // Returns: [] * * cartesianProduct([], []) * // Returns: [] */ declare function cartesianProduct(...inputs: T): { [K in keyof T]: ElementOf; }[]; declare const logger: Logger; /** * Sleeps for the specified timeout. * * @param {number} timeout - The timeout in milliseconds. * @returns {Promise} A promise that resolves after the timeout. */ declare function sleep(timeout: number): Promise; /** * Gets the package manager used in the project. * * @param {string} [cwd] - The current working directory. * @returns {'yarn' | 'npm' | 'pnpm'} The package manager used in the project. * @throws {Error} If no package manager is found. */ declare function getProjectPackageManager(cwd?: string): 'yarn' | 'npm' | 'pnpm'; /** * Gets the root directory of the project. * * @param {string} [cwd] - The current working directory. * @returns {string} The root directory of the project. * @throws {Error} If no root directory is found. */ declare function getProjectRootDir(cwd?: string): string; /** * Checks if an HTTP service is reachable. * * @param {string} host - The host of the HTTP service. * @param {number} port - The port of the HTTP service. * @param {number} timeout - The timeout in milliseconds. * @param {string} [path] - The path to check. * @returns {Promise} A promise that resolves to true if the service is reachable, false otherwise. */ declare function isHttpServiceReachable(host: string, port: number, timeout: number, path?: string): Promise; /** * Extracts information from a URL. * * @param {string} url - The URL to extract information from. * @returns {{ schema: 'http' | 'https'; host: string; port: string }} An object containing the schema, host, and port. * @throws {Error} If the URL is invalid. */ declare function extractUrlInfo(url: string): { schema: 'http' | 'https'; host: string; port: string; }; export { type AccountMnemonic, type AtLeast, type Bytes, type DeepPartial, type DeepRequired, type Deployment, type Factory, type Hash, type Hex, type Logger, Memoizee, type NestedKeys, type NonPromise, type PadReturnType, type RequireAtLeastOne, type RequiredOnly, SizeExceedsPaddingSizeError, type SizeExceedsPaddingSizeErrorType, arrayify, asEnum, asType, assert, assertDefined, assertType, assumeType, bytesToHex, cartesianProduct, createLogger, deploymentToEvmContract, dirname, enableTS, ensure0x, extractUrlInfo, findContract, findDeployment, findUp, first, firstFactory, getAptosAccountFromMnemonic, getBIP044Path, getCircularReplacer, getEvmAccountFromMnemonic, getInitiaAccountFromMnemonic, getIotaL1AccountFromMnemonic, getKeypairFromMnemonic, getLogger, getProjectPackageManager, getProjectRootDir, getSolanaAccountFromMnemonic, getSuiAccountFromMnemonic, getTonAccountFromMnemonic, getTonWalletFromMnemonic, hasRequiredProperties, hexToBytes, hexlify, initLogger, isHash, isHex, isHexString, isHttpServiceReachable, loadJSorTS, logger, padify, parallel, pkgroot, safeMap, sequence, sleep, trim0x, tryFindDeployment };