From de9956899a729452f249511f3202c96a651108c0 Mon Sep 17 00:00:00 2001 From: Samarendra Gouda Date: Mon, 15 Apr 2024 11:37:36 +0530 Subject: [PATCH] feat: added weeth contracts --- contracts/mainnet/connectors/weeth/events.sol | 7 +++ .../mainnet/connectors/weeth/helpers.sol | 10 +++ .../mainnet/connectors/weeth/interfaces.sol | 8 +++ contracts/mainnet/connectors/weeth/main.sol | 62 +++++++++++++++++++ test/mainnet/weeth/weeth.test.ts | 0 5 files changed, 87 insertions(+) create mode 100644 contracts/mainnet/connectors/weeth/events.sol create mode 100644 contracts/mainnet/connectors/weeth/helpers.sol create mode 100644 contracts/mainnet/connectors/weeth/interfaces.sol create mode 100644 contracts/mainnet/connectors/weeth/main.sol create mode 100644 test/mainnet/weeth/weeth.test.ts diff --git a/contracts/mainnet/connectors/weeth/events.sol b/contracts/mainnet/connectors/weeth/events.sol new file mode 100644 index 0000000..1b0b8c1 --- /dev/null +++ b/contracts/mainnet/connectors/weeth/events.sol @@ -0,0 +1,7 @@ +//SPDX-License-Identifier: MIT +pragma solidity 0.8.19; + +contract Events { + event LogDeposit(uint256 eETHAmount, uint256 weETHAmount, uint256 getId, uint256 setId); + event LogWithdraw(uint256 weETHAmount, uint256 eETHAmount, uint256 getId, uint256 setId); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/weeth/helpers.sol b/contracts/mainnet/connectors/weeth/helpers.sol new file mode 100644 index 0000000..3bc181e --- /dev/null +++ b/contracts/mainnet/connectors/weeth/helpers.sol @@ -0,0 +1,10 @@ +//SPDX-License-Identifier: MIT +pragma solidity 0.8.19; + +import "./interfaces.sol"; +import {TokenInterface} from "../../common/interfaces.sol"; + +contract Helpers{ + IWEETH constant weETHContract = IWEETH(0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee); + TokenInterface constant eETHContract = TokenInterface(0x35fA164735182de50811E8e2E824cFb9B6118ac2); +} diff --git a/contracts/mainnet/connectors/weeth/interfaces.sol b/contracts/mainnet/connectors/weeth/interfaces.sol new file mode 100644 index 0000000..896f333 --- /dev/null +++ b/contracts/mainnet/connectors/weeth/interfaces.sol @@ -0,0 +1,8 @@ +//SPDX-License-Identifier: MIT +pragma solidity 0.8.19; + +interface IWEETH{ + function balanceOf(address account) external view returns (uint256); + function wrap(uint256 _eETHAmount) external returns (uint256); + function unwrap(uint256 _weETHAmount) external returns (uint256); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/weeth/main.sol b/contracts/mainnet/connectors/weeth/main.sol new file mode 100644 index 0000000..c703d6e --- /dev/null +++ b/contracts/mainnet/connectors/weeth/main.sol @@ -0,0 +1,62 @@ +//SPDX-License-Identifier: MIT +pragma solidity 0.8.19; + +import "./helpers.sol"; +import {Basic} from "../../common/basic.sol"; + +contract WEETHContract is Helpers, Basic { + + /** + * @dev Deposit eETH into weETH. + * @notice Wrap eETH into weETH + * @param eETHAmount The amount of eETH to deposit. (For max: `uint256(-1)`) + * @param getId ID to retrieve eETH amount. + * @param setId ID stores the amount of weETH deposited. + */ + function deposit( + uint256 eETHAmount, + uint256 getId, + uint256 setId + ) external returns (string memory _eventName, bytes memory _eventParam) { + uint256 _eETHAmount = getUint(getId, eETHAmount); + _eETHAmount = _eETHAmount == type(uint256).max + ? eETHContract.balanceOf(address(this)) + : _eETHAmount; + + approve(eETHContract, address(weETHContract), _eETHAmount); + uint256 _weETHAmount = weETHContract.wrap(_eETHAmount); + + setUint(setId, _weETHAmount); + + _eventName = "LogDeposit(uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode(_eETHAmount, _weETHAmount, getId, setId); + } + + /** + * @dev Withdraw eETH from weETH from Smart Account + * @notice Unwrap eETH from weETH + * @param weETHAmount The amount of weETH to withdraw. (For max: `uint256(-1)`) + * @param getId ID to retrieve weETH amount. + * @param setId ID stores the amount of eETH. + */ + function withdraw( + uint256 weETHAmount, + uint256 getId, + uint256 setId + ) external returns (string memory _eventName, bytes memory _eventParam) { + uint256 _weETHAmount = getUint(getId, weETHAmount); + _weETHAmount = _weETHAmount == type(uint256).max + ? weETHContract.balanceOf(address(this)) + : _weETHAmount; + + uint256 _eETHAmount = weETHContract.unwrap(_weETHAmount); + setUint(setId, _eETHAmount); + + _eventName = "LogWithdraw(uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode(_weETHAmount, _eETHAmount, getId, setId); + } +} + +contract ConnectV2WEETH is WEETHContract { + string public constant name = "WEETH-v1.0"; +} diff --git a/test/mainnet/weeth/weeth.test.ts b/test/mainnet/weeth/weeth.test.ts new file mode 100644 index 0000000..e69de29