2021-02-08 15:18:32 +00:00
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
|
|
|
|
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
|
|
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
|
|
|
|
|
|
import { DSMath } from "../../common/math.sol";
|
|
|
|
import { Basic } from "../../common/basic.sol";
|
|
|
|
import { Events } from "./events.sol";
|
|
|
|
|
|
|
|
abstract contract BasicResolver is Events, DSMath, Basic {
|
|
|
|
using SafeERC20 for IERC20;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Deposit Assets To Smart Account.
|
2021-03-20 20:28:28 +00:00
|
|
|
* @param token Token Address.
|
|
|
|
* @param amt Token Amount.
|
2021-02-08 15:18:32 +00:00
|
|
|
* @param getId Get Storage ID.
|
|
|
|
* @param setId Set Storage ID.
|
|
|
|
*/
|
|
|
|
function deposit(
|
2021-03-20 20:28:28 +00:00
|
|
|
address token,
|
|
|
|
uint256 amt,
|
|
|
|
uint256 getId,
|
|
|
|
uint256 setId
|
2021-02-08 15:18:32 +00:00
|
|
|
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
2021-03-20 20:28:28 +00:00
|
|
|
uint _amt = getUint(getId, amt);
|
|
|
|
if (token != ethAddr) {
|
|
|
|
IERC20 tokenContract = IERC20(token);
|
|
|
|
_amt = _amt == uint(-1) ? tokenContract.balanceOf(msg.sender) : _amt;
|
|
|
|
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
2021-02-08 15:18:32 +00:00
|
|
|
} else {
|
2021-03-20 20:28:28 +00:00
|
|
|
require(msg.value == _amt || _amt == uint(-1), "invalid-ether-amount");
|
|
|
|
_amt = msg.value;
|
2021-02-08 15:18:32 +00:00
|
|
|
}
|
2021-03-20 20:28:28 +00:00
|
|
|
setUint(setId, _amt);
|
2021-02-08 15:18:32 +00:00
|
|
|
|
|
|
|
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
|
2021-03-20 20:28:28 +00:00
|
|
|
_eventParam = abi.encode(token, _amt, getId, setId);
|
2021-02-08 15:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev Withdraw Assets To Smart Account.
|
2021-03-20 20:28:28 +00:00
|
|
|
* @param token Token Address.
|
|
|
|
* @param amt Token Amount.
|
2021-02-08 15:18:32 +00:00
|
|
|
* @param to Withdraw token address.
|
|
|
|
* @param getId Get Storage ID.
|
|
|
|
* @param setId Set Storage ID.
|
|
|
|
*/
|
|
|
|
function withdraw(
|
2021-03-20 20:28:28 +00:00
|
|
|
address token,
|
|
|
|
uint amt,
|
2021-02-08 15:18:32 +00:00
|
|
|
address payable to,
|
|
|
|
uint getId,
|
|
|
|
uint setId
|
|
|
|
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
2021-03-20 20:28:28 +00:00
|
|
|
uint _amt = getUint(getId, amt);
|
|
|
|
if (token == ethAddr) {
|
|
|
|
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
|
|
|
to.call{value: _amt}("");
|
2021-02-08 15:18:32 +00:00
|
|
|
} else {
|
2021-03-20 20:28:28 +00:00
|
|
|
IERC20 tokenContract = IERC20(token);
|
|
|
|
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
|
|
|
tokenContract.safeTransfer(to, _amt);
|
2021-02-08 15:18:32 +00:00
|
|
|
}
|
2021-03-20 20:28:28 +00:00
|
|
|
setUint(setId, _amt);
|
2021-02-08 15:18:32 +00:00
|
|
|
|
|
|
|
_eventName = "LogWithdraw(address,uint256,address,uint256,uint256)";
|
2021-03-20 20:28:28 +00:00
|
|
|
_eventParam = abi.encode(token, _amt, to, getId, setId);
|
2021-02-08 15:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 12:26:22 +00:00
|
|
|
contract ConnectV2Basic is BasicResolver {
|
2021-03-20 20:28:28 +00:00
|
|
|
string constant public name = "Basic-v1";
|
2021-02-08 15:18:32 +00:00
|
|
|
}
|