syntax = "proto3";

package elys.leveragelp;

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

import "gogoproto/gogo.proto";
import "elys/leveragelp/params.proto";
import "elys/leveragelp/types.proto";
import "elys/leveragelp/pool.proto";
import "elys/leveragelp/query.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 ClaimRewards(MsgClaimRewards) returns (MsgClaimRewardsResponse);
  rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
  rpc AddPool(MsgAddPool) returns (MsgAddPoolResponse);
  rpc RemovePool(MsgRemovePool) returns (MsgRemovePoolResponse);
  rpc Whitelist(MsgWhitelist) returns (MsgWhitelistResponse);
  rpc Dewhitelist(MsgDewhitelist) returns (MsgDewhitelistResponse);
  rpc UpdateStopLoss(MsgUpdateStopLoss) returns (MsgUpdateStopLossResponse);
  rpc ClosePositions(MsgClosePositions) returns (MsgClosePositionsResponse);
  rpc UpdatePool(MsgUpdatePool) returns (MsgUpdatePoolResponse);
  rpc UpdateEnabledPools(MsgUpdateEnabledPools)
      returns (MsgUpdateEnabledPoolsResponse);
}
message MsgOpen {
  option (cosmos.msg.v1.signer) = "creator";
  option (amino.name) = "leveragelp/MsgOpen";
  string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  string collateral_asset = 2;
  string collateral_amount = 3 [
    (cosmos_proto.scalar) = "cosmos.Int",
    (gogoproto.customtype) = "cosmossdk.io/math.Int",
    (gogoproto.nullable) = false
  ];
  uint64 amm_pool_id = 4;
  string leverage = 5 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
  string stop_loss_price = 6 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgOpenResponse {}

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

message MsgCloseResponse {}

message MsgClaimRewards {
  option (cosmos.msg.v1.signer) = "sender";
  option (amino.name) = "leveragelp/MsgClaimRewards";
  string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  repeated uint64 ids = 2;
}

message MsgClaimRewardsResponse {}

message MsgUpdateParams {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "leveragelp/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) = "leveragelp/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) = "leveragelp/MsgDewhitelist";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  string whitelisted_address = 2;
}

message MsgDewhitelistResponse {}

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

message MsgUpdateStopLossResponse {}

message AddPool {
  uint64 amm_pool_id = 1;
  string leverage_max = 3 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgAddPool {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "leveragelp/MsgAddPool";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  AddPool pool = 2 [ (gogoproto.nullable) = false ];
}

message MsgAddPoolResponse {}

message MsgRemovePool {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "leveragelp/MsgRemovePool";
  string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
  uint64 id = 2;
}

message MsgRemovePoolResponse {}

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

message MsgClosePositionsResponse {}

message MsgUpdatePool {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "leveragelp/MsgUpdatePool";
  // 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
  ];
  string max_leveragelp_ratio = 4 [
    (cosmos_proto.scalar) = "cosmos.Dec",
    (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
    (gogoproto.nullable) = false
  ];
}

message MsgUpdatePoolResponse {}
message MsgUpdateEnabledPools {
  option (cosmos.msg.v1.signer) = "authority";
  option (amino.name) = "leveragelp/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 {}
