syntax = "proto3";

package neutron.dex;

import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "neutron/dex/deposit_record.proto";
import "neutron/dex/limit_order_tranche.proto";
import "neutron/dex/limit_order_tranche_user.proto";
import "neutron/dex/params.proto";
import "neutron/dex/pool.proto";
import "neutron/dex/pool_metadata.proto";
import "neutron/dex/pool_reserves.proto";
import "neutron/dex/tick_liquidity.proto";
import "neutron/dex/tx.proto";

// this line is used by starport scaffolding # 1

option go_package = "github.com/neutron-org/neutron/v7/x/dex/types";

// Query defines the gRPC querier service.
service Query {
  // Parameters queries the parameters of the module.
  rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
    option (google.api.http).get = "/neutron/dex/params";
  }

  // Queries a LimitOrderTrancheUser by index.
  rpc LimitOrderTrancheUser(QueryGetLimitOrderTrancheUserRequest) returns (QueryGetLimitOrderTrancheUserResponse) {
    option (google.api.http).get = "/neutron/dex/limit_order_tranche_user/{address}/{tranche_key}";
  }

  // Queries a list of LimitOrderTranchUser items.
  rpc LimitOrderTrancheUserAll(QueryAllLimitOrderTrancheUserRequest) returns (QueryAllLimitOrderTrancheUserResponse) {
    option (google.api.http).get = "/neutron/dex/limit_order_tranche_user";
  }

  // Queries a list of LimitOrderTrancheUser items for a given address.
  rpc LimitOrderTrancheUserAllByAddress(QueryAllLimitOrderTrancheUserByAddressRequest) returns (QueryAllLimitOrderTrancheUserByAddressResponse) {
    option (google.api.http).get = "/neutron/dex/user/limit_orders/{address}";
  }

  // Queries a LimitOrderTranche by index.
  rpc LimitOrderTranche(QueryGetLimitOrderTrancheRequest) returns (QueryGetLimitOrderTrancheResponse) {
    option (google.api.http).get =
      "/neutron/dex/limit_order_tranche/{pair_id}/"
      "{token_in}/{tick_index}/{tranche_key}";
  }

  // Queries a list of LimitOrderTranche items for a given pairID / TokenIn
  // combination.
  rpc LimitOrderTrancheAll(QueryAllLimitOrderTrancheRequest) returns (QueryAllLimitOrderTrancheResponse) {
    option (google.api.http).get = "/neutron/dex/limit_order_tranche/{pair_id}/{token_in}";
  }

  // Queries a list of UserDeposits items.
  rpc UserDepositsAll(QueryAllUserDepositsRequest) returns (QueryAllUserDepositsResponse) {
    option (google.api.http).get = "/neutron/dex/user/deposits/{address}";
  }

  // Queries a list of TickLiquidity items.
  rpc TickLiquidityAll(QueryAllTickLiquidityRequest) returns (QueryAllTickLiquidityResponse) {
    option (google.api.http).get = "/neutron/dex/tick_liquidity/{pair_id}/{token_in}";
  }

  // Queries a InactiveLimitOrderTranche by index.
  rpc InactiveLimitOrderTranche(QueryGetInactiveLimitOrderTrancheRequest) returns (QueryGetInactiveLimitOrderTrancheResponse) {
    option (google.api.http) = {
      get: "/neutron/dex/inactive_limit_order_tranche/{pair_id}/{token_in}/{tick_index}/{tranche_key}"
      additional_bindings {
        get: "/neutron/dex/filled_limit_order_tranche/{pair_id}/{token_in}/{tick_index}/{tranche_key}" // this route is deprecated, keep it for backwards compatibility
      }
    };
  }

  // Queries a list of InactiveLimitOrderTranche items.
  rpc InactiveLimitOrderTrancheAll(QueryAllInactiveLimitOrderTrancheRequest) returns (QueryAllInactiveLimitOrderTrancheResponse) {
    option (google.api.http) = {
      get: "/neutron/dex/inactive_limit_order_tranche"
      additional_bindings {
        get: "/neutron/dex/filled_limit_order_tranche" // this route is deprecated, keep it for backwards compatibility
      }
    };
  }

  // Queries a list of PoolReserves items.
  rpc PoolReservesAll(QueryAllPoolReservesRequest) returns (QueryAllPoolReservesResponse) {
    option (google.api.http).get = "/neutron/dex/pool_reserves/{pair_id}/{token_in}";
  }

  // Queries a PoolReserve by index
  rpc PoolReserves(QueryGetPoolReservesRequest) returns (QueryGetPoolReservesResponse) {
    option (google.api.http).get = "/neutron/dex/pool_reserves/{pair_id}/{token_in}/{tick_index}/{fee}";
  }

  // DEPRECATED Queries the simulated result of a multihop swap
  rpc EstimateMultiHopSwap(QueryEstimateMultiHopSwapRequest) returns (QueryEstimateMultiHopSwapResponse) {
    option (google.api.http).get = "/neutron/dex/estimate_multi_hop_swap";
    option deprecated = true;
  }

  // DEPRECATED Queries the simulated result of a PlaceLimit order
  rpc EstimatePlaceLimitOrder(QueryEstimatePlaceLimitOrderRequest) returns (QueryEstimatePlaceLimitOrderResponse) {
    option (google.api.http).get = "/neutron/dex/estimate_place_limit_order";
    option deprecated = true;
  }

  // Queries a pool by pair, tick and fee
  rpc Pool(QueryPoolRequest) returns (QueryPoolResponse) {
    option (google.api.http).get = "/neutron/dex/pool/{pair_id}/{tick_index}/{fee}";
  }

  // Queries a pool by ID
  rpc PoolByID(QueryPoolByIDRequest) returns (QueryPoolResponse) {
    option (google.api.http).get = "/neutron/dex/pool/{pool_id}";
  }

  // Queries a PoolMetadata by ID
  rpc PoolMetadata(QueryGetPoolMetadataRequest) returns (QueryGetPoolMetadataResponse) {
    option (google.api.http).get = "/neutron/dex/pool_metadata/{id}";
  }

  // Queries a list of PoolMetadata items.
  rpc PoolMetadataAll(QueryAllPoolMetadataRequest) returns (QueryAllPoolMetadataResponse) {
    option (google.api.http).get = "/neutron/dex/pool_metadata";
  }

  // Simulates MsgDeposit
  rpc SimulateDeposit(QuerySimulateDepositRequest) returns (QuerySimulateDepositResponse) {
    option (google.api.http).get = "/neutron/dex/simulate_deposit";
  }

  // Simulates MsgWithdrawal
  rpc SimulateWithdrawal(QuerySimulateWithdrawalRequest) returns (QuerySimulateWithdrawalResponse) {
    option (google.api.http).get = "/neutron/dex/simulate_withdrawal";
  }

  // Simulates MsgPlaceLimitOrder
  rpc SimulatePlaceLimitOrder(QuerySimulatePlaceLimitOrderRequest) returns (QuerySimulatePlaceLimitOrderResponse) {
    option (google.api.http).get = "/neutron/dex/simulate_place_limit_order";
  }

  // Simulates MsgWithdrawFilledLimitOrder
  rpc SimulateWithdrawFilledLimitOrder(QuerySimulateWithdrawFilledLimitOrderRequest) returns (QuerySimulateWithdrawFilledLimitOrderResponse) {
    option (google.api.http).get = "/neutron/dex/simulate_withdraw_filled_limit_order";
  }

  // Simulates MsgCancelLimitOrder
  rpc SimulateCancelLimitOrder(QuerySimulateCancelLimitOrderRequest) returns (QuerySimulateCancelLimitOrderResponse) {
    option (google.api.http).get = "/neutron/dex/simulate_cancel_limit_order";
  }

  // Simulates MsgMultiHopSwap
  rpc SimulateMultiHopSwap(QuerySimulateMultiHopSwapRequest) returns (QuerySimulateMultiHopSwapResponse) {
    option (google.api.http).get = "/neutron/dex/simulate_multi_hop_swap";
  }

  // this line is used by starport scaffolding # 2
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
  // params holds all the parameters of this module.
  Params params = 1 [(gogoproto.nullable) = false];
}

message QueryGetLimitOrderTrancheUserRequest {
  string address = 1;
  string tranche_key = 2;
  bool calc_withdrawable_shares = 3;
}

message QueryGetLimitOrderTrancheUserResponse {
  LimitOrderTrancheUser limit_order_tranche_user = 1 [(gogoproto.nullable) = true];
  string withdrawable_shares = 2 [
    (gogoproto.moretags) = "yaml:\"withdrawable_shares\"",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = true,
    (gogoproto.jsontag) = "withdrawable_shares"
  ];
}

message QueryAllLimitOrderTrancheUserRequest {
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllLimitOrderTrancheUserResponse {
  repeated LimitOrderTrancheUser limit_order_tranche_user = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetLimitOrderTrancheRequest {
  string pair_id = 1;
  int64 tick_index = 2;
  string token_in = 3;
  string tranche_key = 4;
}

message QueryGetLimitOrderTrancheResponse {
  LimitOrderTranche limit_order_tranche = 1 [(gogoproto.nullable) = true];
}

message QueryAllLimitOrderTrancheRequest {
  string pair_id = 1;
  string token_in = 2;
  cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

message QueryAllLimitOrderTrancheResponse {
  repeated LimitOrderTranche limit_order_tranche = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryAllUserDepositsRequest {
  string address = 1;
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
  bool include_pool_data = 3;
}

message QueryAllUserDepositsResponse {
  repeated DepositRecord deposits = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryAllLimitOrderTrancheUserByAddressRequest {
  string address = 1;
  cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryAllLimitOrderTrancheUserByAddressResponse {
  repeated LimitOrderTrancheUser limit_orders = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryAllTickLiquidityRequest {
  string pair_id = 1;
  string token_in = 2;
  cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

message QueryAllTickLiquidityResponse {
  repeated TickLiquidity tick_liquidity = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetInactiveLimitOrderTrancheRequest {
  string pair_id = 1;
  string token_in = 2;
  int64 tick_index = 3;
  string tranche_key = 4;
}

message QueryGetInactiveLimitOrderTrancheResponse {
  LimitOrderTranche inactive_limit_order_tranche = 1 [(gogoproto.nullable) = true];
}

message QueryAllInactiveLimitOrderTrancheRequest {
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllInactiveLimitOrderTrancheResponse {
  repeated LimitOrderTranche inactive_limit_order_tranche = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryAllPoolReservesRequest {
  string pair_id = 1;
  string token_in = 2;
  cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

message QueryAllPoolReservesResponse {
  repeated PoolReserves pool_reserves = 1 [(gogoproto.nullable) = true];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetPoolReservesRequest {
  string pair_id = 1;
  string token_in = 2;
  int64 tick_index = 3;
  uint64 fee = 4;
}

message QueryGetPoolReservesResponse {
  PoolReserves pool_reserves = 1 [(gogoproto.nullable) = true];
}

message QueryEstimateMultiHopSwapRequest {
  // DEPRECATED: Use QuerySimulateMultiHopSwap
  string creator = 1;
  string receiver = 2;
  repeated MultiHopRoute routes = 3;
  string amount_in = 4 [
    (gogoproto.moretags) = "yaml:\"amount_in\"",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false,
    (gogoproto.jsontag) = "amount_in"
  ];
  string exit_limit_price = 5 [
    (gogoproto.moretags) = "yaml:\"exit_limit_price\"",
    (gogoproto.customtype) = "github.com/neutron-org/neutron/v7/utils/math.PrecDec",
    (gogoproto.nullable) = false,
    (gogoproto.jsontag) = "exit_limit_price"
  ];

  // If pickBestRoute == true then all routes are run and the route with the
  // best price is chosen otherwise, the first successful route is used.
  bool pick_best_route = 6;
}

message QueryEstimateMultiHopSwapResponse {
  cosmos.base.v1beta1.Coin coin_out = 1 [
    (gogoproto.nullable) = false,
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
    (gogoproto.jsontag) = "coin_out"
  ];
}

message QueryEstimatePlaceLimitOrderRequest {
  // DEPRECATED: Use QuerySimulatePlaceLimitOrder
  string creator = 1;
  string receiver = 2;
  string token_in = 3;
  string token_out = 4;
  int64 tick_index_in_to_out = 5;
  string amount_in = 6 [
    (gogoproto.moretags) = "yaml:\"amount_in\"",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false,
    (gogoproto.jsontag) = "amount_in"
  ];
  LimitOrderType order_type = 7;

  // expirationTime is only valid iff orderType == GOOD_TIL_TIME.
  google.protobuf.Timestamp expiration_time = 8 [
    (gogoproto.stdtime) = true,
    (gogoproto.nullable) = true
  ];
  string maxAmount_out = 9 [
    (gogoproto.moretags) = "yaml:\"max_amount_out\"",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = true,
    (gogoproto.jsontag) = "max_amount_out"
  ];
}

message QueryEstimatePlaceLimitOrderResponse {
  // Total amount of coin used for the limit order
  // You can derive makerLimitInCoin using the equation: totalInCoin =
  // swapInCoin + makerLimitInCoin
  cosmos.base.v1beta1.Coin total_in_coin = 1 [
    (gogoproto.moretags) = "yaml:\"total_in_coin\"",
    (gogoproto.nullable) = false,
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
    (gogoproto.jsontag) = "total_in_coin"
  ];

  // Total amount of the token in that was immediately swapped for swapOutCoin
  cosmos.base.v1beta1.Coin swap_in_coin = 2 [
    (gogoproto.moretags) = "yaml:\"swap_in_coin\"",
    (gogoproto.nullable) = false,
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
    (gogoproto.jsontag) = "swap_in_coin"
  ];

  // Total amount of coin received from the taker portion of the limit order
  // This is the amount of coin immediately available in the users account after
  // executing the limit order. It does not include any future proceeds from the
  // maker portion which will have withdrawn in the future
  cosmos.base.v1beta1.Coin swap_out_coin = 3 [
    (gogoproto.moretags) = "yaml:\"swap_out_coin\"",
    (gogoproto.nullable) = false,
    (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
    (gogoproto.jsontag) = "swap_out_coin"
  ];
}

message QueryPoolRequest {
  string pair_id = 1;
  int64 tick_index = 2;
  uint64 fee = 3;
}

message QueryPoolByIDRequest {
  uint64 pool_id = 1;
}

message QueryPoolResponse {
  Pool pool = 1 [(gogoproto.nullable) = true];
}

message QueryGetPoolMetadataRequest {
  uint64 id = 1;
}

message QueryGetPoolMetadataResponse {
  PoolMetadata Pool_metadata = 1 [(gogoproto.nullable) = false];
}

message QueryAllPoolMetadataRequest {
  cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllPoolMetadataResponse {
  repeated PoolMetadata pool_metadata = 1 [(gogoproto.nullable) = false];
  cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QuerySimulateDepositRequest {
  MsgDeposit msg = 1;
}

message QuerySimulateDepositResponse {
  MsgDepositResponse resp = 1;
}

message QuerySimulateWithdrawalRequest {
  MsgWithdrawal msg = 1;
}

message QuerySimulateWithdrawalResponse {
  MsgWithdrawalResponse resp = 1;
}

message QuerySimulatePlaceLimitOrderRequest {
  MsgPlaceLimitOrder msg = 1;
}

message QuerySimulatePlaceLimitOrderResponse {
  MsgPlaceLimitOrderResponse resp = 1;
}

message QuerySimulateWithdrawFilledLimitOrderRequest {
  MsgWithdrawFilledLimitOrder msg = 1;
}

message QuerySimulateWithdrawFilledLimitOrderResponse {
  MsgWithdrawFilledLimitOrderResponse resp = 1;
}

message QuerySimulateCancelLimitOrderRequest {
  MsgCancelLimitOrder msg = 1;
}

message QuerySimulateCancelLimitOrderResponse {
  MsgCancelLimitOrderResponse resp = 1;
}

message QuerySimulateMultiHopSwapRequest {
  MsgMultiHopSwap msg = 1;
}

message QuerySimulateMultiHopSwapResponse {
  MsgMultiHopSwapResponse resp = 1;
}

// this line is used by starport scaffolding # 3
