@molecularlabs/nucleus-frontend
Version:
Nucleus BoringVault Frontend SDK
61 lines • 2.21 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var bigint_exports = {};
__export(bigint_exports, {
RAY: () => RAY,
WAD: () => WAD,
bigIntToNumberAsString: () => bigIntToNumberAsString,
calculateAtomicPrice: () => calculateAtomicPrice,
calculateExpectedSharesMinted: () => calculateExpectedSharesMinted
});
module.exports = __toCommonJS(bigint_exports);
var import_viem = require("viem");
const RAY = {
bigint: BigInt(1e27),
number: 1e27
};
const WAD = {
bigint: BigInt(1e18),
number: 1e18
};
function bigIntToNumberAsString(value, opts = {}) {
const {
decimals = 18,
minimumFractionDigits = 0,
maximumFractionDigits = 3
} = opts;
const numberValue = Number.parseFloat((0, import_viem.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;
}
//# sourceMappingURL=bigint.js.map