Skip to content

Commit

Permalink
correction remarks3 #353
Browse files Browse the repository at this point in the history
  • Loading branch information
kudzinp committed Feb 4, 2019
1 parent e9ae7ac commit ba5a2d8
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 34 deletions.
8 changes: 8 additions & 0 deletions golos.publication/golos.publication.abi
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
{
"name": "quantity",
"type": "asset"
},
{
"name": "interest_rate",
"type": "uint64"
},
{
"name": "payout_strategy",
"type": "uint8"
}
]
},
Expand Down
47 changes: 18 additions & 29 deletions golos.publication/golos.publication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <common/upsert.hpp>
#include "utils.hpp"
#include "objects.hpp"
#include <common/config.hpp>

namespace golos {

Expand Down Expand Up @@ -323,7 +322,7 @@ int64_t publication::pay_curators(name author, uint64_t msgid, int64_t max_rewar
eosio_assert(claim <= unclaimed_rewards, "LOGIC ERROR! publication::pay_curators: claim > unclaimed_rewards");
if(claim > 0) {
unclaimed_rewards -= claim;
claim -= pay_delegators(msgid, claim, v->voter, tokensymbol, v->delegators);
claim -= pay_delegators(claim, v->voter, tokensymbol, v->delegators);
payto(v->voter, eosio::asset(claim, tokensymbol), static_cast<enum_t>(payment_t::VESTING));
}
}
Expand Down Expand Up @@ -616,9 +615,16 @@ void publication::set_vote(name voter, name author, string permlink, int16_t wei
auto token_code = pool->state.funds.symbol.code();
auto list_delegate_voter = golos::vesting::get_list_delegate(config::vesting_name, voter, token_code);
auto effective_vesting = golos::vesting::get_account_effective_vesting(config::vesting_name, voter, token_code);
for (auto record : list_delegate_voter)
delegators.push_back( {record.sender, record.quantity, record.interest_rate,
record.payout_strategy, effective_vesting} );

for (auto record : list_delegate_voter) {
auto interest_rate = static_cast<uint64_t>(static_cast<uint128_t>(record.quantity.amount) *
record.interest_rate / effective_vesting.amount);

if (interest_rate == 0)
continue;

delegators.push_back( {record.sender, record.quantity, interest_rate, record.payout_strategy} );
}

vote_table.emplace(voter, [&]( auto &item ) {
item.id = vote_table.available_primary_key();
Expand Down Expand Up @@ -812,33 +818,16 @@ void publication::reblog(name rebloger, name author, std::string permlink) {
"You can't reblog, because this message doesn't exist.");
}

int64_t publication::pay_delegators(uint64_t message_id, int64_t claim, name voter,
int64_t publication::pay_delegators(int64_t claim, name voter,
eosio::symbol tokensymbol, std::vector<structures::delegate_voter> delegate_list) {
int64_t dlg_payout_sum = 0;
for (auto delegate_obj : delegate_list) {
if (delegate_obj.payout_strategy == config::to_delegated_vesting) {

auto interest_rate = static_cast<uint64_t>(static_cast<uint128_t>(delegate_obj.quantity.amount) *
delegate_obj.interest_rate / delegate_obj.effective_vesting.amount);

auto dlg_payout = claim * interest_rate / config::_100percent;

tables::account_table acc_table(_self, voter.value);
auto balance = acc_table.find(tokensymbol.code().raw());
acc_table.modify(balance, delegate_obj.delegator, [&](auto& item) {
item.delegate_vesting += eosio::asset(dlg_payout, tokensymbol);
item.received_vesting += eosio::asset(dlg_payout, tokensymbol);
});
tables::delegate_table table(_self, tokensymbol.code().raw());
auto index_table = table.get_index<"unique"_n>();
auto delegate_record = index_table.find(structures::delegate_record::unique_key(delegate_obj.delegator, voter));
if (delegate_record != index_table.end()) {
index_table.modify(delegate_record, name(), [&](auto& item) {
item.deductions += eosio::asset(dlg_payout, tokensymbol);
});
}
dlg_payout_sum += dlg_payout;
}
auto dlg_payout = claim * delegate_obj.interest_rate / config::_100percent;
INLINE_ACTION_SENDER(golos::vesting, paydelegator) (config::vesting_name,
{config::vesting_name, config::active_name},
{voter, eosio::asset(dlg_payout, tokensymbol), delegate_obj.delegator,
delegate_obj.interest_rate, delegate_obj.payout_strategy});
dlg_payout_sum += dlg_payout;
}
return dlg_payout_sum;
}
Expand Down
2 changes: 1 addition & 1 deletion golos.publication/golos.publication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class publication : public contract {
symbol tokensymbol);
void payto(name user, asset quantity, enum_t mode);
void check_account(name user, symbol tokensymbol);
int64_t pay_delegators(uint64_t message_id, int64_t claim, name voter,
int64_t pay_delegators(int64_t claim, name voter,
eosio::symbol tokensymbol, std::vector<structures::delegate_voter> delegate_list);

void send_poolstate_event(const structures::rewardpool& pool);
Expand Down
3 changes: 0 additions & 3 deletions golos.publication/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ struct delegate_voter {
asset quantity;
uint64_t interest_rate;
uint8_t payout_strategy;
asset effective_vesting;
};

struct voteinfo {
Expand All @@ -92,9 +91,7 @@ struct voteinfo {
int16_t weight;
uint64_t time;
int64_t count;

std::vector<delegate_voter> delegators;

base_t curatorsw;
base_t rshares;

Expand Down
19 changes: 19 additions & 0 deletions golos.vesting/golos.vesting.abi
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
{
"name": "unlocked_limit",
"type": "asset"
},
{
"name": "delegation_rewards",
"type": "asset"
}
]
},
Expand Down Expand Up @@ -315,6 +319,17 @@
{"name": "symbol", "type": "symbol"},
{"name": "params", "type": "vesting_param[]"}
]
},
{
"name": "paydelegator",
"base": "",
"fields": [
{"name": "voter", "type": "name"},
{"name": "reward", "type": "asset"},
{"name": "delegator", "type": "name"},
{"name": "interest_rate", "type": "uint64"},
{"name": "payout_strategy", "type": "uint8"}
]
}
],
"events": [
Expand Down Expand Up @@ -383,6 +398,10 @@
{
"name": "close",
"type": "close"
},
{
"name": "paydelegator",
"type": "paydelegator"
}
],
"tables": [
Expand Down
31 changes: 31 additions & 0 deletions golos.vesting/golos.vesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ extern "C" {
execute_action(&vesting::validateprms);
else if (NN(setparams) == action)
execute_action(&vesting::setparams);
else if (NN(paydelegator) == action)
execute_action(&vesting::paydelegator);
}
#undef NN
}
Expand Down Expand Up @@ -415,6 +417,7 @@ void vesting::open(name owner, symbol symbol, name ram_payer) {
a.delegate_vesting.symbol = symbol;
a.received_vesting.symbol = symbol;
a.unlocked_limit.symbol = symbol;
a.delegation_rewards.symbol = symbol;
});
}

Expand All @@ -426,6 +429,7 @@ void vesting::close(name owner, symbol symbol) {
eosio_assert(it->vesting.amount == 0, "Cannot close because the balance vesting is not zero");
eosio_assert(it->delegate_vesting.amount == 0, "Cannot close because the balance delegate vesting is not zero");
eosio_assert(it->received_vesting.amount == 0, "Cannot close because the balance received vesting not zero");
eosio_assert(it->delegation_rewards.amount == 0, "Cannot close because the balance of rewards not zero");
account.erase(it);
}

Expand Down Expand Up @@ -541,5 +545,32 @@ void vesting::timeout_delay_trx() {
trx.send(_self.value, _self);
}

void vesting::paydelegator(name voter, asset reward, name delegator,
uint64_t interest_rate, uint8_t payout_strategy) {
if (payout_strategy == config::to_delegated_vesting) {
tables::account_table acc_table_dlg(_self, delegator.value);
auto balance_dlg = acc_table_dlg.find(reward.symbol.code().raw());
acc_table_dlg.modify(balance_dlg, voter, [&](auto& item) {
item.delegate_vesting += reward;
});
tables::account_table acc_table_rcv(_self, voter.value);
auto balance_rcv = acc_table_rcv.find(reward.symbol.code().raw());
acc_table_rcv.modify(balance_rcv, delegator, [&](auto& item) {
item.received_vesting += reward;
});
tables::delegate_table table(_self, reward.symbol.code().raw());
auto index_table = table.get_index<"unique"_n>();
auto delegate_record = index_table.find(structures::delegate_record::unique_key(delegator, voter));
index_table.modify(delegate_record, name(), [&](auto& item) {
item.deductions += reward;
});
} else if (payout_strategy == config::to_delegator) {
tables::account_table acc_table(_self, delegator.value);
auto balance = acc_table.find(reward.symbol.code().raw());
acc_table.modify(balance, voter, [&](auto& item) {
item.delegation_rewards += reward;
});
}
}

} // golos
2 changes: 2 additions & 0 deletions golos.vesting/golos.vesting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class vesting : public contract {
void timeout_delay_trx();
void calculate_convert_vesting();
void calculate_delegate_vesting();
void paydelegator(name voter, asset reward, name delegator,
uint64_t interest_rate, uint8_t payout_strategy);

static inline asset get_account_vesting(name code, name account, symbol_code sym) {
tables::account_table accounts(code, account.value);
Expand Down
4 changes: 3 additions & 1 deletion golos.vesting/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct user_balance {
asset delegate_vesting;
asset received_vesting;
asset unlocked_limit;
asset delegation_rewards;

uint64_t primary_key() const {
return vesting.symbol.code().raw();
Expand All @@ -46,7 +47,8 @@ struct user_balance {
return std::min(available_vesting(), unlocked_limit);
}

EOSLIB_SERIALIZE(user_balance, (vesting)(delegate_vesting)(received_vesting)(unlocked_limit))
EOSLIB_SERIALIZE(user_balance, (vesting)(delegate_vesting)(received_vesting)
(unlocked_limit)(delegation_rewards))
};

struct delegate_record {
Expand Down

0 comments on commit ba5a2d8

Please sign in to comment.