syntax = "proto3";

package elys.perpetual;

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

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "elys/perpetual/params.proto";
import "elys/perpetual/types.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";

// Msg defines the Msg service.
service Msg {
  option (cosmos.msg.v1.service) = true;
  rpc Open(MsgOpen) returns (MsgOpenResponse);
  rpc Close(MsgClose) returns (MsgCloseResponse);
  rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
  rpc Whitelist(MsgWhitelist) returns (MsgWhitelistResponse);
  rpc Dewhitelist(MsgDewhitelist) returns (MsgDewhitelistResponse);
  rpc UpdateStopLoss(MsgUpdateStopLoss) returns (MsgUpdateStopLossResponse);
  rpc ClosePositions(MsgClosePositions) returns (MsgClosePositionsResponse);
  rpc UpdateTakeProfitPrice(MsgUpdateTakeProfitPrice)
      returns (MsgUpdateTakeProfitPriceResponse);
  rpc UpdateMaxLeverageForPool(MsgUpdateMaxLeverageForPool)
      returns (MsgUpdateMaxLeverageForPoolResponse);
  rpc UpdateEnabledPools(MsgUpdateEnabledPools)
      returns (MsgUpdateEnabledPoolsResponse);
}
message MsgOpen {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "perpetual/MsgOpen";
  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  Position position = 2;
  string leverage = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string trading_asset = 4;
  cosmos.base.v1beta1.Coin collateral = 5 [ (gogoproto.nullable) = false ];
  string take_profit_price = 6 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string stop_loss_price = 7 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  uint64 pool_id = 8;
}

message MsgOpenResponse { uint64 id = 1; }

message MsgClose {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "perpetual/MsgClose";
  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 id = 2;
  string amount = 3 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
}

message MsgCloseResponse {
  uint64 id = 1;
  string amount = 2 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
}

message MsgUpdateParams {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "perpetual/MsgUpdateParams";
  // authority is the address that controls the module (defaults to x/gov unless
  // overwritten).
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  // NOTE: All parameters must be supplied.
  Params params = 2;
}

message MsgUpdateParamsResponse {}

message MsgWhitelist {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "perpetual/MsgWhitelist";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  string whitelisted_address = 2;
}

message MsgWhitelistResponse {}

message MsgDewhitelist {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "perpetual/MsgDewhitelist";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  string whitelisted_address = 2;
}

message MsgDewhitelistResponse {}

message MsgClosePositions {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "perpetual/MsgClosePositions";
  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated PositionRequest liquidate = 2 [ (gogoproto.nullable) = false ];
  repeated PositionRequest stop_loss = 3 [ (gogoproto.nullable) = false ];
  repeated PositionRequest take_profit = 4 [ (gogoproto.nullable) = false ];
}

message MsgClosePositionsResponse {}

message MsgUpdateStopLoss {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "perpetual/MsgUpdateStopLoss";
  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 id = 2;
  string price = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgUpdateStopLossResponse {}

message MsgUpdateTakeProfitPrice {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "perpetual/MsgUpdateTakeProfitPrice";
  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 id = 2;
  string price = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgUpdateTakeProfitPriceResponse {}

message MsgUpdateMaxLeverageForPool {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "perpetual/MsgUpdateMaxLeverageForPool";
  // authority is the address that controls the module (defaults to x/gov unless
  // overwritten).
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

  uint64 pool_id = 2;
  string leverage_max = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgUpdateMaxLeverageForPoolResponse {}
message MsgUpdateEnabledPools {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "perpetual/MsgUpdateEnabledPools";
  // authority is the address that controls the module (defaults to x/gov unless
  // overwritten).
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated uint64 enabled_pools = 2;
}

message MsgUpdateEnabledPoolsResponse {}
