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

replace channel_to_rex with channel_to_system_fees #72

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ namespace eosiosystem {
static constexpr eosio::name names_account{"eosio.names"_n};
static constexpr eosio::name saving_account{"eosio.saving"_n};
static constexpr eosio::name rex_account{"eosio.rex"_n};
static constexpr eosio::name fees_account{"eosio.fees"_n};
static constexpr eosio::name reserve_account{"eosio.reserv"_n}; // cspell:disable-line
static constexpr eosio::name null_account{"eosio.null"_n};
static constexpr symbol ramcore_symbol = symbol(symbol_code("RAMCORE"), 4);
Expand Down Expand Up @@ -1580,6 +1581,7 @@ namespace eosiosystem {
static eosio_global_state4 get_default_inflation_parameters();
symbol core_symbol()const;
void update_ram_supply();
void channel_to_system_fees( const name& from, const asset& amount );

// defined in rex.cpp
void runrex( uint16_t max );
Expand All @@ -1589,8 +1591,6 @@ namespace eosiosystem {
const char* error_msg = "must vote for at least 21 producers or for a proxy before buying REX" )const;
rex_order_outcome fill_rex_order( const rex_balance_table::const_iterator& bitr, const asset& rex );
asset update_rex_account( const name& owner, const asset& proceeds, const asset& unstake_quant, bool force_vote_update = false );
void channel_to_rex( const name& from, const asset& amount, bool required = false );
void channel_namebid_to_rex( const int64_t highest_bid );
template <typename T>
int64_t rent_rex( T& table, const name& from, const name& receiver, const asset& loan_payment, const asset& loan_fund );
template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions contracts/eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace eosiosystem {
if ( fee.amount > 0 ) {
token::transfer_action transfer_act{ token_account, { {payer, active_permission} } };
transfer_act.send( payer, ramfee_account, fee, "ram fee" );
channel_to_rex( ramfee_account, fee );
channel_to_system_fees( ramfee_account, fee );
}

int64_t bytes_out;
Expand Down Expand Up @@ -139,7 +139,7 @@ namespace eosiosystem {
if ( fee > 0 ) {
token::transfer_action transfer_act{ token_account, { {account, active_permission} } };
transfer_act.send( account, ramfee_account, asset(fee, core_symbol()), "sell ram fee" );
channel_to_rex( ramfee_account, asset(fee, core_symbol() ));
channel_to_system_fees( ramfee_account, asset(fee, core_symbol() ));
}

// logging
Expand Down
5 changes: 5 additions & 0 deletions contracts/eosio.system/src/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ namespace eosiosystem {
_gstate2.new_ram_per_block = bytes_per_block;
}

void system_contract::channel_to_system_fees( const name& from, const asset& amount ) {
token::transfer_action transfer_act{ token_account, { from, active_permission } };
transfer_act.send( from, fees_account, amount, "transfer from " + from.to_string() + " to " + fees_account.to_string() );
}

#ifdef SYSTEM_BLOCKCHAIN_PARAMETERS
extern "C" [[eosio::wasm_import]] void set_parameters_packed(const void*, size_t);
#endif
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.system/src/powerup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void system_contract::powerup(const name& payer, const name& receiver, uint32_t

adjust_resources(payer, receiver, core_symbol, net_amount, cpu_amount, true);
adjust_resources(get_self(), reserve_account, core_symbol, net_delta_available, cpu_delta_available, true);
channel_to_rex(payer, fee, true);
channel_to_system_fees(payer, fee);
state_sing.set(state, get_self());

// inline noop action
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.system/src/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace eosiosystem {
(current_time_point() - _gstate.thresh_activated_stake_time) > microseconds(14 * useconds_per_day)
) {
_gstate.last_name_close = timestamp;
channel_namebid_to_rex( highest->high_bid );
channel_to_system_fees( names_account, asset( highest->high_bid, core_symbol() ) );
idx.modify( highest, same_payer, [&]( auto& b ){
b.high_bid = -b.high_bid;
});
Expand Down
48 changes: 1 addition & 47 deletions contracts/eosio.system/src/rex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ namespace eosiosystem {
*/
void system_contract::add_loan_to_rex_pool( const asset& payment, int64_t rented_tokens, bool new_loan )
{
add_to_rex_return_pool( payment );
channel_to_system_fees( get_self(), payment );
_rexpool.modify( _rexpool.begin(), same_payer, [&]( auto& rt ) {
// add payment to total_rent
rt.total_rent.amount += payment.amount;
Expand Down Expand Up @@ -566,14 +566,6 @@ namespace eosiosystem {
return { delete_loan, delta_stake };
};

/// transfer from eosio.names to eosio.rex
if ( pool->namebid_proceeds.amount > 0 ) {
channel_to_rex( names_account, pool->namebid_proceeds );
_rexpool.modify( pool, same_payer, [&]( auto& rt ) {
rt.namebid_proceeds.amount = 0;
});
}

/// process cpu loans
{
rex_cpu_loan_table cpu_loans( get_self(), get_self().value );
Expand Down Expand Up @@ -935,44 +927,6 @@ namespace eosiosystem {
return rex_in_sell_order;
}

/**
* @brief Channels system fees to REX pool
*
* @param from - account from which asset is transferred to REX pool
* @param amount - amount of tokens to be transferred
* @param required - if true, asserts when the system is not configured to channel fees into REX
*/
void system_contract::channel_to_rex( const name& from, const asset& amount, bool required )
{
#if CHANNEL_RAM_AND_NAMEBID_FEES_TO_REX
if ( rex_available() ) {
add_to_rex_return_pool( amount );
// inline transfer to rex_account
token::transfer_action transfer_act{ token_account, { from, active_permission } };
transfer_act.send( from, rex_account, amount,
std::string("transfer from ") + from.to_string() + " to eosio.rex" );
return;
}
#endif
eosio::check( !required, "can't channel fees to rex" );
}

/**
* @brief Updates namebid proceeds to be transferred to REX pool
*
* @param highest_bid - highest bidding amount of closed namebid
*/
void system_contract::channel_namebid_to_rex( const int64_t highest_bid )
{
#if CHANNEL_RAM_AND_NAMEBID_FEES_TO_REX
if ( rex_available() ) {
_rexpool.modify( _rexpool.begin(), same_payer, [&]( auto& rp ) {
rp.namebid_proceeds.amount += highest_bid;
});
}
#endif
}

/**
* @brief Calculates maturity time of purchased REX tokens which is 4 days from end
* of the day UTC
Expand Down
8 changes: 5 additions & 3 deletions tests/eosio.msig_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using mvo = fc::mutable_variant_object;
class eosio_msig_tester : public tester {
public:
eosio_msig_tester() {
create_accounts( { "eosio.msig"_n, "eosio.stake"_n, "eosio.ram"_n, "eosio.ramfee"_n, "alice"_n, "bob"_n, "carol"_n } );
create_accounts( { "eosio.msig"_n, "eosio.stake"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.fees"_n, "alice"_n, "bob"_n, "carol"_n } );
produce_block();

auto trace = base_tester::push_action(config::system_account_name, "setpriv"_n,
Expand Down Expand Up @@ -448,7 +448,8 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_all_approve, eosio_msig_tester )
create_account_with_resources( "carol1111111"_n, "eosio"_n, core_sym::from_string("1.0000"), false );

BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"),
get_balance(config::system_account_name) + get_balance("eosio.ramfee"_n) + get_balance("eosio.stake"_n) + get_balance("eosio.ram"_n) );
get_balance(config::system_account_name) + get_balance("eosio.ramfee"_n) + get_balance("eosio.stake"_n)
+ get_balance("eosio.ram"_n) + get_balance("eosio.fees"_n) );

vector<permission_level> perm = { { "alice"_n, config::active_name }, { "bob"_n, config::active_name },
{"carol"_n, config::active_name} };
Expand Down Expand Up @@ -568,7 +569,8 @@ BOOST_FIXTURE_TEST_CASE( update_system_contract_major_approve, eosio_msig_tester
create_account_with_resources( "carol1111111"_n, "eosio"_n, core_sym::from_string("1.0000"), false );

BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"),
get_balance(config::system_account_name) + get_balance("eosio.ramfee"_n) + get_balance("eosio.stake"_n) + get_balance("eosio.ram"_n) );
get_balance(config::system_account_name) + get_balance("eosio.ramfee"_n) + get_balance("eosio.stake"_n)
+ get_balance("eosio.ram"_n) + get_balance("eosio.fees"_n) );

vector<permission_level> perm = { { "alice"_n, config::active_name }, { "bob"_n, config::active_name },
{"carol"_n, config::active_name}, {"apple"_n, config::active_name}};
Expand Down
3 changes: 0 additions & 3 deletions tests/eosio.powerup_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,6 @@ BOOST_AUTO_TEST_CASE(rent_tests) try {
BOOST_REQUIRE_EQUAL(
t.wasm_assert_msg("max_payment is less than calculated fee: 3000000.0000 TST"), //
t.powerup("bob111111111"_n, "alice1111111"_n, 30, powerup_frac, powerup_frac, asset::from_string("1.0000 TST")));
BOOST_REQUIRE_EQUAL(t.wasm_assert_msg("can't channel fees to rex"), //
t.powerup("bob111111111"_n, "alice1111111"_n, 30, powerup_frac, powerup_frac,
asset::from_string("3000000.0000 TST")));
}

// net:100%, cpu:100%
Expand Down
2 changes: 1 addition & 1 deletion tests/eosio.system_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class eosio_system_tester : public TESTER {
create_account_with_resources( "bob111111111"_n, config::system_account_name, core_sym::from_string("0.4500"), false );
create_account_with_resources( "carol1111111"_n, config::system_account_name, core_sym::from_string("1.0000"), false );

BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") );
BOOST_REQUIRE_EQUAL( core_sym::from_string("1000000000.0000"), get_balance("eosio") + get_balance("eosio.ramfee") + get_balance("eosio.stake") + get_balance("eosio.ram") + get_balance("eosio.fees") );
}

enum class setup_level {
Expand Down
16 changes: 8 additions & 8 deletions tests/eosio.system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
auto init_bytes = total["ram_bytes"].as_uint64();

const asset initial_ram_balance = get_balance("eosio.ram"_n);
const asset initial_ramfee_balance = get_balance("eosio.ramfee"_n);
const asset initial_fees_balance = get_balance("eosio.fees"_n);
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_sym::from_string("200.0000") ) );
BOOST_REQUIRE_EQUAL( core_sym::from_string("800.0000"), get_balance( "alice1111111" ) );
BOOST_REQUIRE_EQUAL( initial_ram_balance + core_sym::from_string("199.0000"), get_balance("eosio.ram"_n) );
BOOST_REQUIRE_EQUAL( initial_ramfee_balance + core_sym::from_string("1.0000"), get_balance("eosio.ramfee"_n) );
BOOST_REQUIRE_EQUAL( initial_fees_balance + core_sym::from_string("1.0000"), get_balance("eosio.fees"_n) );

total = get_total_stake( "alice1111111" );
auto bytes = total["ram_bytes"].as_uint64();
Expand Down Expand Up @@ -3816,7 +3816,7 @@ BOOST_FIXTURE_TEST_CASE( eosioram_ramusage, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( success(), stake( "eosio", "alice1111111", core_sym::from_string("200.0000"), core_sym::from_string("100.0000") ) );

const asset initial_ram_balance = get_balance("eosio.ram"_n);
const asset initial_ramfee_balance = get_balance("eosio.ramfee"_n);
const asset initial_fees_balance = get_balance("eosio.fees"_n);
BOOST_REQUIRE_EQUAL( success(), buyram( "alice1111111", "alice1111111", core_sym::from_string("1000.0000") ) );

BOOST_REQUIRE_EQUAL( false, get_row_by_account( "eosio.token"_n, "alice1111111"_n, "accounts"_n, account_name(symbol{CORE_SYM}.to_symbol_code()) ).empty() );
Expand Down Expand Up @@ -4727,18 +4727,18 @@ BOOST_FIXTURE_TEST_CASE( ramfee_namebid_to_rex, eosio_system_tester ) try {
account_name alice = accounts[0], bob = accounts[1], carol = accounts[2], emily = accounts[3], frank = accounts[4];
setup_rex_accounts( accounts, init_balance, core_sym::from_string("80.0000"), core_sym::from_string("80.0000"), false );

asset cur_ramfee_balance = get_balance( "eosio.ramfee"_n );
asset cur_fees_balance = get_balance( "eosio.fees"_n );
BOOST_REQUIRE_EQUAL( success(), buyram( alice, alice, core_sym::from_string("20.0000") ) );
BOOST_REQUIRE_EQUAL( get_balance( "eosio.ramfee"_n ), core_sym::from_string("0.1000") + cur_ramfee_balance );
BOOST_REQUIRE_EQUAL( get_balance( "eosio.fees"_n ), core_sym::from_string("0.1000") + cur_fees_balance );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("must deposit to REX fund first"),
buyrex( alice, core_sym::from_string("350.0000") ) );
BOOST_REQUIRE_EQUAL( success(), deposit( alice, core_sym::from_string("350.0000") ) );
BOOST_REQUIRE_EQUAL( success(), buyrex( alice, core_sym::from_string("350.0000") ) );
cur_ramfee_balance = get_balance( "eosio.ramfee"_n );
cur_fees_balance = get_balance( "eosio.fees"_n );
asset cur_rex_balance = get_balance( "eosio.rex"_n );
BOOST_REQUIRE_EQUAL( core_sym::from_string("350.0000"), cur_rex_balance );
BOOST_REQUIRE_EQUAL( success(), buyram( bob, carol, core_sym::from_string("70.0000") ) );
BOOST_REQUIRE_EQUAL( cur_ramfee_balance, get_balance( "eosio.ramfee"_n ) );
BOOST_REQUIRE_EQUAL( cur_fees_balance, get_balance( "eosio.fees"_n ) );
BOOST_REQUIRE_EQUAL( get_balance( "eosio.rex"_n ), cur_rex_balance + core_sym::from_string("0.3500") );

cur_rex_balance = get_balance( "eosio.rex"_n );
Expand Down Expand Up @@ -4772,7 +4772,7 @@ BOOST_FIXTURE_TEST_CASE( ramfee_namebid_to_rex, eosio_system_tester ) try {
produce_block( fc::hours(24) );
produce_blocks( 2 );

BOOST_REQUIRE_EQUAL( core_sym::from_string("29.3500"), get_rex_pool()["namebid_proceeds"].as<asset>() );
BOOST_REQUIRE_EQUAL( core_sym::from_string("0.0000"), get_rex_pool()["namebid_proceeds"].as<asset>() );
BOOST_REQUIRE_EQUAL( success(), deposit( frank, core_sym::from_string("5.0000") ) );
BOOST_REQUIRE_EQUAL( success(), buyrex( frank, core_sym::from_string("5.0000") ) );
BOOST_REQUIRE_EQUAL( get_balance( "eosio.rex"_n ), cur_rex_balance + core_sym::from_string("34.3500") );
Expand Down
Loading