10 #include <tvm/schema/message.hpp>
12 #include <tvm/replay_attack_protection/timestamp.hpp>
13 #include <tvm/smart_switcher.hpp>
14 #include <tvm/small_dict_map.hpp>
15 #include <tvm/contract_handle.hpp>
16 #include <tvm/big_queue.hpp>
17 #include <tvm/string.hpp>
18 #include <tvm/numeric_limits.hpp>
19 #include <tvm/suffixes.hpp>
23 #include "FlexWallet.hpp"
25 #include "FlexLendPayloadArgs.hpp"
31 using ITONTokenWalletPtr = handle<ITONTokenWallet>;
36 static constexpr
unsigned safe_delay_period = 5 * 60;
39 bool is_active_time(uint32 order_finish_time) {
40 return tvm_now() <
static_cast<int>(order_finish_time.get());
47 unsigned cost = __builtin_tvm_muldivr(amount.get(), price.numerator().get(), price.denominator().get());
48 if ((cost >> 128) || (cost == 0))
69 using OrderInfoXchgWithIdx = std::pair<unsigned, OrderInfoXchg>;
74 dict_array<OrderInfoXchg>
sells;
75 dict_array<OrderInfoXchg>
buys;
88 [[
internal, noaccept, answer_id, deploy]]
91 uint32 lend_finish_time,
100 [[
internal, noaccept]]
104 [[
internal, noaccept]]
107 opt<uint256> user_id,
108 opt<uint256> order_id
112 [[
internal, noaccept]]
117 opt<uint256> order_id
124 using IPriceXchgPtr = handle<IPriceXchg>;
131 uint128 buys_amount_;
147 static std::pair<StateInit, uint256> execute(
DPriceXchg data, cell code) {
148 cell data_cl = prepare_persistent_data<IPriceXchg, void>({}, data);
149 StateInit init { {}, {}, code, data_cl, {} };
150 cell init_cl = build(init).make_cell();
151 return { init, uint256(tvm_hash(init_cl)) };
Flex root contract interfaces and data-structs.
Price common interfaces and data-structs.
PriceXchgSalt - configuration structure for PriceXchg (stored in code salt)
__always_inline std::optional< uint128 > minor_cost(uint128 amount, price_t price)
Definition: PriceXchg.hpp:46
Flex rational price (numerator / denominator)
PriceXchg persistent data struct.
Definition: PriceXchg.hpp:127
uint128 sells_amount_
Definition: PriceXchg.hpp:129
big_queue< OrderInfoXchg > buys_
Queue of buy orders.
Definition: PriceXchg.hpp:135
big_queue< OrderInfoXchg > sells_
Queue of sell orders.
Definition: PriceXchg.hpp:134
uint128 price_num_
Price numerator in minor tokens for one minor token - rational number, denominator kept in config.
Definition: PriceXchg.hpp:128
PriceXchg events interface.
Definition: PriceXchg.hpp:140
PriceXchg contract interface.
Definition: PriceXchg.hpp:84
OrderRet onTip3LendOwnership(uint128 balance, uint32 lend_finish_time, Tip3Creds creds, cell payload, address answer_addr)
Implementation of ITONTokenWalletNotify::onTip3LendOwnership().
void cancelWalletOrder(bool sell, address owner, uint256 user_id, opt< uint256 > order_id)
Will cancel orders, may be requested only from FlexWallet.
void processQueue()
Process enqueued orders.
PriceXchgDetails getDetails()
Get contract details.
void cancelOrder(bool sell, opt< uint256 > user_id, opt< uint256 > order_id)
Will cancel all sell/buy orders with this sender's client_addr.
tip3-tip3 exchange order info
Definition: PriceXchg.hpp:54
uint128 original_amount
Original amount of major tokens to buy or sell.
Definition: PriceXchg.hpp:57
uint128 account
Remaining native funds from client to pay for processing.
Definition: PriceXchg.hpp:59
bool post_order
Should this order be enqueued if it doesn't already have corresponding orders.
Definition: PriceXchg.hpp:56
bool immediate_client
Should this order try to be executed as a client order first (find existing corresponding orders).
Definition: PriceXchg.hpp:55
uint128 amount
Current remaining amount of major tokens to buy or sell.
Definition: PriceXchg.hpp:58
addr_std_fixed client_addr
Definition: PriceXchg.hpp:62
uint64 ltime
Logical time of starting transaction for the order.
Definition: PriceXchg.hpp:67
uint32 order_finish_time
Order finish time.
Definition: PriceXchg.hpp:64
addr_std_fixed tip3_wallet_provide
Client tip3 wallet to provide tokens (major for sell or minor for buy).
Definition: PriceXchg.hpp:61
uint128 lend_amount
Current remaining amount of lend tokens (major tokens for sell, minor tokens for buy).
Definition: PriceXchg.hpp:60
uint256 order_id
Order id.
Definition: PriceXchg.hpp:66
uint256 user_id
User id.
Definition: PriceXchg.hpp:65
Notification struct about order to a client.
Definition: PriceCommon.hpp:16
PriceXchg contract details (for getter)
Definition: PriceXchg.hpp:72
PriceXchgSalt salt
Configuration from code salt.
Definition: PriceXchg.hpp:76
uint128 price_num
Price numerator in minor tokens for one minor token - rational number, denominator kept in config.
Definition: PriceXchg.hpp:73
dict_array< OrderInfoXchg > buys
Buy orders.
Definition: PriceXchg.hpp:75
dict_array< OrderInfoXchg > sells
Sell orders.
Definition: PriceXchg.hpp:74
Price configuration data (common for prices of one pair). Stored in code salt.
Definition: PriceXchgSalt.hpp:12
Rational value - numerator/denominator.
Definition: RationalValue.hpp:12