/** * Pure computation functions for sub-account metrics and leverage utilities. * All functions return `undefined` when prerequisites are missing. */ import { type Address } from "viem"; import type { IAccount, IAccountLiquidity, IHasVaultAddress, ISubAccount } from "../entities/Account.js"; /** * Health factor for a sub-account's borrow position. * `totalCollateralValue.liquidation / liabilityValue.liquidation` (WAD, 18 dec). * `> 1e18` = healthy, `< 1e18` = liquidatable. */ export declare function computeHealthFactor(subAccount: ISubAccount): bigint | undefined; /** * Current loan-to-value ratio for a sub-account. * `liabilityValue.oracleMid / totalCollateralValue.oracleMid` (WAD). */ export declare function computeCurrentLTV(subAccount: ISubAccount): bigint | undefined; /** * Weighted-average liquidation LTV threshold. * `totalCollateralValue.liquidation / totalCollateralValue.oracleMid` (WAD). */ export declare function computeLiquidationLTV(subAccount: ISubAccount): bigint | undefined; /** * Leverage multiplier for a sub-account (1 = 1x). * `suppliedCollateralValueUsd / (suppliedCollateralValueUsd - borrowedValueUsd)`. */ export declare function computeMultiplier(subAccount: ISubAccount): number | undefined; export declare function computeCollateralMultiplier(suppliedValueUsd: number | undefined, borrowedValueUsd: number | undefined): number | undefined; /** * Total collateral value in USD for a sub-account. * Sourced from sub-account liquidity and populated by `populateMarketPrices`. */ export declare function computeSubAccountTotalCollateralValueUsd(subAccount: ISubAccount): number | undefined; /** * Liability value in USD for a sub-account. * Sourced from sub-account liquidity and populated by `populateMarketPrices`. */ export declare function computeSubAccountLiabilityValueUsd(subAccount: ISubAccount): number | undefined; /** * Net value in USD for a sub-account: sum(suppliedValueUsd) - sum(borrowedValueUsd). */ export declare function computeSubAccountNetValueUsd(subAccount: ISubAccount): number | undefined; /** * Per-collateral liquidation price multipliers. * For each collateral: `(liability - otherCollateral) / thisCollateral` (WAD). * `< 1` means the price can drop by this factor before liquidation. */ export declare function computeCollateralLiquidationPrices(liquidity: IAccountLiquidity): Record; /** * Borrow liquidation price multiplier (WAD). * `totalCollateralValue.liquidation / liabilityValue.liquidation`. * `> 1` = borrow price can increase by this factor before liquidation. */ export declare function computeBorrowLiquidationPrice(liquidity: IAccountLiquidity): bigint | undefined; /** * ROE (Return on Equity) breakdown for a sub-account. * All values are percentage points (5 = 5%). */ export interface SubAccountRoe { /** ROE contribution from base supply APYs. */ lending: number; /** ROE contribution from base borrow APYs (typically negative). */ borrowing: number; /** ROE contribution from reward APRs (supply + borrow incentives). */ rewards: number; /** ROE contribution from intrinsic asset yield (e.g. staking rewards, PT implied yield). */ intrinsicApy: number; /** Total ROE: lending + borrowing + rewards + intrinsicApy. */ total: number; } /** * APY/ROE contribution breakdown. * All values are percentage points (5 = 5%). */ export interface YieldApyBreakdown { /** Contribution from base supply APYs. */ lending: number; /** Contribution from base borrow APYs (typically negative). */ borrowing: number; /** Contribution from supply and borrow reward APRs. */ rewards: number; /** Contribution from intrinsic asset yield. */ intrinsicApy: number; /** Total contribution. */ total: number; } /** * Computes the ROE breakdown for a sub-account. * Requires populated vaults (for APY data) and market prices (for USD values). * Returns `undefined` when prerequisites are missing or equity <= 0. */ export declare function computeSubAccountRoe(subAccount: ISubAccount, viewer: Address | string | undefined | null): SubAccountRoe | undefined; /** * Net APY across the full account, relative to total supplied value. * * `totalNetYield / totalSupplyUsd`, where net yield includes supply APY, * borrow costs, supply/borrow reward APRs, and intrinsic APY. */ export declare function computeAccountNetApy(account: IAccount, viewer: Address | string | undefined | null): number | undefined; /** * Net APY across a pre-filtered set of positions, relative to supplied value. * Use this when a higher-level view intentionally excludes some account positions. */ export declare function computePositionsNetApy(positions: Iterable, viewer: Address | string | undefined | null): number | undefined; /** * Return on equity across the full account, relative to net asset value. * * `totalNetYield / (totalSupplyUsd - totalBorrowUsd)`. */ export declare function computeAccountRoe(account: IAccount, viewer: Address | string | undefined | null): number | undefined; /** * Return on equity across a pre-filtered set of positions, relative to net asset value. * Use this when a higher-level view intentionally excludes some account positions. */ export declare function computePositionsRoe(positions: Iterable, viewer: Address | string | undefined | null): number | undefined; /** * APY contribution breakdown across a pre-filtered set of positions, relative to supplied value. */ export declare function computePositionsNetApyBreakdown(positions: Iterable, viewer: Address | string | undefined | null): YieldApyBreakdown | undefined; /** * ROE contribution breakdown across a pre-filtered set of positions, relative to net asset value. */ export declare function computePositionsRoeBreakdown(positions: Iterable, viewer: Address | string | undefined | null): YieldApyBreakdown | undefined; /** * APY breakdown for a single supplied vault position. * Does not require USD values because a single supply-side APY is value-independent. */ export declare function computeSupplyApyBreakdown(vault: IHasVaultAddress | undefined, viewer: Address | string | undefined | null): YieldApyBreakdown | undefined; /** * Net APY relative to total supply. * `(supplyUsd * (supplyApy + supplyReward) - borrowUsd * (borrowApy - borrowReward)) / supplyUsd` */ export declare function getNetApy(supplyUsd: number, supplyApy: number, borrowUsd: number, borrowApy: number, supplyRewardApy?: number, borrowRewardApy?: number): number; /** * Return on equity (ROE): net yield relative to equity (NAV). * Same numerator as getNetApy, but divided by `equity = supplyUsd - borrowUsd`. */ export declare function getRoe(supplyUsd: number, supplyApy: number, borrowUsd: number, borrowApy: number, supplyRewardApy?: number, borrowRewardApy?: number): number; /** * Maximum multiplier for a given borrow LTV. * `1 / (1 - borrowLtv) - safetyMargin` where borrowLtv is decimal (0.85 = 85%). * The safety margin is deducted from the multiplier itself (not from the LTV), * so a 0.5% margin shaves ~0.005 off the result rather than dropping it sharply * near high LTV. * Floored to 2 decimal places, minimum 1. */ export declare function getMaxMultiplier(borrowLtv: number, safetyMargin?: number): number; /** * Maximum ROE at max leverage. * `supplyApy + (maxMultiplier - 1) * (supplyApy - borrowApy)` */ export declare function getMaxRoe(maxMultiplier: number, supplyApy: number, borrowApy: number): number; export interface AccountYieldPosition { vault?: IHasVaultAddress; suppliedValueUsd?: number; borrowedValueUsd?: number; /** * Optional borrow-side context. When present on a borrow position, the * yield computation also picks up `BORROW_COLLATERAL` campaigns (gated by * the collateral set) and `LOOPING` campaigns (gated by the position * multiplier). Without this context, those campaigns are excluded — the * SDK has no way to know which collaterals back the borrow or what the * effective leverage is. */ borrowContext?: BorrowYieldContext; } /** * Context attached to a borrow `AccountYieldPosition` so collateral-conditional * and leverage-conditional rewards can be attributed to the position. */ export interface BorrowYieldContext { /** * Collateral vault addresses backing this borrow. * `BORROW_COLLATERAL` campaigns whose `collateralAddress` matches an entry * here are added to the borrow-side reward yield. */ collateralAddresses: Address[]; /** * Effective leverage multiplier (supplied / equity) for this borrow. * `LOOPING` campaigns count when this value is within the campaign's * `[minMultiplier, maxMultiplier]` envelope. */ multiplier?: number; /** * Equity (NAV) in USD for this borrow-collateral set. * `LOOPING` rewards are paid per unit of equity (not scaled by leverage), * so their contribution to the yield total is `equityUsd * loopingApr`. */ equityUsd?: number; } //# sourceMappingURL=accountComputations.d.ts.map