diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index 5e514e8..930c95b 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -24,6 +24,15 @@ // be set to 0. #define CHANNEL_RAM_AND_NAMEBID_FEES_TO_REX 1 +#ifdef MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS +#undef MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS +#endif +// MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS macro determines whether matured REX is sold immediately and buying REX is moved immediately to REX savings. +// In order to enable this behavior, the macro must be set to 1. +// https://github.com/eosnetworkfoundation/eos-system-contracts/issues/134 +// https://github.com/eosnetworkfoundation/eos-system-contracts/issues/135 +#define MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS 0 + namespace eosiosystem { using eosio::asset; @@ -1588,6 +1597,7 @@ namespace eosiosystem { int64_t read_rex_savings( const rex_balance_table::const_iterator& bitr ); void put_rex_savings( const rex_balance_table::const_iterator& bitr, int64_t rex ); void update_rex_stake( const name& voter ); + void sell_rex( const name& from, const asset& rex ); void add_loan_to_rex_pool( const asset& payment, int64_t rented_tokens, bool new_loan ); void remove_loan_from_rex_pool( const rex_loan& loan ); diff --git a/contracts/eosio.system/src/rex.cpp b/contracts/eosio.system/src/rex.cpp index ab33409..b1d883f 100644 --- a/contracts/eosio.system/src/rex.cpp +++ b/contracts/eosio.system/src/rex.cpp @@ -62,7 +62,10 @@ namespace eosiosystem { const asset delta_rex_stake = add_to_rex_balance( from, amount, rex_received ); runrex(2); update_rex_account( from, asset( 0, core_symbol() ), delta_rex_stake ); - mvtosavings( from, rex_received ); + + #if MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS + mvtosavings( from, rex_received ); + #endif // dummy action added so that amount of REX tokens purchased shows up in action trace rex_results::buyresult_action buyrex_act( rex_account, std::vector{ } ); @@ -103,6 +106,11 @@ namespace eosiosystem { auto rex_stake_delta = add_to_rex_balance( owner, payment, rex_received ); runrex(2); update_rex_account( owner, asset( 0, core_symbol() ), rex_stake_delta - payment, true ); + + #if MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS + mvtosavings( owner, rex_received ); + #endif + // dummy action added so that amount of REX tokens purchased shows up in action trace rex_results::buyresult_action buyrex_act( rex_account, std::vector{ } ); buyrex_act.send( rex_received ); @@ -111,7 +119,11 @@ namespace eosiosystem { void system_contract::sellrex( const name& from, const asset& rex ) { require_auth( from ); + sell_rex( from, rex ); + } + void system_contract::sell_rex( const name& from, const asset& rex ) + { runrex(2); auto bitr = _rexbalance.require_find( from.value, "user must first buyrex" ); @@ -983,6 +995,11 @@ namespace eosiosystem { rb.matured_rex += rb.rex_maturities.front().second; rb.rex_maturities.erase(rb.rex_maturities.begin()); } + #if MATURED_REX_SOLD_AND_BUY_REX_TO_SAVINGS + if ( rb.matured_rex > 0 ) { + sell_rex(rb.owner, asset(rb.matured_rex, rex_symbol)); + } + #endif }); }