import { type RoundingDirection } from "../math/index.js"; import type { BigIntish, MarketId } from "../types.js"; import type { IMarketParams } from "./MarketParams.js"; /** * Namespace of utility functions to ease market-related calculations. */ export declare namespace MarketUtils { /** * Returns the id of a market based on its params. * @param market The market params. */ function getMarketId(market: IMarketParams): MarketId; /** * Returns the liquidation incentive factor for a given market params. * @param config The market params. */ function getLiquidationIncentiveFactor({ lltv }: { lltv: BigIntish; }): bigint; /** * Returns the market's utilization rate (scaled by WAD). * @param market The market state. */ function getUtilization({ totalSupplyAssets, totalBorrowAssets, }: { totalSupplyAssets: BigIntish; totalBorrowAssets: BigIntish; }): bigint; /** * Returns the per-second rate continuously compounded over a year, * as calculated in Morpho Blue assuming the market is frequently accrued onchain. * @param rate The per-second rate to compound annually. */ function rateToApy(rate: BigIntish): number; /** * Returns the interest accrued on both sides of the given market * as well as the supply shares minted to the fee recipient. * @param borrowRate The average borrow rate since the last market update (scaled by WAD). * @param market The market state. * @param elapsed The time elapsed since the last market update (in seconds). */ function getAccruedInterest(borrowRate: BigIntish, { totalSupplyAssets, totalBorrowAssets, totalSupplyShares, fee, }: { totalSupplyAssets: BigIntish; totalBorrowAssets: BigIntish; totalSupplyShares: BigIntish; fee: BigIntish; }, elapsed?: bigint): { interest: bigint; feeShares: bigint; }; /** * Returns the smallest volume to supply until the market gets the closest to the given utilization rate. * @param market The market state. * @param utilization The target utilization rate (scaled by WAD). */ function getSupplyToUtilization(market: { totalSupplyAssets: BigIntish; totalBorrowAssets: BigIntish; }, utilization: BigIntish): bigint; /** * Returns the liquidity available to withdraw until the market gets the closest to the given utilization rate. * @param market The market state. * @param utilization The target utilization rate (scaled by WAD). */ function getWithdrawToUtilization({ totalSupplyAssets, totalBorrowAssets, }: { totalSupplyAssets: BigIntish; totalBorrowAssets: BigIntish; }, utilization: BigIntish): bigint; /** * Returns the liquidity available to borrow until the market gets the closest to the given utilization rate. * @param market The market state. * @param utilization The target utilization rate (scaled by WAD). */ function getBorrowToUtilization({ totalSupplyAssets, totalBorrowAssets, }: { totalSupplyAssets: BigIntish; totalBorrowAssets: BigIntish; }, utilization: BigIntish): bigint; /** * Returns the smallest volume to repay until the market gets the closest to the given utilization rate. * @param market The market state. * @param utilization The target utilization rate (scaled by WAD). */ function getRepayToUtilization({ totalSupplyAssets, totalBorrowAssets, }: { totalSupplyAssets: BigIntish; totalBorrowAssets: BigIntish; }, utilization: BigIntish): bigint; function getCollateralPower(collateral: BigIntish, { lltv }: { lltv: BigIntish; }): bigint; /** * Returns the value of a given amount of collateral quoted in loan assets. * Return `undefined` iff the market's price is undefined. */ function getCollateralValue(collateral: BigIntish, { price }: { price?: BigIntish; }): bigint | undefined; /** * Returns the maximum debt allowed given a certain amount of collateral. * Return `undefined` iff the market's price is undefined. * To calculate the amount of loan assets that can be borrowed, use `getMaxBorrowableAssets`. */ function getMaxBorrowAssets(collateral: BigIntish, market: { price?: BigIntish; }, { lltv }: { lltv: BigIntish; }): bigint | undefined; /** * Returns the maximum amount of loan assets that can be borrowed given a certain borrow position. * Return `undefined` iff the market's price is undefined. */ function getMaxBorrowableAssets({ collateral, borrowShares, }: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, marketParams: { lltv: BigIntish; }): bigint | undefined; /** * Returns the amount of collateral that would be seized in a liquidation given a certain amount of repaid shares. * Return `undefined` iff the market's price is undefined. */ function getLiquidationSeizedAssets(repaidShares: BigIntish, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, config: { lltv: BigIntish; }): bigint | undefined; /** * Returns the amount of borrow shares that would be repaid in a liquidation given a certain amount of seized collateral. * Return `undefined` iff the market's price is undefined. */ function getLiquidationRepaidShares(seizedAssets: BigIntish, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, config: { lltv: BigIntish; }): bigint | undefined; /** * Returns the maximum amount of collateral that is worth being seized in a liquidation given a certain borrow position. * Return `undefined` iff the market's price is undefined. */ function getSeizableCollateral(position: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, config: { lltv: BigIntish; }): bigint | undefined; /** * Returns the amount of collateral that can be withdrawn given a certain borrow position. * Return `undefined` iff the market's price is undefined. */ function getWithdrawableCollateral({ collateral, borrowShares, }: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, { lltv }: { lltv: BigIntish; }): bigint | undefined; /** * Returns whether a given borrow position is healthy. * Return `undefined` iff the market's price is undefined. * @param position The borrow position to check. */ function isHealthy({ collateral, borrowShares, }: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, marketParams: { lltv: BigIntish; }): boolean | undefined; /** * Returns the price of the collateral quoted in the loan token (e.g. ETH/DAI) * that set the user's position to be liquidatable. * Returns null if the position is not a borrow. */ function getLiquidationPrice({ collateral, borrowShares, }: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; }, marketParams: { lltv: BigIntish; }): bigint | null; /** * Returns the price variation required for the given position to reach its liquidation threshold (scaled by WAD). * Negative when healthy (the price needs to drop x%), positive when unhealthy (the price needs to soar x%). * Returns `undefined` iff the market's price is undefined. * Returns null if the position is not a borrow. */ function getPriceVariationToLiquidationPrice(position: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, marketParams: { lltv: BigIntish; }): bigint | null | undefined; /** * Returns the health factor of a given borrow position (scaled by WAD). * If the debt is 0, health factor is `MaxUint256`. * Returns `undefined` iff the market's price is undefined. */ function getHealthFactor({ collateral, borrowShares, }: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, marketParams: { lltv: BigIntish; }): bigint | undefined; /** * Returns the loan-to-value ratio of a given borrow position (scaled by WAD). * Returns `undefined` iff the market's price is undefined. * Returns null if the position is not a borrow. */ function getLtv({ collateral, borrowShares, }: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }): bigint | null | undefined; /** * Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD). * Returns `undefined` iff the market's price is undefined. */ function getBorrowCapacityUsage(position: { collateral: BigIntish; borrowShares: BigIntish; }, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; price?: BigIntish; }, marketParams: { lltv: BigIntish; }): bigint | undefined; function toSupplyAssets(shares: BigIntish, market: { totalSupplyAssets: BigIntish; totalSupplyShares: BigIntish; }, rounding?: RoundingDirection): bigint; function toSupplyShares(assets: BigIntish, market: { totalSupplyAssets: BigIntish; totalSupplyShares: BigIntish; }, rounding?: RoundingDirection): bigint; function toBorrowAssets(shares: BigIntish, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; }, rounding?: RoundingDirection): bigint; function toBorrowShares(assets: BigIntish, market: { totalBorrowAssets: BigIntish; totalBorrowShares: BigIntish; }, rounding?: RoundingDirection): bigint; }