Skip to content

Commit

Permalink
Implement rex maturity changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed May 3, 2024
1 parent 732fa98 commit b694722
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
19 changes: 18 additions & 1 deletion contracts/eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,14 @@ namespace eosiosystem {
typedef eosio::multi_index< "rexqueue"_n, rex_order,
indexed_by<"bytime"_n, const_mem_fun<rex_order, uint64_t, &rex_order::by_time>>> 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;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion contracts/eosio.system/src/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down
19 changes: 17 additions & 2 deletions contracts/eosio.system/src/rex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 };
Expand Down

0 comments on commit b694722

Please sign in to comment.