Flex
Flex exchange system
PriceCommon.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <tvm/suffixes.hpp>
10 
11 #include "RationalValue.hpp"
12 
13 namespace tvm {
14 
16 struct OrderRet {
17  uint32 err_code;
18  uint128 processed;
19  uint128 enqueued;
20  uint128 price_num;
21  uint128 price_denum;
22  uint256 user_id;
23  uint256 order_id;
24  address pair;
27  bool sell;
28 };
29 
33 __interface IPriceCallback {
34  [[internal, noaccept]]
36  OrderRet ret
37  ) = 300;
38 };
39 using IPriceCallbackPtr = handle<IPriceCallback>;
40 
41 static constexpr price_t taker_fee = { 15u128, 10000u128 };
42 static constexpr price_t maker_vig = { 3u128, 10000u128 };
43 
44 static_assert(taker_fee.denum == maker_vig.denum, "Inconsistent taker fee / maker vig denominators");
45 static_assert(taker_fee.num > maker_vig.num, "Inconsistent taker fee / maker vig numerators");
46 
48 __always_inline
49 uint128 calc_lend_tokens_for_order(bool sell, uint128 major_tokens, price_t price) {
50  auto tokens = sell ? major_tokens : (major_tokens * price);
51  return tokens + tokens * taker_fee;
52 }
53 
54 } // namespace tvm
55 
__always_inline uint128 calc_lend_tokens_for_order(bool sell, uint128 major_tokens, price_t price)
Calculate lend tokens for order (including fees)
Definition: PriceCommon.hpp:49
Flex rational price (numerator / denominator)
Notifications to a client about orders.
Definition: PriceCommon.hpp:33
void onOrderFinished(OrderRet ret)
Notification struct about order to a client.
Definition: PriceCommon.hpp:16
uint128 price_num
Price numerator.
Definition: PriceCommon.hpp:20
address pair
XchgPair address.
Definition: PriceCommon.hpp:24
uint32 err_code
Error code (zero if success)
Definition: PriceCommon.hpp:17
uint8 minor_decimals
Decimals for the minor token.
Definition: PriceCommon.hpp:26
bool sell
Is it a sell order.
Definition: PriceCommon.hpp:27
uint128 enqueued
Enqueued major tokens amount.
Definition: PriceCommon.hpp:19
uint8 major_decimals
Decimals for the major token.
Definition: PriceCommon.hpp:25
uint128 price_denum
Price denominator.
Definition: PriceCommon.hpp:21
uint128 processed
Processed major tokens amount.
Definition: PriceCommon.hpp:18
uint256 order_id
Order id.
Definition: PriceCommon.hpp:23
uint256 user_id
User id.
Definition: PriceCommon.hpp:22
Rational value - numerator/denominator.
Definition: RationalValue.hpp:12