--- Alright, our next function seems a little simpler than the last few, let's take a look. <details> <summary>sellTokenPools Function</summary> ```js /** * @notice wrapper function to facilitate users selling pool tokens in exchange of WETH * @param poolTokenAmount amount of pool tokens to sell * @return wethAmount amount of WETH received by caller */ function sellPoolTokens(uint256 poolTokenAmount) external returns (uint256 wethAmount) { return swapExactOutput(i_poolToken, i_wethToken, poolTokenAmount, uint64(block.timestamp)); } ``` </details> This function just serves as a simplified wrapper for users to call `swapExactOutput` through. With any function call passing parameters, we should verify that what's being passed is correct as well as it's order. These are easy things for developers to overlook. Refer back to `swapExactOutput`: ```js function swapExactOutput( IERC20 inputToken, IERC20 outputToken, uint256 outputAmount, uint64 deadline ) ``` So in our function call: - inputToken = i_poolToken - outputToken = i_wethToken - outputAmount = poolTokenAmount Wait. Do you spot the issue? If our inputToken is poolToken, our outputAmount can't _also_ be derived from poolToken! This should be wethTokenAmount! Massive find. ```js function sellPoolTokens(uint256 poolTokenAmount) external returns (uint256 wethAmount) { // @Audit - Incorrect parameter being passed for swapExactOutput function - poolTokenAmount! return swapExactOutput(i_poolToken, i_wethToken, poolTokenAmount, uint64(block.timestamp)); } ``` This is a perfect exactly of a bug that's a product of `business logic`. It's not a problem with the Solidity, simply the wrong variable was used. This is the type of thing that can be difficult for tooling to catch. Let's wrap up the rest of our functions in the next lesson.
Sells pool tokens for WETH; business logic error: swap exact output instead of swap exact input.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Solidity Developer
Smart Contract SecurityDuration: 25min
Duration: 1h 18min
Duration: 35min
Duration: 2h 28min
Duration: 5h 03min
Duration: 5h 22min
Duration: 4h 33min
Duration: 2h 01min
Duration: 1h 40min
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar