UNPKG

@hyperbridge/sdk

Version:

The hyperclient SDK provides utilities for querying proofs and statuses for cross-chain requests from HyperBridge.

1,317 lines (1,309 loc) 128 kB
import { ConsolaInstance } from 'consola'; import { GraphQLClient } from 'graphql-request'; import { PublicClient, Hex, ContractFunctionArgs, Log } from 'viem'; import { ApiPromise } from '@polkadot/api'; import { SignerOptions } from '@polkadot/api/types'; import { Chain } from 'viem/chains'; declare const _default: { ABI: readonly [{ readonly inputs: readonly []; readonly name: "ChallengePeriodNotElapsed"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "ConsensusClientExpired"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "DuplicateMessage"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "HostFrozen"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "InvalidMessageDestination"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "InvalidProof"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "MessageNotTimedOut"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "MessageTimedOut"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "StateCommitmentNotFound"; readonly type: "error"; }, { readonly inputs: readonly []; readonly name: "UnknownMessage"; readonly type: "error"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly internalType: "bytes"; readonly name: "proof"; readonly type: "bytes"; }]; readonly name: "handleConsensus"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "source"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "dest"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "nonce"; readonly type: "uint64"; }, { readonly internalType: "address"; readonly name: "from"; readonly type: "address"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }, { readonly internalType: "bytes[]"; readonly name: "keys"; readonly type: "bytes[]"; }, { readonly internalType: "uint64"; readonly name: "height"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "context"; readonly type: "bytes"; }]; readonly internalType: "struct GetRequest[]"; readonly name: "timeouts"; readonly type: "tuple[]"; }, { readonly components: readonly [{ readonly internalType: "uint256"; readonly name: "stateMachineId"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "height"; readonly type: "uint256"; }]; readonly internalType: "struct StateMachineHeight"; readonly name: "height"; readonly type: "tuple"; }, { readonly internalType: "bytes[]"; readonly name: "proof"; readonly type: "bytes[]"; }]; readonly internalType: "struct GetTimeoutMessage"; readonly name: "message"; readonly type: "tuple"; }]; readonly name: "handleGetRequestTimeouts"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "uint256"; readonly name: "stateMachineId"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "height"; readonly type: "uint256"; }]; readonly internalType: "struct StateMachineHeight"; readonly name: "height"; readonly type: "tuple"; }, { readonly internalType: "bytes32[]"; readonly name: "multiproof"; readonly type: "bytes32[]"; }, { readonly internalType: "uint256"; readonly name: "leafCount"; readonly type: "uint256"; }]; readonly internalType: "struct Proof"; readonly name: "proof"; readonly type: "tuple"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "source"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "dest"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "nonce"; readonly type: "uint64"; }, { readonly internalType: "address"; readonly name: "from"; readonly type: "address"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }, { readonly internalType: "bytes[]"; readonly name: "keys"; readonly type: "bytes[]"; }, { readonly internalType: "uint64"; readonly name: "height"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "context"; readonly type: "bytes"; }]; readonly internalType: "struct GetRequest"; readonly name: "request"; readonly type: "tuple"; }, { readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "key"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "value"; readonly type: "bytes"; }]; readonly internalType: "struct StorageValue[]"; readonly name: "values"; readonly type: "tuple[]"; }]; readonly internalType: "struct GetResponse"; readonly name: "response"; readonly type: "tuple"; }, { readonly internalType: "uint256"; readonly name: "index"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "kIndex"; readonly type: "uint256"; }]; readonly internalType: "struct GetResponseLeaf[]"; readonly name: "responses"; readonly type: "tuple[]"; }]; readonly internalType: "struct GetResponseMessage"; readonly name: "message"; readonly type: "tuple"; }]; readonly name: "handleGetResponses"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "source"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "dest"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "nonce"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "from"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "to"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "body"; readonly type: "bytes"; }]; readonly internalType: "struct PostRequest[]"; readonly name: "timeouts"; readonly type: "tuple[]"; }, { readonly components: readonly [{ readonly internalType: "uint256"; readonly name: "stateMachineId"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "height"; readonly type: "uint256"; }]; readonly internalType: "struct StateMachineHeight"; readonly name: "height"; readonly type: "tuple"; }, { readonly internalType: "bytes[]"; readonly name: "proof"; readonly type: "bytes[]"; }]; readonly internalType: "struct PostRequestTimeoutMessage"; readonly name: "message"; readonly type: "tuple"; }]; readonly name: "handlePostRequestTimeouts"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "uint256"; readonly name: "stateMachineId"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "height"; readonly type: "uint256"; }]; readonly internalType: "struct StateMachineHeight"; readonly name: "height"; readonly type: "tuple"; }, { readonly internalType: "bytes32[]"; readonly name: "multiproof"; readonly type: "bytes32[]"; }, { readonly internalType: "uint256"; readonly name: "leafCount"; readonly type: "uint256"; }]; readonly internalType: "struct Proof"; readonly name: "proof"; readonly type: "tuple"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "source"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "dest"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "nonce"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "from"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "to"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "body"; readonly type: "bytes"; }]; readonly internalType: "struct PostRequest"; readonly name: "request"; readonly type: "tuple"; }, { readonly internalType: "uint256"; readonly name: "index"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "kIndex"; readonly type: "uint256"; }]; readonly internalType: "struct PostRequestLeaf[]"; readonly name: "requests"; readonly type: "tuple[]"; }]; readonly internalType: "struct PostRequestMessage"; readonly name: "request"; readonly type: "tuple"; }]; readonly name: "handlePostRequests"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "source"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "dest"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "nonce"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "from"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "to"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "body"; readonly type: "bytes"; }]; readonly internalType: "struct PostRequest"; readonly name: "request"; readonly type: "tuple"; }, { readonly internalType: "bytes"; readonly name: "response"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }]; readonly internalType: "struct PostResponse[]"; readonly name: "timeouts"; readonly type: "tuple[]"; }, { readonly components: readonly [{ readonly internalType: "uint256"; readonly name: "stateMachineId"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "height"; readonly type: "uint256"; }]; readonly internalType: "struct StateMachineHeight"; readonly name: "height"; readonly type: "tuple"; }, { readonly internalType: "bytes[]"; readonly name: "proof"; readonly type: "bytes[]"; }]; readonly internalType: "struct PostResponseTimeoutMessage"; readonly name: "message"; readonly type: "tuple"; }]; readonly name: "handlePostResponseTimeouts"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "contract IIsmpHost"; readonly name: "host"; readonly type: "address"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "uint256"; readonly name: "stateMachineId"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "height"; readonly type: "uint256"; }]; readonly internalType: "struct StateMachineHeight"; readonly name: "height"; readonly type: "tuple"; }, { readonly internalType: "bytes32[]"; readonly name: "multiproof"; readonly type: "bytes32[]"; }, { readonly internalType: "uint256"; readonly name: "leafCount"; readonly type: "uint256"; }]; readonly internalType: "struct Proof"; readonly name: "proof"; readonly type: "tuple"; }, { readonly components: readonly [{ readonly components: readonly [{ readonly components: readonly [{ readonly internalType: "bytes"; readonly name: "source"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "dest"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "nonce"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "from"; readonly type: "bytes"; }, { readonly internalType: "bytes"; readonly name: "to"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }, { readonly internalType: "bytes"; readonly name: "body"; readonly type: "bytes"; }]; readonly internalType: "struct PostRequest"; readonly name: "request"; readonly type: "tuple"; }, { readonly internalType: "bytes"; readonly name: "response"; readonly type: "bytes"; }, { readonly internalType: "uint64"; readonly name: "timeoutTimestamp"; readonly type: "uint64"; }]; readonly internalType: "struct PostResponse"; readonly name: "response"; readonly type: "tuple"; }, { readonly internalType: "uint256"; readonly name: "index"; readonly type: "uint256"; }, { readonly internalType: "uint256"; readonly name: "kIndex"; readonly type: "uint256"; }]; readonly internalType: "struct PostResponseLeaf[]"; readonly name: "responses"; readonly type: "tuple[]"; }]; readonly internalType: "struct PostResponseMessage"; readonly name: "response"; readonly type: "tuple"; }]; readonly name: "handlePostResponses"; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly inputs: readonly [{ readonly internalType: "bytes4"; readonly name: "interfaceId"; readonly type: "bytes4"; }]; readonly name: "supportsInterface"; readonly outputs: readonly [{ readonly internalType: "bool"; readonly name: ""; readonly type: "bool"; }]; readonly stateMutability: "view"; readonly type: "function"; }]; }; declare class ChainConfigService { private rpcUrls; constructor(env?: NodeJS.ProcessEnv); getChainConfig(chain: string): ChainConfig; getIntentGatewayAddress(chain: string): `0x${string}`; getTokenGatewayAddress(chain: string): `0x${string}`; getHostAddress(chain: string): `0x${string}`; getWrappedNativeAssetWithDecimals(chain: string): { asset: HexString; decimals: number; }; getDaiAsset(chain: string): HexString; getUsdtAsset(chain: string): HexString; getUsdcAsset(chain: string): HexString; getChainId(chain: string): number; getConsensusStateId(chain: string): HexString; getHyperbridgeChainId(): number; getRpcUrl(chain: string): string; getUniswapRouterV2Address(chain: string): HexString; getUniswapV2FactoryAddress(chain: string): HexString; getUniswapV3FactoryAddress(chain: string): HexString; getUniversalRouterAddress(chain: string): HexString; getUniswapV3QuoterAddress(chain: string): HexString; getUniswapV4QuoterAddress(chain: string): HexString; getPermit2Address(chain: string): HexString; getCoingeckoId(chain: string): string | undefined; getEtherscanApiKey(): string | undefined; getCalldispatcherAddress(chain: string): HexString; } /** * The default address used as fallback when no address is provided. * This represents the zero address in EVM chains. */ declare const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000"; /** * Parameters for an EVM chain. */ interface EvmChainParams { /** * The chain ID of the EVM chain */ chainId: number; /** * The RPC URL of the EVM chain */ rpcUrl: string; /** * The host address of the EVM chain (IsmpHost contract address) */ host: HexString; /** * Consensus state identifier of this chain on hyperbridge */ consensusStateId?: string; } /** * Encapsulates an EVM chain. */ declare class EvmChain implements IChain { private readonly params; private publicClient; private chainConfigService; constructor(params: EvmChainParams); get client(): PublicClient; get host(): HexString; get config(): IEvmConfig; get configService(): ChainConfigService; /** * Derives the key for the request receipt. * @param {HexString} commitment - The commitment to derive the key from. * @returns {HexString} The derived key. */ requestReceiptKey(commitment: HexString): HexString; /** * Queries the request receipt. * @param {HexString} commitment - The commitment to query. * @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request. */ queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>; /** * Queries the proof of the commitments. * @param {IMessage} message - The message to query. * @param {string} counterparty - The counterparty address. * @param {bigint} [at] - The block number to query at. * @returns {Promise<HexString>} The proof. */ queryProof(message: IMessage, counterparty: string, at?: bigint): Promise<HexString>; /** * Query and return the encoded storage proof for the provided keys at the given height. * @param {bigint} at - The block height at which to query the storage proof. * @param {HexString[]} keys - The keys for which to query the storage proof. * @param {HexString} address - Optional contract address to fetch storage proof else default to host contract * @returns {Promise<HexString>} The encoded storage proof. */ queryStateProof(at: bigint, keys: HexString[], address?: HexString): Promise<HexString>; /** * Returns the current timestamp of the chain. * @returns {Promise<bigint>} The current timestamp. */ timestamp(): Promise<bigint>; /** * Get the latest state machine height for a given state machine ID. * @param {StateMachineIdParams} stateMachineId - The state machine ID. * @returns {Promise<bigint>} The latest state machine height. */ latestStateMachineHeight(stateMachineId: StateMachineIdParams): Promise<bigint>; /** * Get the state machine update time for a given state machine height. * @param {StateMachineHeight} stateMachineHeight - The state machine height. * @returns {Promise<bigint>} The statemachine update time in seconds. */ stateMachineUpdateTime(stateMachineHeight: StateMachineHeight): Promise<bigint>; /** * Get the challenge period for a given state machine id. * @param {StateMachineIdParams} stateMachineId - The state machine ID. * @returns {Promise<bigint>} The challenge period in seconds. */ challengePeriod(stateMachineId: StateMachineIdParams): Promise<bigint>; /** * Encodes an ISMP message for the EVM chain. * @param {IIsmpMessage} message The ISMP message to encode. * @returns {HexString} The encoded calldata. */ encode(message: IIsmpMessage): HexString; /** * Calculates the fee required to send a post request to the destination chain. * The fee is calculated based on the per-byte fee for the destination chain * multiplied by the size of the request body. * * @param request - The post request to calculate the fee for * @returns The total fee in wei required to send the post request */ quote(request: IPostRequest | IGetRequest): Promise<bigint>; quoteNative(request: IPostRequest | IGetRequest, fee: bigint): Promise<bigint>; private getAmountsIn; /** * Estimates the gas required for a post request execution on this chain. * This function generates mock proofs for the post request, creates a state override * with the necessary overlay root, and estimates the gas cost for executing the * handlePostRequests transaction on the handler contract. * * @param request - The post request to estimate gas for * @param paraId - The ID of the parachain (Hyperbridge) that will process the request * @returns The estimated gas amount in gas units and the generated calldata */ estimateGas(request: IPostRequest): Promise<{ gas: bigint; postRequestCalldata: HexString; }>; /** * Gets the fee token address and decimals for the chain. * This function gets the fee token address and decimals for the chain. * * @returns The fee token address and decimals */ getFeeTokenWithDecimals(): Promise<{ address: HexString; decimals: number; }>; /** * Gets the nonce of the host. * This function gets the nonce of the host. * * @returns The nonce of the host */ getHostNonce(): Promise<bigint>; } /** * Factory function for creating EVM chain instances with common defaults * * @param chainId - The EVM chain ID * @param host - The IsmpHost contract address * @param options - Optional configuration overrides * @returns A new EvmChain instance * * @example * ```typescript * // Create with minimal config * const ethChain = createEvmChain(1, "0x87ea45..", { * rpcUrl: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY" * }) * * // Create with custom consensus state ID * const arbChain = createEvmChain(42161, "0x87ea42345..", { * rpcUrl: "https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY", * consensusStateId: "ARB_CUSTOM" * }) * ``` */ declare function createEvmChain(chainId: number, host: HexString, options: { rpcUrl: string; consensusStateId?: string; }): EvmChain; /** * Slot for storing request commitments. */ declare const REQUEST_COMMITMENTS_SLOT = 0n; /** * Slot index for response commitments map */ declare const RESPONSE_COMMITMENTS_SLOT = 1n; /** * Slot index for requests receipts map */ declare const REQUEST_RECEIPTS_SLOT = 2n; /** * Slot index for response receipts map */ declare const RESPONSE_RECEIPTS_SLOT = 3n; /** * Slot index for state commitment map */ declare const STATE_COMMITMENTS_SLOT = 5n; declare function requestCommitmentKey(key: Hex): { slot1: Hex; slot2: Hex; }; /** * Derives the storage slot for a specific field in the StateCommitment struct * * struct StateCommitment { * uint256 timestamp; // slot + 0 * bytes32 overlayRoot; // slot + 1 * bytes32 stateRoot; // slot + 2 * } * * @param stateMachineId - The state machine ID * @param height - The block height * @param field - The field index in the struct (0 for timestamp, 1 for overlayRoot, 2 for stateRoot) * @returns The storage slot for the specific field */ declare function getStateCommitmentFieldSlot(stateMachineId: bigint, height: bigint, field: 0 | 1 | 2): HexString; declare function getStateCommitmentSlot(stateMachineId: bigint, height: bigint): HexString; /** * Generates a Merkle Mountain Range (MMR) root hash and proof for a post request. * * This function takes a post request and tree size, encodes it according to the PostRequest format, * and generates both the MMR root hash and a proof. The function builds an MMR with `treeSize` leaves, * where most leaves are variations of the encoded request (XORed with their index), except for the * last leaf, which is the unmodified request. The proof is generated for this unmodified leaf. * * @param postRequest - The post request to generate the MMR root and proof for * @param treeSize - Controls how many leaves will be added to the MMR (exactly `treeSize` leaves) * @returns An object containing: * - root: The MMR root hash as a hex string * - proof: An array of hex strings representing the MMR proof for the unmodified request * - index: The index of the unmodified request in the MMR * - kIndex: The k-index of the unmodified request in the MMR * - treeSize: The number of leaves in the MMR * - mmrSize: The size of the MMR in nodes */ declare function generateRootWithProof(postRequest: IPostRequest, treeSize: bigint): Promise<{ root: HexString; proof: HexString[]; index: bigint; kIndex: bigint; treeSize: bigint; mmrSize: bigint; }>; declare function __test(): Promise<string>; type IStateMachine = { tag: "Evm"; value: number; } | { tag: "Polkadot"; value: number; } | { tag: "Kusama"; value: number; } | { tag: "Substrate"; value: number[]; } | { tag: "Tendermint"; value: number[]; }; declare const ADDRESS_ZERO: HexString; declare const DUMMY_PRIVATE_KEY: HexString; declare const DEFAULT_GRAFFITI: HexString; /** * Returns the maximum of two bigint values * @param a - First bigint value * @param b - Second bigint value * @returns The larger of the two values */ declare function maxBigInt(a: bigint, b: bigint): bigint; /** * Calculates the commitment hash for a post request. * @param post The post request to calculate the commitment hash for. * @returns The commitment hash and the encode packed data. */ declare function postRequestCommitment(post: IPostRequest): { commitment: HexString; encodePacked: HexString; }; declare function orderCommitment(order: Order): HexString; /** * Converts a bytes32 token address to bytes20 format * This removes the extra padded zeros from the address */ declare function bytes32ToBytes20(bytes32Address: string): HexString; declare function bytes20ToBytes32(bytes20Address: string): HexString; declare function hexToString(hex: string): string; /** * Retries a promise-returning operation with exponential backoff. * This function will attempt to execute the operation up to maxRetries times, * with an exponential backoff delay between attempts. * * @param operation The async operation to retry * @param retryConfig Configuration object containing retry parameters * @returns Promise that resolves with the operation result or rejects with the last error */ declare function retryPromise<T>(operation: () => Promise<T>, retryConfig: RetryConfig): Promise<T>; /** * Calculates the commitment hash for a get request. * @param get The get request to calculate the commitment hash for. * @returns The commitment hash. */ declare function getRequestCommitment(get: IGetRequest): HexString; /** * Estimates the gas required for a post request transaction on the source chain. * This function constructs a post request, generates mock proofs, and estimates * the gas cost for executing the transaction on the source chain. */ declare function estimateGasForPost(params: { postRequest: IPostRequest; sourceClient: PublicClient; hostLatestStateMachineHeight: bigint; hostAddress: HexString; }): Promise<{ gas_fee: bigint; call_data: EstimateGasCallData; }>; /** * Constructs the request body for a redeem escrow operation. * This function encodes the order commitment, beneficiary address, and token inputs * to match the format expected by the IntentGateway contract. */ declare function constructRedeemEscrowRequestBody(order: Order, beneficiary: HexString): HexString; declare function fetchPrice(identifier: string, chainId?: number, apiKey?: string): Promise<number>; /** * Fetches the current network gas price from an Etherscan-family explorer API. * Returns the ProposeGasPrice (in gwei) converted to wei as bigint. */ declare function getGasPriceFromEtherscan(chainId: string, apiKey?: string): Promise<bigint>; /** * ERC20 method signatures used for storage slot detection */ declare enum ERC20Method { /** ERC20 balanceOf(address) method signature */ BALANCE_OF = "0x70a08231", /** ERC20 allowance(address,address) method signature */ ALLOWANCE = "0xdd62ed3e" } /** * Retrieves the storage slot for a contract call using debug_traceCall * * This function uses the Ethereum debug API to trace contract execution and identify * the storage slot accessed during the call. It's commonly used for ERC20 token state * mappings like balanceOf and allowance, but can work with any contract call that * performs SLOAD operations. * * @param client - The viem PublicClient instance connected to an RPC node with debug API enabled * @param tokenAddress - The address of the contract to trace * @param data - The full encoded function call data (method signature + encoded parameters) * @returns The storage slot as a hex string * @throws Error if the storage slot cannot be found or if debug API is not available * * @example * ```ts * import { ERC20Method, bytes20ToBytes32 } from '@hyperbridge/sdk' * * // Get balance storage slot for ERC20 * const balanceData = ERC20Method.BALANCE_OF + bytes20ToBytes32(userAddress).slice(2) * const balanceSlot = await getStorageSlot( * client, * tokenAddress, * balanceData as HexString * ) * * // Get allowance storage slot for ERC20 * const allowanceData = ERC20Method.ALLOWANCE + * bytes20ToBytes32(ownerAddress).slice(2) + * bytes20ToBytes32(spenderAddress).slice(2) * const allowanceSlot = await getStorageSlot( * client, * tokenAddress, * allowanceData as HexString * ) * ``` */ declare function getStorageSlot(client: PublicClient, contractAddress: HexString, data: HexString): Promise<string>; /** * Adjusts fee amounts between different decimal precisions. * Handles scaling up or down based on the decimal difference. * * @param feeInFeeToken - The fee amount to adjust * @param fromDecimals - The current decimal precision * @param toDecimals - The target decimal precision * @returns The adjusted fee amount with the target decimal precision */ declare function adjustFeeDecimals(feeInFeeToken: bigint, fromDecimals: number, toDecimals: number): bigint; /** * Chains that should prefer the Etherscan API for gas price lookup */ declare const USE_ETHERSCAN_CHAINS: Set<string>; /** * Testnet chains */ declare const TESTNET_CHAINS: Set<string>; declare class SubstrateChain implements IChain { private readonly params; api?: ApiPromise; private rpcClient; constructor(params: ISubstrateConfig); get config(): ISubstrateConfig; connect(): Promise<void>; /** * Disconnects the Substrate chain connection. */ disconnect(): Promise<void>; /** * Returns the storage key for a request receipt in the child trie * The request commitment is the key * @param key - The H256 hash key (as a 0x-prefixed hex string) * @returns The storage key as a hex string */ requestReceiptKey(key: HexString): HexString; /** * Returns the storage key for a request commitment in the child trie * The request commitment is the key * @param key - The H256 hash key (as a 0x-prefixed hex string) * @returns The storage key as a hex string */ requestCommitmentKey(key: HexString): HexString; /** * Queries a request commitment from the ISMP child trie storage. * @param {HexString} commitment - The commitment hash to look up. * @returns {Promise<HexString | undefined>} The commitment data if found, undefined otherwise. */ queryRequestCommitment(commitment: HexString): Promise<HexString | undefined>; /** * Queries the request receipt. * @param {HexString} commitment - The commitment to query. * @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request. */ queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>; /** * Returns the current timestamp of the chain. * @returns {Promise<bigint>} The current timestamp. */ timestamp(): Promise<bigint>; /** * Queries the proof of the commitments. * @param {IMessage} message - The message to query. * @param {string} counterparty - The counterparty address. * @param {bigint} [at] - The block number to query at. * @returns {Promise<HexString>} The proof. */ queryProof(message: IMessage, counterparty: string, at?: bigint): Promise<HexString>; /** * Submit an unsigned ISMP transaction to the chain. Resolves when the transaction is finalized. * @param message - The message to be submitted. * @returns A promise that resolves to an object containing the transaction hash, block hash, and block number. */ submitUnsigned(message: IIsmpMessage): Promise<{ transactionHash: string; blockHash: string; blockNumber: number; timestamp: number; }>; /** * Query the state proof for a given set of keys at a specific block height. * @param at The block height to query the state proof at. * @param keys The keys to query the state proof for. * @returns The state proof as a hexadecimal string. */ queryStateProof(at: bigint, keys: HexString[]): Promise<HexString>; /** * Get the latest state machine height for a given state machine ID. * @param {StateMachineIdParams} stateMachineId - The state machine ID. * @returns {Promise<bigint>} The latest state machine height. */ latestStateMachineHeight(stateMachineId: StateMachineIdParams): Promise<bigint>; /** * Get the state machine update time for a given state machine height. * @param {StateMachineHeight} stateMachineHeight - The state machine height. * @returns {Promise<bigint>} The statemachine update time in seconds. */ stateMachineUpdateTime(stateMachineHeight: StateMachineHeight): Promise<bigint>; /** * Get the challenge period for a given state machine id. * @param {StateMachineIdParams} stateMachineId - The state machine ID. * @returns {Promise<bigint>} The challenge period in seconds. */ challengePeriod(stateMachineId: StateMachineIdParams): Promise<bigint>; /** * Encode an ISMP calldata for a substrate chain. * @param message The ISMP message to encode. * @returns The encoded message as a hexadecimal string. */ encode(message: IIsmpMessage): HexString; /** * Returns the index of a pallet by its name, by looking up the pallets in the runtime metadata. * @param {string} name - The name of the pallet. * @returns {number} The index of the pallet. */ private getPalletIndex; } /** * Converts a state machine ID string to an enum value. * @param {string} id - The state machine ID string. * @returns {IStateMachine} The corresponding enum value. */ declare function convertStateMachineIdToEnum(id: string): IStateMachine; /** * Converts a state machine enum representation to a string. * @param {IStateMachine} stateMachine - The state machine enum object. * @returns {string} The state machine ID string like "EVM-97" or "SUBSTRATE-cere". */ declare function convertStateMachineEnumToString(stateMachine: { tag: string; value: number | number[]; }): string; /** * Converts a stateId object back to the state_id format used by the RPC. * @param stateId - The stateId object from StateMachineIdParams * @returns The string representation like "EVM-11155111" or "SUBSTRATE-cere" */ declare function convertStateIdToStateMachineId(stateId: { Evm?: number; Substrate?: HexString; Polkadot?: number; Kusama?: number; }): string; /** * Converts an IGetRequest object to a codec representation. * @param {IGetRequest} request - The IGetRequest object. * @returns The codec representation of the request. */ declare function convertIGetRequestToCodec(request: IGetRequest): { readonly source: IStateMachine; readonly dest: IStateMachine; readonly from: number[]; readonly nonce: bigint; readonly keys: number[][]; readonly context: number[]; readonly timeoutTimestamp: bigint; readonly height: bigint; }; /** * Convert codec representation back to IGetRequest */ declare function convertCodecToIGetRequest(codec: { source: { tag: string; value: number | number[]; }; dest: { tag: string; value: number | number[]; }; from: number[]; nonce: bigint; keys: number[][]; height: bigint; context: number[]; timeoutTimestamp: bigint; }): IGetRequest; /** * Converts an IProof object to a codec representation. * @param {IProof} proof - The IProof object. * @returns The codec representation of the proof. */ declare function convertIProofToCodec(proof: IProof): { readonly height: { readonly height: bigint; readonly id: { readonly consensusStateId: number[]; readonly id: IStateMachine; }; }; readonly proof: number[]; }; /** * Converts a codec representation back to an IProof object. * @param {any} codec - The codec representation of the proof. * @returns {IProof} The IProof object. */ declare function convertCodecToIProof(codec: { height: { height: bigint; id: { consensusStateId: number[]; id: { tag: string; value: number | number[]; }; }; }; proof: number[]; }): IProof; declare function encodeISMPMessage(message: IIsmpMessage): Uint8Array; /** * Type representing an ISMP message. */ type IIsmpMessage = IRequestMessage | ITimeoutPostRequestMessage | IGetResponseMessage | IGetRequestMessage; interface IRequestMessage { /** * The kind of message. */ kind: "PostRequest"; /** * The requests to be posted. */ requests: IPostRequest[]; /** * The proof of the requests. */ proof: IProof; /** * The signer of the message. */ signer: HexString; } interface IGetRequestMessage { /** * The kind of message. */ kind: "GetRequest"; /** * The requests to be posted. */ requests: IGetRequest[]; /** * The proof of the requests from the source chain. */ source: IProof; /** * The proof of the response from the target chain */ response: IProof; /** * The signer of the message. */ signer: HexString; } interface IGetResponse { /** * The request that triggered this response. */ get: IGetRequest; /** * The response message. */ values: GetResponseStorageValues[]; } interface IGetResponseMessage { /** * The kind of message. */ kind: "GetResponse"; /** * The responses to be posted. */ responses: IGetResponse[]; /** * The proof of the responses. */ proof: IProof; /** * The signer of the message. */ signer: HexString; } interface ITimeoutPostRequestMessage { /** * The kind of message. */ kind: "TimeoutPostRequest"; /** * The requests to be posted. */ requests: IPostRequest[]; /** * The proof of the requests. */ proof: IProof; } interface IProof { /** * The height of the proof. */ height: bigint; /** * The state machine identifier of the proof. */ stateMachine: string; /** * The associated consensus state identifier of the proof. */ consensusStateId: string; /** * The encoded storage proof */ proof: HexString; } /** * Interface representing a chain. */ interface IChain { /** * Returns the configuration for this chain */ get config(): IEvmConfig | ISubstrateConfig; timestamp(): Promise<bigint>; /** * Returns the state trie key for the request-receipt storage item for the given request commitment. */ requestReceiptKey(commitment: HexString): HexString; /** * Query and return the request-receipt for the given request commitment. */ queryRequestReceipt(commitment: HexString):