// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^0.8.0;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 2 of 7: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 6 of 7: OwnableTokenAccessControl.sol
// SPDX-License-Identifier: MITpragmasolidity =0.8.11;import"@openzeppelin/contracts/access/Ownable.sol";
/// @title OwnableTokenAccessControl/// @notice Basic access control for utility tokens /// @author ponkycontractOwnableTokenAccessControlisOwnable{
/// @dev Keeps track of how many accounts have been granted each type of accessuint96private _accessCounts;
mapping (address=>uint256) private _accessFlags;
/// @dev Access typesenumAccess { Mint, Burn, Transfer, Claim }
/// @dev Emitted when `account` is granted `access`.eventAccessGranted(bytes32indexed access, addressindexed account);
/// @dev Emitted when `account` is revoked `access`.eventAccessRevoked(bytes32indexed access, addressindexed account);
/// @dev Helper constants for fitting each access index into _accessCountsuintconstantprivate _AC_BASE =4;
uintconstantprivate _AC_MASK_BITSIZE =1<< _AC_BASE;
uintconstantprivate _AC_DISABLED = (1<< (_AC_MASK_BITSIZE -1));
uintconstantprivate _AC_MASK_COUNT = _AC_DISABLED -1;
/// @dev Convert the string `access` to an uintfunction_accessToIndex(bytes32 access) internalpurevirtualreturns (uint index) {
if (access =='MINT') {returnuint(Access.Mint);}
if (access =='BURN') {returnuint(Access.Burn);}
if (access =='TRANSFER') {returnuint(Access.Transfer);}
if (access =='CLAIM') {returnuint(Access.Claim);}
revert("Access type does not exist");
}
function_hasAccess(Access access, address account) internalviewreturns (bool) {
return (_accessFlags[account] & (1<<uint(access))) !=0;
}
functionhasAccess(bytes32 access, address account) publicviewreturns (bool) {
uint256 flag =1<< _accessToIndex(access);
return (_accessFlags[account] & flag) !=0;
}
functiongrantAccess(bytes32 access, address account) externalonlyOwner{
require(account.code.length>0, "Can only grant access to a contract");
uint index = _accessToIndex(access);
uint256 flags = _accessFlags[account];
uint256 newFlags = flags | (1<< index);
require(flags != newFlags, "Account already has access");
_accessFlags[account] = newFlags;
uint shift = index << _AC_BASE;
uint256 accessCount = _accessCounts >> shift;
require((accessCount & _AC_DISABLED) ==0, "Granting this access is permanently disabled");
require((accessCount & _AC_MASK_COUNT) < _AC_MASK_COUNT, "Access limit reached");
unchecked {
_accessCounts +=uint96(1<< shift);
}
emit AccessGranted(access, account);
}
functionrevokeAccess(bytes32 access, address account) externalonlyOwner{
uint index = _accessToIndex(access);
uint256 flags = _accessFlags[account];
uint256 newFlags = flags &~(1<< index);
require(flags != newFlags, "Account does not have access");
_accessFlags[account] = newFlags;
uint shift = index << _AC_BASE;
unchecked {
_accessCounts -=uint96(1<< shift);
}
emit AccessRevoked(access, account);
}
/// @dev Returns the number of contracts that have `access`.functioncountOfAccess(bytes32 access) externalviewreturns (uint256 accessCount) {
uint index = _accessToIndex(access);
uint shift = index << _AC_BASE;
accessCount = (_accessCounts >> shift) & _AC_MASK_COUNT;
}
/// @dev `access` can still be revoked but not grantedfunctionpermanentlyDisableGrantingAccess(bytes32 access) externalonlyOwner{
uint index = _accessToIndex(access);
uint shift = index << _AC_BASE;
uint256 flag = _AC_DISABLED << shift;
uint256 accessCounts = _accessCounts;
require((accessCounts & flag) ==0, "Granting this access is already disabled");
_accessCounts =uint96(accessCounts | flag);
}
}