@eco-foundation/routes-ts
Version:
The Eco Routes Protocol is a decentralized intent based system that allows users to submit their intent to the network and have it fulfilled by a solver on the destination rollup of their choise.
64 lines (63 loc) • 2.92 kB
TypeScript
/**
* @file utils.ts
*
* Utility functions for working with Solidity ABI structures in TypeScript.
* Provides tools to extract, parse, and manipulate ABI definitions for type-safe
* interaction with smart contracts.
*/
import { Abi, AbiParameter } from 'viem';
/**
* Extracts the ABI struct definition with the given name from a contract ABI
*
* This function enables type-safe extraction of Solidity struct definitions from
* contract ABIs, which is essential for encoding and decoding complex data structures.
*
* @param abi - The contract ABI containing the struct definition
* @param structName - The name of the struct to extract
* @returns The struct component definition with proper typing
* @throws Error if the struct is not found in the ABI
*/
export declare function extractAbiStruct<AbiExt extends Abi, AbiReturn extends readonly AbiParameter[]>(abi: AbiExt, structName: string): AbiReturn;
/**
* Converts a Base58 address string to its hex representation.
* This function supports both TRON and Solana addresses, automatically detecting
* the address type and handling the conversion appropriately.
*
* @param base58Address - The Base58 encoded address string
* @returns The hex representation with 0x prefix, padded to 32 bytes (64 hex characters)
* @throws Error if the Base58 address is invalid or conversion fails
*
* @example
* ```typescript
* // TRON address
* const tronHex = base58ToHex("TQh8ig6rmuMqb5u8efU5LDvoott1oLzoqu")
* console.log(tronHex) // "0x000000000000000000000000a17fa8126b6a12feb2fe9c19f618fe04d7329074"
*
* // Solana address
* const solanaHex = base58ToHex("C34z78p3WtkDZoxtBqiKgeuC71rbnv2H7koqHmb5Eo3M")
* console.log(solanaHex) // "0xa3f83922f3081c229a9f7ff240f29f34a3548e8c7f05b6202d0d7df3de781788"
* ```
*/
export declare function base58ToHex(base58Address: string): string;
/**
* Converts a hex address string to its Base58 representation.
* This function supports both TRON and Solana address formats, with automatic detection
* based on the hex input length and content.
*
* @param hexAddress - The hex encoded address string with or without 0x prefix
* @param targetFormat - Optional format specification ('tron' | 'solana' | 'auto')
* @returns The Base58 representation
* @throws Error if the hex address is invalid or conversion fails
*
* @example
* ```typescript
* // TRON address (20 bytes padded to 32 bytes)
* const tronAddress = hexToBase58("0x000000000000000000000000a17fa8126b6a12feb2fe9c19f618fe04d7329074")
* console.log(tronAddress) // "TQh8ig6rmuMqb5u8efU5LDvoott1oLzoqu"
*
* // Solana address (32 bytes)
* const solanaAddress = hexToBase58("0xa3f83922f3081c229a9f7ff240f29f34a3548e8c7f05b6202d0d7df3de781788")
* console.log(solanaAddress) // "C34z78p3WtkDZoxtBqiKgeuC71rbnv2H7koqHmb5Eo3M"
* ```
*/
export declare function hexToBase58(hexAddress: string, targetFormat?: 'tron' | 'solana' | 'auto'): string;