Skip to content

Commit

Permalink
Merge pull request #2133 from bitshares/old-hardfork-for-issue-1800
Browse files Browse the repository at this point in the history
Fix issue 1800: Temp-account market fee sharing
  • Loading branch information
abitmore authored Apr 11, 2020
2 parents f55a5c8 + 0a3a0a6 commit 70cc85f
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 7 deletions.
21 changes: 17 additions & 4 deletions libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,22 +1248,35 @@ asset database::pay_market_fees(const account_object* seller, const asset_object
}
// cut referrer percent from reward
auto registrar_reward = reward;
if( seller->referrer != seller->registrar )

auto registrar = seller->registrar;
auto referrer = seller->referrer;

// After HF core-1800, for funds going to temp-account, redirect to committee-account
if( head_block_time() >= HARDFORK_CORE_1800_TIME )
{
if( registrar == GRAPHENE_TEMP_ACCOUNT )
registrar = GRAPHENE_COMMITTEE_ACCOUNT;
if( referrer == GRAPHENE_TEMP_ACCOUNT )
referrer = GRAPHENE_COMMITTEE_ACCOUNT;
}

if( referrer != registrar )
{
const auto referrer_rewards_value = detail::calculate_percent( reward.amount,
seller->referrer_rewards_percentage );

if ( referrer_rewards_value > 0 && is_authorized_asset(*this, seller->referrer(*this), recv_asset) )
if ( referrer_rewards_value > 0 && is_authorized_asset(*this, referrer(*this), recv_asset) )
{
FC_ASSERT ( referrer_rewards_value <= reward.amount.value,
"Referrer reward shouldn't be greater than total reward" );
const asset referrer_reward = recv_asset.amount(referrer_rewards_value);
registrar_reward -= referrer_reward;
deposit_market_fee_vesting_balance(seller->referrer, referrer_reward);
deposit_market_fee_vesting_balance(referrer, referrer_reward);
}
}
if( registrar_reward.amount > 0 )
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
153 changes: 150 additions & 3 deletions tests/tests/market_fee_sharing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ struct reward_database_fixture : database_fixture
set_expiration(db, trx);
}

void generate_blocks_past_hf1800()
{
database_fixture::generate_blocks( HARDFORK_CORE_1800_TIME );
database_fixture::generate_block();
set_expiration(db, trx);
}

asset core_asset(int64_t x )
{
return asset( x*core_precision );
Expand Down Expand Up @@ -429,10 +436,11 @@ BOOST_AUTO_TEST_CASE(create_actors)
{
try
{
ACTORS((jill)(izzyregistrar)(izzyreferrer));
ACTORS((jill)(izzyregistrar)(izzyreferrer)(tempregistrar));

upgrade_to_lifetime_member(izzyregistrar);
upgrade_to_lifetime_member(izzyreferrer);
upgrade_to_lifetime_member(tempregistrar);

price price(asset(1, asset_id_type(1)), asset(1));
uint16_t market_fee_percent = 20 * GRAPHENE_1_PERCENT;
Expand All @@ -441,16 +449,155 @@ 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);
const account_object tmp = create_account("tmp", tempregistrar,
GRAPHENE_TEMP_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, tmp.get_id(), core_asset(1000) );
transfer( committee_account, izzyregistrar.get_id(), core_asset(1000) );
transfer( committee_account, izzyreferrer.get_id(), core_asset(1000) );
transfer( committee_account, tempregistrar.get_id(), core_asset(1000) );
}
FC_LOG_AND_RETHROW()
}

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

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_share_between_temp_acc_and_committee_acc_after_hf_1800)
{
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(fee_shares_to_temp_referrer_before_hf_1800)
{
try
{
INVOKE(create_actors);

GET_ACTOR(jill);
GET_ACTOR(tempregistrar);

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);
BOOST_CHECK_EQUAL( get_market_fee_reward( tempregistrar, jillcoin), 0);

GET_ACTOR(alice);
GET_ACTOR(tmp);

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

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

}
FC_LOG_AND_RETHROW()

}

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

generate_blocks_past_hf1800();
GET_ACTOR(jill);
GET_ACTOR(tempregistrar);

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);
BOOST_CHECK_EQUAL( get_market_fee_reward( tempregistrar, jillcoin), 0);

GET_ACTOR(alice);
GET_ACTOR(tmp);

create_sell_order( alice, jillcoin.amount(100000), core_asset(1) );
create_sell_order( tmp, 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);
BOOST_CHECK_GT( get_market_fee_reward( tempregistrar, jillcoin), 0);

}
FC_LOG_AND_RETHROW()

}

BOOST_AUTO_TEST_CASE(white_list_is_empty_test)
Expand Down Expand Up @@ -590,7 +737,7 @@ BOOST_AUTO_TEST_CASE(create_asset_via_proposal_test)
{
ACTOR(issuer);
price core_exchange_rate(asset(1, asset_id_type(1)), asset(1));

asset_create_operation create_op;
create_op.issuer = issuer.id;
create_op.fee = asset();
Expand Down Expand Up @@ -917,7 +1064,7 @@ BOOST_AUTO_TEST_CASE(white_list_asset_rewards_test)
}

BOOST_AUTO_TEST_CASE( create_vesting_balance_object_test )
{
{
/**
* Test checks that an account could have duplicates VBO (with the same asset_type)
* for any type of vesting_balance_type
Expand Down

0 comments on commit 70cc85f

Please sign in to comment.