-
Notifications
You must be signed in to change notification settings - Fork 220
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
add (un)/wrapping for steth #317
Changes from 2 commits
e416d41
6ca3b87
efef4ac
242d110
be68f1f
f85d73a
ccff95c
7d1ba64
a7deced
e807f9e
1d1abbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,13 @@ pragma solidity ^0.8.17; | |
import {IAllowanceTransfer} from 'permit2/src/interfaces/IAllowanceTransfer.sol'; | ||
import {ERC20} from 'solmate/src/tokens/ERC20.sol'; | ||
import {IWETH9} from '../interfaces/external/IWETH9.sol'; | ||
import {IWSTETH} from '../interfaces/external/IWSTETH.sol'; | ||
|
||
struct RouterParameters { | ||
address permit2; | ||
address weth9; | ||
address steth; | ||
address wsteth; | ||
address seaportV1_5; | ||
address seaportV1_4; | ||
address openseaConduit; | ||
|
@@ -34,6 +37,10 @@ contract RouterImmutables { | |
/// @dev WETH9 address | ||
IWETH9 internal immutable WETH9; | ||
|
||
ERC20 internal immutable STETH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add @ dev comments |
||
|
||
IWSTETH internal immutable WSTETH; | ||
|
||
/// @dev Permit2 address | ||
IAllowanceTransfer internal immutable PERMIT2; | ||
|
||
|
@@ -99,6 +106,8 @@ contract RouterImmutables { | |
constructor(RouterParameters memory params) { | ||
PERMIT2 = IAllowanceTransfer(params.permit2); | ||
WETH9 = IWETH9(params.weth9); | ||
WSTETH = IWSTETH(params.wsteth); | ||
STETH = ERC20(params.steth); | ||
SEAPORT_V1_5 = params.seaportV1_5; | ||
SEAPORT_V1_4 = params.seaportV1_4; | ||
OPENSEA_CONDUIT = params.openseaConduit; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.4; | ||
|
||
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; | ||
|
||
/// @title Interface for wstETH | ||
interface IWSTETH is IERC20 { | ||
/// @notice wrap steth to get wsteth | ||
function wrap(uint256 stETHAmount) external returns (uint256); | ||
|
||
/// @notice unwrap wsteth to get steth | ||
function unwrap(uint256 wstETHAmount) external returns (uint256); | ||
|
||
function tokensPerStEth() external view returns (uint256); | ||
|
||
function stEthPerToken() external view returns (uint256); | ||
|
||
function stETH() external view returns (address); | ||
|
||
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) | ||
external; | ||
|
||
function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,5 +70,8 @@ library Commands { | |
uint256 constant SEAPORT_V1_4 = 0x20; | ||
uint256 constant EXECUTE_SUB_PLAN = 0x21; | ||
uint256 constant APPROVE_ERC20 = 0x22; | ||
uint256 constant WRAP_STETH = 0x23; | ||
uint256 constant UNWRAP_STETH = 0x24; | ||
|
||
// COMMAND_PLACEHOLDER for 0x23 to 0x3f (all unused) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: change comment for new command values |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ abstract contract Payments is RouterImmutables { | |
|
||
error InsufficientToken(); | ||
error InsufficientETH(); | ||
error InsufficientSTETH(); | ||
error InvalidBips(); | ||
error InvalidSpender(); | ||
|
||
|
@@ -137,4 +138,37 @@ abstract contract Payments is RouterImmutables { | |
} | ||
} | ||
} | ||
|
||
/// @notice Wrap an amount of stETH into wstETH | ||
/// @param recipient The recipient of the stETH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: wstETH |
||
/// @param amount The amount of wstETH desired | ||
function wrapSTETH(address recipient, uint256 amount) internal { | ||
if (amount == Constants.CONTRACT_BALANCE) { | ||
amount = STETH.balanceOf(address(this)); | ||
} else if (amount > STETH.balanceOf(address(this))) { | ||
revert InsufficientSTETH(); | ||
} | ||
if (amount > 0) { | ||
WSTETH.wrap(amount); | ||
if (recipient != address(this)) { | ||
WSTETH.transfer(recipient, amount); | ||
ewilz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
/// @notice Unwraps all of the contract's wstETH into stETH | ||
/// @param recipient The recipient of the stETH | ||
/// @param amountMinimum The minimum amount of ETH desired | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: amount of stETH desired |
||
function unwrapSTETH(address recipient, uint256 amountMinimum) internal { | ||
uint256 amount = WSTETH.balanceOf(address(this)); | ||
if (amount < amountMinimum) { | ||
revert InsufficientSTETH(); | ||
} | ||
if (amount > 0) { | ||
WSTETH.unwrap(amount); | ||
if (recipient != address(this)) { | ||
recipient.safeTransferETH(amount); | ||
ewilz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"UniversalRouterV1_2": "0xd0872d928672ae2ff74bdb2f5130ac12229cafaf", | ||
"UnsupportedProtocol": "0x7B46ee9BaB49bd5b37117494689A035b0F187B59" | ||
} | ||
} |
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.
added 2 commands but this number increased by 3? Seems it switched from inclusive to exclusive
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.
It looks like this was just forgotten in a past PR