interface CollateralParams {
    name?: string;
    liquidationLTV?: number;
    liquidationPremium?: number;
    maxLTV?: number;
    cap?: number;
}
interface Collateral extends CollateralParams {
    amount: number;
    price: number;
}
type InterestRateParams = {
    urKink: number;
    baseIR: number;
    slope1: number;
    slope2: number;
};
type Epoch = {
    startTimestamp: number;
    endTimestamp: number;
    totalRewards: number;
};
type SafetyModuleParams = {
    slope1: number;
    slope2: number;
    baseRewardRate: number;
    stakedPercentageKink: number;
};

declare const secondsInAYear: number;

/**
 * Account Module
 *
 * This module handles account-related calculations including:
 * - Account health calculations
 * - Account LTV (Loan-to-Value) ratio calculations
 * - Account maximum and liquidation LTV thresholds
 *
 * The module provides essential functions for monitoring account status
 * and risk assessment through various LTV metrics.
 */

/**
 * Calculates the total value of all collateral assets
 * @param collaterals - Array of collateral assets
 * @returns The sum of all collateral values (amount * price)
 */
declare function calculateTotalCollateralValue(collaterals: Collateral[]): number;
/**
 * Calculates the health factor of an account based on collaterals and current debt
 * @param collaterals - Array of collateral assets
 * @param currentDebt - Current outstanding debt
 * @returns The health factor (ratio of weighted collateral value to debt)
 * @throws Error if liquidationLTV is not defined or current debt is zero
 */
declare function calculateAccountHealth(collaterals: Collateral[], currentDebt: number): number;
/**
 * Calculates the current Loan-to-Value ratio for an account
 * @param accountTotalDebt - Total outstanding debt for the account
 * @param collaterals - Array of collateral assets
 * @returns The current LTV ratio (debt/collateral value)
 */
declare function calculateAccountLTV(accountTotalDebt: number, collaterals: Collateral[]): number;
/**
 * Calculates the maximum allowed LTV for an account based on collateral composition
 * @param collaterals - Array of collateral assets
 * @returns The maximum allowed LTV ratio
 * @throws Error if maxLTV is not defined for any collateral
 */
declare function calculateAccountMaxLTV(collaterals: Collateral[]): number;
/**
 * Calculates the liquidation LTV threshold for an account
 * @param collaterals - Array of collateral assets
 * @returns The liquidation LTV threshold
 */
declare function calculateAccountLiqLTV(collaterals: Collateral[]): number;
/**
 * Calculates the maximum amount of a specific collateral that can be withdrawn
 * @param collateralToWithdraw - The collateral asset to withdraw
 * @param allCollaterals - Array of all collateral assets
 * @param debtShares - Current debt shares of the account
 * @param openInterest - Total outstanding loans in the protocol
 * @param totalDebtShares - Total debt shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Current time delta
 * @param decimals - Number of decimals for the token being withdrawn
 * @param futureDeltaSeconds - Optional seconds to add for future debt calculation (default: 600 seconds/10 minutes)
 * @returns The maximum amount that can be withdrawn
 */
declare function calculateMaxWithdrawAmount(collateralToWithdraw: Collateral, allCollaterals: Collateral[], debtShares: number, openInterest: number, totalDebtShares: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number, decimals: number, futureDeltaSeconds?: number): number;

/**
 * Borrow and Debt Module
 *
 * This module handles all borrowing and debt-related calculations including:
 * - Utilization rate computation
 * - Interest rate calculations (due interest, compounded interest)
 * - APR/APY calculations
 * - Borrowing capacity and availability checks
 * - Maximum repayment calculations
 * - Debt share conversions and management
 * - Protocol reserve handling
 */

/**
 * Calculates the utilization rate of the protocol
 * @param openInterest - The total amount of outstanding loans in the protocol
 * @param totalAssets - The total amount of assets deposited in the protocol
 * @returns A percentage that can be above 100% (> 1) but never negative as it's the ratio of two non-negative numbers
 * @example
 * computeUtilizationRate(500, 1000) // Returns 0.5 (50% utilization)
 * computeUtilizationRate(0, 1000)   // Returns 0 (0% utilization)
 * computeUtilizationRate(1500, 1000) // Returns 1.5 (150% utilization)
 */
declare function computeUtilizationRate(openInterest: number, totalAssets: number): number;
/**
 * Calculates the annualized APR based on utilization rate
 * @param ur - Current utilization rate
 * @param irParams - Interest rate parameters including kink point and slopes
 * @returns The annualized interest rate
 */
declare function annualizedAPR(ur: number, irParams: InterestRateParams): number;
/**
 * Calculates the total interest due on a debt amount
 * @param debtAmt - The amount of debt to calculate interest for
 * @param openInterest - The total outstanding loans in the protocol
 * @param totalAssets - The total assets in the protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The total amount due including interest
 */
declare function calculateDueInterest(debtAmt: number, openInterest: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Calculates just the interest portion due on a given sum
 * @param debtAmt - The principal amount to calculate interest on
 * @param openInterest - The total outstanding loans
 * @param totalAssets - The total assets in the protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The interest amount accrued
 */
declare function compoundedInterest(debtAmt: number, openInterest: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Calculates the borrowing APY including compounding effects
 * @param ur - Current utilization rate
 * @param irParams - Interest rate parameters
 * @returns The effective annual percentage yield for borrowing
 */
declare function calculateBorrowAPY(ur: number, irParams: InterestRateParams): number;
/**
 * Converts debt assets to shares based on the current share price
 * @param debtAssets - Amount of debt in asset terms to convert to shares
 * @param totalDebtShares - Total debt shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param openInterest - Total outstanding loans
 * @param protocolReservePercentage - Percentage of interest that goes to protocol reserves
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The equivalent amount of debt shares
 */
declare function convertDebtAssetsToShares(debtAssets: number, totalDebtShares: number, totalAssets: number, openInterest: number, protocolReservePercentage: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Converts debt shares to assets based on the current share price
 * @param debtShares - Amount of debt shares to convert to assets
 * @param openInterest - Total outstanding loans
 * @param totalDebtShares - Total debt shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The equivalent amount of debt in asset terms
 */
declare function convertDebtSharesToAssets(debtShares: number, openInterest: number, totalDebtShares: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Calculates the maximum amount that can be borrowed against provided collaterals
 * @param collaterals - Array of collateral assets
 * @returns The total borrowing capacity based on collateral values and maxLTVs
 * @throws Error if any collateral's maxLTV is undefined
 */
declare function calculateBorrowCapacity(collaterals: Collateral[]): number;
/**
 * Calculates how much can be borrowed from the protocol's available liquidity
 * @param freeLiquidity - The total available liquidity
 * @param reserveBalance - The protocol's reserve balance
 * @returns The amount available for borrowing from the protocol
 */
declare function protocolAvailableToBorrow(freeLiquidity: number, reserveBalance: number): number;
/**
 * Calculates how much a user can borrow based on their collateral and protocol constraints
 * @param collaterals - User's collateral assets
 * @param freeLiquidity - Protocol's available liquidity
 * @param reserveBalance - Protocol's reserve balance
 * @param currentDebt - User's current outstanding debt
 * @returns The maximum amount the user can borrow
 */
declare function userAvailableToBorrow(collaterals: Collateral[], freeLiquidity: number, reserveBalance: number, currentDebt: number): number;
/**
 * Calculates the maximum repayment amount including accrued interest
 * @param debtShares - Amount of debt shares
 * @param openInterest - Total outstanding loans
 * @param totalDebtShares - Total debt shares in protocol
 * @param totalAssets - Total assets in protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The maximum amount that can be repaid including interest
 */
declare function calculateMaxRepayAmount(debtShares: number, openInterest: number, totalDebtShares: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number): number;

/**
 * LP (Liquidity Provider) Module
 *
 * This module handles liquidity provider-related calculations including:
 * - Converting between LP assets and shares
 * - APY calculations for liquidity providers
 * - Total earnings calculations
 *
 * The module uses share-based accounting to track LP positions,
 * allowing for automatic interest distribution through share price appreciation.
 */

/**
 * Converts LP assets to shares based on the current share price
 * @param assets - Amount of assets to convert to shares
 * @param totalShares - Total LP shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param openInterest - Total outstanding loans
 * @param protocolReservePercentage - Percentage of interest that goes to protocol reserves
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The equivalent amount of LP shares
 */
declare function convertLpAssetsToShares(assets: number, totalShares: number, totalAssets: number, openInterest: number, protocolReservePercentage: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Converts LP shares to assets based on the current share price
 * @param shares - Amount of shares to convert to assets
 * @param totalShares - Total LP shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param openInterest - Total outstanding loans
 * @param protocolReservePercentage - Percentage of interest that goes to protocol reserves
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The equivalent amount of assets
 */
declare function convertLpSharesToAssets(shares: number, totalShares: number, totalAssets: number, openInterest: number, protocolReservePercentage: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Calculates the Annual Percentage Yield (APY) for liquidity providers
 * @param ur - Current utilization rate
 * @param irParams - Interest rate parameters
 * @param protocolReservePercentage - Percentage of interest that goes to protocol reserves
 * @returns The APY for liquidity providers
 */
declare function calculateLpAPY(ur: number, irParams: InterestRateParams, protocolReservePercentage: number): number;
/**
 * Computes the total earnings for a liquidity provider
 * @param shares - Amount of LP shares
 * @param totalShares - Total LP shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param openInterest - Total outstanding loans
 * @param protocolReservePercentage - Percentage of interest that goes to protocol reserves
 * @param irParams - Interest rate parameters
 * @param reserveBalance - Protocol's reserve balance
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The total earnings in asset terms
 */
declare function computeTotalEarning(shares: number, totalShares: number, totalAssets: number, openInterest: number, protocolReservePercentage: number, irParams: InterestRateParams, reserveBalance: number, timeDelta: number): number;

/**
 * Liquidation Module
 *
 * This module handles liquidation-related calculations including:
 * - Maximum repayment amount calculations for liquidators
 * - Liquidation threshold checks
 * - Liquidation trigger points
 * - Price drop calculations
 *
 * The module provides essential functions for the liquidation process,
 * ensuring proper risk management and incentives for liquidators.
 */

/**
 * Calculates the price drop percentage that would trigger liquidation
 * @param collaterals - Array of collateral assets
 * @param currentDebt - Current outstanding debt
 * @returns The percentage drop in collateral value that would trigger liquidation
 */
declare function calculateDrop(collaterals: Collateral[], currentDebt: number): number;
/**
 * Calculates the collateral value at which liquidation would be triggered
 * @param accountLiqLTV - Account's liquidation LTV threshold
 * @param debtShares - Amount of debt shares
 * @param openInterest - Total outstanding loans
 * @param totalDebtShares - Total debt shares in protocol
 * @param totalAssets - Total assets in protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @returns The collateral value at which liquidation would occur
 */
declare function calculateLiquidationPoint(accountLiqLTV: number, debtShares: number, openInterest: number, totalDebtShares: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number): number;
/**
 * Calculates the maximum amount a liquidator can repay for a position
 * @param debtShares - Amount of debt shares to be liquidated
 * @param openInterest - Total outstanding loans
 * @param totalDebtShares - Total debt shares in the protocol
 * @param totalAssets - Total assets in the protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @param collateral - The collateral asset being liquidated
 * @param allCollaterals - Array of all collateral assets in the position
 * @returns The maximum amount that can be repaid by the liquidator
 * @throws Error if liquidation LTV or liquidation premium are not defined
 */
declare const liquidatorMaxRepayAmount: (debtShares: number, openInterest: number, totalDebtShares: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number, collateral: Collateral, allCollaterals: Collateral[]) => number;
/**
 * Calculates the amount of collateral to transfer to the liquidator
 * @param repayAmount - Amount being repaid by the liquidator
 * @param collateral - The collateral being liquidated
 * @returns The amount of collateral to transfer to the liquidator
 * @throws Error if liquidation premium is not defined
 */
declare const calculateCollateralToTransfer: (repayAmount: number, collateral: Collateral) => number;
declare const liquidationRisk: (debtAssets: number, openInterest: number, totalDebtShares: number, totalAssets: number, protocolReservePercentage: number, irParams: InterestRateParams, timeDelta: number, initialDebtShares: number, initialOpenInterest: number, initialTotalDebtShares: number, initialTotalAssets: number, accountLiqLTV: number) => number;

/**
 * LP (Liquidity Provider) Rewards Module
 *
 * This module provides utility functions to compute the
 * due incentives for initial liquidity suppliers to Granite
 */

/**
 * Calculates the actual APR based on epoch and deposit amount
 * @param totalLpShares - Total LP shares in the market
 * @param userLpShares - Amount of user deposited assets in shares terms
 * @param epoch - The current epoch
 * @returns The actual APR scaled as a decimal (e.g., 0.05 for 5% APR)
 */
declare function calculateLpRewardApy(totalLpShares: number, userLpShares: number, epoch: Epoch): number;
/**
 * Estimates future rewards based on current LP share and APR
 * @param depositAmount - Amount of tokens deposited
 * @param apr - Annual Percentage Rate as a decimal
 * @param durationInSeconds - Duration for which to estimate rewards
 * @returns Estimated rewards for the given period
 */
declare function estimatedRewards(depositAmount: number, apr: number, durationInSeconds: number): number;

/**
 * Safety Module
 *
 * This module provides utility functions to compute the
 * APY and withdrawal queue status of the Granite safety module
 */

declare function stakingRate(stakedLpShares: number, totalLpShares: number): number;
declare function stakersRewardRate(sr: number, params: SafetyModuleParams): number;
declare function lpApyWithStaking(ur: number, irParams: InterestRateParams, protocolReservePercentage: number, sr: number, smParams: SafetyModuleParams): number;
declare function stakerBonus(ur: number, irParams: InterestRateParams, sr: number, smParams: SafetyModuleParams): number;
declare function stakingAPY(ur: number, irParams: InterestRateParams, protocolReservePercentage: number, sr: number, smParams: SafetyModuleParams): number;

/**
 * Leverage Module
 *
 * This module provides helpers to compute the max leverage
 * and required collateral to swap for margin trading
 */

/**
 * Calculates the maximum leverage multiplier.
 * Assumes no fees or slippage and liquidation at the max LTV threshold.
 * @param maxLtv - Corrected maxLTV
 * @returns The leverage multiplier 1 / (1 - maxLTV)
 */
declare function absoluteMaxLeverage(maxLTV: number): number;
/**
 * Calculates the effective maximum borrowable fraction after costs.
 * Adjusts maxLTV by deducting flash loan fees and expected swap slippage.
 * @param collateral - Collateral configuration including maxLTV
 * @param flashLoanFee - Flash loan fee as a fraction of notional
 * @param slippage - Expected slippage as a fraction of notional
 * @returns The effective max LTV after costs
 */
declare function correctedMaxLTV(collateral: Collateral, flashLoanFee: number, slippage: number): number;
/**
 * Calculates the unencumbered collateral amount given the user debt and including accrued interest.
 * It works for a single collateral position.
 * @param debtShares - Amount of debt shares
 * @param openInterest - Total outstanding loans
 * @param totalDebtShares - Total debt shares in protocol
 * @param totalAssets - Total assets in protocol
 * @param irParams - Interest rate parameters
 * @param timeDelta - Time elapsed since last interest accrual
 * @param collateral - Current collateral params
 * @param maxLTVcorrected - Max LTV corrected for flash loan fees and slippage
 * @returns The free collateral that the user has deposited
 */
declare function unencumberedCollateral(debtShares: number, openInterest: number, totalDebtShares: number, totalAssets: number, irParams: InterestRateParams, timeDelta: number, collateral: Collateral, maxLTVcorrected: number): number;
/**
 * Computes the slippage cost when levering up.
 * Based on the new collateral purchased and expected slippage.
 * @param collateralValue - Current collateral value
 * @param slippage - Expected slippage as a fraction of notional
 * @returns The incremental loss due to slippage
 */
declare function leverageMaxSlippage(collateralValue: number, slippage: number): number;
/**
 * Computes the swap loss for a flash loan funded purchase.
 * Compares the flash loan notional to the value received from the swap.
 * @param flashLoanAmount - Amount borrowed via flash loan in quote terms
 * @param quote - Amount of market asset received from the swap
 * @param collateralPrice - Price of collateral in quote terms
 * @param marketAssetPrice - Price of the market asset used for the swap
 * @returns The loss due to price impact and conversion
 */
declare function swapLoss(flashLoanAmount: number, quote: number, collateralPrice: number, marketAssetPrice: number): number;
/**
 * Derives flash loan notional and implied slippage fraction from swap results.
 * @param newCollateralValue - Value of newly acquired collateral
 * @param swapLoss - Loss attributed to slippage and pricing
 * @returns The flash loan notional and the realized slippage fraction
 */
declare function computeFlashLoanValues(newCollateralValue: number, swapLoss: number): {
    flashLoanValue: number;
    slippage: number;
};

export { type Collateral, type CollateralParams, type Epoch, type InterestRateParams, type SafetyModuleParams, absoluteMaxLeverage, annualizedAPR, calculateAccountHealth, calculateAccountLTV, calculateAccountLiqLTV, calculateAccountMaxLTV, calculateBorrowAPY, calculateBorrowCapacity, calculateCollateralToTransfer, calculateDrop, calculateDueInterest, calculateLiquidationPoint, calculateLpAPY, calculateLpRewardApy, calculateMaxRepayAmount, calculateMaxWithdrawAmount, calculateTotalCollateralValue, compoundedInterest, computeFlashLoanValues, computeTotalEarning, computeUtilizationRate, convertDebtAssetsToShares, convertDebtSharesToAssets, convertLpAssetsToShares, convertLpSharesToAssets, correctedMaxLTV, estimatedRewards, leverageMaxSlippage, liquidationRisk, liquidatorMaxRepayAmount, lpApyWithStaking, protocolAvailableToBorrow, secondsInAYear, stakerBonus, stakersRewardRate, stakingAPY, stakingRate, swapLoss, unencumberedCollateral, userAvailableToBorrow };
