UNPKG

@paxoslabs/earn-sdk

Version:
47 lines (45 loc) 1.47 kB
import { formatUnits } from 'viem'; // src/utils/try-catch.ts async function tryCatch(promise) { try { const data = await promise; return { data, error: void 0, success: true }; } catch (error) { return { data: void 0, error, success: false }; } } var RAY = { bigint: BigInt(1e27), number: 1e27 }; var WAD = { bigint: BigInt(1e18), number: 1e18 }; function bigIntToNumberAsString(value, opts = {}) { const { decimals = 18, minimumFractionDigits = 0, maximumFractionDigits = 3 } = opts; const numberValue = Number.parseFloat(formatUnits(value, decimals)); return new Intl.NumberFormat("en-US", { minimumFractionDigits, maximumFractionDigits }).format(numberValue); } function calculateExpectedSharesMinted(depositAmount, rateInQuote, shareDecimals) { const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals); const sharesMinted = depositAmount * ONE_SHARE / rateInQuote; return sharesMinted; } function calculateAtomicPrice(rateInQuote, slippage) { const basisPoints = 1e4; const slippageInBasisPoints = Math.floor(slippage * basisPoints); const percentageToKeep = basisPoints - slippageInBasisPoints; const atomicPrice = rateInQuote * BigInt(percentageToKeep) / BigInt(basisPoints); return atomicPrice; } export { RAY, WAD, bigIntToNumberAsString, calculateAtomicPrice, calculateExpectedSharesMinted, tryCatch }; //# sourceMappingURL=chunk-MHZTLW64.mjs.map //# sourceMappingURL=chunk-MHZTLW64.mjs.map