From 88ab475734a82f12a8eec19be83c30fd207ab5f7 Mon Sep 17 00:00:00 2001 From: Csongor Kiss Date: Tue, 27 Jun 2023 20:17:16 +0100 Subject: [PATCH] terra/terra-cosmwasm: fix custom query serialisation --- .../packages/terra-cosmwasm-2.2.0/src/lib.rs | 6 +- .../packages/terra-cosmwasm-2.2.0/src/msg.rs | 63 ----------------- .../terra-cosmwasm-2.2.0/src/querier.rs | 70 ++----------------- .../terra-cosmwasm-2.2.0/src/query.rs | 12 +--- .../terra-cosmwasm-2.2.0/src/route.rs | 12 ---- 5 files changed, 7 insertions(+), 156 deletions(-) delete mode 100644 terra/packages/terra-cosmwasm-2.2.0/src/msg.rs delete mode 100644 terra/packages/terra-cosmwasm-2.2.0/src/route.rs diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs b/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs index a6f4fa5f1c..6e5845184a 100644 --- a/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs +++ b/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs @@ -1,15 +1,11 @@ -mod msg; mod querier; mod query; -mod route; -pub use msg::{create_swap_msg, create_swap_send_msg, TerraMsg, TerraMsgWrapper}; pub use querier::TerraQuerier; pub use query::{ ContractInfoResponse, ExchangeRateItem, ExchangeRatesResponse, SwapResponse, TaxCapResponse, - TaxRateResponse, TerraQuery, TerraQueryWrapper, + TaxRateResponse, TerraQuery, }; -pub use route::TerraRoute; // This export is added to all contracts that import this package, signifying that they require // "terra" support on the chain they run on. diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/msg.rs b/terra/packages/terra-cosmwasm-2.2.0/src/msg.rs deleted file mode 100644 index 06fe27dace..0000000000 --- a/terra/packages/terra-cosmwasm-2.2.0/src/msg.rs +++ /dev/null @@ -1,63 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use crate::route::TerraRoute; -use cosmwasm_std::{Coin, CosmosMsg}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -/// TerraMsgWrapper is an override of CosmosMsg::Custom to show this works and can be extended in the contract -pub struct TerraMsgWrapper { - pub route: TerraRoute, - pub msg_data: TerraMsg, -} - -// this is a helper to be able to return these as CosmosMsg easier -impl From for CosmosMsg { - fn from(original: TerraMsgWrapper) -> Self { - CosmosMsg::Custom(original) - } -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum TerraMsg { - Swap { - offer_coin: Coin, - ask_denom: String, - }, - SwapSend { - to_address: String, - offer_coin: Coin, - ask_denom: String, - }, -} - -// create_swap_msg returns wrapped swap msg -pub fn create_swap_msg(offer_coin: Coin, ask_denom: String) -> CosmosMsg { - TerraMsgWrapper { - route: TerraRoute::Market, - msg_data: TerraMsg::Swap { - offer_coin, - ask_denom, - }, - } - .into() -} - -// create_swap_send_msg returns wrapped swap send msg -pub fn create_swap_send_msg( - to_address: String, - offer_coin: Coin, - ask_denom: String, -) -> CosmosMsg { - TerraMsgWrapper { - route: TerraRoute::Market, - msg_data: TerraMsg::SwapSend { - to_address, - offer_coin, - ask_denom, - }, - } - .into() -} diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs b/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs index 19dac14b47..dab35138d3 100644 --- a/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs +++ b/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs @@ -1,10 +1,6 @@ -use cosmwasm_std::{Coin, QuerierWrapper, StdResult}; +use cosmwasm_std::{QuerierWrapper, StdResult}; -use crate::query::{ - ContractInfoResponse, ExchangeRatesResponse, SwapResponse, TaxCapResponse, TaxRateResponse, - TerraQuery, TerraQueryWrapper, -}; -use crate::route::TerraRoute; +use crate::query::{TaxCapResponse, TaxRateResponse, TerraQuery}; /// This is a helper wrapper to easily use our custom queries pub struct TerraQuerier<'a> { @@ -16,29 +12,9 @@ impl<'a> TerraQuerier<'a> { TerraQuerier { querier } } - pub fn query_swap>( - &self, - offer_coin: Coin, - ask_denom: T, - ) -> StdResult { - let request = TerraQueryWrapper { - route: TerraRoute::Market, - query_data: TerraQuery::Swap { - offer_coin, - ask_denom: ask_denom.into(), - }, - } - .into(); - - self.querier.custom_query(&request) - } - pub fn query_tax_cap>(&self, denom: T) -> StdResult { - let request = TerraQueryWrapper { - route: TerraRoute::Treasury, - query_data: TerraQuery::TaxCap { - denom: denom.into(), - }, + let request = TerraQuery::TaxCap { + denom: denom.into(), } .into(); @@ -46,43 +22,7 @@ impl<'a> TerraQuerier<'a> { } pub fn query_tax_rate(&self) -> StdResult { - let request = TerraQueryWrapper { - route: TerraRoute::Treasury, - query_data: TerraQuery::TaxRate {}, - } - .into(); - - self.querier.custom_query(&request) - } - - pub fn query_exchange_rates>( - &self, - base_denom: T, - quote_denoms: Vec, - ) -> StdResult { - let request = TerraQueryWrapper { - route: TerraRoute::Oracle, - query_data: TerraQuery::ExchangeRates { - base_denom: base_denom.into(), - quote_denoms: quote_denoms.into_iter().map(|x| x.into()).collect(), - }, - } - .into(); - - self.querier.custom_query(&request) - } - - pub fn query_contract_info>( - &self, - contract_address: T, - ) -> StdResult { - let request = TerraQueryWrapper { - route: TerraRoute::Wasm, - query_data: TerraQuery::ContractInfo { - contract_address: contract_address.into(), - }, - } - .into(); + let request = TerraQuery::TaxRate {}.into(); self.querier.custom_query(&request) } diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/query.rs b/terra/packages/terra-cosmwasm-2.2.0/src/query.rs index 07fbe3fc53..78dcc9dd1a 100644 --- a/terra/packages/terra-cosmwasm-2.2.0/src/query.rs +++ b/terra/packages/terra-cosmwasm-2.2.0/src/query.rs @@ -1,19 +1,9 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::route::TerraRoute; use cosmwasm_std::{Coin, CustomQuery, Decimal, Uint128}; -/// TerraQueryWrapper is an override of QueryRequest::Custom to access Terra-specific modules -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub struct TerraQueryWrapper { - pub route: TerraRoute, - pub query_data: TerraQuery, -} - -// implement custom query -impl CustomQuery for TerraQueryWrapper {} +impl CustomQuery for TerraQuery {} /// TerraQuery is defines available query datas #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/route.rs b/terra/packages/terra-cosmwasm-2.2.0/src/route.rs deleted file mode 100644 index 164fa54df0..0000000000 --- a/terra/packages/terra-cosmwasm-2.2.0/src/route.rs +++ /dev/null @@ -1,12 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -/// TerraRoute is enum type to represent terra query route path -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum TerraRoute { - Market, - Treasury, - Oracle, - Wasm, -}