osmosis-labs / isotonic

Smart Contracts for the Lendex Protocol
MIT License
1 stars 0 forks source link

Market: Credit line should include existing debt #122

Closed ueco-jb closed 2 years ago

ueco-jb commented 2 years ago

I just noticed, that our credit_line query returns credit_line simply by multiplying collateral by ratio: https://github.com/confio/isotonic/blob/9287d9b0ae50e334f737990cabaf58b6a3401dad/contracts/isotonic-market/src/contract.rs#L845-L848

where it should be actually:

let debt = coin_times_price_rate(&debt, &price_ratio)?.amount;
let credit_line = collateral.amount * config.collateral_ratio - debt;

Creating an issue to highlight, but it will be probably fixed along https://github.com/confio/isotonic/issues/121.

uint commented 2 years ago

I don't think this is a bug. The credit_line - debt is calculated elsewhere, e.g. here.

ueco-jb commented 2 years ago

This queries available common tokens for other calculations, but the one I highlighted is still a response for QueryMsg::CreditLine. Should there be a credit_line, that actually doesn't calculate a debt?

uint commented 2 years ago

I'm not sure I understand. What I linked queries credit_line and subtracts debt to figure out how much is available.

I looked up the definition of "credit line" and it's the limit of how much you can borrow in total, not how much more you can borrow.

uint commented 2 years ago

Closing - see comment above!