import { type Address } from "viem"; import { type GetFreeSubAccountsOptions } from "../utils/subAccounts.js"; import type { VaultEntity } from "../services/vaults/vaultMetaService/index.js"; import type { IVaultMetaService } from "../services/vaults/vaultMetaService/index.js"; import type { VaultFetchOptions } from "../services/vaults/index.js"; import type { PriceUsd } from "./ERC4626Vault.js"; import type { IPriceService } from "../services/priceService/index.js"; import type { IRewardsService, UserReward, ViewerOptions } from "../services/rewardsService/index.js"; import { type DataIssue } from "../utils/entityDiagnostics.js"; import type { SubAccountRoe } from "../utils/accountComputations.js"; export type AddressPrefix = `0x${string}`; /** Base interface for vault-like values (has `address`). Used as generic constraint so custom vault entity types work. */ export interface IHasVaultAddress { address: Address; } /** Default vault entity type (EVault | EulerEarn | SecuritizeCollateralVault). Use as IVaultEntity in the SDK. */ export type IVaultEntity = VaultEntity; export interface AccountPopulated { vaults: boolean; marketPrices: boolean; userRewards: boolean; } export interface AssetValue { liquidation: bigint; borrowing: bigint; oracleMid: bigint; } export type DaysToLiquidation = "Infinity" | "MoreThanAYear" | number; /** Vault is only ever a vault entity type (EVault, EulerEarn, SecuritizeCollateralVault, or custom). Use generic = never for unresolved (vault omitted). */ export interface AccountLiquidityCollateral { address: Address; vault?: TVaultEntity; value: AssetValue; /** USD price per underlying asset. Populated by `populateMarketPrices`. */ marketPriceUsd?: PriceUsd; /** Collateral value in USD. `collateral deposit amount * marketPriceUsd`. */ valueUsd?: number; } /** Raw liquidity data shape (returned by data sources). */ export interface IAccountLiquidity { vaultAddress: Address; vault?: TVaultEntity; unitOfAccount: Address; daysToLiquidation: DaysToLiquidation; liabilityValue: AssetValue; totalCollateralValue: AssetValue; collaterals: AccountLiquidityCollateral[]; /** Liability value in USD. Populated by `populateMarketPrices`. */ liabilityValueUsd?: number; /** Total collateral value in USD. Populated by `populateMarketPrices`. */ totalCollateralValueUsd?: number; /** Per-collateral liquidation price multipliers (WAD). Computed getter on AccountLiquidity class. */ readonly collateralLiquidationPrices?: Record; /** Borrow liquidation price multiplier (WAD). `> 1` = safe margin. Computed getter on AccountLiquidity class. */ readonly borrowLiquidationPrice?: bigint; } /** AccountLiquidity with computed getters for liquidation prices. */ export declare class AccountLiquidity implements IAccountLiquidity { vaultAddress: Address; vault?: TVaultEntity; unitOfAccount: Address; daysToLiquidation: DaysToLiquidation; liabilityValue: AssetValue; totalCollateralValue: AssetValue; collaterals: AccountLiquidityCollateral[]; liabilityValueUsd?: number; totalCollateralValueUsd?: number; constructor(data: IAccountLiquidity); /** Per-collateral liquidation price multipliers (WAD). */ get collateralLiquidationPrices(): Record; /** Borrow liquidation price multiplier (WAD). `> 1` = safe margin. */ get borrowLiquidationPrice(): bigint | undefined; } export interface IAccountPosition { account: Address; vaultAddress: Address; /** Resolved vault entity only (never Address). Omitted when unresolved. */ vault?: TVaultEntity; asset: Address; shares: bigint; assets: bigint; borrowed: bigint; isController: boolean; isCollateral: boolean; balanceForwarderEnabled: boolean; rewardStreams?: AccountRewardStream[]; liquidity?: IAccountLiquidity; /** USD price per underlying asset. Populated by `populateMarketPrices`. */ marketPriceUsd?: PriceUsd; /** Supplied value in USD. `assets * marketPriceUsd / 10^decimals`. */ suppliedValueUsd?: number; /** Borrowed value in USD. `borrowed * marketPriceUsd / 10^decimals`. */ borrowedValueUsd?: number; /** Borrow liquidation price in USD. Computed getter on positions. */ readonly borrowLiquidationPriceUsd?: number; /** Per-collateral liquidation price in USD. Computed getter on positions. */ readonly collateralLiquidationPricesUsd?: Record; } export interface AccountRewardStream { /** Account/sub-account that accrues and claims the reward. */ account: Address; /** Vault/rewarded address passed to the reward stream contract. */ vault: Address; /** Reward token address. */ reward: Address; /** Claimable amount from `earnedReward(..., ignoreRecentReward=false)`. */ earnedReward: bigint; /** Claimable amount from `earnedReward(..., ignoreRecentReward=true)`. */ earnedRewardRecentIgnored: bigint; } export declare class AccountPosition implements IAccountPosition { account: Address; vaultAddress: Address; vault?: TVaultEntity; asset: Address; shares: bigint; assets: bigint; borrowed: bigint; isController: boolean; isCollateral: boolean; balanceForwarderEnabled: boolean; rewardStreams?: AccountRewardStream[]; liquidity?: IAccountLiquidity; marketPriceUsd?: PriceUsd; suppliedValueUsd?: number; borrowedValueUsd?: number; constructor(data: IAccountPosition); get borrowLiquidationPriceUsd(): number | undefined; get collateralLiquidationPricesUsd(): Record | undefined; } /** Raw sub-account data shape (returned by data sources). */ export interface ISubAccount { timestamp: number; account: Address; owner: Address; lastAccountStatusCheckTimestamp: number; /** Always addresses; only positions and liquidity collaterals get resolved vault entities. */ enabledControllers: Address[]; /** Always addresses; only positions and liquidity collaterals get resolved vault entities. */ enabledCollaterals: Address[]; positions: IAccountPosition[]; /** Health factor (WAD). `> 1e18` = healthy. Computed getter on SubAccount class. */ readonly healthFactor?: bigint; /** Current LTV (WAD). `liabilityValue / totalCollateralValue`. Computed getter on SubAccount class. */ readonly currentLTV?: bigint; /** Weighted-average liquidation LTV threshold (WAD). Computed getter on SubAccount class. */ readonly liquidationLTV?: bigint; /** Leverage multiplier (1 = 1x). Requires USD data. Computed getter on SubAccount class. */ readonly multiplier?: number; /** Total collateral value in USD. Requires USD data. Computed getter on SubAccount class. */ readonly totalCollateralValueUsd?: number; /** Liability value in USD. Requires USD data. Computed getter on SubAccount class. */ readonly liabilityValueUsd?: number; /** Net value in USD: sum(supplied) - sum(borrowed). Computed getter on SubAccount class. */ readonly netValueUsd?: number; /** ROE breakdown (percentage points). Requires populated vaults + market prices. Computed getter on SubAccount class. */ readonly roe?: SubAccountRoe; } /** SubAccount with computed getters for risk metrics. */ export declare class SubAccount implements ISubAccount { timestamp: number; account: Address; owner: Address; lastAccountStatusCheckTimestamp: number; enabledControllers: Address[]; enabledCollaterals: Address[]; positions: AccountPosition[]; constructor(data: ISubAccount); /** Health factor (WAD). `> 1e18` = healthy. */ get healthFactor(): bigint | undefined; /** Current LTV (WAD). `liabilityValue / totalCollateralValue`. */ get currentLTV(): bigint | undefined; /** Weighted-average liquidation LTV threshold (WAD). */ get liquidationLTV(): bigint | undefined; /** Leverage multiplier (1 = 1x). Requires USD data. */ get multiplier(): number | undefined; /** Total collateral value in USD. Requires USD data. */ get totalCollateralValueUsd(): number | undefined; /** Liability value in USD. Requires USD data. */ get liabilityValueUsd(): number | undefined; /** Net value in USD: sum(supplied) - sum(borrowed). */ get netValueUsd(): number | undefined; /** Default-view (no viewer) ROE breakdown. Same as `getRoe()`. */ get roe(): SubAccountRoe | undefined; /** * ROE breakdown (percentage points, 5 = 5%). Requires populated vaults + market prices. * * `opts.viewer` filters whitelist/blacklist-gated rewards (see * `defaultIsActiveForViewer`). Omit it for the headline view. */ getRoe(opts?: ViewerOptions): SubAccountRoe | undefined; } export type SubAccountsMap = Partial>>; export interface IAccount { chainId: number; owner: Address; subAccounts: Partial>>; isLockdownMode?: boolean; isPermitDisabledMode?: boolean; populated?: Partial; } export interface GetNextSubAccountOptions extends GetFreeSubAccountsOptions { /** * Borrow vault being opened. When provided, existing deposits and borrows are * treated as occupied and enabled controllers must be compatible. */ borrowVault?: Address; } export declare class Account implements IAccount { chainId: number; owner: Address; isLockdownMode: boolean; isPermitDisabledMode: boolean; subAccounts: SubAccountsMap; /** Per-user unclaimed rewards from Merkl, Brevis/Incentra, and Fuul. Populated by `populateUserRewards`. */ userRewards?: UserReward[]; populated: AccountPopulated; constructor(account: IAccount); getSubAccount(account: Address): SubAccount | undefined; getSubAccountById(id: number): SubAccount | undefined; setSubAccount(subAccount: ISubAccount | SubAccount): void; /** * Returns sub-account addresses with no active supplied or borrowed position. */ getFreeSubAccounts(options?: GetFreeSubAccountsOptions): Address[]; /** * Returns the first sub-account address suitable for opening a new position. * * Without `borrowVault`, only active borrow sub-accounts are treated as * occupied. With `borrowVault`, active supplied and borrowed sub-accounts are * treated as occupied and any known enabled controllers must match that vault. */ getNextSubAccount(options?: GetNextSubAccountOptions): Address | undefined; /** Alias for callers using new-position terminology. */ getNewSubAccount(options?: GetNextSubAccountOptions): Address | undefined; getPosition(account: Address, vault: Address): AccountPosition | undefined; /** * Returns true if the given vault is enabled as collateral for the sub-account. * Returns false when sub-account is not available. */ isCollateralEnabled(subAccountAddress: Address, vault: Address): boolean; /** * Returns true if the given vault is enabled as controller for the sub-account. * Returns false when sub-account is not available. */ isControllerEnabled(subAccountAddress: Address, vault: Address): boolean; /** * Returns the current controller vault address for the sub-account (there can only be one). * Returns undefined when sub-account is not available or has no controller enabled. */ getCurrentController(subAccountAddress: Address): Address | undefined; private occupiedPositionSubAccounts; private borrowPositionSubAccounts; private subAccountsWithPosition; /** * Fetches vault entities from the service and maps them onto positions and liquidity collaterals. * Mutates in place and returns diagnostics from vault fetching/enrichment. */ populateVaults(vaultMetaService: IVaultMetaService, options?: VaultFetchOptions): Promise; /** Maps fetched vault entities onto positions and liquidity collaterals. Mutates in place. */ mapVaultsToPositions(vaults: Array): Account; /** * Populates USD market prices on positions and liquidity data. * Requires `populateVaults` to have been called first (vault entities must be resolved). * Mutates in place and returns diagnostics. */ populateMarketPrices(priceService: IPriceService): Promise; /** Total unclaimed rewards value in USD. `undefined` if no user rewards populated. */ get totalRewardsValueUsd(): number | undefined; /** * Fetches per-user unclaimed rewards from Merkl, Brevis/Incentra, and Fuul providers. * Populates `this.userRewards`. */ populateUserRewards(rewardsService: IRewardsService): Promise; /** * Replaces subAccounts with a map built from the given sub-accounts (keyed by account address). * Use in examples or when building account state from fetched sub-accounts. */ updateSubAccounts(...subAccounts: SubAccount[]): void; } export type AddressOrAccount = Address | Account; //# sourceMappingURL=Account.d.ts.map