-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOSTokenSwap.sol
54 lines (43 loc) · 1.64 KB
/
OSTokenSwap.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
pragma solidity ^0.8.9;
// SPDX-License-Identifier: MIT
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract OSTokenSwap is Ownable, ReentrancyGuard {
uint256 private balance;
bool paused = false;
mapping (address => uint) private balances;
event TransferReceived(address _from, uint _amount);
event TransferSent(address _from, address _destAddr, uint _amount);
constructor() ReentrancyGuard()public{
}
receive() payable external {
balance += msg.value;
emit TransferReceived(msg.sender, msg.value);
}
modifier isPaused {
require(paused);
_;
}
modifier notPaused {
require(! paused);
_;
}
function pauseContract() public onlyOwner notPaused {
paused = true;
}
function unpauseContract() public onlyOwner isPaused {
paused = false;
}
using SafeERC20 for IERC20;
function WithdrawToken(IERC20 token, address to, uint256 amount) nonReentrant() notPaused() public {
require(tx.origin == msg.sender);
uint256 erc20balance = token.balanceOf(address(this));
require(msg.sender.balance>=10000000000000000 ,"Not enough check balance");
balances[msg.sender]=0;
require(amount <= erc20balance, "balance is low");
//Payer
token.safeTransfer(to, amount);
emit TransferSent(msg.sender, to, amount);
}
}