Credit accounts
Retrieving account data

Retrieving Credit Account data

The primary data related to health of the Credit Account (such as various debt amounts and collateral value) can be retrieved by calling a CreditManager function:

function calcDebtAndCollateral(address creditAccount, CollateralCalcTask task)
    external
    view
    returns (CollateralDebtData memory cdd);

This return a structure CollateralDebtData with requested parameters:

struct CollateralDebtData {
    uint256 debt;
    uint256 cumulativeIndexNow;
    uint256 cumulativeIndexLastUpdate;
    uint128 cumulativeQuotaInterest;
    uint256 accruedInterest;
    uint256 accruedFees;
    uint256 totalDebtUSD;
    uint256 totalValue;
    uint256 totalValueUSD;
    uint256 twvUSD;
    uint256 enabledTokensMask;
    uint256 quotedTokensMask;
    address[] quotedTokens;
    address _poolQuotaKeeper;
}
ParameterDescription
debtThe Credit Account's debt principal denominated in underlying.
cumulativeIndexNowThe current value of the pool's interest index.
cumulativeIndexLastUpdatedThe value of the pool's interest index after the account's last debt update.
cumulativeQuotaInterestThe total accumulated unpaid interest from all quotas.
accruedInterestThe accumulated unpaid interest on principal. Computed as debt * (cumulativeIndexNow/cumulativeIndexLastUpdate - 1).
accruedFeesTotal amount of fees owed to the DAO.
totalDebtUSDTotal debt of the account converted to USD (with 10 ** 8 precision).
totalValueTotal value of enabled collateral assets on the account, in underlying.
totalValueUSDTotal value of enabled collateral assets on the account, in USD (with 10 ** 8 precision).
twvUSDTotal weighted value of enabled collateral assets on the account, in USD (with 10 ** 8 precision).
enabledTokensMaskThe mask of enabled collateral tokens for a Credit Account.
quotedTokensMaskThe mask of all quoted tokens in the Credit Manager.
quotedTokensArray of quoted tokens on the Credit Account.
_poolQuotaKeeperAddress of the PoolQuotaKeeper associated with the account's Credit Manager (this is mainly for internal use).

Response granularity

CollateralCalcTask determines the level of detail for the returned data (with higher detail levels generally consuming more gas):

  1. GENERIC_PARAMS - only returns account's debt principal and interest indices.
  2. DEBT_ONLY - returns all debt information, including quota-related debt and fees. As a consequence, this also fills the quotedTokens array.
  3. DEBT_COLLATERAL - returns all debt values and collateral values. This setting is used to compute values during liquidation.
  4. DEBT_COLLATERAL_SAFE_PRICES - same as above, but uses safe pricing for the TWV value. Used to perform collateral checks after collateral withdrawals.

There is also the FULL_COLLATERAL_CHECK_LAZY setting, but it is only used internally and is not available for external queries.

Alternative sources

More detailed Credit Account data can be retrieved from DataCompressor. As it is gas-intensive, it is recommended for gasless static calls only.