0/5
# `SwapRocketPool.calcEthToReth` exercise Write your code inside the [`SwapRocketPool` contract](https://github.com/Cyfrin/defi-reth/blob/main/foundry/src/exercises/SwapRocketPool.sol) This exercise is design to implement a function that will calculate the exchange rate from ETH to rETH minus the deposit fee. ```solidity function calcEthToReth(uint256 ethAmount) external view returns (uint256 rEthAmount, uint256 fee) { // Write your code here } ``` ## Instructions 1. **Calculate the ETH to rETH exchange rate** - Implement logic to compute the amount of rETH given `ethAmount`. `rEthAmount` must include the deposit fee. > **Hint:** Check the Rocket Pool contracts (`RocketDepositPool` and `RocketTokenRETH`) for how to fetch > data that are needed to calculate the exchange rate. ## Testing ```shell forge test --fork-url $FORK_URL --match-path test/exercise-swap-rocket-pool.sol --match-test test_calcEthToReth -vvv ```
SwapRocketPool.calcEthToReth
exerciseWrite your code inside the SwapRocketPool
contract
This exercise is design to implement a function that will calculate the exchange rate from ETH to rETH minus the deposit fee.
Calculate the ETH to rETH exchange rate
Implement logic to compute the amount of rETH given ethAmount
. rEthAmount
must include the deposit fee.
Hint: Check the Rocket Pool contracts (
RocketDepositPool
andRocketTokenRETH
) for how to fetch
data that are needed to calculate the exchange rate.
A practical guide to implementing ETH to rETH swap calculations in a Solidity smart contract. The lesson focuses on fetching necessary data from Rocket Pool contracts to calculate the exchange rate and deposit fee, then using it to accurately determine the amount of rETH received for a given ETH amount.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Stay in the loop with the latest Rocket Pool updates and connect with over 5,000 developers in the community.
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 July 8, 2025
Duration: 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 July 8, 2025