Skip to content

Commit

Permalink
parametrize stargate msg helpers with CosmosMsg<NeutronMsg>
Browse files Browse the repository at this point in the history
  • Loading branch information
sotnikov-s committed Dec 20, 2023
1 parent ac6ec2f commit 98f51ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/neutron-sdk/src/stargate/aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ where
/// * **req** is a proto request model. Most likely it's a result of proto code generation;
/// * **path** is an RPC request path. See Msg service definitions in neutron modules' proto files
/// for additional info.
pub fn create_stargate_msg<Req: prost::Message>(path: &str, req: Req) -> CosmosMsg {
CosmosMsg::Stargate {
pub fn create_stargate_msg<Req: prost::Message, T>(path: &str, req: Req) -> CosmosMsg<T> {
CosmosMsg::Stargate::<T> {
type_url: path.to_string(),
value: Binary::from(req.encode_to_vec()),
}
Expand Down
15 changes: 9 additions & 6 deletions packages/neutron-sdk/src/stargate/dex/msg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::bindings::msg::NeutronMsg;
use crate::proto_types::neutron::dex::{
MsgCancelLimitOrder, MsgDeposit, MsgMultiHopSwap, MsgPlaceLimitOrder,
MsgWithdrawFilledLimitOrder, MsgWithdrawal,
Expand All @@ -18,24 +19,26 @@ const MULTI_HOP_SWAP_MSG_PATH: &str = "/neutron.dex.MsgMultiHopSwap";

/// Provides liquidity to a specific trading pair by depositing tokens at a specific price into one
/// or both sides of the pair in “a liquidity pool”.
pub fn msg_deposit(req: DepositRequest) -> CosmosMsg {
pub fn msg_deposit(req: DepositRequest) -> CosmosMsg<NeutronMsg> {
create_stargate_msg(DEPOSIT_MSG_PATH, MsgDeposit::from(req))
}

/// Redeems PoolShares for the user’s pro-rata portion of tokens within a liquidity pool. When
/// withdrawing from a pool they will receive token_a and token_b in the same ratio as what is
/// currently present in the pool.
pub fn msg_withdrawal(req: WithdrawalRequest) -> CosmosMsg {
pub fn msg_withdrawal(req: WithdrawalRequest) -> CosmosMsg<NeutronMsg> {
create_stargate_msg(WITHDRAWAL_MSG_PATH, MsgWithdrawal::from(req))
}

/// Provides new liquidity to the dex that can be swapped through by other traders.
pub fn msg_place_limit_order(req: PlaceLimitOrderRequest) -> CosmosMsg {
pub fn msg_place_limit_order(req: PlaceLimitOrderRequest) -> CosmosMsg<NeutronMsg> {
create_stargate_msg(PLACE_LIMIT_ORDER_MSG_PATH, MsgPlaceLimitOrder::from(req))
}

/// Withdraws all available credits from an either partially or entirely fulfilled limit order.
pub fn msg_withdraw_filled_limit_order(req: WithdrawFilledLimitOrderRequest) -> CosmosMsg {
pub fn msg_withdraw_filled_limit_order(
req: WithdrawFilledLimitOrderRequest,
) -> CosmosMsg<NeutronMsg> {
create_stargate_msg(
WITHDRAW_FILLED_LIMIT_ORDER_MSG_PATH,
MsgWithdrawFilledLimitOrder::from(req),
Expand All @@ -48,11 +51,11 @@ pub fn msg_withdraw_filled_limit_order(req: WithdrawFilledLimitOrderRequest) ->
///
/// NOTE: Cancelling a partially filled limit order does not withdraw the traded portion. A separate
/// call must be made to `WithdrawFilledLimitOrder` to withdraw any proceeds from the limit order.
pub fn msg_cancel_limit_order(req: CancelLimitOrderRequest) -> CosmosMsg {
pub fn msg_cancel_limit_order(req: CancelLimitOrderRequest) -> CosmosMsg<NeutronMsg> {
create_stargate_msg(CANCEL_LIMIT_ORDER_MSG_PATH, MsgCancelLimitOrder::from(req))
}

/// Swaps by routing through a series of pools to achieve better prices.
pub fn msg_multi_hop_swap(req: MultiHopSwapRequest) -> CosmosMsg {
pub fn msg_multi_hop_swap(req: MultiHopSwapRequest) -> CosmosMsg<NeutronMsg> {
create_stargate_msg(MULTI_HOP_SWAP_MSG_PATH, MsgMultiHopSwap::from(req))
}

0 comments on commit 98f51ec

Please sign in to comment.