@daimo/pay
Version:
Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.
50 lines (49 loc) • 2.21 kB
TypeScript
import { BigIntStr, DaimoPayToken } from "@daimo/pay-common";
export declare const USD_DECIMALS = 2;
/**
* Round a number to a given number of decimal places
*
* @param round - The rounding strategy to use:
* - "up": Always rounds up to the next decimal place (ceiling)
* - "down": Always rounds down to the previous decimal place (floor)
* - "nearest": Rounds to the nearest decimal place (standard rounding)
*/
export declare function roundDecimals(value: number, decimals: number, round: "up" | "down" | "nearest"): string;
/**
* Format a number as a USD amount
*
* @param usd - The USD amount to format
* @param round - The rounding strategy to use ("up", "down", or "nearest")
* @returns The formatted USD amount
*/
export declare function formatUsd(usd: number, round?: "up" | "down" | "nearest"): string;
/**
* Round a USD amount to `USD_DECIMALS` precision
*/
export declare function roundUsd(usd: number, round?: "up" | "down" | "nearest"): string;
/**
* Round a token amount to `displayDecimals` precision
*/
export declare function roundTokenAmount(amount: bigint | BigIntStr, token: DaimoPayToken, round?: "up" | "down" | "nearest"): string;
/**
* Round a token amount in units to `displayDecimals` precision
*/
export declare function roundTokenAmountUnits(amountUnits: number, token: DaimoPayToken, round?: "up" | "down" | "nearest"): string;
/**
* Convert a USD amount to a token amount with `displayDecimals` precision
*
* @param usd - The USD amount to convert
* @param token - The token to convert to
* @param round - The rounding strategy to use ("up", "down", or "nearest")
* @returns The token amount
*/
export declare function usdToRoundedTokenAmount(usd: number, token: DaimoPayToken, round?: "up" | "down" | "nearest"): string;
/**
* Convert a token amount to a USD amount with `USD_DECIMALS` precision
*
* @param amount - The token amount to convert
* @param token - The token to convert from
* @param round - The rounding strategy to use ("up", "down", or "nearest")
* @returns The formatted USD amount
*/
export declare function tokenAmountToRoundedUsd(amount: bigint | BigIntStr, token: DaimoPayToken, round?: "up" | "down" | "nearest"): string;