Transaction Hash:
Block:
21679660 at Jan-22-2025 11:14:11 AM +UTC
Transaction Fee:
0.00021853927695834 ETH
$0.41
Gas Used:
28,860 Gas / 7.572393519 Gwei
Emitted Events:
271 |
LizcoinERC20.Approval( owner=[Sender] 0xf9955feb1763c6fd31746868ba08df33e497bc1d, spender=0x7a250d56...659F2488D, oldValue=115792089237316195423570985008687907853269984665640564039457584007913129639935, value=115792089237316195423570985008687907853269984665640564039457584007913129639935 )
|
272 |
LizcoinERC20.Approval( owner=[Sender] 0xf9955feb1763c6fd31746868ba08df33e497bc1d, spender=0x7a250d56...659F2488D, value=115792089237316195423570985008687907853269984665640564039457584007913129639935 )
|
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x95222290...5CC4BAfe5
Miner
| (beaverbuild) | 12.924628150835871949 Eth | 12.924653703277938529 Eth | 0.00002555244206658 | |
0xF9955fEB...3e497Bc1D |
0.16190970485226105 Eth
Nonce: 11
|
0.16169116557530271 Eth
Nonce: 12
| 0.00021853927695834 |
Execution Trace
LizcoinERC20.approve( spender=0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, value=115792089237316195423570985008687907853269984665640564039457584007913129639935 ) => ( success=True )
// SPDX-License-Identifier: MIT pragma solidity >=0.8.4; // custom errors (0.8.4) import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; /** * @title Initializable Role-based Access Control Core (I-RBAC-C) * * @notice Access control smart contract provides an API to check * if a specific operation is permitted globally and/or * if a particular user has a permission to execute it. * * @notice This contract is inherited by other contracts requiring the role-based access control (RBAC) * protection for the restricted access functions * * @notice It deals with two main entities: features and roles. * * @notice Features are designed to be used to enable/disable public functions * of the smart contract (used by a wide audience). * @notice User roles are designed to control the access to restricted functions * of the smart contract (used by a limited set of maintainers). * * @notice Terms "role", "permissions" and "set of permissions" have equal meaning * in the documentation text and may be used interchangeably. * @notice Terms "permission", "single permission" implies only one permission bit set. * * @notice Access manager is a special role which allows to grant/revoke other roles. * Access managers can only grant/revoke permissions which they have themselves. * As an example, access manager with no other roles set can only grant/revoke its own * access manager permission and nothing else. * * @notice Access manager permission should be treated carefully, as a super admin permission: * Access manager with even no other permission can interfere with another account by * granting own access manager permission to it and effectively creating more powerful * permission set than its own. * * @dev Both current and OpenZeppelin AccessControl implementations feature a similar API * to check/know "who is allowed to do this thing". * @dev Zeppelin implementation is more flexible: * - it allows setting unlimited number of roles, while current is limited to 256 different roles * - it allows setting an admin for each role, while current allows having only one global admin * @dev Current implementation is more lightweight: * - it uses only 1 bit per role, while Zeppelin uses 256 bits * - it allows setting up to 256 roles at once, in a single transaction, while Zeppelin allows * setting only one role in a single transaction * * @dev This smart contract is designed to be inherited by other * smart contracts which require access control management capabilities. * * @dev Access manager permission has a bit 255 set. * This bit must not be used by inheriting contracts for any other permissions/features. * * @dev This is an initializable version of the RBAC, based on Zeppelin implementation, * it can be used for EIP-1167 minimal proxies, for ERC1967 proxies, etc. * see https://docs.openzeppelin.com/contracts/4.x/api/proxy#Clones * see https://docs.openzeppelin.com/contracts/4.x/upgradeable * see https://docs.openzeppelin.com/contracts/4.x/api/proxy#UUPSUpgradeable * see https://forum.openzeppelin.com/t/uups-proxies-tutorial-solidity-javascript/7786 * see https://eips.ethereum.org/EIPS/eip-1167 * * @dev The 'core' version of the RBAC contract hides three rarely used external functions from the public ABI, * making them internal and thus reducing the overall compiled implementation size. * isFeatureEnabled() public -> _isFeatureEnabled() internal * isSenderInRole() public -> _isSenderInRole() internal * isOperatorInRole() public -> _isOperatorInRole() internal * * @custom:since 1.1.0 * * @author Basil Gorin */ abstract contract InitializableAccessControlCore is Initializable { \t/** \t * @dev Privileged addresses with defined roles/permissions \t * @dev In the context of ERC20/ERC721 tokens these can be permissions to \t * allow minting or burning tokens, transferring on behalf and so on \t * \t * @dev Maps user address to the permissions bitmask (role), where each bit \t * represents a permission \t * @dev Bitmask 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF \t * represents all possible permissions \t * @dev 'This' address mapping represents global features of the smart contract \t * \t * @dev We keep the mapping private to prevent direct writes to it from the inheriting \t * contracts, `getRole()` and `updateRole()` functions should be used instead \t */ \tmapping(address => uint256) private userRoles; \t/** \t * @dev Empty reserved space in storage. The size of the __gap array is calculated so that \t * the amount of storage used by a contract always adds up to the 50. \t * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps \t */ \tuint256[49] private __gap; \t/** \t * @notice Access manager is responsible for assigning the roles to users, \t * enabling/disabling global features of the smart contract \t * @notice Access manager can add, remove and update user roles, \t * remove and update global features \t * \t * @dev Role ROLE_ACCESS_MANAGER allows modifying user roles and global features \t * @dev Role ROLE_ACCESS_MANAGER has single bit at position 255 enabled \t */ \tuint256 public constant ROLE_ACCESS_MANAGER = 0x8000000000000000000000000000000000000000000000000000000000000000; \t/** \t * @notice Upgrade manager is responsible for smart contract upgrades, \t * see https://docs.openzeppelin.com/contracts/4.x/api/proxy#UUPSUpgradeable \t * see https://docs.openzeppelin.com/contracts/4.x/upgradeable \t * \t * @dev Role ROLE_UPGRADE_MANAGER allows passing the _authorizeUpgrade() check \t * @dev Role ROLE_UPGRADE_MANAGER has single bit at position 254 enabled \t */ \tuint256 public constant ROLE_UPGRADE_MANAGER = 0x4000000000000000000000000000000000000000000000000000000000000000; \t/** \t * @dev Bitmask representing all the possible permissions (super admin role) \t * @dev Has all the bits are enabled (2^256 - 1 value) \t */ \tuint256 internal constant FULL_PRIVILEGES_MASK = type(uint256).max; // before 0.8.0: uint256(-1) overflows to 0xFFFF... \t/** \t * @notice Thrown when a function is executed by an account that does not have \t * the required access permission(s) (role) \t * \t * @dev This error is used to enforce role-based access control (RBAC) restrictions \t */ \terror AccessDenied(); \t/** \t * @dev Fired in updateRole() and updateFeatures() \t * \t * @param operator address which was granted/revoked permissions \t * @param requested permissions requested \t * @param assigned permissions effectively set \t */ \tevent RoleUpdated(address indexed operator, uint256 requested, uint256 assigned); \t/** \t * @notice Function modifier making a function defined as public behave as restricted \t * (so that only a pre-configured set of accounts can execute it) \t * \t * @param role the role transaction executor is required to have; \t * the function throws an "access denied" exception if this condition is not met \t */ \tmodifier restrictedTo(uint256 role) { \t\t// verify the access permission \t\t_requireSenderInRole(role); \t\t// execute the rest of the function \t\t_; \t} \t/** \t * @dev Creates/deploys the RBAC implementation to be used in a proxy \t * \t * @dev Note: \t * the implementation is already initialized and \t * `_postConstruct` is not executable on the implementation \t * `_postConstruct` is still available in the context of a proxy \t * and should be executed on the proxy deployment (in the same tx) \t */ \tconstructor() initializer {} \t/** \t * @dev Contract initializer, sets the contract owner to have full privileges \t * \t * @dev Can be executed only once, reverts when executed second time \t * \t * @dev IMPORTANT: \t * this function SHOULD be executed during proxy deployment (in the same transaction) \t * \t * @param _owner smart contract owner having full privileges, can be zero \t * @param _features initial features mask of the contract, can be zero \t */ \tfunction _postConstruct(address _owner, uint256 _features) internal virtual onlyInitializing { \t\t// grant owner full privileges \t\t__setRole(_owner, FULL_PRIVILEGES_MASK, FULL_PRIVILEGES_MASK); \t\t// update initial features bitmask \t\t__setRole(address(this), _features, _features); \t} \t/** \t * @dev Highest version that has been initialized. \t * Non-zero value means contract was already initialized. \t * @dev see {Initializable}, {reinitializer}. \t * \t * @return highest version that has been initialized \t */ \tfunction getInitializedVersion() public view returns(uint64) { \t\t// delegate to `_getInitializedVersion` \t\treturn _getInitializedVersion(); \t} \t/** \t * @notice Retrieves globally set of features enabled \t * \t * @dev Effectively reads userRoles role for the contract itself \t * \t * @return 256-bit bitmask of the features enabled \t */ \tfunction features() public view returns (uint256) { \t\t// features are stored in 'this' address mapping of `userRoles` \t\treturn getRole(address(this)); \t} \t/** \t * @notice Updates set of the globally enabled features (`features`), \t * taking into account sender's permissions \t * \t * @dev Requires transaction sender to have `ROLE_ACCESS_MANAGER` permission \t * @dev Function is left for backward compatibility with older versions \t * \t * @param _mask bitmask representing a set of features to enable/disable \t */ \tfunction updateFeatures(uint256 _mask) public { \t\t// delegate call to `updateRole` \t\tupdateRole(address(this), _mask); \t} \t/** \t * @notice Reads the permissions (role) for a given user from the `userRoles` mapping \t * (privileged addresses with defined roles/permissions) \t * @notice In the context of ERC20/ERC721 tokens these can be permissions to \t * allow minting or burning tokens, transferring on behalf and so on \t * \t * @dev Having a simple getter instead of making the mapping public \t * allows enforcing the encapsulation of the mapping and protects from \t * writing to it directly in the inheriting smart contracts \t * \t * @param operator address of a user to read permissions for, \t * or self address to read global features of the smart contract \t */ \tfunction getRole(address operator) public view returns(uint256) { \t\t// read the value from `userRoles` and return \t\treturn userRoles[operator]; \t} \t/** \t * @notice Updates set of permissions (role) for a given user, \t * taking into account sender's permissions. \t * \t * @dev Setting role to zero is equivalent to removing an all permissions \t * @dev Setting role to `FULL_PRIVILEGES_MASK` is equivalent to \t * copying senders' permissions (role) to the user \t * @dev Requires transaction sender to have `ROLE_ACCESS_MANAGER` permission \t * \t * @param operator address of a user to alter permissions for, \t * or self address to alter global features of the smart contract \t * @param role bitmask representing a set of permissions to \t * enable/disable for a user specified \t */ \tfunction updateRole(address operator, uint256 role) public { \t\t// caller must have a permission to update user roles \t\t_requireSenderInRole(ROLE_ACCESS_MANAGER); \t\t// evaluate the role and reassign it \t\t__setRole(operator, role, _evaluateBy(msg.sender, getRole(operator), role)); \t} \t/** \t * @notice Determines the permission bitmask an operator can set on the \t * target permission set \t * @notice Used to calculate the permission bitmask to be set when requested \t * in `updateRole` and `updateFeatures` functions \t * \t * @dev Calculated based on: \t * 1) operator's own permission set read from userRoles[operator] \t * 2) target permission set - what is already set on the target \t * 3) desired permission set - what do we want set target to \t * \t * @dev Corner cases: \t * 1) Operator is super admin and its permission set is `FULL_PRIVILEGES_MASK`: \t * `desired` bitset is returned regardless of the `target` permission set value \t * (what operator sets is what they get) \t * 2) Operator with no permissions (zero bitset): \t * `target` bitset is returned regardless of the `desired` value \t * (operator has no authority and cannot modify anything) \t * \t * @dev Example: \t * Consider an operator with the permissions bitmask 00001111 \t * is about to modify the target permission set 01010101 \t * Operator wants to set that permission set to 00110011 \t * Based on their role, an operator has the permissions \t * to update only lowest 4 bits on the target, meaning that \t * high 4 bits of the target set in this example is left \t * unchanged and low 4 bits get changed as desired: 01010011 \t * \t * @param operator address of the contract operator which is about to set the permissions \t * @param target input set of permissions to operator is going to modify \t * @param desired desired set of permissions operator would like to set \t * @return resulting set of permissions given operator will set \t */ \tfunction _evaluateBy(address operator, uint256 target, uint256 desired) internal view returns (uint256) { \t\t// read operator's permissions \t\tuint256 p = getRole(operator); \t\t// taking into account operator's permissions, \t\t// 1) enable the permissions desired on the `target` \t\ttarget |= p & desired; \t\t// 2) disable the permissions desired on the `target` \t\ttarget &= FULL_PRIVILEGES_MASK ^ (p & (FULL_PRIVILEGES_MASK ^ desired)); \t\t// return calculated result \t\treturn target; \t} \t/** \t * @notice Ensures that the transaction sender has the required access permission(s) (role) \t * \t * @dev Reverts with an `AccessDenied` error if the sender does not have the required role \t * \t * @param required the set of permissions (role) that the transaction sender is required to have \t */ \tfunction _requireSenderInRole(uint256 required) internal view { \t\t// check if the transaction has the required permission(s), \t\t// reverting with the "access denied" error if not \t\t_requireAccessCondition(_isSenderInRole(required)); \t} \t/** \t * @notice Ensures that a specific condition is met \t * \t * @dev Reverts with an `AccessDenied` error if the condition is not met \t * \t * @param condition the condition that needs to be true for the function to proceed \t */ \tfunction _requireAccessCondition(bool condition) internal pure { \t\t// check if the condition holds \t\tif(!condition) { \t\t\t// revert with the "access denied" error if not \t\t\trevert AccessDenied(); \t\t} \t} \t/** \t * @notice Checks if requested set of features is enabled globally on the contract \t * \t * @param required set of features to check against \t * @return true if all the features requested are enabled, false otherwise \t */ \tfunction _isFeatureEnabled(uint256 required) internal view returns (bool) { \t\t// delegate call to `__hasRole`, passing `features` property \t\treturn __hasRole(features(), required); \t} \t/** \t * @notice Checks if transaction sender `msg.sender` has all the permissions required \t * \t * @param required set of permissions (role) to check against \t * @return true if all the permissions requested are enabled, false otherwise \t */ \tfunction _isSenderInRole(uint256 required) internal view returns (bool) { \t\t// delegate call to `isOperatorInRole`, passing transaction sender \t\treturn _isOperatorInRole(msg.sender, required); \t} \t/** \t * @notice Checks if operator has all the permissions (role) required \t * \t * @param operator address of the user to check role for \t * @param required set of permissions (role) to check \t * @return true if all the permissions requested are enabled, false otherwise \t */ \tfunction _isOperatorInRole(address operator, uint256 required) internal view returns (bool) { \t\t// delegate call to `__hasRole`, passing operator's permissions (role) \t\treturn __hasRole(getRole(operator), required); \t} \t/** \t * @dev Sets the `assignedRole` role to the operator, logs both `requestedRole` and `actualRole` \t * \t * @dev Unsafe: \t * provides direct write access to `userRoles` mapping without any security checks, \t * doesn't verify the executor (msg.sender) permissions, \t * must be kept private at all times \t * \t * @param operator address of a user to alter permissions for, \t * or self address to alter global features of the smart contract \t * @param requestedRole bitmask representing a set of permissions requested \t * to be enabled/disabled for a user specified, used only to be logged into event \t * @param assignedRole bitmask representing a set of permissions to \t * enable/disable for a user specified, used to update the mapping and to be logged into event \t */ \tfunction __setRole(address operator, uint256 requestedRole, uint256 assignedRole) private { \t\t// assign the role to the operator \t\tuserRoles[operator] = assignedRole; \t\t// fire an event \t\temit RoleUpdated(operator, requestedRole, assignedRole); \t} \t/** \t * @dev Checks if role `actual` contains all the permissions required `required` \t * \t * @param actual existent role \t * @param required required role \t * @return true if actual has required role (all permissions), false otherwise \t */ \tfunction __hasRole(uint256 actual, uint256 required) private pure returns (bool) { \t\t// check the bitmask for the role required and return the result \t\treturn actual & required == required; \t} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /** * @title EIP-2612: permit - 712-signed approvals * * @notice A function permit extending ERC-20 which allows for approvals to be made via secp256k1 signatures. * This kind of “account abstraction for ERC-20” brings about two main benefits: * - transactions involving ERC-20 operations can be paid using the token itself rather than ETH, * - approve and pull operations can happen in a single transaction instead of two consecutive transactions, * - while adding as little as possible over the existing ERC-20 standard. * * @notice See https://eips.ethereum.org/EIPS/eip-2612#specification */ interface EIP2612 { \t/** \t * @notice EIP712 domain separator of the smart contract. It should be unique to the contract \t * and chain to prevent replay attacks from other domains, and satisfy the requirements of EIP-712, \t * but is otherwise unconstrained. \t */ \tfunction DOMAIN_SEPARATOR() external view returns (bytes32); \t/** \t * @notice Counter of the nonces used for the given address; nonce are used sequentially \t * \t * @dev To prevent from replay attacks nonce is incremented for each address after a successful `permit` execution \t * \t * @param owner an address to query number of used nonces for \t * @return number of used nonce, nonce number to be used next \t */ \tfunction nonces(address owner) external view returns (uint); \t/** \t * @notice For all addresses owner, spender, uint256s value, deadline and nonce, uint8 v, bytes32 r and s, \t * a call to permit(owner, spender, value, deadline, v, r, s) will set approval[owner][spender] to value, \t * increment nonces[owner] by 1, and emit a corresponding Approval event, \t * if and only if the following conditions are met: \t * - The current blocktime is less than or equal to deadline. \t * - owner is not the zero address. \t * - nonces[owner] (before the state update) is equal to nonce. \t * - r, s and v is a valid secp256k1 signature from owner of the message: \t * \t * @param owner token owner address, granting an approval to spend its tokens \t * @param spender an address approved by the owner (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t */ \tfunction permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /** * @title EIP-3009: Transfer With Authorization * * @notice A contract interface that enables transferring of fungible assets via a signed authorization. * See https://eips.ethereum.org/EIPS/eip-3009 * See https://eips.ethereum.org/EIPS/eip-3009#specification */ interface EIP3009 { \t/** \t * @dev Fired whenever the nonce gets used (ex.: `transferWithAuthorization`, `receiveWithAuthorization`) \t * \t * @param authorizer an address which has used the nonce \t * @param nonce the nonce used \t */ \tevent AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce); \t/** \t * @dev Fired whenever the nonce gets cancelled (ex.: `cancelAuthorization`) \t * \t * @dev Both `AuthorizationUsed` and `AuthorizationCanceled` imply the nonce \t * cannot be longer used, the only difference is that `AuthorizationCanceled` \t * implies no smart contract state change made (except the nonce marked as cancelled) \t * \t * @param authorizer an address which has cancelled the nonce \t * @param nonce the nonce cancelled \t */ \tevent AuthorizationCanceled(address indexed authorizer, bytes32 indexed nonce); \t/** \t * @notice Returns the state of an authorization, more specifically \t * if the specified nonce was already used by the address specified \t * \t * @dev Nonces are expected to be client-side randomly generated 32-byte data \t * unique to the authorizer's address \t * \t * @param authorizer Authorizer's address \t * @param nonce Nonce of the authorization \t * @return true if the nonce is used \t */ \tfunction authorizationState( \t\taddress authorizer, \t\tbytes32 nonce \t) external view returns (bool); \t/** \t * @notice Execute a transfer with a signed authorization \t * \t * @param from Payer's address (Authorizer) \t * @param to Payee's address \t * @param value Amount to be transferred \t * @param validAfter The time after which this is valid (unix time) \t * @param validBefore The time before which this is valid (unix time) \t * @param nonce Unique nonce \t * @param v v of the signature \t * @param r r of the signature \t * @param s s of the signature \t */ \tfunction transferWithAuthorization( \t\taddress from, \t\taddress to, \t\tuint256 value, \t\tuint256 validAfter, \t\tuint256 validBefore, \t\tbytes32 nonce, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) external; \t/** \t * @notice Receive a transfer with a signed authorization from the payer \t * \t * @dev This has an additional check to ensure that the payee's address matches \t * the caller of this function to prevent front-running attacks. \t * @dev See https://eips.ethereum.org/EIPS/eip-3009#security-considerations \t * \t * @param from Payer's address (Authorizer) \t * @param to Payee's address \t * @param value Amount to be transferred \t * @param validAfter The time after which this is valid (unix time) \t * @param validBefore The time before which this is valid (unix time) \t * @param nonce Unique nonce \t * @param v v of the signature \t * @param r r of the signature \t * @param s s of the signature \t */ \tfunction receiveWithAuthorization( \t\taddress from, \t\taddress to, \t\tuint256 value, \t\tuint256 validAfter, \t\tuint256 validBefore, \t\tbytes32 nonce, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) external; \t/** \t * @notice Attempt to cancel an authorization \t * \t * @param authorizer Authorizer's address \t * @param nonce Nonce of the authorization \t * @param v v of the signature \t * @param r r of the signature \t * @param s s of the signature \t */ \tfunction cancelAuthorization( \t\taddress authorizer, \t\tbytes32 nonce, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) external; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "./ERC20Spec.sol"; import "./ERC165Spec.sol"; /** * @title ERC1363 Interface * * @dev Interface defining a ERC1363 Payable Token contract. * Implementing contracts MUST implement the ERC1363 interface as well as the ERC20 and ERC165 interfaces. */ interface ERC1363 is ERC20, ERC165 { \t/* \t * Note: the ERC-165 identifier for this interface is 0xb0202a11. \t * 0xb0202a11 === \t * bytes4(keccak256('transferAndCall(address,uint256)')) ^ \t * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ \t * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^ \t * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^ \t * bytes4(keccak256('approveAndCall(address,uint256)')) ^ \t * bytes4(keccak256('approveAndCall(address,uint256,bytes)')) \t */ \t/** \t * @notice Transfer tokens from `msg.sender` to another address and then call `onTransferReceived` on receiver \t * @param to address The address which you want to transfer to \t * @param value uint256 The amount of tokens to be transferred \t * @return true unless throwing \t */ \tfunction transferAndCall(address to, uint256 value) external returns (bool); \t/** \t * @notice Transfer tokens from `msg.sender` to another address and then call `onTransferReceived` on receiver \t * @param to address The address which you want to transfer to \t * @param value uint256 The amount of tokens to be transferred \t * @param data bytes Additional data with no specified format, sent in call to `to` \t * @return true unless throwing \t */ \tfunction transferAndCall(address to, uint256 value, bytes memory data) external returns (bool); \t/** \t * @notice Transfer tokens from one address to another and then call `onTransferReceived` on receiver \t * @param from address The address which you want to send tokens from \t * @param to address The address which you want to transfer to \t * @param value uint256 The amount of tokens to be transferred \t * @return true unless throwing \t */ \tfunction transferFromAndCall(address from, address to, uint256 value) external returns (bool); \t/** \t * @notice Transfer tokens from one address to another and then call `onTransferReceived` on receiver \t * @param from address The address which you want to send tokens from \t * @param to address The address which you want to transfer to \t * @param value uint256 The amount of tokens to be transferred \t * @param data bytes Additional data with no specified format, sent in call to `to` \t * @return true unless throwing \t */ \tfunction transferFromAndCall(address from, address to, uint256 value, bytes memory data) external returns (bool); \t/** \t * @notice Approve the passed address to spend the specified amount of tokens on behalf of msg.sender \t * and then call `onApprovalReceived` on spender. \t * @param spender address The address which will spend the funds \t * @param value uint256 The amount of tokens to be spent \t */ \tfunction approveAndCall(address spender, uint256 value) external returns (bool); \t/** \t * @notice Approve the passed address to spend the specified amount of tokens on behalf of msg.sender \t * and then call `onApprovalReceived` on spender. \t * @param spender address The address which will spend the funds \t * @param value uint256 The amount of tokens to be spent \t * @param data bytes Additional data with no specified format, sent in call to `spender` \t */ \tfunction approveAndCall(address spender, uint256 value, bytes memory data) external returns (bool); } /** * @title ERC1363Receiver Interface * * @dev Interface for any contract that wants to support `transferAndCall` or `transferFromAndCall` * from ERC1363 token contracts. */ interface ERC1363Receiver { \t/* \t * Note: the ERC-165 identifier for this interface is 0x88a7ca5c. \t * 0x88a7ca5c === bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)")) \t */ \t/** \t * @notice Handle the receipt of ERC1363 tokens \t * \t * @dev Any ERC1363 smart contract calls this function on the recipient \t * after a `transfer` or a `transferFrom`. This function MAY throw to revert and reject the \t * transfer. Return of other than the magic value MUST result in the \t * transaction being reverted. \t * Note: the token contract address is always the message sender. \t * \t * @param operator address The address which called `transferAndCall` or `transferFromAndCall` function \t * @param from address The address which are token transferred from \t * @param value uint256 The amount of tokens transferred \t * @param data bytes Additional data with no specified format \t * @return `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))` \t * unless throwing \t */ \tfunction onTransferReceived(address operator, address from, uint256 value, bytes memory data) external returns (bytes4); } /** * @title ERC1363Spender Interface * * @dev Interface for any contract that wants to support `approveAndCall` * from ERC1363 token contracts. */ interface ERC1363Spender { \t/* \t * Note: the ERC-165 identifier for this interface is 0x7b04a2d0. \t * 0x7b04a2d0 === bytes4(keccak256("onApprovalReceived(address,uint256,bytes)")) \t */ \t/** \t * @notice Handle the approval of ERC1363 tokens \t * \t * @dev Any ERC1363 smart contract calls this function on the recipient \t * after an `approve`. This function MAY throw to revert and reject the \t * approval. Return of other than the magic value MUST result in the \t * transaction being reverted. \t * Note: the token contract address is always the message sender. \t * \t * @param owner address The address which called `approveAndCall` function \t * @param value uint256 The amount of tokens to be spent \t * @param data bytes Additional data with no specified format \t * @return `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))` \t * unless throwing \t */ \tfunction onApprovalReceived(address owner, uint256 value, bytes memory data) external returns (bytes4); } /** * @title Mintable ERC1363 Extension * * @notice Adds mint functions to the ERC1363 interface, these functions * follow the same idea and logic as ERC1363 transferAndCall functions, * allowing to notify the recipient ERC1363Receiver contract about the tokens received */ interface MintableERC1363 is ERC1363 { \t/** \t * @notice Mint tokens to the receiver and then call `onTransferReceived` on the receiver \t * @param to address The address which you want to mint to \t * @param value uint256 The amount of tokens to be minted \t * @return true unless throwing \t */ \tfunction mintAndCall(address to, uint256 value) external returns (bool); \t/** \t * @notice Mint tokens to the receiver and then call `onTransferReceived` on the receiver \t * @param to address The address which you want to mint to \t * @param value uint256 The amount of tokens to be minted \t * @param data bytes Additional data with no specified format, sent in call to `to` \t * @return true unless throwing \t */ \tfunction mintAndCall(address to, uint256 value, bytes memory data) external returns (bool); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /** * @title ERC-165 Standard Interface Detection * * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * @dev Implementers can declare support of contract interfaces, * which can then be queried by others. * * @author Christian Reitwießner, Nick Johnson, Fabian Vogelsteller, Jordi Baylina, Konrad Feldmeier, William Entriken */ interface ERC165 { \t/** \t * @notice Query if a contract implements an interface \t * \t * @dev Interface identification is specified in ERC-165. \t * This function uses less than 30,000 gas. \t * \t * @param interfaceID The interface identifier, as specified in ERC-165 \t * @return `true` if the contract implements `interfaceID` and \t * `interfaceID` is not 0xffffffff, `false` otherwise \t */ \tfunction supportsInterface(bytes4 interfaceID) external view returns (bool); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /** * @title EIP-20: ERC-20 Token Standard * * @notice The ERC-20 (Ethereum Request for Comments 20), proposed by Fabian Vogelsteller in November 2015, * is a Token Standard that implements an API for tokens within Smart Contracts. * * @notice It provides functionalities like to transfer tokens from one account to another, * to get the current token balance of an account and also the total supply of the token available on the network. * Besides these it also has some other functionalities like to approve that an amount of * token from an account can be spent by a third party account. * * @notice If a Smart Contract implements the following methods and events it can be called an ERC-20 Token * Contract and, once deployed, it will be responsible to keep track of the created tokens on Ethereum. * * @notice See https://ethereum.org/en/developers/docs/standards/tokens/erc-20/ * @notice See https://eips.ethereum.org/EIPS/eip-20 */ interface ERC20 { \t/** \t * @dev Fired in transfer(), transferFrom() to indicate that token transfer happened \t * \t * @param from an address tokens were consumed from \t * @param to an address tokens were sent to \t * @param value number of tokens transferred \t */ \tevent Transfer(address indexed from, address indexed to, uint256 value); \t/** \t * @dev Fired in approve() to indicate an approval event happened \t * \t * @param owner an address which granted a permission to transfer \t * tokens on its behalf \t * @param spender an address which received a permission to transfer \t * tokens on behalf of the owner `owner` \t * @param value amount of tokens granted to transfer on behalf \t */ \tevent Approval(address indexed owner, address indexed spender, uint256 value); \t/** \t * @return name of the token (ex.: USD Coin) \t */ \t// OPTIONAL - This method can be used to improve usability, \t// but interfaces and other contracts MUST NOT expect these values to be present. \t// function name() external view returns (string memory); \t/** \t * @return symbol of the token (ex.: USDC) \t */ \t// OPTIONAL - This method can be used to improve usability, \t// but interfaces and other contracts MUST NOT expect these values to be present. \t// function symbol() external view returns (string memory); \t/** \t * @dev Returns the number of decimals used to get its user representation. \t * For example, if `decimals` equals `2`, a balance of `505` tokens should \t * be displayed to a user as `5,05` (`505 / 10 ** 2`). \t * \t * @dev Tokens usually opt for a value of 18, imitating the relationship between \t * Ether and Wei. This is the value {ERC20} uses, unless this function is \t * overridden; \t * \t * @dev NOTE: This information is only used for _display_ purposes: it in \t * no way affects any of the arithmetic of the contract, including \t * {IERC20-balanceOf} and {IERC20-transfer}. \t * \t * @return token decimals \t */ \t// OPTIONAL - This method can be used to improve usability, \t// but interfaces and other contracts MUST NOT expect these values to be present. \t// function decimals() external view returns (uint8); \t/** \t * @return the amount of tokens in existence \t */ \tfunction totalSupply() external view returns (uint256); \t/** \t * @notice Gets the balance of a particular address \t * \t * @param owner the address to query the the balance for \t * @return balance an amount of tokens owned by the address specified \t */ \tfunction balanceOf(address owner) external view returns (uint256 balance); \t/** \t * @notice Transfers some tokens to an external address or a smart contract \t * \t * @dev Called by token owner (an address which has a \t * positive token balance tracked by this smart contract) \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * self address or \t * * smart contract which doesn't support ERC20 \t * \t * @param to an address to transfer tokens to, \t * must be either an external address or a smart contract, \t * compliant with the ERC20 standard \t * @param value amount of tokens to be transferred,, zero \t * value is allowed \t * @return success true on success, throws otherwise \t */ \tfunction transfer(address to, uint256 value) external returns (bool success); \t/** \t * @notice Transfers some tokens on behalf of address `from' (token owner) \t * to some other address `to` \t * \t * @dev Called by token owner on his own or approved address, \t * an address approved earlier by token owner to \t * transfer some amount of tokens on its behalf \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * smart contract which doesn't support ERC20 \t * \t * @param from token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to an address to transfer tokens to, \t * must be either an external address or a smart contract, \t * compliant with the ERC20 standard \t * @param value amount of tokens to be transferred,, zero \t * value is allowed \t * @return success true on success, throws otherwise \t */ \tfunction transferFrom(address from, address to, uint256 value) external returns (bool success); \t/** \t * @notice Approves address called `spender` to transfer some amount \t * of tokens on behalf of the owner (transaction sender) \t * \t * @dev Transaction sender must not necessarily own any tokens to grant the permission \t * \t * @param spender an address approved by the caller (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t * @return success true on success, throws otherwise \t */ \tfunction approve(address spender, uint256 value) external returns (bool success); \t/** \t * @notice Returns the amount which `spender` is still allowed to withdraw from `owner`. \t * \t * @dev A function to check an amount of tokens owner approved \t * to transfer on its behalf by some other address called "spender" \t * \t * @param owner an address which approves transferring some tokens on its behalf \t * @param spender an address approved to transfer some tokens on behalf \t * @return remaining an amount of tokens approved address `spender` can transfer on behalf \t * of token owner `owner` \t */ \tfunction allowance(address owner, address spender) external view returns (uint256 remaining); } /** * @title Mintable/burnable ERC20 Extension * * @notice Adds mint/burn functions to the ERC20 interface; * these functions are usually present in ERC20 implementations; * they become a must for the bridged tokens since the bridge usually * needs to have a way to mint tokens deposited from L1 to L2 * and to burn tokens to be withdrawn from L2 to L1 */ interface MintableBurnableERC20 is ERC20 { \t/** \t * @dev Mints (creates) some tokens to address specified \t * @dev The value specified is treated as is without taking \t * into account what `decimals` value is \t * \t * @param to an address to mint tokens to \t * @param value an amount of tokens to mint (create) \t * @return success true on success, false otherwise \t */ \tfunction mint(address to, uint256 value) external returns (bool success); \t/** \t * @dev Burns (destroys) some tokens from the address specified \t * \t * @dev The value specified is treated as is without taking \t * into account what `decimals` value is \t * \t * @param from an address to burn some tokens from \t * @param value an amount of tokens to burn (destroy) \t * @return success true on success, false otherwise \t */ \tfunction burn(address from, uint256 value) external returns (bool success); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. * * @dev Copy of the Zeppelin's library: * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/b0cf6fbb7a70f31527f36579ad644e1cf12fdf4e/contracts/utils/cryptography/ECDSA.sol */ library ECDSA { \t/** \t * @dev Overload of {ECDSA-recover} that receives the `v`, \t * `r` and `s` signature fields separately. \t */ \tfunction recover( \t\tbytes32 hash, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) internal pure returns (address) { \t\t// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature \t\t// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines \t\t// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most \t\t// signatures from current libraries generate a unique signature with an s-value in the lower half order. \t\t// \t\t// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value \t\t// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or \t\t// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept \t\t// these malleable signatures as well. \t\trequire( \t\t\tuint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, \t\t\t"invalid signature 's' value" \t\t); \t\trequire(v == 27 || v == 28, "invalid signature 'v' value"); \t\t// If the signature is valid (and not malleable), return the signer address \t\taddress signer = ecrecover(hash, v, r, s); \t\trequire(signer != address(0), "invalid signature"); \t\treturn signer; \t} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "../interfaces/ERC1363Spec.sol"; import "../interfaces/EIP2612.sol"; import "../interfaces/EIP3009.sol"; import "../lib/ECDSA.sol"; import "@lazy-sol/access-control-upgradeable/contracts/InitializableAccessControlCore.sol"; /** * @title Advanced ERC20 * * @notice Feature rich lightweight ERC20 implementation which is not built on top of OpenZeppelin ERC20 implementation. * It uses some other OpenZeppelin code: * - low level functions to work with ECDSA signatures (recover) * - low level functions to work contract addresses (isContract) * - OZ UUPS proxy and smart contracts upgradeability code * * @notice Token Summary: * - Symbol: configurable (set on deployment) * - Name: configurable (set on deployment) * - Decimals: 18 * - Initial/maximum total supply: configurable (set on deployment) * - Initial supply holder (initial holder) address: configurable (set on deployment) * - Mintability: configurable (initially enabled, but possible to revoke forever) * - Burnability: configurable (initially enabled, but possible to revoke forever) * - DAO Support: supports voting delegation * * @notice Features Summary: * - Supports atomic allowance modification, resolves well-known ERC20 issue with approve (arXiv:1907.00903) * - Voting delegation and delegation on behalf via EIP-712 (like in Compound CMP token) - gives the token * powerful governance capabilities by allowing holders to form voting groups by electing delegates * - Unlimited approval feature (like in 0x ZRX token) - saves gas for transfers on behalf * by eliminating the need to update “unlimited” allowance value * - ERC-1363 Payable Token - ERC721-like callback execution mechanism for transfers, transfers on behalf, * approvals, and restricted access mints (which are sometimes viewed as transfers from zero address); * allows creation of smart contracts capable of executing callbacks - in response to token transfer, approval, * and token minting - in a single transaction * - EIP-2612: permit - 712-signed approvals - improves user experience by allowing to use a token * without having an ETH to pay gas fees * - EIP-3009: Transfer With Authorization - improves user experience by allowing to use a token * without having an ETH to pay gas fees * * @notice This smart contract can be used as is, but also can be inherited and used as a template. * * @dev Even though smart contract has mint() function which is used to mint initial token supply, * the function is disabled forever after smart contract deployment by revoking `TOKEN_CREATOR` * permission from the deployer account * * @dev Token balances and total supply are effectively 192 bits long, meaning that maximum * possible total supply smart contract is able to track is 2^192 (close to 10^40 tokens) * * @dev Smart contract doesn't use safe math. All arithmetic operations are overflow/underflow safe. * Additionally, Solidity 0.8.7 enforces overflow/underflow safety. * * @dev Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) - resolved * Related events and functions are marked with "arXiv:1907.00903" tag: * - event Transfer(address indexed by, address indexed from, address indexed to, uint256 value) * - event Approve(address indexed owner, address indexed spender, uint256 oldValue, uint256 value) * - function increaseAllowance(address spender, uint256 value) public returns (bool) * - function decreaseAllowance(address spender, uint256 value) public returns (bool) * See: https://arxiv.org/abs/1907.00903v1 * https://ieeexplore.ieee.org/document/8802438 * See: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * @dev Reviewed * ERC-20 - according to https://eips.ethereum.org/EIPS/eip-20 * ERC-1363 - according to https://eips.ethereum.org/EIPS/eip-1363 * EIP-2612 - according to https://eips.ethereum.org/EIPS/eip-2612 * EIP-3009 - according to https://eips.ethereum.org/EIPS/eip-3009 * * @dev ERC20: contract has passed * - OpenZeppelin ERC20 tests * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/token/ERC20/ERC20.behavior.js * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/token/ERC20/ERC20.test.js * - Ref ERC1363 tests * https://github.com/vittominacori/erc1363-payable-token/blob/master/test/token/ERC1363/ERC1363.behaviour.js * - OpenZeppelin EIP2612 tests * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/token/ERC20/extensions/draft-ERC20Permit.test.js * - Coinbase EIP3009 tests * https://github.com/CoinbaseStablecoin/eip-3009/blob/master/test/EIP3009.test.ts * - Compound voting delegation tests * https://github.com/compound-finance/compound-protocol/blob/master/tests/Governance/CompTest.js * https://github.com/compound-finance/compound-protocol/blob/master/tests/Utils/EIP712.js * - OpenZeppelin voting delegation tests * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/token/ERC20/extensions/ERC20Votes.test.js * See adopted copies of all the tests in the project test folder * * @dev Compound-like voting delegation functions', public getters', and events' names * were changed for better code readability (Advanced ERC20 Name <- Comp/Zeppelin name): * - votingDelegates <- delegates * - votingPowerHistory <- checkpoints * - votingPowerHistoryLength <- numCheckpoints * - totalSupplyHistory <- _totalSupplyCheckpoints (private) * - usedNonces <- nonces (note: nonces are random instead of sequential) * - DelegateChanged (unchanged) * - VotingPowerChanged <- DelegateVotesChanged * - votingPowerOf <- getCurrentVotes * - votingPowerAt <- getPriorVotes * - totalSupplyAt <- getPriorTotalSupply * - delegate (unchanged) * - delegateWithAuthorization <- delegateBySig * @dev Compound-like voting delegation improved to allow the use of random nonces like in EIP-3009, * instead of sequential; same `usedNonces` EIP-3009 mapping is used to track nonces * * @dev Reference implementations "used": * - Atomic allowance: https://github.com/OpenZeppelin/openzeppelin-contracts * - Unlimited allowance: https://github.com/0xProject/protocol * - Voting delegation: https://github.com/compound-finance/compound-protocol * https://github.com/OpenZeppelin/openzeppelin-contracts * - ERC-1363: https://github.com/vittominacori/erc1363-payable-token * - EIP-2612: https://github.com/Uniswap/uniswap-v2-core * - EIP-3009: https://github.com/centrehq/centre-tokens * https://github.com/CoinbaseStablecoin/eip-3009 * - Meta transactions: https://github.com/0xProject/protocol * * @dev The code is based on Artificial Liquid Intelligence Token (ALI) developed by Alethea team * @dev Includes resolutions for ALI ERC20 Audit by Miguel Palhas, https://hackmd.io/@naps62/alierc20-audit * * @author Basil Gorin */ contract AdvancedERC20 is MintableERC1363, MintableBurnableERC20, EIP2612, EIP3009, InitializableAccessControlCore { \t/** \t * @notice Name of the token \t * \t * @notice ERC20 name of the token (long name) \t * \t * @dev ERC20 `function name() public view returns (string)` \t * \t * @dev Field is declared public: getter name() is created when compiled, \t * it returns the name of the token. \t */ \tstring public name; \t/** \t * @notice Symbol of the token \t * \t * @notice ERC20 symbol of that token (short name) \t * \t * @dev ERC20 `function symbol() public view returns (string)` \t * \t * @dev Field is declared public: getter symbol() is created when compiled, \t * it returns the symbol of the token \t */ \tstring public symbol; \t/** \t * @notice Decimals of the token: 18 \t * \t * @dev ERC20 `function decimals() public view returns (uint8)` \t * \t * @dev Field is declared public: getter decimals() is created when compiled, \t * it returns the number of decimals used to get its user representation. \t * For example, if `decimals` equals `6`, a balance of `1,500,000` tokens should \t * be displayed to a user as `1,5` (`1,500,000 / 10 ** 6`). \t * \t * @dev NOTE: This information is only used for _display_ purposes: it in \t * no way affects any of the arithmetic of the contract, including balanceOf() and transfer(). \t */ \tuint8 public constant decimals = 18; \t/** \t * @notice Total supply of the token: initially 10,000,000,000, \t * with the potential to decline over time as some tokens may get burnt but not minted \t * \t * @dev ERC20 `function totalSupply() public view returns (uint256)` \t * \t * @dev Field is declared public: getter totalSupply() is created when compiled, \t * it returns the amount of tokens in existence. \t */ \tuint256 public override totalSupply; // is set to 10 billion * 10^18 in the constructor \t/** \t * @dev A record of all the token balances \t * @dev This mapping keeps record of all token owners: \t * owner => balance \t */ \tmapping(address => uint256) private tokenBalances; \t/** \t * @notice A record of each account's voting delegate \t * \t * @dev Auxiliary data structure used to sum up an account's voting power \t * \t * @dev This mapping keeps record of all voting power delegations: \t * voting delegator (token owner) => voting delegate \t */ \tmapping(address => address) public votingDelegates; \t/** \t * @notice Auxiliary structure to store key-value pair, used to store: \t * - voting power record (key: block.timestamp, value: voting power) \t * - total supply record (key: block.timestamp, value: total supply) \t * @notice A voting power record binds voting power of a delegate to a particular \t * block when the voting power delegation change happened \t * k: block.number when delegation has changed; starting from \t * that block voting power value is in effect \t * v: cumulative voting power a delegate has obtained starting \t * from the block stored in blockNumber \t * @notice Total supply record binds total token supply to a particular \t * block when total supply change happened (due to mint/burn operations) \t */ \tstruct KV { \t\t/* \t\t * @dev key, a block number \t\t */ \t\tuint64 k; \t\t/* \t\t * @dev value, token balance or voting power \t\t */ \t\tuint192 v; \t} \t/** \t * @notice A record of each account's voting power historical data \t * \t * @dev Primarily data structure to store voting power for each account. \t * Voting power sums up from the account's token balance and delegated \t * balances. \t * \t * @dev Stores current value and entire history of its changes. \t * The changes are stored as an array of checkpoints (key-value pairs). \t * Checkpoint is an auxiliary data structure containing voting \t * power (number of votes) and block number when the checkpoint is saved \t * \t * @dev Maps voting delegate => voting power record \t */ \tmapping(address => KV[]) public votingPowerHistory; \t/** \t * @notice A record of total token supply historical data \t * \t * @dev Primarily data structure to store total token supply. \t * \t * @dev Stores current value and entire history of its changes. \t * The changes are stored as an array of checkpoints (key-value pairs). \t * Checkpoint is an auxiliary data structure containing total \t * token supply and block number when the checkpoint is saved \t */ \tKV[] public totalSupplyHistory; \t/** \t * @dev A record of nonces for signing/validating signatures in EIP-2612 `permit` \t * \t * @dev Note: EIP2612 doesn't imply a possibility for nonce randomization like in EIP-3009 \t * \t * @dev Maps delegate address => delegate nonce \t */ \tmapping(address => uint256) public override nonces; \t/** \t * @dev A record of used nonces for EIP-3009 transactions \t * \t * @dev A record of used nonces for signing/validating signatures \t * in `delegateWithAuthorization` for every delegate \t * \t * @dev Maps authorizer address => nonce => true/false (used unused) \t */ \tmapping(address => mapping(bytes32 => bool)) private usedNonces; \t/** \t * @notice A record of all the allowances to spend tokens on behalf \t * @dev Maps token owner address to an address approved to spend \t * some tokens on behalf, maps approved address to that amount \t * @dev owner => spender => value \t */ \tmapping(address => mapping(address => uint256)) private transferAllowances; \t/** \t * @notice Enables ERC20 transfers of the tokens \t * (transfer by the token owner himself) \t * @dev Feature FEATURE_TRANSFERS must be enabled in order for \t * `transfer()` function to succeed \t */ \tuint32 public constant FEATURE_TRANSFERS = 0x0000_0001; \t/** \t * @notice Enables ERC20 transfers on behalf \t * (transfer by someone else on behalf of token owner) \t * @dev Feature FEATURE_TRANSFERS_ON_BEHALF must be enabled in order for \t * `transferFrom()` function to succeed \t * @dev Token owner must call `approve()` first to authorize \t * the transfer on behalf \t */ \tuint32 public constant FEATURE_TRANSFERS_ON_BEHALF = 0x0000_0002; \t/** \t * @dev Defines if the default behavior of `transfer` and `transferFrom` \t * checks if the receiver smart contract supports ERC20 tokens \t * @dev When feature FEATURE_UNSAFE_TRANSFERS is enabled the transfers do not \t * check if the receiver smart contract supports ERC20 tokens, \t * i.e. `transfer` and `transferFrom` behave like `unsafeTransferFrom` \t * @dev When feature FEATURE_UNSAFE_TRANSFERS is disabled (default) the transfers \t * check if the receiver smart contract supports ERC20 tokens, \t * i.e. `transfer` and `transferFrom` behave like `transferFromAndCall` \t */ \tuint32 public constant FEATURE_UNSAFE_TRANSFERS = 0x0000_0004; \t/** \t * @notice Enables token owners to burn their own tokens \t * \t * @dev Feature FEATURE_OWN_BURNS must be enabled in order for \t * `burn()` function to succeed when called by token owner \t */ \tuint32 public constant FEATURE_OWN_BURNS = 0x0000_0008; \t/** \t * @notice Enables approved operators to burn tokens on behalf of their owners \t * \t * @dev Feature FEATURE_BURNS_ON_BEHALF must be enabled in order for \t * `burn()` function to succeed when called by approved operator \t */ \tuint32 public constant FEATURE_BURNS_ON_BEHALF = 0x0000_0010; \t/** \t * @notice Enables delegators to elect delegates \t * @dev Feature FEATURE_DELEGATIONS must be enabled in order for \t * `delegate()` function to succeed \t */ \tuint32 public constant FEATURE_DELEGATIONS = 0x0000_0020; \t/** \t * @notice Enables delegators to elect delegates on behalf \t * (via an EIP712 signature) \t * @dev Feature FEATURE_DELEGATIONS_ON_BEHALF must be enabled in order for \t * `delegateWithAuthorization()` function to succeed \t */ \tuint32 public constant FEATURE_DELEGATIONS_ON_BEHALF = 0x0000_0040; \t/** \t * @notice Enables ERC-1363 transfers with callback \t * @dev Feature FEATURE_ERC1363_TRANSFERS must be enabled in order for \t * ERC-1363 `transferFromAndCall` functions to succeed \t */ \tuint32 public constant FEATURE_ERC1363_TRANSFERS = 0x0000_0080; \t/** \t * @notice Enables ERC-1363 approvals with callback \t * @dev Feature FEATURE_ERC1363_APPROVALS must be enabled in order for \t * ERC-1363 `approveAndCall` functions to succeed \t */ \tuint32 public constant FEATURE_ERC1363_APPROVALS = 0x0000_0100; \t/** \t * @notice Enables approvals on behalf (EIP2612 permits \t * via an EIP712 signature) \t * @dev Feature FEATURE_EIP2612_PERMITS must be enabled in order for \t * `permit()` function to succeed \t */ \tuint32 public constant FEATURE_EIP2612_PERMITS = 0x0000_0200; \t/** \t * @notice Enables meta transfers on behalf (EIP3009 transfers \t * via an EIP712 signature) \t * @dev Feature FEATURE_EIP3009_TRANSFERS must be enabled in order for \t * `transferWithAuthorization()` function to succeed \t */ \tuint32 public constant FEATURE_EIP3009_TRANSFERS = 0x0000_0400; \t/** \t * @notice Enables meta transfers on behalf (EIP3009 transfers \t * via an EIP712 signature) \t * @dev Feature FEATURE_EIP3009_RECEPTIONS must be enabled in order for \t * `receiveWithAuthorization()` function to succeed \t */ \tuint32 public constant FEATURE_EIP3009_RECEPTIONS = 0x0000_0800; \t/** \t * @notice Token creator is responsible for creating (minting) \t * tokens to an arbitrary address \t * @dev Role ROLE_TOKEN_CREATOR allows minting tokens \t * (calling `mint` function) \t */ \tuint32 public constant ROLE_TOKEN_CREATOR = 0x0001_0000; \t/** \t * @notice Token destroyer is responsible for destroying (burning) \t * tokens owned by an arbitrary address \t * @dev Role ROLE_TOKEN_DESTROYER allows burning tokens \t * (calling `burn` function) \t */ \tuint32 public constant ROLE_TOKEN_DESTROYER = 0x0002_0000; \t/** \t * @notice ERC20 receivers are allowed to receive tokens without ERC20 safety checks, \t * which may be useful to simplify tokens transfers into "legacy" smart contracts \t * @dev When `FEATURE_UNSAFE_TRANSFERS` is not enabled addresses having \t * `ROLE_ERC20_RECEIVER` permission are allowed to receive tokens \t * via `transfer` and `transferFrom` functions in the same way they \t * would via `unsafeTransferFrom` function \t * @dev When `FEATURE_UNSAFE_TRANSFERS` is enabled `ROLE_ERC20_RECEIVER` permission \t * doesn't affect the transfer behaviour since \t * `transfer` and `transferFrom` behave like `unsafeTransferFrom` for any receiver \t * @dev ROLE_ERC20_RECEIVER is a shortening for ROLE_UNSAFE_ERC20_RECEIVER \t */ \tuint32 public constant ROLE_ERC20_RECEIVER = 0x0004_0000; \t/** \t * @notice ERC20 senders are allowed to send tokens without ERC20 safety checks, \t * which may be useful to simplify tokens transfers into "legacy" smart contracts \t * @dev When `FEATURE_UNSAFE_TRANSFERS` is not enabled senders having \t * `ROLE_ERC20_SENDER` permission are allowed to send tokens \t * via `transfer` and `transferFrom` functions in the same way they \t * would via `unsafeTransferFrom` function \t * @dev When `FEATURE_UNSAFE_TRANSFERS` is enabled `ROLE_ERC20_SENDER` permission \t * doesn't affect the transfer behaviour since \t * `transfer` and `transferFrom` behave like `unsafeTransferFrom` for any receiver \t * @dev ROLE_ERC20_SENDER is a shortening for ROLE_UNSAFE_ERC20_SENDER \t */ \tuint32 public constant ROLE_ERC20_SENDER = 0x0008_0000; \t/** \t * @notice EIP-712 contract's domain typeHash, \t * see https://eips.ethereum.org/EIPS/eip-712#rationale-for-typehash \t * \t * @dev Note: we do not include version into the domain typehash/separator, \t * it is implied version is concatenated to the name field, like "AdvancedERC20v1" \t */ \t// keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)") \tbytes32 public constant DOMAIN_TYPEHASH = 0x8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866; \t/** \t * @notice EIP-712 contract domain separator, \t * see https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator \t * note: we specify contract version in its name \t */ \tfunction DOMAIN_SEPARATOR() public view override returns(bytes32) { \t\t// build the EIP-712 contract domain separator, see https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator \t\t// note: we specify contract version in its name \t\treturn keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes("AdvancedERC20v1")), block.chainid, address(this))); \t} \t/** \t * @notice EIP-712 delegation struct typeHash, \t * see https://eips.ethereum.org/EIPS/eip-712#rationale-for-typehash \t */ \t// keccak256("Delegation(address delegate,uint256 nonce,uint256 expiry)") \tbytes32 public constant DELEGATION_TYPEHASH = 0xff41620983935eb4d4a3c7384a066ca8c1d10cef9a5eca9eb97ca735cd14a755; \t/** \t * @notice EIP-712 permit (EIP-2612) struct typeHash, \t * see https://eips.ethereum.org/EIPS/eip-712#rationale-for-typehash \t */ \t// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)") \tbytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; \t/** \t * @notice EIP-712 TransferWithAuthorization (EIP-3009) struct typeHash, \t * see https://eips.ethereum.org/EIPS/eip-712#rationale-for-typehash \t */ \t// keccak256("TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)") \tbytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH = 0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267; \t/** \t * @notice EIP-712 ReceiveWithAuthorization (EIP-3009) struct typeHash, \t * see https://eips.ethereum.org/EIPS/eip-712#rationale-for-typehash \t */ \t// keccak256("ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)") \tbytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH = 0xd099cc98ef71107a616c4f0f941f04c322d8e254fe26b3c6668db87aae413de8; \t/** \t * @notice EIP-712 CancelAuthorization (EIP-3009) struct typeHash, \t * see https://eips.ethereum.org/EIPS/eip-712#rationale-for-typehash \t */ \t// keccak256("CancelAuthorization(address authorizer,bytes32 nonce)") \tbytes32 public constant CANCEL_AUTHORIZATION_TYPEHASH = 0x158b0a9edf7a828aad02f63cd515c68ef2f50ba807396f6d12842833a1597429; \t/** \t * @dev Fired in mint() function \t * \t * @param by an address which minted some tokens (transaction sender) \t * @param to an address the tokens were minted to \t * @param value an amount of tokens minted \t */ \tevent Minted(address indexed by, address indexed to, uint256 value); \t/** \t * @dev Fired in burn() function \t * \t * @param by an address which burned some tokens (transaction sender) \t * @param from an address the tokens were burnt from \t * @param value an amount of tokens burnt \t */ \tevent Burnt(address indexed by, address indexed from, uint256 value); \t/** \t * @dev Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) \t * \t * @dev Similar to ERC20 Transfer event, but also logs an address which executed transfer \t * \t * @dev Fired in transfer(), transferFrom() and some other (non-ERC20) functions \t * \t * @param by an address which performed the transfer \t * @param from an address tokens were consumed from \t * @param to an address tokens were sent to \t * @param value number of tokens transferred \t */ \tevent Transfer(address indexed by, address indexed from, address indexed to, uint256 value); \t/** \t * @dev Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) \t * \t * @dev Similar to ERC20 Approve event, but also logs old approval value \t * \t * @dev Fired in approve(), increaseAllowance(), decreaseAllowance() functions, \t * may get fired in transfer functions \t * \t * @param owner an address which granted a permission to transfer \t * tokens on its behalf \t * @param spender an address which received a permission to transfer \t * tokens on behalf of the owner `owner` \t * @param oldValue previously granted amount of tokens to transfer on behalf \t * @param value new granted amount of tokens to transfer on behalf \t */ \tevent Approval(address indexed owner, address indexed spender, uint256 oldValue, uint256 value); \t/** \t * @dev Notifies that a key-value pair in `votingDelegates` mapping has changed, \t * i.e. a delegator address has changed its delegate address \t * \t * @param source delegator address, a token owner, effectively transaction sender (`by`) \t * @param from old delegate, an address which delegate right is revoked \t * @param to new delegate, an address which received the voting power \t */ \tevent DelegateChanged(address indexed source, address indexed from, address indexed to); \t/** \t * @dev Notifies that a key-value pair in `votingPowerHistory` mapping has changed, \t * i.e. a delegate's voting power has changed. \t * \t * @param by an address which executed delegate, mint, burn, or transfer operation \t * which had led to delegate voting power change \t * @param target delegate whose voting power has changed \t * @param fromVal previous number of votes delegate had \t * @param toVal new number of votes delegate has \t */ \tevent VotingPowerChanged(address indexed by, address indexed target, uint256 fromVal, uint256 toVal); \t/** \t * @dev Deploys the token smart contract, \t * assigns initial token supply to the address specified \t * \t * @param contractOwner smart contract owner (has minting/burning and all other permissions) \t * @param _name token name to set \t * @param _symbol token symbol to set \t * @param initialHolder owner of the initial token supply \t * @param initialSupply initial token supply \t * @param initialFeatures RBAC features enabled initially \t */ \tconstructor( \t\taddress contractOwner, \t\tstring memory _name, \t\tstring memory _symbol, \t\taddress initialHolder, \t\tuint256 initialSupply, \t\tuint256 initialFeatures \t) { \t\t// delegate to the same `postConstruct` function which would be used \t\t// by all the proxies to be deployed and to be pointing to this impl \t\tpostConstruct(contractOwner, _name, _symbol, initialHolder, initialSupply, initialFeatures); \t} \t/** \t * @dev "Constructor replacement" for a smart contract with a delayed initialization (post-deployment initialization) \t * \t * @param contractOwner smart contract owner (has minting/burning and all other permissions) \t * @param _name token name to set \t * @param _symbol token symbol to set \t * @param initialHolder owner of the initial token supply \t * @param initialSupply initial token supply value \t * @param initialFeatures RBAC features enabled initially \t */ \tfunction postConstruct( \t\taddress contractOwner, \t\tstring memory _name, \t\tstring memory _symbol, \t\taddress initialHolder, \t\tuint256 initialSupply, \t\tuint256 initialFeatures \t) public initializer { \t\t// verify name and symbol are set \t\trequire(bytes(_name).length > 0, "token name is not set"); \t\trequire(bytes(_symbol).length > 0, "token symbol is not set"); \t\t// assign token name and symbol \t\tname = _name; \t\tsymbol = _symbol; \t\t// verify initial holder address non-zero (is set) if there is an initial supply to mint \t\trequire(initialSupply == 0 || initialHolder != address(0), "_initialHolder not set (zero address)"); \t\t// if there is an initial supply to mint \t\tif(initialSupply != 0) { \t\t\t// mint the initial supply \t\t\t__mint(initialHolder, initialSupply); \t\t} \t\t// if initial contract owner or features are specified \t\tif(contractOwner != address(0) || initialFeatures != 0) { \t\t\t// initialize the RBAC module \t\t\t_postConstruct(contractOwner, initialFeatures); \t\t} \t} \t/** \t * @inheritdoc ERC165 \t */ \tfunction supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) { \t\t// reconstruct from current interface(s) and super interface(s) (if any) \t\treturn interfaceId == type(ERC165).interfaceId \t\t || interfaceId == type(ERC20).interfaceId \t\t || interfaceId == type(ERC1363).interfaceId \t\t || interfaceId == type(EIP2612).interfaceId \t\t || interfaceId == type(EIP3009).interfaceId; \t} \t// ===== Start: ERC-1363 functions ===== \t/** \t * @notice Transfers some tokens and then executes `onTransferReceived` callback on the receiver \t * \t * @inheritdoc ERC1363 \t * \t * @dev Called by token owner (an address which has a \t * positive token balance tracked by this smart contract) \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * EOA or smart contract which doesn't support ERC1363Receiver interface \t * @dev Returns true on success, throws otherwise \t * \t * @param to an address to transfer tokens to, \t * must be a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @return true unless throwing \t */ \tfunction transferAndCall(address to, uint256 value) public override returns (bool) { \t\t// delegate to `transferFromAndCall` passing `msg.sender` as `from` \t\treturn transferFromAndCall(msg.sender, to, value); \t} \t/** \t * @notice Transfers some tokens and then executes `onTransferReceived` callback on the receiver \t * \t * @inheritdoc ERC1363 \t * \t * @dev Called by token owner (an address which has a \t * positive token balance tracked by this smart contract) \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * EOA or smart contract which doesn't support ERC1363Receiver interface \t * @dev Returns true on success, throws otherwise \t * \t * @param to an address to transfer tokens to, \t * must be a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @param data [optional] additional data with no specified format, \t * sent in onTransferReceived call to `to` \t * @return true unless throwing \t */ \tfunction transferAndCall(address to, uint256 value, bytes memory data) public override returns (bool) { \t\t// delegate to `transferFromAndCall` passing `msg.sender` as `from` \t\treturn transferFromAndCall(msg.sender, to, value, data); \t} \t/** \t * @notice Transfers some tokens on behalf of address `from' (token owner) \t * to some other address `to` and then executes `onTransferReceived` callback on the receiver \t * \t * @inheritdoc ERC1363 \t * \t * @dev Called by token owner on his own or approved address, \t * an address approved earlier by token owner to \t * transfer some amount of tokens on its behalf \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * EOA or smart contract which doesn't support ERC1363Receiver interface \t * @dev Returns true on success, throws otherwise \t * \t * @param from token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to an address to transfer tokens to, \t * must be a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @return true unless throwing \t */ \tfunction transferFromAndCall(address from, address to, uint256 value) public override returns (bool) { \t\t// delegate to `transferFromAndCall` passing empty data param \t\treturn transferFromAndCall(from, to, value, ""); \t} \t/** \t * @notice Transfers some tokens on behalf of address `from' (token owner) \t * to some other address `to` and then executes a `onTransferReceived` callback on the receiver \t * \t * @inheritdoc ERC1363 \t * \t * @dev Called by token owner on his own or approved address, \t * an address approved earlier by token owner to \t * transfer some amount of tokens on its behalf \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * EOA or smart contract which doesn't support ERC1363Receiver interface \t * @dev Returns true on success, throws otherwise \t * \t * @param from token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to an address to transfer tokens to, \t * must be a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @param data [optional] additional data with no specified format, \t * sent in onTransferReceived call to `to` \t * @return true unless throwing \t */ \tfunction transferFromAndCall(address from, address to, uint256 value, bytes memory data) public override returns (bool) { \t\t// ensure ERC-1363 transfers are enabled \t\trequire(_isFeatureEnabled(FEATURE_ERC1363_TRANSFERS), "ERC1363 transfers are disabled"); \t\t// first delegate call to `unsafeTransferFrom` to perform the unsafe token(s) transfer \t\tunsafeTransferFrom(from, to, value); \t\t// after the successful transfer - check if receiver supports \t\t// ERC1363Receiver and execute a callback handler `onTransferReceived`, \t\t// reverting whole transaction on any error \t\t_notifyTransferred(from, to, value, data, false); \t\t// function throws on any error, so if we're here - it means operation successful, just return true \t\treturn true; \t} \t/** \t * @notice Approves address called `spender` to transfer some amount \t * of tokens on behalf of the owner, then executes a `onApprovalReceived` callback on `spender` \t * \t * @inheritdoc ERC1363 \t * \t * @dev Caller must not necessarily own any tokens to grant the permission \t * \t * @dev Throws if `spender` is an EOA or a smart contract which doesn't support ERC1363Spender interface \t * \t * @param spender an address approved by the caller (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t * @return true unless throwing \t */ \tfunction approveAndCall(address spender, uint256 value) public override returns (bool) { \t\t// delegate to `approveAndCall` passing empty data \t\treturn approveAndCall(spender, value, ""); \t} \t/** \t * @notice Approves address called `spender` to transfer some amount \t * of tokens on behalf of the owner, then executes a callback on `spender` \t * \t * @inheritdoc ERC1363 \t * \t * @dev Caller must not necessarily own any tokens to grant the permission \t * \t * @param spender an address approved by the caller (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t * @param data [optional] additional data with no specified format, \t * sent in onApprovalReceived call to `spender` \t * @return true unless throwing \t */ \tfunction approveAndCall(address spender, uint256 value, bytes memory data) public override returns (bool) { \t\t// ensure ERC-1363 approvals are enabled \t\trequire(_isFeatureEnabled(FEATURE_ERC1363_APPROVALS), "ERC1363 approvals are disabled"); \t\t// execute regular ERC20 approve - delegate to `approve` \t\tapprove(spender, value); \t\t// after the successful approve - check if receiver supports \t\t// ERC1363Spender and execute a callback handler `onApprovalReceived`, \t\t// reverting whole transaction on any error \t\t_notifyApproved(spender, value, data); \t\t// function throws on any error, so if we're here - it means operation successful, just return true \t\treturn true; \t} \t/** \t * @dev Auxiliary function to invoke `onTransferReceived` on a target address \t * The call is not executed if the target address is not a contract; in such \t * a case function throws if `allowEoa` is set to false, succeeds if it's true \t * \t * @dev Throws on any error; returns silently on success \t * \t * @param from representing the previous owner of the given token value \t * @param to target address that will receive the tokens \t * @param value the amount mount of tokens to be transferred \t * @param data [optional] data to send along with the call \t * @param allowEoa indicates if function should fail if `to` is an EOA \t */ \tfunction _notifyTransferred(address from, address to, uint256 value, bytes memory data, bool allowEoa) private { \t\t// if recipient `to` is EOA \t\tif(to.code.length == 0) { // !AddressUtils.isContract(_to) \t\t\t// ensure EOA recipient is allowed \t\t\trequire(allowEoa, "EOA recipient"); \t\t\t// exit if successful \t\t\treturn; \t\t} \t\t// otherwise - if `to` is a contract - execute onTransferReceived \t\tbytes4 response = ERC1363Receiver(to).onTransferReceived(msg.sender, from, value, data); \t\t// expected response is ERC1363Receiver(_to).onTransferReceived.selector \t\t// bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)")) \t\trequire(response == ERC1363Receiver(to).onTransferReceived.selector, "invalid onTransferReceived response"); \t} \t/** \t * @dev Auxiliary function to invoke `onApprovalReceived` on a target address \t * The call is not executed if the target address is not a contract; in such \t * a case function throws if `allowEoa` is set to false, succeeds if it's true \t * \t * @dev Throws on any error; returns silently on success \t * \t * @param spender the address which will spend the funds \t * @param value the amount of tokens to be spent \t * @param data [optional] data to send along with the call \t */ \tfunction _notifyApproved(address spender, uint256 value, bytes memory data) private { \t\t// ensure recipient is not EOA \t\trequire(spender.code.length > 0, "EOA spender"); // AddressUtils.isContract(_spender) \t\t// otherwise - if `to` is a contract - execute onApprovalReceived \t\tbytes4 response = ERC1363Spender(spender).onApprovalReceived(msg.sender, value, data); \t\t// expected response is ERC1363Spender(_to).onApprovalReceived.selector \t\t// bytes4(keccak256("onApprovalReceived(address,uint256,bytes)")) \t\trequire(response == ERC1363Spender(spender).onApprovalReceived.selector, "invalid onApprovalReceived response"); \t} \t// ===== End: ERC-1363 functions ===== \t// ===== Start: ERC20 functions ===== \t/** \t * @notice Gets the balance of a particular address \t * \t * @inheritdoc ERC20 \t * \t * @param owner the address to query the the balance for \t * @return balance an amount of tokens owned by the address specified \t */ \tfunction balanceOf(address owner) public view override returns (uint256 balance) { \t\t// read the balance and return \t\treturn tokenBalances[owner]; \t} \t/** \t * @notice Transfers some tokens to an external address or a smart contract \t * \t * @inheritdoc ERC20 \t * \t * @dev Called by token owner (an address which has a \t * positive token balance tracked by this smart contract) \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * self address or \t * * smart contract which doesn't support ERC20 \t * \t * @param to an address to transfer tokens to, \t * must be either an external address or a smart contract, \t * compliant with the ERC20 standard \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @return success true on success, throws otherwise \t */ \tfunction transfer(address to, uint256 value) public override returns (bool success) { \t\t// just delegate call to `transferFrom`, \t\t// `FEATURE_TRANSFERS` is verified inside it \t\treturn transferFrom(msg.sender, to, value); \t} \t/** \t * @notice Transfers some tokens on behalf of address `from' (token owner) \t * to some other address `to` \t * \t * @inheritdoc ERC20 \t * \t * @dev Called by token owner on his own or approved address, \t * an address approved earlier by token owner to \t * transfer some amount of tokens on its behalf \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * smart contract which doesn't support ERC20 \t * \t * @param from token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to an address to transfer tokens to, \t * must be either an external address or a smart contract, \t * compliant with the ERC20 standard \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @return success true on success, throws otherwise \t */ \tfunction transferFrom(address from, address to, uint256 value) public override returns (bool success) { \t\t// depending on `FEATURE_UNSAFE_TRANSFERS` we execute either safe (default) \t\t// or unsafe transfer \t\t// if `FEATURE_UNSAFE_TRANSFERS` is enabled \t\t// or receiver has `ROLE_ERC20_RECEIVER` permission \t\t// or sender has `ROLE_ERC20_SENDER` permission \t\tif(_isFeatureEnabled(FEATURE_UNSAFE_TRANSFERS) \t\t\t|| _isOperatorInRole(to, ROLE_ERC20_RECEIVER) \t\t\t|| _isSenderInRole(ROLE_ERC20_SENDER)) { \t\t\t// we execute unsafe transfer - delegate call to `unsafeTransferFrom`, \t\t\t// `FEATURE_TRANSFERS` is verified inside it \t\t\tunsafeTransferFrom(from, to, value); \t\t} \t\t// otherwise - if `FEATURE_UNSAFE_TRANSFERS` is disabled \t\t// and receiver doesn't have `ROLE_ERC20_RECEIVER` permission \t\telse { \t\t\t// we execute safe transfer - delegate call to `safeTransferFrom`, passing empty `data`, \t\t\t// `FEATURE_TRANSFERS` is verified inside it \t\t\tsafeTransferFrom(from, to, value, ""); \t\t} \t\t// both `unsafeTransferFrom` and `safeTransferFrom` throw on any error, so \t\t// if we're here - it means operation successful, \t\t// just return true \t\treturn true; \t} \t/** \t * @notice Transfers some tokens on behalf of address `from' (token owner) \t * to some other address `to` and then executes `onTransferReceived` callback \t * on the receiver if it is a smart contract (not an EOA) \t * \t * @dev Called by token owner on his own or approved address, \t * an address approved earlier by token owner to \t * transfer some amount of tokens on its behalf \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * * smart contract which doesn't support ERC1363Receiver interface \t * @dev Returns true on success, throws otherwise \t * \t * @param from token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to an address to transfer tokens to, \t * must be either an external address or a smart contract, \t * implementing ERC1363Receiver \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t * @param data [optional] additional data with no specified format, \t * sent in onTransferReceived call to `to` in case if its a smart contract \t * @return true unless throwing \t */ \tfunction safeTransferFrom(address from, address to, uint256 value, bytes memory data) public returns (bool) { \t\t// first delegate call to `unsafeTransferFrom` to perform the unsafe token(s) transfer \t\tunsafeTransferFrom(from, to, value); \t\t// after the successful transfer - check if receiver supports \t\t// ERC1363Receiver and execute a callback handler `onTransferReceived`, \t\t// reverting whole transaction on any error \t\t_notifyTransferred(from, to, value, data, true); \t\t// function throws on any error, so if we're here - it means operation successful, just return true \t\treturn true; \t} \t/** \t * @notice Transfers some tokens on behalf of address `from' (token owner) \t * to some other address `to` \t * \t * @dev In contrast to `transferFromAndCall` doesn't check recipient \t * smart contract to support ERC20 tokens (ERC1363Receiver) \t * @dev Designed to be used by developers when the receiver is known \t * to support ERC20 tokens but doesn't implement ERC1363Receiver interface \t * @dev Called by token owner on his own or approved address, \t * an address approved earlier by token owner to \t * transfer some amount of tokens on its behalf \t * @dev Throws on any error like \t * * insufficient token balance or \t * * incorrect `to` address: \t * * zero address or \t * * same as `from` address (self transfer) \t * @dev Returns silently on success, throws otherwise \t * \t * @param from token sender, token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to token receiver, an address to transfer tokens to \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t */ \tfunction unsafeTransferFrom(address from, address to, uint256 value) public { \t\t// make an internal transferFrom - delegate to `__transferFrom` \t\t__transferFrom(msg.sender, from, to, value); \t} \t/** \t * @dev Powers the meta transactions for `unsafeTransferFrom` - EIP-3009 `transferWithAuthorization` \t * and `receiveWithAuthorization` \t * \t * @dev See `unsafeTransferFrom` and `transferFrom` soldoc for details \t * \t * @param by an address executing the transfer, it can be token owner itself, \t * or an operator previously approved with `approve()` \t * @param from token sender, token owner which approved caller (transaction sender) \t * to transfer `value` of tokens on its behalf \t * @param to token receiver, an address to transfer tokens to \t * @param value amount of tokens to be transferred, zero \t * value is allowed \t */ \tfunction __transferFrom(address by, address from, address to, uint256 value) private { \t\t// if `from` is equal to sender, require transfers feature to be enabled \t\t// otherwise require transfers on behalf feature to be enabled \t\trequire(from == by && _isFeatureEnabled(FEATURE_TRANSFERS) \t\t || from != by && _isFeatureEnabled(FEATURE_TRANSFERS_ON_BEHALF), \t\t from == by ? "transfers are disabled": "transfers on behalf are disabled"); \t\t// non-zero source address check - Zeppelin \t\t// obviously, zero source address is a client mistake \t\t// it's not part of ERC20 standard but it's reasonable to fail fast \t\t// since for zero value transfer transaction succeeds otherwise \t\trequire(from != address(0), "transfer from the zero address"); \t\t// non-zero recipient address check \t\trequire(to != address(0), "transfer to the zero address"); \t\t// according to the Ethereum ERC20 token standard, it is possible to transfer \t\t// tokens to oneself using the transfer or transferFrom functions. \t\t// In both cases, the transfer will succeed as long as the sender has a sufficient balance of tokens. \t\t// require(_from != _to, "sender and recipient are the same (_from = _to)"); \t\t// sending tokens to the token smart contract itself is a client mistake \t\trequire(to != address(this), "invalid recipient (transfer to the token smart contract itself)"); \t\t// according to ERC-20 Token Standard, https://eips.ethereum.org/EIPS/eip-20 \t\t// "Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event." \t\tif(value == 0) { \t\t\t// emit an improved transfer event (arXiv:1907.00903) \t\t\temit Transfer(by, from, to, value); \t\t\t// emit an ERC20 transfer event \t\t\temit Transfer(from, to, value); \t\t\t// don't forget to return - we're done \t\t\treturn; \t\t} \t\t// no need to make arithmetic overflow check on the `value` - by design of mint() \t\t// in case of transfer on behalf \t\tif(from != by) { \t\t\t// read allowance value - the amount of tokens allowed to transfer - into the stack \t\t\tuint256 _allowance = transferAllowances[from][by]; \t\t\t// verify sender has an allowance to transfer amount of tokens requested \t\t\trequire(_allowance >= value, "transfer amount exceeds allowance"); \t\t\t// we treat max uint256 allowance value as an "unlimited" and \t\t\t// do not decrease allowance when it is set to "unlimited" value \t\t\tif(_allowance < type(uint256).max) { \t\t\t\t// update allowance value on the stack \t\t\t\t_allowance -= value; \t\t\t\t// update the allowance value in storage \t\t\t\ttransferAllowances[from][by] = _allowance; \t\t\t\t// emit an improved atomic approve event \t\t\t\temit Approval(from, by, _allowance + value, _allowance); \t\t\t\t// emit an ERC20 approval event to reflect the decrease \t\t\t\temit Approval(from, by, _allowance); \t\t\t} \t\t} \t\t// verify sender has enough tokens to transfer on behalf \t\trequire(tokenBalances[from] >= value, "transfer amount exceeds balance"); \t\t// perform the transfer: \t\t// decrease token owner (sender) balance \t\ttokenBalances[from] -= value; \t\t// increase `to` address (receiver) balance \t\ttokenBalances[to] += value; \t\t// move voting power associated with the tokens transferred \t\t__moveVotingPower(by, votingDelegates[from], votingDelegates[to], value); \t\t// emit an improved transfer event (arXiv:1907.00903) \t\temit Transfer(by, from, to, value); \t\t// emit an ERC20 transfer event \t\temit Transfer(from, to, value); \t} \t/** \t * @notice Approves address called `spender` to transfer some amount \t * of tokens on behalf of the owner (transaction sender) \t * \t * @inheritdoc ERC20 \t * \t * @dev Transaction sender must not necessarily own any tokens to grant the permission \t * \t * @param spender an address approved by the caller (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t * @return success true on success, throws otherwise \t */ \tfunction approve(address spender, uint256 value) public override returns (bool success) { \t\t// make an internal approve - delegate to `__approve` \t\t__approve(msg.sender, spender, value); \t\t// operation successful, return true \t\treturn true; \t} \t/** \t * @dev Powers the meta transaction for `approve` - EIP-2612 `permit` \t * \t * @dev Approves address called `spender` to transfer some amount \t * of tokens on behalf of the `owner` \t * \t * @dev `owner` must not necessarily own any tokens to grant the permission \t * @dev Throws if `spender` is a zero address \t * \t * @param owner owner of the tokens to set approval on behalf of \t * @param spender an address approved by the token owner \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t */ \tfunction __approve(address owner, address spender, uint256 value) private { \t\t// non-zero spender address check - Zeppelin \t\t// obviously, zero spender address is a client mistake \t\t// it's not part of ERC20 standard but it's reasonable to fail fast \t\trequire(spender != address(0), "approve to the zero address"); \t\t// read old approval value to emmit an improved event (arXiv:1907.00903) \t\tuint256 oldValue = transferAllowances[owner][spender]; \t\t// perform an operation: write value requested into the storage \t\ttransferAllowances[owner][spender] = value; \t\t// emit an improved atomic approve event (arXiv:1907.00903) \t\temit Approval(owner, spender, oldValue, value); \t\t// emit an ERC20 approval event \t\temit Approval(owner, spender, value); \t} \t/** \t * @notice Returns the amount which spender is still allowed to withdraw from owner. \t * \t * @inheritdoc ERC20 \t * \t * @dev A function to check an amount of tokens owner approved \t * to transfer on its behalf by some other address called "spender" \t * \t * @param owner an address which approves transferring some tokens on its behalf \t * @param spender an address approved to transfer some tokens on behalf \t * @return remaining an amount of tokens approved address `spender` can transfer on behalf \t * of token owner `owner` \t */ \tfunction allowance(address owner, address spender) public view override returns (uint256 remaining) { \t\t// read the value from storage and return \t\treturn transferAllowances[owner][spender]; \t} \t// ===== End: ERC20 functions ===== \t// ===== Start: Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) ===== \t/** \t * @notice Increases the allowance granted to `spender` by the transaction sender \t * \t * @dev Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) \t * \t * @dev Throws if value to increase by is zero or too big and causes arithmetic overflow \t * \t * @param spender an address approved by the caller (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens to increase by \t * @return true unless throwing \t */ \tfunction increaseAllowance(address spender, uint256 value) public returns (bool) { \t\t// read current allowance value \t\tuint256 currentVal = transferAllowances[msg.sender][spender]; \t\t// non-zero value and arithmetic overflow check on the allowance \t\tunchecked { \t\t\t// put operation into unchecked block to display user-friendly overflow error message for Solidity 0.8+ \t\t\trequire(currentVal + value > currentVal, "zero value approval increase or arithmetic overflow"); \t\t} \t\t// delegate call to `approve` with the new value \t\treturn approve(spender, currentVal + value); \t} \t/** \t * @notice Decreases the allowance granted to `spender` by the caller. \t * \t * @dev Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) \t * \t * @dev Throws if value to decrease by is zero or is greater than currently allowed value \t * \t * @param spender an address approved by the caller (token owner) \t * to spend some tokens on its behalf \t * @param value an amount of tokens to decrease by \t * @return true unless throwing \t */ \tfunction decreaseAllowance(address spender, uint256 value) public returns (bool) { \t\t// read current allowance value \t\tuint256 currentVal = transferAllowances[msg.sender][spender]; \t\t// non-zero value check on the allowance \t\trequire(value > 0, "zero value approval decrease"); \t\t// verify allowance decrease doesn't underflow \t\trequire(currentVal >= value, "ERC20: decreased allowance below zero"); \t\t// delegate call to `approve` with the new value \t\treturn approve(spender, currentVal - value); \t} \t// ===== End: Resolution for the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) ===== \t// ===== Start: Minting/burning extension ===== \t/** \t * @dev Mints (creates) some tokens to address specified \t * @dev The value specified is treated as is without taking \t * into account what `decimals` value is \t * \t * @dev Requires executor to have `ROLE_TOKEN_CREATOR` permission \t * \t * @dev Throws on overflow, if totalSupply + value doesn't fit into uint192 \t * \t * @param to the destination address to mint tokens to \t * @param value an amount of tokens to mint (create) \t * @return success true on success, throws otherwise \t */ \tfunction mint(address to, uint256 value) public override virtual returns(bool success) { \t\t// check if caller has sufficient permissions to mint tokens \t\trequire(_isSenderInRole(ROLE_TOKEN_CREATOR), "access denied"); \t\t// delegate call to unsafe `__mint` \t\t__mint(to, value); \t\t// always return true \t\treturn true; \t} \t/** \t * @dev Mints (creates) some tokens and then executes `onTransferReceived` callback on the receiver, \t * passing zero address as the token source address `from` \t * @dev The value specified is treated as is without taking into account what `decimals` value is \t * \t * @dev Requires executor to have `ROLE_TOKEN_CREATOR` permission \t * @dev Throws on overflow, if totalSupply + value doesn't fit into uint192 \t * @dev Throws if the destination address `to` is a smart contract not supporting ERC1363Receiver interface \t * \t * @param to the destination address to mint tokens to, can be an EAO \t * or a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to mint (create) \t * @return success true on success, throws otherwise \t */ \tfunction safeMint(address to, uint256 value, bytes memory data) public virtual returns(bool success) { \t\t// first delegate call to `mint` to perform regular minting \t\tmint(to, value); \t\t// after the successful minting - check if receiver supports \t\t// ERC1363Receiver and execute a callback handler `onTransferReceived`, \t\t// reverting whole transaction on any error \t\t_notifyTransferred(address(0), to, value, data, true); \t\t// function throws on any error, so if we're here - it means operation successful, just return true \t\treturn true; \t} \t/** \t * @dev Mints (creates) some tokens and then executes `onTransferReceived` callback on the receiver, \t * passing zero address as the token source address `from` \t * @dev The value specified is treated as is without taking into account what `decimals` value is \t * \t * @dev Requires executor to have `ROLE_TOKEN_CREATOR` permission \t * @dev Throws on overflow, if totalSupply + value doesn't fit into uint192 \t * @dev Throws if the destination address `to` is EOA or smart contract not supporting ERC1363Receiver interface \t * \t * @param to the destination address to mint tokens to, \t * must be a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to mint (create) \t * @return success true on success, throws otherwise \t */ \tfunction mintAndCall(address to, uint256 value) public override virtual returns (bool success) { \t\t// delegate to `mintAndCall` passing empty data param \t\treturn mintAndCall(to, value, ""); \t} \t/** \t * @dev Mints (creates) some tokens and then executes `onTransferReceived` callback on the receiver, \t * passing zero address as the token source address `from` \t * @dev The value specified is treated as is without taking into account what `decimals` value is \t * \t * @dev Requires executor to have `ROLE_TOKEN_CREATOR` permission \t * @dev Throws on overflow, if totalSupply + value doesn't fit into uint192 \t * @dev Throws if the destination address `to` is EOA or smart contract not supporting ERC1363Receiver interface \t * \t * @param to the destination address to mint tokens to, \t * must be a smart contract, implementing the ERC1363Receiver interface \t * @param value amount of tokens to mint (create) \t * @param data [optional] additional data with no specified format, \t * sent in onTransferReceived call to `to` \t * @return success true on success, throws otherwise \t */ \tfunction mintAndCall(address to, uint256 value, bytes memory data) public override virtual returns (bool success) { \t\t// first delegate call to `mint` to perform regular minting \t\tmint(to, value); \t\t// after the successful minting - check if receiver supports \t\t// ERC1363Receiver and execute a callback handler `onTransferReceived`, \t\t// reverting whole transaction on any error \t\t_notifyTransferred(address(0), to, value, data, false); \t\t// function throws on any error, so if we're here - it means operation successful, just return true \t\treturn true; \t} \t/** \t * @dev Mints (creates) some tokens to address specified \t * @dev The value specified is treated as is without taking \t * into account what `decimals` value is \t * \t * @dev Unsafe: doesn't verify the executor (msg.sender) permissions, \t * must be kept private at all times \t * \t * @dev Throws on overflow, if totalSupply + value doesn't fit into uint256 \t * \t * @param to an address to mint tokens to \t * @param value an amount of tokens to mint (create) \t */ \tfunction __mint(address to, uint256 value) private { \t\t// non-zero recipient address check \t\trequire(to != address(0), "zero address"); \t\t// non-zero value and arithmetic overflow check on the total supply \t\t// this check automatically secures arithmetic overflow on the individual balance \t\tunchecked { \t\t\t// put operation into unchecked block to display user-friendly overflow error message for Solidity 0.8+ \t\t\trequire(totalSupply + value > totalSupply, "zero value or arithmetic overflow"); \t\t} \t\t// uint192 overflow check (required by voting delegation) \t\trequire(totalSupply + value <= type(uint192).max, "total supply overflow (uint192)"); \t\t// perform mint: \t\t// increase total amount of tokens value \t\ttotalSupply += value; \t\t// increase `to` address balance \t\ttokenBalances[to] += value; \t\t// update total token supply history \t\t__updateHistory(totalSupplyHistory, add, value); \t\t// create voting power associated with the tokens minted \t\t__moveVotingPower(msg.sender, address(0), votingDelegates[to], value); \t\t// fire a minted event \t\temit Minted(msg.sender, to, value); \t\t// emit an improved transfer event (arXiv:1907.00903) \t\temit Transfer(msg.sender, address(0), to, value); \t\t// fire ERC20 compliant transfer event \t\temit Transfer(address(0), to, value); \t} \t/** \t * @dev Burns (destroys) some tokens from the address specified \t * \t * @dev The value specified is treated as is without taking \t * into account what `decimals` value is \t * \t * @dev Requires executor to have `ROLE_TOKEN_DESTROYER` permission \t * or FEATURE_OWN_BURNS/FEATURE_BURNS_ON_BEHALF features to be enabled \t * \t * @dev Can be disabled by the contract creator forever by disabling \t * FEATURE_OWN_BURNS/FEATURE_BURNS_ON_BEHALF features and then revoking \t * its own roles to burn tokens and to enable burning features \t * \t * @param from an address to burn some tokens from \t * @param value an amount of tokens to burn (destroy) \t * @return success true on success, throws otherwise \t */ \tfunction burn(address from, uint256 value) public override virtual returns(bool success) { \t\t// check if caller has sufficient permissions to burn tokens \t\t// and if not - check for possibility to burn own tokens or to burn on behalf \t\tif(!_isSenderInRole(ROLE_TOKEN_DESTROYER)) { \t\t\t// if `from` is equal to sender, require own burns feature to be enabled \t\t\t// otherwise require burns on behalf feature to be enabled \t\t\trequire(from == msg.sender && _isFeatureEnabled(FEATURE_OWN_BURNS) \t\t\t || from != msg.sender && _isFeatureEnabled(FEATURE_BURNS_ON_BEHALF), \t\t\t from == msg.sender? "burns are disabled": "burns on behalf are disabled"); \t\t\t// in case of burn on behalf \t\t\tif(from != msg.sender) { \t\t\t\t// read allowance value - the amount of tokens allowed to be burnt - into the stack \t\t\t\tuint256 _allowance = transferAllowances[from][msg.sender]; \t\t\t\t// verify sender has an allowance to burn amount of tokens requested \t\t\t\trequire(_allowance >= value, "burn amount exceeds allowance"); \t\t\t\t// we treat max uint256 allowance value as an "unlimited" and \t\t\t\t// do not decrease allowance when it is set to "unlimited" value \t\t\t\tif(_allowance < type(uint256).max) { \t\t\t\t\t// update allowance value on the stack \t\t\t\t\t_allowance -= value; \t\t\t\t\t// update the allowance value in storage \t\t\t\t\ttransferAllowances[from][msg.sender] = _allowance; \t\t\t\t\t// emit an improved atomic approve event (arXiv:1907.00903) \t\t\t\t\temit Approval(msg.sender, from, _allowance + value, _allowance); \t\t\t\t\t// emit an ERC20 approval event to reflect the decrease \t\t\t\t\temit Approval(from, msg.sender, _allowance); \t\t\t\t} \t\t\t} \t\t} \t\t// at this point we know that either sender is ROLE_TOKEN_DESTROYER or \t\t// we burn own tokens or on behalf (in latest case we already checked and updated allowances) \t\t// we have left to execute balance checks and burning logic itself \t\t// non-zero burn value check \t\trequire(value != 0, "zero value burn"); \t\t// non-zero source address check - Zeppelin \t\trequire(from != address(0), "burn from the zero address"); \t\t// verify `from` address has enough tokens to destroy \t\t// (basically this is a arithmetic overflow check) \t\trequire(tokenBalances[from] >= value, "burn amount exceeds balance"); \t\t// perform burn: \t\t// decrease `from` address balance \t\ttokenBalances[from] -= value; \t\t// decrease total amount of tokens value \t\ttotalSupply -= value; \t\t// update total token supply history \t\t__updateHistory(totalSupplyHistory, sub, value); \t\t// destroy voting power associated with the tokens burnt \t\t__moveVotingPower(msg.sender, votingDelegates[from], address(0), value); \t\t// fire a burnt event \t\temit Burnt(msg.sender, from, value); \t\t// emit an improved transfer event (arXiv:1907.00903) \t\temit Transfer(msg.sender, from, address(0), value); \t\t// fire ERC20 compliant transfer event \t\temit Transfer(from, address(0), value); \t\t// always return true \t\treturn true; \t} \t// ===== End: Minting/burning extension ===== \t// ===== Start: EIP-2612 functions ===== \t/** \t * @inheritdoc EIP2612 \t * \t * @dev Executes approve(spender, value) on behalf of the owner who EIP-712 \t * signed the transaction, i.e. as if transaction sender is the EIP712 signer \t * \t * @dev Sets the `value` as the allowance of `spender` over `owner` tokens, \t * given `owner` EIP-712 signed approval \t * \t * @dev Inherits the Multiple Withdrawal Attack on ERC20 Tokens (arXiv:1907.00903) \t * vulnerability in the same way as ERC20 `approve`, use standard ERC20 workaround \t * if this might become an issue: \t * https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit \t * \t * @dev Emits `Approval` event(s) in the same way as `approve` does \t * \t * @dev Requires: \t * - `spender` to be non-zero address \t * - `exp` to be a timestamp in the future \t * - `v`, `r` and `s` to be a valid `secp256k1` signature from `owner` \t * over the EIP712-formatted function arguments. \t * - the signature to use `owner` current nonce (see `nonces`). \t * \t * @dev For more information on the signature format, see the \t * https://eips.ethereum.org/EIPS/eip-2612#specification \t * \t * @param owner owner of the tokens to set approval on behalf of, \t * an address which signed the EIP-712 message \t * @param spender an address approved by the token owner \t * to spend some tokens on its behalf \t * @param value an amount of tokens spender `spender` is allowed to \t * transfer on behalf of the token owner \t * @param exp signature expiration time (unix timestamp) \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t */ \tfunction permit(address owner, address spender, uint256 value, uint256 exp, uint8 v, bytes32 r, bytes32 s) public override { \t\t// verify permits are enabled \t\trequire(_isFeatureEnabled(FEATURE_EIP2612_PERMITS), "EIP2612 permits are disabled"); \t\t// derive signer of the EIP712 Permit message, and \t\t// update the nonce for that particular signer to avoid replay attack!!! --------->>> ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ \t\taddress signer = __deriveSigner(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, exp), v, r, s); \t\t// perform message integrity and security validations \t\trequire(signer == owner, "invalid signature"); \t\trequire(block.timestamp < exp, "signature expired"); \t\t// delegate call to `__approve` - execute the logic required \t\t__approve(owner, spender, value); \t} \t// ===== End: EIP-2612 functions ===== \t// ===== Start: EIP-3009 functions ===== \t/** \t * @inheritdoc EIP3009 \t * \t * @notice Checks if specified nonce was already used \t * \t * @dev Nonces are expected to be client-side randomly generated 32-byte values \t * unique to the authorizer's address \t * \t * @dev Alias for usedNonces(authorizer, nonce) \t * \t * @param authorizer an address to check nonce for \t * @param nonce a nonce to check \t * @return true if the nonce was used, false otherwise \t */ \tfunction authorizationState(address authorizer, bytes32 nonce) public override view returns (bool) { \t\t// simply return the value from the mapping \t\treturn usedNonces[authorizer][nonce]; \t} \t/** \t * @inheritdoc EIP3009 \t * \t * @notice Execute a transfer with a signed authorization \t * \t * @param from token sender and transaction authorizer \t * @param to token receiver \t * @param value amount to be transferred \t * @param validAfter signature valid after time (unix timestamp) \t * @param validBefore signature valid before time (unix timestamp) \t * @param nonce unique random nonce \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t */ \tfunction transferWithAuthorization( \t\taddress from, \t\taddress to, \t\tuint256 value, \t\tuint256 validAfter, \t\tuint256 validBefore, \t\tbytes32 nonce, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) public override { \t\t// ensure EIP-3009 transfers are enabled \t\trequire(_isFeatureEnabled(FEATURE_EIP3009_TRANSFERS), "EIP3009 transfers are disabled"); \t\t// derive signer of the EIP712 TransferWithAuthorization message \t\taddress signer = __deriveSigner(abi.encode(TRANSFER_WITH_AUTHORIZATION_TYPEHASH, from, to, value, validAfter, validBefore, nonce), v, r, s); \t\t// perform message integrity and security validations \t\trequire(signer == from, "invalid signature"); \t\trequire(block.timestamp > validAfter, "signature not yet valid"); \t\trequire(block.timestamp < validBefore, "signature expired"); \t\t// use the nonce supplied (verify, mark as used, emit event) \t\t__useNonce(from, nonce, false); \t\t// delegate call to `__transferFrom` - execute the logic required \t\t__transferFrom(signer, from, to, value); \t} \t/** \t * @inheritdoc EIP3009 \t * \t * @notice Receive a transfer with a signed authorization from the payer \t * \t * @dev This has an additional check to ensure that the payee's address \t * matches the caller of this function to prevent front-running attacks. \t * \t * @param from token sender and transaction authorizer \t * @param to token receiver \t * @param value amount to be transferred \t * @param validAfter signature valid after time (unix timestamp) \t * @param validBefore signature valid before time (unix timestamp) \t * @param nonce unique random nonce \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t */ \tfunction receiveWithAuthorization( \t\taddress from, \t\taddress to, \t\tuint256 value, \t\tuint256 validAfter, \t\tuint256 validBefore, \t\tbytes32 nonce, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) public override { \t\t// verify EIP3009 receptions are enabled \t\trequire(_isFeatureEnabled(FEATURE_EIP3009_RECEPTIONS), "EIP3009 receptions are disabled"); \t\t// derive signer of the EIP712 ReceiveWithAuthorization message \t\taddress signer = __deriveSigner(abi.encode(RECEIVE_WITH_AUTHORIZATION_TYPEHASH, from, to, value, validAfter, validBefore, nonce), v, r, s); \t\t// perform message integrity and security validations \t\trequire(signer == from, "invalid signature"); \t\trequire(block.timestamp > validAfter, "signature not yet valid"); \t\trequire(block.timestamp < validBefore, "signature expired"); \t\trequire(to == msg.sender, "access denied"); \t\t// use the nonce supplied (verify, mark as used, emit event) \t\t__useNonce(from, nonce, false); \t\t// delegate call to `__transferFrom` - execute the logic required \t\t__transferFrom(signer, from, to, value); \t} \t/** \t * @inheritdoc EIP3009 \t * \t * @notice Attempt to cancel an authorization \t * \t * @param authorizer transaction authorizer \t * @param nonce unique random nonce to cancel (mark as used) \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t */ \tfunction cancelAuthorization( \t\taddress authorizer, \t\tbytes32 nonce, \t\tuint8 v, \t\tbytes32 r, \t\tbytes32 s \t) public override { \t\t// derive signer of the EIP712 ReceiveWithAuthorization message \t\taddress signer = __deriveSigner(abi.encode(CANCEL_AUTHORIZATION_TYPEHASH, authorizer, nonce), v, r, s); \t\t// perform message integrity and security validations \t\trequire(signer == authorizer, "invalid signature"); \t\t// cancel the nonce supplied (verify, mark as used, emit event) \t\t__useNonce(authorizer, nonce, true); \t} \t/** \t * @dev Auxiliary function to verify structured EIP712 message signature and derive its signer \t * \t * @dev Recovers the non-zero signer address from the signed message throwing on failure \t * \t * @param abiEncodedTypehash abi.encode of the message typehash together with all its parameters \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t * @return recovered non-zero signer address, unless throwing \t */ \tfunction __deriveSigner(bytes memory abiEncodedTypehash, uint8 v, bytes32 r, bytes32 s) private view returns(address) { \t\t// build the EIP-712 hashStruct of the message \t\tbytes32 hashStruct = keccak256(abiEncodedTypehash); \t\t// calculate the EIP-712 digest "\\x19\\x01" ‖ domainSeparator ‖ hashStruct(message) \t\tbytes32 digest = keccak256(abi.encodePacked("\\x19\\x01", DOMAIN_SEPARATOR(), hashStruct)); \t\t// recover the address which signed the message with v, r, s \t\taddress signer = ECDSA.recover(digest, v, r, s); \t\t// according to the specs, zero address must be rejected when using ecrecover \t\t// this check already happened inside `ECDSA.recover` \t\t// return the signer address derived from the signature \t\treturn signer; \t} \t/** \t * @dev Auxiliary function to use/cancel the nonce supplied for a given authorizer: \t * 1. Verifies the nonce was not used before \t * 2. Marks the nonce as used \t * 3. Emits an event that the nonce was used/cancelled \t * \t * @dev Set `cancellation` to false (default) to use nonce, \t * set `cancellation` to true to cancel nonce \t * \t * @dev It is expected that the nonce supplied is a randomly \t * generated uint256 generated by the client \t * \t * @param authorizer an address to use/cancel nonce for \t * @param nonce random nonce to use \t * @param cancellation true to emit `AuthorizationCancelled`, false to emit `AuthorizationUsed` event \t */ \tfunction __useNonce(address authorizer, bytes32 nonce, bool cancellation) private { \t\t// verify nonce was not used before \t\trequire(!usedNonces[authorizer][nonce], "invalid nonce"); \t\t// update the nonce state to "used" for that particular signer to avoid replay attack \t\tusedNonces[authorizer][nonce] = true; \t\t// depending on the usage type (use/cancel) \t\tif(cancellation) { \t\t\t// emit an event regarding the nonce cancelled \t\t\temit AuthorizationCanceled(authorizer, nonce); \t\t} \t\telse { \t\t\t// emit an event regarding the nonce used \t\t\temit AuthorizationUsed(authorizer, nonce); \t\t} \t} \t// ===== End: EIP-3009 functions ===== \t// ===== Start: DAO Support (Compound-like voting delegation) ===== \t/** \t * @notice Gets current voting power of the account `holder` \t * \t * @param holder the address of account to get voting power of \t * @return current cumulative voting power of the account, \t * sum of token balances of all its voting delegators \t */ \tfunction votingPowerOf(address holder) public view returns (uint256) { \t\t// get a link to an array of voting power history records for an address specified \t\tKV[] storage history = votingPowerHistory[holder]; \t\t// lookup the history and return latest element \t\treturn history.length == 0? 0: history[history.length - 1].v; \t} \t/** \t * @notice Gets past voting power of the account `holder` at some block `blockNum` \t * \t * @dev Throws if `blockNum` is not in the past (not the finalized block) \t * \t * @param holder the address of account to get voting power of \t * @param blockNum block number to get the voting power at \t * @return past cumulative voting power of the account, \t * sum of token balances of all its voting delegators at block number `blockNum` \t */ \tfunction votingPowerAt(address holder, uint256 blockNum) public view returns (uint256) { \t\t// make sure block number is in the past (the finalized block) \t\trequire(blockNum < block.number, "block not yet mined"); // Compound msg not yet determined \t\t// `votingPowerHistory[holder]` is an array ordered by `blockNumber`, ascending; \t\t// apply binary search on `votingPowerHistory[_of]` to find such an entry number `i`, that \t\t// `votingPowerHistory[holder][i].k ≤ blockNum`, but in the same time \t\t// `votingPowerHistory[holder][i + 1].k > blockNum` \t\t// return the result - voting power found at index `i` \t\treturn __binaryLookup(votingPowerHistory[holder], blockNum); \t} \t/** \t * @dev Reads an entire voting power history array for the delegate specified \t * \t * @param holder delegate to query voting power history for \t * @return voting power history array for the delegate of interest \t */ \tfunction votingPowerHistoryOf(address holder) public view returns(KV[] memory) { \t\t// return an entire array as memory \t\treturn votingPowerHistory[holder]; \t} \t/** \t * @dev Returns length of the voting power history array for the delegate specified; \t * useful since reading an entire array just to get its length is expensive (gas cost) \t * \t * @param holder delegate to query voting power history length for \t * @return voting power history array length for the delegate of interest \t */ \tfunction votingPowerHistoryLength(address holder) public view returns(uint256) { \t\t// read array length and return \t\treturn votingPowerHistory[holder].length; \t} \t/** \t * @notice Gets past total token supply value at some block `blockNum` \t * \t * @dev Throws if `blockNum` is not in the past (not the finalized block) \t * \t * @param blockNum block number to get the total token supply at \t * @return past total token supply at block number `blockNum` \t */ \tfunction totalSupplyAt(uint256 blockNum) public view returns(uint256) { \t\t// make sure block number is in the past (the finalized block) \t\trequire(blockNum < block.number, "block not yet mined"); \t\t// `totalSupplyHistory` is an array ordered by `k`, ascending; \t\t// apply binary search on `totalSupplyHistory` to find such an entry number `i`, that \t\t// `totalSupplyHistory[i].k ≤ blockNum`, but in the same time \t\t// `totalSupplyHistory[i + 1].k > blockNum` \t\t// return the result - value `totalSupplyHistory[i].v` found at index `i` \t\treturn __binaryLookup(totalSupplyHistory, blockNum); \t} \t/** \t * @dev Reads an entire total token supply history array \t * \t * @return total token supply history array, a key-value pair array, \t * where key is a block number and value is total token supply at that block \t */ \tfunction entireSupplyHistory() public view returns(KV[] memory) { \t\t// return an entire array as memory \t\treturn totalSupplyHistory; \t} \t/** \t * @dev Returns length of the total token supply history array; \t * useful since reading an entire array just to get its length is expensive (gas cost) \t * \t * @return total token supply history array \t */ \tfunction totalSupplyHistoryLength() public view returns(uint256) { \t\t// read array length and return \t\treturn totalSupplyHistory.length; \t} \t/** \t * @notice Delegates voting power of the delegator `msg.sender` to the delegate `to` \t * \t * @dev Accepts zero value address to delegate voting power to, effectively \t * removing the delegate in that case \t * \t * @param to address to delegate voting power to \t */ \tfunction delegate(address to) public { \t\t// verify delegations are enabled \t\trequire(_isFeatureEnabled(FEATURE_DELEGATIONS), "delegations are disabled"); \t\t// delegate call to `__delegate` \t\t__delegate(msg.sender, to); \t} \t/** \t * @dev Powers the meta transaction for `delegate` - `delegateWithAuthorization` \t * \t * @dev Auxiliary function to delegate delegator's `from` voting power to the delegate `to` \t * @dev Writes to `votingDelegates` and `votingPowerHistory` mappings \t * \t * @param from delegator who delegates his voting power \t * @param to delegate who receives the voting power \t */ \tfunction __delegate(address from, address to) private { \t\t// read current delegate to be replaced by a new one \t\taddress fromDelegate = votingDelegates[from]; \t\t// read current voting power (it is equal to token balance) \t\tuint256 value = tokenBalances[from]; \t\t// reassign voting delegate to `to` \t\tvotingDelegates[from] = to; \t\t// update voting power for `fromDelegate` and `to` \t\t__moveVotingPower(from, fromDelegate, to, value); \t\t// emit an event \t\temit DelegateChanged(from, fromDelegate, to); \t} \t/** \t * @notice Delegates voting power of the delegator (represented by its signature) to the delegate `to` \t * \t * @dev Accepts zero value address to delegate voting power to, effectively \t * removing the delegate in that case \t * \t * @dev Compliant with EIP-712: Ethereum typed structured data hashing and signing, \t * see https://eips.ethereum.org/EIPS/eip-712 \t * \t * @param to address to delegate voting power to \t * @param nonce nonce used to construct the signature, and used to validate it; \t * nonce is increased by one after successful signature validation and vote delegation \t * @param exp signature expiration time \t * @param v the recovery byte of the signature \t * @param r half of the ECDSA signature pair \t * @param s half of the ECDSA signature pair \t */ \tfunction delegateWithAuthorization(address to, bytes32 nonce, uint256 exp, uint8 v, bytes32 r, bytes32 s) public { \t\t// verify delegations on behalf are enabled \t\trequire(_isFeatureEnabled(FEATURE_DELEGATIONS_ON_BEHALF), "delegations on behalf are disabled"); \t\t// derive signer of the EIP712 Delegation message \t\taddress signer = __deriveSigner(abi.encode(DELEGATION_TYPEHASH, to, nonce, exp), v, r, s); \t\t// perform message integrity and security validations \t\trequire(block.timestamp < exp, "signature expired"); // Compound msg \t\t// use the nonce supplied (verify, mark as used, emit event) \t\t__useNonce(signer, nonce, false); \t\t// delegate call to `__delegate` - execute the logic required \t\t__delegate(signer, to); \t} \t/** \t * @dev Auxiliary function to move voting power `value` \t * from delegate `from` to the delegate `to` \t * \t * @dev Doesn't have any effect if `from == to`, or if `value == 0` \t * \t * @param by an address which executed delegate, mint, burn, or transfer operation \t * which had led to delegate voting power change \t * @param from delegate to move voting power from \t * @param to delegate to move voting power to \t * @param value voting power to move from `from` to `to` \t */ \tfunction __moveVotingPower(address by, address from, address to, uint256 value) private { \t\t// if there is no move (`from == to`) or there is nothing to move (`value == 0`) \t\tif(from == to || value == 0) { \t\t\t// return silently with no action \t\t\treturn; \t\t} \t\t// if source address is not zero - decrease its voting power \t\tif(from != address(0)) { \t\t\t// get a link to an array of voting power history records for an address specified \t\t\tKV[] storage h = votingPowerHistory[from]; \t\t\t// update source voting power: decrease by `value` \t\t\t(uint256 fromVal, uint256 toVal) = __updateHistory(h, sub, value); \t\t\t// emit an event \t\t\temit VotingPowerChanged(by, from, fromVal, toVal); \t\t} \t\t// if destination address is not zero - increase its voting power \t\tif(to != address(0)) { \t\t\t// get a link to an array of voting power history records for an address specified \t\t\tKV[] storage h = votingPowerHistory[to]; \t\t\t// update destination voting power: increase by `value` \t\t\t(uint256 fromVal, uint256 toVal) = __updateHistory(h, add, value); \t\t\t// emit an event \t\t\temit VotingPowerChanged(by, to, fromVal, toVal); \t\t} \t} \t/** \t * @dev Auxiliary function to append key-value pair to an array, \t * sets the key to the current block number and \t * value as derived \t * \t * @param h array of key-value pairs to append to \t * @param op a function (add/subtract) to apply \t * @param delta the value for a key-value pair to add/subtract \t */ \tfunction __updateHistory( \t\tKV[] storage h, \t\tfunction(uint256,uint256) pure returns(uint256) op, \t\tuint256 delta \t) private returns(uint256 fromVal, uint256 toVal) { \t\t// init the old value - value of the last pair of the array \t\tfromVal = h.length == 0? 0: h[h.length - 1].v; \t\t// init the new value - result of the operation on the old value \t\ttoVal = op(fromVal, delta); \t\t// if there is an existing voting power value stored for current block \t\tif(h.length != 0 && h[h.length - 1].k == block.number) { \t\t\t// update voting power which is already stored in the current block \t\t\th[h.length - 1].v = uint192(toVal); \t\t} \t\t// otherwise - if there is no value stored for current block \t\telse { \t\t\t// add new element into array representing the value for current block \t\t\th.push(KV(uint64(block.number), uint192(toVal))); \t\t} \t} \t/** \t * @dev Auxiliary function to lookup for a value in a sorted by key (ascending) \t * array of key-value pairs \t * \t * @dev This function finds a key-value pair element in an array with the closest key \t * to the key of interest (not exceeding that key) and returns the value \t * of the key-value pair element found \t * \t * @dev An array to search in is a KV[] key-value pair array ordered by key `k`, \t * it is sorted in ascending order (`k` increases as array index increases) \t * \t * @dev Returns zero for an empty array input regardless of the key input \t * \t * @param h an array of key-value pair elements to search in \t * @param k key of interest to look the value for \t * @return the value of the key-value pair of the key-value pair element with the closest \t * key to the key of interest (not exceeding that key) \t */ \tfunction __binaryLookup(KV[] storage h, uint256 k) private view returns(uint256) { \t\t// if an array is empty, there is nothing to lookup in \t\tif(h.length == 0) { \t\t\t// by documented agreement, fall back to a zero result \t\t\treturn 0; \t\t} \t\t// check last key-value pair key: \t\t// if the key is smaller than the key of interest \t\tif(h[h.length - 1].k <= k) { \t\t\t// we're done - return the value from the last element \t\t\treturn h[h.length - 1].v; \t\t} \t\t// check first voting power history record block number: \t\t// if history was never updated before the block of interest \t\tif(h[0].k > k) { \t\t\t// we're done - voting power at the block num of interest was zero \t\t\treturn 0; \t\t} \t\t// left bound of the search interval, originally start of the array \t\tuint256 i = 0; \t\t// right bound of the search interval, originally end of the array \t\tuint256 j = h.length - 1; \t\t// the iteration process narrows down the bounds by \t\t// splitting the interval in a half oce per each iteration \t\twhile(j > i) { \t\t\t// get an index in the middle of the interval [i, j] \t\t\tuint256 m = j - (j - i) / 2; \t\t\t// read an element to compare it with the value of interest \t\t\tKV memory kv = h[m]; \t\t\t// if we've got a strict equal - we're lucky and done \t\t\tif(kv.k == k) { \t\t\t\t// just return the result - pair value at index `k` \t\t\t\treturn kv.v; \t\t\t} \t\t\t// if the value of interest is larger - move left bound to the middle \t\t\telse if(kv.k < k) { \t\t\t\t// move left bound `i` to the middle position `k` \t\t\t\ti = m; \t\t\t} \t\t\t// otherwise, when the value of interest is smaller - move right bound to the middle \t\t\telse { \t\t\t\t// move right bound `j` to the middle position `k - 1`: \t\t\t\t// element at position `k` is greater and cannot be the result \t\t\t\tj = m - 1; \t\t\t} \t\t} \t\t// reaching that point means no exact match found \t\t// since we're interested in the element which is not larger than the \t\t// element of interest, we return the lower bound `i` \t\treturn h[i].v; \t} \t/** \t * @dev Adds a + b \t * Function is used as a parameter for other functions \t * \t * @param a addition term 1 \t * @param b addition term 2 \t * @return a + b \t */ \tfunction add(uint256 a, uint256 b) private pure returns(uint256) { \t\t// add `a` to `b` and return \t\treturn a + b; \t} \t/** \t * @dev Subtracts a - b \t * Function is used as a parameter for other functions \t * \t * @dev Requires a ≥ b \t * \t * @param a subtraction term 1 \t * @param b subtraction term 2, b ≤ a \t * @return a - b \t */ \tfunction sub(uint256 a, uint256 b) private pure returns(uint256) { \t\t// subtract `b` from `a` and return \t\treturn a - b; \t} \t// ===== End: DAO Support (Compound-like voting delegation) ===== } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@lazy-sol/advanced-erc20/contracts/token/AdvancedERC20.sol"; /** * * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑ ↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑ ↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑↑↑↑↑↑ * ↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑ * ↑↑↑↑↑↑ ↑↑ ↑↑ ↑↑↑↑↑↑ * ↑↑↑↑↑↑ ↑↑↑↑↑↑ * ↑↑↑↑↑ ↑↑ ↑↑ ↑↑↑↑ * ↑↑↑↑ ↑↑↑ ↑↑ ↑↑↑↑ * ↑↑↑↑ ↑ ↑ ↑↑ ↑↑ ↑↑↑↑ * ↑↑↑ ↑ ↑↑ ↑↑ ↑ ↑↑↑ * ↑↑↑↑ ↑ ↑↑ ↑↑ ↑ ↑↑↑ * ↑↑↑ ↑ ↑↑↑ ↑↑↑ ↑ ↑↑↑ * ↑↑↑ ↑ ↑↑ ↑↑↑↑↑↑↑↑↑↑ ↑↑ ↑ ↑↑↑ * ↑↑↑ ↑ ↑↑ ↑↑↑↑ ↑↑↑↑↑↑↑↑↑ ↑↑ ↑ ↑↑↑ * ↑↑↑ ↑ ↑↑ ↑↑↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑ ↑ ↑↑↑ * ↑↑↑ ↑ ↑↑↑↑ ↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑ ↑ ↑↑ * ↑↑↑ ↑ ↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑ ↑↑↑ ↑↑↑ ↑ ↑↑↑ * ↑↑↑ ↑↑ ↑↑ ↑↑↑↑ ↑↑↑↑↑↑ ↑↑ ↑↑↑ ↑ ↑↑ ↑↑↑↑ ↑ ↑↑ * ↑↑↑ ↑ ↑ ↑ ↑ ↑↑ ↑ ↑ ↑↑ ↑↑↑↑ ↑↑ ↑↑↑ * ↑↑ ↑ ↑↑ ↑ ↑ ↑ ↑↑ ↑↑ ↑↑ ↑↑ ↑↑ ↑↑↑ ↑ ↑↑ * ↑↑↑ ↑ ↑ ↑ ↑↑ ↑↑ ↑↑ ↑↑↑↑ ↑↑ ↑↑↑↑↑↑↑ ↑↑↑ ↑ ↑↑↑ * ↑↑↑ ↑ ↑ ↑ ↑↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑ ↑↑↑ * ↑↑ ↑↑ ↑ ↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑ ↑↑ * ↑↑ ↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑ ↑↑↑↑↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑ * ↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑ ↑↑ ↑↑ ↑↑ ↑↑ * ↑↑ ↑↑ ↑↑ ↑↑↑↑↑ ↑↑ ↑↑ ↑ ↑↑ * ↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑ ↑ ↑↑ * ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑ ↑↑ * ↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑ ↑↑↑ * ↑↑↑ ↑ ↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑ * ↑↑↑ ↑ ↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑ * ↑↑↑ ↑ ↑ ↑↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑↑ * ↑↑↑ ↑↑ ↑ ↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑↑↑ * ↑↑↑ ↑ ↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑ ↑↑ ↑ ↑↑ * ↑↑↑↑ ↑ ↑ ↑↑↑↑ ↑↑↑↑ ↑↑ ↑↑↑ ↑ ↑↑↑ * ↑↑↑↑ ↑ ↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑↑↑ * ↑↑↑↑ ↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑↑ * ↑↑↑ ↑ ↑↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑↑↑ * ↑↑↑↑ ↑ ↑↑↑↑ ↑↑↑ ↑↑ ↑↑↑↑↑ * ↑↑↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑↑ * ↑↑↑ ↑↑ ↑↑ ↑↑ ↑↑↑ * ↑↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑↑↑ * ↑↑↑↑↑ ↑↑↑ ↑ ↑↑ ↑↑↑↑↑ * ↑↑↑↑↑↑ ↑↑↑ ↑ ↑ ↑↑ ↑ ↑↑↑↑↑↑ * ↑↑↑↑↑↑ ↑↑↑ ↑ ↑↑ ↑↑ ↑↑↑↑↑↑ * ↑↑↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑↑ * ↑↑↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑ * ↑↑↑↑↑↑↑ ↑↑ ↑↑↑↑↑ ↑↑ ↑↑ ↑↑↑↑ ↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑ ↑ ↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑ ↑ ↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ * */ /** * @title Lizcoin ERC20 * * @notice The ERC-20 token Lizcoin is the governance token for the Gaming Sub-DAO of Lizard Labs. * While the studio focuses on immersive, interconnected gaming experiences, the token is primarily used for * yield farming and revenue distribution for active participants, protocol governance, and liquidity staking. * * @notice Token Summary: * - Symbol: LIZ * - Name: Lizcoin * - Decimals: 18 * - Initial total supply: 9B (1B to be minted as staking rewards) * - Final total supply: 10B (not enforced by the token contract) * - Initial supply holder (initial holder) address: 0xC93c904fFE3d55E15483eF37e38ECAF8Fe003Ba7 * - Mintability: configurable (initially enabled, but possible to revoke forever) * - Burnability: configurable (initially enabled, but possible to revoke forever) * - DAO Support: supports voting delegation * * @notice Features Summary: * - Supports atomic allowance modification, resolves well-known ERC20 issue with approve (arXiv:1907.00903) * - Voting delegation and delegation on behalf via EIP-712 (like in Compound CMP token) - gives the token * powerful governance capabilities by allowing holders to form voting groups by electing delegates * - Unlimited approval feature (like in 0x ZRX token) - saves gas for transfers on behalf * by eliminating the need to update “unlimited” allowance value * - ERC-1363 Payable Token - ERC721-like callback execution mechanism for transfers, * transfers on behalf and approvals; allows creation of smart contracts capable of executing callbacks * in response to transfer or approval in a single transaction * - EIP-2612: permit - 712-signed approvals - improves user experience by allowing to use a token * without having an ETH to pay gas fees * - EIP-3009: Transfer With Authorization - improves user experience by allowing to use a token * without having an ETH to pay gas fees * * @dev Based on the https://github.com/lazy-sol/advanced-erc20 implementation * * @author Lizard Labs Core Contributors */ contract LizcoinERC20 is AdvancedERC20 { \t/** \t * @dev Deploys the token smart contract, \t * sets token name, symbol, initial token supply \t * \t * @param _initialHolder initial holder of the token supply \t */ \tconstructor(address _initialHolder) AdvancedERC20 ( \t\tmsg.sender, // _contractOwner smart contract owner (has minting/burning and all other permissions) \t\t"Lizcoin", // _name token name to set \t\t"LIZ", // _symbol token symbol to set \t\t_initialHolder, // _initialHolder owner of the initial token supply \t\t// 9 bil + 15 mil + 16'358'635 + 147'227'717 \t\t9_178_586_352 ether, // _initialSupply initial token supply (9.18 bil) \t\t0xFFFF // _initialFeatures RBAC features enabled initially \t) {} }