// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

abstract contract Context {

function _msgSender() internal view virtual returns (address) {

return msg.sender;

}

function _msgData() internal view virtual returns (bytes calldata) {

return msg.data;

}

}

abstract contract Ownable is Context {

address private _owner;

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

constructor() {

_transferOwnership(_msgSender());

}

function owner() public view virtual returns (address) {

return _owner;

}

modifier onlyOwner() {

require(owner() == _msgSender(), "Ownable: caller is not the owner");

_;

}

function renounceOwnership() public virtual onlyOwner {

_transferOwnership(address(0));

}

function transferOwnership(address newOwner) public virtual onlyOwner {

require(newOwner != address(0), "Ownable: new owner is the zero address");

_transferOwnership(newOwner);

}

function _transferOwnership(address newOwner) internal virtual {

address oldOwner = _owner;

_owner = newOwner;

emit OwnershipTransferred(oldOwner, newOwner);

}

}

interface IERC20 {

function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

function transfer(address recipient, uint256 amount) external returns (bool);

function allowance(address owner, address spender) external view returns (uint256);

function approve(address spender, uint256 amount) external returns (bool);

function transferFrom(

address sender,

address recipient,

uint256 amount

) external returns (bool);

event Transfer(address indexed from, address indexed to, uint256 value);

event Approval(address indexed owner, address indexed spender, uint256 value);

}

interface IERC20Metadata is IERC20 {

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint8);

}

library SafeMath {

function add(uint256 a, uint256 b) internal pure returns (uint256) {

uint256 c = a + b;

require(c >= a, "SafeMath: addition overflow");

return c;

}

function sub(uint256 a, uint256 b) internal pure returns (uint256) {

return sub(a, b, "SafeMath: subtraction overflow");

}

function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {

require(b <= a, errorMessage);

uint256 c = a - b;

return c;

}

function mul(uint256 a, uint256 b) internal pure returns (uint256) {

// NanFeng-TG @NFKJ991

// Token development, project official website development, Dapp development.

if (a == 0) {

return 0;

}

uint256 c = a * b;

require(c / a == b, "SafeMath: multiplication overflow");

return c;

}

function div(uint256 a, uint256 b) internal pure returns (uint256) {

return div(a, b, "SafeMath: division by zero");

}

function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {

require(b > 0, errorMessage);

uint256 c = a / b;

// assert(a == b * c + a % b); // There is no case in which this doesn't hold

return c;

}

function mod(uint256 a, uint256 b) internal pure returns (uint256) {

return mod(a, b, "SafeMath: modulo by zero");

}

function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {

require(b != 0, errorMessage);

return a % b;

}

}

library SafeMathInt {

int256 private constant MIN_INT256 = int256(1) << 255;

int256 private constant MAX_INT256 = ~(int256(1) << 255);

/**

* @dev Multiplies two int256 variables and fails on overflow.

*/

function mul(int256 a, int256 b) internal pure returns (int256) {

int256 c = a * b;

// Detect overflow when multiplying MIN_INT256 with -1

require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));

require((b == 0) || (c / b == a));

return c;

}

/**

* @dev Division of two int256 variables and fails on overflow.

*/

function div(int256 a, int256 b) internal pure returns (int256) {

// Prevent overflow when dividing MIN_INT256 by -1

require(b != -1 || a != MIN_INT256);

// Solidity already throws when dividing by 0.

return a / b;

}

/**

* @dev Subtracts two int256 variables and fails on overflow.

*/

function sub(int256 a, int256 b) internal pure returns (int256) {

int256 c = a - b;

require((b >= 0 && c <= a) || (b < 0 && c > a));

return c;

}

/**

* @dev Adds two int256 variables and fails on overflow.

*/

function add(int256 a, int256 b) internal pure returns (int256) {

int256 c = a + b;

require((b >= 0 && c >= a) || (b < 0 && c < a));

return c;

}

/**

* @dev Converts to absolute value, and fails on overflow.

*/

function abs(int256 a) internal pure returns (int256) {

require(a != MIN_INT256);

return a < 0 ? -a : a;

}

function toUint256Safe(int256 a) internal pure returns (uint256) {

require(a >= 0);

return uint256(a);

}

}

library SafeMathUint {

function toInt256Safe(uint256 a) internal pure returns (int256) {

int256 b = int256(a);

require(b >= 0);

return b;

}

}

library Clones {

/**

* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.

*

* This function uses the create opcode, which should never revert.

*/

function clone(address implementation) internal returns (address instance) {

assembly {

let ptr := mload(0x40)

mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)

mstore(add(ptr, 0x14), shl(0x60, implementation))

mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)

instance := create(0, ptr, 0x37)

}

require(instance != address(0), "ERC1167: create failed");

}

/**

* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.

*

* This function uses the create2 opcode and a `salt` to deterministically deploy

* the clone. Using the same `implementation` and `salt` multiple time will revert, since

* the clones cannot be deployed twice at the same address.

*/

function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {

assembly {

let ptr := mload(0x40)

mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)

mstore(add(ptr, 0x14), shl(0x60, implementation))

mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)

instance := create2(0, ptr, 0x37, salt)

}

require(instance != address(0), "ERC1167: create2 failed");

}

/**

* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.

*/

function predictDeterministicAddress(

address implementation,

bytes32 salt,

address deployer

) internal pure returns (address predicted) {

assembly {

let ptr := mload(0x40)

mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)

mstore(add(ptr, 0x14), shl(0x60, implementation))

mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)

mstore(add(ptr, 0x38), shl(0x60, deployer))

mstore(add(ptr, 0x4c), salt)

mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))

predicted := keccak256(add(ptr, 0x37), 0x55)

}

}

/**

* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.

*/

function predictDeterministicAddress(address implementation, bytes32 salt)

internal

view

returns (address predicted)

{

return predictDeterministicAddress(implementation, salt, address(this));

}

}

contract ERC20 is Context, IERC20, IERC20Metadata {

using SafeMath for uint256;

mapping(address => uint256) private _balances;

mapping(address => mapping(address => uint256)) private _allowances;

uint256 private _totalSupply;

string private _name;

string private _symbol;

精彩内容

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。