Skip to content

Commit

Permalink
Disallow increasing debt if still calling cryptonomex#672
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Apr 7, 2018
1 parent 9224047 commit 3ad74dc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
const call_order_object* call_obj = nullptr;

optional<price> old_collateralization;
optional<share_type> old_debt;

if( itr == call_idx.end() )
{
Expand All @@ -232,6 +233,7 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
{
call_obj = &*itr;
old_collateralization = call_obj->collateralization();
old_debt = call_obj->debt;

d.modify( *call_obj, [&]( call_order_object& call ){
call.collateral += o.delta_collateral.amount;
Expand All @@ -244,8 +246,7 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
});
}

auto debt = call_obj->get_debt();
if( debt.amount == 0 )
if( call_obj->debt == 0 )
{
FC_ASSERT( call_obj->collateral == 0 );
d.remove( *call_obj );
Expand Down Expand Up @@ -295,19 +296,22 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
("a", ~call_obj->call_price )("b", _bitasset_data->current_feed.settlement_price)
);
}
else // after hard fork, always allow call order to be updated if collateral ratio is increased
else // after hard fork, always allow call order to be updated if collateral ratio is increased and debt is not increased
{
// We didn't fill any call orders. This may be because we
// aren't in margin call territory, or it may be because there
// were no matching orders. In the latter case,
// if collateral ratio is not increased, we throw.
// if collateral ratio is not increased or debt is increased, we throw.
// be here, we know no margin call was executed,
// so call_obj's collateral ratio should be set only by op
FC_ASSERT( ( old_collateralization.valid() && call_obj->collateralization() > *old_collateralization )
FC_ASSERT( ( old_collateralization.valid() && call_obj->debt <= *old_debt
&& call_obj->collateralization() > *old_collateralization )
|| ~call_obj->call_price < _bitasset_data->current_feed.settlement_price,
"Can only update to higher collateral ratio if it would trigger a margin call that cannot be fully filled",
"Can only increase collateral ratio without increasing debt if would trigger a margin call that cannot be fully filled",
("new_call_price", ~call_obj->call_price )
("settlement_price", _bitasset_data->current_feed.settlement_price)
("old_debt", old_debt)
("new_debt", call_obj->debt)
("old_collateralization", old_collateralization)
("new_collateralization", call_obj->collateralization() )
);
Expand Down

0 comments on commit 3ad74dc

Please sign in to comment.