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.
Parameters:
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.
Parameters:
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.
_swap
Internal function responsible for executing token swaps. Essentially, this function triggers the swap function within the Pair contract.
Parameters:
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:
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.
Parameters:
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
.
Parameters:
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:
output
uint
Amount of tokenOut received.
swapETHIn
Swaps ETH for tokenOut. This function converts input ETH to WETH before executing an actual swap.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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:
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.
Parameters:
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.
Parameters:
to
address
Address that owns the position of this stake.
amount
uint
Amount of DYSON to stake.
lockDuration
uint
Lock duration.
Return Values:
sDYSONAmount
uint
Amount of sDYSON received.
selfPermit
Enables this contract to expend a specified token from the msg.sender
to facilitate ERC-2612 functionality.
Parameters:
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.
Parameters:
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.
Parameters:
data
bytes[]
Array of bytes of function calldata to be delegate called.
Return Values:
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:
Explore the fair price section in our white paper for comprehensive insights into the price calculation mechanism.
Parameters:
pair
address
Pair contract address.
token0Amt
uint
Amount of token0.
Return Values:
token1Amt
uint
Amount of token1.
Last updated