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
approveTargetControl: Fully controlled by the caller.
Constraints: Has to be whitelisted.
Impact: The address to approve tokens for.
swapTargetControl: Fully controlled by the caller.
Constraints: Has to be whitelisted.
Impact: The address that swaps the tokens.
fromTokenControl: Fully controlled by the caller.
Constraints:
msg.senderneeds to have enough balance.Impact: The token to swap from.
toTokenControl: Fully controlled by the caller.
Constraints:
address(this)needs to have enough balance.Impact: The token to swap to.
fromAmountControl: Fully controlled by the caller.
Constraints:
msg.senderneeds to have enough balance offromToken.Impact: The amount of
fromTokento swap.
minToAmountControl: Fully controlled by the caller.
Constraints: Checked that the returned
toTokens are greater than or equal to this value.Impact: The minimum amount of
toTokento receive.
toControl: 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.
dataControl: Fully controlled by the caller.
Constraints: None.
Impact: The data to pass to the
swapTarget.
Branches and code coverage
Intended branches
Ensure that
approveTargetis not the zero address.Ensure that
swapTargetis not the zero address.Ensure that
fromTokenis not the zero address.Ensure that
toTokenis not the zero address.Ensure that
tois not the zero address.Ensure that
approveTargetis whitelisted.Ensure that
swapTargetis whitelisted.If
fromTokenis not ETH, transferfromAmountfrom themsg.senderand approve it toapproveTarget.Call
swapTargetwith the provideddatathat facilitates the swap.Ensure the
swapcall was successful.Assure that the
postbalance oftoTokenis greater than or equal to theprebalance.Ensure that the
realToAmountis greater than or equal to theminToAmountand greater than zero.Forward the recently swapped tokens to the
toaddress.
Negative behavior
Should not reenter.