From d1ae7e69bcb23cdaffe1d963c5356b029c38e3d7 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 6 Sep 2023 10:30:32 +0000 Subject: [PATCH 1/2] Record filled amount in limit orders --- libraries/chain/db_market.cpp | 3 +++ libraries/chain/include/graphene/chain/config.hpp | 2 +- libraries/chain/include/graphene/chain/market_object.hpp | 9 +++++---- libraries/chain/market_object.cpp | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 930de41a9..6842ef0e4 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -1232,6 +1232,7 @@ database::match_result_type database::match_limit_settled_debt( const limit_orde obj.for_sale = bitasset.individual_settlement_fund; obj.sell_price = ~bitasset.get_individual_settlement_price(); } + // Note: filled_amount is not updated, but it should be fine }); // Note: // After the price is updated, it is possible that the order can be matched with another order on the order @@ -1325,6 +1326,7 @@ database::match_result_type database::match_settled_debt_limit( const limit_orde obj.for_sale = bitasset.individual_settlement_fund; obj.sell_price = ~bitasset.get_individual_settlement_price(); } // GCOVR_EXCL_STOP + // Note: filled_amount is not updated, but it should be fine }); } @@ -1889,6 +1891,7 @@ bool database::fill_limit_order( const limit_order_object& order, const asset& p } modify( order, [&pays,&new_take_profit_order_id]( limit_order_object& b ) { b.for_sale -= pays.amount; + b.filled_amount += pays.amount.value; b.deferred_fee = 0; b.deferred_paid_fee.amount = 0; if( new_take_profit_order_id.valid() ) // A new take profit order is created, link it to this order diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 9ac7aa723..24bdbfa55 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -32,7 +32,7 @@ #define GRAPHENE_MAX_NESTED_OBJECTS (200) -const std::string GRAPHENE_CURRENT_DB_VERSION = "20230529"; +const std::string GRAPHENE_CURRENT_DB_VERSION = "20230906"; #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index 4faa8e5c2..b04430585 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -45,10 +45,11 @@ using namespace graphene::db; class limit_order_object : public abstract_object { public: - time_point_sec expiration; - account_id_type seller; - share_type for_sale; ///< asset id is sell_price.base.asset_id - price sell_price; + time_point_sec expiration; ///< When this limit order will expire + account_id_type seller; ///< Who is selling + share_type for_sale; ///< The amount for sale, asset id is sell_price.base.asset_id + price sell_price; ///< The seller's asking price + fc::uint128_t filled_amount = 0; ///< The amount that has been sold, asset id is sell_price.base.asset_id share_type deferred_fee; ///< fee converted to CORE asset deferred_paid_fee; ///< originally paid fee bool is_settled_debt = false; ///< Whether this order is an individual settlement fund diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index bc78adb1d..9f9fc5357 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -308,7 +308,7 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_object, (graphene::db::object), - (expiration)(seller)(for_sale)(sell_price)(deferred_fee)(deferred_paid_fee) + (expiration)(seller)(for_sale)(sell_price)(filled_amount)(deferred_fee)(deferred_paid_fee) (is_settled_debt)(on_fill)(take_profit_order_id) ) From 692608b01a7b55b35cb4187b01047c68c9ac63fd Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 6 Sep 2023 19:53:34 +0000 Subject: [PATCH 2/2] Fix typo in a comment to fix code coverage report GCOVR_EXEL_STOP -> GCOVR_EXCL_STOP --- libraries/chain/db_market.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 6842ef0e4..01043fcb8 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -1225,7 +1225,7 @@ database::match_result_type database::match_limit_settled_debt( const limit_orde wlog( "Unexpected scene: obj.for_sale > bitasset.individual_settlement_fund" ); obj.for_sale = bitasset.individual_settlement_fund; obj.sell_price = ~bitasset.get_individual_settlement_price(); - } // GCOVR_EXEL_STOP + } // GCOVR_EXCL_STOP } else {