-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyPing.sol
96 lines (80 loc) · 2.82 KB
/
MyPing.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
89
90
91
92
93
94
95
96
pragma solidity ^0.5.9;
import "@element36-io/cash36-contracts/contracts/Token36.sol"; // CHF36.sol etc implemnet this
import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";
/**
* @dev A token holder contract that will allow a beneficiary to extract the
* tokens anytime.
*
* For a more complete vesting schedule, see {TokenVesting}.
*/
contract MyPing {
using SafeERC20 for Token36;
// ERC20 basic token contract being held
Token36 private _token;
// beneficiary of tokens after they are released
address private _beneficiary;
// beneficiary of tokens after they are released
address private _pingSender;
/**
* We dont want any eth
*/
function () external payable {
revert("no eth accepted");
}
constructor(Token36 token) public {
_token = token;
}
/**
* Load the contract with tokens for a beneficiary (or to be stolen with steal-function)
*/
function ping(address beneficiary, uint256 value) public {
require ((0 < value && value <= 200*1e18)," 0<tokens<=200");
uint256 balance = _token.balanceOf(address(this));
require(balance == 0, "ping occupied - use pong or steal first");
_pingSender = msg.sender;
_token.safeTransferFrom(msg.sender,address(this),value);
_beneficiary = beneficiary;
}
/**
* Load the contract with tokens for a beneficiary (or to be stolen with steal-function)
*/
function pongWalletFree(bytes32 clue,uint256 amount) public {
require(_beneficiary == address(0), "beneficiary registered");
uint256 balance = _token.balanceOf(address(this));
require(0 < balance, "no balance");
require(balance >= amount, "too little balance");
_token.transferClue(clue, amount);
//_token.burn(amount);
}
/**
* @notice Transfers tokens to beneficiary - cash36 will check KYC
*/
function pong() public {
uint256 amount = _token.balanceOf(address(this));
require(amount > 0, "ping 0 tokens here");
require(_beneficiary != address(0), "no beneficiary registered");
_token.safeTransfer(_beneficiary, amount);
_beneficiary = address(0);
}
/**
* @notice Transfers tokens to the caller - remark: Cash36 contract will check validate KYC
*/
function steal() public {
uint256 amount = _token.balanceOf(address(this));
require(amount > 0, "no tokens to release");
_beneficiary = address(0);
_token.safeTransfer(msg.sender, amount);
}
/**
* @return the token being held.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view returns (address) {
return _beneficiary;
}
}