UNPKG

@funkit/connect

Version:

Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.

45 lines (44 loc) 1.84 kB
import type { Dnum } from 'dnum'; /** * Multiply a token amount by a float price, returning the result * as a Dnum in `resultDecimals` precision. Uses floor rounding so the * displayed value never exceeds the real value. * * @example * // 6.999920 USDC (6 dec) × $1.00 → Dnum representing $6.99 (2 dec, floored) * mulByPriceRoundedDown(dnum.from(6.99992, 6), 1.0, 2) // → Dnum [699n, 2] */ export declare function mulByPriceRoundedDown(amount: Dnum, price: number, resultDecimals: number): Dnum; /** * Convert a human-readable number to a Dnum. * Uses truncation (not rounding) so the result never exceeds the input. */ export declare function toBaseUnits(amount: number, decimals: number): Dnum; /** * Like `toBaseUnits` but rounds up instead of truncating. * Use for minimum amounts where going below the input would be incorrect. */ export declare function toBaseUnitsCeil(amount: number, decimals: number): Dnum; /** * Convert a Dnum to a human-readable number. * **Use only at the display boundary** — the result is lossy. */ export declare function toDisplayNumber(amount: Dnum): number; /** * Floor a number to the given decimal places. * Replaces inlined `Math.floor(x * 100) / 100` patterns. * * @example floorToDecimals(6.999, 2) → 6.99 */ export declare function floorToDecimals(value: number, decimals: number): number; /** * Format a USD balance floored to the cent (`196.867461` → `"$196.86"`) so the * display never overstates what the user holds — plain 2-decimal currency * formatting would round `196.867461` *up* to `$196.87`. */ export declare function formatUsdFlooredToCent(balanceUsd: number): string; /** * Compare two token amounts. Returns true if a > b. * Handles different decimal representations. */ export declare function tokenGreaterThan(a: Dnum, b: Dnum): boolean;