This repository has been archived by the owner on Sep 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_wallet.sol
88 lines (74 loc) · 2.34 KB
/
simple_wallet.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pragma solidity >=0.5.0 <0.6.0;
import "./ownable.sol";
import "./IERC20.sol";
contract SimpleWallet is Ownable {
uint256 public fee = 0;
address public feeOwner = 0x...;
event ReceiveETH(address _from, uint256 _amount);
event TransferETH(address _from, address _to, uint256 _amount);
event TransferERC20(address _from, address _to, uint256 _amount);
event AllowanceERC20Changed(address owner, uint256 _amount);
event FeeETHChanged(address owner, uint256 _amount);
// Modifier for feeOwner to be able to set up the fee
modifier onlyFeeOwner() {
require(msg.sender == feeOwner);
_;
}
function balance() public view returns (uint256) {
return address(this).balance();
}
// Operations with ETH
// Receive
function() external payable {
emit ReceiveETH(msg.sender, msg.value);
}
// Transfer to
function transferETH(uint256 _amount, address payable _to)
public
onlyOwner
{
require(_amount + fee <= balance());
(bool success, ) = _to.transfer(_amount);
require(success);
feeOwner.transfer(fee);
emit TransferETH(msg.sender, _to, _amount);
}
// Additional Fee
// Getting Fee
function feeETHGet() external view returns (uint256) {
return fee;
}
// Setting the fee for the ETH transaction
function feeETHSet(uint256 _amount) external onlyFeeOwner {
fee = _amount;
emit FeeETHChanged(msg.sender, _amount);
}
// Operations with ERC20 tokens
// Transfer to
function transferERC20(
IERC20 _token,
uint256 _amount,
address payable _to
) public onllyOwner {
uint256 erc20Balance = _token.balanceOf(address(this));
require(_amount <= erc20Balance);
require(token.transferFrom(msg.sender, _to, _amount));
emit TransferERC20(msg.sender, _to, _amount);
}
// Receiving the allowence amount of the wallet owner
function allowanceERC20Get(IERC20 _token)
external
view
onlyOwner
returns (uint256)
{
return _token.allowance(msg.sender, msg.sender);
}
// Setting the allowance amount
function allowanceERC20Set(IERC20 _token, uint256 _amount)
external
onlyOwner
{
require(_token.approve(msg.sender, _amount));
}
}