Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Debt Ceilings Transparent for Users #1287

Open
peetzweg opened this issue Feb 7, 2023 · 1 comment
Open

Make Debt Ceilings Transparent for Users #1287

peetzweg opened this issue Feb 7, 2023 · 1 comment
Assignees
Labels
🗞 [Contracts] All issues related to `packages/contracts` 💄 [UI] All Issues related to `packages/ui`

Comments

@peetzweg
Copy link
Contributor

peetzweg commented Feb 7, 2023

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

@peetzweg peetzweg added 💄 [UI] All Issues related to `packages/ui` 🗞 [Contracts] All issues related to `packages/contracts` labels Feb 7, 2023
@peetzweg
Copy link
Contributor Author

peetzweg commented Feb 7, 2023

cc @vminkov @carlomazzaferro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗞 [Contracts] All issues related to `packages/contracts` 💄 [UI] All Issues related to `packages/ui`
Projects
None yet
Development

No branches or pull requests

2 participants