forked from DanielAbalde/Token-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenERC20.sol
More file actions
50 lines (45 loc) · 1.88 KB
/
TokenERC20.sol
File metadata and controls
50 lines (45 loc) · 1.88 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./../TokenAbstraction.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract TokenERC20 is TokenAbstraction
{
function standard() public pure virtual override returns(bytes32){ return "ERC20"; }
function _isStandard(address contractAddress) internal view override virtual returns(bool){
try IERC165(contractAddress).supportsInterface(type(IERC20).interfaceId) returns (bool result){
if(result){
return true;
}
}catch{}
bool success;
(success, ) = contractAddress.staticcall(abi.encodeWithSignature("totalSupply()"));
if(!success) {
return false;
}
(success, ) = contractAddress.staticcall(abi.encodeWithSignature("balanceOf(address)", msg.sender));
if(!success) {
return false;
}
return true;
}
function _isOwner(Token memory token, address account) internal view override virtual returns (bool){
try IERC20(token.Contract).balanceOf(account) returns (uint256 balance){
return balance >= token.Amount;
}catch{
return false;
}
}
function _balanceOf(Token memory token, address account) internal view override virtual returns (uint256){
return IERC20(token.Contract).balanceOf(account);
}
function _isApproved(Token memory token, address account, address operator) internal view override virtual returns (bool) {
try IERC20(token.Contract).allowance(account, operator) returns (uint256 balance){
return balance >= token.Amount;
}catch{
return false;
}
}
function _transfer(Token memory token, address from, address to) internal override virtual returns (bool){
return IERC20(token.Contract).transferFrom(from, to, token.Amount);
}
}