-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestToken.sol
71 lines (58 loc) · 1.86 KB
/
TestToken.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract TestToken is Ownable, ERC20 {
address[] public poolLists;
mapping(address => bool) private _isPoolEnabled;
constructor(uint256 _totalSupply) ERC20("TestToken", "TT") {
_mint(msg.sender, _totalSupply);
}
function isPool(address _contractAddress) external view returns (bool) {
return _isPoolEnabled[_contractAddress];
}
function setPoolStatus(address _contractAddress, bool _status)
external
onlyOwner
{
_isPoolEnabled[_contractAddress] = _status;
}
function addPool(address _contractAddress) external onlyOwner {
_isPoolEnabled[_contractAddress] = true;
poolLists.push(_contractAddress);
}
function _isContract(address _address) private view returns (bool) {
uint32 size;
assembly {
size := extcodesize(_address)
}
return (size > 0);
}
function isContract(address _address) external view returns (bool) {
return _isContract(_address);
}
function _beforeTokenTransfer(
address sender,
address recipient,
uint256 amount
) internal override {
bool isBuy = _isPoolEnabled[sender];
bool isSell = _isPoolEnabled[recipient];
if (isBuy) {
require(
!_isContract(recipient),
"Receipient should not be contract address"
);
}
if (isSell) {
require(
!_isContract(sender),
"Sender should not be contract address"
);
}
super._beforeTokenTransfer(sender, recipient, amount);
}
function burn(uint256 value) external {
_burn(msg.sender, value);
}
}