Function: swap(address token, address owner, address receiver, uint256 amount, uint256 slippage)
This acts like a middleware for swapping on a specific DEX.
Inputs
tokenControl: Fully controlled by the user.
Constraints: Must be a valid address, not whitelisted.
Impact: The token to be swapped.
ownerControl: Fully controlled by the user.
Constraints: N/A.
Impact: Not used.
receiverControl: Fully controlled by the user.
Constraints: N/A.
Impact: The address to receive the swapped tokens.
amountControl: Fully controlled by the user.
Constraints: N/A; transfer logic handled in
safeTransferToSelf.Impact: The amount of tokens to be swapped.
slippageControl: Fully controlled by the user.
Constraints: N/A.
Impact: The maximum amount of slippage allowed.
Branches and code coverage (including function calls)
Intended branches
Decrease the depositing token balance of the
msg.sender.Increase the swapped token balance of the
receiver.Assure that the resulting tokens are within the slippage bounds.
Negative behavior
Should not allow swapping same token for same token.