EVMAuth1155
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
Name | Type | Description |
---|---|---|
initialDelay | uint48 | Delay in seconds before a new default admin can exercise their role |
initialDefaultAdmin | address | Address to be granted the initial default admin role |
initialTreasury | address payable | Address where purchase revenues will be sent |
roleGrants | RoleGrant[] | Array of initial role assignments |
uri_ | string | Base 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
Name | Type | Description |
---|---|---|
initialDelay | uint48 | Delay in seconds before a new default admin can exercise their role |
initialDefaultAdmin | address | Address to be granted the initial default admin role |
initialTreasury | address payable | Address where purchase revenues will be sent |
roleGrants | RoleGrant[] | Array of initial role assignments |
uri_ | string | Base 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
Name | Type | Description |
---|---|---|
interfaceId | bytes4 |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | true 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 tosuper.uri()
which in most cases will containERC1155._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
Name | Type | Description |
---|---|---|
account | address | Address to check balance for |
id | uint256 | Token type identifier |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Total 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
Name | Type | Description |
---|---|---|
to | address | Recipient address for minted tokens |
id | uint256 | Token type identifier to mint |
amount | uint256 | Quantity of tokens to mint |
data | bytes | Additional 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
Name | Type | Description |
---|---|---|
to | address | Recipient address for minted tokens |
ids | uint256[] | Array of token type identifiers to mint |
amounts | uint256[] | Array of quantities to mint for each token type |
data | bytes | Additional 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
Name | Type | Description |
---|---|---|
from | address | Address to burn tokens from |
id | uint256 | Token type identifier to burn |
amount | uint256 | Quantity 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
Name | Type | Description |
---|---|---|
from | address | Address to burn tokens from |
ids | uint256[] | Array of token type identifiers to burn |
amounts | uint256[] | 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
Name | Type | Description |
---|---|---|
baseURI | string | New 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier to update |
tokenURI | string | New 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
Name | Type | Description |
---|---|---|
account | address | Address from which tokens were pruned |
id | uint256 | Token type identifier |
amount | uint256 | Quantity 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
Name | Type | Description |
---|---|---|
to | address | Address to receive minted tokens |
id | uint256 | Token type identifier |
amount | uint256 | Quantity 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
Name | Type | Description |
---|---|---|
from | address | Source address (zero address for minting) |
to | address | Destination address (zero address for burning) |
ids | uint256[] | Array of token type identifiers |
values | uint256[] | Array of quantities to transfer |