Annex Docs
Search…
Get Account Liquidity
Account Liquidity represents the USD value borrowable by a user, before it reaches liquidation. Users with a shortfall (negative liquidity) are subject to liquidation, and can’t withdraw or borrow assets until Account Liquidity is positive again.
For each market the user has entered into, their supplied balance is multiplied by the market’s collateral factor, and summed; borrow balances are then subtracted, to equal Account Liquidity. Borrowing an asset reduces Account Liquidity for each USD borrowed; withdrawing an asset reduces Account Liquidity by the asset’s collateral factor times each USD withdrawn.
Because the Annex Protocol exclusively uses unsigned integers, Account Liquidity returns either a surplus or shortfall.
Comptroller
1
function getAccountLiquidity(address account) view returns (uint, uint, uint)
Copied!
  • account: The account whose liquidity shall be calculated.
  • RETURN: Tuple of values (error, liquidity, shortfall). The error shall be 0 on success, otherwise an error code. A non-zero liquidity value indicates the account has available account liquidity. A non-zero shortfall value indicates the account is currently below his/her collateral requirement and is subject to liquidation. At most one of liquidity or shortfall shall be non-zero.
Solidity
1
Comptroller troll = Comptroller(0xABCD...);
2
(uint error, uint liquidity, uint shortfall) = troll.getAccountLiquidity(msg.caller);
3
require(error == 0, "join the Discord");
4
require(shortfall == 0, "account underwater");
5
require(liquidity > 0, "account has excess collateral");
Copied!
Web3 1.0
1
const troll = Comptroller.at(0xABCD...);
2
const result = await troll.methods.getAccountLiquidity(0xBorrower).call();
3
const {0: error, 1: liquidity, 2: shortfall} = result;
Copied!
Last modified 4mo ago
Copy link