Skip to content

Commit

Permalink
fix marketmap queries
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 15, 2024
1 parent 584a411 commit f7f850c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/marketmap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cw2 = { workspace = true }
schemars = { workspace = true }
serde = { version = "1.0.180", default-features = false, features = ["derive"] }
neutron-sdk = { workspace = true }
neutron-std = { workspace = true }

[dev-dependencies]
cosmwasm-schema = { workspace = true }
27 changes: 13 additions & 14 deletions contracts/marketmap/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use cosmwasm_std::{
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
};
use cw2::set_contract_version;
use neutron_std::types::slinky::marketmap::v1::MarketmapQuerier;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::query::QueryMsg;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {}
Expand Down Expand Up @@ -38,27 +40,24 @@ pub fn execute(
}

#[entry_point]
pub fn query(deps: Deps, env: Env, msg: MarketMapQuery) -> StdResult<Binary> {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
query_marketmap(deps, env, msg)
}

fn query_marketmap(deps: Deps, _env: Env, msg: MarketMapQuery) -> StdResult<Binary> {
fn query_marketmap(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
let querier = MarketmapQuerier::new(&deps.querier);
match msg {
MarketMapQuery::Params { .. } => {
let query_response: ParamsResponse = deps.querier.query(&msg.into())?;
to_json_binary(&query_response)
QueryMsg::Params { .. } => {
to_json_binary(&querier.params()?)
}
MarketMapQuery::LastUpdated { .. } => {
let query_response: LastUpdatedResponse = deps.querier.query(&msg.into())?;
to_json_binary(&query_response)
QueryMsg::LastUpdated { .. } => {
to_json_binary(&querier.last_updated()?)
}
MarketMapQuery::MarketMap { .. } => {
let query_response: MarketMapResponse = deps.querier.query(&msg.into())?;
to_json_binary(&query_response)
QueryMsg::MarketMap { .. } => {
to_json_binary(&querier.market_map()?)
}
MarketMapQuery::Market { .. } => {
let query_response: MarketResponse = deps.querier.query(&msg.into())?;
to_json_binary(&query_response)
QueryMsg::Market { currency_pair } => {
to_json_binary(&querier.market(Some(currency_pair))?)
}
}
}
1 change: 1 addition & 0 deletions contracts/marketmap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod contract;
mod query;
14 changes: 14 additions & 0 deletions contracts/marketmap/src/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use neutron_std::types::slinky::types::v1::CurrencyPair;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
Params { },
LastUpdated { },
MarketMap { },
Market {
currency_pair: CurrencyPair,
},
}
11 changes: 6 additions & 5 deletions contracts/neutron_validator_test/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use cosmwasm_std::{coin, to_json_binary, Addr, Binary, CosmosMsg, CustomQuery, D
use cw2::set_contract_version;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use neutron_sdk::interchain_queries::queries::get_registered_query;
use neutron_sdk::interchain_queries::types::{
Expand All @@ -38,7 +37,7 @@ use neutron_sdk::interchain_queries::v045::types::{COSMOS_SDK_TRANSFER_MSG_URL,
use neutron_sdk::interchain_queries::v045::{
new_register_balances_query_msg, new_register_transfers_query_msg,
};
use neutron_sdk::interchain_txs::helpers::{decode_message_response, get_port_id};
use neutron_sdk::interchain_txs::helpers::{decode_message_response, get_port_id, register_interchain_account};
use neutron_sdk::interchain_txs::v047::helpers::decode_acknowledgement_response;
use neutron_sdk::sudo::msg::{RequestPacket, SudoMsg};
use neutron_sdk::{NeutronError, NeutronResult};
Expand All @@ -52,6 +51,7 @@ use crate::storage::{
};
use neutron_std::types::cosmos::base::v1beta1::Coin as CosmosCoin;
use neutron_std::types::neutron::interchaintxs::v1::{InterchaintxsQuerier, MsgSubmitTxResponse};
use neutron_sdk::interchain_queries::helpers::{update_interchain_query as helpers_update_interchain_query, remove_interchain_query as helpers_remove_interchain_query};

// Default timeout for SubmitTX is two weeks
const DEFAULT_TIMEOUT_SECONDS: u64 = 60 * 60 * 24 * 7 * 2;
Expand Down Expand Up @@ -258,11 +258,12 @@ fn execute_register_ica(
interchain_account_id: String,
) -> NeutronResult<Response> {
let register = register_interchain_account(
env.contract.address.clone(),
connection_id,
interchain_account_id.clone(),
None,
vec![],
Some(ChannelOrdering::OrderOrdered),
);
)?;
let key = get_port_id(env.contract.address.as_str(), &interchain_account_id);
INTERCHAIN_ACCOUNTS.save(deps.storage, key, &None)?;
Ok(Response::new().add_message(register))
Expand Down Expand Up @@ -428,7 +429,7 @@ pub fn register_transfers_query(
}

pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult<Response> {
let remove_msg = remove_interchain_query_helper(contract, query_id)?;
let remove_msg = helpers_remove_interchain_query(contract, query_id)?;
Ok(Response::new().add_message(remove_msg))
}

Expand Down

0 comments on commit f7f850c

Please sign in to comment.