Skip to main content

Balance Sheet

The BalanceSheet is the global debt registry for Hifi. It tracks the collateral deposits and the debt taken on by all users.

When a user borrow hTokens, a vault is opened for them in the BalanceSheet. All vaults are recorded and managed in this contract.

Constant Functions

getBondList

function getBondList(
address account
) external returns (contract IHToken[])

Returns the list of bond markets the given account entered.

It is not an error to provide an invalid address.

Parameters

NameTypeDescription
accountaddressThe borrower account to make the query against.

getCollateralAmount

function getCollateralAmount(
address account,
contract IErc20 collateral
) external returns (uint256 collateralAmount)

Returns the amount of collateral deposited by the given account for the given collateral type.

It is not an error to provide an invalid address.

Parameters

NameTypeDescription
accountaddressThe borrower account to make the query against.
collateralcontract IErc20The collateral to make the query against.

getCollateralList

function getCollateralList(
address account
) external returns (contract IErc20[])

Returns the list of collaterals the given account deposited.

It is not an error to provide an invalid address.

Parameters

NameTypeDescription
accountaddressThe borrower account to make the query against.

getCurrentAccountLiquidity

function getCurrentAccountLiquidity(
address account
) external returns (uint256 excessLiquidity, uint256 shortfallLiquidity)

Calculates the current account liquidity.

Parameters

NameTypeDescription
accountaddressThe account to make the query against.

Return Values

NameTypeDescription
excessLiquidityaddressaccount liquidity in excess of collateral requirements.
shortfallLiquidityaccount shortfall below collateral requirements

getDebtAmount

function getDebtAmount(
address account,
contract IHToken bond
) external returns (uint256 debtAmount)

Returns the amount of debt accrued by the given account in the given bond market.

It is not an error to provide an invalid address.

Parameters

NameTypeDescription
accountaddressThe borrower account to make the query against.
bondcontract IHTokenThe bond to make the query against.

getHypotheticalAccountLiquidity

function getHypotheticalAccountLiquidity(
address account,
contract IErc20 collateralModify,
uint256 collateralAmountModify,
contract IHToken bondModify,
uint256 debtAmountModify
) external returns (uint256 excessLiquidity, uint256 shortfallLiquidity)

Calculates the account liquidity given a modified collateral, collateral amount, bond and debt amount, using the current prices provided by the oracle.

Works by summing up each collateral amount multiplied by the USD value of each unit and divided by its respective collateral ratio, then dividing the sum by the total amount of debt drawn by the user.

Caveats:

  • This function expects that the "collateralList" and the "bondList" are each modified in advance to include the collateral and bond due to be modified.

Parameters

NameTypeDescription
accountaddressThe account to make the query against.
collateralModifycontract IErc20The collateral to make the check against.
collateralAmountModifyuint256The hypothetical normalized amount of collateral.
bondModifycontract IHTokenThe bond to make the check against.
debtAmountModifyuint256The hypothetical amount of debt.

Return Values

NameTypeDescription
excessLiquidityaddresshypothetical account liquidity in excess of collateral requirements.
shortfallLiquiditycontract IErc20hypothetical account shortfall below collateral requirements

getRepayAmount

function getRepayAmount(
contract IErc20 collateral,
uint256 seizableCollateralAmount,
contract IHToken bond
) external returns (uint256 repayAmount)

Calculates the amount of hTokens that should be repaid in order to seize a given amount of collateral. Note that this is for informational purposes only, it doesn't say anything about whether the user can be liquidated.

The formula applied:

repayAmount=seizableCollateralAmountโˆ—collateralPriceliquidationIncentiveโˆ—underlyingPricerepayAmount = \frac{seizableCollateralAmount * collateralPrice}{liquidationIncentive * underlyingPrice}

Parameters

NameTypeDescription
collateralcontract IErc20The collateral to make the query against.
seizableCollateralAmountuint256The amount of collateral to seize.
bondcontract IHTokenThe bond to make the query against.

Return Values

NameTypeDescription
repayAmountcontract IErc20The amount of hTokens that should be repaid.

getSeizableCollateralAmount

function getSeizableCollateralAmount(
contract IHToken bond,
uint256 repayAmount,
contract IErc20 collateral
) external returns (uint256 seizableCollateralAmount)

Calculates the amount of collateral that can be seized when liquidating a borrow. Note that this is for informational purposes only, it doesn't say anything about whether the user can be liquidated.

The formula applied:

seizableCollateralAmount=repayAmountโˆ—liquidationIncentiveโˆ—underlyingPricecollateralPriceseizableCollateralAmount = \frac{repayAmount * liquidationIncentive * underlyingPrice}{collateralPrice}

Parameters

NameTypeDescription
bondcontract IHTokenThe bond to make the query against.
repayAmountuint256The amount of hTokens to repay.
collateralcontract IErc20The collateral to make the query against.

Return Values

NameTypeDescription
seizableCollateralAmountcontract IHTokenThe amount of seizable collateral.

Non-Constant Functions

borrow

function borrow(
contract IHToken bond,
uint256 borrowAmount
) external

Increases the debt of the caller and mints new hTokens.

Emits a {Borrow} event.

Requirements:

  • The Fintroller must allow this action to be performed.
  • The maturity of the bond must be in the future.
  • The amount to borrow cannot be zero.
  • The new length of the bond list must be below the max bonds limit.
  • The new total amount of debt cannot exceed the debt ceiling.
  • The caller must not end up having a shortfall of liquidity.

Parameters

NameTypeDescription
bondcontract IHTokenThe address of the bond contract.
borrowAmountuint256The amount of hTokens to borrow and print into existence.

depositCollateral

function depositCollateral(
contract IErc20 collateral,
uint256 depositAmount
) external

Deposits collateral in the caller's account.

Emits a {DepositCollateral} event.

Requirements:

  • The amount to deposit cannot be zero.
  • The Fintroller must allow this action to be performed.
  • The caller must have allowed this contract to spend collateralAmount tokens.
  • The new collateral amount cannot exceed the collateral ceiling.

Parameters

NameTypeDescription
collateralcontract IErc20The address of the collateral contract.
depositAmountuint256The amount of collateral to deposit.

liquidateBorrow

function liquidateBorrow(
address bond,
contract IHToken borrower,
uint256 repayAmount,
contract IErc20 collateral
) external

Repays the debt of the borrower and rewards the caller with a surplus of collateral.

Emits a {LiquidateBorrow} event.

Requirements:

  • All from "repayBorrow".
  • The caller cannot be the same with the borrower.
  • The Fintroller must allow this action to be performed.
  • The borrower must have a shortfall of liquidity if the bond didn't mature.
  • The amount of seized collateral cannot be more than what the borrower has in the vault.

Parameters

NameTypeDescription
bondaddressThe address of the bond contract.
borrowercontract IHTokenThe account to liquidate.
repayAmountuint256The amount of hTokens to repay.
collateralcontract IErc20The address of the collateral contract.

repayBorrow

function repayBorrow(
contract IHToken bond,
uint256 repayAmount
) external

Erases the borrower's debt and takes the hTokens out of circulation.

Emits a {RepayBorrow} event.

Requirements:

  • The amount to repay cannot be zero.
  • The Fintroller must allow this action to be performed.
  • The caller must have at least repayAmount hTokens.
  • The caller must have at least repayAmount debt.

Parameters

NameTypeDescription
bondcontract IHTokenThe address of the bond contract.
repayAmountuint256The amount of hTokens to repay.

repayBorrowBehalf

function repayBorrowBehalf(
address borrower,
contract IHToken bond,
uint256 repayAmount
) external

Erases the borrower's debt and takes the hTokens out of circulation.

Emits a {RepayBorrow} event.

Requirements:

  • Same as the repayBorrow function, but here borrower is the account that must have at least repayAmount hTokens to repay the borrow.

Parameters

NameTypeDescription
borroweraddressThe borrower account for which to repay the borrow.
bondcontract IHTokenThe address of the bond contract
repayAmountuint256The amount of hTokens to repay.

setOracle

function setOracle(
contract IChainlinkOperator newOracle
) external

Updates the oracle contract's address saved in storage.

Emits a {SetOracle} event.

Requirements:

  • The caller must be the owner.
  • The new address cannot be the zero address.

Parameters

NameTypeDescription
newOraclecontract IChainlinkOperatorThe new oracle contract.

withdrawCollateral

function withdrawCollateral(
contract IErc20 collateral,
uint256 withdrawAmount
) external

Withdraws a portion or all of the collateral.

Emits a {WithdrawCollateral} event.

Requirements:

  • The amount to withdraw cannot be zero.
  • There must be enough collateral in the vault.
  • The caller's account cannot fall below the collateral ratio.

Parameters

NameTypeDescription
collateralcontract IErc20The address of the collateral contract.
withdrawAmountuint256The amount of collateral to withdraw.

Events

Borrow

event Borrow(
address account,
contract IHToken bond,
uint256 borrowAmount
)

Emitted when a borrow is made.

Parameters

NameTypeDescription
accountaddressThe address of the borrower.
bondcontract IHTokenThe address of the bond contract.
borrowAmountuint256The amount of hTokens borrowed.

DepositCollateral

event DepositCollateral(
address account,
contract IErc20 collateral,
uint256 collateralAmount
)

Emitted when collateral is deposited.

Parameters

NameTypeDescription
accountaddressThe address of the borrower.
collateralcontract IErc20The related collateral.
collateralAmountuint256The amount of deposited collateral.

LiquidateBorrow

event LiquidateBorrow(
address liquidator,
address borrower,
contract IHToken bond,
uint256 repayAmount,
contract IErc20 collateral,
uint256 seizedCollateralAmount
)

Emitted when a borrow is liquidated.

Parameters

NameTypeDescription
liquidatoraddressThe address of the liquidator.
borroweraddressThe address of the borrower.
bondcontract IHTokenThe address of the bond contract.
repayAmountuint256The amount of repaid funds.
collateralcontract IErc20The address of the collateral contract.
seizedCollateralAmountuint256The amount of seized collateral.

RepayBorrow

event RepayBorrow(
address payer,
address borrower,
contract IHToken bond,
uint256 repayAmount,
uint256 newDebtAmount
)

Emitted when a borrow is repaid.

Parameters

NameTypeDescription
payeraddressThe address of the payer.
borroweraddressThe address of the borrower.
bondcontract IHTokenThe address of the bond contract.
repayAmountuint256The amount of repaid funds.
newDebtAmountuint256The amount of the new debt.

SetOracle

event SetOracle(
address owner,
address oldOracle,
address newOracle
)

Emitted when a new oracle is set.

Parameters

NameTypeDescription
owneraddressThe address of the owner.
oldOracleaddressThe address of the old oracle.
newOracleaddressThe address of the new oracle.

WithdrawCollateral

event WithdrawCollateral(
address account,
contract IErc20 collateral,
uint256 collateralAmount
)

Emitted when collateral is withdrawn.

Parameters

NameTypeDescription
accountaddressThe address of the borrower.
collateralcontract IErc20The related collateral.
collateralAmountuint256The amount of withdrawn collateral.