syntax = "proto3";
package provenance.exchange.v1;

option go_package = "github.com/provenance-io/provenance/x/exchange";

option java_package        = "io.provenance.exchange.v1";
option java_multiple_files = true;

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

// Order associates an order id with one of the order types.
message Order {
  option (gogoproto.goproto_getters) = false;

  // order_id is the numerical identifier for this order.
  uint64 order_id = 1;
  // order is the specifics of this order.
  oneof order {
    // ask_order is the information about this order if it represents an ask order.
    AskOrder ask_order = 2;
    // bid_order is the information about this order if it represents a bid order.
    BidOrder bid_order = 3;
  }
}

// AskOrder represents someone's desire to sell something at a minimum price.
message AskOrder {
  option (cosmos.msg.v1.signer)      = "seller";
  option (gogoproto.goproto_getters) = false;

  // market_id identifies the market that this order belongs to.
  uint32 market_id = 1;
  // seller is the address of the account that owns this order and has the assets to sell.
  string seller = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // assets are the things that the seller wishes to sell.
  // A hold is placed on this until the order is filled or cancelled.
  cosmos.base.v1beta1.Coin assets = 3 [(gogoproto.nullable) = false];
  // price is the minimum amount that the seller is willing to accept for the assets. The seller's settlement
  // proportional fee (and possibly the settlement flat fee) is taken out of the amount the seller receives,
  // so it's possible that the seller will still receive less than this price.
  cosmos.base.v1beta1.Coin price = 4 [(gogoproto.nullable) = false];
  // seller_settlement_flat_fee is the flat fee for sellers that will be charged during settlement. If this denom is the
  // same denom as the price, it will come out of the actual price received. If this denom is different, the amount must
  // be in the seller's account and a hold is placed on it until the order is filled or cancelled.
  cosmos.base.v1beta1.Coin seller_settlement_flat_fee = 5;
  // allow_partial should be true if partial fulfillment of this order should be allowed, and should be false if the
  // order must be either filled in full or not filled at all.
  bool allow_partial = 6;
  // external_id is an optional string used to externally identify this order. Max length is 100 characters.
  // If an order in this market with this external id already exists, this order will be rejected.
  string external_id = 7;
}

// BidOrder represents someone's desire to buy something at a specific price.
message BidOrder {
  option (cosmos.msg.v1.signer)      = "buyer";
  option (gogoproto.goproto_getters) = false;

  // market_id identifies the market that this order belongs to.
  uint32 market_id = 1;
  // buyer is the address of the account that owns this order and has the price to spend.
  string buyer = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // assets are the things that the buyer wishes to buy.
  cosmos.base.v1beta1.Coin assets = 3 [(gogoproto.nullable) = false];
  // price is the amount that the buyer will pay for the assets.
  // A hold is placed on this until the order is filled or cancelled.
  cosmos.base.v1beta1.Coin price = 4 [(gogoproto.nullable) = false];
  // buyer_settlement_fees are the fees (both flat and proportional) that the buyer will pay (in addition to the price)
  // when the order is settled. A hold is placed on this until the order is filled or cancelled.
  repeated cosmos.base.v1beta1.Coin buyer_settlement_fees = 5 [
    (gogoproto.nullable)     = false,
    (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
    (amino.dont_omitempty)   = true,
    (amino.encoding)         = "legacy_coins"
  ];
  // allow_partial should be true if partial fulfillment of this order should be allowed, and should be false if the
  // order must be either filled in full or not filled at all.
  bool allow_partial = 6;
  // external_id is an optional string used to externally identify this order. Max length is 100 characters.
  // If an order in this market with this external id already exists, this order will be rejected.
  string external_id = 7;
}