From 20fd1cf2272e88f52cdd73f2a8d3743b212f527e Mon Sep 17 00:00:00 2001 From: Jakub Date: Tue, 28 Nov 2023 13:46:59 +0100 Subject: [PATCH] Lend-market v2: Implement query interface --- contracts/lending/market_v2/src/contract.rs | 36 ++++++++++++++++++++- contracts/lending/market_v2/src/msg.rs | 21 +++--------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/contracts/lending/market_v2/src/contract.rs b/contracts/lending/market_v2/src/contract.rs index aad23d52..7946eddd 100644 --- a/contracts/lending/market_v2/src/contract.rs +++ b/contracts/lending/market_v2/src/contract.rs @@ -735,7 +735,41 @@ mod execute { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { 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 { diff --git a/contracts/lending/market_v2/src/msg.rs b/contracts/lending/market_v2/src/msg.rs index da7b370a..dee28ecd 100644 --- a/contracts/lending/market_v2/src/msg.rs +++ b/contracts/lending/market_v2/src/msg.rs @@ -117,7 +117,6 @@ pub enum QueryMsg { token: ContractInfo, /// Address that wishes to transfer account: String, - viewing_key: String, }, #[returns(ReserveResponse)] Reserve {}, @@ -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