osmosis-labs / isotonic

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

Market: Use proper collateral in `credit_line` query #121

Closed ueco-jb closed 2 years ago

ueco-jb commented 2 years ago

Currently credit_line calculates collateral based only on that one particular market. https://github.com/confio/isotonic/blob/9287d9b0ae50e334f737990cabaf58b6a3401dad/contracts/isotonic-market/src/contract.rs#L832

Actual credit line response should include collateral (and therefore available credit line) from all markets under same Credit Agency.

1) Either create a new query, that uses collateral from Credit Agency 2) Or modify existing; it depends - do we even need query, where collateral from only one market is shown?

uint commented 2 years ago

The market::credit_line queries are used by the credit_agency::total_credit_line query to calculate the actual total credit line. So market::credit_line is an internal endpoint that we need to remain exactly as it is right now.

uint commented 2 years ago

Did this and #122 come up because frontend needs some way to determine how much can be borrowed from a market? If so, I'd add a new BorrowCapacity {account: String} query to isotonic_market (not sure about naming) specifically for this. Then it can also maybe take the actual liquid balance of the market into account.

fn borrow_capacity(..., account: String) -> ... {
    // query_available_tokens is a helper function that already exists in the market contract!
    std::cmp::min(query_available_tokens(account), deps.querier.query_balance(env.contract.address, cfg.market_token))
}

Edit: or... possibly without the account param, using info.sender. Not sure.