Skip to content

Commit

Permalink
Lend-market v2: Implement query interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb committed Nov 28, 2023
1 parent b98f062 commit 20fd1cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
36 changes: 35 additions & 1 deletion contracts/lending/market_v2/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,41 @@ mod execute {
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
use QueryMsg::*;
Ok(to_binary(&"")?)
let res = match msg {
WithPermit { permit, query_msg } => {
// Handle AuthQueryMsg here
match query_msg {
AuthQueryMsg::TokensBalance { account } => {
to_binary(&query::tokens_balance(deps, env, account)?)?
}
AuthQueryMsg::Withdrawable { account } => {
to_binary(&query::withdrawable(deps, env, account)?)?
}
AuthQueryMsg::Borrowable { account } => {
to_binary(&query::borrowable(deps, env, account)?)?
}
AuthQueryMsg::CreditLine { account } => {
let account = deps.api.addr_validate(&account)?;
to_binary(&query::credit_line(deps, env, account)?)?
}
}
}
Configuration {} => to_binary(&query::config(deps, env)?)?,
Interest {} => to_binary(&query::interest(deps)?)?,
PriceMarketLocalPerCommon {} => to_binary(&query::price_market_local_per_common(deps)?)?,
TransferableAmount {
token,
account,
viewing_key,
} => to_binary(&query::transferable_amount(deps, token, account)?)?,
Reserve {} => to_binary(&query::reserve(deps, env)?)?,
Apy {} => to_binary(&query::apy(deps)?)?,
TotalDebt {} => {
let (total, multiplier) = debt::total(deps.storage)?;
to_binary(&TotalDebtResponse { total, multiplier })?
}
};
Ok(res)
}

mod query {
Expand Down
21 changes: 4 additions & 17 deletions contracts/lending/market_v2/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pub enum QueryMsg {
token: ContractInfo,
/// Address that wishes to transfer
account: String,
viewing_key: String,
},
#[returns(ReserveResponse)]
Reserve {},
Expand All @@ -139,28 +138,16 @@ impl Query for QueryMsg {
pub enum AuthQueryMsg {
/// Returns TokensBalanceResponse
#[returns(TokensBalanceResponse)]
TokensBalance {
account: String,
viewing_key: String,
},
TokensBalance { account: String },
/// Returns the amount that the given account can withdraw
#[returns(Coin)]
Withdrawable {
account: String,
viewing_key: String,
},
Withdrawable { account: String },
/// Returns the amount that the given account can borrow
#[returns(Coin)]
Borrowable {
account: String,
viewing_key: String,
},
Borrowable { account: String },
/// Returns CreditLineResponse
#[returns(lending_utils::credit_line::CreditLineResponse)]
CreditLine {
account: String,
viewing_key: String,
},
CreditLine { account: String },
}

// Define an enum for all possible return types of AuthQueryMsg
Expand Down

0 comments on commit 20fd1cf

Please sign in to comment.