Flex
Flex exchange system
XchgPair.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "FlexWallet.hpp"
11 #include "XchgPairSalt.hpp"
12 
13 #include <tvm/schema/message.hpp>
14 #include <tvm/smart_switcher.hpp>
15 #include <tvm/contract_handle.hpp>
16 
17 namespace tvm {
18 
21  address tip3_major_root;
22  address tip3_minor_root;
23  uint128 min_amount;
24  uint128 minmove;
25  uint128 price_denum;
26  address notify_addr;
29  Tip3Config major_tip3cfg;
30  Tip3Config minor_tip3cfg;
31  address_opt next;
32  bool unlisted;
33 };
34 
38 __interface IXchgPair {
39 
41  [[internal, deploy]]
42  void onDeploy(
43  uint128 min_amount,
44  uint128 minmove,
45  uint128 price_denum,
46  uint128 deploy_value,
47  address notify_addr,
48  Tip3Config major_tip3cfg,
49  Tip3Config minor_tip3cfg
50  ) = 10;
51 
53  [[internal, answer_id]]
55 
57  [[internal]]
58  void setNext(address next) = 12;
59 
61  [[internal]]
62  void unlist() = 13;
63 
64  // ========== getters ==========
66  [[getter]]
67  XchgPairDetails getDetails() = immutable_ids::pair_get_details_id;
68 
70  [[getter]]
72 
74  [[getter]]
75  cell getPriceXchgCode(bool salted) = immutable_ids::pair_get_price_xchg_code_id;
76 
78  [[getter]]
79  cell getPriceXchgSalt() = 15;
80 };
81 using IXchgPairPtr = handle<IXchgPair>;
82 
84 struct DXchgPair {
85  address tip3_major_root_;
86  address tip3_minor_root_;
87  // ^^^ Fields defined at deploy (used for address calculation) ^^^
88  uint128 min_amount_;
89  uint128 minmove_;
90  uint128 price_denum_;
91  address notify_addr_;
94  opt<Tip3Config> major_tip3cfg_;
95  opt<Tip3Config> minor_tip3cfg_;
96  opt<address> next_;
97  bool_t unlisted_;
98 };
99 
102 __interface EXchgPair {
103 };
104 
106 template<>
107 struct preparer<IXchgPair, DXchgPair> {
108  __always_inline
109  static std::pair<StateInit, uint256> execute(DXchgPair data, cell code) {
110  cell data_cl = prepare_persistent_data<IXchgPair, void, DXchgPair>({}, data);
111  StateInit init { {}, {}, code, data_cl, {} };
112  cell init_cl = build(init).make_cell();
113  return { init, uint256(tvm_hash(init_cl)) };
114  }
115 };
116 
117 } // namespace tvm
Exchange pair (XchgPair) configuration structure (stored in code salt)
XchgPair persistent data struct.
Definition: XchgPair.hpp:84
uint128 minmove_
Minimum move for price.
Definition: XchgPair.hpp:89
address notify_addr_
Notification address (AMM)
Definition: XchgPair.hpp:91
address tip3_major_root_
Address of Wrapper for major tip3 token. Used for address calculation.
Definition: XchgPair.hpp:85
opt< address > next_
Next XchgPair address.
Definition: XchgPair.hpp:96
opt< Tip3Config > major_tip3cfg_
Configuration of the major tip3 token.
Definition: XchgPair.hpp:94
address tip3_minor_root_
Address of Wrapper for minor tip3 token. Used for address calculation.
Definition: XchgPair.hpp:86
opt< Tip3Config > minor_tip3cfg_
Configuration of the minor tip3 token.
Definition: XchgPair.hpp:95
uint128 min_amount_
Minimum amount of major tokens for a deal or an order.
Definition: XchgPair.hpp:88
address major_reserve_wallet_
Major reserve wallet.
Definition: XchgPair.hpp:92
bool_t unlisted_
If pair is unlisted.
Definition: XchgPair.hpp:97
uint128 price_denum_
Price denominator for the pair.
Definition: XchgPair.hpp:90
address minor_reserve_wallet_
Minor reserve wallet.
Definition: XchgPair.hpp:93
XchgPair events interface.
Definition: XchgPair.hpp:102
XchgPair contract interface.
Definition: XchgPair.hpp:38
void setNext(address next)
Set next pair address.
cell getPriceXchgCode(bool salted)
Get PriceXchg contract code with configuration salt added.
XchgPairSalt getConfig()
Get XchgPair configuration from code salt (common for all pairs of one flex)
XchgPairDetails getDetails()
Get contract details.
void onDeploy(uint128 min_amount, uint128 minmove, uint128 price_denum, uint128 deploy_value, address notify_addr, Tip3Config major_tip3cfg, Tip3Config minor_tip3cfg)
Initialization method, may only be called by Flex root or previous XchgPair.
void unlist()
Set unlisted flag.
XchgPairDetails requestDetails()
Request contract details (by internal message)
cell getPriceXchgSalt()
Get PriceXchg salt (configuration) for this pair.
XchgPair details (for getter)
Definition: XchgPair.hpp:20
uint128 min_amount
Minimum amount of major tokens for a deal or an order.
Definition: XchgPair.hpp:23
address_opt next
Next XchgPair address.
Definition: XchgPair.hpp:31
address tip3_major_root
Address of Wrapper for major tip3 token.
Definition: XchgPair.hpp:21
bool unlisted
If pair is unlisted.
Definition: XchgPair.hpp:32
address notify_addr
Notification address (AMM)
Definition: XchgPair.hpp:26
uint128 minmove
Minimum move for price.
Definition: XchgPair.hpp:24
address major_reserve_wallet
Major reserve wallet.
Definition: XchgPair.hpp:27
Tip3Config minor_tip3cfg
Configuration of the minor tip3 token.
Definition: XchgPair.hpp:30
uint128 price_denum
Price denominator for the pair.
Definition: XchgPair.hpp:25
Tip3Config major_tip3cfg
Configuration of the major tip3 token.
Definition: XchgPair.hpp:29
address minor_reserve_wallet
Minor reserve wallet.
Definition: XchgPair.hpp:28
address tip3_minor_root
Address of Wrapper for minor tip3 token.
Definition: XchgPair.hpp:22
XchgPair configuration structure (stored in salt)
Definition: XchgPairSalt.hpp:21