UNPKG

onesec-bridge

Version:
91 lines (90 loc) 3.44 kB
import { Principal } from "@dfinity/principal"; import type { Amount, IcrcAccount, Tx } from "./types"; /** * Convert a number to a scaled bigint representation. * @param value The number to convert * @param decimals Number of decimal places to scale by * @returns Scaled bigint representation */ export declare function numberToBigintScaled(value: number, decimals: number): bigint; /** * Convert a scaled bigint to a number representation. * @param value The bigint to convert * @param decimals Number of decimal places to scale by * @returns Number representation */ export declare function bigintToNumberScaled(value: bigint, decimals: number): number; /** * Create an Amount object from a bigint value in units. * @param units Amount in token's smallest units * @param decimals Number of decimal places for the token * @returns Amount object with both unit and token representations */ export declare function amountFromUnits(units: bigint, decimals: number): Amount; /** * Create an Amount object from a number value in tokens. * @param tokens Amount in human-readable token units * @param decimals Number of decimal places for the token * @returns Amount object with both unit and token representations */ export declare function amountFromTokens(tokens: number, decimals: number): Amount; /** * Sleep for the specified number of milliseconds. * @param ms Number of milliseconds to sleep * @returns Promise that resolves after the specified time */ export declare function sleep(ms: number): Promise<void>; /** * Calculate the next delay for exponential backoff. * @param currentDelayMs Current delay in milliseconds * @param maxDelayMs Maximum delay in milliseconds (default: 10,000ms) * @returns Next delay in milliseconds */ export declare function exponentialBackoff(currentDelayMs: number, maxDelayMs?: number): number; /** * Encode an ICRC account for use in canister calls. * * Format of the first array: * - bytes[0] = tag: ICRC or account identifier. * - bytes[1..32] = encoded principal. * * Format of the second array: * - empty if there is no subaccount * - otherwise, subaccount bytes. * * @param account ICRC account to encode * @returns Tuple of encoded principal and optional subaccount */ export declare function encodeIcrcAccount(account: IcrcAccount): [Uint8Array, Uint8Array?]; /** * Encode a Principal for use in ICRC account encoding. * * Format: * - bytes[0] = 0 (ICRC account tag) * - bytes[1] = the length of the principal in bytes. * - bytes[2..length+2] = the principal itself. * - bytes[length+2..32] = zeros. * * @param p Principal to encode * @returns Encoded principal as Uint8Array */ export declare function encodePrincipal(p: Principal): Uint8Array; /** * Format a bigint amount for display with appropriate decimal precision. * @param amount Amount in smallest units * @param decimals Number of decimal places for the token * @returns Formatted string representation */ export declare function format(amount: bigint, decimals: number): string; /** * Format an ICRC account for display. * @param account ICRC account to format * @returns Human-readable string representation */ export declare function formatIcpAccount(account: IcrcAccount): string; /** * Format a transaction for display. * @param tx Transaction to format (optional) * @returns Human-readable string representation */ export declare function formatTx(tx?: Tx): string;