Skip to content

Commit

Permalink
removinh auth queries and base_decimal, some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jbernal87 committed Mar 13, 2024
1 parent 9443f46 commit 47f1633
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 223 deletions.
18 changes: 9 additions & 9 deletions contracts/injective-cosmwasm-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ optimize = """docker run --rm -v "$(pwd)":/code \

[dependencies]
cosmwasm-std = { version = "1.5.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] }
cw-storage-plus = "1.2.0"
cw2 = "0.16.0"
cw-storage-plus = { version = "1.2.0" }
cw2 = { version = "0.16.0" }
injective-cosmwasm = { path = "../../packages/injective-cosmwasm" }
injective-math = { path = "../../packages/injective-math" }
injective-protobuf = { path = "../../packages/injective-protobuf"}
schemars = { version ="0.8.16"}
schemars = { version ="0.8.16"}
serde = { version = "1.0.196", default-features = false, features = [ "derive" ] }
thiserror = { version = "1.0.56" }
protobuf = "3.3.0"
prost = "0.11.9"
protobuf = { version = "3.3.0" }
prost = { version = "0.11.9" }
injective-std = { version = "0.1.5" }
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
cosmwasm-schema = { version = "1.5.0" }
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
cosmwasm-schema = { version = "1.5.0" }

[dev-dependencies]
injective-test-tube = "1.1.7"
injective-std = { version = "0.1.5" }
injective-test-tube = { version = "1.1.7" }
injective-std = { version = "0.1.5" }
18 changes: 5 additions & 13 deletions contracts/injective-cosmwasm-mock/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use crate::{
query::{
handle_aggregate_account_volume_query, handle_aggregate_market_volume_query, handle_derivative_market_mid_price_and_tob_query,
handle_derivative_market_orderbook_query, handle_derivative_market_query, handle_derivative_orders_to_cancel_up_to_amount_query,
handle_effective_subaccount_position_query, handle_exchange_params_query, handle_grantee_grants_query,
handle_market_atomic_execution_fee_multiplier_query, handle_market_volatility_query, handle_perpetual_market_funding_query,
handle_perpetual_market_info_query, handle_query_grants_query, handle_query_oracle_price_query, handle_query_oracle_volatility_query,
handle_spot_market_mid_price_and_tob_query, handle_spot_market_orderbook_query, handle_spot_market_query,
handle_spot_orders_to_cancel_up_to_amount_query, handle_subaccount_deposit_query, handle_trader_derivative_orders_query,
handle_trader_spot_orders_query, handle_vanilla_subaccount_position_query,
handle_effective_subaccount_position_query, handle_exchange_params_query, handle_market_atomic_execution_fee_multiplier_query,
handle_market_volatility_query, handle_perpetual_market_funding_query, handle_perpetual_market_info_query, handle_query_oracle_price_query,
handle_query_oracle_volatility_query, handle_spot_market_mid_price_and_tob_query, handle_spot_market_orderbook_query,
handle_spot_market_query, handle_spot_orders_to_cancel_up_to_amount_query, handle_subaccount_deposit_query,
handle_trader_derivative_orders_query, handle_trader_spot_orders_query, handle_vanilla_subaccount_position_query,
},
reply::{handle_create_derivative_order_reply, handle_create_order_reply},
};
Expand Down Expand Up @@ -123,13 +122,6 @@ pub fn query(deps: Deps<InjectiveQueryWrapper>, _env: Env, msg: QueryMsg) -> Std
limit_cumulative_notional,
} => handle_derivative_market_orderbook_query(&querier, &market_id, limit_cumulative_notional),
QueryMsg::TestMarketAtomicExecutionFeeMultiplier { market_id } => handle_market_atomic_execution_fee_multiplier_query(&querier, &market_id),
QueryMsg::TestQueryGrants {
grantee,
granter,
msg_type_url,
pagination,
} => handle_query_grants_query(&querier, grantee, granter, msg_type_url, pagination),
QueryMsg::TestGranteeGrants { grantee, pagination } => handle_grantee_grants_query(&querier, grantee, pagination),
QueryMsg::TestQueryOracleVolatility {
base_info,
quote_info,
Expand Down
8 changes: 3 additions & 5 deletions contracts/injective-cosmwasm-mock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
pub mod contract;
mod error;
pub mod msg;
#[cfg(test)]
mod testing;

mod handle;
pub mod msg;
mod order_management;
mod query;
mod reply;
mod state;
#[cfg(test)]
mod testing;
mod types;
#[cfg(test)]
pub mod utils;

pub use crate::error::ContractError;
10 changes: 0 additions & 10 deletions contracts/injective-cosmwasm-mock/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,6 @@ pub enum QueryMsg {
TestMarketAtomicExecutionFeeMultiplier {
market_id: MarketId,
},
TestQueryGrants {
grantee: String,
granter: String,
msg_type_url: String,
pagination: Option<u32>,
},
TestGranteeGrants {
grantee: String,
pagination: Option<u32>,
},
TestQueryOracleVolatility {
base_info: Option<OracleInfo>,
quote_info: Option<OracleInfo>,
Expand Down
14 changes: 0 additions & 14 deletions contracts/injective-cosmwasm-mock/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,6 @@ pub fn handle_market_atomic_execution_fee_multiplier_query(querier: &InjectiveQu
to_json_binary(&querier.query_market_atomic_execution_fee_multiplier(market_id)?)
}

pub fn handle_query_grants_query(
querier: &InjectiveQuerier,
grantee: String,
granter: String,
msg_type_url: String,
pagination: Option<u32>,
) -> StdResult<Binary> {
to_json_binary(&querier.query_grants(&grantee, &granter, &msg_type_url, &pagination)?)
}

pub fn handle_grantee_grants_query(querier: &InjectiveQuerier, grantee: String, pagination: Option<u32>) -> StdResult<Binary> {
to_json_binary(&querier.query_grantee_grants(&grantee, &pagination)?)
}

pub fn handle_query_oracle_volatility_query(
querier: &InjectiveQuerier,
base_info: Option<OracleInfo>,
Expand Down
1 change: 0 additions & 1 deletion contracts/injective-cosmwasm-mock/src/testing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod test_authz;
mod test_exchange;
mod test_exchange_derivative;
mod test_oracle;
48 changes: 0 additions & 48 deletions contracts/injective-cosmwasm-mock/src/testing/test_authz.rs

This file was deleted.

31 changes: 2 additions & 29 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ use crate::{
CancellationStrategy, Deposit, DerivativeMarketResponse, ExchangeParamsResponse, FullDerivativeMarket, InjectiveQuery, InjectiveQueryWrapper,
MarketMidPriceAndTOBResponse, MarketStatus, MarketVolatilityResponse, OracleInfo, OracleVolatilityResponse, OrderSide,
PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, PythPriceResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse,
QueryDenomDecimalResponse, QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, SpotMarketResponse,
SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse,
TraderSpotOrdersResponse,
QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, SpotMarketResponse, SubaccountDepositResponse,
SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, TraderSpotOrdersResponse,
};
use crate::{MarketId, SubaccountId};

Expand Down Expand Up @@ -211,16 +210,6 @@ fn default_aggregate_account_volume_handler() -> QuerierResult {
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}

fn default_denom_decimal_handler() -> QuerierResult {
let response = QueryDenomDecimalResponse { decimals: 6 };
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}

fn default_denom_decimals_handler() -> QuerierResult {
let response = QueryDenomDecimalsResponse { denom_decimals: vec![] };
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}

fn default_oracle_volatility_response_handler() -> QuerierResult {
let response = OracleVolatilityResponse {
volatility: Some(FPDecimal::ONE),
Expand Down Expand Up @@ -550,14 +539,6 @@ impl WasmMockQuerier {
_ => panic!("unsupported"),
},
QueryRequest::Custom(query) => match query.query_data.clone() {
InjectiveQuery::Grants {
granter: _,
grantee: _,
msg_type_url: _,
pagination: _,
} => todo!(),
InjectiveQuery::GranteeGrants { grantee: _, pagination: _ } => todo!(),
InjectiveQuery::GranterGrants { granter: _, pagination: _ } => todo!(),
InjectiveQuery::SubaccountDeposit { subaccount_id, denom } => match &self.subaccount_deposit_response_handler {
Some(handler) => handler.handle(subaccount_id, denom),
None => default_subaccount_deposit_response_handler(),
Expand Down Expand Up @@ -660,14 +641,6 @@ impl WasmMockQuerier {
Some(handler) => handler.handle(account),
None => default_aggregate_account_volume_handler(),
},
InjectiveQuery::DenomDecimal { denom } => match &self.denom_decimal_handler {
Some(handler) => handler.handle(denom),
None => default_denom_decimal_handler(),
},
InjectiveQuery::DenomDecimals { denoms } => match &self.denom_decimals_handler {
Some(handler) => handler.handle(denoms),
None => default_denom_decimals_handler(),
},
InjectiveQuery::StakedAmount {
delegator_address,
max_delegations,
Expand Down
77 changes: 4 additions & 73 deletions packages/injective-cosmwasm/src/querier.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
use cosmwasm_std::{Addr, QuerierWrapper, StdResult};

use injective_math::FPDecimal;

use crate::authz::response::{GranteeGrantsResponse, GranterGrantsResponse, GrantsResponse};
use crate::exchange::response::StakedAmountResponse;
use crate::exchange::{
cancel::CancellationStrategy,
order::OrderSide,
response::{
DerivativeMarketResponse, ExchangeParamsResponse, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OracleVolatilityResponse,
PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, QueryAggregateMarketVolumeResponse, QueryAggregateVolumeResponse,
QueryDenomDecimalResponse, QueryDenomDecimalsResponse, QueryMarketAtomicExecutionFeeMultiplierResponse, QueryOrderbookResponse,
SpotMarketResponse, SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse,
TraderDerivativeOrdersResponse, TraderSpotOrdersResponse,
QueryMarketAtomicExecutionFeeMultiplierResponse, QueryOrderbookResponse, SpotMarketResponse, StakedAmountResponse, SubaccountDepositResponse,
SubaccountEffectivePositionInMarketResponse, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, TraderSpotOrdersResponse,
},
types::{MarketId, SubaccountId},
};
Expand All @@ -25,6 +18,8 @@ use crate::query::{InjectiveQuery, InjectiveQueryWrapper};
use crate::route::InjectiveRoute;
use crate::tokenfactory::response::{TokenFactoryCreateDenomFeeResponse, TokenFactoryDenomSupplyResponse};
use crate::wasmx::response::QueryContractRegistrationInfoResponse;
use cosmwasm_std::{Addr, QuerierWrapper, StdResult};
use injective_math::FPDecimal;

pub struct InjectiveQuerier<'a> {
querier: &'a QuerierWrapper<'a, InjectiveQueryWrapper>,
Expand All @@ -35,48 +30,6 @@ impl<'a> InjectiveQuerier<'a> {
InjectiveQuerier { querier }
}

// Authz
pub fn query_grants(&self, grantee: &str, granter: &str, msg_type_url: &str, pagination: &Option<u32>) -> StdResult<GrantsResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Authz,
query_data: InjectiveQuery::Grants {
grantee: grantee.to_string(),
granter: granter.to_string(),
msg_type_url: msg_type_url.to_string(),
pagination: *pagination,
},
};

let res: GrantsResponse = self.querier.query(&request.into())?;
Ok(res)
}

pub fn query_grantee_grants(&self, grantee: &str, pagination: &Option<u32>) -> StdResult<GranteeGrantsResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Authz,
query_data: InjectiveQuery::GranteeGrants {
grantee: grantee.to_string(),
pagination: *pagination,
},
};

let res: GranteeGrantsResponse = self.querier.query(&request.into())?;
Ok(res)
}

pub fn query_granter_grants(&self, granter: &str, pagination: &Option<u32>) -> StdResult<GranterGrantsResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Authz,
query_data: InjectiveQuery::GranterGrants {
granter: granter.to_string(),
pagination: *pagination,
},
};

let res: GranterGrantsResponse = self.querier.query(&request.into())?;
Ok(res)
}

// Exchange
pub fn query_exchange_params(&self) -> StdResult<ExchangeParamsResponse> {
let request = InjectiveQueryWrapper {
Expand Down Expand Up @@ -363,28 +316,6 @@ impl<'a> InjectiveQuerier<'a> {
Ok(res)
}

pub fn query_denom_decimal<T: Into<String> + Clone>(&self, denom: &'a T) -> StdResult<QueryDenomDecimalResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Exchange,
query_data: InjectiveQuery::DenomDecimal { denom: denom.clone().into() },
};

let res: QueryDenomDecimalResponse = self.querier.query(&request.into())?;
Ok(res)
}

pub fn query_denom_decimals<T: Into<Vec<String>> + Clone>(&self, denoms: &'a T) -> StdResult<QueryDenomDecimalsResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Exchange,
query_data: InjectiveQuery::DenomDecimals {
denoms: denoms.clone().into(),
},
};

let res: QueryDenomDecimalsResponse = self.querier.query(&request.into())?;
Ok(res)
}

pub fn query_spot_market_mid_price_and_tob<T: Into<MarketId> + Clone>(&self, market_id: &'a T) -> StdResult<MarketMidPriceAndTOBResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Exchange,
Expand Down
21 changes: 0 additions & 21 deletions packages/injective-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ pub struct InjectiveQueryWrapper {
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InjectiveQuery {
// Authz
Grants {
granter: String,
grantee: String,
msg_type_url: String,
pagination: Option<u32>,
},
GranteeGrants {
grantee: String,
pagination: Option<u32>,
},
GranterGrants {
granter: String,
pagination: Option<u32>,
},
// Exchange
ExchangeParams {},
SubaccountDeposit {
Expand Down Expand Up @@ -130,12 +115,6 @@ pub enum InjectiveQuery {
AggregateAccountVolume {
account: String,
},
DenomDecimal {
denom: String,
},
DenomDecimals {
denoms: Vec<String>,
},
MarketAtomicExecutionFeeMultiplier {
market_id: MarketId,
},
Expand Down

0 comments on commit 47f1633

Please sign in to comment.