Resolve #94
Core exchange rate is now redundantly stored in price feed for bitassets, and updated when the median feed changes. This allows feed producers to update the core exchange rate. Redundant storage is necessary, because the core exchange rate is needed for user-issued assets as well as market issued assets.
This commit is contained in:
parent
0936f9b5f2
commit
5b55ab71ea
4 changed files with 33 additions and 15 deletions
|
|
@ -313,6 +313,9 @@ void_result asset_update_feed_producers_evaluator::do_apply(const asset_update_f
|
|||
a.feeds[*itr];
|
||||
a.update_median_feeds(db().head_block_time());
|
||||
});
|
||||
db().modify(o.asset_to_update(db()), [this](asset_object& a) {
|
||||
a.options.core_exchange_rate = bitasset_to_update->current_feed.core_exchange_rate;
|
||||
});
|
||||
db().check_call_orders( o.asset_to_update(db()) );
|
||||
|
||||
return void_result();
|
||||
|
|
@ -429,9 +432,12 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope
|
|||
a.feeds[o.publisher] = make_pair(d.head_block_time(), o.feed);
|
||||
a.update_median_feeds(d.head_block_time());
|
||||
});
|
||||
d.modify(base, [&d](asset_object& a) {
|
||||
a.options.core_exchange_rate = a.bitasset_data(d).current_feed.core_exchange_rate;
|
||||
});
|
||||
|
||||
/// TODO: optimization: only do this if the median feed actually changed, otherwise there is no point
|
||||
db().check_call_orders( base );
|
||||
db().check_call_orders(base);
|
||||
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW((o)) }
|
||||
|
|
|
|||
|
|
@ -219,16 +219,24 @@ void database::clear_expired_orders()
|
|||
|
||||
void database::update_expired_feeds()
|
||||
{
|
||||
auto& asset_idx = get_index_type<asset_bitasset_data_index>();
|
||||
for( const asset_bitasset_data_object* b : asset_idx )
|
||||
if( b->feed_is_expired(head_block_time()) )
|
||||
auto& asset_idx = get_index_type<asset_index>().indices();
|
||||
for( const asset_object& a : asset_idx )
|
||||
{
|
||||
if( !a.is_market_issued() )
|
||||
continue;
|
||||
|
||||
const asset_bitasset_data_object& b = a.bitasset_data(*this);
|
||||
if( b.feed_is_expired(head_block_time()) )
|
||||
{
|
||||
modify(*b, [this](asset_bitasset_data_object& a) {
|
||||
modify(b, [this](asset_bitasset_data_object& a) {
|
||||
a.update_median_feeds(head_block_time());
|
||||
});
|
||||
|
||||
check_call_orders( b->current_feed.settlement_price.base.asset_id(*this) );
|
||||
modify(a, [&b](asset_object& a) {
|
||||
a.options.core_exchange_rate = b.current_feed.core_exchange_rate;
|
||||
});
|
||||
check_call_orders(b.current_feed.settlement_price.base.asset_id(*this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void database::update_withdraw_permissions()
|
||||
|
|
|
|||
|
|
@ -145,6 +145,9 @@ namespace graphene { namespace chain {
|
|||
*/
|
||||
price settlement_price;
|
||||
|
||||
/// Price at which automatically exchanging this asset for CORE from fee pool occurs (used for paying fees)
|
||||
price core_exchange_rate;
|
||||
|
||||
/** Fixed point between 1.000 and 10.000, implied fixed point denominator is GRAPHENE_COLLATERAL_RATIO_DENOM */
|
||||
uint16_t maintenance_collateral_ratio = GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO;
|
||||
|
||||
|
|
@ -183,7 +186,8 @@ namespace graphene { namespace chain {
|
|||
FC_REFLECT( graphene::chain::asset, (amount)(asset_id) )
|
||||
FC_REFLECT( graphene::chain::price, (base)(quote) )
|
||||
|
||||
#define GRAPHENE_PRICE_FEED_FIELDS (settlement_price)(maintenance_collateral_ratio)(maximum_short_squeeze_ratio)
|
||||
#define GRAPHENE_PRICE_FEED_FIELDS (settlement_price)(maintenance_collateral_ratio)(maximum_short_squeeze_ratio) \
|
||||
(core_exchange_rate)
|
||||
|
||||
FC_REFLECT( graphene::chain::price_feed, GRAPHENE_PRICE_FEED_FIELDS )
|
||||
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ const asset_object& database_fixture::create_bitasset(
|
|||
creator.fee = asset();
|
||||
creator.symbol = name;
|
||||
creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
|
||||
creator.precision = 2;
|
||||
creator.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS;
|
||||
creator.common_options.market_fee_percent = market_fee_percent;
|
||||
creator.common_options.issuer_permissions = flags;
|
||||
creator.common_options.flags = flags & ~global_settle;
|
||||
|
|
|
|||
Loading…
Reference in a new issue