Description
General
The way the debt ceiling feature is currently implemented makes it impossible for the frontend to show any viable information to the user how his supplied collateral is used or can be used for borrowing.
Showing the debt ceilings values for each collateral asset, does not give any valuable information to the user. As we have no insights how these values are used. The calculation is a bit "tricky" and personally I don't get it. For me it works but not the way I imagine it to work. So my mental modal of this feature is different to the implementation. And the implementation is implemented as is by the limitations of the Compound Comptroller model.
Maths
Regarding the math involved regarding the debt ceiling calculation it's all implemented in the Comptroller.getHypotheticalAccountLiquidityInternal()
method. Specifically these lines:
It's calculating the per asset borrowAmountCap
like this:
uint256 borrowAmountCap = vars.totalBorrowCapForCollateral - vars.totalBorrowsBefore;
and sums them all up:
vars.sumCollateral += borrowAmountCap;
But it's confusing to me that the totalBorrowsBefore
is used. As this will impact every "debtCeiling" value of an asset.
Example:
Pool: USDC, ETH, BTC
Market: USDC => BTC:5,000 USDC, ETH: 2,000 USDC
Borrowed 5000 USDC with just BTC as collateral
I as a User just supplied ETH and want to borrow in this Market. However, there is already 5K USDC borrowed. This means these lines
uint256 borrowAmountCap = vars.totalBorrowCapForCollateral - vars.totalBorrowsBefore;
will result in 0, so I can't borrow anymore even if the whole market of USDC is borrowed against BTC. I can't borrow anymore with my ETH. Is this correct?
Visualisation
For visualisation, at best I imagine to have something similiar to this. But with the current implementation it's not possible. Best we can do is show the debt ceilings, but they don't give any valuable information. So we decided