@chorus-one/ethereum
Version:
All-in-one toolkit for building staking dApps on Ethereum network
29 lines (28 loc) • 1.11 kB
JavaScript
import Decimal from 'decimal.js';
import { getBaseData } from '../utils/getBaseData';
import { MintTokenControllerAbi } from '../contracts/mintCotrollerAbi';
export const getMintHealth = async (params) => {
const { connector, mintedShares, stakedAssets, vault } = params;
const mintedAssets = await connector.eth.readContract({
abi: MintTokenControllerAbi,
address: connector.mintTokenController,
functionName: 'convertToAssets',
args: [mintedShares]
});
if (mintedAssets === 0n || stakedAssets === 0n) {
return 'healthy';
}
const { thresholdPercent } = await getBaseData(connector, vault);
const healthFactor = new Decimal(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';
};