Skip to content

Commit

Permalink
Update derived data when ICR changed
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Apr 24, 2020
1 parent 4f02fcf commit 9963c8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
11 changes: 11 additions & 0 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ static bool update_bitasset_object_options(
is_witness_or_committee_fed = true;
}

// check if ICR will change
const auto& old_icr = bdo.options.extensions.value.initial_collateral_ratio;
const auto& new_icr = op.new_options.extensions.value.initial_collateral_ratio;
bool icr_changed = ( ( old_icr.valid() != new_icr.valid() )
|| ( old_icr.valid() && *old_icr != *new_icr ) );

bdo.options = op.new_options;

// are we modifying the underlying? If so, reset the feeds
Expand Down Expand Up @@ -610,6 +616,11 @@ static bool update_bitasset_object_options(
// We need to call check_call_orders if the settlement price changes after hardfork core-868-890
return ( after_hf_core_868_890 && ! (old_feed == bdo.current_feed) );
}
else if( icr_changed ) // feeds not updated, but ICR changed
{
// update data derived from ICR
bdo.refresh_current_initial_collateralization();
}

return false;
}
Expand Down
18 changes: 11 additions & 7 deletions libraries/chain/asset_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_poin
// update data derived from MCR
current_maintenance_collateralization = current_feed.maintenance_collateralization();
// update data derived from ICR
const auto& icr = options.extensions.value.initial_collateral_ratio;
if( icr.valid() && *icr > current_feed.maintenance_collateral_ratio ) // if ICR is set and is above MCR
current_initial_collateralization = current_feed.calculate_initial_collateralization( *icr );
else // if ICR is not set, or not above MCR
current_initial_collateralization = current_maintenance_collateralization;
refresh_current_initial_collateralization();
}
return;
}
Expand Down Expand Up @@ -120,6 +116,16 @@ void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_poin
// update data derived from MCR
current_maintenance_collateralization = current_feed.maintenance_collateralization();
// update data derived from ICR
refresh_current_initial_collateralization();
}
}

void asset_bitasset_data_object::refresh_current_initial_collateralization()
{
if( current_feed.settlement_price.is_null() )
current_initial_collateralization = price();
else
{
const auto& icr = options.extensions.value.initial_collateral_ratio;
if( icr.valid() && *icr > current_feed.maintenance_collateral_ratio ) // if ICR is set and is above MCR
current_initial_collateralization = current_feed.calculate_initial_collateralization( *icr );
Expand All @@ -128,8 +134,6 @@ void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_poin
}
}



asset asset_object::amount_from_string(string amount_string) const
{ try {
bool negative_found = false;
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ namespace graphene { namespace chain {
/// consistent.
price current_initial_collateralization;

/// Derive @ref current_initial_collateralization from other member variables.
/// Note: this assumes @ref current_maintenance_collateralization is fresh.
void refresh_current_initial_collateralization();

/// True if this asset implements a @ref prediction_market
bool is_prediction_market = false;

Expand Down

0 comments on commit 9963c8c

Please sign in to comment.