-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02260f0
commit cc5c202
Showing
7 changed files
with
209 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: BSD 3-Clause License | ||
pragma solidity ^0.8.24; | ||
|
||
import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
|
||
interface IWrapper { | ||
|
||
/// @notice Wraps the given amount of the given token. | ||
/// @param _amount The amount to wrap. | ||
/// @param _token The token to wrap. | ||
/// @return The amount of wrapped tokens and the wrapped token. | ||
function wrap(uint256 _amount, IERC20 _token) external returns (uint256, IERC20); | ||
|
||
/// @notice Unwraps the given amount of the given token. | ||
/// @param _amount The amount to unwrap. | ||
/// @param _token The token to unwrap. | ||
/// @return The amount of unwrapped tokens and the unwrapped token. | ||
function unwrap(uint256 _amount, IERC20 _token) external returns (uint256, IERC20); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-License-Identifier: BSD 3-Clause License | ||
pragma solidity ^0.8.24; | ||
|
||
import {Initializable} from "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; | ||
import {IERC4626} from "lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol"; | ||
import {IERC20, SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
import {IwstETH} from "src/external/lido/IwstETH.sol"; | ||
import {IWrapper} from "src/interfaces/IWrapper.sol"; | ||
|
||
contract LSDWrapper is IWrapper, Initializable { | ||
|
||
using SafeERC20 for IERC20; | ||
|
||
IERC20 public immutable wstETH; | ||
IERC20 public immutable woETH; | ||
IERC20 public immutable oETH; | ||
IERC20 public immutable stETH; | ||
|
||
// ============================================================================================ | ||
// Constructor | ||
// ============================================================================================ | ||
|
||
constructor(address _wstETH, address _woETH, address _oETH, address _stETH) { | ||
if (_wstETH == address(0) || _woETH == address(0) || _oETH == address(0) || _stETH == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
||
wstETH = IERC20(_wstETH); | ||
woETH = IERC20(_woETH); | ||
oETH = IERC20(_oETH); | ||
stETH = IERC20(_stETH); | ||
} | ||
|
||
function initialize() external initializer { | ||
stETH.forceApprove(address(wstETH), type(uint256).max); | ||
oETH.forceApprove(address(woETH), type(uint256).max); | ||
} | ||
|
||
// ============================================================================================ | ||
// External functions | ||
// ============================================================================================ | ||
|
||
/// @inheritdoc IWrapper | ||
function wrap(uint256 _amount, IERC20 _token) external returns (uint256, IERC20) { | ||
if (_token == stETH) { | ||
stETH.safeTransferFrom(msg.sender, address(this), _amount); | ||
_amount = IwstETH(address(wstETH)).wrap(_amount); | ||
wstETH.safeTransfer(msg.sender, _amount); | ||
return (_amount, wstETH); | ||
} else if (_token == oETH) { | ||
oETH.safeTransferFrom(msg.sender, address(this), _amount); | ||
return (IERC4626(address(woETH)).deposit(_amount, msg.sender), woETH); | ||
} else { | ||
return (_amount, _token); | ||
} | ||
} | ||
|
||
/// @inheritdoc IWrapper | ||
function unwrap(uint256 _amount, IERC20 _token) external returns (uint256, IERC20) { | ||
if (_token == wstETH) { | ||
wstETH.safeTransferFrom(msg.sender, address(this), _amount); | ||
_amount = IwstETH(address(wstETH)).unwrap(_amount); | ||
stETH.safeTransfer(msg.sender, _amount); | ||
return (_amount, stETH); | ||
} else if (_token == woETH) { | ||
return (IERC4626(address(woETH)).redeem(_amount, msg.sender, msg.sender), oETH); | ||
} else { | ||
return (_amount, _token); | ||
} | ||
} | ||
|
||
// ============================================================================================ | ||
// Errors | ||
// ============================================================================================ | ||
|
||
error ZeroAddress(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: BSD 3-Clause License | ||
pragma solidity ^0.8.24; | ||
|
||
import {TestAssetUtils} from "test/utils/TestAssetUtils.sol"; | ||
|
||
import "./ynLSDeWithdrawals.t.sol"; | ||
|
||
contract ynLSDeDepositAdapterTest is ynLSDeWithdrawalsTest { | ||
|
||
TestAssetUtils public testAssetUtils; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
// upgrade deposit adapter | ||
{ | ||
_upgradeContract( | ||
address(ynEigenDepositAdapter_), | ||
address(new ynEigenDepositAdapter()), | ||
abi.encodeWithSignature("initializeV2(address)", address(wrapper)) | ||
); | ||
} | ||
|
||
// deploy testAssetUtils | ||
{ | ||
testAssetUtils = new TestAssetUtils(); | ||
} | ||
} | ||
|
||
// function testDepositSTETH(uint256 _amount) public { | ||
// vm.assume(_amount > 0 && _amount <= 10 ether); | ||
|
||
// testAssetUtils.get_stETH(user, _amount); | ||
|
||
// vm.startPrank(user); | ||
// IERC20(chainAddresses.lsd.STETH_ADDRESS).approve(address(ynEigenDepositAdapter_), _amount); | ||
// uint256 _ynOut = ynEigenDepositAdapter_.deposit(IERC20(chainAddresses.lsd.STETH_ADDRESS), _amount, user); | ||
// vm.stopPrank(); | ||
|
||
// assertEq(IERC20(yneigen).balanceOf(user), _ynOut, "testDepositSTETH"); | ||
// } | ||
|
||
function testDepositOETH(uint256 _amount) public { | ||
vm.assume(_amount > 0 && _amount <= 10 ether); | ||
|
||
testAssetUtils.get_OETH(user, _amount); | ||
|
||
vm.startPrank(user); | ||
IERC20(chainAddresses.lsd.OETH_ADDRESS).approve(address(ynEigenDepositAdapter_), _amount); | ||
uint256 _ynOut = ynEigenDepositAdapter_.deposit(IERC20(chainAddresses.lsd.OETH_ADDRESS), _amount, user); | ||
vm.stopPrank(); | ||
|
||
assertEq(IERC20(yneigen).balanceOf(user), _ynOut, "testDepositOETH"); | ||
} | ||
} |
Oops, something went wrong.