PandExchange

Technical documentation of the PandExchange V1 contract

Contract name: PandExchange

Code source: Public soon

Data structure

UserDCAData

struct UserDCAData {
    uint256 periodDays;
    uint256 totalOccurrences;
    uint256 currentOccurrence;
    uint256 amountPerOccurrence;
    address tokenIn;
    address tokenOut;
    uint256 tokenInLockedAmount;
    address[] swapPath;
    uint256 fee5Decimals;
    address exchangeRouterAddress;
    uint256 slippageTolerance5Decimals;
}

The data structure holding all the information for a single DCAO of a user. The user address is not present in the structure as each UserDCAData object is linked to the user address by a mapping in the MapDCA public variable.

Public variables

MapDCA

mapping(address => mapping(uint256 => UserDCAData)) public mapDCA;

The mapping responsible for stocking all the DCAO of every users. Each user address is mapped to another mapping which link an ID to the corresponding UserDCAData object. To get the DCAO of user, you need his address and the ID of the specific DCAO you are looking for. The ID is the block.timestamp of the time the DCAO has been created. It ensures unicity for the IDs for each user.

Read functions

GetOwner

function getOwner() public view returns (address)

This function return the address of the contract's owner. The owner address is used to send the fee taken at each DCAO creation on the contract

Write functions

addNewDCAToUser

function addNewDCAToUser(
        UserDCAData memory _userDCAData,
        uint256 _amountOutMinFirstTransaction
    ) external payable notPaused returns (uint256)

This function allows an user to create a new DCAO for himself. It cannot be called if the contract is paused.

Event: Emits AddedNewDCA

Parameters:

Return value(s):

Note: As the first occurrence is executed at the creation of a DCAO, the executeSingleUserDCA function is also called. Find its description below.

executeSingleUserDCA

function executeSingleUserDCA(
        address _userAddress,
        uint256 _DCAStartDate,
        uint256 _amountOutMin
    ) public notPaused

This function execute an occurrence of a DCAO for any user. This does two things: Updating the state of the concerned DCAO in the contract, and performing the swap. It cannot be used while the contract is paused.

Events: Emit OccurrenceExecuted

Parameters:

deleteUserDCA

function deleteUserDCA(uint256 _startDate) external

This function delete the DCAO of an user. Doing so transfer back to the user all unused input token. This function can be used even if the contract is paused, so that it is not possible to block any users' funds

Events: Emit DeletedDCA

Parameters:

modifyDCAFee

function modifyDCAFee(uint256 _newFee5Decimals, uint256 _DCAStartDate)
        public
        notPaused

This function allows an user to modify the executor's fee for one of its DCAO. This function cannot be used when the contract is paused.

Events: Emit FeeUpdated

Parameters:

modifySlippageTolerance

function modifySlippageTolerance(uint256 _DCAStartDate, uint256 _newSlippage)
        public
        notPaused

This function allows an user to update the slippage tolerance for each swap of a specific DCAO. This function cannot be used when the contract is paused.

Event: Emit SlippageToleranceUpdated

Parameters:

setOwner

function setOwner(address _newOwner) public onlyOwner

This function allow the current contract's owner to change the owner address

Event: Emit NewOwner

Parameters:

pause

function pause() public onlyOwner

This function pause the contract preventing certain functions to be executed, such as addNewDCAToUser or executeSingleUserDCA. Only the owner can pause the contract

Event: None

Parameters: None

unPause

function unPause() public onlyOwner

This function unpause the contract allowing certain functions to be executed, such as addNewDCAToUser or executeSingleUserDCA. Only the owner can unpause the contract

Event: None

Parameters: None

Events

AddedNewDCA

event AddedNewDCA(
        uint256 indexed DCACreationTimestamp,
        address indexed userAddress,
        uint256 totalOccurrence,
        uint256 period,
        uint256 amountPerOccurrence,
        address tokenIn,
        address tokenOut,
        uint256 fee5Decimals,
        address exchangeRouterAddress,
        uint256 slippageTolerance5Decimals
    );

Emitted when a DCAO is created on the contract. It exposes the key information for this DCAO for anyone to keep track of it.

OccurrenceExecuted

event OccurrenceExecuted(
        uint256 indexed DCACreationTimestamp,
        address indexed userAddress,
        uint256 totalOccurrence,
        uint256 currentOccurrence,
        uint256 nextOccurrenceTimestamp,
        uint256 estimatedMinimumAmountOut,
        address tokenIn,
        address tokenOut,
        uint256 tokenInAmount,
        uint256 fee5Decimals
    );

Emitted when an occurrence of a DCAO is executed.

DeletedDCA

event DeletedDCA(
        uint256 indexed DCACreationTimestamp,
        address indexed userAddress
    );

Emitted when a DCA is deleted

FeeUpdated

event FeeUpdated(
        address indexed owner,
        uint256 indexed DCACreationTimestamp,
        uint256 oldFee,
        uint256 newFee
    );

Emitted when the executor's fee of a DCAO is updated

SlippageToleranceUpdated

event SlippageTolerancegeUpdated(
        address indexed owner,
        uint256 indexed DCACreationTimestamp,
        uint256 oldSlippageTolerance,
        uint256 newSlippageTolerance
    );

Emitted when the slippage tolerance of a DCAO is updated

NewOwner

event NewOwner(address indexed oldOwner, address indexed newOwner);

Emitted when the contract's owner is changed

Last updated