From b694722bf2ab193fc53867b193717c4b3a6c9955 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Fri, 3 May 2024 13:58:37 +0200 Subject: [PATCH] Implement rex maturity changes ref: https://github.com/eosnetworkfoundation/eos-system-contracts/issues/132 --- .../include/eosio.system/eosio.system.hpp | 19 ++++++++++++++++++- contracts/eosio.system/src/eosio.system.cpp | 3 ++- contracts/eosio.system/src/rex.cpp | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index d3dfc4b7..ddaf7384 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -539,6 +539,14 @@ namespace eosiosystem { typedef eosio::multi_index< "rexqueue"_n, rex_order, indexed_by<"bytime"_n, const_mem_fun>> rex_order_table; + struct [[eosio::table("rexmaturity"),eosio::contract("eosio.system")]] rex_maturity { + uint32_t num_of_maturity_buckets = 5; + + EOSLIB_SERIALIZE( rex_maturity, (num_of_maturity_buckets) ) + }; + + typedef eosio::singleton<"rexmaturity"_n, rex_maturity> rex_maturity_singleton; + struct rex_order_outcome { bool success; asset proceeds; @@ -720,6 +728,7 @@ namespace eosiosystem { rex_fund_table _rexfunds; rex_balance_table _rexbalance; rex_order_table _rexorders; + rex_maturity_singleton _rexmaturity; public: static constexpr eosio::name active_permission{"active"_n}; @@ -1079,6 +1088,14 @@ namespace eosiosystem { [[eosio::action]] void closerex( const name& owner ); + /** + * Facilitates the modification of REX maturity buckets + * + * @param num_of_maturity_buckets - used to calculate maturity time of purchase REX tokens from end of the day UTC. + */ + [[eosio::action]] + void rexmaturity(const uint32_t num_of_maturity_buckets); + /** * Undelegate bandwidth action, decreases the total tokens delegated by `from` to `receiver` and/or * frees the memory associated with the delegation if there is nothing @@ -1569,7 +1586,7 @@ namespace eosiosystem { bool rex_loans_available()const; bool rex_system_initialized()const { return _rexpool.begin() != _rexpool.end(); } bool rex_available()const { return rex_system_initialized() && _rexpool.begin()->total_rex.amount > 0; } - static time_point_sec get_rex_maturity(); + static time_point_sec get_rex_maturity(const name& system_account_name = "eosio"_n ); asset add_to_rex_balance( const name& owner, const asset& payment, const asset& rex_received ); asset add_to_rex_pool( const asset& payment ); void add_to_rex_return_pool( const asset& fee ); diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index 527b0324..ab8c7183 100644 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -30,7 +30,8 @@ namespace eosiosystem { _rexretbuckets(get_self(), get_self().value), _rexfunds(get_self(), get_self().value), _rexbalance(get_self(), get_self().value), - _rexorders(get_self(), get_self().value) + _rexorders(get_self(), get_self().value), + _rexmaturity(get_self(), get_self().value) { _gstate = _global.exists() ? _global.get() : get_default_parameters(); _gstate2 = _global2.exists() ? _global2.get() : eosio_global_state2{}; diff --git a/contracts/eosio.system/src/rex.cpp b/contracts/eosio.system/src/rex.cpp index 99542c13..d1198b0c 100644 --- a/contracts/eosio.system/src/rex.cpp +++ b/contracts/eosio.system/src/rex.cpp @@ -8,6 +8,20 @@ namespace eosiosystem { using eosio::token; using eosio::seconds; + void system_contract::rexmaturity(const uint32_t num_of_maturity_buckets) + { + require_auth(get_self()); + + check(num_of_maturity_buckets > 0, "num_of_maturity_buckets must be positive"); + check(num_of_maturity_buckets <= 30, "num_of_maturity_buckets must be less than or equal to 30"); + + auto state = _rexmaturity.get_or_default(); + if ( _rexmaturity.exists() ) check(state.num_of_maturity_buckets != num_of_maturity_buckets, "num_of_maturity_buckets is the same as the current value"); + + state.num_of_maturity_buckets = num_of_maturity_buckets; + _rexmaturity.set(state, get_self()); + } + void system_contract::deposit( const name& owner, const asset& amount ) { require_auth( owner ); @@ -959,9 +973,10 @@ namespace eosiosystem { * * @return time_point_sec */ - time_point_sec system_contract::get_rex_maturity() + time_point_sec system_contract::get_rex_maturity( const name& system_account_name ) { - const uint32_t num_of_maturity_buckets = 5; + rex_maturity_singleton _rexmaturity(system_account_name, system_account_name.value); + const uint32_t num_of_maturity_buckets = _rexmaturity.get_or_default().num_of_maturity_buckets; // default 5 static const uint32_t now = current_time_point().sec_since_epoch(); static const uint32_t r = now % seconds_per_day; static const time_point_sec rms{ now - r + num_of_maturity_buckets * seconds_per_day };