ReferralRegistry
Inherits: IReferralRegistry, Ownable2Step
Author: luoyhang003
Maintains referrer–referee relationships for the Genesis Expedition event.
- A referee can only be bound once; future attempts return false.
- Self-referrals and zero-address referrers are replaced with a DEAD_ADDRESS marker.
- Only keeper contracts (staking contracts) can bind referral relationships.
- Owner can configure keeper addresses.
- The DEAD_ADDRESS is used to explicitly mark invalid or blocked relationships.
State Variables
DEAD_ADDRESS
Pseudo-referrer used to indicate invalid or rejected referral bindings.
When a user self-refers or referrer is zero address, we assign DEAD_ADDRESS.
address constant DEAD_ADDRESS = 0x000000000000000000000000000000000000dEaD
referrerOf
Tracks each user's referrer.
A value of ZERO means "not yet bound", DEAD_ADDRESS means "invalid binding".
mapping(address => address) private referrerOf
keepers
Addresses authorized to bind referrals.
Usually STOStaking and STONEUSDStaking contracts.
mapping(address => bool) private keepers
Functions
onlyKeepers
Restricts function access to keeper contracts only.
Reverts with NotKeeperContract() if caller is not authorized.
modifier onlyKeepers() ;
constructor
Initializes the Referral Registry.
Deploying address becomes owner (via Ownable2Step).
constructor() Ownable(msg.sender);
getReferrerOf
Returns the referrer for a given referee.
- Returns address(0) if not yet bound.
- Returns DEAD_ADDRESS if binding was invalid (self-referral or bad input).
function getReferrerOf(address _referee) external view returns (address referrer_);
Parameters
| Name | Type | Description |
|---|---|---|
_referee | address | The address whose referrer is queried. |
Returns
| Name | Type | Description |
|---|---|---|
referrer_ | address | The referee's referrer. |
bindReferral
Binds a referee to a referrer. Can only be called by keeper contracts.
Rules:
- A referee can only be bound once.
- Self-referrals or zero-address referrers are replaced with DEAD_ADDRESS.
- Returns true only if a successful valid binding occurred.
function bindReferral(address _referee, address _referrer) external onlyKeepers returns (bool binded_);
Parameters
| Name | Type | Description |
|---|---|---|
_referee | address | The user being referred. |
_referrer | address | The address that referred the referee. |
Returns
| Name | Type | Description |
|---|---|---|
binded_ | bool | Whether a new valid referral entry was successfully created. |
setKeepers
Updates keeper authorization for a contract or address.
- Only owner can call.
- Setting
_flag = trueauthorizes the address as a keeper. - Setting
_flag = falseremoves authorization.
function setKeepers(address _keeper, bool _flag) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
_keeper | address | Address to update. |
_flag | bool | Whether the address should be authorized as a keeper. |
_onlyKeepers
Ensures that the caller is an authorized keeper contract.
Reverts with NotKeeperContract() if keepers[msg.sender] is false.
function _onlyKeepers() internal view;