-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from AntelopeIO/merge-savanna-tokenonmics
[3.4 -> Main] Merge Tokenonmics Updates into Main
- Loading branch information
Showing
31 changed files
with
1,746 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ setacctram | |
setalimits | ||
setcode | ||
setinflation | ||
setpayfactor | ||
setparams | ||
setpriv | ||
setram | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_contract(eosio.bpay eosio.bpay ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.bpay.cpp) | ||
|
||
target_include_directories(eosio.bpay PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../eosio.system/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../eosio.token/include) | ||
|
||
set_target_properties(eosio.bpay | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | ||
|
||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/ricardian/eosio.bpay.contracts.md.in ${CMAKE_CURRENT_BINARY_DIR}/ricardian/eosio.bpay.contracts.md @ONLY ) | ||
|
||
target_compile_options( eosio.bpay PUBLIC -R${CMAKE_CURRENT_SOURCE_DIR}/ricardian -R${CMAKE_CURRENT_BINARY_DIR}/ricardian ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <eosio/eosio.hpp> | ||
#include <eosio.system/eosio.system.hpp> | ||
#include <eosio.token/eosio.token.hpp> | ||
|
||
using namespace std; | ||
|
||
namespace eosio { | ||
/** | ||
* The `eosio.bpay` contract handles system bpay distribution. | ||
*/ | ||
class [[eosio::contract("eosio.bpay")]] bpay : public contract { | ||
public: | ||
using contract::contract; | ||
|
||
/** | ||
* ## TABLE `rewards` | ||
* | ||
* @param owner - block producer owner account | ||
* @param quantity - reward quantity in EOS | ||
* | ||
* ### example | ||
* | ||
* ```json | ||
* [ | ||
* { | ||
* "owner": "alice", | ||
* "quantity": "8.800 EOS" | ||
* } | ||
* ] | ||
* ``` | ||
*/ | ||
struct [[eosio::table("rewards")]] rewards_row { | ||
name owner; | ||
asset quantity; | ||
|
||
uint64_t primary_key() const { return owner.value; } | ||
}; | ||
typedef eosio::multi_index< "rewards"_n, rewards_row > rewards_table; | ||
|
||
/** | ||
* Claim rewards for a block producer. | ||
* | ||
* @param owner - block producer owner account | ||
*/ | ||
[[eosio::action]] | ||
void claimrewards( const name owner); | ||
|
||
[[eosio::on_notify("eosio.token::transfer")]] | ||
void on_transfer( const name from, const name to, const asset quantity, const string memo ); | ||
|
||
private: | ||
}; | ||
} /// namespace eosio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1 class="contract">claimrewards</h1> | ||
|
||
--- | ||
spec_version: "0.2.0" | ||
title: Claim Rewards | ||
summary: '{{nowrap owner}} claims block production rewards' | ||
icon: @ICON_BASE_URL@/@MULTISIG_ICON_URI@ | ||
--- | ||
|
||
{{owner}} claims block production rewards accumulated through network fees. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <eosio.bpay/eosio.bpay.hpp> | ||
|
||
namespace eosio { | ||
|
||
void bpay::claimrewards( const name owner ) { | ||
require_auth( owner ); | ||
|
||
rewards_table _rewards( get_self(), get_self().value ); | ||
|
||
const auto& row = _rewards.get( owner.value, "no rewards to claim" ); | ||
|
||
eosio::token::transfer_action transfer( "eosio.token"_n, { get_self(), "active"_n }); | ||
transfer.send( get_self(), owner, row.quantity, "producer block pay" ); | ||
|
||
_rewards.erase(row); | ||
} | ||
|
||
void bpay::on_transfer( const name from, const name to, const asset quantity, const string memo ) { | ||
if (from == get_self() || to != get_self()) { | ||
return; | ||
} | ||
|
||
// ignore eosio system incoming transfers (caused by bpay income transfers eosio => eosio.bpay => producer) | ||
if ( from == "eosio"_n) return; | ||
|
||
symbol system_symbol = eosiosystem::system_contract::get_core_symbol(); | ||
|
||
check( quantity.symbol == system_symbol, "only core token allowed" ); | ||
|
||
rewards_table _rewards( get_self(), get_self().value ); | ||
eosiosystem::producers_table _producers( "eosio"_n, "eosio"_n.value ); | ||
|
||
eosiosystem::global_state_singleton _global("eosio"_n, "eosio"_n.value); | ||
check( _global.exists(), "global state does not exist"); | ||
uint16_t producer_count = _global.get().last_producer_schedule_size; | ||
|
||
// get producer with the most votes | ||
// using `by_votes` secondary index | ||
auto idx = _producers.get_index<"prototalvote"_n>(); | ||
auto prod = idx.begin(); | ||
|
||
// get top n producers by vote, excluding inactive | ||
std::vector<name> top_producers; | ||
while (true) { | ||
if (prod == idx.end()) break; | ||
if (prod->is_active == false) continue; | ||
|
||
top_producers.push_back(prod->owner); | ||
|
||
if (top_producers.size() == producer_count) break; | ||
|
||
prod++; | ||
} | ||
|
||
asset reward = quantity / top_producers.size(); | ||
|
||
// distribute rewards to top producers | ||
for (auto producer : top_producers) { | ||
auto row = _rewards.find( producer.value ); | ||
if (row == _rewards.end()) { | ||
_rewards.emplace( get_self(), [&](auto& row) { | ||
row.owner = producer; | ||
row.quantity = reward; | ||
}); | ||
} else { | ||
_rewards.modify(row, get_self(), [&](auto& row) { | ||
row.quantity += reward; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
} /// namespace eosio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_contract(eosio.fees eosio.fees ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.fees.cpp) | ||
|
||
target_include_directories(eosio.fees PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../eosio.system/include) | ||
|
||
set_target_properties(eosio.fees | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | ||
|
||
target_compile_options( eosio.fees PUBLIC ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <eosio/asset.hpp> | ||
#include <eosio/eosio.hpp> | ||
#include <eosio.system/eosio.system.hpp> | ||
|
||
#include <string> | ||
|
||
namespace eosiosystem { | ||
class system_contract; | ||
} | ||
|
||
namespace eosio { | ||
|
||
using std::string; | ||
/** | ||
* The eosio.fees smart contract facilitates the collection of transaction fees from system accounts and their subsequent distribution to the Resource Exchange (REX) pool. | ||
* | ||
* This contract serves as an essential component for inclusion in system-level unit tests. | ||
* | ||
* A comprehensive implementation of the eosio.fees contract can be accessed at EOS Network Foundation GitHub repository. | ||
* https://github.com/eosnetworkfoundation/eosio.fees | ||
*/ | ||
class [[eosio::contract("eosio.fees")]] fees : public contract { | ||
public: | ||
using contract::contract; | ||
|
||
[[eosio::on_notify("eosio.token::transfer")]] | ||
void on_transfer( const name from, const name to, const asset quantity, const string memo ); | ||
|
||
[[eosio::action]] | ||
void noop(); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <eosio.fees/eosio.fees.hpp> | ||
|
||
namespace eosio { | ||
|
||
void fees::on_transfer( const name from, const name to, const asset quantity, const string memo ) | ||
{ | ||
if ( to != get_self() ) { | ||
return; | ||
} | ||
if (eosiosystem::system_contract::rex_available()) { | ||
eosiosystem::system_contract::donatetorex_action donatetorex( "eosio"_n, { get_self(), "active"_n }); | ||
donatetorex.send(get_self(), quantity, memo); | ||
} | ||
} | ||
|
||
void fees::noop() | ||
{ | ||
require_auth( get_self() ); | ||
} | ||
|
||
} /// namespace eosio |
Oops, something went wrong.