Router

Router serves as an entry point for swapping, depositing, and withdrawing. It helps users handle WETH wrap/unwrap issues and prevents token approval for multiple pairs. Users can deposit dual investments, swap, boost, and stake DYSON.

rely

Allows another address to transfer tokens from this contract.

function rely(
    address tokenAddress, 
    address contractAddress, 
    bool enable) onlyOwner external

Parameters:

NameTypeDescription

tokenAddress

address

Address of the token to approve.

contractAddress

address

Address to grant allowance.

enable

bool

True to enable allowance, false otherwise.

rescueERC20

Rescues tokens stuck in this contract.

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

Parameters:

NameTypeDescription

tokenAddress

address

Address of the token to be rescued.

to

address

Address that will receive the rescued tokens.

amount

uint

Amount of tokens to be rescued.

receive

Receives ETH only from the WETH contract.

receive() external payable

_swap

Internal function responsible for executing token swaps. Essentially, this function triggers the swap function within the Pair contract.

function _swap(
    address tokenIn, 
    address tokenOut, 
    uint index, 
    address to, 
    uint input, 
    uint minOutput) internal returns (uint output)

Parameters:

NameTypeDescription

tokenIn

address

Address of the token to swap.

tokenOut

address

Address of the received token.

index

uint

Number of the pair instance.

to

address

Address that will receive the output token.

input

uint

Amount of tokenIn to swap.

minOutput

uint

Minimum amount of tokenOut expected.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received.

unwrapAndSendETH

Internal function to unwrap WETH and send ETH. This function is utilized in executing withdrawETH , swapETHOut and swapETHOutWithMultiHops operations.

function unwrapAndSendETH(
    address to, 
    uint amount) internal

Parameters:

NameTypeDescription

to

address

Address that will receive the ETH.

amount

uint

Amount of ETH to unwrap and send.

swap

External function for swapping tokenIn for tokenOut. This functions simply invokes _swap .

function swap(
    address tokenIn, 
    address tokenOut, 
    uint index, 
    address to, 
    uint input, 
    uint minOutput) external returns (uint output)

Parameters:

NameTypeDescription

tokenIn

address

Address of the spent token.

tokenOut

address

Address of the received token.

index

uint

Number of the pair instance.

to

address

Address that will receive tokenOut.

input

uint

Amount of tokenIn to swap.

minOutput

uint

Minimum amount of tokenOut expected.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received.

swapETHIn

Swaps ETH for tokenOut. This function converts input ETH to WETH before executing an actual swap.

function swapETHIn(
    address tokenOut, 
    uint index, 
    address to, 
    uint minOutput) external payable returns (uint output)

Parameters:

NameTypeDescription

tokenOut

address

Address of the received token.

index

uint

Number of the pair instance.

to

address

Address that will receive tokenOut.

minOutput

uint

Minimum amount of tokenOut expected.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received.

swapETHOut

Swaps tokenIn for ETH. This function converts output WETH to ETH after executing an actual swap, and send ETH back to the swapper.

function swapETHOut(
    address tokenIn, 
    uint index, 
    address to, 
    uint input, 
    uint minOutput) external returns (uint output)

Parameters:

NameTypeDescription

tokenIn

address

Address of the spent token.

index

uint

Number of the pair instance.

to

address

Address that will receive ETH.

input

uint

Amount of tokenIn to swap.

minOutput

uint

Minimum amount of ETH expected.

Return Values:

NameTypeDescription

output

uint

Amount of ETH received.

swapWithMultiHops

Swaps tokenIn for tokenOut with multiple hops. Please refer to swap with multiple hops section for an in-depth understanding of how this operation functions.

function swapWithMultiHops(
    address[] calldata tokens, 
    uint[] calldata indexes, 
    address to, 
    uint input, 
    uint minOutput) external returns (uint output)

Parameters:

NameTypeDescription

tokens

address[]

Array of swapping tokens.

indexes

uint[]

Array of pair instance.

to

address

Address that will receive tokenOut.

input

uint

Amount of tokenIn to swap.

minOutput

uint

Minimum amount of tokenOut expected.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received.

swapETHInWithMultiHops

Swaps ETH for tokenOut with multiple hops. Please refer to swap with multiple hops section for an in-depth understanding of how this operation functions.

function swapETHInWithMultiHops(
    address[] calldata tokens, 
    uint[] calldata indexes, 
    address to, 
    uint minOutput) external payable returns (uint output)

Parameters:

NameTypeDescription

tokens

address[]

Array of swapping tokens.

indexes

uint[]

Array of pair instance.

to

address

Address that will receive tokenOut.

minOutput

uint

Minimum amount of tokenOut expected.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received.

swapETHOutWithMultiHops

Swaps tokenIn for ETH with multiple hops. Please refer to swap with multiple hops section for an in-depth understanding of how this operation functions.

function swapETHOutWithMultiHops(
    address[] calldata tokens, 
    uint[] calldata indexes, 
    address to, 
    uint input, 
    uint minOutput) external returns (uint output)

Parameters:

NameTypeDescription

tokens

address[]

Array of swapping tokens.

indexes

uint[]

Array of pair instance.

to

address

Address that will receive ETH.

input

uint

Amount of tokenIn to swap.

minOutput

uint

Minimum amount of ETH expected.

Return Values:

NameTypeDescription

output

uint

Amount of ETH received.

_deposit

Internal function to perform a dual investment deposit. Essentially, this function simply triggers the deposit functions in Pair contract.

function _deposit(
    address tokenIn, 
    address tokenOut, 
    uint index, 
    address to, 
    uint input, 
    uint minOutput, 
    uint time) internal returns (uint output)

Parameters:

NameTypeDescription

tokenIn

address

Address of the spent token.

tokenOut

address

Address of the received token.

index

uint

Number of the pair instance.

to

address

Address that will receive Pair note.

input

uint

Amount of tokenIn to deposit.

minOutput

uint

Minimum amount of tokenOut expected if the swap is performed.

time

uint

Lock time for the deposit.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received if the swap is performed.

deposit

External function for depositing tokenIn to receive Pair notes. This function simply triggers the _deposit function.

function deposit(
    address tokenIn, 
    address tokenOut, 
    uint index, 
    address to, 
    uint input, 
    uint minOutput, 
    uint time) external returns (uint output)

Parameters:

NameTypeDescription

tokenIn

address

Address of the spent token.

tokenOut

address

Address of the received token.

index

uint

Number of the pair instance.

to

address

Address that will receive Pair note.

input

uint

Amount of tokenIn to deposit.

minOutput

uint

Minimum amount of tokenOut expected if the swap is performed.

time

uint

Lock time for the deposit.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received if the swap is performed.

depositETH

Deposits ETH to receive Pair notes. This function converts input ETH to WETH before executing an actual deposit to Pair contract.

function depositETH(
    address tokenOut, 
    uint index, 
    address to, 
    uint minOutput, 
    uint time) external payable returns (uint output)

Parameters:

NameTypeDescription

tokenOut

address

Address of the received token.

index

uint

Number of the pair instance.

to

address

Address that will receive Pair note.

minOutput

uint

Minimum amount of tokenOut expected if the swap is performed.

time

uint

Lock time for the deposit.

Return Values:

NameTypeDescription

output

uint

Amount of tokenOut received if the swap is performed.

withdraw

Withdraws a Pair note. This function simply triggers the withdrawFrom function in Pair contract.

Please refer to withdraw through Router section for an in-depth understanding of how this operation functions.

function withdraw(
    address pair, 
    uint index, 
    address to) external returns (uint token0Amt, uint token1Amt)

Parameters:

NameTypeDescription

pair

address

Pair contract address.

index

uint

Index of the note to withdraw.

to

address

Address that will receive either token0 or token1.

Return Values:

NameTypeDescription

token0Amt

uint

Amount of token0 withdrawn.

token1Amt

uint

Amount of token1 withdrawn.

withdrawMultiPositions

Withdraws multiple Pair notes. This function withdraws multiple positions of a user across the pools.

Please refer to withdraw through Router section for an in-depth understanding of how this operation functions.

function withdrawMultiPositions(
    address[] calldata pairs, 
    uint[] calldata indexes, 
    address[] calldata tos) external returns (uint[] memory token0Amounts, uint[] memory token1Amounts)

Parameters:

NameTypeDescription

pairs

address[]

Array of Pair contract addresses.

indexes

uint[]

Array of indexes of the notes to withdraw.

tos

address[]

Array of addresses that will receive either token0 or token1.

Return Values:

NameTypeDescription

token0Amounts

uint[]

Array of amounts of token0 withdrawn.

token1Amounts

uint[]

Array of amounts of token1 withdrawn.

withdrawETH

Withdraws a Pair note and, if either token0 or token1 withdrawn is WETH, withdraws from WETH and sends ETH to the receiver.

function withdrawETH(
    address pair, 
    uint index, 
    address to) external returns (uint token0Amt, uint token1Amt)

Parameters:

NameTypeDescription

pair

address

Pair contract address.

index

uint

Index of the note to withdraw.

to

address

Address that will receive either token0 or token1.

Return Values:

NameTypeDescription

token0Amt

uint

Amount of token0 withdrawn.

token1Amt

uint

Amount of token1 withdrawn.

depositToGauge

Deposits sDYSON to a gauge. This function simply triggers deposit function in Gauge contract.

function depositToGauge(
    address gauge, 
    uint amount, 
    address to) external

Parameters:

NameTypeDescription

gauge

address

Gauge contract address.

amount

uint

Amount of sDYSON to deposit.

to

address

Address that owns the position of this deposit.

stakeDyson

Stakes DYSON to sDYSON. This function simply triggers stake function in sDYSON contract.

function stakeDyson(
    address to, 
    uint amount, 
    uint lockDuration) external returns (uint sDYSONAmount)

Parameters:

NameTypeDescription

to

address

Address that owns the position of this stake.

amount

uint

Amount of DYSON to stake.

lockDuration

uint

Lock duration.

Return Values:

NameTypeDescription

sDYSONAmount

uint

Amount of sDYSON received.

selfPermit

Enables this contract to expend a specified token from the msg.sender to facilitate ERC-2612 functionality.

function selfPermit(
    address token,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s) public 

Parameters:

NameTypeDescription

token

address

Address of the token spent.

value

uint

The amount that can be spent of token.

deadline

uint

A timestamp, the current block time must be less than or equal to this timestamp.

v

uint8

Must produce a valid secp256k1 signature from the holder along with r and s.

r

bytes32

Must produce a valid secp256k1 signature from the holder along with v and s.

s

bytes32

Must produce a valid secp256k1 signature from the holder along with v and r.

setApprovalForAllWithSig

Sets approval for all positions of a pair using a signature. Please refer to Approve Router for withdrawal with signature section for an in-depth understanding of how this operation functions.

function setApprovalForAllWithSig(
    address pair, 
    bool approved, 
    uint deadline, 
    bytes calldata sig) public

Parameters:

NameTypeDescription

pair

address

Pair contract address.

approved

bool

True to approve, false to revoke.

deadline

uint

Deadline when the signature expires.

sig

bytes

Signature.

multicall

Multi delegatecall without supporting payable. This function is primarily utilized when a user needs to set approval for withdrawal across multiple pools.

function multicall(
    bytes[] calldata data) public returns (bytes[] memory results)

Parameters:

NameTypeDescription

data

bytes[]

Array of bytes of function calldata to be delegate called.

Return Values:

NameTypeDescription

results

bytes[]

Array of bytes containing the results of each delegate call.

fairPrice

Calculates the price of token1 in token0 based on the following formula:

fairPrice = reserve1 * sqrt(1-fee0) / (reserve0 * sqrt(1-fee1) )

Explore the fair price section in our white paper for comprehensive insights into the price calculation mechanism.

function fairPrice(
    address pair, 
    uint token0Amt) external view returns (uint token1Amt)

Parameters:

NameTypeDescription

pair

address

Pair contract address.

token0Amt

uint

Amount of token0.

Return Values:

NameTypeDescription

token1Amt

uint

Amount of token1.

Last updated