Skip to content

Commit

Permalink
frame_length removed, last_reward added #75
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynarov committed Apr 27, 2019
1 parent fd9b76b commit ddb61bb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
1 change: 0 additions & 1 deletion cyber.stake/abi/cyber.stake.abi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"fields": [
{ "type": "symbol", "name": "token_symbol" },
{ "type": "uint8[]", "name": "max_proxies" },
{ "type": "int64", "name": "frame_length" },
{ "type": "int64", "name": "payout_step_length" },
{ "type": "uint16", "name": "payout_steps_num" },
{ "type": "int64", "name": "min_own_staked_for_election" }
Expand Down
6 changes: 3 additions & 3 deletions cyber.stake/include/cyber.stake/cyber.stake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ struct structures {
uint64_t id;
symbol token_symbol;
std::vector<uint8_t> max_proxies;
int64_t frame_length;
int64_t payout_step_length;
uint16_t payout_steps_num;
int64_t min_own_staked_for_election = 0;
Expand All @@ -100,6 +99,7 @@ struct structures {
uint64_t id;
symbol_code token_code;
int64_t total_staked;
time_point_sec last_reward;
bool enabled = false;
uint64_t primary_key()const { return id; }
};
Expand Down Expand Up @@ -127,7 +127,7 @@ struct structures {
using payouts = eosio::multi_index<"payout"_n, structures::payout, payout_id_index, payout_acc_index>;

void update_stake_proxied(symbol_code token_code, name agent_name) {
::update_stake_proxied(token_code.raw(), agent_name.value, int64_t(1), static_cast<int>(true));
::update_stake_proxied(token_code.raw(), agent_name.value, static_cast<int>(true));
}

void send_scheduled_payout(payouts& payouts_table, name account, int64_t payout_step_length, symbol sym, bool claim_mode = false);
Expand Down Expand Up @@ -209,7 +209,7 @@ struct structures {
using contract::contract;

[[eosio::action]] void create(symbol token_symbol, std::vector<uint8_t> max_proxies,
int64_t frame_length, int64_t payout_step_length, uint16_t payout_steps_num,
int64_t payout_step_length, uint16_t payout_steps_num,
int64_t min_own_staked_for_election);

[[eosio::action]] void enable(symbol token_symbol);
Expand Down
9 changes: 5 additions & 4 deletions cyber.stake/src/cyber.stake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void stake::setproxylvl(name account, symbol_code token_code, uint8_t level) {
}

void stake::create(symbol token_symbol, std::vector<uint8_t> max_proxies,
int64_t frame_length, int64_t payout_step_length, uint16_t payout_steps_num,
int64_t payout_step_length, uint16_t payout_steps_num,
int64_t min_own_staked_for_election)
{
auto token_code = token_symbol.code();
Expand All @@ -407,7 +407,6 @@ void stake::create(symbol token_symbol, std::vector<uint8_t> max_proxies,
for (size_t i = 1; i < max_proxies.size(); i++) {
eosio_assert(max_proxies[i - 1] >= max_proxies[i], "incorrect proxy levels");
}
eosio_assert(frame_length > 0, "incorrect frame_length");
eosio_assert(payout_step_length > 0, "incorrect payout_step_length");
eosio_assert(min_own_staked_for_election >= 0, "incorrect min_own_staked_for_election");
auto issuer = eosio::token::get_issuer(config::token_name, token_code);
Expand All @@ -419,7 +418,6 @@ void stake::create(symbol token_symbol, std::vector<uint8_t> max_proxies,
.id = token_code.raw(),
.token_symbol = token_symbol,
.max_proxies = max_proxies,
.frame_length = frame_length,
.payout_step_length = payout_step_length,
.payout_steps_num = payout_steps_num,
.min_own_staked_for_election = min_own_staked_for_election
Expand Down Expand Up @@ -516,7 +514,10 @@ void stake::reward(name account, asset quantity) {
a.own_share = quantity.amount;
});
}
modify_stat(token_code, [&](auto& s) { s.total_staked += quantity.amount; });
modify_stat(token_code, [&](auto& s) {
s.total_staked += quantity.amount;
s.last_reward = time_point_sec(::now());
});

INLINE_ACTION_SENDER(eosio::token, issue)(config::token_name, {issuer, config::reward_name}, {issuer, quantity, ""});
INLINE_ACTION_SENDER(eosio::token, transfer)(config::token_name, {issuer, config::reward_name},
Expand Down
2 changes: 1 addition & 1 deletion tests/cyber.govern_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class cyber_govern_tester : public golos_tester {
BOOST_TEST_MESSAGE("--- creating token and stake");
BOOST_CHECK_EQUAL(success(), token.create(_issuer, asset(max_supply_amount, token._symbol)));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol,
std::vector<uint8_t>{30, 10, 3, 1}, cfg::balances_update_window, 7 * 24 * 60 * 60, 52));
std::vector<uint8_t>{30, 10, 3, 1}, 7 * 24 * 60 * 60, 52));

BOOST_TEST_MESSAGE("--- installing governance contract");
install_contract(govern_account_name, contracts::govern_wasm(), contracts::govern_abi());
Expand Down
6 changes: 3 additions & 3 deletions tests/cyber.stake_test_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct cyber_stake_api: base_contract_api {

////actions
action_result create(account_name issuer, symbol token_symbol,
std::vector<uint8_t> max_proxies, int64_t frame_length, int64_t payout_step_length, uint16_t payout_steps_num,
std::vector<uint8_t> max_proxies, int64_t payout_step_length, uint16_t payout_steps_num,
int64_t min_own_staked_for_election = 0) {

_tester->delegate_authority(issuer, {_code}, cyber::config::token_name, N(issue), cyber::config::reward_name);
Expand All @@ -23,7 +23,6 @@ struct cyber_stake_api: base_contract_api {
return push(N(create), issuer, args()
("token_symbol", token_symbol)
("max_proxies", max_proxies)
("frame_length", frame_length)
("payout_step_length", payout_step_length)
("payout_steps_num", payout_steps_num)
("min_own_staked_for_election", min_own_staked_for_election)
Expand Down Expand Up @@ -210,10 +209,11 @@ struct cyber_stake_api: base_contract_api {
return variant();
}

variant make_stats(symbol token_symbol, int64_t total_staked, bool enabled = false) {
variant make_stats(symbol token_symbol, int64_t total_staked, bool enabled = false, time_point_sec last_reward = time_point_sec()) {
return mvo()
("token_code", token_symbol.to_symbol_code())
("total_staked", total_staked)
("last_reward", last_reward)
("enabled", enabled);
}
};
Expand Down
31 changes: 15 additions & 16 deletions tests/cyber.stake_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class cyber_stake_tester : public golos_tester {
BOOST_TEST_MESSAGE("--- creating token and stake");
BOOST_CHECK_EQUAL(success(), token.create(_issuer, asset(10000000000, token._symbol)));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol,
std::vector<uint8_t>{30, 10, 3, 1}, cfg::balances_update_window, 7 * 24 * 60 * 60, 52));
std::vector<uint8_t>{30, 10, 3, 1}, 7 * 24 * 60 * 60, 52));

BOOST_TEST_MESSAGE("--- installing governance contract");
install_contract(govern_account_name, contracts::govern_wasm(), contracts::govern_abi());
Expand Down Expand Up @@ -192,7 +192,7 @@ BOOST_FIXTURE_TEST_CASE(basic_tests, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _bob, stake_b, ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _carol, stake_c, ""));

BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, frame_length, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.open(_alice, token._symbol.to_symbol_code()));
BOOST_CHECK_EQUAL(success(), stake.open(_bob, token._symbol.to_symbol_code()));
BOOST_CHECK_EQUAL(success(), stake.open(_carol, token._symbol.to_symbol_code()));
Expand Down Expand Up @@ -283,7 +283,7 @@ BOOST_FIXTURE_TEST_CASE(increase_proxy_level_test, cyber_stake_tester) try {
double pct_c = 0.2;
asset staked(10000000, token._symbol);
BOOST_CHECK_EQUAL(success(), token.create(_issuer, asset(1000000000, token._symbol)));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, frame_length, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.open(_alice, token._symbol.to_symbol_code()));
BOOST_CHECK_EQUAL(success(), stake.open(_bob, token._symbol.to_symbol_code()));
BOOST_CHECK_EQUAL(success(), stake.open(_carol, token._symbol.to_symbol_code()));
Expand Down Expand Up @@ -341,7 +341,7 @@ BOOST_FIXTURE_TEST_CASE(open_test, cyber_stake_tester) try {
asset stake_u(100, token._symbol);
BOOST_CHECK_EQUAL(success(), token.create(_issuer, asset(10000000000, token._symbol)));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _alice, stake_u , ""));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {1}, 1, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {1}, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, stake_u));
BOOST_CHECK_EQUAL(err.agent_exists(), stake.open(_alice, token._symbol.to_symbol_code()));
BOOST_CHECK_EQUAL(success(), stake.open(_bob, token._symbol.to_symbol_code()));
Expand All @@ -368,7 +368,7 @@ BOOST_FIXTURE_TEST_CASE(bw_tests, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.open(_carol, token._symbol, _carol)); // resource usage
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _issuer, stake_w, ""));

BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, frame_length, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, stake_u));
BOOST_CHECK_EQUAL(success(), token.transfer(_bob, _code, stake_u));
BOOST_CHECK_EQUAL(success(), stake.enable(_issuer, token._symbol));
Expand Down Expand Up @@ -410,7 +410,7 @@ BOOST_FIXTURE_TEST_CASE(general_test, cyber_stake_tester) try {
int64_t step_amount = stake_amount / payout_steps_num;
BOOST_CHECK_EQUAL(success(), token.create(_issuer, token.from_amount(100500)));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _alice, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 10, 3, 1}, 600, payout_step_length, payout_steps_num));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 10, 3, 1}, payout_step_length, payout_steps_num));
BOOST_CHECK_EQUAL(err.no_agent(), stake.withdraw(_alice, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(err.no_funds(), stake.withdraw(_alice, token.from_amount(stake_amount + 1)));
Expand Down Expand Up @@ -475,7 +475,7 @@ BOOST_FIXTURE_TEST_CASE(proxy_test, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _alice, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _bob, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _carol, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 10, 3, 1}, 600, 100500, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 10, 3, 1}, 100500, 1));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_bob, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_carol, _code, token.from_amount(stake_amount)));
Expand Down Expand Up @@ -522,8 +522,7 @@ BOOST_FIXTURE_TEST_CASE(proxy_level_test, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _alice, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _bob, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _carol, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1},
2 * cfg::block_interval_ms / 1000, 100500, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 100500, 1));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_bob, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_carol, _code, token.from_amount(stake_amount)));
Expand Down Expand Up @@ -631,7 +630,7 @@ BOOST_FIXTURE_TEST_CASE(fee_parallel_test, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _carol, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _whale, token.from_amount(stake_amount), ""));

BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 1, 100500, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 100500, 1));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_bob, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_carol, _code, token.from_amount(stake_amount)));
Expand Down Expand Up @@ -681,7 +680,7 @@ BOOST_FIXTURE_TEST_CASE(fee_series_test, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _bob, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _carol, token.from_amount(stake_amount), ""));

BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 1, 100500, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 100500, 1));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_bob, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_carol, _code, token.from_amount(stake_amount)));
Expand Down Expand Up @@ -738,7 +737,7 @@ BOOST_FIXTURE_TEST_CASE(no_fee_test, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _alice, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _bob, token.from_amount(stake_amount), ""));

BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 1, 100500, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 3, 2, 1}, 100500, 1));
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(stake_amount)));
BOOST_CHECK_EQUAL(success(), token.transfer(_bob, _code, token.from_amount(stake_amount)));

Expand Down Expand Up @@ -767,7 +766,7 @@ BOOST_FIXTURE_TEST_CASE(min_staked_test, cyber_stake_tester) try {
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _alice, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _bob, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), token.issue(_issuer, _carol, token.from_amount(stake_amount), ""));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 10, 3, 1}, 1, 100500, 1, min_for_election));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {30, 10, 3, 1}, 100500, 1, min_for_election));
int64_t alice_stake = min_for_election - 1;
BOOST_CHECK_EQUAL(success(), token.transfer(_alice, _code, token.from_amount(alice_stake)));
BOOST_CHECK_EQUAL(success(), stake.setproxylvl(_alice, token._symbol.to_symbol_code(), 2));
Expand Down Expand Up @@ -822,7 +821,7 @@ BOOST_FIXTURE_TEST_CASE(_3x3_test, cyber_stake_tester) try {
stake_amounts.back() = stake_amount;

BOOST_CHECK_EQUAL(success(), token.create(_issuer, token.from_amount(1000 * stake_amount * (max_proxy_level + 1) * agents_on_level)));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {agents_on_level, agents_on_level}, 1, 1, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {agents_on_level, agents_on_level}, 1, 1));
auto agents = create_agents(max_proxy_level, agents_on_level, stake_amounts);

int64_t fee = 6500;
Expand Down Expand Up @@ -868,7 +867,7 @@ BOOST_FIXTURE_TEST_CASE(fuzz_test, cyber_stake_tester) try {
auto total_staked = 0;

BOOST_CHECK_EQUAL(success(), token.create(_issuer, token.from_amount(1000 * stake_amount * (max_proxy_level + 1) * agents_on_level)));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {agents_on_level, agents_on_level, agents_on_level, agents_on_level}, 1, 1, 1));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, {agents_on_level, agents_on_level, agents_on_level, agents_on_level}, 1, 1));
auto agents = create_agents(max_proxy_level, agents_on_level, stake_amount);
std::srand(0);
total_staked += stake_amount * (max_proxy_level + 1) * agents_on_level;
Expand Down Expand Up @@ -982,7 +981,7 @@ BOOST_FIXTURE_TEST_CASE(recursive_update_test, cyber_stake_tester) try {
double reward_factor = 0.1;

BOOST_CHECK_EQUAL(success(), token.create(_issuer, asset(1000000000, token._symbol)));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, frame_length, 7 * 24 * 60 * 60, 52));
BOOST_CHECK_EQUAL(success(), stake.create(_issuer, token._symbol, max_proxies, 7 * 24 * 60 * 60, 52));

uint8_t level = 0;
size_t u = 0;
Expand Down

0 comments on commit ddb61bb

Please sign in to comment.