IRouterAdapter
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
Name | Type | Description |
---|---|---|
recipient | address | Address to receive the swapped token |
tokenIn | address | Token to sell (use ETH_ADDRESS to start from native ETH) |
amountIn | uint256 | Amount of tokens to sell |
tokenOut | address | Token to buy (use ETH_ADDRESS to end with native ETH) |
rawParams | bytes | Additional swap parameters |
Returns
Name | Type | Description |
---|---|---|
amountOut | uint256 | Amount of bought tokens |