Skip to content

Commit

Permalink
Add new SimulateXX queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Aug 28, 2024
1 parent a11018a commit aacd22a
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/neutron-sdk/src/bindings/dex/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_std::Uint128;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::types::{DepositOption, MultiHopRoute, PrecDec};
use super::types::{DepositOptions, MultiHopRoute, PrecDec};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
Expand All @@ -26,7 +26,7 @@ pub enum DexMsg {
/// Fees to use for each deposit
fees: Vec<u64>,
/// Additional deposit options
options: Vec<DepositOption>,
options: Vec<DepositOptions>,
},
/// Withdraw is used to redeem PoolShares for the user’s pro-rata
/// portion of tokens within a liquidity pool. Users can withdraw from a pool at any time
Expand Down
56 changes: 54 additions & 2 deletions packages/neutron-sdk/src/bindings/dex/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::bindings::dex::types::{
DepositRecord, LimitOrderTranche, LimitOrderTrancheUser, LimitOrderType, MultiHopRoute, Params,
Pool, PoolMetadata, PoolReserves, PrecDec, TickLiquidity,
DepositRecord, LimitOrderTranche, LimitOrderTrancheUser, LimitOrderType, MsgCancelLimitOrder,
MsgCancelLimitOrderResponse, MsgDeposit, MsgDepositResponse, MsgMultiHopSwap,
MsgMultiHopSwapResponse, MsgPlaceLimitOrder, MsgPlaceLimitOrderResponse,
MsgWithdrawFilledLimitOrder, MsgWithdrawFilledLimitOrderResponse, MsgWithdrawal,
MsgWithdrawalResponse, MultiHopRoute, Params, Pool, PoolMetadata, PoolReserves, PrecDec,
TickLiquidity,
};
use crate::bindings::query::{PageRequest, PageResponse};
use cosmwasm_std::{Coin, Int128};
Expand Down Expand Up @@ -106,6 +110,18 @@ pub enum DexQuery {
PoolMetadata { id: u64 },
/// Queries a list of PoolMetadata items.
PoolMetadataAll { pagination: Option<PageRequest> },
/// Simulates MsgDeposit
SimulateDeposit { msg: MsgDeposit },
/// Simulates MsgWithdrawal
SimulateWithdrawal { msg: MsgWithdrawal },
/// Simulates MsgPlaceLimitOrder
SimulatePlaceLimitOrder { msg: MsgPlaceLimitOrder },
/// Simulates MsgWithdrawFilledLimitOrder
SimulateWithdrawFilledLimitOrder { msg: MsgWithdrawFilledLimitOrder },
/// Simulates MsgCancelLimitOrder
SimulateCancelLimitOrder { msg: MsgCancelLimitOrder },
/// Simulates MsgMultiHopSwap
SimulateMultiHopSwap { msg: MsgMultiHopSwap },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down Expand Up @@ -229,3 +245,39 @@ pub struct AllPoolMetadataResponse {
pub pool_metadata: Vec<PoolMetadata>,
pub pagination: Option<PageResponse>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct SimulateDepositResponse {
resp: MsgDepositResponse,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct SimulateWithdrawalResponse {
resp: MsgWithdrawalResponse,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct SimulatePlaceLimitOrderResponse {
resp: MsgPlaceLimitOrderResponse,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct SimulateWithdrawFilledLimitOrderResponse {
resp: MsgWithdrawFilledLimitOrderResponse,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct SimulateCancelLimitOrderResponse {
resp: MsgCancelLimitOrderResponse,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct SimulateMultiHopSwapResponse {
resp: MsgMultiHopSwapResponse,
}
122 changes: 119 additions & 3 deletions packages/neutron-sdk/src/bindings/dex/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::Int128;
use cosmwasm_std::{Coin, Int128, Uint128};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -78,6 +78,13 @@ pub struct TradePairID {
pub taker_denom: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub struct FailedDeposit {
pub deposit_idx: u64,
pub error: String,
}

// TODO implement math for PrecDec
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
Expand All @@ -102,8 +109,9 @@ impl From<String> for PrecDec {

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct DepositOption {
pub disable_swap: bool,
pub struct DepositOptions {
pub disable_autoswap: bool,
pub fail_tx_on_bel: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down Expand Up @@ -189,3 +197,111 @@ pub struct PoolReservesKey {
pub tick_index_taker_to_maker: i64,
pub fee: Option<u64>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgDeposit {
pub token_a: String,
pub token_b: String,
pub amounts_a: Vec<Uint128>,
pub amounts_b: Vec<Uint128>,
pub tick_indexes_a_to_b: Vec<i64>,
pub fees: Vec<u64>,
pub options: Vec<DepositOptions>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgDepositResponse {
pub reserve0_deposited: Vec<Uint128>,
pub reserve1_deposited: Vec<Uint128>,
pub failed_deposits: Vec<FailedDeposit>,
pub shares_issued: Vec<Coin>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgWithdrawal {
pub creator: String,
pub receiver: String,
pub token_a: String,
pub token_b: String,
pub shares_to_remove: Vec<Uint128>,
pub tick_indexes_a_to_b: Vec<i64>,
pub fees: Vec<u64>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgWithdrawalResponse {
pub reserve0_withdrawn: Uint128,
pub reserve1_withdrawn: Uint128,
pub shares_burned: Vec<Coin>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgPlaceLimitOrder {
pub token_in: String,
pub token_out: String,
pub tick_index_in_to_out: i64,
pub amount_in: Uint128,
pub order_type: LimitOrderType,
pub expiration_time: Option<u64>,
pub max_amount_out: Option<Uint128>,
pub limit_sell_price: PrecDec,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgPlaceLimitOrderResponse {
pub tranche_key: String,
pub coin_in: Coin,
pub taker_coin_out: Coin,
pub taker_coin_in: Coin,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgWithdrawFilledLimitOrder {
pub creator: String,
pub tranche_key: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgWithdrawFilledLimitOrderResponse {
pub taker_coin_out: Coin,
pub maker_coin_out: Coin,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgCancelLimitOrder {
pub creator: String,
pub tranche_key: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgCancelLimitOrderResponse {
pub taker_coin_out: Coin,
pub maker_coin_out: Coin,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgMultiHopSwap {
pub routes: Vec<MultiHopRoute>,
pub amount_in: Uint128,
pub exit_limit_price: PrecDec,
pub pick_best_route: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MsgMultiHopSwapResponse {
pub coin_out: Coin,
pub route: MultiHopRoute,
pub dust: Vec<Coin>,
}
2 changes: 1 addition & 1 deletion packages/neutron-sdk/src/proto_types/NEUTRON_COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v4.1.0
f0fe2f9adfd5ff6c092d50c6a30adb4efab8a590
Loading

0 comments on commit aacd22a

Please sign in to comment.