Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

EVMAuth6909

Git Source

Inherits: ERC6909MetadataUpgradeable, ERC6909ContentURIUpgradeable, EVMAuth

Author: EVMAuth

Multi-token authentication contract implementing ERC-6909 with time-based access control.

Extends ERC-6909 with authorization features including time-to-live tokens, role-based access, and configurable purchasing mechanisms. Implements UUPS upgradeable pattern for future enhancements.

Functions

initialize

Initializes the EVMAuth6909 contract with admin and treasury configuration.

Initializer used when deployed directly as an upgradeable contract.

function initialize(
    uint48 initialDelay,
    address initialDefaultAdmin,
    address payable initialTreasury,
    RoleGrant[] calldata roleGrants,
    string memory uri_
) public virtual initializer;

Parameters

NameTypeDescription
initialDelayuint48Delay in seconds before a new default admin can exercise their role
initialDefaultAdminaddressAddress to be granted the initial default admin role
initialTreasuryaddress payableAddress where purchase revenues will be sent
roleGrantsRoleGrant[]Array of initial role assignments
uri_stringContract URI per EIP-6909 content URI extension

__EVMAuth6909_init

Internal initializer that sets up all parent contracts.

Calls parent initializers in correct order for upgradeable contracts.

function __EVMAuth6909_init(
    uint48 initialDelay,
    address initialDefaultAdmin,
    address payable initialTreasury,
    RoleGrant[] calldata roleGrants,
    string memory uri_
) internal onlyInitializing;

Parameters

NameTypeDescription
initialDelayuint48Delay in seconds before a new default admin can exercise their role
initialDefaultAdminaddressAddress to be granted the initial default admin role
initialTreasuryaddress payableAddress where purchase revenues will be sent
roleGrantsRoleGrant[]Array of initial role assignments
uri_stringContract URI per EIP-6909 content URI extension

__EVMAuth6909_init_unchained

Unchained initializer for contract-specific storage.

Sets the contract URI for ERC-6909 content URI support.

function __EVMAuth6909_init_unchained(string memory uri_) internal onlyInitializing;

Parameters

NameTypeDescription
uri_stringContract URI per EIP-6909 content URI extension

supportsInterface

Query if a contract implements an interface

Interface identification is specified in ERC-165. This function uses less than 30,000 gas.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC6909Upgradeable, AccessControlDefaultAdminRulesUpgradeable, IERC165)
    returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<none>booltrue if the contract implements interfaceID and interfaceID is not 0xffffffff, false otherwise

balanceOf

Gets current balance excluding expired tokens.

Iterates through balance records and sums non-expired amounts.

function balanceOf(address account, uint256 id)
    public
    view
    virtual
    override(ERC6909Upgradeable, IERC6909, TokenEphemeral)
    returns (uint256);

Parameters

NameTypeDescription
accountaddressAddress to check balance for
iduint256Token type identifier

Returns

NameTypeDescription
<none>uint256Total non-expired balance

mint

Mints new tokens of a specific type to an account.

Restricted to addresses with MINTER_ROLE.

function mint(address to, uint256 id, uint256 amount) external onlyRole(MINTER_ROLE);

Parameters

NameTypeDescription
toaddressRecipient address for minted tokens
iduint256Token type identifier to mint
amountuint256Quantity of tokens to mint

burn

Burns tokens of a specific type from an account.

Restricted to addresses with BURNER_ROLE.

function burn(address from, uint256 id, uint256 amount) external onlyRole(BURNER_ROLE);

Parameters

NameTypeDescription
fromaddressAddress to burn tokens from
iduint256Token type identifier to burn
amountuint256Quantity of tokens to burn

setContractURI

Updates the contract-level metadata URI.

Restricted to addresses with TOKEN_MANAGER_ROLE.

function setContractURI(string memory contractURI) external virtual onlyRole(TOKEN_MANAGER_ROLE);

Parameters

NameTypeDescription
contractURIstringNew contract metadata URI

setTokenURI

Updates the metadata URI for a specific token type.

Restricted to addresses with TOKEN_MANAGER_ROLE.

function setTokenURI(uint256 id, string memory contentURI) external virtual onlyRole(TOKEN_MANAGER_ROLE);

Parameters

NameTypeDescription
iduint256Token type identifier to update
contentURIstringNew metadata URI for this token type

setTokenMetadata

Updates the on-chain metadata for a specific token type.

Restricted to addresses with TOKEN_MANAGER_ROLE. Sets name, symbol, and decimals.

function setTokenMetadata(uint256 id, string memory name, string memory symbol, uint8 decimals)
    external
    virtual
    onlyRole(TOKEN_MANAGER_ROLE);

Parameters

NameTypeDescription
iduint256Token type identifier to update
namestringDisplay name for the token type
symbolstringTrading symbol for the token type
decimalsuint8Number of decimal places for token amounts

_burnPrunedTokens

Internal hook to handle burning of pruned tokens.

Override this function to integrate with the token standard's burn mechanism. Called automatically during pruning if expired tokens are found.

function _burnPrunedTokens(address account, uint256 id, uint256 amount) internal virtual override;

Parameters

NameTypeDescription
accountaddressAddress from which tokens were pruned
iduint256Token type identifier
amountuint256Quantity of tokens that were pruned (expired)

_mintPurchasedTokens

Abstract function to mint purchased tokens.

Must be implemented by inheriting contracts.

function _mintPurchasedTokens(address to, uint256 id, uint256 amount) internal virtual override;

Parameters

NameTypeDescription
toaddressAddress to receive minted tokens
iduint256Token type identifier
amountuint256Quantity to mint

_update

Internal function handling token transfers, mints, and burns.

Enforces pause state and validates transfers. No receiver callbacks in ERC-6909.

Notes:

  • throws: InvalidSelfTransfer When from equals to

  • throws: InvalidZeroValueTransfer When amount is zero

function _update(address from, address to, uint256 id, uint256 amount)
    internal
    virtual
    override
    whenNotPaused
    notFrozen(from)
    notFrozen(to)
    tokenExists(id)
    tokenTransferable(from, to, id);

Parameters

NameTypeDescription
fromaddressSource address (zero address for minting)
toaddressDestination address (zero address for burning)
iduint256Token type identifier
amountuint256Quantity to transfer