Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1800: Temp-account market fee sharing #1870

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,11 @@ asset database::pay_market_fees(const account_object& seller, const asset_object
FC_ASSERT( reward < issuer_fees, "Market reward should be less than issuer fees");
// cut referrer percent from reward
auto registrar_reward = reward;

auto registrar = ( seller.registrar == GRAPHENE_TEMP_ACCOUNT && head_block_time() >= HARDFORK_CORE_1800_TIME )
? GRAPHENE_COMMITTEE_ACCOUNT
: seller.registrar;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be done for both registrar and referrer.


if( seller.referrer != seller.registrar )
{
const auto referrer_rewards_value = detail::calculate_percent( reward.amount,
Expand All @@ -1263,7 +1268,8 @@ asset database::pay_market_fees(const account_object& seller, const asset_object
deposit_market_fee_vesting_balance(seller.referrer, referrer_reward);
}
}
deposit_market_fee_vesting_balance(seller.registrar, registrar_reward);
deposit_market_fee_vesting_balance(registrar, registrar_reward);

}
}
}
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/hardfork.d/CORE_1800.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// bitshares-core issue #1800 Fix "Temp-account market fee sharing"
#ifndef HARDFORK_CORE_1800_TIME
#define HARDFORK_CORE_1800_TIME (fc::time_point_sec( 1600000000 )) // Tue, 23 Jul 2019 13:35:00 UTC
#endif
73 changes: 73 additions & 0 deletions tests/tests/market_fee_sharing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ struct reward_database_fixture : database_fixture
database_fixture::generate_block();
}

void generate_blocks_past_hf1800()
{
database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME );
database_fixture::generate_block();
}

asset core_asset(int64_t x )
{
return asset( x*core_precision );
Expand Down Expand Up @@ -431,18 +437,85 @@ BOOST_AUTO_TEST_CASE(create_actors)

const account_object alice = create_account("alice", izzyregistrar, izzyreferrer, 50/*0.5%*/);
const account_object bob = create_account("bob", izzyregistrar, izzyreferrer, 50/*0.5%*/);
const account_object old = create_account("old", GRAPHENE_TEMP_ACCOUNT(db), GRAPHENE_COMMITTEE_ACCOUNT(db), 50u);

// prepare users' balance
issue_uia( alice, jillcoin.amount( 20000000 ) );

transfer( committee_account, alice.get_id(), core_asset(1000) );
transfer( committee_account, bob.get_id(), core_asset(1000) );
transfer( committee_account, old.get_id(), core_asset(1000) );
transfer( committee_account, izzyregistrar.get_id(), core_asset(1000) );
transfer( committee_account, izzyreferrer.get_id(), core_asset(1000) );
}
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE(fee_shares_between_temp_acc_and_committee_acc)
{
try
{
INVOKE(create_actors);

generate_blocks_past_hf1268();
GET_ACTOR(jill);

constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT;
const asset_object &jillcoin = get_asset("JCOIN");

flat_set<account_id_type> whitelist;
update_asset(jill_id, jill_private_key, jillcoin.get_id(), jillcoin_reward_percent, whitelist);

BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0);
BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0);

GET_ACTOR(alice);
GET_ACTOR(old);

create_sell_order( alice, jillcoin.amount(100000), core_asset(1) );
create_sell_order( old, core_asset(1), jillcoin.amount(100000) );

BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0);
BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0);

}
FC_LOG_AND_RETHROW()

}

BOOST_AUTO_TEST_CASE(fee_do_not_shares_between_temp_acc_and_committee_acc)
{
try
{
INVOKE(create_actors);

generate_blocks_past_hf1800();
GET_ACTOR(jill);

constexpr auto jillcoin_reward_percent = 2*GRAPHENE_1_PERCENT;
const asset_object &jillcoin = get_asset("JCOIN");

flat_set<account_id_type> whitelist;
update_asset(jill_id, jill_private_key, jillcoin.get_id(), jillcoin_reward_percent, whitelist);

BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0);
BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0);

GET_ACTOR(alice);
GET_ACTOR(old);

create_sell_order( alice, jillcoin.amount(100000), core_asset(1) );
create_sell_order( old, core_asset(1), jillcoin.amount(100000) );


BOOST_CHECK_EQUAL( get_market_fee_reward( GRAPHENE_TEMP_ACCOUNT(db), jillcoin), 0);
BOOST_CHECK_GT( get_market_fee_reward( GRAPHENE_COMMITTEE_ACCOUNT(db), jillcoin), 0);

}
FC_LOG_AND_RETHROW()

}

BOOST_AUTO_TEST_CASE(white_list_is_empty_test)
{
try
Expand Down