From 6707ecd744256c84e7487109e82fadeeb36ef0a3 Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 18 Oct 2024 12:45:48 +0400 Subject: [PATCH] unify tokenfactory contract messages --- contracts/dex_grpc/src/contract.rs | 114 +++++++++++-------------- contracts/tokenfactory/src/contract.rs | 11 +-- contracts/tokenfactory/src/msg.rs | 15 +--- 3 files changed, 59 insertions(+), 81 deletions(-) diff --git a/contracts/dex_grpc/src/contract.rs b/contracts/dex_grpc/src/contract.rs index 241ff1a..a294027 100644 --- a/contracts/dex_grpc/src/contract.rs +++ b/contracts/dex_grpc/src/contract.rs @@ -1,7 +1,6 @@ use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use cosmwasm_std::{ - entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, - StdResult, + entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, }; use cw2::set_contract_version; use neutron_sdk::sudo::msg::SudoMsg; @@ -32,7 +31,8 @@ pub fn execute( _info: MessageInfo, msg: ExecuteMsg, ) -> StdResult { - deps.api.debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str()); + deps.api + .debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str()); match msg { ExecuteMsg::Deposit { receiver, @@ -43,19 +43,17 @@ pub fn execute( tick_indexes_a_to_b, fees, options, - } => Ok( - Response::new().add_message(MsgDeposit { - creator: env.contract.address.to_string(), - receiver, - token_a, - token_b, - amounts_a, - amounts_b, - tick_indexes_a_to_b, - fees, - options, - }), - ), + } => Ok(Response::new().add_message(MsgDeposit { + creator: env.contract.address.to_string(), + receiver, + token_a, + token_b, + amounts_a, + amounts_b, + tick_indexes_a_to_b, + fees, + options, + })), ExecuteMsg::Withdrawal { receiver, @@ -64,17 +62,15 @@ pub fn execute( shares_to_remove, tick_indexes_a_to_b, fees, - } => Ok( - Response::new().add_message(MsgWithdrawal { - creator: env.contract.address.to_string(), - receiver, - token_a, - token_b, - shares_to_remove, - tick_indexes_a_to_b, - fees, - }), - ), + } => Ok(Response::new().add_message(MsgWithdrawal { + creator: env.contract.address.to_string(), + receiver, + token_a, + token_b, + shares_to_remove, + tick_indexes_a_to_b, + fees, + })), #[allow(deprecated)] ExecuteMsg::PlaceLimitOrder { receiver, @@ -86,35 +82,31 @@ pub fn execute( order_type, expiration_time, max_amount_out, - } => Ok( - Response::new().add_message(MsgPlaceLimitOrder { - creator: env.contract.address.to_string(), - receiver, - token_in, - token_out, - tick_index_in_to_out, - limit_sell_price, - amount_in, - order_type, - expiration_time, - max_amount_out, - min_average_sell_price: "".to_string(), // TODO - }), - ), - ExecuteMsg::WithdrawFilledLimitOrder { tranche_key } => Ok(Response::new().add_message( - MsgWithdrawFilledLimitOrder { + } => Ok(Response::new().add_message(MsgPlaceLimitOrder { + creator: env.contract.address.to_string(), + receiver, + token_in, + token_out, + tick_index_in_to_out, + limit_sell_price, + amount_in, + order_type, + expiration_time, + max_amount_out, + min_average_sell_price: "".to_string(), // TODO + })), + ExecuteMsg::WithdrawFilledLimitOrder { tranche_key } => { + Ok(Response::new().add_message(MsgWithdrawFilledLimitOrder { creator: env.contract.address.to_string(), tranche_key, - }, - )), + })) + } ExecuteMsg::CancelLimitOrder { tranche_key } => { - Ok( - Response::new().add_message(MsgCancelLimitOrder { - creator: env.contract.address.to_string(), - tranche_key, - }), - ) + Ok(Response::new().add_message(MsgCancelLimitOrder { + creator: env.contract.address.to_string(), + tranche_key, + })) } ExecuteMsg::MultiHopSwap { @@ -123,16 +115,14 @@ pub fn execute( amount_in, exit_limit_price, pick_best_route, - } => Ok( - Response::new().add_message(MsgMultiHopSwap { - creator: env.contract.address.to_string(), - receiver, - routes, - amount_in, - exit_limit_price, - pick_best_route, - }), - ), + } => Ok(Response::new().add_message(MsgMultiHopSwap { + creator: env.contract.address.to_string(), + receiver, + routes, + amount_in, + exit_limit_price, + pick_best_route, + })), } } diff --git a/contracts/tokenfactory/src/contract.rs b/contracts/tokenfactory/src/contract.rs index 0794928..497012a 100644 --- a/contracts/tokenfactory/src/contract.rs +++ b/contracts/tokenfactory/src/contract.rs @@ -134,11 +134,8 @@ pub fn execute( pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> NeutronResult { let querier = TokenfactoryQuerier::new(&deps.querier); Ok(match msg { - QueryMsg::FullDenom { - creator_addr, - subdenom, - } => { - let res = &querier.full_denom(creator_addr, subdenom)?; + QueryMsg::FullDenom { creator, subdenom } => { + let res = &querier.full_denom(creator, subdenom)?; to_json_binary(res)? } QueryMsg::DenomAdmin { creator, subdenom } => { @@ -149,8 +146,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> NeutronResult { .ok_or(Std(StdError::generic_err("authority metadata not found")))?, )? } - QueryMsg::BeforeSendHook { creator, denom } => { - to_json_binary(&querier.before_send_hook_address(creator, denom)?)? + QueryMsg::BeforeSendHook { creator, subdenom } => { + to_json_binary(&querier.before_send_hook_address(creator, subdenom)?)? } }) } diff --git a/contracts/tokenfactory/src/msg.rs b/contracts/tokenfactory/src/msg.rs index c4dcecc..73b68cc 100644 --- a/contracts/tokenfactory/src/msg.rs +++ b/contracts/tokenfactory/src/msg.rs @@ -56,18 +56,9 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - FullDenom { - creator_addr: String, - subdenom: String, - }, - DenomAdmin { - creator: String, - subdenom: String, - }, - BeforeSendHook { - creator: String, - denom: String, - }, + FullDenom { creator: String, subdenom: String }, + DenomAdmin { creator: String, subdenom: String }, + BeforeSendHook { creator: String, subdenom: String }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]