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

EVMAuth

Git Source

Inherits: TokenAccessControl, TokenEnumerable, TokenEphemeral, TokenPurchasable, TokenTransferable, UUPSUpgradeable

Author: EVMAuth

Core abstract contract for EVM-based authentication tokens.

Combines access control, sequential token IDs, token expiry, direct purchasing, and token transfer. restriction into a unified token management system. Implements UUPS upgradeable pattern.

Functions

__EVMAuth_init

Internal initializer for EVMAuth contract setup.

Initializes all parent contracts in correct order.

function __EVMAuth_init(
    uint48 initialDelay,
    address initialDefaultAdmin,
    address payable initialTreasury,
    RoleGrant[] calldata roleGrants
) internal onlyInitializing;

Parameters

NameTypeDescription
initialDelayuint48Security delay for admin role transfers
initialDefaultAdminaddressInitial admin address
initialTreasuryaddress payableTreasury address for revenue collection
roleGrantsRoleGrant[]Array of initial role assignments

__EVMAuth_init_unchained

Unchained initializer for contract-specific storage.

Currently empty but reserved for future EVMAuth-specific initialization.

function __EVMAuth_init_unchained(RoleGrant[] calldata roleGrants) internal onlyInitializing;

Parameters

NameTypeDescription
roleGrantsRoleGrant[]Array of initial role assignments

tokenConfig

Retrieves complete configuration for a token type.

Aggregates settings from all parent contracts.

function tokenConfig(uint256 id) public view virtual tokenExists(id) returns (EVMAuthToken memory);

Parameters

NameTypeDescription
iduint256Token type identifier

Returns

NameTypeDescription
<none>EVMAuthTokenComplete token configuration with ID

tokenPrice

Gets native currency price for a token type.

Overrides TokenPurchasable with existence check.

function tokenPrice(uint256 id) public view virtual override tokenExists(id) returns (uint256);

Parameters

NameTypeDescription
iduint256Token type identifier

Returns

NameTypeDescription
<none>uint256Native currency price (wei for ETH chains)

tokenERC20Prices

Gets all accepted ERC-20 payment options.

Returns array of payment token addresses and prices.

function tokenERC20Prices(uint256 id) public view virtual override tokenExists(id) returns (PaymentToken[] memory);

Parameters

NameTypeDescription
iduint256Token type identifier

Returns

NameTypeDescription
<none>PaymentToken[]Array of PaymentToken structs

tokenTTL

Gets time-to-live for a token type.

0 indicates permanent tokens.

function tokenTTL(uint256 id) public view virtual override tokenExists(id) returns (uint256);

Parameters

NameTypeDescription
iduint256Token type identifier

Returns

NameTypeDescription
<none>uint256TTL in seconds

isTransferable

Checks if token type allows transfers.

Non-transferable tokens are soulbound to original recipient.

function isTransferable(uint256 id) public view virtual override tokenExists(id) returns (bool);

Parameters

NameTypeDescription
iduint256Token type identifier

Returns

NameTypeDescription
<none>boolTrue if transferable, false if soulbound

createToken

Creates a new token type with specified configuration.

Restricted to TOKEN_MANAGER_ROLE. Claims next sequential ID.

Note: emits: EVMAuthTokenConfigured

function createToken(EVMAuthTokenConfig calldata config)
    external
    virtual
    onlyRole(TOKEN_MANAGER_ROLE)
    returns (uint256 id);

Parameters

NameTypeDescription
configEVMAuthTokenConfigComplete configuration for the new token type

Returns

NameTypeDescription
iduint256Newly created token type identifier

updateToken

Updates complete configuration for an existing token type.

Restricted to TOKEN_MANAGER_ROLE. Token must exist.

Note: emits: EVMAuthTokenConfigured

function updateToken(uint256 id, EVMAuthTokenConfig calldata config) external virtual onlyRole(TOKEN_MANAGER_ROLE);

Parameters

NameTypeDescription
iduint256Token type identifier to update
configEVMAuthTokenConfigNew complete configuration

setTreasury

Updates the treasury address where purchase revenues are sent.

Restricted to addresses with TREASURER_ROLE.

function setTreasury(address payable newTreasury) external onlyRole(TREASURER_ROLE);

Parameters

NameTypeDescription
newTreasuryaddress payableThe new treasury address

_createToken

Internal function to create a new token type.

Claims next sequential ID and applies configuration.

Note: emits: EVMAuthTokenConfigured

function _createToken(EVMAuthTokenConfig calldata config) internal virtual returns (uint256 id);

Parameters

NameTypeDescription
configEVMAuthTokenConfigComplete configuration for new token type

Returns

NameTypeDescription
iduint256Newly created token type identifier

_updateToken

Internal function to update token configuration.

Updates all configuration parameters atomically.

Note: emits: EVMAuthTokenConfigured

function _updateToken(uint256 id, EVMAuthTokenConfig calldata config) internal virtual tokenExists(id);

Parameters

NameTypeDescription
iduint256Token type identifier (must exist)
configEVMAuthTokenConfigNew complete configuration

_authorizeUpgrade

*Function that should revert when msg.sender is not authorized to upgrade the contract. Called by {upgradeToAndCall}. Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.

function _authorizeUpgrade(address) internal onlyOwner {}
```*


```solidity
function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(UPGRADE_MANAGER_ROLE);

Events

EVMAuthTokenConfigured

Emitted when a token type is created or reconfigured.

event EVMAuthTokenConfigured(uint256 indexed id, EVMAuthTokenConfig config);

Parameters

NameTypeDescription
iduint256Token type identifier
configEVMAuthTokenConfigNew configuration settings

Errors

InvalidSelfTransfer

Error for self-transfer attempts.

error InvalidSelfTransfer(address sender);

Parameters

NameTypeDescription
senderaddressAddress attempting self-transfer

InvalidZeroValueTransfer

Error for zero-amount transfer attempts.

error InvalidZeroValueTransfer();

Structs

EVMAuthTokenConfig

Configuration parameters for a token type.

struct EVMAuthTokenConfig {
    uint256 price;
    PaymentToken[] erc20Prices;
    uint256 ttl;
    bool transferable;
}

Properties

NameTypeDescription
priceuint256Native currency price for purchasing this token
erc20PricesPaymentToken[]Array of accepted ERC-20 tokens and their prices
ttluint256Time-to-live in seconds (0 for permanent tokens)
transferableboolWhether token can be transferred between accounts

EVMAuthToken

Complete token type information including ID and configuration.

struct EVMAuthToken {
    uint256 id;
    EVMAuthTokenConfig config;
}

Properties

NameTypeDescription
iduint256Unique identifier for the token type
configEVMAuthTokenConfigFull configuration settings for the token

RoleGrant

Structure for role assignment during initialization.

struct RoleGrant {
    bytes32 role;
    address account;
}

Properties

NameTypeDescription
rolebytes32The role being granted
accountaddressThe account receiving the role