BorrowLiquidation Logics
Here the logics used in Borrow Liquidation contract and BorrowLib are explained.
ETH price ratio
uint128 ratio = BorrowLib.calculateEthPriceRatio(
depositDetail.ethPriceAtDeposit,
_currentEthPrice
);function calculateEthPriceRatio(
uint128 depositEthPrice,
uint128 currentEthPrice
) public pure returns(uint128){
return (currentEthPrice * 10000)/depositEthPrice;
}It will returns the ratio of current ETH price to the deposit ETH price.
Functions which are using the above logic
Borrower Debt
uint256 borrowerDebt = (
(depositDetail.normalizedAmount * _lastCumulativeRate)/BorrowLib.RATE_PRECISION
);to calculate the borrower's debt we are using this formula. Last cumulative rate we will get from calculateCumulativeRate method.
BorrowLib.RATE_PRECISION is base precision used, since last cumulative rate already have this precision we are dividing it here.
Functions which are using the above logic
Return to ABOND
here return to treasury is the borrower's debt. USDA_PRECISION is used for decimals, since USDa has 6 decimals only.
Functions which are using the above logic
Liquidation Amount to get from other chain
First calculate the each chain CDS amount proportions by dividing them with global CDS amount. Based on the proportions, calculate the liquidation amount to get from each chain.
Let say, if one chain don't have any CDS amount, then take all liquidation amount from other chain. If one chain don't have enough liquidation amount to get, then get available CDS amount from that chain and get remaining from other chain. If both have enough CDS amount, then get the amount based on proportion.
Functions which are using the above logic
CDS profits for Destination Chain
_liqAmount
uint128
Total Liquidation amount needed.
_liqAmountToGetFromOtherChain
uint128
Proportion of Liquidation amount to get from destination chain in total liquidation amount.
_cdsProfits
uint128
Total CDS profits from liquidation.
Calculate the proportion of CDS amount contributed by each chain. Based on the proportions divide the CDS profits for each chain.
Functions which are using the above logic
Last updated