-
Notifications
You must be signed in to change notification settings - Fork 93
Lido withdraw strategy #2080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lido withdraw strategy #2080
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## sparrowDom/nativeStaking #2080 +/- ##
============================================================
- Coverage 62.52% 61.86% -0.67%
============================================================
Files 65 66 +1
Lines 3253 3322 +69
Branches 844 649 -195
============================================================
+ Hits 2034 2055 +21
- Misses 1216 1264 +48
Partials 3 3 ☔ View full report in Codecov by Sentry. |
…icka/lido-withdraw-strategy
Lido withdraw strategy
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
…icka/lido-withdraw-strategy
| weth.transfer(vaultAddress, wethBalance); | ||
| emit Withdrawal(address(weth), address(0), wethBalance); | ||
| } | ||
| uint256 fraxEthBalance = stETH.balanceOf(address(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the name of the variable refers to an other liquid staking protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good pickup. I did a search and replace for frxEth but missed fraxEth
| ); | ||
| } | ||
|
|
||
| function _abstractSetPToken(address, address) internal override { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe throw this internal method to the bottom of the contract? So it's not between all the external withdraw methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. I've also made it pure
…icka/lido-withdraw-strategy
made _abstractSetPToken pure
…icka/lido-withdraw-strategy
…icka/lido-withdraw-strategy
|
Since #2097 deployed 097 already and this PR seems to be update that, we need a different deployment file |
| uint256 stETHRemaining = stETHStart; | ||
| uint256 i = 0; | ||
| while (stETHRemaining > MaxWithdrawalAmount) { | ||
| amounts[i++] = MaxWithdrawalAmount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice I haven't seen this expression in years. Had too google that the [i++] returns the initial value but after the expression still increments it.
| const finalNativeEthBalanceVault = await oethVault.provider.getBalance( | ||
| oethVault.address | ||
| ); | ||
| expect(finalWethBalanceVault.sub(initialWethBalanceVault)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good fork tests 🙏
|
@shahthepro yeah the diff on 097 deployment file is pretty terrible :) there is a clean 098 deployment file in master that is ok. |
| IStETHWithdrawal private constant withdrawalQueue = | ||
| IStETHWithdrawal(0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1); | ||
| /// @notice Maximum amount of stETH that can be withdrawn in a single request | ||
| uint256 public constant MaxWithdrawalAmount = 1000 ether; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For constants, using upper snake case would be nice, not necessary to change at this point
RequirementsThe strategy should interact with Lido Withdrawal Queue and should be able to redeem stETH. Easy ChecksAuthentication
Ethereum
Cryptographic code
Gas problems
Black magic
Overflow
Proxy
Events
Medium ChecksRounding
Dependencies
External calls
Tests
Deploy
Strategy SpecificRemove this section if the code being reviewed is not a strategy. Strategy checks
Downstream
ThinkingLogic
Deployment ConsiderationsDeployment seems to be split and moved to a different file on master, so leaving it out of this review Internal StateEverything seems about right. The contract depends on AttackDoesn't seem to be vulnerable to common attacks. FlavorCode is simple and elegant. Doesn't seem to have any vulnerability |
| amounts[i++] = MaxWithdrawalAmount; | ||
| stETHRemaining -= MaxWithdrawalAmount; | ||
| } | ||
| amounts[i] = stETHRemaining; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this revert if the stETHRemaining == 0? Though considering current stETH balance on the vault is 17,886.18 this is highly unlikely to happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed it would revert since according to the docs (https://docs.lido.fi/contracts/withdrawal-queue-erc721/):
The minimal amount for a request is 100 wei, and the maximum is 1000 eth. More significant amounts should be split into several requests, which allows us to avoid clogging the queue with an extra large request.
Still this edge case is so highly unlinkely, that I wouldn't fix it. And in case it does happen, someone can just send some stETH dust to the Vault and the problem is solved
RequirementsThe strategy contract is interacting with Lido withdrawal queue to natively redeem stETH for ETH. Easy ChecksAuthentication
Ethereum
Cryptographic code
Gas problems
Black magic
Overflow
Proxy
Events
Medium ChecksRounding
Dependencies
External calls
Tests
Deploy
Strategy SpecificStrategy checks
Downstream
ThinkingLogic
Deployment ConsiderationsNo this is a pretty straight forward deploy. Internal State
Does this code do that? AttackWhat could the impacts of code failure in this code be. What conditions could cause this code to fail if they were not true. Does this code successfully block all attacks. FlavorCode is very clean and simple. |
|
I mistakenly merged this PR to I'll create a new branch for post merge changes |
|
Yeah I know. I've left some comments in the code, though those 2 comments that are actionable are really nitpicky. I don't think you need to do any changes. |
Contract changes
LidoWithdrawalStrategycontract to swap stETH or WETH using the Lido Withdrawa QueueDependencies
Security
If you made a contract change, make sure to complete the checklist below before merging it in master.
Refer to our documentation for more details about contract security best practices.
Contract change checklist: