EVMAuth
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
Name | Type | Description |
---|---|---|
initialDelay | uint48 | Security delay for admin role transfers |
initialDefaultAdmin | address | Initial admin address |
initialTreasury | address payable | Treasury address for revenue collection |
roleGrants | RoleGrant[] | 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
Name | Type | Description |
---|---|---|
roleGrants | RoleGrant[] | 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier |
Returns
Name | Type | Description |
---|---|---|
<none> | EVMAuthToken | Complete 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Native 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier |
Returns
Name | Type | Description |
---|---|---|
<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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | TTL 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True 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
Name | Type | Description |
---|---|---|
config | EVMAuthTokenConfig | Complete configuration for the new token type |
Returns
Name | Type | Description |
---|---|---|
id | uint256 | Newly 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier to update |
config | EVMAuthTokenConfig | New 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
Name | Type | Description |
---|---|---|
newTreasury | address payable | The 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
Name | Type | Description |
---|---|---|
config | EVMAuthTokenConfig | Complete configuration for new token type |
Returns
Name | Type | Description |
---|---|---|
id | uint256 | Newly 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier (must exist) |
config | EVMAuthTokenConfig | New 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
Name | Type | Description |
---|---|---|
id | uint256 | Token type identifier |
config | EVMAuthTokenConfig | New configuration settings |
Errors
InvalidSelfTransfer
Error for self-transfer attempts.
error InvalidSelfTransfer(address sender);
Parameters
Name | Type | Description |
---|---|---|
sender | address | Address 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
Name | Type | Description |
---|---|---|
price | uint256 | Native currency price for purchasing this token |
erc20Prices | PaymentToken[] | Array of accepted ERC-20 tokens and their prices |
ttl | uint256 | Time-to-live in seconds (0 for permanent tokens) |
transferable | bool | Whether token can be transferred between accounts |
EVMAuthToken
Complete token type information including ID and configuration.
struct EVMAuthToken {
uint256 id;
EVMAuthTokenConfig config;
}
Properties
Name | Type | Description |
---|---|---|
id | uint256 | Unique identifier for the token type |
config | EVMAuthTokenConfig | Full configuration settings for the token |
RoleGrant
Structure for role assignment during initialization.
struct RoleGrant {
bytes32 role;
address account;
}
Properties
Name | Type | Description |
---|---|---|
role | bytes32 | The role being granted |
account | address | The account receiving the role |