From 9dbf78c891f32e5f0f9728106a783c2171e19d20 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 09:52:33 -0400 Subject: [PATCH 1/5] start refactoring short --- .../chain/include/graphene/chain/asset.hpp | 25 +- .../include/graphene/chain/operations.hpp | 92 +----- .../graphene/chain/short_order_evaluator.hpp | 27 +- .../graphene/chain/short_order_object.hpp | 66 ----- .../chain/include/graphene/chain/types.hpp | 9 +- libraries/chain/operations.cpp | 38 +-- libraries/chain/short_order_evaluator.cpp | 276 +++++------------- 7 files changed, 84 insertions(+), 449 deletions(-) diff --git a/libraries/chain/include/graphene/chain/asset.hpp b/libraries/chain/include/graphene/chain/asset.hpp index bee277ec..aac46ed1 100644 --- a/libraries/chain/include/graphene/chain/asset.hpp +++ b/libraries/chain/include/graphene/chain/asset.hpp @@ -121,7 +121,7 @@ namespace graphene { namespace chain { /** * @class price_feed - * @brief defines market parameters for shorts and margin positions + * @brief defines market parameters for margin positions */ struct price_feed { @@ -131,10 +131,6 @@ namespace graphene { namespace chain { * unreasonable prices. */ price call_limit; - /** - * Short orders will only be matched against bids above this price. - */ - price short_limit; /** * Forced settlements will evaluate using this price. */ @@ -144,20 +140,6 @@ namespace graphene { namespace chain { */ uint32_t max_margin_period_sec = GRAPHENE_DEFAULT_MARGIN_PERIOD_SEC; - /** - * Required maintenance collateral is defined - * as a fixed point number with a maximum value of 10.000 - * and a minimum value of 1.000. - * - * This value must be greater than required_maintenance_collateral or - * a margin call would be triggered immediately. - * - * Default requirement is $2 of collateral per $1 of debt based - * upon the premise that both parties to every trade should bring - * equal value to the table. - */ - uint16_t required_initial_collateral = GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO; - /** * Required maintenance collateral is defined * as a fixed point number with a maximum value of 10.000 @@ -191,6 +173,7 @@ namespace graphene { namespace chain { FC_REFLECT( graphene::chain::asset, (amount)(asset_id) ) FC_REFLECT( graphene::chain::price, (base)(quote) ) -#define GRAPHENE_PRICE_FEED_FIELDS (call_limit)(short_limit)(settlement_price)(max_margin_period_sec)\ - (required_initial_collateral)(required_maintenance_collateral) + +#define GRAPHENE_PRICE_FEED_FIELDS (call_limit)(settlement_price)(max_margin_period_sec)(required_maintenance_collateral) + FC_REFLECT( graphene::chain::price_feed, GRAPHENE_PRICE_FEED_FIELDS ) diff --git a/libraries/chain/include/graphene/chain/operations.hpp b/libraries/chain/include/graphene/chain/operations.hpp index b670be1d..ba876c9a 100644 --- a/libraries/chain/include/graphene/chain/operations.hpp +++ b/libraries/chain/include/graphene/chain/operations.hpp @@ -827,89 +827,6 @@ namespace graphene { namespace chain { } }; - /** - * @ingroup operations - * - * Define a new short order, if it is filled it will - * be merged with existing call orders for the same - * account. If maintenance_collateral_ratio is set - * it will update any existing open call orders to - * use the new maintenance level. - * - * When shorting you specify the total amount to sell - * and the amount of collateral along with the initial - * ratio. The price it will sell at is (amount_to_sell/(collateral*initial_collateral_ratio/2000)) - */ - struct short_order_create_operation - { - /// The account placing a short order (this account must sign the transaction) - account_id_type seller; - /// The amount of market-issued asset to short sell - asset amount_to_sell; - /// The fee paid by seller - asset fee; - /// The amount of collateral to withdraw from the seller - asset collateral; - /// Fixed point representation of initial collateral ratio, with three digits of precision - /// Must be greater than or equal to the minimum specified by price feed - uint16_t initial_collateral_ratio = GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO; - /// Fixed point representation of maintenance collateral ratio, with three digits of precision - /// Must be greater than or equal to the minimum specified by price feed - uint16_t maintenance_collateral_ratio = GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO; - /// Expiration time for this order. Any unfilled portion of this order which is on the books at or past this time - /// will automatically be canceled. - time_point_sec expiration = time_point_sec::maximum(); - - account_id_type fee_payer()const { return seller; } - void get_required_auth(flat_set& active_auth_set, flat_set&)const; - void validate()const; - share_type calculate_fee( const fee_schedule_type& k )const; - - pair get_market()const - { - return amount_to_sell.asset_id < collateral.asset_id ? - std::make_pair( amount_to_sell.asset_id, collateral.asset_id ) : - std::make_pair( collateral.asset_id, amount_to_sell.asset_id ); - } - - /** convention: amount_to_sell / amount_to_receive */ - price sell_price()const { return ~price::call_price(amount_to_sell, collateral, initial_collateral_ratio); } - - /** convention: amount_to_sell / amount_to_receive means we are - * selling collateral to receive debt - **/ - price call_price() const { return price::call_price(amount_to_sell, collateral, maintenance_collateral_ratio); } - - void get_balance_delta( balance_accumulator& acc, const operation_result& result = asset())const - { - acc.adjust( fee_payer(), -fee ); - acc.adjust( seller, -collateral ); - } - }; - - /** - * @ingroup operations - * Cancel the short order and return the balance to the - * order->seller account. - */ - struct short_order_cancel_operation - { - short_order_id_type order; - account_id_type fee_paying_account; ///< Must be order->seller - asset fee; ///< paid by order->seller - - account_id_type fee_payer()const { return fee_paying_account; } - void get_required_auth(flat_set& active_auth_set, flat_set&)const; - void validate()const; - share_type calculate_fee( const fee_schedule_type& k )const; - - void get_balance_delta( balance_accumulator& acc, const operation_result& result )const - { - acc.adjust( fee_payer(), -fee ); - acc.adjust( fee_payer(), result.get() ); - } - }; - /** * @ingroup operations @@ -924,13 +841,15 @@ namespace graphene { namespace chain { * have appropriate asset_ids, even if the amount is zero. * * @note this operation can be used to force a market order using the collateral without requiring outside funds. + * + * @note this operation can be used to issue new bitassets provided there is sufficient collateral */ struct call_order_update_operation { account_id_type funding_account; ///< pays fee, collateral, and cover asset fee; ///< paid by funding_account asset collateral_to_add; ///< the amount of collateral to add to the margin position - asset amount_to_cover; ///< the amount of the debt to be paid off + asset amount_to_cover; ///< the amount of the debt to be paid off, may be negative to issue new debt uint16_t maintenance_collateral_ratio = 0; ///< 0 means don't change, 1000 means feed account_id_type fee_payer()const { return funding_account; } @@ -1393,9 +1312,7 @@ namespace graphene { namespace chain { typedef fc::static_variant< transfer_operation, limit_order_create_operation, - short_order_create_operation, limit_order_cancel_operation, - short_order_cancel_operation, call_order_update_operation, key_create_operation, account_create_operation, @@ -1594,9 +1511,6 @@ FC_REFLECT( graphene::chain::limit_order_create_operation, ) FC_REFLECT( graphene::chain::fill_order_operation, (fee)(order_id)(account_id)(pays)(receives) ) FC_REFLECT( graphene::chain::limit_order_cancel_operation,(fee)(fee_paying_account)(order) ) -FC_REFLECT( graphene::chain::short_order_cancel_operation,(fee)(fee_paying_account)(order) ) -FC_REFLECT( graphene::chain::short_order_create_operation, (fee)(seller)(amount_to_sell)(collateral) - (initial_collateral_ratio)(maintenance_collateral_ratio)(expiration) ) FC_REFLECT( graphene::chain::call_order_update_operation, (fee)(funding_account)(collateral_to_add)(amount_to_cover)(maintenance_collateral_ratio) ) FC_REFLECT( graphene::chain::transfer_operation, diff --git a/libraries/chain/include/graphene/chain/short_order_evaluator.hpp b/libraries/chain/include/graphene/chain/short_order_evaluator.hpp index acf1acd4..485424fb 100644 --- a/libraries/chain/include/graphene/chain/short_order_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/short_order_evaluator.hpp @@ -22,32 +22,6 @@ namespace graphene { namespace chain { - class short_order_create_evaluator : public evaluator - { - public: - typedef short_order_create_operation operation_type; - - object_id_type do_evaluate( const short_order_create_operation& o ); - object_id_type do_apply( const short_order_create_operation& o ); - - const short_order_create_operation* _op = nullptr; - const account_object* _seller = nullptr; - const asset_object* _sell_asset = nullptr; - const asset_object* _receive_asset = nullptr; - share_type _priority_fee = 0; - }; - - class short_order_cancel_evaluator : public evaluator - { - public: - typedef short_order_cancel_operation operation_type; - - asset do_evaluate( const short_order_cancel_operation& o ); - asset do_apply( const short_order_cancel_operation& o ); - - const short_order_object* _order; - }; - class call_order_update_evaluator : public evaluator { public: @@ -60,6 +34,7 @@ namespace graphene { namespace chain { const asset_object* _debt_asset = nullptr; const account_object* _paying_account = nullptr; const call_order_object* _order = nullptr; + const bitasset_data_object* _bitasset_data = nullptr; }; } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/short_order_object.hpp b/libraries/chain/include/graphene/chain/short_order_object.hpp index acbc59d8..1036b743 100644 --- a/libraries/chain/include/graphene/chain/short_order_object.hpp +++ b/libraries/chain/include/graphene/chain/short_order_object.hpp @@ -26,47 +26,6 @@ namespace graphene { namespace chain { using namespace graphene::db; - /** - * @class short_order_object - * @brief maintains state about requests to short an asset - * - * Short orders are only valid if their sell price is above the - * fair market value of the asset at the feed price. Users can - * place shorts at any price but their order will be ignored - * beyond the feed. - * - * All shorts have a minimial initial collateral ratio requirement that is - * defined by the network, but individuals may choose to have a higher - * initial collateral to avoid the risk of being margin called. - * - * All shorts have a maintenance collateral ratio that must be kept or - * the network will automatically cover the short order. Users can - * specify a higher maintenance collateral ratio as a form of "stop loss" - * and to potentially get ahead of a short squeeze. - */ - class short_order_object : public abstract_object - { - public: - static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = short_order_object_type; - - time_point_sec expiration; - account_id_type seller; - share_type for_sale; - share_type available_collateral; ///< asset_id == sell_price.quote.asset_id - price sell_price; ///< the price the short is currently at = min(limit_price,feed) - price call_price; ///< the price that will be used to trigger margin calls after match, must be 1:1 if prediction market - uint16_t initial_collateral_ratio = 0; ///< may be higher than the network requires - uint16_t maintenance_collateral_ratio = 0; ///< may optionally be higher than the network requires - - asset get_collateral()const { return asset( available_collateral, sell_price.quote.asset_id ); } - /** if the initial_collateral_ratio is 0, then this is a prediction market order which means the - * amount for sale depends upon price and available collateral. - */ - asset amount_for_sale()const { return asset( for_sale, sell_price.base.asset_id ); } - asset amount_to_receive()const { return amount_for_sale() * sell_price; } - }; - /** * @class call_order_object * @brief tracks debt and call price information @@ -115,27 +74,6 @@ namespace graphene { namespace chain { { return balance.asset_id; } }; - struct by_id; - struct by_price; - struct by_account; - struct by_expiration; - struct by_collateral; - typedef multi_index_container< - short_order_object, - indexed_by< - hashed_unique< tag, - member< object, object_id_type, &object::id > >, - ordered_non_unique< tag, member< short_order_object, time_point_sec, &short_order_object::expiration> >, - ordered_unique< tag, - composite_key< short_order_object, - member< short_order_object, price, &short_order_object::sell_price>, - member< object, object_id_type, &object::id> - >, - composite_key_compare< std::greater, std::less > - > - > - > short_order_multi_index_type; - typedef multi_index_container< call_order_object, indexed_by< @@ -187,10 +125,6 @@ namespace graphene { namespace chain { typedef generic_index force_settlement_index; } } // graphene::chain -FC_REFLECT_DERIVED( graphene::chain::short_order_object, (graphene::db::object), - (expiration)(seller)(for_sale)(available_collateral)(sell_price) - (call_price)(initial_collateral_ratio)(maintenance_collateral_ratio) - ) FC_REFLECT_DERIVED( graphene::chain::call_order_object, (graphene::db::object), (borrower)(collateral)(debt)(call_price)(maintenance_collateral_ratio) ) diff --git a/libraries/chain/include/graphene/chain/types.hpp b/libraries/chain/include/graphene/chain/types.hpp index 7a7d15d1..a4d2b089 100644 --- a/libraries/chain/include/graphene/chain/types.hpp +++ b/libraries/chain/include/graphene/chain/types.hpp @@ -108,7 +108,6 @@ namespace graphene { namespace chain { delegate_object_type, witness_object_type, limit_order_object_type, - short_order_object_type, call_order_object_type, custom_object_type, proposal_object_type, @@ -152,7 +151,6 @@ namespace graphene { namespace chain { class force_settlement_object; class key_object; class limit_order_object; - class short_order_object; class call_order_object; class custom_object; class proposal_object; @@ -169,7 +167,6 @@ namespace graphene { namespace chain { typedef object_id< protocol_ids, delegate_object_type, delegate_object> delegate_id_type; typedef object_id< protocol_ids, witness_object_type, witness_object> witness_id_type; typedef object_id< protocol_ids, limit_order_object_type, limit_order_object> limit_order_id_type; - typedef object_id< protocol_ids, short_order_object_type, short_order_object> short_order_id_type; typedef object_id< protocol_ids, call_order_object_type, call_order_object> call_order_id_type; typedef object_id< protocol_ids, custom_object_type, custom_object> custom_id_type; typedef object_id< protocol_ids, proposal_object_type, proposal_object> proposal_id_type; @@ -358,7 +355,7 @@ namespace graphene { namespace chain { uint32_t witness_withdraw_pay_fee; ///< fee for withdrawing witness pay uint32_t transfer_fee; ///< fee for transferring some asset uint32_t limit_order_fee; ///< fee for placing a limit order in the markets - uint32_t short_order_fee; ///< fee for placing a short order in the markets + uint32_t call_order_fee; ///< fee for placing a call order in the markets uint32_t publish_feed_fee; ///< fee for publishing a price feed uint32_t asset_create_fee; ///< the cost to register the cheapest asset uint32_t asset_update_fee; ///< the cost to modify a registered asset @@ -487,7 +484,6 @@ FC_REFLECT_ENUM( graphene::chain::object_type, (delegate_object_type) (witness_object_type) (limit_order_object_type) - (short_order_object_type) (call_order_object_type) (custom_object_type) (proposal_object_type) @@ -532,7 +528,7 @@ FC_REFLECT( graphene::chain::fee_schedule_type, (witness_withdraw_pay_fee) (transfer_fee) (limit_order_fee) - (short_order_fee) + (call_order_fee) (publish_feed_fee) (asset_create_fee) (asset_update_fee) @@ -587,7 +583,6 @@ FC_REFLECT_TYPENAME( graphene::chain::force_settlement_id_type ) FC_REFLECT_TYPENAME( graphene::chain::delegate_id_type ) FC_REFLECT_TYPENAME( graphene::chain::witness_id_type ) FC_REFLECT_TYPENAME( graphene::chain::limit_order_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::short_order_id_type ) FC_REFLECT_TYPENAME( graphene::chain::call_order_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_id_type ) FC_REFLECT_TYPENAME( graphene::chain::proposal_id_type ) diff --git a/libraries/chain/operations.cpp b/libraries/chain/operations.cpp index c08027e2..ce9c2942 100644 --- a/libraries/chain/operations.cpp +++ b/libraries/chain/operations.cpp @@ -393,37 +393,6 @@ share_type limit_order_cancel_operation::calculate_fee(const fee_schedule_type& return k.limit_order_fee; } -void short_order_create_operation::get_required_auth(flat_set& active_auth_set, flat_set&) const -{ - active_auth_set.insert(seller); -} - -void short_order_create_operation::validate()const -{ - FC_ASSERT( fee.amount >= 0 ); - FC_ASSERT( initial_collateral_ratio >= GRAPHENE_MIN_COLLATERAL_RATIO ); - FC_ASSERT( initial_collateral_ratio > maintenance_collateral_ratio ); - FC_ASSERT( initial_collateral_ratio <= GRAPHENE_MAX_COLLATERAL_RATIO ); -} - -share_type short_order_create_operation::calculate_fee(const fee_schedule_type& k) const -{ - return k.short_order_fee; -} -void short_order_cancel_operation::get_required_auth(flat_set& active_auth_set, flat_set&) const -{ - active_auth_set.insert(fee_paying_account); -} - -void short_order_cancel_operation::validate()const -{ - FC_ASSERT( fee.amount >= 0 ); -} - -share_type short_order_cancel_operation::calculate_fee(const fee_schedule_type& k) const -{ - return k.short_order_fee; -} void call_order_update_operation::get_required_auth(flat_set& active_auth_set, flat_set&) const { @@ -433,18 +402,13 @@ void call_order_update_operation::get_required_auth(flat_set& a void call_order_update_operation::validate()const { FC_ASSERT( fee.amount >= 0 ); - FC_ASSERT( collateral_to_add.amount > 0 || amount_to_cover.amount > 0 || maintenance_collateral_ratio > 0 ); - if( amount_to_cover.amount == 0 ) FC_ASSERT( collateral_to_add.amount >= 0 ); - if( collateral_to_add.amount.value <= 0 ) FC_ASSERT( amount_to_cover.amount.value > 0 ); - - FC_ASSERT( amount_to_cover.amount >= 0 ); FC_ASSERT( amount_to_cover.asset_id != collateral_to_add.asset_id ); FC_ASSERT( maintenance_collateral_ratio == 0 || maintenance_collateral_ratio >= 1000 ); } share_type call_order_update_operation::calculate_fee(const fee_schedule_type& k) const { - return k.short_order_fee; + return k.call_order_fee; } proposal_create_operation proposal_create_operation::genesis_proposal(const database& db) diff --git a/libraries/chain/short_order_evaluator.cpp b/libraries/chain/short_order_evaluator.cpp index ab05611a..743fe634 100644 --- a/libraries/chain/short_order_evaluator.cpp +++ b/libraries/chain/short_order_evaluator.cpp @@ -23,139 +23,6 @@ #include namespace graphene { namespace chain { -object_id_type short_order_create_evaluator::do_evaluate( const short_order_create_operation& op ) -{ - database& d = db(); - - FC_ASSERT( op.expiration >= d.head_block_time() ); - - const asset_object& base_asset = op.amount_to_sell.asset_id(d); - const asset_object& quote_asset = op.collateral.asset_id(d); - - FC_ASSERT( base_asset.is_market_issued() ); - FC_ASSERT( quote_asset.id == base_asset.bitasset_data(d).options.short_backing_asset ); - _seller = fee_paying_account; - _receive_asset = "e_asset; - _sell_asset = &base_asset; - - - FC_ASSERT( !(base_asset.options.flags & white_list) || _seller->is_authorized_asset(base_asset) ); - FC_ASSERT( !(quote_asset.options.flags & white_list) || _seller->is_authorized_asset(quote_asset) ); - - const asset_bitasset_data_object& bitasset_data = _sell_asset->bitasset_data(d); - if( bitasset_data.is_prediction_market ) - { - FC_ASSERT( op.initial_collateral_ratio == 0 ); - FC_ASSERT( op.maintenance_collateral_ratio == 0 ); - auto p = op.sell_price(); - - // the maximum price is 1:1, it does not make sense to charge more than - // the collateral backing the position. - FC_ASSERT( p.base.amount < p.quote.amount ); - } - else - { - FC_ASSERT( op.initial_collateral_ratio >= bitasset_data.current_feed.required_initial_collateral ); - FC_ASSERT( op.maintenance_collateral_ratio >= bitasset_data.current_feed.required_maintenance_collateral ); - FC_ASSERT( op.sell_price() >= bitasset_data.current_feed.short_limit ); - } - - return object_id_type(); -} - -object_id_type short_order_create_evaluator::do_apply( const short_order_create_operation& op ) -{ - db().adjust_balance(op.seller, -op.collateral); - - const auto& new_order_object = db().create( [&]( short_order_object& obj ){ - obj.seller = _seller->id; - obj.for_sale = op.amount_to_sell.amount; - obj.available_collateral = op.collateral.amount; - obj.sell_price = op.sell_price(); - obj.call_price = op.call_price(); - obj.initial_collateral_ratio = op.initial_collateral_ratio; - obj.maintenance_collateral_ratio = op.maintenance_collateral_ratio; - obj.expiration = op.expiration; - }); - short_order_id_type new_id = new_order_object.id; - - if( op.collateral.asset_id == asset_id_type() ) - { - auto& bal_obj = fee_paying_account->statistics(db()); - db().modify( bal_obj, [&]( account_statistics_object& obj ){ - obj.total_core_in_orders += op.collateral.amount; - }); - } - - // Possible optimization: We only need to check calls if both are true: - // - The new order is at the front of the book - // - The new order is below the call limit price - db().check_call_orders(*_sell_asset); - - if( !db().find(new_id) ) // then we were filled by call order - return new_id; - - const auto& limit_order_idx = db().get_index_type(); - const auto& limit_price_idx = limit_order_idx.indices().get(); - - auto min_limit_price = ~op.sell_price(); - - auto itr = limit_price_idx.lower_bound( min_limit_price.max() ); - auto end = limit_price_idx.upper_bound( min_limit_price ); - - while( itr != end ) - { - auto old_itr = itr; - ++itr; - if( db().match( *old_itr, new_order_object, old_itr->sell_price ) != 1 ) - break; // 1 means ONLY old iter filled - } - - //Possible optimization: only check calls if the new order completely filled some old order - //Do I need to check both assets? - db().check_call_orders(*_sell_asset); - db().check_call_orders(*_receive_asset); - - return new_id; -} // short_order_evaluator::do_apply - - -asset short_order_cancel_evaluator::do_evaluate( const short_order_cancel_operation& o ) -{ - database& d = db(); - - _order = &o.order(d); - FC_ASSERT( _order->seller == o.fee_paying_account ); - - return _order->get_collateral(); -} - -asset short_order_cancel_evaluator::do_apply( const short_order_cancel_operation& o ) -{ - database& d = db(); - - auto refunded = _order->get_collateral(); - d.adjust_balance(o.fee_paying_account, refunded); - auto base_asset = _order->sell_price.base.asset_id; - auto quote_asset = _order->sell_price.quote.asset_id; - - d.remove( *_order ); - - if( refunded.asset_id == asset_id_type() ) - { - auto& stats_obj = fee_paying_account->statistics(d); - d.modify( stats_obj, [&]( account_statistics_object& obj ){ - obj.total_core_in_orders -= refunded.amount; - }); - } - - // Possible optimization: order can be called by canceling a short order iff the canceled order was at the top of the book. - // Do I need to check calls in both assets? - db().check_call_orders(base_asset(d)); - db().check_call_orders(quote_asset(d)); - - return refunded; -} asset call_order_update_evaluator::do_evaluate(const call_order_update_operation& o) { try { @@ -164,101 +31,104 @@ asset call_order_update_evaluator::do_evaluate(const call_order_update_operation _paying_account = &o.funding_account(d); _debt_asset = &o.amount_to_cover.asset_id(d); - const asset_bitasset_data_object& bitasset_data = _debt_asset->bitasset_data(d); - FC_ASSERT( _debt_asset->is_market_issued(), "Unable to cover ${sym} as it is not a market-issued asset.", + _bitasset_data = &_debt_asset->bitasset_data(d); + FC_ASSERT( _debt_asset->is_market_issued(), "Unable to cover ${sym} as it is not a collateralized asset.", ("sym", _debt_asset->symbol) ); - FC_ASSERT( o.collateral_to_add.asset_id == bitasset_data.options.short_backing_asset ); + FC_ASSERT( o.collateral_to_add.asset_id == _bitasset_data->options.short_backing_asset ); - if( bitasset_data.is_prediction_market ) + if( _bitasset_data->is_prediction_market ) { - FC_ASSERT( o.collateral_to_add.amount <= 0 ); - FC_ASSERT( -o.collateral_to_add.amount == o.amount_to_cover.amount ); + FC_ASSERT( o.collateral_to_add.amount == -o.amount_to_cover.amount ); FC_ASSERT( o.maintenance_collateral_ratio == 0 ); } else { FC_ASSERT( o.maintenance_collateral_ratio == 0 || - o.maintenance_collateral_ratio > bitasset_data.current_feed.required_maintenance_collateral ); + o.maintenance_collateral_ratio > _bitasset_data->current_feed.required_maintenance_collateral ); } - FC_ASSERT( d.get_balance(*_paying_account, *_debt_asset) >= o.amount_to_cover, - "Cannot cover by ${c} when payer has ${b}", - ("c", o.amount_to_cover.amount)("b", d.get_balance(*_paying_account, *_debt_asset).amount) ); - FC_ASSERT( d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)) >= o.collateral_to_add, - "Cannot increase collateral by ${c} when payer has ${b}", ("c", o.amount_to_cover.amount) - ("b", d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)).amount) ); - - auto& call_idx = d.get_index_type().indices().get(); - auto itr = call_idx.find( boost::make_tuple(o.funding_account, o.amount_to_cover.asset_id) ); - FC_ASSERT( itr != call_idx.end(), "Could not find call order for ${sym} belonging to ${acct}.", - ("sym", _debt_asset->symbol)("acct", _paying_account->name) ); - _order = &*itr; - - FC_ASSERT( o.amount_to_cover.asset_id == _order->debt_type() ); - - FC_ASSERT( o.amount_to_cover.amount <= _order->get_debt().amount ); - - if( o.amount_to_cover.amount < _order->get_debt().amount ) + if( o.amount_to_cover > 0 ) { - FC_ASSERT( (_order->get_debt() - o.amount_to_cover) * - price::call_price(_order->get_debt() - o.amount_to_cover, - _order->get_collateral() + o.collateral_to_add, - o.maintenance_collateral_ratio? o.maintenance_collateral_ratio - : _order->maintenance_collateral_ratio) - < _order->get_collateral(), - "Order would be called immediately following this update. Refusing to apply update." ); - FC_ASSERT( o.amount_to_cover < _order->get_debt(), "Cover amount is greater than debt." ); - } else { - _closing_order = true; - FC_ASSERT( o.collateral_to_add.amount == -_order->get_collateral().amount, "", - ("collateral", _order->get_collateral()) ); - return _order->get_collateral(); + FC_ASSERT( d.get_balance(*_paying_account, *_debt_asset) >= o.amount_to_cover, + "Cannot cover by ${c} when payer only has ${b}", + ("c", o.amount_to_cover.amount)("b", d.get_balance(*_paying_account, *_debt_asset).amount) ); } + if( o.collateral_to_add > 0 ) + { + FC_ASSERT( d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)) >= o.collateral_to_add, + "Cannot increase collateral by ${c} when payer only has ${b}", ("c", o.amount_to_cover.amount) + ("b", d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)).amount) ); + } + return asset(); } FC_CAPTURE_AND_RETHROW( (o) ) } + asset call_order_update_evaluator::do_apply(const call_order_update_operation& o) { database& d = db(); + asset collateral_returned = -o.collateral_to_add; - d.adjust_balance(_paying_account->get_id(), -o.amount_to_cover); + d.adjust_balance( o.funding_account, -o.amount_to_cover); + d.adjust_balance( o.funding_account, -o.collateral_to_add); // Deduct the debt paid from the total supply of the debt asset. - d.modify(_debt_asset->dynamic_asset_data_id(d), [&](asset_dynamic_data_object& dynamic_asset) { - dynamic_asset.current_supply -= o.amount_to_cover.amount; - assert(dynamic_asset.current_supply >= 0); - }); - - asset collateral_returned; - if( _closing_order ) + if( o.amount_to_cover != 0 ) { - collateral_returned = _order->get_collateral(); - // Credit the account's balances for his returned collateral. - d.adjust_balance(_paying_account->get_id(), collateral_returned); - d.modify(_paying_account->statistics(d), [&](account_statistics_object& stats) { - if( _order->get_collateral().asset_id == asset_id_type() ) - stats.total_core_in_orders -= collateral_returned.amount; + d.modify(_debt_asset->dynamic_asset_data_id(d), [&](asset_dynamic_data_object& dynamic_asset) { + dynamic_asset.current_supply -= o.amount_to_cover.amount; + assert(dynamic_asset.current_supply >= 0); }); - // Remove the call order. - d.remove(*_order); - } else { - // Update the call order. - d.modify(*_order, [&o](call_order_object& call) { - call.debt -= o.amount_to_cover.amount; - call.collateral += o.collateral_to_add.amount; - if( o.maintenance_collateral_ratio ) - call.maintenance_collateral_ratio = o.maintenance_collateral_ratio; - call.update_call_price(); - }); - if( o.collateral_to_add.amount > 0 ) - // Deduct the added collateral from the account. - d.adjust_balance(_paying_account->get_id(), -o.collateral_to_add); - d.modify(_paying_account->statistics(d), [&](account_statistics_object& stats) { - if( o.collateral_to_add.asset_id == asset_id_type() ) - stats.total_core_in_orders += o.collateral_to_add.amount; - }); } + auto& call_idx = d.get_index_type().indices().get(); + auto itr = call_idx.find( boost::make_tuple(o.funding_account, o.amount_to_cover.asset_id) ); + if( itr == call_idx.end() ) + { + FC_ASSERT( o.collateral_to_add.amount > 0 ); + FC_ASSERT( o.amount_to_cover.amount < 0 ); + d.create( [&](call_order_object& call ){ + call.owner = o.funding_account; + call.collateral = o.collateral_to_add.amount; + call.debt = -o.amount_to_cover.amount; + call.maintenance_collateral_ratio = o.maintenance_collateral_ratio; + // TODO: this is only necessary for non-prediction markets + call.update_call_price(); + FC_ASSERT( call.call_price < _bitasset_data->current_feed.settlement_price ); + }); + } + else + { + if( itr->debt - o.amount_to_cover == 0 ) + { + FC_ASSERT( o.collateral_to_add == 0 ); + collateral_returned = itr->get_collateral(); + d.adjust_balance( o.funding_account, call. + d.remove( *itr ); + } + else + { + FC_ASSERT( (itr->debt - o.amount_to_cover.amount) >= 0 ); + FC_ASSERT( (itr->collateral + o.collateral_to_add.amount) >= 0 ); + + d.modify( *itr, [&]( call_order_object& call ){ + call.collateral += o.collateral_to_add.amount; + call.debt -= o.amount_to_cover.amount; + if( o.maintenance_collateral_ratio ) + call.maintenance_collateral_ratio = o.maintenance_collateral_ratio; + + // TODO: this is only necessary for non-prediction markets + call.update_call_price(); + FC_ASSERT( call.call_price < _bitasset_data->current_feed.settlement_price ); + }); + } + } + if( collateral_returned.asset_id == asset_id_type() && collateral_returned.amount != 0 ) + { + d.modify(_paying_account->statistics(d), [&](account_statistics_object& stats) { + stats.total_core_in_orders -= collateral_returned.amount; + }); + } return collateral_returned; } From 4ca3bb9f065bc5a3f7e984dac0cd9c2adbad6628 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 09:53:40 -0400 Subject: [PATCH 2/5] rename short to call --- .../{short_order_evaluator.cpp => call_order_evaluator.cpp} | 0 .../{short_order_evaluator.hpp => call_order_evaluator.hpp} | 0 .../chain/{short_order_object.hpp => call_order_object.hpp} | 1 - 3 files changed, 1 deletion(-) rename libraries/chain/{short_order_evaluator.cpp => call_order_evaluator.cpp} (100%) rename libraries/chain/include/graphene/chain/{short_order_evaluator.hpp => call_order_evaluator.hpp} (100%) rename libraries/chain/include/graphene/chain/{short_order_object.hpp => call_order_object.hpp} (98%) diff --git a/libraries/chain/short_order_evaluator.cpp b/libraries/chain/call_order_evaluator.cpp similarity index 100% rename from libraries/chain/short_order_evaluator.cpp rename to libraries/chain/call_order_evaluator.cpp diff --git a/libraries/chain/include/graphene/chain/short_order_evaluator.hpp b/libraries/chain/include/graphene/chain/call_order_evaluator.hpp similarity index 100% rename from libraries/chain/include/graphene/chain/short_order_evaluator.hpp rename to libraries/chain/include/graphene/chain/call_order_evaluator.hpp diff --git a/libraries/chain/include/graphene/chain/short_order_object.hpp b/libraries/chain/include/graphene/chain/call_order_object.hpp similarity index 98% rename from libraries/chain/include/graphene/chain/short_order_object.hpp rename to libraries/chain/include/graphene/chain/call_order_object.hpp index 1036b743..5c1f8b67 100644 --- a/libraries/chain/include/graphene/chain/short_order_object.hpp +++ b/libraries/chain/include/graphene/chain/call_order_object.hpp @@ -120,7 +120,6 @@ namespace graphene { namespace chain { > force_settlement_object_multi_index_type; - typedef generic_index short_order_index; typedef generic_index call_order_index; typedef generic_index force_settlement_index; } } // graphene::chain From 663036f2aa98ef650f31cf0afaaf115e235f5a4e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 10:14:10 -0400 Subject: [PATCH 3/5] it builds --- libraries/chain/CMakeLists.txt | 2 +- libraries/chain/asset.cpp | 11 +- libraries/chain/asset_evaluator.cpp | 2 +- libraries/chain/call_order_evaluator.cpp | 22 +-- libraries/chain/db_debug.cpp | 9 +- libraries/chain/db_init.cpp | 7 +- libraries/chain/db_market.cpp | 148 +----------------- libraries/chain/db_update.cpp | 12 +- libraries/chain/evaluator.cpp | 2 +- .../graphene/chain/call_order_evaluator.hpp | 2 +- .../graphene/chain/call_order_object.hpp | 4 +- .../chain/include/graphene/chain/database.hpp | 2 - libraries/chain/limit_order_evaluator.cpp | 42 +---- 13 files changed, 35 insertions(+), 230 deletions(-) diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 17635897..100fd8a3 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -16,7 +16,7 @@ add_library( graphene_chain asset_evaluator.cpp transfer_evaluator.cpp proposal_evaluator.cpp - short_order_evaluator.cpp + call_order_evaluator.cpp limit_order_evaluator.cpp vesting_balance_evaluator.cpp withdraw_permission_evaluator.cpp diff --git a/libraries/chain/asset.cpp b/libraries/chain/asset.cpp index cb1f6fdb..bb36910d 100644 --- a/libraries/chain/asset.cpp +++ b/libraries/chain/asset.cpp @@ -122,18 +122,11 @@ namespace graphene { namespace chain { { try { if( !call_limit.is_null() ) call_limit.validate(); - if( !short_limit.is_null() ) - short_limit.validate(); if( !settlement_price.is_null() ) settlement_price.validate(); - FC_ASSERT( call_limit.is_null() == short_limit.is_null() ); - FC_ASSERT( call_limit.base.asset_id == short_limit.quote.asset_id ); - FC_ASSERT( call_limit.quote.asset_id == short_limit.base.asset_id ); FC_ASSERT( max_margin_period_sec > 0 ); - FC_ASSERT( required_maintenance_collateral < required_initial_collateral ); FC_ASSERT( required_maintenance_collateral >= 1000 ); - FC_ASSERT( call_limit.is_null() || call_limit < ~short_limit ); - } FC_CAPTURE_AND_RETHROW( (call_limit.is_null())(short_limit.is_null())(call_limit)(short_limit) - (max_margin_period_sec)(required_maintenance_collateral)(required_initial_collateral) ) } + } FC_CAPTURE_AND_RETHROW( (call_limit.is_null())(call_limit) + (max_margin_period_sec)(required_maintenance_collateral) ) } } } // graphene::chain diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 096d05db..1bda2aed 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/libraries/chain/call_order_evaluator.cpp b/libraries/chain/call_order_evaluator.cpp index 743fe634..45005365 100644 --- a/libraries/chain/call_order_evaluator.cpp +++ b/libraries/chain/call_order_evaluator.cpp @@ -16,9 +16,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include +#include #include -#include +#include #include #include @@ -47,17 +47,17 @@ asset call_order_update_evaluator::do_evaluate(const call_order_update_operation o.maintenance_collateral_ratio > _bitasset_data->current_feed.required_maintenance_collateral ); } - if( o.amount_to_cover > 0 ) + if( o.amount_to_cover.amount > 0 ) { FC_ASSERT( d.get_balance(*_paying_account, *_debt_asset) >= o.amount_to_cover, "Cannot cover by ${c} when payer only has ${b}", ("c", o.amount_to_cover.amount)("b", d.get_balance(*_paying_account, *_debt_asset).amount) ); } - if( o.collateral_to_add > 0 ) + if( o.collateral_to_add.amount > 0 ) { - FC_ASSERT( d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)) >= o.collateral_to_add, + FC_ASSERT( d.get_balance(*_paying_account, _bitasset_data->options.short_backing_asset(d)) >= o.collateral_to_add, "Cannot increase collateral by ${c} when payer only has ${b}", ("c", o.amount_to_cover.amount) - ("b", d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)).amount) ); + ("b", d.get_balance(*_paying_account, _bitasset_data->options.short_backing_asset(d)).amount) ); } return asset(); @@ -73,7 +73,7 @@ asset call_order_update_evaluator::do_apply(const call_order_update_operation& o d.adjust_balance( o.funding_account, -o.collateral_to_add); // Deduct the debt paid from the total supply of the debt asset. - if( o.amount_to_cover != 0 ) + if( o.amount_to_cover.amount != 0 ) { d.modify(_debt_asset->dynamic_asset_data_id(d), [&](asset_dynamic_data_object& dynamic_asset) { dynamic_asset.current_supply -= o.amount_to_cover.amount; @@ -88,7 +88,7 @@ asset call_order_update_evaluator::do_apply(const call_order_update_operation& o FC_ASSERT( o.collateral_to_add.amount > 0 ); FC_ASSERT( o.amount_to_cover.amount < 0 ); d.create( [&](call_order_object& call ){ - call.owner = o.funding_account; + call.borrower = o.funding_account; call.collateral = o.collateral_to_add.amount; call.debt = -o.amount_to_cover.amount; call.maintenance_collateral_ratio = o.maintenance_collateral_ratio; @@ -99,11 +99,11 @@ asset call_order_update_evaluator::do_apply(const call_order_update_operation& o } else { - if( itr->debt - o.amount_to_cover == 0 ) + if( itr->debt - o.amount_to_cover.amount == 0 ) { - FC_ASSERT( o.collateral_to_add == 0 ); + FC_ASSERT( o.collateral_to_add.amount == 0 ); collateral_returned = itr->get_collateral(); - d.adjust_balance( o.funding_account, call. + d.adjust_balance( o.funding_account, collateral_returned ); d.remove( *itr ); } else diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index d7d8f4e0..34f12b58 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -60,13 +60,6 @@ void database::debug_dump() if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; total_balances[for_sale.asset_id] += for_sale.amount; } - for( const short_order_object& o : db.get_index_type().indices() ) - { - idump(("short_order")(o)); - auto col = o.get_collateral(); - if( col.asset_id == asset_id_type() ) core_in_orders += col.amount; - total_balances[col.asset_id] += col.amount; - } for( const call_order_object& o : db.get_index_type().indices() ) { idump(("call_order")(o)); diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 57c3cd37..f4ae2196 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -75,8 +75,6 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); - register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); @@ -108,7 +106,6 @@ void database::initialize_indexes() add_index< primary_index> >(); add_index< primary_index> >(); add_index< primary_index >(); - add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 22fb778d..0ffb9d31 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include @@ -225,10 +225,6 @@ int database::match( const limit_order_object& bid, const limit_order_object& as return match( bid, ask, match_price ); } -int database::match( const limit_order_object& bid, const short_order_object& ask, const price& match_price ) -{ - return match( bid, ask, match_price ); -} asset database::match( const call_order_object& call, const force_settlement_object& settle, const price& match_price, asset max_settlement ) @@ -290,107 +286,6 @@ bool database::fill_order( const limit_order_object& order, const asset& pays, c } } -bool database::fill_order( const short_order_object& order, const asset& pays, const asset& receives ) -{ try { - assert( order.amount_for_sale().asset_id == pays.asset_id ); - assert( pays.asset_id != receives.asset_id ); - - const call_order_index& call_index = get_index_type(); - - const account_object& seller = order.seller(*this); - const asset_object& recv_asset = receives.asset_id(*this); - const asset_object& pays_asset = pays.asset_id(*this); - assert( pays_asset.is_market_issued() ); - - auto issuer_fees = pay_market_fees( recv_asset, receives ); - - bool filled = pays == order.amount_for_sale(); - asset seller_to_collateral; - if( (*pays_asset.bitasset_data_id)(*this).is_prediction_market ) - { - assert( pays.amount >= receives.amount ); - seller_to_collateral = pays.amount - receives.amount; - } - else - { - seller_to_collateral = filled ? order.get_collateral() : pays * order.sell_price; - } - auto buyer_to_collateral = receives - issuer_fees; - - if( receives.asset_id == asset_id_type() ) - { - const auto& statistics = seller.statistics(*this); - modify( statistics, [&]( account_statistics_object& b ){ - b.total_core_in_orders += buyer_to_collateral.amount; - }); - } - - modify( pays_asset.dynamic_asset_data_id(*this), [&]( asset_dynamic_data_object& obj ){ - obj.current_supply += pays.amount; - }); - - const auto& call_account_index = call_index.indices().get(); - auto call_itr = call_account_index.find( boost::make_tuple(order.seller, pays.asset_id) ); - if( call_itr == call_account_index.end() ) - { - create( [&]( call_order_object& c ){ - c.borrower = seller.id; - c.collateral = seller_to_collateral.amount + buyer_to_collateral.amount; - c.debt = pays.amount; - c.maintenance_collateral_ratio = order.maintenance_collateral_ratio; - c.call_price = price::max(seller_to_collateral.asset_id, pays.asset_id); - c.update_call_price(); - }); - } - else - { - modify( *call_itr, [&]( call_order_object& c ){ - c.debt += pays.amount; - c.collateral += seller_to_collateral.amount + buyer_to_collateral.amount; - c.maintenance_collateral_ratio = order.maintenance_collateral_ratio; - c.update_call_price(); - }); - } - - if( filled ) - { - remove( order ); - } - else - { - modify( order, [&]( short_order_object& b ) { - b.for_sale -= pays.amount; - b.available_collateral -= seller_to_collateral.amount; - assert( b.available_collateral > 0 ); - assert( b.for_sale > 0 ); - }); - - /** - * There are times when the AMOUNT_FOR_SALE * SALE_PRICE == 0 which means that we - * have hit the limit where the seller is asking for nothing in return. When this - * happens we must refund any balance back to the seller, it is too small to be - * sold at the sale price. - */ - if( order.amount_to_receive().amount == 0 ) - { - adjust_balance(seller.get_id(), order.get_collateral()); - if( order.get_collateral().asset_id == asset_id_type() ) - { - const auto& statistics = seller.statistics(*this); - modify( statistics, [&]( account_statistics_object& b ){ - b.total_core_in_orders -= order.available_collateral; - }); - } - - remove( order ); - filled = true; - } - } - - push_applied_operation( fill_order_operation{ order.id, order.seller, pays, receives, issuer_fees } ); - - return filled; -} FC_CAPTURE_AND_RETHROW( (order)(pays)(receives) ) } bool database::fill_order( const call_order_object& order, const asset& pays, const asset& receives ) { try { @@ -483,11 +378,6 @@ bool database::check_call_orders( const asset_object& mia ) const limit_order_index& limit_index = get_index_type(); const auto& limit_price_index = limit_index.indices().get(); - const short_order_index& short_index = get_index_type(); - const auto& short_price_index = short_index.indices().get(); - - auto short_itr = short_price_index.lower_bound( price::max( mia.id, bitasset.options.short_backing_asset ) ); - auto short_end = short_price_index.upper_bound( ~bitasset.current_feed.call_limit ); auto limit_itr = limit_price_index.lower_bound( price::max( mia.id, bitasset.options.short_backing_asset ) ); auto limit_end = limit_price_index.upper_bound( ~bitasset.current_feed.call_limit ); @@ -499,33 +389,14 @@ bool database::check_call_orders( const asset_object& mia ) while( call_itr != call_end ) { - bool current_is_limit = true; bool filled_call = false; price match_price; asset usd_for_sale; if( limit_itr != limit_end ) { assert( limit_itr != limit_price_index.end() ); - if( short_itr != short_end && limit_itr->sell_price < short_itr->sell_price ) - { - assert( short_itr != short_price_index.end() ); - current_is_limit = false; - match_price = short_itr->sell_price; - usd_for_sale = short_itr->amount_for_sale(); - } - else - { - current_is_limit = true; - match_price = limit_itr->sell_price; - usd_for_sale = limit_itr->amount_for_sale(); - } - } - else if( short_itr != short_end ) - { - assert( short_itr != short_price_index.end() ); - current_is_limit = false; - match_price = short_itr->sell_price; - usd_for_sale = short_itr->amount_for_sale(); + match_price = limit_itr->sell_price; + usd_for_sale = limit_itr->amount_for_sale(); } else return filled_short_or_limit; @@ -569,16 +440,9 @@ bool database::check_call_orders( const asset_object& mia ) auto old_call_itr = call_itr; if( filled_call ) ++call_itr; fill_order( *old_call_itr, call_pays, call_receives ); - if( current_is_limit ) - { - auto old_limit_itr = !filled_call ? limit_itr++ : limit_itr; - fill_order( *old_limit_itr, order_pays, order_receives ); - } - else - { - auto old_short_itr = !filled_call ? short_itr++ : short_itr; - fill_order( *old_short_itr, order_pays, order_receives ); - } + + auto old_limit_itr = !filled_call ? limit_itr++ : limit_itr; + fill_order( *old_limit_itr, order_pays, order_receives ); } // whlie call_itr != call_end return filled_short_or_limit; diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 1ba5b95e..cd4dc03c 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -131,16 +131,6 @@ void database::clear_expired_orders() apply_operation(cancel_context, canceler); } - //Cancel expired short orders - auto& short_index = get_index_type().indices().get(); - while( !short_index.empty() && short_index.begin()->expiration <= head_block_time() ) - { - const short_order_object& order = *short_index.begin(); - short_order_cancel_operation canceler; - canceler.fee_paying_account = order.seller; - canceler.order = order.id; - apply_operation(cancel_context, canceler); - } //Process expired force settlement orders auto& settlement_index = get_index_type().indices().get(); diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 46117211..61803be7 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include diff --git a/libraries/chain/include/graphene/chain/call_order_evaluator.hpp b/libraries/chain/include/graphene/chain/call_order_evaluator.hpp index 485424fb..d7d6cc0c 100644 --- a/libraries/chain/include/graphene/chain/call_order_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/call_order_evaluator.hpp @@ -34,7 +34,7 @@ namespace graphene { namespace chain { const asset_object* _debt_asset = nullptr; const account_object* _paying_account = nullptr; const call_order_object* _order = nullptr; - const bitasset_data_object* _bitasset_data = nullptr; + const asset_bitasset_data_object* _bitasset_data = nullptr; }; } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/call_order_object.hpp b/libraries/chain/include/graphene/chain/call_order_object.hpp index 5c1f8b67..becbc781 100644 --- a/libraries/chain/include/graphene/chain/call_order_object.hpp +++ b/libraries/chain/include/graphene/chain/call_order_object.hpp @@ -74,6 +74,9 @@ namespace graphene { namespace chain { { return balance.asset_id; } }; + struct by_collateral; + struct by_account; + struct by_price; typedef multi_index_container< call_order_object, indexed_by< @@ -101,7 +104,6 @@ namespace graphene { namespace chain { > > call_order_multi_index_type; - struct by_account; struct by_expiration; typedef multi_index_container< force_settlement_object, diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 469a78ad..ba6a3a14 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -281,7 +281,6 @@ namespace graphene { namespace chain { template int match( const limit_order_object& bid, const OrderType& ask, const price& match_price ); int match( const limit_order_object& bid, const limit_order_object& ask, const price& trade_price ); - int match( const limit_order_object& bid, const short_order_object& ask, const price& trade_price ); /// @return the amount of asset settled asset match(const call_order_object& call, const force_settlement_object& settle, @@ -293,7 +292,6 @@ namespace graphene { namespace chain { * @return true if the order was completely filled and thus freed. */ bool fill_order( const limit_order_object& order, const asset& pays, const asset& receives ); - bool fill_order( const short_order_object& order, const asset& pays, const asset& receives ); bool fill_order( const call_order_object& order, const asset& pays, const asset& receives ); bool fill_order( const force_settlement_object& settle, const asset& pays, const asset& receives ); diff --git a/libraries/chain/limit_order_evaluator.cpp b/libraries/chain/limit_order_evaluator.cpp index d3429567..0e8a0d2e 100644 --- a/libraries/chain/limit_order_evaluator.cpp +++ b/libraries/chain/limit_order_evaluator.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace graphene { namespace chain { @@ -104,44 +103,13 @@ object_id_type limit_order_create_evaluator::do_apply( const limit_order_create_ if( converted_some && !db().find(result) ) // then we were filled by call order return result; } - const auto& short_order_idx = db().get_index_type(); - const auto& sell_price_idx = short_order_idx.indices().get(); - - FC_ASSERT( max_price.max() >= max_price ); - auto short_itr = sell_price_idx.lower_bound( max_price.max() ); - auto short_end = sell_price_idx.upper_bound( max_price ); - - while( !filled ) - { - if( limit_itr != limit_end ) - { - if( short_itr != short_end && limit_itr->sell_price < short_itr->sell_price ) - { - auto old_short_itr = short_itr; - ++short_itr; - filled = (db().match( new_order_object, *old_short_itr, old_short_itr->sell_price ) != 2 ); - } - else - { - auto old_limit_itr = limit_itr; - ++limit_itr; - filled = (db().match( new_order_object, *old_limit_itr, old_limit_itr->sell_price ) != 2 ); - } - } - else if( short_itr != short_end ) - { - auto old_short_itr = short_itr; - ++short_itr; - filled = (db().match( new_order_object, *old_short_itr, old_short_itr->sell_price ) != 2 ); - } - else break; - } } - else while( !filled && limit_itr != limit_end ) + + while( !filled && limit_itr != limit_end ) { - auto old_itr = limit_itr; - ++limit_itr; - filled = (db().match( new_order_object, *old_itr, old_itr->sell_price ) != 2); + auto old_limit_itr = limit_itr; + ++limit_itr; + filled = (db().match( new_order_object, *old_limit_itr, old_limit_itr->sell_price ) != 2 ); } //Possible optimization: only check calls if the new order completely filled some old order From 4cee2ca608f3accdf04eceea174fe7937da35e71 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 11:22:28 -0400 Subject: [PATCH 4/5] Update plugins and wallet to remove shorts --- libraries/app/api.cpp | 20 -------- libraries/app/include/graphene/app/api.hpp | 10 +--- .../account_history_plugin.cpp | 2 - libraries/wallet/cache.cpp | 4 +- .../wallet/include/graphene/wallet/wallet.hpp | 10 ++-- libraries/wallet/wallet.cpp | 46 +++++-------------- 6 files changed, 20 insertions(+), 72 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 98d25611..241678b3 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -215,22 +215,6 @@ namespace graphene { namespace app { return result; } - vector database_api::get_short_orders(asset_id_type a, uint32_t limit)const - { - const auto& short_order_idx = _db.get_index_type(); - const auto& sell_price_idx = short_order_idx.indices().get(); - const asset_object& mia = _db.get(a); - - FC_ASSERT( mia.is_market_issued(), "must be a market issued asset" ); - - price index_price = price::min(mia.get_id(), mia.bitasset_data(_db).options.short_backing_asset); - - auto short_itr = sell_price_idx.lower_bound(index_price.max()); - auto short_end = sell_price_idx.upper_bound(index_price.min()); - - return vector(short_itr, short_end); - } - vector database_api::get_call_orders(asset_id_type a, uint32_t limit)const { const auto& call_index = _db.get_index_type().indices().get(); @@ -358,15 +342,11 @@ namespace graphene { namespace app { case operation::tag::value: market = op.op.get().get_market(); break; - case operation::tag::value: - market = op.op.get().get_market(); - break; case operation::tag::value: market = op.op.get().get_market(); break; /* case operation::tag::value: - case operation::tag::value: */ default: break; } diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index e34f290c..e4729c3d 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -142,13 +142,6 @@ namespace graphene { namespace app { * @return The limit orders, ordered from least price to greatest */ vector get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; - /** - * @brief Get short orders in a given asset - * @param a ID of asset being sold - * @param limit Maximum number of orders to retrieve - * @return The short orders, ordered from least price to greatest - */ - vector get_short_orders(asset_id_type a, uint32_t limit)const; /** * @brief Get call orders in a given asset * @param a ID of asset being called @@ -342,7 +335,6 @@ FC_API(graphene::app::database_api, (get_named_account_balances) (lookup_asset_symbols) (get_limit_orders) - (get_short_orders) (get_call_orders) (get_settle_orders) (list_assets) diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index d8e1148e..0fd4fac5 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -141,9 +141,7 @@ struct operation_get_impacted_accounts } void operator()( const limit_order_create_operation& o )const { } - void operator()( const short_order_create_operation& o )const { } void operator()( const limit_order_cancel_operation& o )const { } - void operator()( const short_order_cancel_operation& o )const { } void operator()( const call_order_update_operation& o )const { } void operator()( const key_create_operation& o )const { } void operator()( const custom_operation& o )const { } diff --git a/libraries/wallet/cache.cpp b/libraries/wallet/cache.cpp index d5c3f382..18b1d7b0 100644 --- a/libraries/wallet/cache.cpp +++ b/libraries/wallet/cache.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,8 +72,6 @@ object* create_object( const variant& v ) return create_object_of_type< witness_object >( v ); case limit_order_object_type: return create_object_of_type< limit_order_object >( v ); - case short_order_object_type: - return create_object_of_type< short_order_object >( v ); case call_order_object_type: return create_object_of_type< call_order_object >( v ); /* diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index fc1f0a9f..3359e2b5 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -114,7 +114,6 @@ class wallet_api vector list_assets(const string& lowerbound, uint32_t limit)const; vector get_account_history(string name, int limit)const; vector get_limit_orders(string a, string b, uint32_t limit)const; - vector get_short_orders(string a, uint32_t limit)const; vector get_call_orders(string a, uint32_t limit)const; vector get_settle_orders(string a, uint32_t limit)const; global_property_object get_global_properties() const; @@ -204,7 +203,11 @@ class wallet_api bool fill_or_kill = false, bool broadcast = false); - signed_transaction short_sell_asset(string seller_name, string amount_to_sell, string asset_symbol, + /** + * This method will create a transaction with two operations, the first one will borrow amount_to_sell + * given amount of collateral + */ + signed_transaction borrow_asset(string seller_name, string amount_to_sell, string asset_symbol, string amount_of_collateral, bool broadcast = false); signed_transaction create_asset(string issuer, @@ -272,7 +275,7 @@ FC_API( graphene::wallet::wallet_api, (upgrade_account) (create_account_with_brain_key) (sell_asset) - (short_sell_asset) + (borrow_asset) (transfer) (create_asset) (issue_asset) @@ -289,7 +292,6 @@ FC_API( graphene::wallet::wallet_api, (load_wallet_file) (normalize_brain_key) (get_limit_orders) - (get_short_orders) (get_call_orders) (get_settle_orders) (save_wallet_file) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 2d0d6dec..9f2d255a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1011,7 +1011,7 @@ public: return sign_transaction( tx, broadcast ); } - signed_transaction short_sell_asset(string seller_name, string amount_to_sell, string asset_symbol, + signed_transaction borrow_asset(string seller_name, string amount_to_sell, string asset_symbol, string amount_of_collateral, bool broadcast = false) { account_object seller = get_account(seller_name); @@ -1019,11 +1019,10 @@ public: FC_ASSERT(mia.is_market_issued()); asset_object collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); - short_order_create_operation op; - op.seller = seller.id; - op.expiration = fc::time_point::now() + fc::days(365*10); - op.amount_to_sell = mia.amount_from_string(amount_to_sell); - op.collateral = collateral.amount_from_string(amount_of_collateral); + call_order_update_operation op; + op.funding_account = seller.id; + op.amount_to_cover = -mia.amount_from_string(amount_to_sell); + op.collateral_to_add = collateral.amount_from_string(amount_of_collateral); signed_transaction trx; trx.operations = {op}; @@ -1040,27 +1039,11 @@ public: FC_ASSERT(order_id.space() == protocol_ids, "Invalid order ID ${id}", ("id", order_id)); signed_transaction trx; - switch( order_id.type() ) - { - case short_order_object_type: { - short_order_cancel_operation op; - op.fee_paying_account = get_object(order_id).seller; - op.order = order_id; - op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees); - trx.operations = {op}; - break; - } - case limit_order_object_type: { - limit_order_cancel_operation op; - op.fee_paying_account = get_object(order_id).seller; - op.order = order_id; - op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees); - trx.operations = {op}; - break; - } - default: - FC_THROW("Invalid order ID ${id}", ("id", order_id)); - } + limit_order_cancel_operation op; + op.fee_paying_account = get_object(order_id).seller; + op.order = order_id; + op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees); + trx.operations = {op}; trx.validate(); return sign_transaction(trx, broadcast); @@ -1384,11 +1367,6 @@ vector wallet_api::get_limit_orders(string a, string b, uint return my->_remote_db->get_limit_orders(get_asset(a).id, get_asset(b).id, limit); } -vector wallet_api::get_short_orders(string a, uint32_t limit)const -{ - return my->_remote_db->get_short_orders(get_asset(a).id, limit); -} - vector wallet_api::get_call_orders(string a, uint32_t limit)const { return my->_remote_db->get_call_orders(get_asset(a).id, limit); @@ -1740,11 +1718,11 @@ signed_transaction wallet_api::sell_asset(string seller_account, symbol_to_receive, expiration, fill_or_kill, broadcast); } -signed_transaction wallet_api::short_sell_asset(string seller_name, string amount_to_sell, +signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell, string asset_symbol, string amount_of_collateral, bool broadcast) { FC_ASSERT(!is_locked()); - return my->short_sell_asset(seller_name, amount_to_sell, asset_symbol, amount_of_collateral, broadcast); + return my->borrow_asset(seller_name, amount_to_sell, asset_symbol, amount_of_collateral, broadcast); } } } From 2ae6ce9cdce9075bd12ee8a48497cb1bc193bed7 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 12:17:09 -0400 Subject: [PATCH 5/5] updating tests to remove references to short --- docs | 2 +- .../db/include/graphene/db/level_map.hpp | 1 + programs/js_operation_serializer/main.cpp | 2 +- tests/common/database_fixture.cpp | 113 +-- tests/common/database_fixture.hpp | 17 - tests/tests/block_tests.cpp | 52 +- tests/tests/operation_tests.cpp | 693 +----------------- tests/tests/operation_tests2.cpp | 19 +- 8 files changed, 39 insertions(+), 860 deletions(-) diff --git a/docs b/docs index 1b53a8ec..71ed2984 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 1b53a8eca77783d073ce7cc95991447c3f34b927 +Subproject commit 71ed2984b71d57cab13cdf12074cff150edc1d3d diff --git a/libraries/db/include/graphene/db/level_map.hpp b/libraries/db/include/graphene/db/level_map.hpp index 55ecb99b..ec9df5d1 100644 --- a/libraries/db/include/graphene/db/level_map.hpp +++ b/libraries/db/include/graphene/db/level_map.hpp @@ -45,6 +45,7 @@ namespace graphene { namespace db { public: void open( const fc::path& dir, bool create = true, size_t cache_size = 0 ) { try { + idump( (dir)(create)); FC_ASSERT( !is_open(), "Database is already open!" ); ldb::Options opts; diff --git a/programs/js_operation_serializer/main.cpp b/programs/js_operation_serializer/main.cpp index 21db9e66..eab7181c 100644 --- a/programs/js_operation_serializer/main.cpp +++ b/programs/js_operation_serializer/main.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 27d57445..fda2bc10 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -126,12 +126,6 @@ void database_fixture::verify_asset_supplies( )const if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; total_balances[for_sale.asset_id] += for_sale.amount; } - for( const short_order_object& o : db.get_index_type().indices() ) - { - asset col = o.get_collateral(); - if( col.asset_id == asset_id_type() ) core_in_orders += col.amount; - total_balances[col.asset_id] += col.amount; - } for( const call_order_object& o : db.get_index_type().indices() ) { asset col = o.get_collateral(); @@ -409,32 +403,6 @@ void database_fixture::issue_uia( const account_object& recipient, asset amount return; } -const short_order_object*database_fixture::create_short(account_id_type seller, const asset& amount_to_sell, const asset& collateral_provided, uint16_t initial_collateral_ratio, uint16_t maintenance_collateral_ratio) -{ - return create_short(seller(db), amount_to_sell, collateral_provided, initial_collateral_ratio, maintenance_collateral_ratio); -} - -const short_order_object* database_fixture::create_short( - const account_object& seller, - const asset& amount_to_sell, - const asset& collateral_provided, - uint16_t initial_collateral_ratio /* = 2000 */, - uint16_t maintenance_collateral_ratio /* = 1750 */ - ) -{ - short_order_create_operation op; - op.seller = seller.id; - op.amount_to_sell = amount_to_sell; - op.collateral = collateral_provided; - op.initial_collateral_ratio = initial_collateral_ratio; - op.maintenance_collateral_ratio = maintenance_collateral_ratio; - trx.operations.push_back(std::move(op)); - trx.validate(); - processed_transaction ptx = db.push_transaction(trx, ~0); - trx.operations.clear(); - return db.find(ptx.operation_results[0].get()); -} - const account_object& database_fixture::create_account( const string& name, const key_id_type& key /* = key_id_type() */ @@ -603,18 +571,6 @@ asset database_fixture::cancel_limit_order( const limit_order_object& order ) return processed.operation_results[0].get(); } -asset database_fixture::cancel_short_order( const short_order_object& order ) -{ - short_order_cancel_operation cancel_order; - cancel_order.fee_paying_account = order.seller; - cancel_order.order = order.id; - trx.operations.push_back(cancel_order); - for( auto& op : trx.operations ) op.visit( operation_set_fee( db.current_fee_schedule() ) ); - trx.validate(); - auto processed = db.push_transaction(trx, ~0); - trx.operations.clear(); - return processed.operation_results[0].get(); -} void database_fixture::transfer( account_id_type from, @@ -727,15 +683,6 @@ string database_fixture::pretty( const asset& a )const return ss.str(); } -void database_fixture::print_short_order( const short_order_object& cur )const -{ - std::cout << std::setw(10) << cur.seller(db).name << " "; - std::cout << std::setw(10) << "SHORT" << " "; - std::cout << std::setw(16) << pretty( cur.amount_for_sale() ) << " "; - std::cout << std::setw(16) << pretty( cur.amount_to_receive() ) << " "; - std::cout << std::setw(16) << (~cur.sell_price).to_real() << " "; -} - void database_fixture::print_limit_order( const limit_order_object& cur )const { std::cout << std::setw(10) << cur.seller(db).name << " "; @@ -783,68 +730,16 @@ void database_fixture::print_joint_market( const string& syma, const string& sym const auto& limit_idx = db.get_index_type(); const auto& limit_price_idx = limit_idx.indices().get(); - const auto& short_idx = db.get_index_type(); - const auto& sell_price_idx = short_idx.indices().get(); auto limit_itr = limit_price_idx.begin(); - auto short_itr = sell_price_idx.rbegin(); - while( true ) + while( limit_itr != limit_price_idx.end() ) { std::cout << std::endl; - if( limit_itr != limit_price_idx.end() ) - { - if( short_itr != sell_price_idx.rend() && limit_itr->sell_price > ~short_itr->sell_price ) - { - print_short_order( *short_itr ); - ++short_itr; - } - else // print the limit - { - print_limit_order( *limit_itr ); - ++limit_itr; - } - } - else if( short_itr != sell_price_idx.rend() ) - { - print_short_order( *short_itr ); - ++short_itr; - } - else - break; + print_limit_order( *limit_itr ); + ++limit_itr; } } -void database_fixture::print_short_market( const string& syma, const string& symb )const -{ - const auto& limit_idx = db.get_index_type(); - const auto& price_idx = limit_idx.indices().get(); - - cout << std::fixed; - cout.precision(5); - cout << std::setw(10) << std::left << "NAME" << " "; - cout << std::setw(16) << std::right << "FOR SHORT" << " "; - cout << std::setw(16) << std::right << "COLLATERAL" << " "; - cout << std::setw(10) << std::right << "PRICE" << " "; - cout << std::setw(10) << std::right << "1/PRICE" << " "; - cout << std::setw(10) << std::right << "CALL PRICE" << " "; - cout << std::setw(10) << std::right << "I-Ratio" << " "; - cout << std::setw(10) << std::right << "M-Ratio" << "\n"; - cout << string(100, '=') << std::endl; - auto cur = price_idx.begin(); - while( cur != price_idx.end() ) - { - cout << std::setw( 10 ) << std::left << cur->seller(db).name << " "; - cout << std::setw( 16 ) << std::right << pretty( cur->amount_for_sale() ) << " "; - cout << std::setw( 16 ) << std::right << pretty( cur->get_collateral() ) << " "; - cout << std::setw( 10 ) << std::right << cur->sell_price.to_real() << " "; - cout << std::setw( 10 ) << std::right << (~cur->sell_price).to_real() << " "; - cout << std::setw( 10 ) << std::right << (cur->call_price).to_real() << " "; - cout << std::setw( 10 ) << std::right << (cur->initial_collateral_ratio)/double(1000) << " "; - cout << std::setw( 10 ) << std::right << (cur->maintenance_collateral_ratio)/double(1000) << " "; - cout << "\n"; - ++cur; - } -} int64_t database_fixture::get_balance( account_id_type account, asset_id_type a )const { diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 66b2ceeb..803fc6ac 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -147,20 +147,6 @@ struct database_fixture { const asset_object& create_user_issued_asset( const string& name ); void issue_uia( const account_object& recipient, asset amount ); - const short_order_object* create_short( - account_id_type seller, - const asset& amount_to_sell, - const asset& collateral_provided, - uint16_t initial_collateral_ratio = 2000, - uint16_t maintenance_collateral_ratio = 1750 - ); - const short_order_object* create_short( - const account_object& seller, - const asset& amount_to_sell, - const asset& collateral_provided, - uint16_t initial_collateral_ratio = 2000, - uint16_t maintenance_collateral_ratio = 1750 - ); const account_object& create_account( const string& name, @@ -197,7 +183,6 @@ struct database_fixture { const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv ); const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv ); asset cancel_limit_order( const limit_order_object& order ); - asset cancel_short_order( const short_order_object& order ); void transfer( account_id_type from, account_id_type to, const asset& amount, const asset& fee = asset() ); void transfer( const account_object& from, const account_object& to, const asset& amount, const asset& fee = asset() ); void fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount ); @@ -206,11 +191,9 @@ struct database_fixture { void upgrade_to_lifetime_member( const account_object& account ); void print_market( const string& syma, const string& symb )const; string pretty( const asset& a )const; - void print_short_order( const short_order_object& cur )const; void print_limit_order( const limit_order_object& cur )const; void print_call_orders( )const; void print_joint_market( const string& syma, const string& symb )const; - void print_short_market( const string& syma, const string& symb )const; int64_t get_balance( account_id_type account, asset_id_type a )const; int64_t get_balance( const account_object& account, const asset_object& a )const; }; diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index c74e182d..31d3b98d 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -464,53 +464,6 @@ BOOST_FIXTURE_TEST_CASE( maintenance_interval, database_fixture ) } } -/** - * Orders should specify a valid expiration time and they will ba automatically canceled if not filled by that time. - * This feature allows people to safely submit orders that have a limited lifetime, which is essential to some - * traders. - */ -BOOST_FIXTURE_TEST_CASE( short_order_expiration, database_fixture ) -{ try { - //Get a sane head block time - generate_block(); - - auto* test = &create_bitasset("TEST"); - auto* core = &asset_id_type()(db); - auto* nathan = &create_account("nathan"); - auto* genesis = &account_id_type()(db); - - transfer(*genesis, *nathan, core->amount(50000)); - - BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 50000 ); - - short_order_create_operation op; - op.seller = nathan->id; - op.amount_to_sell = test->amount(500); - op.collateral = core->amount(500); - op.expiration = db.head_block_time() + fc::seconds(10); - trx.operations.push_back(op); - auto ptrx = db.push_transaction(trx, ~0); - - BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 ); - - auto ptrx_id = ptrx.operation_results.back().get(); - auto short_index = db.get_index_type().indices(); - auto short_itr = short_index.begin(); - BOOST_REQUIRE( short_itr != short_index.end() ); - BOOST_REQUIRE( short_itr->id == ptrx_id ); - BOOST_REQUIRE( db.find_object(short_itr->id) ); - BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 ); - auto id = short_itr->id; - - generate_blocks(op.expiration); - test = &get_asset("TEST"); - core = &asset_id_type()(db); - nathan = &get_account("nathan"); - genesis = &account_id_type()(db); - - BOOST_CHECK(db.find_object(id) == nullptr); - BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 50000 ); -} FC_LOG_AND_RETHROW() } BOOST_FIXTURE_TEST_CASE( limit_order_expiration, database_fixture ) { try { @@ -606,6 +559,8 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) BOOST_FIXTURE_TEST_CASE( force_settlement, database_fixture ) { try { + FC_ASSERT( "TODO" ); + /* auto private_key = generate_private_key("genesis"); account_id_type nathan_id = create_account("nathan").get_id(); account_id_type shorter1_id = create_account("shorter1").get_id(); @@ -726,6 +681,7 @@ BOOST_FIXTURE_TEST_CASE( force_settlement, database_fixture ) BOOST_CHECK(db.find(settle_id)); BOOST_CHECK_EQUAL(get_balance(nathan_id, asset_id_type()), 5878); BOOST_CHECK(!db.get_index_type().indices().empty()); + */ } FC_LOG_AND_RETHROW() } BOOST_FIXTURE_TEST_CASE( pop_block_twice, database_fixture ) diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index e3bc8c00..525aed07 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -314,18 +314,12 @@ BOOST_AUTO_TEST_CASE( update_mia ) pop.publisher = account_id_type(1); price_feed feed; feed.call_limit = price(bit_usd.amount(5), bit_usd.amount(5)); - feed.short_limit = feed.call_limit; REQUIRE_THROW_WITH_VALUE(pop, feed, feed); feed.call_limit = price(bit_usd.amount(5), asset(5)); - feed.short_limit = ~feed.call_limit; REQUIRE_THROW_WITH_VALUE(pop, feed, feed); - feed.short_limit = price(asset(4), bit_usd.amount(5)); - REQUIRE_THROW_WITH_VALUE(pop, feed, feed); - std::swap(feed.call_limit, feed.short_limit); pop.feed = feed; REQUIRE_THROW_WITH_VALUE(pop, feed.max_margin_period_sec, 0); REQUIRE_THROW_WITH_VALUE(pop, feed.required_maintenance_collateral, 0); - REQUIRE_THROW_WITH_VALUE(pop, feed.required_initial_collateral, 500); trx.operations.back() = pop; db.push_transaction(trx, ~0); } @@ -349,129 +343,6 @@ BOOST_AUTO_TEST_CASE( update_mia ) } } -BOOST_AUTO_TEST_CASE( create_short_test ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 100 ) ); // 1:1 price - BOOST_REQUIRE( first_short != nullptr ); - BOOST_REQUIRE( create_short( shorter_account, bitusd.amount(100), asset( 200 ) ) ); // 1:2 price - BOOST_REQUIRE( create_short( shorter_account, bitusd.amount(100), asset( 300 ) ) ); // 1:3 price - BOOST_REQUIRE_EQUAL( get_balance(shorter_account, asset_id_type()(db) ), 10000-600 ); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} -BOOST_AUTO_TEST_CASE( cancel_short_test ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 100 ) ); // 1:1 price - BOOST_REQUIRE( first_short != nullptr ); - BOOST_REQUIRE( create_short( shorter_account, bitusd.amount(100), asset( 200 ) ) ); // 1:2 price - BOOST_REQUIRE( create_short( shorter_account, bitusd.amount(100), asset( 300 ) ) ); // 1:3 price - BOOST_REQUIRE_EQUAL( get_balance(shorter_account, asset_id_type()(db) ), 10000-600 ); - auto refund = cancel_short_order( *first_short ); - BOOST_REQUIRE_EQUAL( get_balance(shorter_account, asset_id_type()(db) ), 10000-500 ); - FC_ASSERT( refund == asset(100) ); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( match_short_now_exact ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - auto buy_order = create_sell_order( buyer_account, asset(200), bitusd.amount(100) ); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - BOOST_REQUIRE( first_short == nullptr ); - print_call_orders(); - //print_short_market("",""); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( dont_match_short ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - create_sell_order( buyer_account, asset(125), bitusd.amount(100) ); - create_sell_order( buyer_account, asset(150), bitusd.amount(100) ); - auto buy_order = create_sell_order( buyer_account, asset(100), bitusd.amount(100) ); - //print_market("",""); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - auto second_short = create_short( shorter_account, bitusd.amount(100), asset( 300 ) ); // 1:1 price - auto third_short = create_short( shorter_account, bitusd.amount(100), asset( 400 ) ); // 1:1 price - //print_short_market("",""); - BOOST_REQUIRE( first_short && second_short && third_short ); - //print_joint_market("",""); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( match_all_short_with_surplus_collaterl ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - //auto buy_order = create_sell_order( buyer_account, asset(200), bitusd.amount(101) ); - auto buy_order = create_sell_order( buyer_account, asset(300), bitusd.amount(100) ); - print_market("",""); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - print_short_market("",""); - BOOST_REQUIRE( !first_short ); - //print_short_market("",""); - print_call_orders(); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - BOOST_AUTO_TEST_CASE( create_uia ) { @@ -916,7 +787,6 @@ BOOST_AUTO_TEST_CASE( delegate_feeds ) asset_publish_feed_operation op({asset(), active_witnesses[0]}); op.asset_id = bit_usd.get_id(); op.feed.call_limit = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); - op.feed.short_limit = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(10)); // We'll expire margins after a month op.feed.max_margin_period_sec = fc::days(30).to_seconds(); // Accept defaults for required collateral @@ -938,38 +808,29 @@ BOOST_AUTO_TEST_CASE( delegate_feeds ) const asset_bitasset_data_object& bitasset = bit_usd.bitasset_data(db); BOOST_CHECK(bitasset.current_feed.call_limit.to_real() == GRAPHENE_BLOCKCHAIN_PRECISION / 30.0); - BOOST_CHECK_EQUAL(bitasset.current_feed.short_limit.to_real(), 10.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.max_margin_period_sec == fc::days(30).to_seconds()); - BOOST_CHECK(bitasset.current_feed.required_initial_collateral == GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO); BOOST_CHECK(bitasset.current_feed.required_maintenance_collateral == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = active_witnesses[1]; op.feed.call_limit = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); - op.feed.short_limit = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(20)); op.feed.max_margin_period_sec = fc::days(10).to_seconds(); trx.operations.back() = op; db.push_transaction(trx, ~0); BOOST_CHECK_EQUAL(bitasset.current_feed.call_limit.to_real(), GRAPHENE_BLOCKCHAIN_PRECISION / 25.0); - BOOST_CHECK_EQUAL(bitasset.current_feed.short_limit.to_real(), 20.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.max_margin_period_sec == fc::days(30).to_seconds()); - BOOST_CHECK(bitasset.current_feed.required_initial_collateral == GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO); BOOST_CHECK(bitasset.current_feed.required_maintenance_collateral == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = active_witnesses[2]; op.feed.call_limit = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); - op.feed.short_limit = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(10)); op.feed.max_margin_period_sec = fc::days(100).to_seconds(); // But this delegate is an idiot. - op.feed.required_initial_collateral = 1001; op.feed.required_maintenance_collateral = 1000; trx.operations.back() = op; db.push_transaction(trx, ~0); BOOST_CHECK_EQUAL(bitasset.current_feed.call_limit.to_real(), GRAPHENE_BLOCKCHAIN_PRECISION / 30.0); - BOOST_CHECK_EQUAL(bitasset.current_feed.short_limit.to_real(), 10.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.max_margin_period_sec == fc::days(30).to_seconds()); - BOOST_CHECK(bitasset.current_feed.required_initial_collateral == GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO); BOOST_CHECK(bitasset.current_feed.required_maintenance_collateral == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); } catch (const fc::exception& e) { edump((e.to_detail_string())); @@ -977,241 +838,12 @@ BOOST_AUTO_TEST_CASE( delegate_feeds ) } } -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( limit_match_existing_short_exact ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - create_sell_order( buyer_account, asset(125), bitusd.amount(100) ); - create_sell_order( buyer_account, asset(150), bitusd.amount(100) ); - auto buy_order = create_sell_order( buyer_account, asset(100), bitusd.amount(100) ); - //print_market("",""); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - auto second_short = create_short( shorter_account, bitusd.amount(100), asset( 300 ) ); // 1:1 price - auto third_short = create_short( shorter_account, bitusd.amount(100), asset( 400 ) ); // 1:1 price - //print_short_market("",""); - BOOST_REQUIRE( first_short && second_short && third_short ); - //print_joint_market("",""); - auto unmatched_order = create_sell_order( buyer_account, asset(200), bitusd.amount(100) ); - //print_joint_market("",""); - BOOST_REQUIRE( !unmatched_order ); - // now it shouldn't fill - unmatched_order = create_sell_order( buyer_account, asset(200), bitusd.amount(100) ); - //print_joint_market("",""); - BOOST_REQUIRE( unmatched_order ); - BOOST_CHECK( unmatched_order->amount_for_sale() == asset(200) ); - BOOST_CHECK( unmatched_order->amount_to_receive() == bitusd.amount(100) ); - BOOST_CHECK( second_short->amount_for_sale() == bitusd.amount(100) ); - BOOST_CHECK( third_short->amount_for_sale() == bitusd.amount(100) ); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( limit_match_existing_short_partial_exact_price ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - create_sell_order( buyer_account, asset(125), bitusd.amount(100) ); - create_sell_order( buyer_account, asset(150), bitusd.amount(100) ); - auto buy_order = create_sell_order( buyer_account, asset(100), bitusd.amount(100) ); - //print_market("",""); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - auto second_short = create_short( shorter_account, bitusd.amount(100), asset( 300 ) ); // 1:1 price - auto third_short = create_short( shorter_account, bitusd.amount(100), asset( 400 ) ); // 1:1 price - //print_short_market("",""); - BOOST_REQUIRE( first_short && second_short && third_short ); - //print_joint_market("",""); - auto unmatched_order = create_sell_order( buyer_account, asset(100), bitusd.amount(50) ); - //print_joint_market("",""); - BOOST_REQUIRE( !unmatched_order ); - BOOST_CHECK( first_short->amount_for_sale() == bitusd.amount(50) ); - BOOST_CHECK( first_short->get_collateral() == asset(100) ); - BOOST_CHECK( second_short->amount_for_sale() == bitusd.amount(100) ); - BOOST_CHECK( third_short->amount_for_sale() == bitusd.amount(100) ); - - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( limit_match_existing_short_partial_over_price ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - create_sell_order( buyer_account, asset(125), bitusd.amount(100) ); - create_sell_order( buyer_account, asset(150), bitusd.amount(100) ); - auto buy_order = create_sell_order( buyer_account, asset(100), bitusd.amount(100) ); - //print_market("",""); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - auto second_short = create_short( shorter_account, bitusd.amount(100), asset( 300 ) ); // 1:1 price - auto third_short = create_short( shorter_account, bitusd.amount(100), asset( 400 ) ); // 1:1 price - BOOST_REQUIRE( first_short && second_short && third_short ); - //print_joint_market("",""); - auto unmatched_order = create_sell_order( buyer_account, asset(100), bitusd.amount(40) ); - //print_joint_market("",""); - BOOST_REQUIRE( !unmatched_order ); - BOOST_CHECK( first_short->amount_for_sale() == bitusd.amount(50) ); - BOOST_CHECK( first_short->get_collateral() == asset(100) ); - BOOST_CHECK( second_short->amount_for_sale() == bitusd.amount(100) ); - BOOST_CHECK( third_short->amount_for_sale() == bitusd.amount(100) ); - - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( limit_match_multiple_existing_short_partial_over_price ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - create_sell_order( buyer_account, asset(125), bitusd.amount(100) ); - create_sell_order( buyer_account, asset(150), bitusd.amount(100) ); - auto buy_order = create_sell_order( buyer_account, asset(100), bitusd.amount(100) ); - //print_market("",""); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - auto next_short = create_short( shorter_account, bitusd.amount(100), asset( 210 ) ); // 1:1 price - auto second_short = create_short( shorter_account, bitusd.amount(100), asset( 300 ) ); // 1:1 price - auto third_short = create_short( shorter_account, bitusd.amount(100), asset( 400 ) ); // 1:1 price - //print_short_market("",""); - BOOST_REQUIRE( first_short && second_short && third_short ); - auto unmatched_order = create_sell_order( buyer_account, asset(200+115), bitusd.amount(150) ); - // print_joint_market("",""); - BOOST_REQUIRE( !unmatched_order ); - //wdump( (next_short->amount_for_sale().amount)(next_short->get_collateral().amount) ); - BOOST_CHECK( next_short->amount_for_sale() == bitusd.amount(46) ); - BOOST_CHECK( next_short->get_collateral() == asset(97) ); - BOOST_CHECK( second_short->amount_for_sale() == bitusd.amount(100) ); - BOOST_CHECK( third_short->amount_for_sale() == bitusd.amount(100) ); - print_call_orders(); - - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - -/** - * Assume there exists an offer to buy BITUSD - * Create a short that exactly matches that offer at a price 2:1 - */ -BOOST_AUTO_TEST_CASE( limit_dont_match_existing_short_partial_over_price ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter_account = create_account( "shorter" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - create_sell_order( buyer_account, asset(125), bitusd.amount(100) ); - create_sell_order( buyer_account, asset(150), bitusd.amount(100) ); - auto buy_order = create_sell_order( buyer_account, asset(100), bitusd.amount(100) ); - BOOST_REQUIRE( buy_order ); - auto first_short = create_short( shorter_account, bitusd.amount(100), asset( 200 ) ); // 1:1 price - auto second_short = create_short( shorter_account, bitusd.amount(100), asset( 300 ) ); // 1:1 price - auto third_short = create_short( shorter_account, bitusd.amount(100), asset( 400 ) ); // 1:1 price - //print_short_market("",""); - BOOST_REQUIRE( first_short && second_short && third_short ); - //print_joint_market("",""); - auto unmatched_order = create_sell_order( buyer_account, asset(100), bitusd.amount(60) ); - BOOST_REQUIRE( unmatched_order ); - BOOST_CHECK( first_short->amount_for_sale() == bitusd.amount(100) ); - BOOST_CHECK( first_short->get_collateral() == asset(200) ); - BOOST_CHECK( second_short->amount_for_sale() == bitusd.amount(100) ); - BOOST_CHECK( third_short->amount_for_sale() == bitusd.amount(100) ); - }catch ( const fc::exception& e ) - { - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; - } -} - -BOOST_AUTO_TEST_CASE( multiple_shorts_matching_multiple_bids_in_order ) -{ try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const account_object& shorter1_account = create_account( "shorter1" ); - const account_object& shorter2_account = create_account( "shorter2" ); - const account_object& shorter3_account = create_account( "shorter3" ); - const account_object& buyer_account = create_account( "buyer" ); - transfer( genesis_account(db), shorter1_account, asset( 10000 ) ); - transfer( genesis_account(db), shorter2_account, asset( 10000 ) ); - transfer( genesis_account(db), shorter3_account, asset( 10000 ) ); - transfer( genesis_account(db), buyer_account, asset( 10000 ) ); - - BOOST_REQUIRE( create_sell_order( buyer_account, asset(125), bitusd.amount(100) ) ); - BOOST_REQUIRE( create_sell_order( buyer_account, asset(150), bitusd.amount(100) ) ); - BOOST_REQUIRE( create_sell_order( buyer_account, asset(200), bitusd.amount(100) ) ); - print_joint_market("",""); - BOOST_REQUIRE( !create_short( shorter1_account, bitusd.amount(100), asset( 200 ) ) ); - BOOST_REQUIRE( !create_short( shorter2_account, bitusd.amount(100), asset( 150 ) ) ); - BOOST_REQUIRE( !create_short( shorter3_account, bitusd.amount(100), asset( 125 ) ) ); - print_call_orders(); - - auto& index = db.get_index_type().indices().get(); - BOOST_CHECK(index.find(boost::make_tuple(buyer_account.id, bitusd.id)) == index.end()); - BOOST_CHECK(index.find(boost::make_tuple(shorter1_account.id, bitusd.id)) != index.end()); - BOOST_CHECK(index.find(boost::make_tuple(shorter1_account.id, bitusd.id))->get_debt() == bitusd.amount(100) ); - BOOST_CHECK(index.find(boost::make_tuple(shorter1_account.id, bitusd.id))->call_price == price(asset(300), bitusd.amount(100)) ); - BOOST_CHECK(index.find(boost::make_tuple(shorter2_account.id, bitusd.id)) != index.end()); - BOOST_CHECK(index.find(boost::make_tuple(shorter2_account.id, bitusd.id))->get_debt() == bitusd.amount(100) ); - BOOST_CHECK(index.find(boost::make_tuple(shorter3_account.id, bitusd.id)) != index.end()); - BOOST_CHECK(index.find(boost::make_tuple(shorter3_account.id, bitusd.id))->get_debt() == bitusd.amount(100) ); -}catch ( const fc::exception& e ) -{ - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; -} } BOOST_AUTO_TEST_CASE( full_cover_test ) { try { - INVOKE(multiple_shorts_matching_multiple_bids_in_order); + FC_ASSERT( "Reimplement with new borrowing semantics" ); + /* const asset_object& bit_usd = get_asset("BITUSD"); const asset_object& core = asset_id_type()(db); const account_object& debt_holder = get_account("shorter1"); @@ -1239,6 +871,7 @@ BOOST_AUTO_TEST_CASE( full_cover_test ) BOOST_CHECK_EQUAL(get_balance(debt_holder, bit_usd), 0); BOOST_CHECK(index.find(boost::make_tuple(debt_holder.id, bit_usd.id)) == index.end()); + */ } catch( fc::exception& e) { edump((e.to_detail_string())); throw; @@ -1248,7 +881,7 @@ BOOST_AUTO_TEST_CASE( full_cover_test ) BOOST_AUTO_TEST_CASE( partial_cover_test ) { try { - INVOKE(multiple_shorts_matching_multiple_bids_in_order); + FC_ASSERT( "Reimplement with new borrowing semantics" ); const asset_object& bit_usd = get_asset("BITUSD"); const asset_object& core = asset_id_type()(db); const account_object& debt_holder = get_account("shorter1"); @@ -1319,251 +952,6 @@ BOOST_AUTO_TEST_CASE( partial_cover_test ) } } -BOOST_AUTO_TEST_CASE( limit_order_matching_mix_of_shorts_and_limits ) -{ try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const asset_object& core = get_asset( GRAPHENE_SYMBOL ); - const account_object& shorter1 = create_account( "shorter1" ); - const account_object& shorter2 = create_account( "shorter2" ); - const account_object& shorter3 = create_account( "shorter3" ); - const account_object& buyer1 = create_account( "buyer1" ); - const account_object& buyer2 = create_account( "buyer2" ); - const account_object& buyer3 = create_account( "buyer3" ); - - transfer( genesis_account(db), shorter1, core.amount( 10000 ) ); - transfer( genesis_account(db), shorter2, core.amount( 10000 ) ); - transfer( genesis_account(db), shorter3, core.amount( 10000 ) ); - transfer( genesis_account(db), buyer1, core.amount( 10000 ) ); - transfer( genesis_account(db), buyer2, core.amount( 10000 ) ); - transfer( genesis_account(db), buyer3, core.amount( 10000 ) ); - - // create some BitUSD - BOOST_REQUIRE( create_sell_order( buyer1, core.amount(1000), bitusd.amount(1000) ) ); - BOOST_REQUIRE( !create_short( shorter1, bitusd.amount(1000), core.amount(1000) ) ); - BOOST_REQUIRE_EQUAL( get_balance(buyer1, bitusd), 990 ); // 1000 - 1% fee - - // create a mixture of BitUSD sells and shorts - BOOST_REQUIRE( create_short( shorter1, bitusd.amount(100), core.amount(125) ) ); - BOOST_REQUIRE( create_sell_order( buyer1, bitusd.amount(100), core.amount(150) ) ); - BOOST_REQUIRE( create_short( shorter2, bitusd.amount(100), core.amount(200) ) ); - BOOST_REQUIRE( create_sell_order( buyer1, bitusd.amount(100), core.amount(225) ) ); - BOOST_REQUIRE( create_short( shorter3, bitusd.amount(100), core.amount(250) ) ); - - print_joint_market("",""); // may have bugs - - // buy up everything but the highest order - auto unfilled_order = create_sell_order( buyer2, core.amount(700), bitusd.amount(311) ); - if( unfilled_order ) wdump((*unfilled_order)); - print_joint_market("",""); - if( unfilled_order ) wdump((*unfilled_order)); - BOOST_REQUIRE( !unfilled_order ); - BOOST_REQUIRE_EQUAL( get_balance(buyer2, bitusd), 396 ); - - print_joint_market("",""); - print_call_orders(); - -}catch ( const fc::exception& e ) -{ - elog( "${e}", ("e", e.to_detail_string() ) ); - throw; -} } - -BOOST_AUTO_TEST_CASE( big_short ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const asset_object& core = get_asset( GRAPHENE_SYMBOL ); - const account_object& shorter1 = create_account( "shorter1" ); - const account_object& buyer1 = create_account( "buyer1" ); - const account_object& buyer2 = create_account( "buyer2" ); - const account_object& buyer3 = create_account( "buyer3" ); - - transfer( genesis_account(db), shorter1, asset( 10000 ) ); - transfer( genesis_account(db), buyer1, asset( 10000 ) ); - transfer( genesis_account(db), buyer2, asset( 10000 ) ); - transfer( genesis_account(db), buyer3, asset( 10000 ) ); - - create_sell_order(buyer1, core.amount(500), bitusd.amount(500)); - create_sell_order(buyer2, core.amount(500), bitusd.amount(600)); - auto unmatched_buy3 = create_sell_order(buyer3, core.amount(500), bitusd.amount(700)); - - auto unmatched = create_short(shorter1, bitusd.amount(1300), core.amount(800)); - if( unmatched ) wdump((*unmatched)); - - BOOST_CHECK( !unmatched ); - BOOST_CHECK( unmatched_buy3 ); - BOOST_CHECK_EQUAL( unmatched_buy3->amount_for_sale().amount.value, 358); - // The extra 1 is rounding leftovers; it has to go somewhere. - BOOST_CHECK_EQUAL( unmatched_buy3->amount_to_receive().amount.value, 501); - // All three buyers offered 500 CORE for varying numbers of dollars. - BOOST_CHECK_EQUAL(get_balance(buyer1, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer2, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer3, core), 9500); - // Sans the 1% market fee, buyer1 got 500 USD, buyer2 got 600 USD - BOOST_CHECK_EQUAL(get_balance(buyer1, bitusd), 495); - BOOST_CHECK_EQUAL(get_balance(buyer2, bitusd), 594); - // Buyer3 wanted 700 USD, but the shorter only had 1300-500-600=200 left, so buyer3 got 200. - BOOST_CHECK_EQUAL(get_balance(buyer3, bitusd), 198); - // Shorter1 never had any USD, so he shouldn't have any now. He paid 800 CORE, so he should have 9200 left. - BOOST_CHECK_EQUAL(get_balance(shorter1, bitusd), 0); - BOOST_CHECK_EQUAL(get_balance(shorter1, core), 9200); - - const auto& call_index = db.get_index_type().indices().get(); - const auto call_itr = call_index.find(boost::make_tuple(shorter1.id, bitusd.id)); - BOOST_CHECK(call_itr != call_index.end()); - const call_order_object& call_object = *call_itr; - BOOST_CHECK(call_object.borrower == shorter1.id); - // 800 from shorter1, 500 from buyer1 and buyer2 each, 500/700*200 from buyer3 totals 1942 - BOOST_CHECK_EQUAL(call_object.collateral.value, 1942); - // Shorter1 sold 1300 USD. Make sure that's recorded accurately. - BOOST_CHECK_EQUAL(call_object.debt.value, 1300); - // 13 USD was paid in market fees. - BOOST_CHECK_EQUAL(bitusd.dynamic_asset_data_id(db).accumulated_fees.value, 13); - } catch( const fc::exception& e) { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( big_short2 ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const asset_object& core = get_asset( GRAPHENE_SYMBOL ); - const account_object& shorter1 = create_account( "shorter1" ); - const account_object& buyer1 = create_account( "buyer1" ); - const account_object& buyer2 = create_account( "buyer2" ); - const account_object& buyer3 = create_account( "buyer3" ); - - transfer( genesis_account(db), shorter1, asset( 10000 ) ); - transfer( genesis_account(db), buyer1, asset( 10000 ) ); - transfer( genesis_account(db), buyer2, asset( 10000 ) ); - transfer( genesis_account(db), buyer3, asset( 10000 ) ); - - create_sell_order(buyer1, core.amount(500), bitusd.amount(500)); - create_sell_order(buyer2, core.amount(500), bitusd.amount(600)); - auto unmatched_buy3 = create_sell_order(buyer3, core.amount(500), bitusd.amount(700)); - - //We want to perfectly match the first two orders, so that's 1100 USD at 500/600 = 916 - auto unmatched = create_short(shorter1, bitusd.amount(1100), core.amount(916)); - if( unmatched ) wdump((*unmatched)); - - BOOST_CHECK( !unmatched ); - BOOST_CHECK( unmatched_buy3 ); - BOOST_CHECK_EQUAL( unmatched_buy3->amount_for_sale().amount.value, 500); - // The extra 1 is rounding leftovers; it has to go somewhere. - BOOST_CHECK_EQUAL( unmatched_buy3->amount_to_receive().amount.value, 700); - // All three buyers offered 500 CORE for varying numbers of dollars. - BOOST_CHECK_EQUAL(get_balance(buyer1, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer2, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer3, core), 9500); - // Sans the 1% market fee, buyer1 got 500 USD, buyer2 got 600 USD - BOOST_CHECK_EQUAL(get_balance(buyer1, bitusd), 495); - BOOST_CHECK_EQUAL(get_balance(buyer2, bitusd), 594); - // Buyer3's order wasn't matched. He should have no USD. - BOOST_CHECK_EQUAL(get_balance(buyer3, bitusd), 0); - // Shorter1 never had any USD, so he shouldn't have any now. He paid 916 CORE, so he should have 9084 left. - BOOST_CHECK_EQUAL(get_balance(shorter1, bitusd), 0); - BOOST_CHECK_EQUAL(get_balance(shorter1, core), 9084); - - const auto& call_index = db.get_index_type().indices().get(); - const auto call_itr = call_index.find(boost::make_tuple(shorter1.id, bitusd.id)); - BOOST_CHECK(call_itr != call_index.end()); - const call_order_object& call_object = *call_itr; - BOOST_CHECK(call_object.borrower == shorter1.id); - // 916 from shorter1, 500 from buyer1 and buyer2 each adds to 1916 - BOOST_CHECK_EQUAL(call_object.collateral.value, 1916); - // Shorter1 sold 1100 USD. Make sure that's recorded accurately. - BOOST_CHECK_EQUAL(call_object.debt.value, 1100); - // 11 USD was paid in market fees. - BOOST_CHECK_EQUAL(bitusd.dynamic_asset_data_id(db).accumulated_fees.value, 11); - } catch( const fc::exception& e) { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( big_short3 ) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const asset_object& core = get_asset( GRAPHENE_SYMBOL ); - const account_object& shorter1 = create_account( "shorter1" ); - const account_object& buyer1 = create_account( "buyer1" ); - const account_object& buyer2 = create_account( "buyer2" ); - const account_object& buyer3 = create_account( "buyer3" ); - - transfer( genesis_account(db), shorter1, asset( 10000 ) ); - transfer( genesis_account(db), buyer1, asset( 10000 ) ); - transfer( genesis_account(db), buyer2, asset( 10000 ) ); - transfer( genesis_account(db), buyer3, asset( 10000 ) ); - - create_short(shorter1, bitusd.amount(1300), core.amount(800)); - - print_joint_market("",""); - - create_sell_order(buyer1, core.amount(500), bitusd.amount(500)); - create_sell_order(buyer2, core.amount(500), bitusd.amount(600)); - auto unmatched_buy3 = create_sell_order(buyer3, core.amount(500), bitusd.amount(700)); - - print_joint_market("",""); - - BOOST_CHECK( unmatched_buy3 ); - BOOST_CHECK_EQUAL( unmatched_buy3->amount_for_sale().amount.value, 500); - BOOST_CHECK_EQUAL( unmatched_buy3->amount_to_receive().amount.value, 700); - BOOST_CHECK_EQUAL(get_balance(buyer1, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer2, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer3, core), 9500); - BOOST_CHECK_EQUAL(get_balance(buyer1, bitusd), 804); - BOOST_CHECK_EQUAL(get_balance(buyer2, bitusd), 484); - BOOST_CHECK_EQUAL(get_balance(buyer3, bitusd), 0); - BOOST_CHECK_EQUAL(get_balance(shorter1, bitusd), 0); - BOOST_CHECK_EQUAL(get_balance(shorter1, core), 9200); - - const auto& call_index = db.get_index_type().indices().get(); - const auto call_itr = call_index.find(boost::make_tuple(shorter1.id, bitusd.id)); - BOOST_CHECK(call_itr != call_index.end()); - const call_order_object& call_object = *call_itr; - BOOST_CHECK(call_object.borrower == shorter1.id); - BOOST_CHECK_EQUAL(call_object.collateral.value, 1600); - BOOST_CHECK_EQUAL(call_object.debt.value, 1300); - BOOST_CHECK_EQUAL(bitusd.dynamic_asset_data_id(db).accumulated_fees.value, 12); - } catch( const fc::exception& e) { - edump((e.to_detail_string())); - throw; - } -} - -/** - * Originally, this test exposed a bug in vote tallying causing the total number of votes to exceed the number of - * voting shares. This bug was resolved in commit 489b0dafe981c3b96b17f23cfc9ddc348173c529 - */ -BOOST_AUTO_TEST_CASE(break_vote_count) -{ - try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const asset_object& core = get_asset( GRAPHENE_SYMBOL ); - const account_object& shorter1 = create_account( "shorter1" ); - const account_object& buyer1 = create_account( "buyer1" ); - - transfer( genesis_account(db), shorter1, asset( 100000000 ) ); - transfer( genesis_account(db), buyer1, asset( 100000000 ) ); - - create_short(shorter1, bitusd.amount(1300), core.amount(800)); - - create_sell_order(buyer1, core.amount(500), bitusd.amount(500)); - - BOOST_CHECK_EQUAL(get_balance(buyer1, core), 99999500); - BOOST_CHECK_EQUAL(get_balance(buyer1, bitusd), 804); - BOOST_CHECK_EQUAL(get_balance(shorter1, bitusd), 0); - BOOST_CHECK_EQUAL(get_balance(shorter1, core), 99999200); - - create_sell_order(shorter1, core.amount(90000000), bitusd.amount(1)); - } catch( const fc::exception& e) { - edump((e.to_detail_string())); - throw; - } -} /** * Create an order such that when the trade executes at the @@ -1600,6 +988,8 @@ BOOST_AUTO_TEST_CASE( trade_amount_equals_zero ) BOOST_AUTO_TEST_CASE( margin_call_limit_test ) { try { + FC_ASSERT( "TODO - Reimplement with new short semantics" ); + /* const asset_object& bitusd = create_bitasset( "BITUSD" ); const asset_object& core = get_asset( GRAPHENE_SYMBOL ); @@ -1663,6 +1053,7 @@ BOOST_AUTO_TEST_CASE( margin_call_limit_test ) BOOST_CHECK_THROW(db.get_object(below_id), fc::exception); BOOST_CHECK(call.get_debt() == bitusd.amount(210)); BOOST_CHECK(call.get_collateral() == core.amount(803)); + */ } catch( const fc::exception& e) { edump((e.to_detail_string())); throw; @@ -1671,6 +1062,8 @@ BOOST_AUTO_TEST_CASE( margin_call_limit_test ) BOOST_AUTO_TEST_CASE( margin_call_limit_test_protected ) { try { + FC_ASSERT( "TODO - Reimplement with new short semantics" ); + /* const asset_object& bitusd = create_bitasset( "BITUSD" ); const asset_object& core = get_asset( GRAPHENE_SYMBOL ); @@ -1698,6 +1091,7 @@ BOOST_AUTO_TEST_CASE( margin_call_limit_test_protected ) auto unmatched = create_sell_order( buyer1, bitusd.amount(990), core.amount(1500) ); if( unmatched ) edump((*unmatched)); BOOST_REQUIRE( unmatched ); + */ } catch( const fc::exception& e) { edump((e.to_detail_string())); @@ -1707,6 +1101,8 @@ BOOST_AUTO_TEST_CASE( margin_call_limit_test_protected ) BOOST_AUTO_TEST_CASE( dont_margin_call_limit_test ) { try { + FC_ASSERT( "TODO - Reimplement with new short semantics" ); + /* const asset_object& bitusd = create_bitasset( "BITUSD" ); const asset_object& core = get_asset( GRAPHENE_SYMBOL ); @@ -1733,6 +1129,7 @@ BOOST_AUTO_TEST_CASE( dont_margin_call_limit_test ) auto unmatched = create_sell_order( buyer1, bitusd.amount(990), core.amount(1100) ); if( unmatched ) edump((*unmatched)); BOOST_REQUIRE( unmatched ); + */ } catch( const fc::exception& e) { edump((e.to_detail_string())); @@ -1742,6 +1139,8 @@ BOOST_AUTO_TEST_CASE( dont_margin_call_limit_test ) BOOST_AUTO_TEST_CASE( margin_call_short_test ) { try { + FC_ASSERT( "TODO - Reimplement with new short semantics" ); + /* const asset_object& bitusd = create_bitasset( "BITUSD" ); const asset_object& core = get_asset( GRAPHENE_SYMBOL ); @@ -1769,6 +1168,7 @@ BOOST_AUTO_TEST_CASE( margin_call_short_test ) auto unmatched = create_short( buyer1, bitusd.amount(990), core.amount(1500) ); if( unmatched ) edump((*unmatched)); BOOST_REQUIRE( !unmatched ); + */ } catch( const fc::exception& e) { edump((e.to_detail_string())); @@ -1778,6 +1178,8 @@ BOOST_AUTO_TEST_CASE( margin_call_short_test ) BOOST_AUTO_TEST_CASE( margin_call_short_test_limit_protected ) { try { + FC_ASSERT( "TODO - Reimplement with new short semantics" ); + /* const asset_object& bitusd = create_bitasset( "BITUSD" ); const asset_object& core = get_asset( GRAPHENE_SYMBOL ); @@ -1805,6 +1207,7 @@ BOOST_AUTO_TEST_CASE( margin_call_short_test_limit_protected ) auto unmatched = create_short( buyer1, bitusd.amount(990), core.amount(1500) ); if( unmatched ) edump((*unmatched)); BOOST_REQUIRE( unmatched ); + */ } catch( const fc::exception& e) { edump((e.to_detail_string())); @@ -2032,66 +1435,12 @@ BOOST_AUTO_TEST_CASE( unimp_bulk_discount_test ) */ BOOST_AUTO_TEST_CASE( margin_call_black_swan ) { try { - const asset_object& bitusd = create_bitasset( "BITUSD" ); - const asset_object& core = get_asset( GRAPHENE_SYMBOL ); - - db.modify( bitusd.bitasset_data(db), [&]( asset_bitasset_data_object& usd ){ - usd.current_feed.call_limit = core.amount(30) / bitusd.amount(1); - }); - - const account_object& shorter1 = create_account( "shorter1" ); - const account_object& shorter2 = create_account( "shorter2" ); - const account_object& buyer1 = create_account( "buyer1" ); - const account_object& buyer2 = create_account( "buyer2" ); - - transfer( genesis_account(db), shorter1, asset( 10000 ) ); - transfer( genesis_account(db), shorter2, asset( 10000 ) ); - transfer( genesis_account(db), buyer1, asset( 10000 ) ); - transfer( genesis_account(db), buyer2, asset( 10000 ) ); - - BOOST_REQUIRE( create_sell_order( buyer1, asset(1000), bitusd.amount(1000) ) ); - BOOST_REQUIRE( !create_short( shorter1, bitusd.amount(1000), asset(1000) ) ); - BOOST_REQUIRE_EQUAL( get_balance(buyer1, bitusd), 990 ); // 1000 - 1% fee - - verify_asset_supplies(); - ilog( "=================================== START===================================\n\n"); - // this should cause the highest bid to below the margin call threshold - // which means it should be filled by the cover, except the cover does not - // have enough collateral and thus a black swan event should occur. - auto unmatched = create_sell_order( buyer1, bitusd.amount(990), core.amount(5000) ); - if( unmatched ) edump((*unmatched)); - /** black swans should cause all of the bitusd to be converted into backing - * asset at the price of the least collateralized call position at the time. This - * means that this sell order would be removed. - */ - BOOST_REQUIRE( !unmatched ); - + FC_ASSERT( "TODO - Reimplement with new short semantics" ); } catch( const fc::exception& e) { edump((e.to_detail_string())); throw; } } -/** - * This test sets up a far more complex blackswan scenerio where the - * BitUSD exists in the following places: - * - * 0) Limit Orders for the BitAsset - * 1) Limit Orders for UIA Assets - * 2) Short Orders for BitAsset backed by BitUSD - * 3) Call Orders for BitAsset backed by BitUSD - * 4) Issuer Fees - * - * This test should fail until the black swan handling code can - * perform a recursive blackswan for any other BitAssets that use - * BitUSD as collateral. - */ -BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( unimp_advanced_black_swan, 1 ) -BOOST_AUTO_TEST_CASE( unimp_advanced_black_swan ) -{ - BOOST_FAIL( "not implemented" ); -} - - /** * Assume the referrer gets 99% of transaction fee diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 67f11d19..1d1db4b1 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -337,7 +337,6 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) asset_publish_feed_operation op({asset(), vikram_id}); op.asset_id = bit_usd_id; op.feed.call_limit = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); - op.feed.short_limit = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(10)); // We'll expire margins after a month op.feed.max_margin_period_sec = fc::days(30).to_seconds(); // Accept defaults for required collateral @@ -346,37 +345,28 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) const asset_bitasset_data_object& bitasset = bit_usd.bitasset_data(db); BOOST_CHECK(bitasset.current_feed.call_limit.to_real() == GRAPHENE_BLOCKCHAIN_PRECISION / 30.0); - BOOST_CHECK_EQUAL(bitasset.current_feed.short_limit.to_real(), 10.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.max_margin_period_sec == fc::days(30).to_seconds()); - BOOST_CHECK(bitasset.current_feed.required_initial_collateral == GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO); BOOST_CHECK(bitasset.current_feed.required_maintenance_collateral == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = ben_id; op.feed.call_limit = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); - op.feed.short_limit = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(20)); op.feed.max_margin_period_sec = fc::days(10).to_seconds(); trx.operations.back() = op; db.push_transaction(trx, ~0); BOOST_CHECK_EQUAL(bitasset.current_feed.call_limit.to_real(), GRAPHENE_BLOCKCHAIN_PRECISION / 25.0); - BOOST_CHECK_EQUAL(bitasset.current_feed.short_limit.to_real(), 20.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.max_margin_period_sec == fc::days(30).to_seconds()); - BOOST_CHECK(bitasset.current_feed.required_initial_collateral == GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO); BOOST_CHECK(bitasset.current_feed.required_maintenance_collateral == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = dan_id; op.feed.call_limit = price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); - op.feed.short_limit = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(10)); op.feed.max_margin_period_sec = fc::days(100).to_seconds(); - op.feed.required_initial_collateral = 1001; op.feed.required_maintenance_collateral = 1000; trx.operations.back() = op; db.push_transaction(trx, ~0); BOOST_CHECK_EQUAL(bitasset.current_feed.call_limit.to_real(), GRAPHENE_BLOCKCHAIN_PRECISION / 30.0); - BOOST_CHECK_EQUAL(bitasset.current_feed.short_limit.to_real(), 10.0 / GRAPHENE_BLOCKCHAIN_PRECISION); BOOST_CHECK(bitasset.current_feed.max_margin_period_sec == fc::days(30).to_seconds()); - BOOST_CHECK(bitasset.current_feed.required_initial_collateral == GRAPHENE_DEFAULT_INITIAL_COLLATERAL_RATIO); BOOST_CHECK(bitasset.current_feed.required_maintenance_collateral == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = nathan_id; @@ -451,6 +441,8 @@ BOOST_AUTO_TEST_CASE( witness_create ) BOOST_AUTO_TEST_CASE( global_settle_test ) { try { ACTORS((nathan)(ben)(valentine)(dan)); + FC_ASSERT( !"TODO - Reimplement this" ); + /* asset_id_type bit_usd_id = create_bitasset("BITUSD", nathan_id, 100, global_settle | charge_market_fee).get_id(); transfer(genesis_account, ben_id, asset(10000)); transfer(genesis_account, valentine_id, asset(10000)); @@ -489,6 +481,7 @@ BOOST_AUTO_TEST_CASE( global_settle_test ) BOOST_CHECK_EQUAL(get_balance(ben_id, asset_id_type()), 10091); BOOST_CHECK_EQUAL(get_balance(dan_id, bit_usd_id), 0); BOOST_CHECK_EQUAL(get_balance(dan_id, asset_id_type()), 9850); + */ } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE( worker_create_test ) @@ -680,6 +673,8 @@ BOOST_AUTO_TEST_CASE( refund_worker_test ) BOOST_AUTO_TEST_CASE( force_settlement_unavailable ) { try { + FC_ASSERT( !"TODO - Reimplement this" ); + /* auto private_key = generate_private_key("genesis"); account_id_type nathan_id = create_account("nathan").get_id(); account_id_type shorter1_id = create_account("shorter1").get_id(); @@ -735,7 +730,6 @@ BOOST_AUTO_TEST_CASE( force_settlement_unavailable ) price_feed feed; feed.settlement_price = price(asset(1),asset(1, bit_usd)); feed.call_limit = price::min(0, bit_usd); - feed.short_limit = price::min(bit_usd, 0); pop.feed = feed; trx.operations.push_back(pop); } @@ -793,6 +787,7 @@ BOOST_AUTO_TEST_CASE( force_settlement_unavailable ) BOOST_CHECK(db.get_index_type().indices().empty()); BOOST_CHECK_EQUAL(get_balance(nathan_id, bit_usd), bit_usd(db).dynamic_data(db).current_supply.value); } + */ } FC_LOG_AND_RETHROW() } // TODO: Write linear VBO tests