Function: externalSwap(address approveTarget, address swapTarget, address fromToken, address toToken, uint256 fromAmount, uint256 minToAmount, address payable to, bytes data)
Performs a swap between two tokens using external (i.e., not WOOFI) swapTarget
.
Inputs
approveTarget
Control: Fully controlled by the caller.
Constraints: Has to be whitelisted.
Impact: The address to approve tokens for.
swapTarget
Control: Fully controlled by the caller.
Constraints: Has to be whitelisted.
Impact: The address that swaps the tokens.
fromToken
Control: Fully controlled by the caller.
Constraints:
msg.sender
needs to have enough balance.Impact: The token to swap from.
toToken
Control: Fully controlled by the caller.
Constraints:
address(this)
needs to have enough balance.Impact: The token to swap to.
fromAmount
Control: Fully controlled by the caller.
Constraints:
msg.sender
needs to have enough balance offromToken
.Impact: The amount of
fromToken
to swap.
minToAmount
Control: Fully controlled by the caller.
Constraints: Checked that the returned
toToken
s are greater than or equal to this value.Impact: The minimum amount of
toToken
to receive.
to
Control: Fully controlled by the caller.
Constraints: None. Checked that it is not the zero address.
Impact: The destination address to send the swapped tokens to.
data
Control: Fully controlled by the caller.
Constraints: None.
Impact: The data to pass to the
swapTarget
.
Branches and code coverage
Intended branches
Ensure that
approveTarget
is not the zero address.Ensure that
swapTarget
is not the zero address.Ensure that
fromToken
is not the zero address.Ensure that
toToken
is not the zero address.Ensure that
to
is not the zero address.Ensure that
approveTarget
is whitelisted.Ensure that
swapTarget
is whitelisted.If
fromToken
is not ETH, transferfromAmount
from themsg.sender
and approve it toapproveTarget
.Call
swapTarget
with the provideddata
that facilitates the swap.Ensure the
swap
call was successful.Assure that the
post
balance oftoToken
is greater than or equal to thepre
balance.Ensure that the
realToAmount
is greater than or equal to theminToAmount
and greater than zero.Forward the recently swapped tokens to the
to
address.
Negative behavior
Should not reenter.