osmosis-labs / isotonic

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

Credit Agency properly authorizes borrows and transfers #26

Closed ethanfrey closed 2 years ago

ethanfrey commented 2 years ago

With #23 we can get a global view of a user's account in all markets.

With this, we can make Markets more intelligent and properly authorise borrows and transfers, rather than use the stubs we defined in #6 and #7

The Market must store the address of the Credit Agency in the constructor (present as info.sender). When we need to check for withdraw LToken, transfer LToken or borrow BToken, we perform the following:

let credit = deps.querier.query_wasm_smart(&credit_agency, &QueryMsg::TotalCreditLine{account})?;
// how much eg OSMO we can still use
let available_common = credit.credit_line.saturating_sub(credit.debt);
// We defined price as common/local in #21 so we need to divide by it
let available = available_common / query_price()?;

For borrowing, we can borrow up to available tokens

For withdraw or transfer, we can move more collateral, as eg 2 collateral remove the right to borrow 1 unit.

let can_transfer = available / config.collateral_ratio;
ueco-jb commented 2 years ago

@ethanfrey also question regarding transfering ltokens - we don't have such option currently, am I wrong? Our API is:

Deposit {}
Withdraw { amount }
Borrow { amount }
Repay
ethanfrey commented 2 years ago

Token transfers happen on the lendex-token contract itself, not the market. Where the lendex-token contract needs to ask the market if it is allowed to transfer.

You may have to update some of those multi-tests as well.