Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Limit Order Modification Feature #2743

Merged
merged 31 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
61d85de
Progress #1604: Basic implementation
nathanielhourt Feb 21, 2019
f6bbe4b
Progress #1604: Tests and Fixes
nathanielhourt Feb 22, 2019
5484c9f
Ref #1604: Add matching logic
nathanielhourt Feb 22, 2019
3d24f7c
Progress #1604: Add dust check
nathanielhourt Feb 26, 2019
073ecbe
Progress #1604: Add hardfork guards
nathanielhourt Feb 26, 2019
a34c855
Ref #1604: Another test case
nathanielhourt Feb 26, 2019
fba5bac
Progress #1604: Do not allow sooner expiration
nathanielhourt Feb 27, 2019
8a82d92
Add fee_schedule::exists<op_type>()
nathanielhourt Feb 27, 2019
6180946
Ref #1604: Add missing hardfork guard
nathanielhourt Feb 27, 2019
55dc688
Eliminate variable fee
nathanielhourt Oct 7, 2019
a71cfe4
Merge hardfork branch, fix build and tests
abitmore Apr 29, 2023
a03b4ce
Fix issues about limit_order_update_evaluator
abitmore May 8, 2023
44e6de4
Do not allow inappropriate price manipulation
abitmore May 9, 2023
2387df3
Remove redundant checks for order matching
abitmore May 9, 2023
2b3bcd3
Remove redundant checks for account balance
abitmore May 9, 2023
e8e9d0d
Simplify try-catch wrappers in tests
abitmore May 9, 2023
136007e
Update tests to adapt code changes
abitmore May 10, 2023
cf2fca6
Remove mostly useless try/catch wrappers
abitmore May 10, 2023
9160a7e
Add tests for limit_order_update_operation
abitmore May 10, 2023
c58db0b
Fix potential dereferencing issues in tests
abitmore May 10, 2023
85bef43
Add asset authorization tests for order_update op
abitmore May 10, 2023
afcff0d
Update a comment and an assertion message
abitmore May 10, 2023
dfce7c6
Update default order update fee
abitmore May 11, 2023
8898b5a
Process operation fees
abitmore May 11, 2023
269a16d
Reduce log level of exceptions in order_update_op
abitmore May 11, 2023
032f125
Update a comment
abitmore May 12, 2023
663ecd9
Move deferred fee processing code into a function
abitmore May 12, 2023
d381110
Add tests for order_update fee if paid in CORE
abitmore May 12, 2023
1195df5
Add tests for order_update fee if not paid in CORE
abitmore May 12, 2023
2a34e1b
Update variable names to fix variable shadowing
abitmore May 15, 2023
126987e
Update a comment
abitmore May 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void database::initialize_evaluators()
register_evaluator<asset_global_settle_evaluator>();
register_evaluator<assert_evaluator>();
register_evaluator<limit_order_create_evaluator>();
register_evaluator<limit_order_update_evaluator>();
register_evaluator<limit_order_cancel_evaluator>();
register_evaluator<call_order_update_evaluator>();
register_evaluator<bid_collateral_evaluator>();
Expand Down
12 changes: 6 additions & 6 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
// 1. due to expiration: always deduct a fee if there is any fee deferred
// 2. due to cull_small: deduct a fee after hard fork 604, but not before (will set skip_cancel_fee)
const account_statistics_object* seller_acc_stats = nullptr;
const asset_dynamic_data_object* fee_asset_dyn_data = nullptr;
const asset_dynamic_data_object* deferred_fee_asset_dyn_data = nullptr;
limit_order_cancel_operation vop;
share_type deferred_fee = order.deferred_fee;
asset deferred_paid_fee = order.deferred_paid_fee;
Expand Down Expand Up @@ -576,8 +576,8 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
fee128 /= order.deferred_fee.value;
share_type cancel_fee_amount = static_cast<int64_t>(fee128);
// cancel_fee should be positive, pay it to asset's accumulated_fees
fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this);
modify( *fee_asset_dyn_data, [&cancel_fee_amount](asset_dynamic_data_object& addo) {
deferred_fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this);
modify( *deferred_fee_asset_dyn_data, [&cancel_fee_amount](asset_dynamic_data_object& addo) {
addo.accumulated_fees += cancel_fee_amount;
});
// cancel_fee should be no more than deferred_paid_fee
Expand Down Expand Up @@ -613,9 +613,9 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_
{
adjust_balance(order.seller, deferred_paid_fee);
// be here, must have: fee_asset != CORE
if( !fee_asset_dyn_data )
fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this);
modify( *fee_asset_dyn_data, [&](asset_dynamic_data_object& addo) {
if( !deferred_fee_asset_dyn_data )
deferred_fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this);
modify( *deferred_fee_asset_dyn_data, [&deferred_fee](asset_dynamic_data_object& addo) {
addo.fee_pool += deferred_fee;
});
}
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/db_notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ struct get_impacted_account_visitor
{
_impacted.insert( op.fee_payer() ); // seller
}
void operator()(const limit_order_update_operation& op)
{
_impacted.insert(op.fee_payer()); // seller
}
void operator()( const limit_order_cancel_operation& op )
{
_impacted.insert( op.fee_payer() ); // fee_paying_account
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ namespace graphene { namespace chain {
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( insufficient_balance, limit_order_create, 6,
"Insufficient balance" )

GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( limit_order_update );
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_update, 1, "Order does not exist" )
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_update, 2, "Order owned by someone else" )

GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( limit_order_cancel );
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_cancel, 1, "Order does not exist" )
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_cancel, 2, "Order owned by someone else" )
Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/hardfork.d/CORE_1604.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// bitshares-core issue #1604 Operation to modify existing limit order
#ifndef HARDFORK_CORE_1604_TIME
#define HARDFORK_CORE_1604_TIME (fc::time_point_sec(1893456000)) // Jan 1 00:00:00 2030 (Not yet scheduled)
#define HARDFORK_CORE_1604_PASSED(head_block_time) (head_block_time >= HARDFORK_CORE_1604_TIME)
#endif
4 changes: 4 additions & 0 deletions libraries/chain/include/graphene/chain/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace graphene { namespace chain {
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( receiving_asset_unauthorized, limit_order_create, 5 )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( insufficient_balance, limit_order_create, 6 )

GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( limit_order_update );
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_update, 1 )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_update, 2 )

GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( limit_order_cancel );
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_cancel, 1 )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_cancel, 2 )
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/include/graphene/chain/hardfork_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct hardfork_visitor {
using BSIP_40_ops = fc::typelist::list< protocol::custom_authority_create_operation,
protocol::custom_authority_update_operation,
protocol::custom_authority_delete_operation>;
using hf1604_ops = fc::typelist::list< protocol::limit_order_update_operation>;
using hf2103_ops = fc::typelist::list< protocol::ticket_create_operation,
protocol::ticket_update_operation>;
using liquidity_pool_ops = fc::typelist::list< protocol::liquidity_pool_create_operation,
Expand Down Expand Up @@ -82,6 +83,9 @@ struct hardfork_visitor {
std::enable_if_t<fc::typelist::contains<BSIP_40_ops, Op>(), bool>
visit() { return HARDFORK_BSIP_40_PASSED(now); }
template<typename Op>
std::enable_if_t<fc::typelist::contains<hf1604_ops, Op>(), bool>
visit() { return HARDFORK_CORE_1604_PASSED(now); }
template<typename Op>
std::enable_if_t<fc::typelist::contains<hf2103_ops, Op>(), bool>
visit() { return HARDFORK_CORE_2103_PASSED(now); }
template<typename Op>
Expand Down
36 changes: 31 additions & 5 deletions libraries/chain/include/graphene/chain/market_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ namespace graphene { namespace chain {
void_result do_evaluate( const limit_order_create_operation& o );
object_id_type do_apply( const limit_order_create_operation& o ) const;

/** override the default behavior defined by generic_evalautor
/** override the default behavior defined by generic_evaluator
*/
virtual void convert_fee() override;
void convert_fee() override;

/** override the default behavior defined by generic_evalautor which is to
/** override the default behavior defined by generic_evaluator which is to
* post the fee to fee_paying_account_stats.pending_fees
*/
virtual void pay_fee() override;
void pay_fee() override;

private:
share_type _deferred_fee = 0;
Expand All @@ -59,6 +59,32 @@ namespace graphene { namespace chain {
const asset_object* _receive_asset = nullptr;
};

class limit_order_update_evaluator : public evaluator<limit_order_update_evaluator>
{
public:
using operation_type = limit_order_update_operation;

void_result do_evaluate(const limit_order_update_operation& o);
void_result do_apply(const limit_order_update_operation& o);
abitmore marked this conversation as resolved.
Show resolved Hide resolved

abitmore marked this conversation as resolved.
Show resolved Hide resolved
/** override the default behavior defined by generic_evaluator
*/
void convert_fee() override;

/** override the default behavior defined by generic_evaluator which is to
* post the fee to fee_paying_account_stats.pending_fees
*/
void pay_fee() override;

private:
void process_deferred_fee();

share_type _deferred_fee;
asset _deferred_paid_fee;
const limit_order_object* _order = nullptr;
const account_statistics_object* _seller_acc_stats = nullptr;
};

class limit_order_cancel_evaluator : public evaluator<limit_order_cancel_evaluator>
{
public:
Expand All @@ -68,7 +94,7 @@ namespace graphene { namespace chain {
asset do_apply( const limit_order_cancel_operation& o ) const;

private:
const limit_order_object* _order;
const limit_order_object* _order = nullptr;
};

class call_order_update_evaluator : public evaluator<call_order_update_evaluator>
Expand Down
Loading