Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

STONEUSDStaking

Git Source

Inherits: ISTONEUSDStaking

Author: luoyhang003

Handles the entire staking logic for STONEUSD within the Genesis Expedition event.

  • Users lock STONEUSD in batches of 1000 STONEUSD.
  • Each batch grants 1 Raw Stone and (1 or 3) Hammers.
  • Users may lock up to 10 batches (10,000 STONEUSD).
  • Locked STONEUSD unlocks only once: after the event ends.
  • Integrates with GenesisExpedition for resource distribution.
  • Integrates with ReferralRegistry for referral bonus hammer rewards.

State Variables

DURATION

Duration of the staking event.

uint256 public constant DURATION = 70 days

STONEUSD_PER_LOCK

Required STONEUSD amount per valid lock batch.

uint256 public constant STONEUSD_PER_LOCK = 1_000 * 1e18

MAX_LOCK_COUNT

Maximum number of valid lock batches per user.

uint256 public constant MAX_LOCK_COUNT = 10

STONEUSD_ADDR

STONEUSD ERC20 token address.

address public immutable STONEUSD_ADDR

EXPEDITION_ADDR

Genesis Expedition main contract address.

address public immutable EXPEDITION_ADDR

REFERRAL_REGISTRY_ADDR

Referral Registry contract address.

address public immutable REFERRAL_REGISTRY_ADDR

START_TIME

Genesis Expedition start time (UTC-0 aligned).

uint256 public immutable START_TIME

END_TIME

Time when the staking period ends.

uint256 public immutable END_TIME

locked

Total STONEUSD locked per user.

mapping(address => uint256) private locked

lockCount

Number of valid lock batches a user has consumed.

mapping(address => uint256) private lockCount

isEligible

Whether the user has already qualified for daily hammer rewards.

mapping(address => bool) private isEligible

Functions

onlyEventActive

Ensures that a function can only be executed while event is active.

Active range: [START_TIME, END_TIME].

modifier onlyEventActive() ;

constructor

Initializes the STONEUSD staking module.

_startTime must be exactly aligned to UTC-0 (mod 1 days == 0).

constructor(address _stoneusdAddr, address _expeditionAddr, address _referralRegistryAddr, uint256 _startTime) ;

Parameters

NameTypeDescription
_stoneusdAddraddressAddress of STONEUSD ERC20 token.
_expeditionAddraddressAddress of Genesis Expedition contract.
_referralRegistryAddraddressAddress of Referral Registry contract.
_startTimeuint256Timestamp of event start.

lock

Allows users to lock STONEUSD to earn Raw Stones and Hammers.

  • Lock amount must be >= 1000 STONEUSD.
  • Lock amount cannot exceed remaining quota.
  • First–time lockers receive +2 bonus hammers and activation for daily hammer rewards.
function lock(uint256 _tokenLocked, address _referrer) external onlyEventActive;

Parameters

NameTypeDescription
_tokenLockeduint256Amount of STONEUSD the user wants to lock.
_referreraddressOptional referrer who may receive bonus hammers.

unlock

Unlocks all STONEUSD previously locked by the caller.

  • Unlock is allowed only after END_TIME.
  • All STONEUSD unlocks at once, not progressively.
function unlock() external;

getLockedAmount

Returns how much STONEUSD the user has locked.

function getLockedAmount(address _player) external view returns (uint256 locked_);

Parameters

NameTypeDescription
_playeraddressAddress of user.

Returns

NameTypeDescription
locked_uint256Total STONEUSD locked.

getLockQuota

Returns how much more STONEUSD the user is allowed to lock.

Maximum lock capacity = MAX_LOCK_COUNT * STONEUSD_PER_LOCK.

function getLockQuota(address _player) public view returns (uint256 quota_);

Parameters

NameTypeDescription
_playeraddressAddress of user.

Returns

NameTypeDescription
quota_uint256Remaining lockable STONEUSD amount.

getEligibility

Returns whether user has already qualified for daily hammer rewards.

function getEligibility(address _player) external view returns (bool eligibility_);

Parameters

NameTypeDescription
_playeraddressAddress of user.

Returns

NameTypeDescription
eligibility_boolTrue if user is eligible.

getLockCount

Returns the number of valid lock batches the user has performed.

function getLockCount(address _player) external view returns (uint256 lockCount_);

Parameters

NameTypeDescription
_playeraddressAddress of user.

Returns

NameTypeDescription
lockCount_uint256Count of 1000-STONEUSD lock batches.

_onlyEventActive

Internal check to ensure event is active.

Reverts if block.timestamp is outside the active event window.

function _onlyEventActive() internal view;

_bindReferral

Registers a referrer relationship for referral rewards.

Returns true only if binding succeeds and is new.

function _bindReferral(address _referee, address _referrer) internal returns (bool);

Parameters

NameTypeDescription
_refereeaddressAddress performing the lock.
_referreraddressAddress that referred the referee.

Returns

NameTypeDescription
<none>boolWhether the binding operation created a new referral link.