syntax = "proto3";

package elys.amm;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "elys/amm/params.proto";
import "elys/amm/swap_route.proto";
import "elys/amm/pool_params.proto";
import "elys/amm/pool_asset.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/elys-network/elys/x/amm/types";

// Msg defines the Msg service.
service Msg {
  option (cosmos.msg.v1.service) = true;

  rpc CreatePool(MsgCreatePool) returns (MsgCreatePoolResponse);
  rpc JoinPool(MsgJoinPool) returns (MsgJoinPoolResponse);
  rpc ExitPool(MsgExitPool) returns (MsgExitPoolResponse);
  rpc UpFrontSwapExactAmountIn(MsgUpFrontSwapExactAmountIn)
      returns (MsgUpFrontSwapExactAmountInResponse);
  rpc SwapExactAmountIn(MsgSwapExactAmountIn)
      returns (MsgSwapExactAmountInResponse);
  rpc SwapExactAmountOut(MsgSwapExactAmountOut)
      returns (MsgSwapExactAmountOutResponse);
  rpc SwapByDenom(MsgSwapByDenom) returns (MsgSwapByDenomResponse);
  rpc FeedMultipleExternalLiquidity(MsgFeedMultipleExternalLiquidity)
      returns (MsgFeedMultipleExternalLiquidityResponse);
  rpc UpdatePoolParams(MsgUpdatePoolParams)
      returns (MsgUpdatePoolParamsResponse);
  rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}
message MsgCreatePool {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgCreatePool";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  PoolParams pool_params = 2 [ (gogoproto.nullable) = false ];
  repeated PoolAsset pool_assets = 3 [ (gogoproto.nullable) = false ];
}

message MsgCreatePoolResponse {
  uint64 pool_id = 1 [ (gogoproto.customname) = "PoolID" ];
}

message MsgJoinPool {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgJoinPool";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 pool_id = 2;
  repeated cosmos.base.v1beta1.Coin max_amounts_in = 3
      [ (gogoproto.nullable) = false ];
  string share_amount_out = 4 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
}

message MsgJoinPoolResponse {
  string share_amount_out = 1 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  repeated cosmos.base.v1beta1.Coin token_in = 2
      [ (gogoproto.nullable) = false ];
}

message MsgExitPool {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgExitPool";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 pool_id = 2;
  repeated cosmos.base.v1beta1.Coin min_amounts_out = 3
      [ (gogoproto.nullable) = false ];
  string share_amount_in = 4 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  string token_out_denom = 5;
}

message MsgExitPoolResponse {
  repeated cosmos.base.v1beta1.Coin token_out = 1
      [ (gogoproto.nullable) = false ];
  string weight_balance_ratio = 2 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string slippage = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string swap_fee = 4 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgUpFrontSwapExactAmountIn {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgUpFrontSwapExactAmountIn";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated SwapAmountInRoute routes = 2 [ (gogoproto.nullable) = false ];
  cosmos.base.v1beta1.Coin token_in = 3 [ (gogoproto.nullable) = false ];
  string token_out_min_amount = 4 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
}

message MsgUpFrontSwapExactAmountInResponse {
  string token_out_amount = 1 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  string swap_fee = 2 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string discount = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgSwapExactAmountIn {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgSwapExactAmountIn";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated SwapAmountInRoute routes = 2 [ (gogoproto.nullable) = false ];
  cosmos.base.v1beta1.Coin token_in = 3 [ (gogoproto.nullable) = false ];
  string token_out_min_amount = 4 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  string recipient = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

message MsgSwapExactAmountInResponse {
  string token_out_amount = 1 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  string swap_fee = 2 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string discount = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string recipient = 4;
}

message MsgSwapExactAmountOut {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgSwapExactAmountOut";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated SwapAmountOutRoute routes = 2 [ (gogoproto.nullable) = false ];
  cosmos.base.v1beta1.Coin token_out = 3 [ (gogoproto.nullable) = false ];
  string token_in_max_amount = 4 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  string recipient = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

message MsgSwapExactAmountOutResponse {
  string token_in_amount = 1 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  string swap_fee = 2 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string discount = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string recipient = 4;
}

message MsgFeedMultipleExternalLiquidity {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgFeedMultipleExternalLiquidity";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated ExternalLiquidity liquidity = 2 [ (gogoproto.nullable) = false ];
}

message MsgFeedMultipleExternalLiquidityResponse {}

message AssetAmountDepth {
  string asset = 1;
  string amount = 2 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string depth = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

// ExternalLiquidity defines price, volume, and time information for an exchange
// rate.
message ExternalLiquidity {
  uint64 pool_id = 1;
  repeated AssetAmountDepth amount_depth_info = 2
      [ (gogoproto.nullable) = false ];
}

message MsgSwapByDenom {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "amm/MsgSwapByDenom";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  cosmos.base.v1beta1.Coin amount = 2 [ (gogoproto.nullable) = false ];
  cosmos.base.v1beta1.Coin min_amount = 3 [ (gogoproto.nullable) = false ];
  cosmos.base.v1beta1.Coin max_amount = 4 [ (gogoproto.nullable) = false ];
  string denom_in = 5;
  string denom_out = 6;
  string recipient = 7 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

message MsgSwapByDenomResponse {
  cosmos.base.v1beta1.Coin amount = 1 [ (gogoproto.nullable) = false ];
  repeated SwapAmountInRoute in_route = 2;
  repeated SwapAmountOutRoute out_route = 3;
  string spot_price = 4 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string swap_fee = 5 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string discount = 6 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string recipient = 7;
  string slippage = 8 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string weight_bonus = 9 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgUpdatePoolParams {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "amm/MsgUpdatePoolParams";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 pool_id = 2;
  PoolParams pool_params = 3 [ (gogoproto.nullable) = false ];
}

message MsgUpdatePoolParamsResponse {
  uint64 pool_id = 1;
  PoolParams pool_params = 2;
}

message MsgUpdateParams {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "amm/MsgUpdateParams";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  Params params = 2;
}

message MsgUpdateParamsResponse {}
