IRouterAdapter

Git Source

Functions

adapterSwap

Performs a tokenIn -> tokenOut swap, according to the provided params. If tokenIn is ETH_ADDRESS, this method should be invoked with msg.value = amountIn. If tokenIn is ERC20, the tokens should be already transferred to this contract (using msg.value = 0). If tokenOut is ETH_ADDRESS, native ETH will be sent to the recipient (be aware of potential reentrancy). If tokenOut is ERC20, the tokens will be transferred to the recipient.

Contracts implementing {IRouterAdapter} interface are required to enforce the above restrictions. On top of that, they must ensure that exactly amountOut worth of tokenOut is transferred to the recipient. Swap deadline and slippage is checked outside of this contract.

function adapterSwap(
    address recipient,
    address tokenIn,
    uint256 amountIn,
    address tokenOut,
    bytes calldata rawParams
)
    external
    payable
    returns (uint256 amountOut);

Parameters

NameTypeDescription
recipientaddressAddress to receive the swapped token
tokenInaddressToken to sell (use ETH_ADDRESS to start from native ETH)
amountInuint256Amount of tokens to sell
tokenOutaddressToken to buy (use ETH_ADDRESS to end with native ETH)
rawParamsbytesAdditional swap parameters

Returns

NameTypeDescription
amountOutuint256Amount of bought tokens