mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #261 from Instadapp/WSTETH-Connector
Wsteth connector
This commit is contained in:
commit
e7d48417bf
7
contracts/mainnet/connectors/wsteth/events.sol
Normal file
7
contracts/mainnet/connectors/wsteth/events.sol
Normal file
|
@ -0,0 +1,7 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(uint256 stethAmt, uint256 wstethAmt, uint256 getId, uint256 setId);
|
||||
event LogWithdraw(uint256 wstethAmt, uint256 stethAmt, uint256 getId, uint256 setId);
|
||||
}
|
9
contracts/mainnet/connectors/wsteth/helpers.sol
Normal file
9
contracts/mainnet/connectors/wsteth/helpers.sol
Normal file
|
@ -0,0 +1,9 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
import './interface.sol';
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
||||
abstract contract Helpers {
|
||||
IWSTETH internal constant wstethContract = IWSTETH(0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0);
|
||||
TokenInterface internal constant stethContract = TokenInterface(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
|
||||
}
|
8
contracts/mainnet/connectors/wsteth/interface.sol
Normal file
8
contracts/mainnet/connectors/wsteth/interface.sol
Normal file
|
@ -0,0 +1,8 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IWSTETH {
|
||||
function balanceOf(address account) external view returns (uint256);
|
||||
function wrap(uint256 _stETHAmount) external returns (uint256);
|
||||
function unwrap(uint256 _wstETHAmount) external returns (uint256);
|
||||
}
|
64
contracts/mainnet/connectors/wsteth/main.sol
Normal file
64
contracts/mainnet/connectors/wsteth/main.sol
Normal file
|
@ -0,0 +1,64 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import './helpers.sol';
|
||||
|
||||
/**
|
||||
* @title WSTETH.
|
||||
* @dev Wrap and Unwrap STETH.
|
||||
*/
|
||||
|
||||
abstract contract WSTETHContract is Helpers, Basic {
|
||||
|
||||
/**
|
||||
* @dev Deposit STETH into WSTETH.
|
||||
* @notice Wrap STETH into WSTETH
|
||||
* @param stethAmt The amount of STETH to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve STETH amount.
|
||||
* @param setId ID stores the amount of WSTETH deposited.
|
||||
*/
|
||||
function deposit(
|
||||
uint256 stethAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
|
||||
uint256 _amt = getUint(getId, stethAmt);
|
||||
_amt = _amt == uint(-1) ? _amt = stethContract.balanceOf(address(this)) : _amt;
|
||||
|
||||
approve(stethContract, address(wstethContract), _amt);
|
||||
|
||||
uint256 _wstethAmt = wstethContract.wrap(_amt);
|
||||
setUint(setId, _wstethAmt);
|
||||
|
||||
_eventName = "LogDeposit(uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amt, _wstethAmt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw STETH from WSTETH from Smart Account
|
||||
* @notice Unwrap STETH from WSTETH
|
||||
* @param wstethAmt The amount of WSTETH to withdraw. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve WSTETH amount.
|
||||
* @param setId ID stores the amount of STETH.
|
||||
*/
|
||||
function withdraw(
|
||||
uint256 wstethAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
|
||||
uint256 _amt = getUint(getId, wstethAmt);
|
||||
_amt = _amt == uint(-1) ? wstethContract.balanceOf(address(this)) : _amt;
|
||||
|
||||
uint256 _stethAmt = wstethContract.unwrap(_amt);
|
||||
setUint(setId, _stethAmt);
|
||||
|
||||
_eventName = "LogWithdraw(uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_amt, _stethAmt, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2WSTETH is WSTETHContract {
|
||||
string constant public name = "WSTETH-v1.0";
|
||||
}
|
Loading…
Reference in New Issue
Block a user