From 52fd7788a53f5ceb87eb1d2e2335481cf9ab3127 Mon Sep 17 00:00:00 2001 From: Terry Pawn Date: Sun, 17 Dec 2023 23:54:22 +0800 Subject: [PATCH] Rename WstETHtoStETHSwap to WstETHWrappingSwap --- contracts/swap/WstETHWrappingSwap.sol | 137 ++++++++++++++++++++++++++ contracts/swap/WstETHtoStETHSwap.sol | 62 ------------ 2 files changed, 137 insertions(+), 62 deletions(-) create mode 100644 contracts/swap/WstETHWrappingSwap.sol delete mode 100644 contracts/swap/WstETHtoStETHSwap.sol diff --git a/contracts/swap/WstETHWrappingSwap.sol b/contracts/swap/WstETHWrappingSwap.sol new file mode 100644 index 00000000..aadcfd4f --- /dev/null +++ b/contracts/swap/WstETHWrappingSwap.sol @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity >=0.6.10 <0.8.0; + +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; +import "../interfaces/IStableSwap.sol"; +import "../interfaces/IWstETH.sol"; +import "../utils/SafeDecimalMath.sol"; + +contract WstETHWrappingSwap is IStableSwap { + using SafeERC20 for IERC20; + using SafeDecimalMath for uint256; + + address public immutable wstETH; // Base + address public immutable stETH; // Quote + + constructor(address wstETH_) public { + wstETH = wstETH_; + stETH = IWstETH(wstETH_).stETH(); + } + + function getQuoteOut(uint256 baseIn) external view override returns (uint256 quoteOut) { + quoteOut = IWstETH(wstETH).getStETHByWstETH(baseIn); + } + + function getQuoteIn(uint256 baseOut) external view override returns (uint256 quoteIn) { + quoteIn = IWstETH(wstETH).getStETHByWstETH(baseOut); + } + + function getBaseOut(uint256 quoteIn) external view override returns (uint256 baseOut) { + baseOut = IWstETH(wstETH).getWstETHByStETH(quoteIn); + } + + function getBaseIn(uint256 quoteOut) external view override returns (uint256 baseIn) { + baseIn = IWstETH(wstETH).getWstETHByStETH(quoteOut); + } + + function buy( + uint256, + uint256, + address recipient, + bytes calldata + ) external override returns (uint256 realBaseOut) { + uint256 quoteIn = IERC20(stETH).balanceOf(address(this)); + realBaseOut = IWstETH(wstETH).wrap(quoteIn); + IERC20(wstETH).safeTransfer(recipient, realBaseOut); + } + + function sell( + uint256, + uint256, + address recipient, + bytes calldata + ) external override returns (uint256 realQuoteOut) { + uint256 baseIn = IERC20(wstETH).balanceOf(address(this)); + realQuoteOut = IWstETH(wstETH).unwrap(baseIn); + IERC20(stETH).safeTransfer(recipient, realQuoteOut); + } + + function baseAddress() external view override returns (address) { + return wstETH; + } + + function quoteAddress() external view override returns (address) { + return stETH; + } + + function getOraclePrice() external view override returns (uint256) { + return IWstETH(wstETH).stEthPerToken(); + } + + function getCurrentPrice() external view override returns (uint256) { + return IWstETH(wstETH).stEthPerToken(); + } + + function fund() external view override returns (IFundV3) { + revert("Not implemented"); + } + + function baseTranche() external view override returns (uint256) { + revert("Not implemented"); + } + + function allBalances() external view override returns (uint256, uint256) { + revert("Not implemented"); + } + + function getCurrentD() external view override returns (uint256) { + revert("Not implemented"); + } + + function getCurrentPriceOverOracle() external view override returns (uint256) { + revert("Not implemented"); + } + + function getPriceOverOracleIntegral() external view override returns (uint256) { + revert("Not implemented"); + } + + function addLiquidity(uint256, address) external override returns (uint256) { + revert("Not implemented"); + } + + function removeLiquidity( + uint256, + uint256, + uint256, + uint256 + ) external override returns (uint256, uint256) { + revert("Not implemented"); + } + + function removeLiquidityUnwrap( + uint256, + uint256, + uint256, + uint256 + ) external override returns (uint256, uint256) { + revert("Not implemented"); + } + + function removeBaseLiquidity(uint256, uint256, uint256) external override returns (uint256) { + revert("Not implemented"); + } + + function removeQuoteLiquidity(uint256, uint256, uint256) external override returns (uint256) { + revert("Not implemented"); + } + + function removeQuoteLiquidityUnwrap( + uint256, + uint256, + uint256 + ) external override returns (uint256) { + revert("Not implemented"); + } +} diff --git a/contracts/swap/WstETHtoStETHSwap.sol b/contracts/swap/WstETHtoStETHSwap.sol deleted file mode 100644 index fb16d9a5..00000000 --- a/contracts/swap/WstETHtoStETHSwap.sol +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -pragma solidity >=0.6.10 <0.8.0; - -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; -import "../utils/SafeDecimalMath.sol"; -import "../interfaces/IWstETH.sol"; - -contract WstETHtoStETHSwap { - using SafeERC20 for IERC20; - using SafeDecimalMath for uint256; - - address public immutable wstETH; // Base - address public immutable stETH; // Quote - - constructor(address wstETH_) public { - wstETH = wstETH_; - stETH = IWstETH(wstETH_).stETH(); - } - - function getQuoteOut(uint256 baseIn) external view returns (uint256 quoteOut) { - quoteOut = IWstETH(wstETH).getStETHByWstETH(baseIn); - } - - function getQuoteIn(uint256 baseOut) external view returns (uint256 quoteIn) { - quoteIn = IWstETH(wstETH).getStETHByWstETH(baseOut); - } - - function getBaseOut(uint256 quoteIn) external view returns (uint256 baseOut) { - baseOut = IWstETH(wstETH).getWstETHByStETH(quoteIn); - } - - function getBaseIn(uint256 quoteOut) external view returns (uint256 baseIn) { - baseIn = IWstETH(wstETH).getWstETHByStETH(quoteOut); - } - - function buy( - uint256, - uint256, - address recipient, - bytes calldata - ) external returns (uint256 realBaseOut) { - uint256 quoteIn = IERC20(stETH).balanceOf(address(this)); - realBaseOut = IWstETH(wstETH).wrap(quoteIn); - IERC20(wstETH).safeTransfer(recipient, realBaseOut); - } - - function sell( - uint256, - uint256, - address recipient, - bytes calldata - ) external returns (uint256 realQuoteOut) { - uint256 baseIn = IERC20(wstETH).balanceOf(address(this)); - realQuoteOut = IWstETH(wstETH).unwrap(baseIn); - IERC20(stETH).safeTransfer(recipient, realQuoteOut); - } - - function getOraclePrice() public view returns (uint256) { - return IWstETH(wstETH).stEthPerToken(); - } -}