STONEUSDStaking
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
| Name | Type | Description |
|---|---|---|
_stoneusdAddr | address | Address of STONEUSD ERC20 token. |
_expeditionAddr | address | Address of Genesis Expedition contract. |
_referralRegistryAddr | address | Address of Referral Registry contract. |
_startTime | uint256 | Timestamp 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
| Name | Type | Description |
|---|---|---|
_tokenLocked | uint256 | Amount of STONEUSD the user wants to lock. |
_referrer | address | Optional 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
| Name | Type | Description |
|---|---|---|
_player | address | Address of user. |
Returns
| Name | Type | Description |
|---|---|---|
locked_ | uint256 | Total 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
| Name | Type | Description |
|---|---|---|
_player | address | Address of user. |
Returns
| Name | Type | Description |
|---|---|---|
quota_ | uint256 | Remaining lockable STONEUSD amount. |
getEligibility
Returns whether user has already qualified for daily hammer rewards.
function getEligibility(address _player) external view returns (bool eligibility_);
Parameters
| Name | Type | Description |
|---|---|---|
_player | address | Address of user. |
Returns
| Name | Type | Description |
|---|---|---|
eligibility_ | bool | True 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
| Name | Type | Description |
|---|---|---|
_player | address | Address of user. |
Returns
| Name | Type | Description |
|---|---|---|
lockCount_ | uint256 | Count 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
| Name | Type | Description |
|---|---|---|
_referee | address | Address performing the lock. |
_referrer | address | Address that referred the referee. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether the binding operation created a new referral link. |