dsa-connectors/contracts/mainnet/connectors/weth/main.sol

66 lines
1.9 KiB
Solidity
Raw Normal View History

2021-06-18 08:43:03 +00:00
pragma solidity ^0.7.0;
/**
2021-06-24 18:54:05 +00:00
* @title WETH.
* @dev Wrap and Unwrap WETH.
2021-06-18 08:43:03 +00:00
*/
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { Events } from "./events.sol";
2021-06-18 08:55:16 +00:00
import { Helpers } from "./helpers.sol";
2021-06-18 08:43:03 +00:00
2021-06-18 08:55:16 +00:00
abstract contract Resolver is Events, DSMath, Basic, Helpers {
2021-06-18 08:43:03 +00:00
/**
* @dev Deposit ETH into WETH.
* @notice Wrap ETH into WETH
* @param amt The amount of ETH to deposit. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of ETH deposited.
*/
function deposit(
uint256 amt,
uint256 getId,
uint256 setId
) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, amt);
2021-06-18 08:48:20 +00:00
_amt = _amt == uint(-1) ? address(this).balance : _amt;
2021-06-18 08:55:16 +00:00
wethContract.deposit{value: _amt}();
2021-06-18 08:43:03 +00:00
setUint(setId, _amt);
_eventName = "LogDeposit(uint256,uint256,uint256)";
_eventParam = abi.encode(_amt, getId, setId);
}
/**
* @dev Withdraw ETH from WETH from Smart Account
* @notice Unwrap ETH from WETH
* @param amt The amount of weth to withdraw. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of ETH withdrawn.
*/
function withdraw(
uint amt,
uint getId,
uint setId
) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, amt);
2021-06-18 08:55:16 +00:00
_amt = _amt == uint(-1) ? wethContract.balanceOf(address(this)) : _amt;
approve(wethContract, wethAddr, _amt);
2021-06-18 08:55:16 +00:00
wethContract.withdraw(_amt);
2021-06-18 08:43:03 +00:00
setUint(setId, _amt);
_eventName = "LogWithdraw(uint256,uint256,uint256)";
_eventParam = abi.encode(_amt, getId, setId);
}
}
contract ConnectV2WETH is Resolver {
2021-06-18 08:48:20 +00:00
string constant public name = "WETH-v1.0";
2021-06-18 08:43:03 +00:00
}