32 #include <graphene/chain/hardfork.hpp>
38 namespace graphene {
namespace chain {
46 "The on_fill extension is not allowed until the core-2535 hardfork");
48 "The on_fill action list must contain only one action until expanded in a future hardfork" );
50 FC_ASSERT( d.
find( take_profit_action.fee_asset_id ),
"Fee asset does not exist" );
63 limit_order_create_market_not_whitelisted,
64 "This market has not been whitelisted by the selling asset", );
70 limit_order_create_market_blacklisted,
71 "This market has been blacklisted by the selling asset", );
75 limit_order_create_selling_asset_unauthorized,
76 "The account is not allowed to transact the selling asset", );
79 limit_order_create_receiving_asset_unauthorized,
80 "The account is not allowed to transact the receiving asset", );
83 limit_order_create_insufficient_balance,
84 "insufficient balance",
92 if(
db().head_block_time() <= HARDFORK_CORE_604_TIME )
104 if(
db().head_block_time() <= HARDFORK_445_TIME )
109 if(
db().head_block_time() > HARDFORK_CORE_604_TIME &&
fee_asset->
get_id() != asset_id_type() )
126 obj.seller = _seller->
id;
130 obj.deferred_fee = _deferred_fee;
131 obj.deferred_paid_fee = _deferred_paid_fee;
143 limit_order_create_kill_unfilled,
144 "Killing limit order ${op} due to unable to fill",
177 "The on_fill action list must contain zero or one action until expanded in a future hardfork" );
181 FC_ASSERT( d.
find( take_profit_action.fee_asset_id ),
"Fee asset does not exist" );
188 limit_order_update_nonexist_order,
189 "Limit order ${oid} does not exist, cannot update",
194 limit_order_update_owner_mismatch,
195 "Limit order ${oid} is owned by someone else, cannot update",
200 auto base_id = o.
new_price->base.asset_id;
201 auto quote_id = o.
new_price->quote.asset_id;
203 "Cannot update limit order with incompatible price");
210 "The base amount in the new price cannot be greater than the estimated maximum amount for sale" );
218 "Cannot update limit order with incompatible asset");
219 if (delta.amount < 0)
221 "Cannot deduct all or more from order than order contains");
231 auto new_amount_to_receive = new_amount * new_price;
233 FC_ASSERT( new_amount_to_receive.amount > 0,
234 "Cannot update limit order: order becomes too small; cancel order instead" );
245 const auto& sell_asset = sell_asset_id(d);
246 const auto& receive_asset = receive_asset_id(d);
249 if( !sell_asset.options.whitelist_markets.empty() )
251 FC_ASSERT( sell_asset.options.whitelist_markets.find( receive_asset_id )
252 != sell_asset.options.whitelist_markets.end(),
253 "This market has not been whitelisted by the selling asset" );
255 if( !sell_asset.options.blacklist_markets.empty() )
257 FC_ASSERT( sell_asset.options.blacklist_markets.find( receive_asset_id )
258 == sell_asset.options.blacklist_markets.end(),
259 "This market has been blacklisted by the selling asset" );
263 "The account is not allowed to transact the selling asset" );
266 "The account is not allowed to transact the receiving asset" );
271 void limit_order_update_evaluator::process_deferred_fee()
286 if( core_cancel_fee.
amount > 0 )
291 fc::uint128_t fee128( core_cancel_fee.
amount.
value );
292 if( core_create_fee.
amount > 0 )
299 if( fee128 >
static_cast<uint64_t
>( deferred_fee.
value ) )
300 fee128 = deferred_fee.
value;
301 core_cancel_fee.
amount =
static_cast<int64_t
>( fee128 );
305 if( core_cancel_fee.
amount > 0 )
307 if( !_seller_acc_stats )
309 d.
modify( *_seller_acc_stats, [&core_cancel_fee, &d]( account_statistics_object& obj ) {
312 deferred_fee -= core_cancel_fee.
amount;
315 if( deferred_paid_fee.
amount > 0 )
317 fc::uint128_t fee128( deferred_paid_fee.
amount.
value );
323 share_type cancel_fee_amount =
static_cast<int64_t
>(fee128);
325 deferred_fee_asset_dyn_data = &deferred_paid_fee.
asset_id(d).dynamic_asset_data_id(d);
326 d.
modify( *deferred_fee_asset_dyn_data, [&cancel_fee_amount](asset_dynamic_data_object& addo) {
327 addo.accumulated_fees += cancel_fee_amount;
330 deferred_paid_fee.
amount -= cancel_fee_amount;
346 if( !deferred_fee_asset_dyn_data )
347 deferred_fee_asset_dyn_data = &deferred_paid_fee.
asset_id(d).dynamic_asset_data_id(d);
348 d.
modify( *deferred_fee_asset_dyn_data, [&deferred_fee](asset_dynamic_data_object& addo) {
349 addo.fee_pool += deferred_fee;
355 bool limit_order_update_evaluator::is_linked_tp_order_compatible(
const limit_order_update_operation& o)
const
359 bool is_compatible =
true;
360 if( o.on_fill->empty() )
368 is_compatible =
false;
378 is_compatible =
false;
388 const auto& new_take_profit_action = o.on_fill->front().get<create_take_profit_order_action>();
389 if( old_take_profit_action.spread_percent != new_take_profit_action.spread_percent
390 || old_take_profit_action.repeat != new_take_profit_action.repeat )
392 is_compatible =
false;
396 return is_compatible;
417 process_deferred_fee();
432 unlink = !is_linked_tp_order_compatible( o );
473 limit_order_cancel_nonexist_order,
474 "Limit order ${oid} does not exist",
478 limit_order_cancel_owner_mismatch,
479 "Limit order ${oid} is owned by someone else",
516 (
"sym", _debt_asset->
symbol) );
525 if (next_maintenance_time > HARDFORK_CORE_1465_TIME)
528 "Borrowing this quantity would exceed MAX_SUPPLY" );
532 "This transaction would bring current supply below zero.");
539 "Cannot update debt position when the asset has been globally settled" );
542 "Collateral asset type should be same as backing asset of debt asset" );
546 if( itr != call_idx.end() )
553 FC_ASSERT( new_collateral == 0,
"Should claim all collateral when closing debt position" );
554 _closing_order =
true;
558 FC_ASSERT( new_collateral > 0 && new_debt > 0,
559 "Both collateral and debt should be positive after updated a debt position if not to close it" );
570 "Debt amount and collateral amount should be same when updating debt position in a prediction "
573 && !( HARDFORK_CORE_2467_PASSED( next_maintenance_time ) && _closing_order ) )
580 "The account is not allowed to transact the debt asset" );
582 "The account is not allowed to transact the collateral asset" );
614 stats.total_core_in_orders += o.delta_collateral.amount;
621 auto call_order_id = call_ptr->
id;
627 if( bitasset_options::black_swan_response_type::no_settlement == bsrm )
638 return call_order_id;
642 bool before_core_hardfork_1270 = ( next_maint_time <= HARDFORK_CORE_1270_TIME );
650 call.borrower = o.funding_account;
652 call.
debt = o.delta_debt.amount;
653 if( before_core_hardfork_1270 )
657 call.call_price =
price(
asset( 1, o.delta_collateral.asset_id ),
asset( 1, o.delta_debt.asset_id ) );
664 old_debt = call_ptr->
debt;
668 call.
debt = new_debt;
669 if( before_core_hardfork_1270 )
681 return call_order_id;
690 bool increasing_cr = ( old_collateralization.
valid() && call_ptr->
debt <= *old_debt
691 && call_collateralization > *old_collateralization );
692 if( HARDFORK_CORE_2481_PASSED( next_maint_time ) )
698 "Could not create a debt position which would trigger a blackswan event instantly, "
699 "unless it is to increase collateral ratio of an existing debt position and "
700 "is not increasing its debt amount" );
704 if( bitasset_options::black_swan_response_type::no_settlement == bsrm )
712 bool called_some = d.
check_call_orders( *_debt_asset,
false,
false, _bitasset_data );
723 if( !HARDFORK_CORE_2467_PASSED( next_maint_time ) )
726 "Updating call order would trigger a margin call that cannot be fully filled" );
739 "Could not create a debt position which would trigger a margin call instantly, "
740 "unless the debt position is fully filled, or it is to increase collateral ratio of "
741 "an existing debt position and is not increasing its debt amount, "
742 "or the remaining debt position's collateral ratio is above required "
743 "initial collateral ratio (ICR)" );
749 FC_ASSERT( call_ptr,
"no margin call was executed and yet the call object was deleted" );
759 call_order_update_unfilled_margin_call,
760 "Updating call order would trigger a margin call that cannot be fully filled",
779 bool ok = increasing_cr;
781 ok = before_core_hardfork_1270 ?
785 "Can only increase collateral ratio without increasing debt when the debt position's "
786 "collateral ratio is lower than or equal to required initial collateral ratio (ICR), "
787 "if not to trigger a margin call immediately",
788 (
"old_debt", old_debt)
789 (
"new_debt", call_ptr->
debt)
790 (
"old_collateralization", old_collateralization)
791 (
"new_collateralization", call_collateralization)
796 return call_order_id;
809 (
"sym", _debt_asset->
symbol) );
814 if( HARDFORK_CORE_2281_PASSED( next_maint_time ) )
828 if( bid !=
index.end() )
840 "Cannot increase bid from ${oc} to ${nc} collateral when payer only has ${b}",
842 (
"b", collateral_balance.amount) );
846 (
"b", collateral_balance.amount) );
853 "The account is not allowed to transact the debt asset" );
855 "The account is not allowed to transact the collateral asset" );