Skip to content

Commit

Permalink
unify tokenfactory contract messages
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 18, 2024
1 parent 4362c29 commit 6707ecd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 81 deletions.
114 changes: 52 additions & 62 deletions contracts/dex_grpc/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -32,7 +31,8 @@ pub fn execute(
_info: MessageInfo,
msg: ExecuteMsg,
) -> StdResult<Response> {
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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
})),
}
}

Expand Down
11 changes: 4 additions & 7 deletions contracts/tokenfactory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,8 @@ pub fn execute(
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> NeutronResult<Binary> {
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 } => {
Expand All @@ -149,8 +146,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> NeutronResult<Binary> {
.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)?)?
}
})
}
Expand Down
15 changes: 3 additions & 12 deletions contracts/tokenfactory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 6707ecd

Please sign in to comment.