Skip to content

Commit

Permalink
Release wax-1.7.0-1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jalbiero authored Sep 5, 2019
2 parents dfc2721 + 61fb772 commit 81fbfb0
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ IMPROVEMENTS:

BUG FIXES:

## Pending (wax-1.7.0-1.1.0)
## wax-1.7.0-1.2.0

BREAKING CHANGES:

FEATURES:
- [KEW-1394] Token burn for unstaking

IMPROVEMENTS:

BUG FIXES:

## wax-1.7.0-1.1.0

BREAKING CHANGES:

Expand Down
21 changes: 19 additions & 2 deletions contracts/eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,11 @@ namespace eosiosystem {
const auto claim_time = std::min(current_time_point(), gbm_final_time);

if (claim_time <= genesis_tbl_row.last_updated) {
return 0;
return genesis_tbl_row.unclaimed_balance.amount;
}

const int64_t elapsed_useconds = (claim_time - genesis_tbl_row.last_updated).count();
const int64_t unclaimed_balance = static_cast<int64_t>(genesis_tbl_row.balance.amount * (elapsed_useconds / double(useconds_in_gbm_period))) + genesis_tbl_row.unclaimed_balance.amount;
const int64_t unclaimed_balance = static_cast<int64_t>(genesis_tbl_row.balance.amount * (elapsed_useconds / double(useconds_in_gbm_period))) + genesis_tbl_row.unclaimed_balance.amount;
return unclaimed_balance;
}

Expand Down Expand Up @@ -561,27 +561,44 @@ namespace eosiosystem {
const auto unclaimed_balance = get_unclaimed_gbm_balance(owner);

const asset zero_asset( 0, core_symbol() );
// withdrawn_genesis represents the amount of genesis affected by unstaking.
asset withdrawn_genesis;

del_bandwidth_table del_bw_tbl( _self, owner.value );
auto del_bw_itr = del_bw_tbl.find( owner.value );
genesis_tbl.modify( owner_genesis, owner, [&]( auto& genesis ){
genesis.unclaimed_balance = asset(unclaimed_balance, core_symbol());
genesis.last_updated = current_time_point();
if(del_bw_itr == del_bw_tbl.end()) {
withdrawn_genesis = genesis.balance;
genesis.balance = zero_asset; // receiver consumed all her tokens an row will be erased
} else {
// receiver consumed shorter amount than available delegated_to_self_tokens
// if remaining amount is greater or equal than genesis balance
// -> genesis balance should stay unchanged
// else (remaining amount is less than genesis balance )
// -> genesis balance is now decreased to new_delegated_to_self_tokens amount
const auto prev_genesis = genesis.balance;
genesis.balance = std::min<asset>(del_bw_itr->net_weight + del_bw_itr->cpu_weight, genesis.balance);
withdrawn_genesis = prev_genesis - genesis.balance;
}
});

if( owner_genesis.balance == zero_asset && owner_genesis.unclaimed_balance == zero_asset){
genesis_tbl.erase(owner_genesis);
}

const auto unstake_time = std::min(current_time_point(), gbm_final_time);
const int64_t delta_time_usec = (gbm_final_time - unstake_time).count();
int64_t to_burn_amount = static_cast<int64_t>(withdrawn_genesis.amount * (delta_time_usec / double(useconds_in_gbm_period)));

if (to_burn_amount > 0) {
const asset to_burn(to_burn_amount, core_symbol());
token::transfer_action transfer_act{ token_account, { {genesis_account, active_permission} } };
transfer_act.send(genesis_account, get_self(), to_burn, "transfering back to eosio to burn pre-minted tokens from unstaking.");
token::retire_action retire_act{ token_account, { {get_self(), active_permission} } };
retire_act.send(to_burn, "to burn pre-minted tokens from unstaking.");
}
}
}

Expand Down
78 changes: 78 additions & 0 deletions tests/eosio.system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace eosio_system;
BOOST_AUTO_TEST_SUITE(eosio_system_tests)

bool within_one(int64_t a, int64_t b) { return std::abs(a - b) <= 1; }
bool within_and_gte(int64_t a, int64_t b, int64_t w) { return a - b <= w && a >= b; }

BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {

Expand Down Expand Up @@ -1998,6 +1999,83 @@ BOOST_FIXTURE_TEST_CASE(voter_gbm_pay, eosio_system_tester, * boost::unit_test::
}
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(gbm_burns_on_immature_balance, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try {
cross_15_percent_threshold();

create_account_with_resources(N(user11111111), config::system_account_name, core_sym::from_string("100.0000"), false, core_sym::from_string("10.0000"), core_sym::from_string("10.0000"));

// This transfer creates a sub_balance for genesis.wax account
transfer( N(eosio), N(genesis.wax), core_sym::from_string("100000000.0000"), N(eosio) );

uint64_t nonce = 1;
asset genesis_tokens_user1{core_sym::from_string("5000.0000")};
awardgenesis(N(user11111111), genesis_tokens_user1, nonce);

produce_block( fc::days(1) ); //Wait until July 1st
produce_block( fc::days(1096 / 2) );

BOOST_REQUIRE_EQUAL(success(), unstake( N(user11111111), N(user11111111), core_sym::from_string("2500.0000"), core_sym::from_string("2500.0000")));
produce_blocks(1);

auto balance = get_balance(N(genesis.wax)).get_amount();
const double tolerance = 1e-5; // ~0.000028%
// We burned and extra ~2500 due to an early genesis withdrawal
auto expected = core_sym::from_string("99992500.0000").get_amount();
// balance is within and greater than or equal to expected, meaning we are not left with a deficit.
// Ie. we can always cover the genesis rewards outstanding
BOOST_REQUIRE(within_and_gte(balance, expected, expected * tolerance));
claimgenesis(N(user11111111));
balance = get_balance(N(genesis.wax)).get_amount();
// We claimed the reward earned for half maturity genesis coins, clearing all remaining coins reserved
expected = core_sym::from_string("99990000.0000").get_amount();
BOOST_REQUIRE(within_and_gte(balance, expected, 1));
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(gbm_does_not_burn_matured_balance, eosio_system_tester, * boost::unit_test::tolerance(1e-5)) try {
cross_15_percent_threshold();

create_account_with_resources(N(user11111111), config::system_account_name, core_sym::from_string("100.0000"), false, core_sym::from_string("10.0000"), core_sym::from_string("10.0000"));

// This transfer creates a sub_balance for genesis.wax account
transfer( N(eosio), N(genesis.wax), core_sym::from_string("100000000.0000"), N(eosio) );

uint64_t nonce = 1;
asset genesis_tokens_user1{core_sym::from_string("5000.0000")};
awardgenesis(N(user11111111), genesis_tokens_user1, nonce);

produce_block( fc::days(1) ); //Wait until July 1st
produce_block( fc::days(1096) );

BOOST_REQUIRE_EQUAL(success(), unstake( N(user11111111), N(user11111111), core_sym::from_string("2500.0000"), core_sym::from_string("2500.0000")));
produce_blocks(1);

// No coins were burned because the genesis award reached full maturity
BOOST_REQUIRE_EQUAL(get_balance(N(genesis.wax)), core_sym::from_string("99995000.0000"));
claimgenesis(N(user11111111));
// Claiming the fully mature genesis rewards clears the amount reserved
BOOST_REQUIRE_EQUAL(get_balance(N(genesis.wax)), core_sym::from_string("99990000.0000"));
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(gbm_burning_preminted_invalid_values, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try {
cross_15_percent_threshold();

create_account_with_resources(N(user11111111), config::system_account_name, core_sym::from_string("100.0000"), false, core_sym::from_string("10.0000"), core_sym::from_string("10.0000"));

// This transfer creates a sub_balance for genesis.wax account
transfer( N(eosio), N(genesis.wax), core_sym::from_string("100000000.0000"), N(eosio) );

uint64_t nonce = 1;
asset genesis_tokens_user1{core_sym::from_string("5000.0000")};
awardgenesis(N(user11111111), genesis_tokens_user1, nonce);

produce_block( fc::days(1) ); //Wait until July 1st
produce_block( fc::days(1096 / 4) );

BOOST_REQUIRE_EQUAL(wasm_assert_msg("insufficient staked net bandwidth"), unstake( N(user11111111), N(user11111111), core_sym::from_string("3000.0000"), core_sym::from_string("3000.0000")));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("must unstake a positive amount"), unstake( N(user11111111), N(user11111111), core_sym::from_string("0.0000"), core_sym::from_string("0.0000")));
BOOST_REQUIRE_EQUAL(wasm_assert_msg("must unstake a positive amount"), unstake( N(user11111111), N(user11111111), core_sym::from_string("-10.0000"), core_sym::from_string("-10.0000")));
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try {

const double continuous_rate = 0.0582689;
Expand Down

0 comments on commit 81fbfb0

Please sign in to comment.