Agency

This contract oversees the referral mechanism in Dyson Finance. When a user deposits in Pair and is registered in the referral system, they receive additional DYSON tokens as a reward. Each user in the referral system is designated as an Agent, and the referral of an Agent is referred to as the child of that Agent.

rescueERC20

function rescueERC20(
    address tokenAddress, 
    address to, 
    uint256 amount) onlyOwner external

Parameters:

NameTypeDescription

tokenAddress

address

Address of the ERC20 token.

to

address

Address that will receive the rescued tokens.

amount

uint

Amount of tokens to be rescued.

addController

Adds a new address as a controller. Only callable by the owner. A controller possesses the authority to invoke the adminAdd function within the Agency contract.

function addController(
    address _controller) external onlyOwner

Parameters:

NameTypeDescription

_controller

address

Address to be added as a controller.

removeController

Removes an address from the list of controllers. Only callable by the owner.

function removeController(
    address _controller) external onlyOwner

Parameters:

NameTypeDescription

_controller

address

Address to be removed from controllers.

adminAdd

Adds a new child agent to the root agent. This child becomes a 1st generation agent who owns a tier1 NFT. Only callable by the owner or controllers.

function adminAdd(
    address newUser) external returns (uint id)

Parameters:

NameTypeDescription

newUser

address

Address of the new agent.

Return Values:

NameTypeDescription

id

uint

Id of the new agent.

transfer

Transfers agent data to a different user, only callable by the AgentNFT contract. It's important to note that the agent cannot be transferred again until the cooldown time, calculated as (generation + 1) * TRANSFER_CD, is completed. This cooldown time is ten times longer than the cooldown time for swapping SP to DYSON.

function transfer(
    address from, 
    address to, 
    uint id) external returns (bool)

Parameters:

NameTypeDescription

from

address

Previous owner of the agent.

to

address

User who will receive the agent.

id

uint

Index of the agent to be transferred.

Return Values:

NameTypeDescription

None

bool

True if the transfer is successful.

register

This function is a critical component that allows users to join the referral system by providing an invite code (onceSig) and the signature of their referrer (parentSig). This function facilitates the growth of the referral network by establishing relationships between referrers and referees within the system. Let's break down the key aspects of the register function:

  1. Validation: The function checks whether the current timestamp is before the specified deadline to ensure the invite code is still valid.

  2. Agent Check: Verifies that the user calling the function does not already have an existing agent in the referral system.

  3. One-Time Code Verification: Validates the onceSig (invite code) by recovering the address associated with the provided signature. Ensures the invite code has not been used before.

  4. Referrer Signature Verification: Validates the parentSig (referrer's signature) to confirm the legitimacy of the referrer. Notice that when the parent is a contract wallet, the parentSig provided will be the address of the parent instead of a signature.

  5. Referrer Information Retrieval: Retrieves the referrer's agent information, including their ID, from the system.

  6. Registration Delay Check: Ensures that the referrer has passed the registration delay before being able to refer new users.

  7. New Agent Creation: Creates a new agent for the registering user, establishing a parent-child relationship with the referrer.

  8. One-Time Code Deactivation: Marks the invite code as used to prevent its reuse.

  9. Reward Transfer (Optional): If the user sent some Ether along with the registration, it is transferred to the referrer as a reward.

Note

  • The function makes use of cryptographic techniques, including signature verification (ecrecover), to ensure the security and integrity of the registration process.

  • The function also involves an optional Ether transfer as a reward to the referrer for bringing in a new user.

function register(
    bytes memory parentSig, 
    bytes memory onceSig, 
    uint deadline) payable external returns (uint id)

Parameters:

NameTypeDescription

parentSig

bytes

Referrer's signature or referrer's address.

onceSig

bytes

Invite code.

deadline

uint

Deadline of the invite code.

Return Values:

NameTypeDescription

id

uint

Id of the new agent.

sign

Parent on-chain pre-sign for a referral code. This function serves as an on-chain pre-signing mechanism specifically designed for contract wallets. A contract wallet is required to provide its address as an argument to the digest parameter when invoking the sign function.

function sign(
    bytes32 digest) external

Parameters:

NameTypeDescription

digest

bytes32

Digest of the referral code.

userInfo

Retrieves user's agent data.

function userInfo(
    address _owner) external view returns (address ref, uint gen)

Parameters:

NameTypeDescription

_owner

address

User's address.

Return Values:

NameTypeDescription

ref

address

Parent agent's owner address.

gen

uint

Generation of user's agent.

getAgent

Retrieves agent data by user's id.

function getAgent(
    uint id) external view returns (address, uint, uint, uint, uint[] memory)

Parameters:

NameTypeDescription

id

uint

Id of the user.

Return Values:

NameTypeDescription

owner

address

User's agent owner address.

gen

uint

Generation of user's agent.

birth

uint

Timestamp when the agent registered.

parentId

uint

Id of the agent's parent.

childrenId

uint[]

Ids of the agent's children.

Last updated