Scroll Router

Functions

swap

 /**
     * @dev  Performs a swap using the provided route and swap parameters.
     * @param   route  The route parameters for the swap.
     * @param   swap_parameters  The parameters for the swaps to perform.
     * @return  The amount of the output token received.
     */
    function swap(RouteParam calldata route, SwapParams[] calldata swap_parameters)
        external
        payable
        returns (uint256)

Paramaters

RouteParam

Parameter nameTypeDescription

token_in

address

contract address of token to sell

token_out

address

contract address of token to buy

amount_in

u256

amount of token to sell

min_received

u256

minimum received amount of user get

destination

address

The receiver address for the output token

swap_type

enum(SwapType)

swap type

SwapType(Enum)

Parameter nameValueDescription

ethToToken

0

swap Eth to erc20 token

tokenToEth

1

swap erc20 token to Eth

tokenToToken

2

swap erc20 to erc20 token

SwapParams

Parameter nameTypeDescription

token_in

address

contract address of token to sell

token_out

address

contract address of token to buy

rate

u32

rate * 10**4 gives 4 precision points

protocol_id

u32

procotol id

pool_address

address

pool contract address

swap_tpe

enum(SwapType)

swap type

extra_data

Array<felt252>

extra data for route

Events

Swap

event Swap(
       address sender,
       uint256 amount_in,
       uint256 amount_out,
       address token_in,
       address token_out,
       address destination
  )
Parameter nameTypeDescription

sender

address

address that execute the transaction.

token_in

address

contract address of token to sell

token_out

address

contract address of token to buy

amount_in

u256

amount of token to sold

amount_out

u256

amount of token to bought.

destination

address

receiver address for the output token

Last updated