syntax = "proto3";

// Fiat currency and orderbook types: fiat currencies for pricing,
// orderbook currency identifiers, swap amounts, and order matching.

package hydra_app;

import "primitives.proto";

// Supported fiat currencies for asset pricing and conversion.
enum FiatCurrency {
  // Unspecified fiat currency (invalid default).
  FIAT_CURRENCY_UNSPECIFIED = 0;
  // United States Dollar.
  FIAT_CURRENCY_USD = 1;
  // Euro.
  FIAT_CURRENCY_EUR = 2;
  // British Pound Sterling.
  FIAT_CURRENCY_GBP = 3;
  // Australian Dollar.
  FIAT_CURRENCY_AUD = 4;
  // Canadian Dollar.
  FIAT_CURRENCY_CAD = 5;
  // Swiss Franc.
  FIAT_CURRENCY_CHF = 6;
  // Chinese Yuan.
  FIAT_CURRENCY_CNY = 7;
  // Japanese Yen.
  FIAT_CURRENCY_JPY = 8;
  // South Korean Won.
  FIAT_CURRENCY_KRW = 9;
  // Russian Ruble.
  FIAT_CURRENCY_RUB = 10;
  // Turkish Lira.
  FIAT_CURRENCY_TRY = 11;
  // Indian Rupee.
  FIAT_CURRENCY_INR = 12;
}

// Identifies a specific asset on a specific network for orderbook operations.
message OrderbookCurrency {
  // The protocol family of the network.
  Protocol protocol = 1;
  // The network identifier.
  string network_id = 2;
  // The asset identifier on that network.
  string asset_id = 3;
}

// Specifies the amount for a swap operation.
//
// Use `From` to specify the amount of the sending currency, or `To` to
// specify the desired amount of the receiving currency.
message SwapAmount {
  // Specify the amount of the sending (source) currency.
  message From {
    // The amount to send.
    DecimalString amount = 1;
  }
  // Specify the desired amount of the receiving (destination) currency.
  message To {
    // The amount to receive.
    DecimalString amount = 1;
  }

  oneof amount {
    From from = 1;
    To to = 2;
  }
}

// Per-leg settlement method for an order. The on-chain refund/claim address is
// declared later, at the orderbook's PrepareSwap (not here), so this is a pure
// method selector. The zero value is CHANNEL, so an unset field means channel.
enum LegSettlement {
  // Channel only (the default).
  LEG_SETTLEMENT_CHANNEL = 0;
  // On-chain HTLC only.
  LEG_SETTLEMENT_ONCHAIN = 1;
  // Either; the orderbook picks one (prefers channel).
  LEG_SETTLEMENT_CHANNEL_OR_ONCHAIN = 2;
}

// Per-order settlement preference, signed into the order. Absent = channel on
// both legs with no route filter.
message OrderSettlement {
  // How this party SENDS funds to the orderbook hub.
  LegSettlement sending = 1;
  // How this party RECEIVES funds from the orderbook hub.
  LegSettlement receiving = 2;
  // Taker-only route-wide method filter: a bitmask with bit 0 = Channel,
  // bit 1 = Onchain. Absent imposes no constraint. Must be absent on a
  // resting maker order.
  optional uint32 route_filter = 3;
}

// Represents a match of an order in the orderbook for a pair of currencies.
message PairOrderMatch {
  // The currency being sent
  OrderbookCurrency sending_currency = 1;
  // The currency being received
  OrderbookCurrency receiving_currency = 2;
  // The matched amount being sent
  DecimalString sending_amount = 3;
  // The matched amount being received
  DecimalString receiving_amount = 4;
  // The fee paid in the receiving currency
  DecimalString receiving_fee = 5;
  // The slippage of the order ((average price of order - best price of order)
  // / best price of order)
  DecimalString slippage = 6;
}

// Represents a match of an order in the orderbook for a swap between two
// currencies. It can either be a single pair order match or a swap that
// involves multiple pair order matches.
message OrderMatch {
  message Pair {
    PairOrderMatch pair_order_match = 1;
  }

  message Swap {
    repeated PairOrderMatch pair_order_matches = 1;
  }

  oneof order_match {
    Pair pair = 1;
    Swap swap = 2;
  }
}
