From 26f47189f0820db268c93815555d5bf4ea4728f2 Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Mon, 7 Nov 2016 10:18:18 +0100 Subject: [PATCH] Creating default dividend asset --- libraries/chain/db_init.cpp | 54 +++++++++++++++++++ .../include/graphene/chain/asset_object.hpp | 3 ++ .../chain/include/graphene/chain/config.hpp | 2 + .../graphene/chain/protocol/asset_ops.hpp | 2 + libraries/chain/tournament_object.cpp | 4 +- 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 5a94e827..9c90bf4c 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -327,6 +327,16 @@ void database::init_genesis(const genesis_state_type& genesis_state) a.network_fee_percentage = 0; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT; }).get_id() == GRAPHENE_PROXY_TO_SELF_ACCOUNT); + FC_ASSERT(create([this](account_object& a) { + a.name = "default-dividend-distribution"; + a.statistics = create([&](account_statistics_object& s){s.owner = a.id;}).id; + a.owner.weight_threshold = 1; + a.active.weight_threshold = 1; + a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_PROXY_TO_SELF_ACCOUNT; + a.membership_expiration_date = time_point_sec::maximum(); + a.network_fee_percentage = 0; + a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT; + }).get_id() == TOURNAMENT_RAKE_FEE_ACCOUNT_ID); // Create more special accounts while( true ) @@ -369,6 +379,46 @@ void database::init_genesis(const genesis_state_type& genesis_state) }); assert( asset_id_type(core_asset.id) == asset().asset_id ); assert( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) ); + + // Create default dividend asset + const asset_dynamic_data_object& dyn_asset1 = + create([&](asset_dynamic_data_object& a) { + a.current_supply = GRAPHENE_MAX_SHARE_SUPPLY; + }); + const asset_dividend_data_object& div_asset1 = + create([&](asset_dividend_data_object& a) { + a.options.minimum_distribution_interval = 3*24*60*60; + a.options.minimum_fee_percentage = 10*GRAPHENE_1_PERCENT; + a.options.next_payout_time = genesis_state.initial_timestamp + fc::hours(1); + a.options.payout_interval = 7*24*60*60; + a.dividend_distribution_account = TOURNAMENT_RAKE_FEE_ACCOUNT_ID; + }); + const asset_bitasset_data_object& bit_asset1 = + create([&](asset_bitasset_data_object& a) { + a.current_feed.maintenance_collateral_ratio = 1750; + a.current_feed.maximum_short_squeeze_ratio = 1500; + a.current_feed_publication_time = genesis_state.initial_timestamp + fc::hours(1); + }); + + const asset_object& default_asset = + create( [&]( asset_object& a ) { + a.symbol = "DEF"; + a.options.max_market_fee = + a.options.max_supply = genesis_state.max_core_supply; + a.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS; + a.options.flags = 0; + a.options.issuer_permissions = 79; + a.issuer = TOURNAMENT_RAKE_FEE_ACCOUNT_ID; + a.options.core_exchange_rate.base.amount = 1; + a.options.core_exchange_rate.base.asset_id = asset_id_type(0); + a.options.core_exchange_rate.quote.amount = 1; + a.options.core_exchange_rate.quote.asset_id = asset_id_type(1); + a.dynamic_asset_data_id = dyn_asset1.id; + a.dividend_data_id = div_asset1.id; + a.bitasset_data_id = bit_asset1.id; + }); + assert( default_asset.id == asset_id_type(1) ); + // Create more special assets while( true ) { @@ -468,6 +518,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) const auto& accounts_by_name = get_index_type().indices().get(); auto get_account_id = [&accounts_by_name](const string& name) { auto itr = accounts_by_name.find(name); + if (itr == accounts_by_name.end()) return GRAPHENE_NULL_ACCOUNT; FC_ASSERT(itr != accounts_by_name.end(), "Unable to find account '${acct}'. Did you forget to add a record for it to initial_accounts?", ("acct", name)); @@ -634,6 +685,8 @@ void database::init_genesis(const genesis_state_type& genesis_state) { total_supplies[ asset_id_type(0) ] = GRAPHENE_MAX_SHARE_SUPPLY; } + total_debts[ asset_id_type(1) ] = + total_supplies[ asset_id_type(1) ] = 0; const auto& idx = get_index_type().indices().get(); auto it = idx.begin(); @@ -653,6 +706,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) elog( "Genesis for asset ${aname} is not balanced\n" " Debt is ${debt}\n" " Supply is ${supply}\n", + ("aname", debt_itr->first) ("debt", debt_itr->second) ("supply", supply_itr->second) ); diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 70f8443d..3e2fd24d 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -352,6 +352,8 @@ FC_REFLECT_DERIVED( graphene::chain::asset_dividend_data_object, (graphene::db:: (options) (last_scheduled_payout_time) (last_payout_time ) + (last_scheduled_distribution_time) + (last_distribution_time) (dividend_distribution_account) ) @@ -369,4 +371,5 @@ FC_REFLECT_DERIVED( graphene::chain::asset_object, (graphene::db::object), (dynamic_asset_data_id) (bitasset_data_id) (buyback_account) + (dividend_data_id) ) diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 089f9c3b..0c9f4a88 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -168,6 +168,8 @@ #define GRAPHENE_TEMP_ACCOUNT (graphene::chain::account_id_type(4)) /// Represents the canonical account for specifying you will vote directly (as opposed to a proxy) #define GRAPHENE_PROXY_TO_SELF_ACCOUNT (graphene::chain::account_id_type(5)) +/// +#define TOURNAMENT_RAKE_FEE_ACCOUNT_ID (graphene::chain::account_id_type(6)) /// Sentinel value used in the scheduler. #define GRAPHENE_NULL_WITNESS (graphene::chain::witness_id_type(0)) ///@} diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index ca82526c..62c9c9a2 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -595,6 +595,8 @@ FC_REFLECT( graphene::chain::asset_options, FC_REFLECT( graphene::chain::dividend_asset_options, (next_payout_time) (payout_interval) + (minimum_fee_percentage) + (minimum_distribution_interval) (extensions) ) diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index 07e6254c..95c15ddb 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -268,11 +268,9 @@ namespace graphene { namespace chain { assert(event.match.match_winners.size() == 1); const account_id_type& winner = *event.match.match_winners.begin(); uint16_t rake_fee_percentage = event.db.get_global_properties().parameters.rake_fee_percentage; - share_type rake_amount = (fc::uint128_t(fsm.tournament_obj->prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT).to_uint64(); -#ifdef TOURNAMENT_RAKE_FEE_ACCOUNT_ID + share_type rake_amount = (fc::uint128_t(fsm.tournament_obj->prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64(); event.db.adjust_balance(account_id_type(TOURNAMENT_RAKE_FEE_ACCOUNT_ID), asset(rake_amount, fsm.tournament_obj->options.buy_in.asset_id)); -#endif event.db.adjust_balance(winner, asset(fsm.tournament_obj->prize_pool - rake_amount, fsm.tournament_obj->options.buy_in.asset_id)); }