switched simple_wallet over to new routines for yield calculations; updated yield_info display to include yield earned on active STAKE TXs
This commit is contained in:
@@ -8394,86 +8394,42 @@ bool simple_wallet::supply_info(const std::vector<std::string> &args) {
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool simple_wallet::yield_info(const std::vector<std::string> &args) {
|
||||
|
||||
// Get the total circulating supply of SALs
|
||||
std::vector<std::pair<std::string, std::string>> supply_amounts;
|
||||
if(!m_wallet->get_circulating_supply(supply_amounts)) {
|
||||
fail_msg_writer() << "failed to get circulating supply. Make sure you are connected to a daemon.";
|
||||
return false;
|
||||
}
|
||||
boost::multiprecision::uint128_t total_supply_128 = 0;
|
||||
for (auto supply_asset: supply_amounts) {
|
||||
if (supply_asset.first == "SAL") {
|
||||
boost::multiprecision::uint128_t supply_128(supply_asset.second);
|
||||
total_supply_128 = supply_128;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// EXPERIMENTAL - change to get_yield_summary_info() method
|
||||
uint64_t t_burnt, t_supply, t_locked, t_yield, yps, ybi_size;
|
||||
std::vector<std::tuple<size_t, std::string, uint64_t, uint64_t>> yield_payouts;
|
||||
bool ok = m_wallet->get_yield_summary_info(t_burnt, t_supply, t_locked, t_yield, yps, ybi_size, yield_payouts);
|
||||
|
||||
// Get the yield data from the blockchain
|
||||
std::vector<cryptonote::yield_block_info> ybi_data;
|
||||
bool r = m_wallet->get_yield_info(ybi_data);
|
||||
if (!r)
|
||||
return false;
|
||||
// Get the chain height
|
||||
const uint64_t blockchain_height = m_wallet->get_blockchain_current_height();
|
||||
|
||||
// Scan the entries we have received to gather the state (total yield over period captured)
|
||||
uint64_t total_burnt = 0;
|
||||
uint64_t total_yield = 0;
|
||||
uint64_t yield_per_stake = 0;
|
||||
for (size_t idx=1; idx<ybi_data.size(); ++idx) {
|
||||
if (ybi_data[idx].locked_coins_tally == 0) {
|
||||
total_burnt += ybi_data[idx].slippage_total_this_block;
|
||||
} else {
|
||||
total_yield += ybi_data[idx].slippage_total_this_block;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the yield_per_staked_SAL value
|
||||
if (ybi_data.back().locked_coins_tally > 0) {
|
||||
boost::multiprecision::uint128_t yield_per_stake_128 = ybi_data.back().slippage_total_this_block;
|
||||
yield_per_stake_128 *= COIN;
|
||||
yield_per_stake_128 /= ybi_data.back().locked_coins_tally;
|
||||
yield_per_stake = yield_per_stake_128.convert_to<uint64_t>();
|
||||
message_writer(console_color_default, false) << boost::format(tr("\nSTAKED FUNDS:"));
|
||||
for (auto &p: yield_payouts) {
|
||||
uint64_t height, burnt, yield;
|
||||
std::string txid;
|
||||
std::tie(height, txid, burnt, yield) = p;
|
||||
if (blockchain_height > ybi_size + height)
|
||||
message_writer(console_color_green, true) << boost::format(tr("Height %d, txid %s, staked %s SAL, earned %s SAL"))
|
||||
% height
|
||||
% txid
|
||||
% print_money(burnt)
|
||||
% print_money(yield);
|
||||
else
|
||||
message_writer(console_color_green, false) << boost::format(tr("Height %d, txid %s, staked %s SAL, %s SAL accrued so far"))
|
||||
% height
|
||||
% txid
|
||||
% print_money(burnt)
|
||||
% print_money(yield);
|
||||
}
|
||||
|
||||
// Output the necessary information about yield stats
|
||||
message_writer(console_color_default, false) << boost::format(tr("YIELD INFO:\n\tSupply coins burnt over last %s: %d\n\tTotal coins locked: %d\n\tYield accrued over last %s: %d\n\tYield per SAL staked: %d"))
|
||||
% get_human_readable_timespan((ybi_data.size()-1) * DIFFICULTY_TARGET_V2)
|
||||
% print_money(total_burnt)
|
||||
% print_money(ybi_data.back().locked_coins_tally)
|
||||
% get_human_readable_timespan((ybi_data.size()-1) * DIFFICULTY_TARGET_V2)
|
||||
% print_money(total_yield)
|
||||
% print_money(yield_per_stake);
|
||||
message_writer(console_color_default, false) << boost::format(tr("\nYIELD INFO:\n\tSupply coins burnt over last %s: %d\n\tTotal coins locked: %d\n\tYield accrued over last %s: %d\n\tYield per SAL staked: %d"))
|
||||
% get_human_readable_timespan((ybi_size-1) * DIFFICULTY_TARGET_V2)
|
||||
% print_money(t_burnt)
|
||||
% print_money(t_locked)
|
||||
% get_human_readable_timespan((ybi_size-1) * DIFFICULTY_TARGET_V2)
|
||||
% print_money(t_yield)
|
||||
% print_money(yps);
|
||||
|
||||
// Now summarise our own YIELD TXs that are yet to mature
|
||||
tools::wallet2::transfer_container transfers;
|
||||
m_wallet->get_transfers(transfers);
|
||||
if (transfers.empty())
|
||||
return true;
|
||||
|
||||
std::map<size_t, size_t> payouts;
|
||||
message_writer(console_color_default, false) << boost::format(tr("\nSTAKED FUNDS:"));
|
||||
for (size_t idx = transfers.size()-1; idx>0; --idx) {
|
||||
const tools::wallet2::transfer_details& td = transfers[idx];
|
||||
//if (td.m_block_height < ybi_data[0].block_height) break;
|
||||
if (td.m_tx.type == cryptonote::transaction_type::STAKE) {
|
||||
if (payouts.count(idx)) {
|
||||
message_writer(console_color_green, true) << boost::format(tr("Height %d, txid %s, staked %s SAL, earned %s SAL"))
|
||||
% td.m_block_height
|
||||
% td.m_txid
|
||||
% print_money(td.m_tx.amount_burnt)
|
||||
% print_money(transfers[payouts[idx]].m_amount - td.m_tx.amount_burnt);
|
||||
} else {
|
||||
message_writer(console_color_green, false) << boost::format(tr("Height %d, txid %s, staked %s SAL"))
|
||||
% td.m_block_height
|
||||
% td.m_txid
|
||||
% print_money(td.m_tx.amount_burnt);
|
||||
}
|
||||
} else if (td.m_tx.type == cryptonote::transaction_type::PROTOCOL) {
|
||||
// Store list of reverse-lookup indices to tell YIELD TXs how much they earned
|
||||
if (transfers[td.m_td_origin_idx].m_tx.type == cryptonote::transaction_type::STAKE)
|
||||
payouts[td.m_td_origin_idx] = idx;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -2412,6 +2412,27 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt,
|
||||
|
||||
ybi_data_size = ybi_data.size();
|
||||
|
||||
// Iterate over the transfers in our wallet
|
||||
std::map<size_t, size_t> map_payouts;
|
||||
std::map<std::string, std::pair<size_t, std::pair<uint64_t, uint64_t>>> payouts_active;
|
||||
for (size_t idx = m_transfers.size()-1; idx>0; --idx) {
|
||||
const tools::wallet2::transfer_details& td = m_transfers[idx];
|
||||
//if (td.m_block_height < ybi_data[0].block_height) break;
|
||||
if (td.m_tx.type == cryptonote::transaction_type::STAKE) {
|
||||
if (map_payouts.count(idx)) {
|
||||
payouts.push_back(std::make_tuple(td.m_block_height, epee::string_tools::pod_to_hex(td.m_txid), td.m_tx.amount_burnt, m_transfers[map_payouts[idx]].m_amount - td.m_tx.amount_burnt));
|
||||
} else {
|
||||
//payouts.push_back(std::make_tuple(td.m_block_height, epee::string_tools::pod_to_hex(td.m_txid), td.m_tx.amount_burnt, 0));
|
||||
payouts_active[epee::string_tools::pod_to_hex(td.m_txid)] = std::make_pair(td.m_block_height, std::make_pair(td.m_tx.amount_burnt, 0));
|
||||
}
|
||||
} else if (td.m_tx.type == cryptonote::transaction_type::PROTOCOL) {
|
||||
// Store list of reverse-lookup indices to tell YIELD TXs how much they earned
|
||||
if (m_transfers[td.m_td_origin_idx].m_tx.type == cryptonote::transaction_type::STAKE)
|
||||
map_payouts[td.m_td_origin_idx] = idx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Scan the entries we have received to gather the state (total yield over period captured)
|
||||
total_burnt = 0;
|
||||
total_yield = 0;
|
||||
@@ -2421,8 +2442,22 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt,
|
||||
total_burnt += ybi_data[idx].slippage_total_this_block;
|
||||
} else {
|
||||
total_yield += ybi_data[idx].slippage_total_this_block;
|
||||
|
||||
// EXPERIMENTAL - add up yield earned for active STAKE TXs
|
||||
for (auto &payout: payouts_active) {
|
||||
if (ybi_data[idx].block_height < payout.second.first) continue;
|
||||
boost::multiprecision::uint128_t amount_128 = ybi_data[idx].slippage_total_this_block;
|
||||
amount_128 *= payout.second.second.first;
|
||||
amount_128 /= ybi_data[idx].locked_coins_tally;
|
||||
payout.second.second.second += amount_128.convert_to<uint64_t>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &payout: payouts_active) {
|
||||
// Copy to the list of payouts proper
|
||||
payouts.push_back(std::make_tuple(payout.second.first, payout.first, payout.second.second.first, payout.second.second.second));
|
||||
}
|
||||
|
||||
// Get the total currently locked
|
||||
total_locked = ybi_data.back().locked_coins_tally;
|
||||
@@ -2434,7 +2469,7 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt,
|
||||
yield_per_stake_128 /= ybi_data.back().locked_coins_tally;
|
||||
yield_per_stake = yield_per_stake_128.convert_to<uint64_t>();
|
||||
}
|
||||
|
||||
/*
|
||||
// Iterate over the transfers in our wallet
|
||||
std::map<size_t, size_t> map_payouts;
|
||||
for (size_t idx = m_transfers.size()-1; idx>0; --idx) {
|
||||
@@ -2452,7 +2487,7 @@ bool wallet2::get_yield_summary_info(uint64_t &total_burnt,
|
||||
map_payouts[td.m_td_origin_idx] = idx;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
// Return success to caller
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user