Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turned aggregate_volume into an option as the proto is omit if empty #213

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@
},
};

use crate::utils::{add_spot_orders, get_perpetual_market_id, scale_price_quantity_for_spot_market, ExchangeType, HumanOrder, scale_price_quantity_perp_market, add_derivative_orders};
use crate::utils::{
add_derivative_orders, add_spot_orders, get_perpetual_market_id, scale_price_quantity_for_spot_market, scale_price_quantity_perp_market,
ExchangeType, HumanOrder,
};
use cosmwasm_std::{Addr, Coin};
use injective_cosmwasm::exchange::response::{QueryAggregateVolumeResponse, QueryOrderbookResponse};
use injective_cosmwasm::{DerivativeMarketResponse, ExchangeParamsResponse, MarketId, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OrderSide, PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarketResponse, SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountId, SubaccountPositionInMarketResponse, TraderDerivativeOrdersResponse, TraderSpotOrdersResponse, TrimmedDerivativeLimitOrder, TrimmedSpotLimitOrder};
use injective_cosmwasm::{
DerivativeMarketResponse, ExchangeParamsResponse, MarketId, MarketMidPriceAndTOBResponse, MarketVolatilityResponse, OrderSide,
PerpetualMarketFundingResponse, PerpetualMarketInfoResponse, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarketResponse,
SubaccountDepositResponse, SubaccountEffectivePositionInMarketResponse, SubaccountId, SubaccountPositionInMarketResponse,
TraderDerivativeOrdersResponse, TraderSpotOrdersResponse, TrimmedDerivativeLimitOrder, TrimmedSpotLimitOrder,
};
use injective_math::FPDecimal;
use injective_std::types::injective::exchange::v1beta1::{Deposit, DerivativeOrder, MsgCreateDerivativeLimitOrder, MsgCreateSpotLimitOrder, MsgDeposit, MsgInstantPerpetualMarketLaunch, MsgInstantSpotMarketLaunch, OrderInfo, OrderType, QueryAggregateMarketVolumeResponse, QuerySubaccountDepositsRequest, SpotOrder};
use injective_std::types::injective::exchange::v1beta1::{
Deposit, DerivativeOrder, MsgCreateDerivativeLimitOrder, MsgCreateSpotLimitOrder, MsgDeposit, MsgInstantPerpetualMarketLaunch,
MsgInstantSpotMarketLaunch, OrderInfo, OrderType, QueryAggregateMarketVolumeResponse, QuerySubaccountDepositsRequest, SpotOrder,
};
use injective_test_tube::injective_cosmwasm::get_default_subaccount_id_for_checked_address;
use injective_test_tube::{Account, Exchange, Module, RunnerResult, Wasm};

Expand Down Expand Up @@ -269,8 +280,7 @@
];
add_derivative_orders(&env.app, market_id.clone(), liquidity_orders.to_owned(), None);

let (price, quantity, margin) =
scale_price_quantity_perp_market("9.7", "1", "2", &QUOTE_DECIMALS);
let (price, quantity, margin) = scale_price_quantity_perp_market("9.7", "1", "2", &QUOTE_DECIMALS);

let trader = &env.users[1];
let subaccount_id = get_default_subaccount_id_for_checked_address(&Addr::unchecked(trader.account.address()))
Expand Down Expand Up @@ -304,7 +314,6 @@
};
let res: SubaccountEffectivePositionInMarketResponse = wasm.query(&env.contract_address, &query_msg).unwrap();
assert!(res.state.is_some());

}

#[test]
Expand Down Expand Up @@ -339,8 +348,7 @@
];
add_derivative_orders(&env.app, market_id.clone(), liquidity_orders.to_owned(), None);

let (price, quantity, margin) =
scale_price_quantity_perp_market("9.7", "1", "2", &QUOTE_DECIMALS);
let (price, quantity, margin) = scale_price_quantity_perp_market("9.7", "1", "2", &QUOTE_DECIMALS);

let trader = &env.users[1];
let subaccount_id = get_default_subaccount_id_for_checked_address(&Addr::unchecked(trader.account.address()))
Expand Down Expand Up @@ -375,18 +383,14 @@
let res: SubaccountPositionInMarketResponse = wasm.query(&env.contract_address, &query_msg).unwrap();
assert!(res.state.is_some());

let liquidity_orders: Vec<HumanOrder> = vec![
HumanOrder {
price: "9.7".to_string(),
quantity: "10".to_string(),
order_type: OrderType::Sell,
},
];
let liquidity_orders: Vec<HumanOrder> = vec![HumanOrder {
price: "9.7".to_string(),
quantity: "10".to_string(),
order_type: OrderType::Sell,
}];
add_derivative_orders(&env.app, market_id.clone(), liquidity_orders.to_owned(), None);

let res: SubaccountPositionInMarketResponse = wasm.query(&env.contract_address, &query_msg).unwrap();

Check warning on line 393 in contracts/injective-cosmwasm-mock/src/testing/query_exchange_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `res`

Check warning on line 393 in contracts/injective-cosmwasm-mock/src/testing/query_exchange_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `res`


}

#[test]
Expand Down Expand Up @@ -503,8 +507,7 @@
let exchange = Exchange::new(&env.app);
let market_id = env.market_id.unwrap();

let (price, quantity, margin) =
scale_price_quantity_perp_market("10.1", "1", "2", &QUOTE_DECIMALS);
let (price, quantity, margin) = scale_price_quantity_perp_market("10.1", "1", "2", &QUOTE_DECIMALS);

let trader = &env.users[0];
let subaccount_id = get_default_subaccount_id_for_checked_address(&Addr::unchecked(trader.account.address()))
Expand Down Expand Up @@ -554,10 +557,8 @@
assert_eq!(orders[0].fillable, expected_order.fillable);
assert_eq!(orders[0].isBuy, expected_order.isBuy);
assert_eq!(orders[0].margin, expected_order.margin);

}


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_spot_market_mid_price_and_tob() {
Expand Down Expand Up @@ -675,7 +676,6 @@
);
}


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_perpetual_market_info() {
Expand Down Expand Up @@ -715,7 +715,6 @@
let state = res.state.unwrap();
assert_eq!(state.cumulative_funding, FPDecimal::ZERO);
assert_eq!(state.cumulative_price, FPDecimal::ZERO);

}

#[test]
Expand Down Expand Up @@ -785,7 +784,7 @@
fn test_query_derivative_market_mid_price_and_tob() {
let env = Setup::new(ExchangeType::Derivative);
let wasm = Wasm::new(&env.app);
let exchange = Exchange::new(&env.app);

Check warning on line 787 in contracts/injective-cosmwasm-mock/src/testing/query_exchange_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `exchange`

Check warning on line 787 in contracts/injective-cosmwasm-mock/src/testing/query_exchange_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `exchange`
let market_id = env.market_id.unwrap();

let liquidity_orders: Vec<HumanOrder> = vec![
Expand Down Expand Up @@ -915,21 +914,20 @@
add_spot_orders(&env.app, market_id.clone(), liquidity_orders);

let query_msg = QueryMsg::TestAggregateAccountVolume {
account_id: env.users[0].account.address().to_string(),
account_id: env.users[0].subaccount_id.to_string(),
};

let res: RunnerResult<String> = wasm.query(&env.contract_address, &query_msg);
let res: RunnerResult<QueryAggregateVolumeResponse> = wasm.query(&env.contract_address, &query_msg);
println!("{:?}", res);
assert_eq!(1,2);
assert_eq!(1, 2);
}


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_derivative_market_orderbook() {
let env = Setup::new(ExchangeType::Derivative);
let wasm = Wasm::new(&env.app);
let exchange = Exchange::new(&env.app);

Check warning on line 930 in contracts/injective-cosmwasm-mock/src/testing/query_exchange_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `exchange`

Check warning on line 930 in contracts/injective-cosmwasm-mock/src/testing/query_exchange_test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `exchange`
let market_id = env.market_id.unwrap();

let liquidity_orders: Vec<HumanOrder> = vec![
Expand Down Expand Up @@ -958,7 +956,7 @@

let query_msg = QueryMsg::TestDerivativeMarketOrderbook {
market_id: MarketId::new(market_id.clone()).unwrap(),
limit_cumulative_notional: FPDecimal::MAX ,
limit_cumulative_notional: FPDecimal::MAX,
};

let res: QueryOrderbookResponse = wasm.query(&env.contract_address, &query_msg).unwrap();
Expand Down Expand Up @@ -1010,22 +1008,18 @@
assert_eq!(res.multiplier, human_to_dec("0.0000025", QUOTE_DECIMALS));
}


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_spot_orders_to_cancel_up_to_amount() {

}
fn test_query_spot_orders_to_cancel_up_to_amount() {}

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_derivative_orders_to_cancel_up_to_amount() {}


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_trader_transient_spot_orders() {}

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_trader_transient_derivative_orders() {}
fn test_query_trader_transient_derivative_orders() {}
2 changes: 1 addition & 1 deletion packages/injective-cosmwasm/src/exchange/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct QueryOrderbookResponse {
/// Response to query for aggregate volumes of a given account/subaccount - divided by markets
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct QueryAggregateVolumeResponse {
pub aggregate_volumes: Vec<MarketVolume>,
pub aggregate_volumes: Option<Vec<MarketVolume>>,
}

/// Response to query for aggregate volume for a given market
Expand Down
4 changes: 2 additions & 2 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn default_aggregate_market_volume_handler() -> QuerierResult {

fn default_aggregate_account_volume_handler() -> QuerierResult {
let response = QueryAggregateVolumeResponse {
aggregate_volumes: vec![
aggregate_volumes: Some(vec![
MarketVolume {
market_id: MarketId::unchecked("market_id_1"),
volume: VolumeByType {
Expand All @@ -206,7 +206,7 @@ fn default_aggregate_account_volume_handler() -> QuerierResult {
taker_volume: FPDecimal::from(25000000u128),
},
},
],
]),
};
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
}
Expand Down
Loading