5/5
## Calculating ETH to rETH Exchange Rate We will show you how to calculate the amount of rETH that you can receive for putting in some amount of ETH, and also, calculate the amount of fee that is taken out from this ETH amount. We will need to do two things: - First, get the protocol settings for the deposit fee - Do some calculation - Then call into the rETH contract to calculate the amount of rETH that we will receive. Let's start with the first part of getting the protocol settings for the deposit fee. ```solidity uint256 depositFee = protocolSettings.getDepositFee(); ``` Next, let's calculate the fee. This deposit fee will represent a percentage when we divide it by the `calc_base` 1e18. So we multiply the amount of ETH (ethAmount) by this deposit fee, and then divide it by `calc_base`. ```solidity fee = ethAmount * depositFee / CALC_BASE; ``` And then the amount of rETH that you will receive is calculated by deducting this fee: ```solidity ethAmount -= fee; ``` Then we call the function: ```solidity reth.getRethValue(ethAmount); ``` passing in the `ethAmount` where the fee is already deducted. We then assign this to the variable that is returned: ```solidity rEthAmount = reth.getRethValue(ethAmount); ``` Let's execute the test ```bash forge test --fork-url $FORK_URL --match-path test/exercise-swap-rocket-pool.sol --match-test test_calcEthToReth -vvv ``` The test has passed. Let's look at the logs. The exchange rate of 1 rETH is roughly 1.12 ETH and for putting in 1 ETH we roughly get back 0.88 rETH. Here's the deposit fee.
A comprehensive guide to calculating rETH and fees when using the Rocket Pool smart contract. This lesson focuses on the logic behind the calculation and how to implement the code for both rETH and fee in Solidity.
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 28, 2025
Stay in the loop with the latest Rocket Pool updates and connect with over 5,000 developers in the community.
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 May 28, 2025