# DInterestLens

## `withdrawableAmountOfDeposit(contract DInterest pool, uint64 depositID, uint256 virtualTokenAmount) → uint256 withdrawableAmount, uint256 feeAmount` (external) <a href="#withdrawableamountofdeposit-contract-dinterest-pool-uint64-depositid-uint256-virtualtokenamount-uint" id="withdrawableamountofdeposit-contract-dinterest-pool-uint64-depositid-uint256-virtualtokenamount-uint"></a>

Computes the amount of stablecoins that can be withdrawn by burning `virtualTokenAmount` virtual tokens from the deposit with ID `depositID` at time `timestamp`.

@dev The queried timestamp should >= the deposit's lastTopupTimestamp, since the information before this time is forgotten.

@param pool The DInterest pool

@param depositID The ID of the deposit

@param virtualTokenAmount The amount of virtual tokens to burn

@return withdrawableAmount The amount of stablecoins (after fee) that can be withdrawn @return feeAmount The amount of fees that will be given to the beneficiary

## `accruedInterestOfFunding(contract DInterest pool, uint64 fundingID) → uint256 fundingInterestAmount` (external) <a href="#accruedinterestoffunding-contract-dinterest-pool-uint64-fundingid-uint256-fundinginterestamount-exte" id="accruedinterestoffunding-contract-dinterest-pool-uint64-fundingid-uint256-fundinginterestamount-exte"></a>

Computes the floating-rate interest accrued in the floating-rate bond with ID `fundingID`. @param pool The DInterest pool

@param fundingID The ID of the floating-rate bond

@return fundingInterestAmount The interest accrued, in stablecoins

## `fundingIsActive(contract DInterest pool, uint64 fundingID) → bool` (external) <a href="#fundingisactive-contract-dinterest-pool-uint64-fundingid-bool-external" id="fundingisactive-contract-dinterest-pool-uint64-fundingid-bool-external"></a>

A floating-rate bond is no longer active if its principalPerToken becomes 0, which occurs when the corresponding deposit is completely withdrawn. When such a deposit is topped up, a new Funding struct and floating-rate bond will be created.

@param pool The DInterest pool

@param fundingID The ID of the floating-rate bond

@return True if the funding is active, false otherwise

## `totalInterestOwedToFunders(contract DInterest pool) → uint256 interestOwed` (public) <a href="#totalinterestowedtofunders-contract-dinterest-pool-uint256-interestowed-public" id="totalinterestowedtofunders-contract-dinterest-pool-uint256-interestowed-public"></a>

Computes the floating interest amount owed to deficit funders, which will be paid out when a funded deposit is withdrawn.

Formula:∑irecordedFundedPrincipalAmounti(incomeIndexrecordedMoneyMarketIncomeIndexi−1)=incomeIndex(∑irecordedFundedPrincipalAmountirecordedMoneyMarketIncomeIndexi)−∑irecordedFundedPrincipalAmounti\sum\_i recordedFundedPrincipalAmount\_i (\frac{incomeIndex}{recordedMoneyMarketIncomeIndex\_i} - 1) = incomeIndex (\sum\_i \frac{recordedFundedPrincipalAmount\_i}{recordedMoneyMarketIncomeIndex\_i}) - \sum\_i recordedFundedPrincipalAmount\_i∑i​recordedFundedPrincipalAmounti​(recordedMoneyMarketIncomeIndexi​incomeIndex​−1)=incomeIndex(∑i​recordedMoneyMarketIncomeIndexi​recordedFundedPrincipalAmounti​​)−∑i​recordedFundedPrincipalAmounti​​

where i refers to a funding

@param pool The DInterest pool

@return interestOwed The floating-rate interest accrued to all floating-rate bond holders

## `surplusOfDeposit(contract DInterest pool, uint64 depositID) → bool isNegative, uint256 surplusAmount` (public) <a href="#surplusofdeposit-contract-dinterest-pool-uint64-depositid-bool-isnegative-uint256-surplusamount-publ" id="surplusofdeposit-contract-dinterest-pool-uint64-depositid-bool-isnegative-uint256-surplusamount-publ"></a>

Computes the surplus of a deposit, which is the raw surplus of the unfunded part of the deposit. If the deposit is not funded, this will return the same value as {rawSurplusOfDeposit}. @param depositID The ID of the deposit

@return isNegative True if the surplus is negative, false otherwise

@return surplusAmount The absolute value of the surplus, in stablecoins

## `_depositVirtualTokenToPrincipal(struct DInterest.Deposit depositEntry, uint256 virtualTokenAmount) → uint256` (internal) <a href="#depositvirtualtokentoprincipal-struct-dinterest-deposit-depositentry-uint256-virtualtokenamount-uin" id="depositvirtualtokentoprincipal-struct-dinterest-deposit-depositentry-uint256-virtualtokenamount-uin"></a>

Converts a virtual token value into the corresponding principal value. Principal refers to deposit + full interest + fee.

@param depositEntry The deposit struct

@param virtualTokenAmount The virtual token value

@return The corresponding principal value

## `rawSurplusOfDeposit(uint64 depositID) → bool isNegative, uint256 surplusAmount` (public) <a href="#rawsurplusofdeposit-uint64-depositid-bool-isnegative-uint256-surplusamount-public" id="rawsurplusofdeposit-uint64-depositid-bool-isnegative-uint256-surplusamount-public"></a>

Computes the raw surplus of a deposit, which is the current value of the deposit in the money market minus the amount owed (deposit + interest + fee). The deposit's funding status is not considered here, meaning even if a deposit's fixed-rate interest is fully funded, it likely will still have a non-zero surplus.

@param depositID The ID of the deposit

@return isNegative True if the surplus is negative, false otherwise

@return surplusAmount The absolute value of the surplus, in stablecoins
