Skip to content

Make Debt Ceilings Transparent for Users #1287

Open
@peetzweg

Description

@peetzweg

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.

https://github.com/Midas-Protocol/contracts/blob/e253b31216a09e375e47f7275b0363e0362d8712/contracts/compound/Comptroller.sol#L890-L908

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:

https://github.com/Midas-Protocol/contracts/blob/e253b31216a09e375e47f7275b0363e0362d8712/contracts/compound/Comptroller.sol#L884-L908

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?

numbr.dev example

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

Xnapper-2023-02-07-14 56 50

Metadata

Metadata

Assignees

Labels

💄 [UI]All Issues related to `packages/ui`🗞 [Contracts]All issues related to `packages/contracts`

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions