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

EVMAuth1155

Git Source

Inherits: ERC1155URIStorageUpgradeable, EVMAuth

Author: EVMAuth

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

Extends ERC-1155 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 EVMAuth1155 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_stringBase URI for all token types per EIP-1155 metadata standard

__EVMAuth1155_init

Internal initializer that sets up all parent contracts.

Calls parent initializers in correct order for upgradeable contracts.

function __EVMAuth1155_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_stringBase URI for all token types per EIP-1155 metadata standard

__EVMAuth1155_init_unchained

Unchained initializer for contract-specific storage.

Currently empty but reserved for future EVMAuth1155-specific initialization.

function __EVMAuth1155_init_unchained() internal onlyInitializing;

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(ERC1155Upgradeable, AccessControlDefaultAdminRulesUpgradeable)
    returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

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

uri

*See {IERC1155MetadataURI-uri}. This implementation returns the concatenation of the _baseURI and the token-specific uri if the latter is set This enables the following behaviors:

  • if _tokenURIs[tokenId] is set, then the result is the concatenation of _baseURI and _tokenURIs[tokenId] (keep in mind that _baseURI is empty per default);
  • if _tokenURIs[tokenId] is NOT set then we fallback to super.uri() which in most cases will contain ERC1155._uri;
  • if _tokenURIs[tokenId] is NOT set, and if the parents do not have a uri value set, then the result is empty.*
function uri(uint256 tokenId) public view virtual override returns (string memory);

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(ERC1155Upgradeable, 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, bytes memory data) external onlyRole(MINTER_ROLE);

Parameters

NameTypeDescription
toaddressRecipient address for minted tokens
iduint256Token type identifier to mint
amountuint256Quantity of tokens to mint
databytesAdditional data passed to receiver contract if applicable

mintBatch

Batch mints multiple token types to a single account.

Restricted to addresses with MINTER_ROLE. Arrays must have matching lengths.

function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
    external
    onlyRole(MINTER_ROLE);

Parameters

NameTypeDescription
toaddressRecipient address for minted tokens
idsuint256[]Array of token type identifiers to mint
amountsuint256[]Array of quantities to mint for each token type
databytesAdditional data passed to receiver contract if applicable

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

burnBatch

Batch burns multiple token types from a single account.

Restricted to addresses with BURNER_ROLE. Arrays must have matching lengths.

function burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) external onlyRole(BURNER_ROLE);

Parameters

NameTypeDescription
fromaddressAddress to burn tokens from
idsuint256[]Array of token type identifiers to burn
amountsuint256[]Array of quantities to burn for each token type

setBaseURI

Updates the base URI for all token metadata.

Restricted to addresses with TOKEN_MANAGER_ROLE.

function setBaseURI(string memory baseURI) external virtual onlyRole(TOKEN_MANAGER_ROLE);

Parameters

NameTypeDescription
baseURIstringNew base URI for token metadata

setTokenURI

Updates the metadata URI for a specific token type.

Restricted to addresses with TOKEN_MANAGER_ROLE. Overrides base URI for this token.

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

Parameters

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

_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, token existence, and transferability rules. Recipient contracts must implement IERC1155Receiver.

Notes:

  • throws: InvalidSelfTransfer When from equals to

  • throws: InvalidZeroValueTransfer When any value is zero

function _update(address from, address to, uint256[] memory ids, uint256[] memory values)
    internal
    virtual
    override
    whenNotPaused
    notFrozen(from)
    notFrozen(to)
    allTokensExist(ids)
    allTokensTransferable(from, to, ids);

Parameters

NameTypeDescription
fromaddressSource address (zero address for minting)
toaddressDestination address (zero address for burning)
idsuint256[]Array of token type identifiers
valuesuint256[]Array of quantities to transfer