UNPKG

@chorus-one/ethereum

Version:

All-in-one toolkit for building staking dApps on Ethereum network

36 lines (35 loc) 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMintHealth = void 0; const decimal_js_1 = __importDefault(require("decimal.js")); const getBaseData_1 = require("../utils/getBaseData"); const mintCotrollerAbi_1 = require("../contracts/mintCotrollerAbi"); const getMintHealth = async (params) => { const { connector, mintedShares, stakedAssets, vault } = params; const mintedAssets = await connector.eth.readContract({ abi: mintCotrollerAbi_1.MintTokenControllerAbi, address: connector.mintTokenController, functionName: 'convertToAssets', args: [mintedShares] }); if (mintedAssets === 0n || stakedAssets === 0n) { return 'healthy'; } const { thresholdPercent } = await (0, getBaseData_1.getBaseData)(connector, vault); const healthFactor = new decimal_js_1.default(stakedAssets.toString()) .mul(thresholdPercent.toString()) .div(10 ** 18) .div(mintedAssets.toString()) .toDecimalPlaces(4) .toNumber(); // If healthFactor = 1, then position is Healthy, but we need to add // a small gap to notify the user in advance of problems with the position if (healthFactor >= 1.02) { return 'healthy'; } return 'risky'; }; exports.getMintHealth = getMintHealth;