@paxoslabs/earn-sdk
Version:
Paxos Labs Earn SDK
111 lines (105 loc) • 4.03 kB
text/typescript
import { Chain } from 'viem/chains';
import { E as EarnVault } from './earn-sdk-api-CAc-JIqW.mjs';
import 'viem';
/**
* RAY precision unit (10^27)
* Used for high precision fixed-point calculations
* @type {{bigint: bigint, number: number}}
*/
declare const RAY: {
bigint: bigint;
number: number;
};
/**
* WAD precision unit (10^18)
* Common precision unit for Ethereum tokens (matches ETH's 18 decimals)
* @type {{bigint: bigint, number: number}}
*/
declare const WAD: {
bigint: bigint;
number: number;
};
/**
* Converts a bigint value to a formatted number string with specified decimal precision
*
* @param {bigint} value - The bigint value to convert
* @param {Object} opts - Formatting options
* @param {number} [opts.decimals=18] - Number of decimals to use when converting from bigint
* @param {number} [opts.minimumFractionDigits=0] - Minimum number of fraction digits to display
* @param {number} [opts.maximumFractionDigits=3] - Maximum number of fraction digits to display
* @returns {string} The formatted number as a string
*
* @example
* // Returns "123.456"
* bigIntToNumberAsString(BigInt("123456000000000000000"), { decimals: 18 })
*/
declare function bigIntToNumberAsString(value: bigint, opts?: {
decimals?: number;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
}): string;
/**
* Calculates the expected amount of shares to be minted based on deposit amount and rate
*
* The calculation follows the formula:
* sharesMinted = depositAmount * ONE_SHARE / rateInQuote
*
* @param {bigint} depositAmount - The amount to deposit in quote asset decimals
* @param {bigint} rateInQuote - The rate in quote representing "quote asset per share"
* @param {number} shareDecimals - The decimal precision of the BoringVault shares (ONE_SHARE)
* @returns {bigint} The expected amount of shares to be minted
*/
declare function calculateExpectedSharesMinted(depositAmount: bigint, rateInQuote: bigint, shareDecimals: number): bigint;
/**
* Calculates the atomic price with slippage applied
* The calculation follows the formula:
* atomicPrice = rateInQuote * (1 - slippage)
*
* @param {bigint} rateInQuote - The rate in quote representing "quote asset per share"
* @param {number} slippage - The maximum acceptable slippage as a decimal (e.g., 0.01 for 1%)
* @param {number} quoteDecimals - The decimal precision of the quote asset
* @returns {bigint} The atomic price with slippage applied
*/
declare function calculateAtomicPrice(rateInQuote: bigint, slippage: number): bigint;
/**
* Gets a chain object from the vault config response
* @param chainId The chain ID to look up
* @param config Optional config object. If not provided, will fetch from API
* @returns Promise<Chain>
*/
declare function getChainFromConfig(chainId: number, config?: EarnVault[]): Promise<Chain>;
/**
* Clears the chains cache
*/
declare function clearChainsCache(): void;
/**
* @fileoverview Utility functions for time-related operations
*/
/**
* Calculates a deadline timestamp in seconds from the current time
*
* @param {number} [daysFromNow=DEFAULT_DEADLINE] - Number of days from now to set the deadline
* @returns {number} Unix timestamp in seconds representing the deadline
*
* @example
* // Returns a timestamp 3 days from now (in seconds)
* const threeDay = calculateDeadline();
*
* @example
* // Returns a timestamp 7 days from now (in seconds)
* const weekDeadline = calculateDeadline(7);
*/
declare const calculateDeadline: (daysFromNow?: number) => bigint;
type Success<T> = {
success: true;
data: T;
error?: never;
};
type Failure<E> = {
success: false;
data?: never;
error: E;
};
type SafeResult<T, E = Error> = Success<T> | Failure<E>;
declare function tryCatch<T, E = Error>(promise: Promise<T>): Promise<SafeResult<T, E>>;
export { RAY, WAD, bigIntToNumberAsString, calculateAtomicPrice, calculateDeadline, calculateExpectedSharesMinted, clearChainsCache, getChainFromConfig, tryCatch };