Referral

Git Source

Inherits: IReferral, OwnableInternal, ReentrancyGuard

State Variables

FACTORY

address internal immutable FACTORY;

Functions

constructor

constructor(address factory);

getReferrer

Returns the address of the referrer for a given user

function getReferrer(address user) public view returns (address);

Parameters

NameTypeDescription
useraddressThe address of the user

Returns

NameTypeDescription
<none>addressreferrer The address of the referrer

getRebateTier

Returns the rebate tier for a given referrer

function getRebateTier(address referrer) public view returns (RebateTier);

Parameters

NameTypeDescription
referreraddressThe address of the referrer

Returns

NameTypeDescription
<none>RebateTiertier The rebate tier

getRebatePercents

Returns the primary and secondary rebate percents

function getRebatePercents()
    external
    view
    returns (UD60x18[] memory primaryRebatePercents, UD60x18 secondaryRebatePercent);

Returns

NameTypeDescription
primaryRebatePercentsUD60x18[]The primary rebate percents (18 decimals)
secondaryRebatePercentUD60x18The secondary rebate percent (18 decimals)

getRebatePercents

Returns the primary and secondary rebate percents

function getRebatePercents(address referrer)
    public
    view
    returns (UD60x18 primaryRebatePercents, UD60x18 secondaryRebatePercent);

Returns

NameTypeDescription
primaryRebatePercentsUD60x18The primary rebate percents (18 decimals)
secondaryRebatePercentUD60x18The secondary rebate percent (18 decimals)

getRebates

Returns the rebates for a given referrer

function getRebates(address referrer) public view returns (address[] memory, uint256[] memory);

Parameters

NameTypeDescription
referreraddressThe address of the referrer

Returns

NameTypeDescription
<none>address[]tokens The tokens for which the referrer has rebates
<none>uint256[]rebates The rebates for each token (token decimals)

getRebateAmounts

Returns the primary and secondary rebate amounts for a given user and referrer

function getRebateAmounts(address user, address referrer, UD60x18 tradingFee)
    external
    view
    returns (UD60x18 primaryRebate, UD60x18 secondaryRebate);

Parameters

NameTypeDescription
useraddressThe address of the user
referreraddressThe address of the referrer
tradingFeeUD60x18The trading fee (18 decimals)

Returns

NameTypeDescription
primaryRebateUD60x18The primary rebate amount (18 decimals)
secondaryRebateUD60x18The secondary rebate amount (18 decimals)

setRebateTier

Sets the rebate tier for a given referrer - caller must be owner

function setRebateTier(address referrer, RebateTier tier) external onlyOwner;

Parameters

NameTypeDescription
referreraddressThe address of the referrer
tierRebateTierThe rebate tier

setPrimaryRebatePercent

Sets the primary rebate percents - caller must be owner

function setPrimaryRebatePercent(UD60x18 percent, RebateTier tier) external onlyOwner;

Parameters

NameTypeDescription
percentUD60x18The primary rebate percent (18 decimals)
tierRebateTierThe rebate tier

setSecondaryRebatePercent

Sets the secondary rebate percent - caller must be owner

function setSecondaryRebatePercent(UD60x18 percent) external onlyOwner;

Parameters

NameTypeDescription
percentUD60x18The secondary rebate percent (18 decimals)

useReferral

Pulls the total rebate amount from msg.sender - caller must be an authorized pool

The tokens must be approved for transfer

function useReferral(address user, address referrer, address token, UD60x18 primaryRebate, UD60x18 secondaryRebate)
    external
    nonReentrant;

Parameters

NameTypeDescription
useraddressThe address of the user
referreraddressThe address of the primary referrer
tokenaddressThe address of the token
primaryRebateUD60x18The primary rebate amount (18 decimals)
secondaryRebateUD60x18The secondary rebate amount (18 decimals)

claimRebate

Claims the rebates for the msg.sender

function claimRebate(address[] memory tokens) external nonReentrant;

Parameters

NameTypeDescription
tokensaddress[]The tokens to claim

_tryUpdateRebate

Updates the referrer rebate balance and rebate tokens, if amount is greater than zero

function _tryUpdateRebate(ReferralStorage.Layout storage l, address referrer, address token, UD60x18 amount) internal;

_trySetReferrer

Sets the referrer for a user if they don't already have one. If a referrer has already been set, return the existing referrer.

function _trySetReferrer(address user, address referrer) internal returns (address);

_revertIfPoolNotAuthorized

Reverts if the caller is not an authorized pool

function _revertIfPoolNotAuthorized() internal view;