BalanceSheet
Introduction
The BalanceSheet is the global debt registry of Hifi. All users who borrow fyTokens have to first open a vault bespoke to that fyToken contract. All vaults are recorded in and managed via the BalanceSheet.
Gas Costs
Gas usage is not deterministic due to requisite calls to third-party Erc20 tokens. We provide the table below for guidance only:
Action
Typical Gas Cost
Deposit Collateral
<70K
Free Collateral
<110K if partial, <40K otherwise
Lock Collateral
<40K
Open Vault
<50K
Withdraw Collateral
<40K
Storage Properties
Fintroller
The unique Fintroller associated with this contract.
FintrollerInterface public fintroller;Constant Functions
Get Clutchable Collateral
Determines the amount of collateral that can be clutched when liquidating a borrow according to the formula:
fyToken: The fyToken to make the query against.repayAmount: The amount of fyTokens to repay (must be non-zero).RETURN: The amount of clutchable collateral as uint256, specified in the collateral's decimal system.
Solidity
Ethers.js
Get Current Collateralization Ratio
Determines the current collateralization ratio for the given borrower account.
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.RETURN: A quotient if locked collateral is non-zero, otherwise zero.
Solidity
Ethers.js
Get Hypothetical Collateralization Ratio
Determines the hypothetical collateralization ratio for the given locked collateral and debt, at the current prices provided by the oracle according to the formula:
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.lockedCollateral: The hypothetical locked collateral.debt: The hypothetical debt.RETURN: The hypothetical collateralization ratio as a percentage mantissa if locked collateral is non-zero, otherwise zero.
Requirements
The vault must be open.
"debt" must be non-zero.
The oracle prices must be non-zero.
Solidity
Ethers.js
Get Vault
Reads all the properties of a vault.
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.RETURN: The vault with all its properties.
Solidity
Ethers.js
Get Vault Debt
Reads the debt held by the given account.
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.RETURN: The debt held by the borrower, as an uint256.
Solidity
Ethers.js
Get Vault Locked Collateral
Reads the amount of collateral that the given borrower account locked in the vault.
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.RETURN: The collateral locked in the vault by the borrower, as an uint256.
Solidity
Ethers.js
Is Account Underwater
Checks whether the borrower account can be liquidated or not.
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.RETURN: true = is underwater, otherwise not.
Solidity
Ethers.js
Is Vault Open
Checks whether the borrower account has a vault opened for a particular fyToken.
fyToken: The fyToken to make the query against.borrower: The borrower account to make the query against.RETURN: true = is open, otherwise not.
Solidity
Ethers.js
Non-Constant Functions
Clutch Collateral
Transfers the collateral from the borrower's vault to the liquidator account. Emits a "ClutchCollateral" event.
fyToken: The address of the fyToken contract.liquidator: The account who repays the borrower's debt and receives the collateral.borrower: The account who fell underwater and is liquidated.collateralAmount: The amount of collateral to clutch, specified in the collateral's decimal system.RETURN: true = success, otherwise it reverts
Requirements:
Can only be called by the fyToken contract.
There must be enough collateral in the borrower's vault.
Deposit Collateral
Deposits collateral into the account's vault. Emits a "DepositCollateral" event.
fyToken: The address of the fyToken contract.collateralAmount: The amount of collateral to deposit.RETURN: true = success, otherwise it reverts.
Requirements:
The vault must be open.
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.
Solidity
Ethers.js
Free Collateral
Frees a portion or all of the locked collateral. Emits a "FreeCollateral" event.
fyToken: The address of the fyToken contract.collateralAmount: The amount of locked collateral to free.RETURN: true = success, otherwise it reverts.
Requirements:
The vault must be open.
The amount to free cannot be zero.
There must be enough locked collateral.
The borrower account cannot fall below the collateralization ratio.
Solidity
Ethers.js
Lock Collateral
Locks a portion or all of the free collateral to make it eligible for borrowing. Emits a "LockCollateral" event.
fyToken: The address of the fyToken contract.collateralAmount: The amount of free collateral to lock.RETURN: true = success, otherwise it reverts.
Requirements:
The vault must be open.
The amount to lock cannot be zero.
There must be enough free collateral.
Solidity
Ethers.js
Open Vault
Opens a Vault for the caller. Emits an "OpenVault" event.
fyToken: The address of the fyToken contract for which to open the vault.RETURN: true = success, otherwise it reverts.
Requirements:
The vault cannot be already open.
The fyToken must pass the inspection.
Solidity
Ethers.js
Set Vault Debt
Updates the debt accrued by a particular borrower account. Emits a "SetVaultDebt" event.
fyToken: The address of the fyToken contract.borrower: The borrower account for which to update the debt.newVaultDebt: The new debt to assign to the borrower account.RETURN: true = success, otherwise it reverts.
Requirements:
Can only be called by the fyToken.
Withdraw Collateral
Withdraws a portion or all of the free collateral. Emits a "WithdrawCollateral" event.
fyToken: The address of the fyToken contract.collateralAmount: The amount of collateral to withdraw.RETURN: true = success, otherwise it reverts.
Requirements
The vault must be open.
The amount to withdraw cannot be zero.
There must be enough free collateral in the vault.
Solidity
Ethers.js
Last updated
Was this helpful?