Skip to content

Commit 35e10b0

Browse files
committed
add stargate bindings for sims
1 parent 16f950a commit 35e10b0

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed

packages/neutron-sdk/src/proto_types/neutron.dex.rs

+33
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ pub struct MsgPlaceLimitOrder {
175175
pub expiration_time: ::core::option::Option<::prost_types::Timestamp>,
176176
#[prost(string, tag = "10")]
177177
pub max_amount_out: ::prost::alloc::string::String,
178+
#[prost(string, optional, tag = "11")]
179+
pub limit_sell_price: ::core::option::Option<::prost::alloc::string::String>,
180+
#[prost(string, optional, tag = "12")]
181+
pub min_average_sell_price: ::core::option::Option<::prost::alloc::string::String>,
178182
}
179183
#[derive(Clone, PartialEq, ::prost::Message)]
180184
pub struct MsgPlaceLimitOrderResponse {
@@ -189,6 +193,9 @@ pub struct MsgPlaceLimitOrderResponse {
189193
/// maker portion which will have withdrawn in the future
190194
#[prost(message, optional, tag = "3")]
191195
pub taker_coin_out: ::core::option::Option<cosmos_sdk_proto::cosmos::base::v1beta1::Coin>,
196+
/// Total amount of the token in that was immediately swapped for takerOutCoin
197+
#[prost(message, optional, tag = "4")]
198+
pub taker_coin_in: ::core::option::Option<cosmos_sdk_proto::cosmos::base::v1beta1::Coin>,
192199
}
193200
#[derive(Clone, PartialEq, ::prost::Message)]
194201
pub struct MsgWithdrawFilledLimitOrder {
@@ -234,6 +241,10 @@ pub struct MsgMultiHopSwap {
234241
pub struct MsgMultiHopSwapResponse {
235242
#[prost(message, optional, tag = "1")]
236243
pub coin_out: ::core::option::Option<cosmos_sdk_proto::cosmos::base::v1beta1::Coin>,
244+
#[prost(message, optional, tag = "2")]
245+
pub route: ::core::option::Option<MultiHopRoute>,
246+
#[prost(message, repeated, tag = "3")]
247+
pub dust: ::prost::alloc::vec::Vec<cosmos_sdk_proto::cosmos::base::v1beta1::Coin>,
237248
}
238249
#[derive(Clone, PartialEq, ::prost::Message)]
239250
pub struct MsgUpdateParams {
@@ -634,4 +645,26 @@ pub struct QueryAllPoolMetadataResponse {
634645
pub pagination:
635646
::core::option::Option<cosmos_sdk_proto::cosmos::base::query::v1beta1::PageResponse>,
636647
}
648+
#[derive(Clone, PartialEq, ::prost::Message)]
649+
pub struct QuerySimulatePlaceLimitOrderRequest {
650+
#[prost(message, optional, tag = "1")]
651+
pub msg: ::core::option::Option<MsgPlaceLimitOrder>,
652+
}
653+
#[derive(Clone, PartialEq, ::prost::Message)]
654+
pub struct QuerySimulatePlaceLimitOrderResponse {
655+
#[prost(message, optional, tag = "1")]
656+
pub resp: ::core::option::Option<MsgPlaceLimitOrderResponse>,
657+
}
658+
659+
#[derive(Clone, PartialEq, ::prost::Message)]
660+
pub struct QuerySimulateMultiHopSwapRequest {
661+
#[prost(message, optional, tag = "1")]
662+
pub msg: ::core::option::Option<MsgMultiHopSwap>,
663+
}
664+
#[derive(Clone, PartialEq, ::prost::Message)]
665+
pub struct QuerySimulateMultiHopSwapResponse {
666+
#[prost(message, optional, tag = "1")]
667+
pub resp: ::core::option::Option<MsgPlaceLimitOrderResponse>,
668+
}
669+
637670
// @@protoc_insertion_point(module)

packages/neutron-sdk/src/stargate/dex/query.rs

+30
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::proto_types::neutron::dex::{
66
QueryGetInactiveLimitOrderTrancheRequest, QueryGetLimitOrderTrancheRequest,
77
QueryGetLimitOrderTrancheUserRequest, QueryGetPoolMetadataRequest, QueryGetPoolReservesRequest,
88
QueryParamsRequest, QueryPoolByIdRequest, QueryPoolRequest,
9+
QuerySimulatePlaceLimitOrderRequest, QuerySimulateMultiHopSwapRequest,
910
};
1011
use crate::stargate::aux::make_stargate_query;
1112
use crate::stargate::dex::types::{
@@ -17,10 +18,12 @@ use crate::stargate::dex::types::{
1718
EstimateMultiHopSwapRequest, EstimateMultiHopSwapResponse, EstimatePlaceLimitOrderRequest,
1819
EstimatePlaceLimitOrderResponse, GetInactiveLimitOrderTrancheRequest,
1920
GetInactiveLimitOrderTrancheResponse, GetLimitOrderTrancheRequest,
21+
SimulatePlaceLimitOrderResponse, SimulateMultiHopSwapResponse,
2022
GetLimitOrderTrancheResponse, GetPoolMetadataRequest, GetPoolMetadataResponse,
2123
GetPoolReservesRequest, GetPoolReservesResponse, LimitOrderTrancheUserAllRequest,
2224
LimitOrderTrancheUserAllResponse, LimitOrderTrancheUserRequest, LimitOrderTrancheUserResponse,
2325
ParamsRequest, ParamsResponse, PoolByIdRequest, PoolRequest, PoolResponse,
26+
SimulatePlaceLimitOrderRequest, SimulateMultiHopSwapRequest
2427
};
2528
use cosmwasm_std::{Deps, StdResult};
2629

@@ -45,6 +48,8 @@ const POOL_QUERY_PATH: &str = "/neutron.dex.Query/Pool";
4548
const POOL_BY_ID_QUERY_PATH: &str = "/neutron.dex.Query/PoolByID";
4649
const POOL_METADATA_QUERY_PATH: &str = "/neutron.dex.Query/PoolMetadata";
4750
const POOL_METADATA_ALL_QUERY_PATH: &str = "/neutron.dex.Query/PoolMetadataAll";
51+
const SIMULATE_PLACE_LIMIT_ORDER__QUERY_PATH: &str = "/neutron.dex.Query/SimulatePlaceLimitOrder";
52+
const SIMULATE_MULTI_HOP_SWAP_QUERY_PATH: &str = "/neutron.dex.Query/SimulateMultiHopSwap";
4853

4954
/// Queries the parameters of the module.
5055
pub fn get_params(deps: Deps, req: ParamsRequest) -> StdResult<ParamsResponse> {
@@ -240,3 +245,28 @@ pub fn get_pool_metadata_all(
240245
QueryAllPoolMetadataRequest::from(req),
241246
)
242247
}
248+
249+
250+
/// Simulate Place Limit Order
251+
pub fn simulate_place_place_order(
252+
deps: Deps,
253+
req: SimulatePlaceLimitOrderRequest,
254+
) -> StdResult<SimulatePlaceLimitOrderResponse> {
255+
make_stargate_query(
256+
deps,
257+
SIMULATE_PLACE_LIMIT_ORDER__QUERY_PATH,
258+
QuerySimulatePlaceLimitOrderRequest::from(req),
259+
)
260+
}
261+
262+
/// Simulate MultiHopSwap
263+
pub fn simulate_multi_hop_swap(
264+
deps: Deps,
265+
req: SimulateMultiHopSwapRequest,
266+
) -> StdResult<SimulateMultiHopSwapResponse> {
267+
make_stargate_query(
268+
deps,
269+
SIMULATE_MULTI_HOP_SWAP_QUERY_PATH,
270+
QuerySimulateMultiHopSwapRequest::from(req),
271+
)
272+
}

packages/neutron-sdk/src/stargate/dex/types.rs

+96-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::proto_types::neutron::dex::{
88
QueryEstimateMultiHopSwapRequest, QueryEstimatePlaceLimitOrderRequest,
99
QueryGetInactiveLimitOrderTrancheRequest, QueryGetLimitOrderTrancheRequest,
1010
QueryGetLimitOrderTrancheUserRequest, QueryGetPoolMetadataRequest, QueryGetPoolReservesRequest,
11-
QueryParamsRequest, QueryPoolByIdRequest, QueryPoolRequest,
11+
QueryParamsRequest, QueryPoolByIdRequest, QueryPoolRequest, QuerySimulatePlaceLimitOrderRequest, QuerySimulateMultiHopSwapRequest,
1212
};
1313
use crate::stargate::aux::proto_timestamp_from_i64;
1414
use cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest as PageRequestGen;
@@ -121,6 +121,8 @@ pub struct PlaceLimitOrderRequest {
121121
/// Expiration time for order. Only valid for GoodTilTime limit orders.
122122
pub expiration_time: Option<i64>,
123123
pub max_amount_out: Option<String>,
124+
pub limit_sell_price: Option<String>,
125+
pub min_avg_sell_price: Option<String>,
124126
}
125127

126128
impl From<PlaceLimitOrderRequest> for MsgPlaceLimitOrder {
@@ -135,6 +137,8 @@ impl From<PlaceLimitOrderRequest> for MsgPlaceLimitOrder {
135137
order_type: v.order_type as i32,
136138
expiration_time: v.expiration_time.map(proto_timestamp_from_i64),
137139
max_amount_out: v.max_amount_out.unwrap_or_default(),
140+
limit_sell_price: v.limit_sell_price,
141+
min_average_sell_price: v.min_avg_sell_price,
138142
}
139143
}
140144
}
@@ -665,6 +669,97 @@ impl From<AllPoolMetadataRequest> for QueryAllPoolMetadataRequest {
665669
}
666670
}
667671

672+
//SimulatePlaceLimitOrder
673+
674+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
675+
pub struct SimulatePlaceLimitOrderRequest {
676+
/// Account from which token_in is debited.
677+
pub sender: String,
678+
/// Account to which token_out is credited or that will be allowed to withdraw or cancel a
679+
/// maker order.
680+
pub receiver: String,
681+
/// Token being “sold”.
682+
pub token_in: String,
683+
/// Token being “bought”.
684+
pub token_out: String,
685+
/// Limit tick for a limit order, specified in terms of token_in to token_out.
686+
pub tick_index_in_to_out: i64,
687+
/// Amount of TokenIn to be traded.
688+
pub amount_in: String,
689+
/// Type of limit order to be used.
690+
pub order_type: LimitOrderType,
691+
/// Expiration time for order. Only valid for GoodTilTime limit orders.
692+
pub expiration_time: Option<i64>,
693+
pub max_amount_out: Option<String>,
694+
pub limit_sell_price: Option<String>,
695+
pub min_avg_sell_price: Option<String>,
696+
}
697+
698+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
699+
pub struct SimulatePlaceLimitOrderResponse{
700+
resp: PlaceLimitOrderResponse
701+
}
702+
703+
impl From<SimulatePlaceLimitOrderRequest> for QuerySimulatePlaceLimitOrderRequest {
704+
fn from(v: SimulatePlaceLimitOrderRequest) -> QuerySimulatePlaceLimitOrderRequest {
705+
QuerySimulatePlaceLimitOrderRequest {
706+
msg: Some(MsgPlaceLimitOrder{
707+
creator: v.sender,
708+
receiver: v.receiver,
709+
token_in: v.token_in,
710+
token_out: v.token_out,
711+
tick_index_in_to_out: v.tick_index_in_to_out,
712+
amount_in: v.amount_in,
713+
order_type: v.order_type as i32,
714+
expiration_time: v.expiration_time.map(proto_timestamp_from_i64),
715+
max_amount_out: v.max_amount_out.unwrap_or_default(),
716+
limit_sell_price: v.limit_sell_price,
717+
min_average_sell_price: v.min_avg_sell_price,
718+
})
719+
}
720+
}
721+
}
722+
723+
// SimulateMultiHopSwap
724+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
725+
pub struct SimulateMultiHopSwapRequest{
726+
pub sender: String,
727+
/// Account to which TokenOut is credited
728+
receiver: String,
729+
/// Array of possible routes
730+
routes: Vec<Vec<String>>,
731+
/// Amount of TokenIn to swap
732+
amount_in: String,
733+
/// Minimum price that that must be satisfied for a route to succeed
734+
exit_limit_price: String,
735+
/// If true all routes are run and the route with the best price is used
736+
pick_best_route: bool,
737+
}
738+
739+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
740+
pub struct SimulateMultiHopSwapResponse{
741+
resp: MultiHopSwapResponse
742+
}
743+
744+
impl From<SimulateMultiHopSwapRequest> for QuerySimulateMultiHopSwapRequest {
745+
fn from(v: SimulateMultiHopSwapRequest) -> QuerySimulateMultiHopSwapRequest {
746+
QuerySimulateMultiHopSwapRequest {
747+
msg: Some(MsgMultiHopSwap{
748+
creator: v.sender,
749+
receiver: v.receiver,
750+
routes: v
751+
.routes
752+
.into_iter()
753+
.map(|r| MultiHopRoute { hops: r })
754+
.collect(),
755+
amount_in: v.amount_in,
756+
exit_limit_price: v.exit_limit_price,
757+
pick_best_route: v.pick_best_route,
758+
})
759+
}
760+
}
761+
}
762+
668763
// Common
669764

670765
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

0 commit comments

Comments
 (0)