0/5
## Solution: Uniswap V3 Swap rEth to wEth Let's delve into the solution for swapping our rEth back into wEth using Uniswap V3. We'll be using the internal function `swap`, which handles the specifics of interacting with Uniswap V3. Our task is to pass the correct parameters to this internal function. These parameters include `tokenIn`, `tokenOut`, `fee`, `amountIn`, `amountOutMin`, and the `receiver`. In the process of swapping our rEth back to wEth, we first need to transfer rEth from the message sender into the contract. Then, we approve the Uniswap V3 router to use that rEth from this contract. ```solidity reth.transferFrom(msg.sender, address(this), rEthAmount); ``` Next, we approve the Uniswap V3 router. ```solidity reth.approve(address(router), rEthAmount); ``` Following this, we call the internal function `swap`: ```solidity swap( ); ``` We define `tokenIn` as rEth and `tokenOut` as wEth: ```solidity swap( RETH, WETH, ); ``` The pool fee, which identifies the pool, is a constant imported at the top of the file. Let’s copy that, go back down, and paste it. ```solidity swap( RETH, WETH, UNISWAP_V3_POOL_FEE_RETH_WETH, ); ``` Next, we include the amount in: ```solidity swap( RETH, WETH, UNISWAP_V3_POOL_FEE_RETH_WETH, rEthAmountIn, ); ``` After this, we specify the amount out min: ```solidity swap( RETH, WETH, UNISWAP_V3_POOL_FEE_RETH_WETH, rEthAmountIn, wEthAmountOutMin, ); ``` Finally, we define the receiver of wEth: ```solidity swap( RETH, WETH, UNISWAP_V3_POOL_FEE_RETH_WETH, rEthAmountIn, wEthAmountOutMin, address(this) ); ``` With the code complete, we can now execute the test. The test command is as follows: ```bash forge test --fork-url $FORK_URL --match-path test/exercise-swap-uniswap-v3.sol --match-test test_swapRethToWeth -vvv ``` In this command, the test file is `exercise-swap-uniswap-v3.sol`, and the function we're calling is `test_swapRethToWeth`. The execution gives us back approximately 1.120 wEth.
A comprehensive guide to swapping rETH back into WETH using Uniswap V3. The lesson covers how to interact with Uniswap V3's swap router to exchange rETH for WETH and demonstrates the use of constants for streamlining the process.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Rocket Pool rETH staking, yield mechanisms, trading options, and contract architecture
How to distribute rewards and calculate rETH/ETH exchange rate
How to acquire and redeem rETH
Integrating rETH into DeFi protocols like AAVE V3
How to how to create leveraged ETH positions using rETH
How to provide rETH as liquidity to Balancer and Aura
Getting the USD price of rETH using Rocket Pool NAV oracle
Re-staking with EigenLayer
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 12, 2025
Stay in the loop with the latest Rocket Pool updates and connect with over 5,000 developers in the community.
Solidity Developer
Rocket Pool rETH IntegrationDuration: 4min
Duration: 48min
Duration: 57min
Duration: 30min
Duration: 7min
Duration: 23min
Duration: 6min
Course Overview
About the course
Rocket Pool rETH staking, yield mechanisms, trading options, and contract architecture
How to distribute rewards and calculate rETH/ETH exchange rate
How to acquire and redeem rETH
Integrating rETH into DeFi protocols like AAVE V3
How to how to create leveraged ETH positions using rETH
How to provide rETH as liquidity to Balancer and Aura
Getting the USD price of rETH using Rocket Pool NAV oracle
Re-staking with EigenLayer
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 12, 2025
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