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.

Name
Type
Description

periodDays

uint256

The minimum time between each occurrences, in days. A value of 2 means that the DCAO will be executed every two days

totalOccurrences

uint256

The total number of occurrences in the DCAO

currentOccurrence

uint256

The current number of exchanged that has taken place for this DCAO. A value equal to totalOccurrences means that the DCAO is over

amountPerOccurrence

uint256

The amount of tokenIn that will be exchanged at each occurrence. This amount includes the fee for the transaction executor

tokenIn

address

The address of the input token of this DCAO

tokenOut

addres

The address of the output token of this DCAO

tokenInLockedAmount

uint256

The remaining amount of tokenIn to be exchanged in this DCAO

swapPath

address[]

The path used to swap tokenIn for tokenOut

fee5Decimals

uint256

The fee set by the user for the transactions executors, with 5 decimals. Meaning a value of 100 000 means a fee of 100%, a value of 1 000 means a fee of 1%

exchangeRouterAddress

address

The address of the router where the swap will occur

slippageTolerance5Decimals

uint256

The slippage tolerance set by the user for this DCAO. It describes the maximum difference the user agree to risk between the announced exchanged amount and the real exchanged amount.

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:

Name
Type
Description

_userDCAData

UserDCAData

The data structure containing all the information about the DCAO. See the data structure part for details. Note: currentOccurrence value must be 0 when calling this function

_amountOutMinFirstTransaction

uint256

The minimum exchanged amount for the first occurrence of the DCAO. Used to avoid slippage

Return value(s):

Name
Type
Description

timestamp

uint256

The ID of the newly created DCAO

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:

Name
Type
Description

_userAddress

address

The address of the user owning the desired DCAO

_DCAStartDate

address

The ID of the desired DCAO of the user above

_amountOutMin

uint256

The minimum acceptable amount of output token obtained in the swap. It should be calculated beforehand using the DCAO slippage tolerance value

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:

Name
Type
Description

_startDate

uint256

The ID of the user's DCAO

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:

Name
Type
Description

_newFee5Decimals

uint256

The new fee to be applied for the next occurrences' execution of this specific DCAO. Written with 5 decimals

_DCAStartDate

uint256

The ID of the DCAO the user want to modify

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:

_DCAStartDate

uint256

The ID of the DCAO the user want to modify

_newSlippage

uint256

The new slippage tolerance to be applied for the next occurrences' execution of this specific DCAO. Written with 5 decimals

setOwner

function setOwner(address _newOwner) public onlyOwner

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

Event: Emit NewOwner

Parameters:

_newOwner

address

The address of the new owner of the contract

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.

DCACreationTimestamp

uint256

The ID of the created DCAO

userAddress

address

The address of the user that created the DCAO

totalOccurrence

uint256

The total number of occurrences for this DCAO

period

uint256

The time between each occurrence execution, in days

amountPerOccurrence

uint256

The amount of tokenIn per occurrence, including the executor's fee

tokenIn

address

The input token address

tokenOut

address

The output token address

fee5Decimals

uint256

The executor's fee for every occurrence of this DCAO, with 5 decimals

exchangeRouterAddress

address

The address of the router used for the swap

slippageTolerance5Decimals

uint256

The slippage tolerance for this DCAO, with 5 decimals

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.

DCACreationTimestamp

uint256

The ID of the executed DCAO

userAddress

address

The address of the owner of the executed DCAO

totalOccurrence

uint256

The total number of occurrences for this DCAO

currentOccurrence

uint256

The current number of executed occurrence of the executed DCAO

nextOccurrenceTimestamp

uint256

The time where the next occurrence of this DCAO will be able to be executed

estimatedMinimumAmountOut

uint256

The minimum amount of tokenOut that the owner of the DCAO was rewarded for this specific occurrence

tokenIn

address

The input token address

tokenOut

address

The output token address

tokenInAmount

uint256

The amount of exchanged tokenIn

fee5Decimals

uint256

The executor's fee for every occurrence of this DCAO, with 5 decimals

DeletedDCA

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

Emitted when a DCA is deleted

DCACreationTimestamp

uint256

The ID of the deleted DCAO

userAddress

address

The address of the owner of the deleted DCAO

FeeUpdated

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

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

DCACreationTimestamp

uint256

The ID of the DCAO

userAddress

address

The address of the owner of the DCAO

oldFee

uint256

The old executor's fee, with 5 decimals

newFee

uint256

The new executor's fee, with 5 decimals

SlippageToleranceUpdated

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

Emitted when the slippage tolerance of a DCAO is updated

DCACreationTimestamp

uint256

The ID of the DCAO

userAddress

address

The address of the owner of the DCAO

oldSlippageTolerance

uint256

The old slippage tolerance, with 5 decimals

newSlippageTolerance

uint256

The new slippage tolerance, with 5 decimals

NewOwner

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

Emitted when the contract's owner is changed

oldOwner

address

The address of the previous owner

newOwner

address

The address of the new owner

Last updated