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

Add enhancements to auditor.bos (voter_info.staked & lower vote quorum) #57

Closed
wants to merge 5 commits into from
Closed
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
5 changes: 4 additions & 1 deletion contracts/auditor.bos/include/auditorbos.hpp
Expand Up @@ -4,6 +4,7 @@
#include <eosiolib/time.hpp>

#include "external_types.hpp"
#include "voter_info.hpp"

#define _STRINGIZE(x) #x
#define STRINGIZE(x) _STRINGIZE(x)
Expand Down Expand Up @@ -206,6 +207,7 @@ class auditorbos : public contract {
votes_table votes_cast_by_members;
bios_table candidate_bios;
contr_state _currentState;
voter_table _voters;

public:

Expand All @@ -215,7 +217,8 @@ class auditorbos : public contract {
votes_cast_by_members(_self, _self.value),
candidate_bios(_self, _self.value),
config_singleton(_self, _self.value),
contract_state(_self, _self.value) {
contract_state(_self, _self.value),
_voters( "eosio"_n, "eosio"_n.value ) {

_currentState = contract_state.get_or_default(contr_state());
}
Expand Down
35 changes: 35 additions & 0 deletions contracts/auditor.bos/include/voter_info.hpp
@@ -0,0 +1,35 @@
struct [[eosio::table, eosio::contract("eosio.system")]] voter_info {
name owner; /// the voter
name proxy; /// the proxy set by the voter, if any
std::vector<name> producers; /// the producers approved by this voter if no proxy set
int64_t staked = 0;

/**
* Every time a vote is cast we must first "undo" the last vote weight, before casting the
* new vote weight. Vote weight is calculated as:
*
* stated.amount * 2 ^ ( weeks_since_launch/weeks_per_year)
*/
double last_vote_weight = 0; /// the vote weight cast the last time the vote was updated

/**
* Total vote weight delegated to this voter.
*/
double proxied_vote_weight= 0; /// the total vote weight delegated to this voter as a proxy
bool is_proxy = 0; /// whether the voter is a proxy for others


uint32_t flags1 = 0;
uint32_t reserved2 = 0;
eosio::asset reserved3;

uint64_t primary_key()const { return owner.value; }

enum class flags1_fields : uint32_t {
ram_managed = 1,
net_managed = 2,
cpu_managed = 4
};
};

typedef eosio::multi_index<"voters"_n, voter_info> voter_table;
25 changes: 15 additions & 10 deletions contracts/auditor.bos/src/newtenure_components.cpp
Expand Up @@ -105,27 +105,32 @@ void auditorbos::newtenure(string message) {
// Get the max supply of the lockup asset token (eg. BOS)
auto tokenStats = stats(name(TOKEN_CONTRACT), config.lockupasset.symbol.code().raw()).begin();

uint64_t max_supply = tokenStats->supply.amount;
uint64_t active_supply = tokenStats->supply.amount;

print("\nRead stats");

double percent_of_current_voter_engagement =
double(_currentState.total_weight_of_votes) / double(max_supply) * 100.0;
int64_t total_weight_of_votes = _currentState.total_weight_of_votes;
double percent_of_current_voter_engagement = double(total_weight_of_votes) / double(active_supply) * 100.0;

eosio::print("\n\nToken max supply: ", max_supply, " total votes so far: ", _currentState.total_weight_of_votes);
eosio::print("\n\nNeed inital engagement of: ", config.initial_vote_quorum_percent, "% to start the Audit Cycle.");
eosio::print("\n\nToken supply: ", max_supply * 0.0001, " total votes so far: ", _currentState.total_weight_of_votes * 0.0001);
eosio::print("\n\nNeed initial engagement of: ", config.initial_vote_quorum_percent, "% to start the Audit Cycle..");
eosio::print("\n\nNeed ongoing engagement of: ", config.vote_quorum_percent,
// Divide uint32_t by 10 to add an extra decimal which allows for lower vote quorum threshold
// example: Active Supply 1B / vote quorum 1 = 1M tokens as threshold
double initial_vote_quorum_percent = double(config.initial_vote_quorum_percent) / 10;
double vote_quorum_percent = double(config.vote_quorum_percent) / 10;

eosio::print("\n\nToken active supply: ", active_supply, " total votes so far: ", total_weight_of_votes);
eosio::print("\n\nNeed inital engagement of: ", initial_vote_quorum_percent, "% to start the Audit Cycle.");
eosio::print("\n\nToken supply: ", active_supply * 0.0001, " total votes so far: ", total_weight_of_votes * 0.0001);
eosio::print("\n\nNeed initial engagement of: ", initial_vote_quorum_percent, "% to start the Audit Cycle..");
eosio::print("\n\nNeed ongoing engagement of: ", vote_quorum_percent,
"% to allow new periods to trigger after initial activation.");
eosio::print("\n\nPercent of current voter engagement: ", percent_of_current_voter_engagement, "\n\n");

check(_currentState.met_initial_votes_threshold == true ||
percent_of_current_voter_engagement > config.initial_vote_quorum_percent,
percent_of_current_voter_engagement > initial_vote_quorum_percent,
"ERR::NEWTENURE_VOTER_ENGAGEMENT_LOW_ACTIVATE::Voter engagement is insufficient to activate the Audit Cycle..");
_currentState.met_initial_votes_threshold = true;

check(percent_of_current_voter_engagement > config.vote_quorum_percent,
check(percent_of_current_voter_engagement > vote_quorum_percent,
"ERR::NEWTENURE_VOTER_ENGAGEMENT_LOW_PROCESS::Voter engagement is insufficient to process a new period");

// Set auditors for the next period.
Expand Down
24 changes: 8 additions & 16 deletions contracts/auditor.bos/src/privatehelpers.cpp
Expand Up @@ -34,27 +34,19 @@ void auditorbos::modifyVoteWeights(name voter, vector<name> newVotes) {
// This could be optimised with set diffing to avoid remove then add for unchanged votes. - later
eosio::print("Modify vote weights: ", voter, "\n");

uint64_t asset_name = configs().lockupasset.symbol.code().raw();
int64_t vote_weight = 0; //ac->balance.amount;
// To track previous votes weights
int64_t old_weight = 0;
vector<name> oldVotes = {};

//Find all cases of delegated bandwidth and sum them up
del_bandwidth_table delband(name("eosio"), voter.value);
auto stake = delband.begin();
// Find voter's voting info
auto voters_itr = _voters.find(voter.value);
check(voters_itr != _voters.end(), "ERR::VOTEAUDITOR_INVALID_VOTER_INFO::voter must be voting for any number of block producers or a proxy");

while(stake != delband.end()) {
vote_weight += stake->net_weight.amount;
vote_weight += stake->cpu_weight.amount;
stake++;
}
// Get voter's staked weight
int64_t vote_weight = voters_itr->staked;

// Add any liquid balance
// accounts accountstable(name(TOKEN_CONTRACT), voter.value);
// const auto ac = accountstable.find(asset_name);
// if (ac != accountstable.end()) {
// vote_weight += ac->balance.amount;
// }
// Prevent voters with 0 staked balance from voting
check(vote_weight > 0, "ERR::VOTEAUDITOR_INVALID_STAKE::voter must have a staked balance");

// Find a vote that has been cast by this voter previously.
auto existingVote = votes_cast_by_members.find(voter.value);
Expand Down
16 changes: 5 additions & 11 deletions contracts/auditor.bos/src/voting.cpp
Expand Up @@ -19,19 +19,13 @@ void auditorbos::voteauditor(name voter, vector<name> newvotes) {


void auditorbos::refreshvote(name voter) {
// Anyone can refresh vote
// any account can refresh vote
// background processes will typically execute this action

// if (configs().authaccount == name{0}) {
// require_auth(_self);
// } else {
// require_auth(configs().authaccount);
// }

// Find a vote that has been cast by this voter previously.
auto existingVote = votes_cast_by_members.find(voter.value);
if (existingVote != votes_cast_by_members.end()) {
//new votes is same as old votes, will just apply the deltas
modifyVoteWeights(voter, existingVote->candidates);
}
check( existingVote != votes_cast_by_members.end(), "ERR::VOTEAUDITOR_VOTER_NOT_FOUND::Voter could not be found.");

// new votes is same as old votes, will just apply the deltas
modifyVoteWeights(voter, existingVote->candidates);
}