dsa-connectors/contracts/mainnet/connectors_old/basic.sol

82 lines
2.6 KiB
Solidity
Raw Permalink Normal View History

2021-02-07 16:40:28 +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 files from common directory
2021-02-07 16:40:28 +00:00
import { TokenInterface , MemoryInterface } from "../common/interfaces.sol";
import { Stores } from "../common/stores.sol";
import { DSMath } from "../common/math.sol";
interface AccountInterface {
function isAuth(address _user) external view returns (bool);
}
/**
* @title ConnectBasic.
* @dev Connector to deposit/withdraw assets.
*/
2021-02-05 18:51:11 +00:00
abstract contract BasicResolver is Stores {
event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId);
using SafeERC20 for IERC20;
/**
* @dev Deposit Assets To Smart Account.
* @param erc20 Token Address.
* @param tokenAmt Token Amount.
* @param getId Get Storage ID.
* @param setId Set Storage ID.
*/
function deposit(address erc20, uint tokenAmt, uint getId, uint setId) public payable {
uint amt = getUint(getId, tokenAmt);
2021-02-07 17:33:48 +00:00
if (erc20 != ethAddr) {
IERC20 token = IERC20(erc20);
amt = amt == uint(-1) ? token.balanceOf(msg.sender) : amt;
token.safeTransferFrom(msg.sender, address(this), amt);
} else {
require(msg.value == amt || amt == uint(-1), "invalid-ether-amount");
amt = msg.value;
}
setUint(setId, amt);
emit LogDeposit(erc20, amt, getId, setId);
}
/**
* @dev Withdraw Assets To Smart Account.
* @param erc20 Token Address.
* @param tokenAmt Token Amount.
* @param to Withdraw token address.
* @param getId Get Storage ID.
* @param setId Set Storage ID.
*/
function withdraw(
address erc20,
uint tokenAmt,
address payable to,
uint getId,
uint setId
) public payable {
2020-12-19 04:26:38 +00:00
// require(AccountInterface(address(this)).isAuth(to), "invalid-to-address");
uint amt = getUint(getId, tokenAmt);
2021-02-07 17:33:48 +00:00
if (erc20 == ethAddr) {
amt = amt == uint(-1) ? address(this).balance : amt;
to.transfer(amt);
} else {
IERC20 token = IERC20(erc20);
amt = amt == uint(-1) ? token.balanceOf(address(this)) : amt;
token.safeTransfer(to, amt);
}
setUint(setId, amt);
emit LogWithdraw(erc20, amt, to, getId, setId);
}
}
contract ConnectBasic is BasicResolver {
string public constant name = "Basic-v1.1";
}