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

ReferralRegistry

Git Source

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

NameTypeDescription
_refereeaddressThe address whose referrer is queried.

Returns

NameTypeDescription
referrer_addressThe 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

NameTypeDescription
_refereeaddressThe user being referred.
_referreraddressThe address that referred the referee.

Returns

NameTypeDescription
binded_boolWhether a new valid referral entry was successfully created.

setKeepers

Updates keeper authorization for a contract or address.

  • Only owner can call.
  • Setting _flag = true authorizes the address as a keeper.
  • Setting _flag = false removes authorization.
function setKeepers(address _keeper, bool _flag) external onlyOwner;

Parameters

NameTypeDescription
_keeperaddressAddress to update.
_flagboolWhether 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;