Skip to content

Commit

Permalink
Move force_settle_fee_percent from asset_options to bitasset_options
Browse files Browse the repository at this point in the history
  • Loading branch information
christophersanborn committed May 7, 2020
1 parent c4c8b6a commit fbd832b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
18 changes: 11 additions & 7 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace detail {
}
}

void check_asset_options_hf_bsip87(const fc::time_point_sec& block_time, const asset_options& options)
void check_bitasset_options_hf_bsip87(const fc::time_point_sec& block_time, const bitasset_options& options)
{
// HF_REMOVABLE: Following hardfork check should be removable after hardfork date passes:
FC_ASSERT( !options.extensions.value.force_settle_fee_percent.valid()
Expand Down Expand Up @@ -94,7 +94,10 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o
// Hardfork Checks:
detail::check_asset_options_hf_1774(now, op.common_options);
detail::check_asset_options_hf_bsip81(now, op.common_options);
detail::check_asset_options_hf_bsip87(now, op.common_options); // HF_REMOVABLE
if( op.bitasset_opts ) {
detail::check_bitasset_options_hf_bsip77( now, *op.bitasset_opts );
detail::check_bitasset_options_hf_bsip87( now, *op.bitasset_opts ); // HF_REMOVABLE
}

const auto& chain_parameters = d.get_global_properties().parameters;
FC_ASSERT( op.common_options.whitelist_authorities.size() <= chain_parameters.maximum_asset_whitelist_authorities );
Expand Down Expand Up @@ -128,7 +131,6 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o

if( op.bitasset_opts )
{
detail::check_bitasset_options_hf_bsip77( now, *op.bitasset_opts );
const asset_object& backing = op.bitasset_opts->short_backing_asset(d);
if( backing.is_market_issued() )
{
Expand Down Expand Up @@ -317,7 +319,6 @@ void_result asset_update_evaluator::do_evaluate(const asset_update_operation& o)
// Hardfork Checks:
detail::check_asset_options_hf_1774(now, o.new_options);
detail::check_asset_options_hf_bsip81(now, o.new_options);
detail::check_asset_options_hf_bsip87(now, o.new_options); // HF_REMOVABLE

const asset_object& a = o.asset_to_update(d);
auto a_copy = a;
Expand Down Expand Up @@ -434,7 +435,7 @@ void_result asset_update_issuer_evaluator::do_apply(const asset_update_issuer_op
* @param true if after hf 922/931 (if nothing triggers, this and the logic that depends on it
* should be removed).
*/
void check_children_of_bitasset(database& d, const asset_update_bitasset_operation& op,
void check_children_of_bitasset(const database& d, const asset_update_bitasset_operation& op,
const asset_object& new_backing_asset)
{
// no need to do these checks if the new backing asset is CORE
Expand Down Expand Up @@ -463,9 +464,12 @@ void check_children_of_bitasset(database& d, const asset_update_bitasset_operati

void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bitasset_operation& op)
{ try {
database& d = db();
const database& d = db();
const time_point_sec now = d.head_block_time();

detail::check_bitasset_options_hf_bsip77( d.head_block_time(), op.new_options );
// Hardfork Checks:
detail::check_bitasset_options_hf_bsip77( now, op.new_options );
detail::check_bitasset_options_hf_bsip87( now, op.new_options ); // HF_REMOVABLE

const asset_object& asset_obj = op.asset_to_update(d);

Expand Down
13 changes: 7 additions & 6 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,14 +1408,15 @@ asset database::pay_force_settle_fees(const asset_object& collecting_asset, cons
{
FC_ASSERT( collecting_asset.get_id() != collat_receives.asset_id );

const asset_object& collat_asset = get(collat_receives.asset_id);
if( !collecting_asset.options.extensions.value.force_settle_fee_percent.valid()
|| *collecting_asset.options.extensions.value.force_settle_fee_percent == 0 )
return collat_asset.amount(0);
const bitasset_options& collecting_bitasset_opts = collecting_asset.bitasset_data(*this).options;

if( !collecting_bitasset_opts.extensions.value.force_settle_fee_percent.valid()
|| *collecting_bitasset_opts.extensions.value.force_settle_fee_percent == 0 )
return asset{ 0, collat_receives.asset_id };

auto value = detail::calculate_percent(collat_receives.amount,
*collecting_asset.options.extensions.value.force_settle_fee_percent);
asset settle_fee = collat_asset.amount(value);
*collecting_bitasset_opts.extensions.value.force_settle_fee_percent);
asset settle_fee = asset{ value, collat_receives.asset_id };

// Deposit fee in asset's dynamic data object:
if( value > 0) {
Expand Down
17 changes: 10 additions & 7 deletions libraries/chain/proposal_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace detail {
void check_asset_options_hf_1774(const fc::time_point_sec& block_time, const asset_options& options);
void check_bitasset_options_hf_bsip77(const fc::time_point_sec& block_time, const bitasset_options& options);
void check_asset_options_hf_bsip81(const fc::time_point_sec& block_time, const asset_options& options);
void check_asset_options_hf_bsip87(const fc::time_point_sec& block_time,
const asset_options& options); // HF_REMOVABLE
void check_bitasset_options_hf_bsip87(const fc::time_point_sec& block_time,
const bitasset_options& options); // HF_REMOVABLE
void check_asset_claim_fees_hardfork_87_74_collatfee(const fc::time_point_sec& block_time,
const asset_claim_fees_operation& op); // HF_REMOVABLE
}
Expand All @@ -54,23 +54,26 @@ struct proposal_operation_hardfork_visitor
void operator()(const graphene::chain::asset_create_operation &v) const {

detail::check_asset_options_hf_1774(block_time, v.common_options);
if( v.bitasset_opts.valid() )
detail::check_bitasset_options_hf_bsip77( block_time, *v.bitasset_opts );
detail::check_asset_options_hf_bsip81(block_time, v.common_options);
detail::check_asset_options_hf_bsip87(block_time, v.common_options); // HF_REMOVABLE
if( v.bitasset_opts.valid() ) {
detail::check_bitasset_options_hf_bsip77( block_time, *v.bitasset_opts );
detail::check_bitasset_options_hf_bsip87( block_time, *v.bitasset_opts ); // HF_REMOVABLE
}

}

void operator()(const graphene::chain::asset_update_operation &v) const {

detail::check_asset_options_hf_1774(block_time, v.new_options);
detail::check_asset_options_hf_bsip81(block_time, v.new_options);
detail::check_asset_options_hf_bsip87(block_time, v.new_options); // HF_REMOVABLE

}

void operator()(const graphene::chain::asset_update_bitasset_operation &v) const {
// HARDFORK_BSIP_77

detail::check_bitasset_options_hf_bsip77( block_time, v.new_options );
detail::check_bitasset_options_hf_bsip87( block_time, v.new_options ); // HF_REMOVABLE

}

void operator()(const graphene::chain::asset_claim_fees_operation &v) const {
Expand Down
6 changes: 4 additions & 2 deletions libraries/protocol/asset_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ void bitasset_options::validate() const
FC_ASSERT( *extensions.value.initial_collateral_ratio >= GRAPHENE_MIN_COLLATERAL_RATIO );
FC_ASSERT( *extensions.value.initial_collateral_ratio <= GRAPHENE_MAX_COLLATERAL_RATIO );
}

if( extensions.value.force_settle_fee_percent.valid() )
FC_ASSERT( *extensions.value.force_settle_fee_percent <= GRAPHENE_100_PERCENT );

}

void asset_options::validate()const
Expand Down Expand Up @@ -252,8 +256,6 @@ void asset_options::validate()const
}
if( extensions.value.reward_percent.valid() )
FC_ASSERT( *extensions.value.reward_percent <= GRAPHENE_100_PERCENT );
if( extensions.value.force_settle_fee_percent.valid() )
FC_ASSERT( *extensions.value.force_settle_fee_percent <= GRAPHENE_100_PERCENT );
}

void asset_claim_fees_operation::validate()const {
Expand Down
9 changes: 4 additions & 5 deletions libraries/protocol/include/graphene/protocol/asset_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ namespace graphene { namespace protocol {
fc::optional<flat_set<account_id_type>> whitelist_market_fee_sharing;
// After BSIP81 activation, taker_fee_percent is the taker fee
fc::optional<uint16_t> taker_fee_percent;
// MERGE NOTE: BSIP-74 additions here
fc::optional<uint16_t> force_settle_fee_percent; // BSIP-87
};
typedef extension<additional_asset_options> additional_asset_options_t;

Expand Down Expand Up @@ -108,7 +106,8 @@ namespace graphene { namespace protocol {
/// After BSIP77, when creating a new debt position or updating an existing position,
/// the position will be checked against this parameter.
/// Unused for prediction markets, although we allow it to be set for simpler implementation
fc::optional<uint16_t> initial_collateral_ratio;
fc::optional<uint16_t> initial_collateral_ratio; // BSIP-77
fc::optional<uint16_t> force_settle_fee_percent; // BSIP-87
};

/// Time before a price feed expires
Expand Down Expand Up @@ -564,7 +563,7 @@ FC_REFLECT( graphene::protocol::asset_options,
(extensions)
)

FC_REFLECT( graphene::protocol::bitasset_options::ext, (initial_collateral_ratio) )
FC_REFLECT( graphene::protocol::bitasset_options::ext, (initial_collateral_ratio)(force_settle_fee_percent) )

FC_REFLECT( graphene::protocol::bitasset_options,
(feed_lifetime_sec)
Expand All @@ -577,7 +576,7 @@ FC_REFLECT( graphene::protocol::bitasset_options,
)

FC_REFLECT( graphene::protocol::additional_asset_options,
(reward_percent)(whitelist_market_fee_sharing)(taker_fee_percent)(force_settle_fee_percent) )
(reward_percent)(whitelist_market_fee_sharing)(taker_fee_percent) )

FC_REFLECT( graphene::protocol::asset_create_operation::fee_parameters_type,
(symbol3)(symbol4)(long_symbol)(price_per_kbyte) )
Expand Down

0 comments on commit fbd832b

Please sign in to comment.