XMTP Contracts
⚠️ Experimental: This software is in early development. Expect frequent changes and unresolved issues.
This repository contains all the smart contracts that underpin the XMTP decentralized network.
Usage
The project is built with the Foundry framework, and dependency management is handled using native git submodules.
Additionally, it uses slither for static analysis.
Prerequisites
Optionally, install yarn or any other preferred JS package manager.
Initialize project
Initialize the project dependencies:
yarn install # if using yarn
Initialize foundry:
forge update
Developer tools
The following can be run using npm, yarn and similar JS package managers.
# Forge scripts
build: Builds the contracts.
test: Tests the contracts.
clean: Cleans the forge environment.
coverage: Shows the test coverage.
gas-report: Shows the gas costs.
doc: Serves the project documentation at http://localhost:4000
# Static analysis
slither: Runs slither static analysis.
# Linters
solhint: Runs solhint.
solhint-fix: Runs solhint in fix mode, potentially modifying files.
lint-staged: Runs linters only on files that are staged in git.
# Formatters
prettier: Runs prettier in write mode, potentially modifying files.
prettier-check: Runs prettier in check mode.
Developer documentation
The Foundry book can be found hosted on the contracts documentation page.
To dive deeper into the protocol and its architecture, read the architecture documentation.
Contents
Contents
IERC1967
Functions
implementation
Returns the address of the current implementation.
function implementation() external view returns (address implementation_);
Events
Upgraded
Emitted when the implementation is upgraded.
event Upgraded(address indexed implementation);
Parameters
| Name | Type | Description |
|---|---|---|
implementation | address | The address of the new implementation. |
IERC5267
Inherits: IERC712
The interface as defined by EIP-5267: https://eips.ethereum.org/EIPS/eip-5267
Functions
eip712Domain
Returns the fields and values that describe the domain separator used by this contract for EIP-712.
function eip712Domain()
external
view
returns (
bytes1 fields_,
string memory name_,
string memory version_,
uint256 chainId_,
address verifyingContract_,
bytes32 salt_,
uint256[] memory extensions_
);
Returns
| Name | Type | Description |
|---|---|---|
fields_ | bytes1 | A bit map where bit i is set to 1 if and only if domain field i is present (0 ≤ i ≤ 4). Bits are read from least significant to most significant, and fields are indexed in the order that is specified by EIP-712, identical to the order in which they are listed (i.e. name, version, chainId, verifyingContract, and salt). |
name_ | string | The user readable name of signing domain. |
version_ | string | The current major version of the signing domain. |
chainId_ | uint256 | The EIP-155 chain ID. |
verifyingContract_ | address | The address of the contract that will verify the signature. |
salt_ | bytes32 | A disambiguating salt for the protocol. |
extensions_ | uint256[] | A list of EIP numbers, each of which MUST refer to an EIP that extends EIP-712 with new domain fields, along with a method to obtain the value for those fields, and potentially conditions for inclusion. The values of those fields do not affect whether they are included. |
Events
EIP712DomainChanged
MAY be emitted to signal that the domain could have changed.
event EIP712DomainChanged();
IERC712
The interface as defined by EIP-712: https://eips.ethereum.org/EIPS/eip-712
Functions
DOMAIN_SEPARATOR
Returns the EIP712 domain separator used in the encoding of a signed digest.
function DOMAIN_SEPARATOR() external view returns (bytes32 domainSeparator_);
IMigratable
Inherits: IERC1967
Unlike a simple upgrade, a migration is defined as:
- Logic to determine the migration flow based on any conditions, and/or
- Logic to determine the implementation to upgrade to, and/or
- Logic to determine if the upgrade or migration should occur, and/or
- State changes to the proxy storage, and/or
- Setting the proxy's implementation slot. All the above can be kicked off by anyone, and without parameters, which is useful in governance models.
Functions
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
Events
Migrated
Emitted when the implementation is migrated.
The migrator contains fixed arbitrary code to manipulate storage, including the implementation slot.
event Migrated(address indexed migrator);
Parameters
| Name | Type | Description |
|---|---|---|
migrator | address | The address of the migrator, which the proxy has delegatecalled to perform the migration. |
Errors
ZeroMigrator
Thrown when the migrator being delegatecalled is zero (i.e. address(0)).
error ZeroMigrator();
MigrationFailed
Thrown when the migration fails (i.e. the delegatecall to the migrator reverts).
error MigrationFailed(address migrator_, bytes revertData_);
Parameters
| Name | Type | Description |
|---|---|---|
migrator_ | address | The address of the migrator, which the proxy has delegatecalled to perform the migration. |
revertData_ | bytes | The revert data from the migration. |
EmptyCode
Thrown when the migrator is empty (i.e. has no code).
error EmptyCode(address migrator_);
Parameters
| Name | Type | Description |
|---|---|---|
migrator_ | address | The address of the migrator, which the proxy has delegatecalled to perform the migration. |
IParameterRegistry
Inherits: IMigratable, IParameterKeysErrors, IRegistryParametersErrors
A parameter registry allows admins to set parameters, including whether an account is an admin, and allows any account/contract to query the values of parameters.
Functions
initialize
Initializes the parameter registry, as used by a proxy contract.
Whether an account is an admin is tracked as a key-value pair in the registry itself.
function initialize(address[] calldata admins_) external;
Parameters
| Name | Type | Description |
|---|---|---|
admins_ | address[] | The addresses of the admins that can set parameters. |
set
Sets several parameters.
The length of the keys_ and values_ arrays must be the same.
The caller must be an admin.
function set(string[] calldata keys_, bytes32[] calldata values_) external;
Parameters
| Name | Type | Description |
|---|---|---|
keys_ | string[] | The keys of each parameter to set. |
values_ | bytes32[] | The values of each parameter. |
set
Sets a parameter.
The caller must be an admin.
function set(string calldata key_, bytes32 value_) external;
Parameters
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the parameter to set. |
value_ | bytes32 | The value of the parameter. |
isAdmin
Returns whether an account is an admin (i.e. an account that can set parameters).
function isAdmin(address account_) external view returns (bool isAdmin_);
Parameters
| Name | Type | Description |
|---|---|---|
account_ | address | The address of the account to check. |
Returns
| Name | Type | Description |
|---|---|---|
isAdmin_ | bool | True if the account is an admin, false otherwise. |
get
Gets the values of several parameters.
The default value for each parameter is bytes32(0).
function get(string[] calldata keys_) external view returns (bytes32[] memory values_);
Parameters
| Name | Type | Description |
|---|---|---|
keys_ | string[] | The keys of each parameter to get. |
Returns
| Name | Type | Description |
|---|---|---|
values_ | bytes32[] | The values of each parameter. |
get
Gets the value of a parameter.
The default value for a parameter is bytes32(0).
function get(string calldata key_) external view returns (bytes32 value_);
Parameters
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the parameter to get. |
Returns
| Name | Type | Description |
|---|---|---|
value_ | bytes32 | The value of the parameter. |
migratorParameterKey
The parameter registry key used to fetch the migrator.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function migratorParameterKey() external pure returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the migrator parameter. |
adminParameterKey
The parameter registry key used to fetch the status of an admin.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function adminParameterKey() external pure returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the admin parameter, which is a component of the full key, when prefixing an address. |
Events
ParameterSet
Emitted when a parameter is set.
Values that are not value types (e.g. bytes, arrays, structs, etc.) must be the hash of their contents.
When passing the key as the first argument when emitting this event, it is automatically hashed since reference types are not indexable, and the hash is thus the indexable value.
event ParameterSet(string indexed keyHash, string key, bytes32 value);
Parameters
| Name | Type | Description |
|---|---|---|
keyHash | string | The hash of the key of the parameter. |
key | string | The key of the parameter (which is generally a human-readable string, for clarity). |
value | bytes32 | The value of the parameter (which can represent any value type). |
Errors
NotAdmin
Thrown when the caller is not an admin (e.g. when setting a parameter).
error NotAdmin();
NoKeys
Thrown when no keys are provided (e.g. when setting or getting parameters).
error NoKeys();
ArrayLengthMismatch
Thrown when the array length mismatch (e.g. when setting multiple parameters).
error ArrayLengthMismatch();
EmptyAdmins
Thrown when the array of admins is empty.
error EmptyAdmins();
ZeroAdmin
Thrown when an admin is the zero address.
error ZeroAdmin();
IPayloadBroadcaster
Inherits: IMigratable, IRegistryParametersErrors
A payload broadcaster is a contract that broadcasts payloads as events, where payloads have a min and max size, both of which can be updated from a parameter registry.
Functions
initialize
Initializes the contract.
function initialize() external;
updateMinPayloadSize
Updates the minimum payload size.
Ensures the new minimum is less than the maximum.
Ensures the new minimum is not equal to the old minimum.
function updateMinPayloadSize() external;
updateMaxPayloadSize
Updates the maximum payload size.
Ensures the new maximum is greater than the minimum.
Ensures the new maximum is not equal to the old maximum.
function updateMaxPayloadSize() external;
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
updatePayloadBootstrapper
Updates the payload bootstrapper.
Ensures the new payload bootstrapper is not equal to the old payload bootstrapper.
function updatePayloadBootstrapper() external;
minPayloadSizeParameterKey
The parameter registry key used to fetch the minimum payload size.
function minPayloadSizeParameterKey() external pure returns (string memory key_);
maxPayloadSizeParameterKey
The parameter registry key used to fetch the maximum payload size.
function maxPayloadSizeParameterKey() external pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() external pure returns (string memory key_);
payloadBootstrapperParameterKey
The parameter registry key used to fetch the payload bootstrapper.
function payloadBootstrapperParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
minPayloadSize
Minimum valid payload size (in bytes).
function minPayloadSize() external view returns (uint32 size_);
maxPayloadSize
Maximum valid payload size (in bytes).
function maxPayloadSize() external view returns (uint32 size_);
paused
The pause status.
function paused() external view returns (bool paused_);
payloadBootstrapper
The payload bootstrapper.
function payloadBootstrapper() external view returns (address payloadBootstrapper_);
Events
MinPayloadSizeUpdated
Emitted when the minimum payload size is updated.
Will not be emitted if the new minimum is equal to the old minimum.
event MinPayloadSizeUpdated(uint256 indexed size);
Parameters
| Name | Type | Description |
|---|---|---|
size | uint256 | The new minimum payload size. |
MaxPayloadSizeUpdated
Emitted when the maximum payload size is updated.
Will not be emitted if the new maximum is equal to the old maximum.
event MaxPayloadSizeUpdated(uint256 indexed size);
Parameters
| Name | Type | Description |
|---|---|---|
size | uint256 | The new maximum payload size. |
PauseStatusUpdated
Emitted when the pause status is updated.
event PauseStatusUpdated(bool indexed paused);
Parameters
| Name | Type | Description |
|---|---|---|
paused | bool | The new pause status. |
PayloadBootstrapperUpdated
Emitted when the payload bootstrapper is updated.
event PayloadBootstrapperUpdated(address indexed payloadBootstrapper);
Parameters
| Name | Type | Description |
|---|---|---|
payloadBootstrapper | address | The new payload bootstrapper. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is zero (i.e. address(0)).
error ZeroParameterRegistry();
InvalidPayloadSize
Thrown when the payload size is invalid.
error InvalidPayloadSize(uint256 actualSize_, uint256 minSize_, uint256 maxSize_);
InvalidMaxPayloadSize
Thrown when the maximum payload size is invalid.
error InvalidMaxPayloadSize();
InvalidMinPayloadSize
Thrown when the minimum payload size is invalid.
error InvalidMinPayloadSize();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
Paused
Thrown when any pausable function is called when the contract is paused.
error Paused();
NotPaused
Thrown when any pause-mode-only function is called when the payload broadcaster is not paused.
error NotPaused();
NotPayloadBootstrapper
Thrown when the payload bootstrapper is not the caller.
error NotPayloadBootstrapper();
ERC5267
Functions
constructor
Constructs the contract.
constructor() ERC712();
_initializeERC5267
function _initializeERC5267() internal;
eip712Domain
Returns the fields and values that describe the domain separator used by this contract for EIP-712.
function eip712Domain()
external
view
returns (
bytes1 fields_,
string memory name_,
string memory version_,
uint256 chainId_,
address verifyingContract_,
bytes32 salt_,
uint256[] memory extensions_
);
Returns
| Name | Type | Description |
|---|---|---|
fields_ | bytes1 | A bit map where bit i is set to 1 if and only if domain field i is present (0 ≤ i ≤ 4). Bits are read from least significant to most significant, and fields are indexed in the order that is specified by EIP-712, identical to the order in which they are listed (i.e. name, version, chainId, verifyingContract, and salt). |
name_ | string | The user readable name of signing domain. |
version_ | string | The current major version of the signing domain. |
chainId_ | uint256 | The EIP-155 chain ID. |
verifyingContract_ | address | The address of the contract that will verify the signature. |
salt_ | bytes32 | A disambiguating salt for the protocol. |
extensions_ | uint256[] | A list of EIP numbers, each of which MUST refer to an EIP that extends EIP-712 with new domain fields, along with a method to obtain the value for those fields, and potentially conditions for inclusion. The values of those fields do not affect whether they are included. |
ERC712
Inherits: IERC712
State Variables
_EIP712_DOMAIN_HASH
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
bytes32 internal constant _EIP712_DOMAIN_HASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
_initialChainId
Initial Chain ID set at deployment.
uint256 internal immutable _initialChainId;
_ERC712_STORAGE_LOCATION
bytes32 internal constant _ERC712_STORAGE_LOCATION = 0xc7effa11ad597798220888e5d1ba4eeddcc8c2635d01dae8b9f958ac905c1100;
Functions
_getERC712Storage
function _getERC712Storage() internal pure returns (ERC712Storage storage $);
constructor
Constructs the EIP-712 domain separator.
constructor();
_initializeERC712
function _initializeERC712() internal;
DOMAIN_SEPARATOR
Returns the EIP712 domain separator used in the encoding of a signed digest.
function DOMAIN_SEPARATOR() public view returns (bytes32 domainSeparator_);
_getDomainSeparator
Computes the EIP-712 domain separator.
function _getDomainSeparator() internal view returns (bytes32 domainSeparator_);
Returns
| Name | Type | Description |
|---|---|---|
domainSeparator_ | bytes32 | The EIP-712 domain separator. |
_getDigest
Returns the digest to be signed, via EIP-712, given an internal digest (i.e. hash struct).
function _getDigest(bytes32 internalDigest_) internal view returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
internalDigest_ | bytes32 | The internal digest. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The digest to be signed. |
_name
The name of the contract.
function _name() internal view virtual returns (string memory name_);
_version
The version of the contract.
function _version() internal view virtual returns (string memory version_);
Structs
ERC712Storage
The UUPS storage for the ERC712 contract.
Note: storage-location: erc7201:xmtp.storage.ERC712
struct ERC712Storage {
bytes32 initialDomainSeparator;
}
Properties
| Name | Type | Description |
|---|---|---|
initialDomainSeparator | bytes32 | Initial EIP-712 domain separator set at initialization. |
Migratable
Inherits: IMigratable
State Variables
_IMPLEMENTATION_SLOT
Storage slot with the address of the current implementation.
keccak256('eip1967.proxy.implementation') - 1.
uint256 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
Functions
implementation
Returns the address of the current implementation.
function implementation() public view returns (address implementation_);
_migrate
Performs an arbitrary migration by delegate-calling migrator_.
The migrator fallback code defines the entire migration process, and takes no user-defined arguments.
function _migrate(address migrator_) internal;
Parameters
| Name | Type | Description |
|---|---|---|
migrator_ | address | The address of a trusted migrator contract the will have the authority to perform any state changes, ETH transfers, and contract calls on behalf of this contract. |
ParameterRegistry
Inherits: IParameterRegistry, Migratable, Initializable
A parameter registry is a contract that stores key-value pairs of parameters used by a protocol. Keys should be globally unique and human-readable strings, for easier parsing and indexing. Keys can be set by admins, and whether an account is an admin is itself a key-value pair in the registry, which means that admins can be added and removed by other admins, and the parameter registry can be orphaned.
State Variables
_PARAMETER_REGISTRY_STORAGE_LOCATION
bytes32 internal constant _PARAMETER_REGISTRY_STORAGE_LOCATION =
0xefab3f4eb315eafaa267b58974a509c07c739fbfe8e62b4eff49c4ced6985000;
Functions
_getParameterRegistryStorage
function _getParameterRegistryStorage() internal pure returns (ParameterRegistryStorage storage $);
onlyAdmin
modifier onlyAdmin();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
constructor();
initialize
Initializes the parameter registry, as used by a proxy contract.
Whether an account is an admin is tracked as a key-value pair in the registry itself.
function initialize(address[] calldata admins_) external initializer;
Parameters
| Name | Type | Description |
|---|---|---|
admins_ | address[] | The addresses of the admins that can set parameters. |
set
Sets several parameters.
The length of the keys_ and values_ arrays must be the same.
function set(string[] calldata keys_, bytes32[] calldata values_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
keys_ | string[] | The keys of each parameter to set. |
values_ | bytes32[] | The values of each parameter. |
set
Sets several parameters.
The length of the keys_ and values_ arrays must be the same.
function set(string calldata key_, bytes32 value_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
key_ | string | |
value_ | bytes32 |
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
migratorParameterKey
The parameter registry key used to fetch the migrator.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function migratorParameterKey() public pure virtual returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the migrator parameter. |
adminParameterKey
The parameter registry key used to fetch the status of an admin.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function adminParameterKey() public pure virtual returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the admin parameter, which is a component of the full key, when prefixing an address. |
isAdmin
Returns whether an account is an admin (i.e. an account that can set parameters).
function isAdmin(address account_) public view returns (bool isAdmin_);
Parameters
| Name | Type | Description |
|---|---|---|
account_ | address | The address of the account to check. |
Returns
| Name | Type | Description |
|---|---|---|
isAdmin_ | bool | True if the account is an admin, false otherwise. |
get
Gets the values of several parameters.
The default value for each parameter is bytes32(0).
function get(string[] calldata keys_) external view returns (bytes32[] memory values_);
Parameters
| Name | Type | Description |
|---|---|---|
keys_ | string[] | The keys of each parameter to get. |
Returns
| Name | Type | Description |
|---|---|---|
values_ | bytes32[] | The values of each parameter. |
get
Gets the values of several parameters.
The default value for each parameter is bytes32(0).
function get(string calldata key_) external view returns (bytes32 value_);
Parameters
| Name | Type | Description |
|---|---|---|
key_ | string |
Returns
| Name | Type | Description |
|---|---|---|
value_ | bytes32 | values_ The values of each parameter. |
_setParameter
function _setParameter(ParameterRegistryStorage storage $, string memory key_, bytes32 value_) internal;
_getAdminKey
Returns the admin-specific key used to query to parameter registry to determine if an account is an admin. The admin-specific key is the concatenation of the admin parameter key and the address of the admin. For example, if the admin parameter key is "pr.isAdmin", then the key for admin 0x1234567890123456789012345678901234567890 is "pr.isAdmin.0x1234567890123456789012345678901234567890".
function _getAdminKey(string memory adminParameterKey_, address account_) internal pure returns (string memory key_);
_getRegistryParameter
function _getRegistryParameter(string memory key_) internal view returns (bytes32 value_);
_revertIfNotAdmin
function _revertIfNotAdmin() internal view;
Structs
ParameterRegistryStorage
The UUPS storage for the parameter registry.
Note: storage-location: erc7201:xmtp.storage.ParameterRegistry
struct ParameterRegistryStorage {
mapping(string key => bytes32 value) parameters;
}
Properties
| Name | Type | Description |
|---|---|---|
parameters | mapping(string key => bytes32 value) | A mapping of key-value pairs of parameters. |
PayloadBroadcaster
Inherits: IPayloadBroadcaster, Migratable, Initializable
A payload broadcaster is a contract that broadcasts payloads as events, where payloads have a min and max size, both of which can be updated from a parameter registry.
State Variables
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
_PAYLOAD_BROADCASTER_STORAGE_LOCATION
bytes32 internal constant _PAYLOAD_BROADCASTER_STORAGE_LOCATION =
0xeda186f2b85b2c197e0a3ff15dc0c5c16c74d00b5c7f432acaa215db84203b00;
Functions
_getPayloadBroadcasterStorage
function _getPayloadBroadcasterStorage() internal pure returns (PayloadBroadcasterStorage storage $);
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry must not be the zero address.
The parameter registry is immutable so that it is inlined in the contract code, and has minimal gas cost.
constructor(address parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
initialize
Initializes the contract.
function initialize() public virtual initializer;
updateMinPayloadSize
Updates the minimum payload size.
Ensures the new minimum is less than the maximum.
function updateMinPayloadSize() external;
updateMaxPayloadSize
Updates the maximum payload size.
Ensures the new maximum is greater than the minimum.
function updateMaxPayloadSize() external;
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
updatePayloadBootstrapper
Updates the payload bootstrapper.
Ensures the new payload bootstrapper is not equal to the old payload bootstrapper.
function updatePayloadBootstrapper() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
minPayloadSizeParameterKey
The parameter registry key used to fetch the minimum payload size.
function minPayloadSizeParameterKey() public pure virtual returns (string memory key_);
maxPayloadSizeParameterKey
The parameter registry key used to fetch the maximum payload size.
function maxPayloadSizeParameterKey() public pure virtual returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure virtual returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure virtual returns (string memory key_);
payloadBootstrapperParameterKey
The parameter registry key used to fetch the payload bootstrapper.
function payloadBootstrapperParameterKey() public pure virtual returns (string memory key_);
minPayloadSize
Minimum valid payload size (in bytes).
function minPayloadSize() external view returns (uint32 size_);
maxPayloadSize
Maximum valid payload size (in bytes).
function maxPayloadSize() external view returns (uint32 size_);
paused
The pause status.
function paused() external view returns (bool paused_);
payloadBootstrapper
The payload bootstrapper.
function payloadBootstrapper() external view returns (address payloadBootstrapper_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfPaused
function _revertIfPaused() internal view;
_revertIfNotPaused
function _revertIfNotPaused() internal view;
_revertIfInvalidPayloadSize
function _revertIfInvalidPayloadSize(uint256 payloadSize_) internal view;
_revertIfNotPayloadBootstrapper
function _revertIfNotPayloadBootstrapper() internal view;
Structs
PayloadBroadcasterStorage
The UUPS storage for the payload broadcaster.
Note: storage-location: erc7201:xmtp.storage.PayloadBroadcaster
struct PayloadBroadcasterStorage {
uint32 minPayloadSize;
uint32 maxPayloadSize;
uint64 sequenceId;
bool paused;
address payloadBootstrapper;
}
Properties
| Name | Type | Description |
|---|---|---|
minPayloadSize | uint32 | The minimum payload size. |
maxPayloadSize | uint32 | The maximum payload size. |
sequenceId | uint64 | A sequence ID for uniquely ordering payloads (should be monotonically increasing). |
paused | bool | The paused status. |
payloadBootstrapper | address |
Contents
Contents
IFactory
Inherits: IMigratable
Functions
initialize
Initializes the contract.
function initialize() external;
deployImplementation
Deploys an implementation contract.
function deployImplementation(bytes memory bytecode_) external returns (address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
bytecode_ | bytes | The bytecode of the implementation to deploy (including appended constructor data). |
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the deployed implementation. |
deployProxy
Deploys a proxy contract.
function deployProxy(address implementation_, bytes32 salt_, bytes calldata initializeCallData_)
external
returns (address proxy_);
Parameters
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation the proxy should proxy. |
salt_ | bytes32 | A salt defined by the sender. |
initializeCallData_ | bytes | The call data used to initialize the proxy. |
Returns
| Name | Type | Description |
|---|---|---|
proxy_ | address | The address of the deployed proxy. |
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() external pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
initializableImplementation
The address of the first temporary implementation that proxies will proxy.
*This contract is the first proxied implementation of any proxy, and allows the factory to then set the proxy's actual implementation, and initialize it with respect to that actual implementation. This ensures that:
- The address of a proxy is only defined by the nonce, and not by the implementation it will proxy.
- No contracts are deployed that are not used.
- The proxy can be easily initialized with respect to the actual implementation, atomically.*
function initializableImplementation() external view returns (address initializableImplementation_);
computeImplementationAddress
Computes the address of an implementation contract that would be deployed from a given bytecode.
The address is determined only by the bytecode, and so the same bytecode results in the same address.
function computeImplementationAddress(bytes calldata bytecode_) external view returns (address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
bytecode_ | bytes | The bytecode of the implementation to deploy (including appended constructor data). |
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation that would be deployed. |
computeProxyAddress
Computes the address of a proxy contract that would be deployed from given a caller and salt.
The actual salt used to deploy the proxy via create2 is keccak256(abi.encodePacked(caller_, salt_)).
function computeProxyAddress(address caller_, bytes32 salt_) external view returns (address proxy_);
Parameters
| Name | Type | Description |
|---|---|---|
caller_ | address | The address of the caller that would request the proxy deployment. |
salt_ | bytes32 | The salt defined by the caller. |
Returns
| Name | Type | Description |
|---|---|---|
proxy_ | address | The address of the proxy that would be deployed. |
Events
InitializableImplementationDeployed
Emitted when the "initializable implementation" is deployed.
This contract is only deployed once, when the factory itself is deployed.
event InitializableImplementationDeployed(address indexed implementation);
Parameters
| Name | Type | Description |
|---|---|---|
implementation | address | The address of the deployed "initializable implementation". |
ImplementationDeployed
Emitted when an implementation is deployed.
event ImplementationDeployed(address indexed implementation, bytes32 indexed bytecodeHash);
Parameters
| Name | Type | Description |
|---|---|---|
implementation | address | The address of the deployed implementation. |
bytecodeHash | bytes32 | The hash of the bytecode of the deployed implementation. |
ProxyDeployed
Emitted when a proxy is deployed.
The actual salt used to deploy the proxy via create2 is keccak256(abi.encodePacked(sender, salt)).
event ProxyDeployed(
address indexed proxy,
address indexed implementation,
address indexed sender,
bytes32 salt,
bytes initializeCallData
);
Parameters
| Name | Type | Description |
|---|---|---|
proxy | address | The address of the deployed proxy. |
implementation | address | The address of the implementation the proxy proxies. |
sender | address | The address of the sender that triggered the proxy deployment. |
salt | bytes32 | The salt defined by the sender. |
initializeCallData | bytes | The call data used to initialize the proxy. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry is the zero address.
error ZeroParameterRegistry();
InvalidImplementation
Thrown when the implementation is the zero address.
error InvalidImplementation();
EmptyBytecode
Thrown when the bytecode is empty (i.e. of the implementation to deploy).
error EmptyBytecode();
DeployFailed
Thrown when the deployment of a contract (e.g. an implementation or proxy) fails.
error DeployFailed();
Paused
Thrown when any pausable function is called when the contract is paused.
error Paused();
IInitializable
Functions
initialize
Initializes the contract with respect to the implementation.
function initialize(address implementation_, bytes calldata initializeCallData_) external;
Parameters
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation. |
initializeCallData_ | bytes | The data to initialize the proxy with, with respect to the implementation. |
Errors
ZeroImplementation
Thrown when the implementation address is zero (i.e. address(0)).
error ZeroImplementation();
InitializationFailed
Thrown when the initialization fails.
error InitializationFailed(bytes errorData);
EmptyCode
Thrown when the implementation code is empty.
error EmptyCode(address implementation);
IProxy
Errors
ZeroImplementation
Thrown when the implementation address is zero (i.e. address(0)).
error ZeroImplementation();
Factory
Inherits: IFactory, Migratable, OZInitializable
This contract is used to deploy implementations and proxies deterministically, using create2, and is to
only be deployed once on each chain. Implementations deployed use their own bytecode hash as their salt, so
a unique bytecode (including constructor arguments) will have only one possible address. Proxies deployed use
the sender's address combined with a salt of the sender's choosing as a final salt, and the constructor
arguments are always the same (i.e. the "initializable implementation"), so an address has only 2 degrees
of freedom. This is helpful for ensuring the address of a future/planned contract is constant, while the
implementation is not yet finalized or deployed.
State Variables
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
_FACTORY_STORAGE_LOCATION
bytes32 internal constant _FACTORY_STORAGE_LOCATION = 0x651b031aaeb8a5a65735ac2bad4001a08e08ce7e1a4736b27ec7d04baeb8f600;
Functions
_getFactoryStorage
function _getFactoryStorage() internal pure returns (FactoryStorage storage $);
whenNotPaused
modifier whenNotPaused();
constructor
Constructor that deploys the initializable implementation.
The parameter registry must not be the zero address.
constructor(address parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
initialize
Initializes the contract.
function initialize() external initializer;
deployImplementation
Deploys an implementation contract.
function deployImplementation(bytes calldata bytecode_) external whenNotPaused returns (address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
bytecode_ | bytes | The bytecode of the implementation to deploy (including appended constructor data). |
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the deployed implementation. |
deployProxy
Deploys a proxy contract.
function deployProxy(address implementation_, bytes32 salt_, bytes calldata initializeCallData_)
external
whenNotPaused
returns (address proxy_);
Parameters
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation the proxy should proxy. |
salt_ | bytes32 | A salt defined by the sender. |
initializeCallData_ | bytes | The call data used to initialize the proxy. |
Returns
| Name | Type | Description |
|---|---|---|
proxy_ | address | The address of the deployed proxy. |
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
initializableImplementation
The address of the first temporary implementation that proxies will proxy.
*This contract is the first proxied implementation of any proxy, and allows the factory to then set the proxy's actual implementation, and initialize it with respect to that actual implementation. This ensures that:
- The address of a proxy is only defined by the nonce, and not by the implementation it will proxy.
- No contracts are deployed that are not used.
- The proxy can be easily initialized with respect to the actual implementation, atomically.*
function initializableImplementation() external view returns (address initializableImplementation_);
computeImplementationAddress
Computes the address of an implementation contract that would be deployed from a given bytecode.
The address is determined only by the bytecode, and so the same bytecode results in the same address.
function computeImplementationAddress(bytes calldata bytecode_) external view returns (address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
bytecode_ | bytes | The bytecode of the implementation to deploy (including appended constructor data). |
Returns
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation that would be deployed. |
computeProxyAddress
Computes the address of a proxy contract that would be deployed from given a caller and salt.
The actual salt used to deploy the proxy via create2 is keccak256(abi.encodePacked(caller_, salt_)).
function computeProxyAddress(address caller_, bytes32 salt_) external view returns (address proxy_);
Parameters
| Name | Type | Description |
|---|---|---|
caller_ | address | The address of the caller that would request the proxy deployment. |
salt_ | bytes32 | The salt defined by the caller. |
Returns
| Name | Type | Description |
|---|---|---|
proxy_ | address | The address of the proxy that would be deployed. |
_create2
Creates a contract via create2 and reverts if the deployment fails.
function _create2(bytes memory bytecode_, bytes32 salt_) internal returns (address deployed_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfPaused
function _revertIfPaused() internal view;
Structs
FactoryStorage
The UUPS storage for the factory.
Note: storage-location: erc7201:xmtp.storage.Factory
struct FactoryStorage {
bool paused;
address initializableImplementation;
}
Properties
| Name | Type | Description |
|---|---|---|
paused | bool | The pause status. |
initializableImplementation | address |
Initializable
Inherits: IInitializable
This contract is expected to be the first and default implementation of a Proxy, so that any Proxy can have a constant constructor (and thus proxied implementation), despite remaining completely transparency, which is very helpful to allow consistency in address determinism regardless the final intended proxied implementation address. Thus, no Proxy should be left in a state of proxying this contract.
State Variables
_IMPLEMENTATION_SLOT
Storage slot with the address of the current implementation.
keccak256('eip1967.proxy.implementation') - 1.
uint256 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
Functions
initialize
Initializes the contract with respect to the implementation.
function initialize(address implementation_, bytes calldata initializeCallData_) external;
Parameters
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of the implementation. |
initializeCallData_ | bytes | The data to initialize the proxy with, with respect to the implementation. |
Migrator
State Variables
_IMPLEMENTATION_SLOT
Storage slot with the address of the current implementation.
keccak256('eip1967.proxy.implementation') - 1.
uint256 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
fromImplementation
The implementation to migrate proxies from.
address public immutable fromImplementation;
toImplementation
The implementation to migrate proxies to.
address public immutable toImplementation;
Functions
constructor
Constructs the contract such that it proxies calls to the given implementation.
constructor(address fromImplementation_, address toImplementation_);
Parameters
| Name | Type | Description |
|---|---|---|
fromImplementation_ | address | The address of the implementation to migrate a proxy from. |
toImplementation_ | address | The address of the implementation to migrate a proxy to. |
fallback
Migrates a proxy to the new implementation.
fallback() external;
Errors
ZeroFromImplementation
Thrown when the from implementation is the zero address.
error ZeroFromImplementation();
ZeroToImplementation
Thrown when the to implementation is the zero address.
error ZeroToImplementation();
UnexpectedImplementation
Thrown when the implementation is not the expected implementation.
error UnexpectedImplementation();
Proxy
Inherits: IProxy
State Variables
_IMPLEMENTATION_SLOT
Storage slot with the address of the current implementation.
keccak256('eip1967.proxy.implementation') - 1.
uint256 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
Functions
constructor
Constructs the contract such that it proxies calls to the given implementation.
constructor(address implementation_);
Parameters
| Name | Type | Description |
|---|---|---|
implementation_ | address | The address of some implementation. |
fallback
fallback() external payable;
Contents
- interfaces
- AppChainGateway
- AppChainParameterRegistry
- GroupMessageBroadcaster
- IdentityUpdateBroadcaster
Contents
- IArbSysLike
- ISettlementChainGatewayLike
- IAppChainGateway
- IAppChainParameterRegistry
- IGroupMessageBroadcaster
- IIdentityUpdateBroadcaster
IArbSysLike
Functions
sendTxToL1
function sendTxToL1(address destination_, bytes calldata data_) external payable returns (uint256 messageId_);
ISettlementChainGatewayLike
Functions
receiveWithdrawal
function receiveWithdrawal(address recipient_) external;
receiveWithdrawalIntoUnderlying
function receiveWithdrawalIntoUnderlying(address recipient_) external;
IAppChainGateway
Inherits: IMigratable, IRegistryParametersErrors
The AppChainGateway exposes the ability to receive parameters from the settlement chain gateway.
Functions
initialize
Initializes the parameter registry, as used by a proxy contract.
function initialize() external;
withdraw
Withdraws funds from the app chain to the settlement chain.
function withdraw(address recipient_) external payable;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to which the funds will be delivered to on the settlement chain. |
withdrawIntoUnderlying
Withdraws funds from the app chain to the settlement chain, unwrapped as underlying fee token.
function withdrawIntoUnderlying(address recipient_) external payable;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to which the funds will be delivered to on the settlement chain. |
receiveDeposit
Receives funds from the settlement chain.
The recipient will receive the forwarded amount attached as payable.
function receiveDeposit(address recipient_) external payable;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to which the funds will be delivered to. |
receiveParameters
Receives parameters from the settlement chain.
The caller must be the settlement chain gateway's L3 alias address.
function receiveParameters(uint256 nonce_, string[] calldata keys_, bytes32[] calldata values_) external;
Parameters
| Name | Type | Description |
|---|---|---|
nonce_ | uint256 | The nonce of the parameter transmission (to prevent out-of-sequence resets). |
keys_ | string[] | The keys of the parameters. |
values_ | bytes32[] | The values of each parameter. |
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
settlementChainGateway
The address of the settlement chain gateway.
function settlementChainGateway() external view returns (address settlementChainGateway_);
settlementChainGatewayAlias
The L3 alias address of the settlement chain gateway (i.e. the expected caller of the receiveParameters
function).
function settlementChainGatewayAlias() external view returns (address settlementChainGatewayAlias_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() external pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
Events
ParametersReceived
Emitted when parameters are received from the settlement chain.
The values are not emitted, as they are not relevant to indexing this contract, and will be emitted
by the app chain parameter registry.
event ParametersReceived(uint256 indexed nonce, string[] keys);
Parameters
| Name | Type | Description |
|---|---|---|
nonce | uint256 | The nonce of the parameter transmission (to prevent out-of-sequence parameter updates). |
keys | string[] | The keys of the parameters. |
DepositReceived
Emitted when funds are deposited from the settlement chain.
event DepositReceived(address indexed recipient, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
recipient | address | The address to which the funds will be delivered to. |
amount | uint256 | The amount of funds received. |
PauseStatusUpdated
Emitted when the pause status is set.
event PauseStatusUpdated(bool indexed paused);
Parameters
| Name | Type | Description |
|---|---|---|
paused | bool | The new pause status. |
Withdrawal
Emitted when funds are withdrawn from the app chain.
event Withdrawal(uint256 indexed messageId, address indexed recipient, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
messageId | uint256 | The message ID of the withdrawal. |
recipient | address | The address to which the funds will be delivered to on the settlement chain. |
amount | uint256 | The amount of funds withdrawn. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroSettlementChainGateway
Thrown when the settlement chain gateway address is zero (i.e. address(0)).
error ZeroSettlementChainGateway();
NotSettlementChainGateway
Thrown when the caller is not the settlement chain gateway (i.e. its L3 alias address).
error NotSettlementChainGateway();
ZeroRecipient
Thrown when the recipient address is zero (i.e. address(0)).
error ZeroRecipient();
ZeroWithdrawalAmount
Thrown when the withdrawal amount is zero.
error ZeroWithdrawalAmount();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
Paused
Thrown when any pausable function is called when the contract is paused.
error Paused();
TransferFailed
Thrown when the transfer fails.
error TransferFailed();
IAppChainParameterRegistry
Inherits: IParameterRegistry
An AppChainParameterRegistry is a parameter registry used by the protocol contracts on an app chain.
IGroupMessageBroadcaster
Inherits: IPayloadBroadcaster
The GroupMessageBroadcaster is a group message payload broadcaster on an app chain.
Functions
addMessage
Adds a message to the group.
Ensures the payload length is within the allowed range and increments the sequence ID.
function addMessage(bytes16 groupId_, bytes calldata message_) external;
Parameters
| Name | Type | Description |
|---|---|---|
groupId_ | bytes16 | The group ID. |
message_ | bytes | The message in bytes. |
bootstrapMessages
Bootstraps messages to satisfy a migration.
function bootstrapMessages(bytes16[] calldata groupIds_, bytes[] calldata messages_, uint64[] calldata sequenceIds_)
external;
Parameters
| Name | Type | Description |
|---|---|---|
groupIds_ | bytes16[] | The group IDs. |
messages_ | bytes[] | The messages in bytes. |
sequenceIds_ | uint64[] | The sequence IDs. |
Events
MessageSent
Emitted when a message is sent.
event MessageSent(bytes16 indexed groupId, bytes message, uint64 indexed sequenceId);
Parameters
| Name | Type | Description |
|---|---|---|
groupId | bytes16 | The group ID. |
message | bytes | The message in bytes. Contains the full MLS group message payload. |
sequenceId | uint64 | The unique sequence ID of the message. |
Errors
ArrayLengthMismatch
Thrown when the lengths of input arrays don't match.
error ArrayLengthMismatch();
EmptyArray
Thrown when a supplied array is empty.
error EmptyArray();
IIdentityUpdateBroadcaster
Inherits: IPayloadBroadcaster
The IdentityUpdateBroadcaster is an identity payload broadcaster on an app chain.
Functions
addIdentityUpdate
Adds an identity update to a specific inbox ID.
Ensures the payload length is within the allowed range and increments the sequence ID.
function addIdentityUpdate(bytes32 inboxId_, bytes calldata identityUpdate_) external;
Parameters
| Name | Type | Description |
|---|---|---|
inboxId_ | bytes32 | The inbox ID. |
identityUpdate_ | bytes | The identity update in bytes. |
bootstrapIdentityUpdates
Bootstraps identity updates to satisfy a migration.
function bootstrapIdentityUpdates(
bytes32[] calldata inboxIds_,
bytes[] calldata identityUpdates_,
uint64[] calldata sequenceIds_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
inboxIds_ | bytes32[] | The inbox IDs. |
identityUpdates_ | bytes[] | The identity updates in bytes. |
sequenceIds_ | uint64[] | The sequence IDs. |
Events
IdentityUpdateCreated
Emitted when an identity update is sent.
event IdentityUpdateCreated(bytes32 indexed inboxId, bytes update, uint64 indexed sequenceId);
Parameters
| Name | Type | Description |
|---|---|---|
inboxId | bytes32 | The inbox ID. |
update | bytes | The identity update in bytes. Contains the full MLS identity update payload. |
sequenceId | uint64 | The unique sequence ID of the identity update. |
Errors
ArrayLengthMismatch
Thrown when the lengths of input arrays don't match.
error ArrayLengthMismatch();
EmptyArray
Thrown when a supplied array is empty.
error EmptyArray();
AppChainGateway
Inherits: IAppChainGateway, Migratable, Initializable
The AppChainGateway exposes the ability to receive parameters from the settlement chain gateway, and set them at the parameter registry on this same app chain. Currently, it is a receiver-only contract.
State Variables
_ARB_SYS
The Arbitrum system precompile address.
address internal constant _ARB_SYS = 0x0000000000000000000000000000000000000064;
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
settlementChainGateway
The address of the settlement chain gateway.
address public immutable settlementChainGateway;
settlementChainGatewayAlias
The L3 alias address of the settlement chain gateway (i.e. the expected caller of the receiveParameters
function).
address public immutable settlementChainGatewayAlias;
_APP_CHAIN_GATEWAY_STORAGE_LOCATION
bytes32 internal constant _APP_CHAIN_GATEWAY_STORAGE_LOCATION =
0xf7630100a9c96f7b07fb982ff1e6dad8abbb961bacff2e820fac4ea93b280300;
Functions
_getAppChainGatewayStorage
function _getAppChainGatewayStorage() internal pure returns (AppChainGatewayStorage storage $);
onlySettlementChainGateway
Modifier to ensure the caller is the settlement chain gateway (i.e. its L3 alias address).
modifier onlySettlementChainGateway();
whenNotPaused
modifier whenNotPaused();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry and settlement chain gateway must not be the zero address.
The parameter registry, settlement chain gateway, and the settlement chain gateway alias are immutable so that they are inlined in the contract code, and have minimal gas cost.
constructor(address parameterRegistry_, address settlementChainGateway_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
settlementChainGateway_ | address | The address of the settlement chain gateway. |
initialize
Initializes the parameter registry, as used by a proxy contract.
function initialize() external initializer;
withdraw
Withdraws funds from the app chain to the settlement chain.
function withdraw(address recipient_) external payable whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to which the funds will be delivered to on the settlement chain. |
withdrawIntoUnderlying
Withdraws funds from the app chain to the settlement chain, unwrapped as underlying fee token.
function withdrawIntoUnderlying(address recipient_) external payable whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to which the funds will be delivered to on the settlement chain. |
receiveDeposit
Receives funds from the settlement chain.
The recipient will receive the forwarded amount attached as payable.
function receiveDeposit(address recipient_) external payable;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to which the funds will be delivered to. |
receiveParameters
Receives parameters from the settlement chain.
The caller must be the settlement chain gateway's L3 alias address.
function receiveParameters(uint256 nonce_, string[] calldata keys_, bytes32[] calldata values_)
external
onlySettlementChainGateway;
Parameters
| Name | Type | Description |
|---|---|---|
nonce_ | uint256 | The nonce of the parameter transmission (to prevent out-of-sequence resets). |
keys_ | string[] | The keys of the parameters. |
values_ | bytes32[] | The values of each parameter. |
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
_withdraw
function _withdraw(address recipient_, bytes4 selector_) internal;
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfNotSettlementChainGateway
function _revertIfNotSettlementChainGateway() internal view;
_revertIfPaused
function _revertIfPaused() internal view;
Structs
AppChainGatewayStorage
The UUPS storage for the app chain gateway.
Note: storage-location: erc7201:xmtp.storage.AppChainGateway
struct AppChainGatewayStorage {
bool paused;
mapping(string key => uint256 nonce) keyNonces;
}
Properties
| Name | Type | Description |
|---|---|---|
paused | bool | |
keyNonces | mapping(string key => uint256 nonce) | A mapping of keys and their corresponding nonces, to track order of parameter receptions. |
AppChainParameterRegistry
Inherits: IAppChainParameterRegistry, ParameterRegistry
An AppChainParameterRegistry is a parameter registry used by the protocol contracts on an app chain.
Functions
migratorParameterKey
The parameter registry key used to fetch the migrator.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function migratorParameterKey()
public
pure
override(IParameterRegistry, ParameterRegistry)
returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the migrator parameter. |
adminParameterKey
The parameter registry key used to fetch the status of an admin.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function adminParameterKey() public pure override(IParameterRegistry, ParameterRegistry) returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the admin parameter, which is a component of the full key, when prefixing an address. |
GroupMessageBroadcaster
Inherits: IGroupMessageBroadcaster, PayloadBroadcaster
A GroupMessageBroadcaster is a group message payload broadcaster on an app chain.
Functions
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
constructor(address parameterRegistry_) PayloadBroadcaster(parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
addMessage
Adds a message to the group.
Ensures the payload length is within the allowed range and increments the sequence ID.
function addMessage(bytes16 groupId_, bytes calldata message_) external;
Parameters
| Name | Type | Description |
|---|---|---|
groupId_ | bytes16 | The group ID. |
message_ | bytes | The message in bytes. |
bootstrapMessages
Bootstraps messages to satisfy a migration.
function bootstrapMessages(bytes16[] calldata groupIds_, bytes[] calldata messages_, uint64[] calldata sequenceIds_)
external;
Parameters
| Name | Type | Description |
|---|---|---|
groupIds_ | bytes16[] | The group IDs. |
messages_ | bytes[] | The messages in bytes. |
sequenceIds_ | uint64[] | The sequence IDs. |
minPayloadSizeParameterKey
The parameter registry key used to fetch the minimum payload size.
function minPayloadSizeParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
maxPayloadSizeParameterKey
The parameter registry key used to fetch the maximum payload size.
function maxPayloadSizeParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
payloadBootstrapperParameterKey
The parameter registry key used to fetch the payload bootstrapper.
function payloadBootstrapperParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
IdentityUpdateBroadcaster
Inherits: IIdentityUpdateBroadcaster, PayloadBroadcaster
An IdentityUpdateBroadcaster is an identity payload broadcaster on an app chain.
Functions
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
constructor(address parameterRegistry_) PayloadBroadcaster(parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
addIdentityUpdate
Adds an identity update to a specific inbox ID.
Ensures the payload length is within the allowed range and increments the sequence ID.
function addIdentityUpdate(bytes32 inboxId_, bytes calldata identityUpdate_) external;
Parameters
| Name | Type | Description |
|---|---|---|
inboxId_ | bytes32 | The inbox ID. |
identityUpdate_ | bytes | The identity update in bytes. |
bootstrapIdentityUpdates
Bootstraps identity updates to satisfy a migration.
function bootstrapIdentityUpdates(
bytes32[] calldata inboxIds_,
bytes[] calldata identityUpdates_,
uint64[] calldata sequenceIds_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
inboxIds_ | bytes32[] | The inbox IDs. |
identityUpdates_ | bytes[] | The identity updates in bytes. |
sequenceIds_ | uint64[] | The sequence IDs. |
minPayloadSizeParameterKey
The parameter registry key used to fetch the minimum payload size.
function minPayloadSizeParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
maxPayloadSizeParameterKey
The parameter registry key used to fetch the maximum payload size.
function maxPayloadSizeParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
payloadBootstrapperParameterKey
The parameter registry key used to fetch the payload bootstrapper.
function payloadBootstrapperParameterKey()
public
pure
override(IPayloadBroadcaster, PayloadBroadcaster)
returns (string memory key_);
Contents
Contents
IParameterRegistryLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
set
function set(string calldata key_, bytes32 value_) external;
get
function get(string calldata key_) external view returns (bytes32 value_);
get
function get(string[] calldata keys_) external view returns (bytes32[] memory values_);
IParameterKeysErrors
This interface should be inherited by any contract that uses the Parameter Keys library in order to expose the errors that may be thrown by the library.
Errors
NoKeyComponents
Thrown when no key components are provided.
error NoKeyComponents();
IRegistryParametersErrors
This interface should be inherited by any contract that uses the Registry Parameters library in order to expose the errors that may be thrown by the library.
Errors
ParameterOutOfTypeBounds
Thrown when the parameter is out of type bounds.
error ParameterOutOfTypeBounds();
ISequentialMerkleProofsErrors
This interface should be inherited by any contract that uses the Sequential Merkle Proofs library in order to expose the errors that may be thrown by the library.
Errors
NoLeaves
Thrown when no leaves are provided.
error NoLeaves();
InvalidBitCount32Input
Thrown when the input to _bitCount32 is greater than type(uint32).max.
error InvalidBitCount32Input();
InvalidProof
Thrown when the proof is invalid.
error InvalidProof();
NoProofElements
Thrown when no proof elements are provided.
error NoProofElements();
InvalidLeafCount
Thrown when the leaf count is greater than type(uint32).max.
error InvalidLeafCount();
AddressAliasHelper
Roll-up layer address aliasing as per EIP-6735 (see https://eips.ethereum.org/EIPS/eip-6735).
State Variables
OFFSET
uint160 internal constant OFFSET = uint160(0x1111000000000000000000000000000000001111);
Functions
toAlias
Convert a settlement layer address to roll-up layer alias address.
function toAlias(address account_) internal pure returns (address alias_);
Parameters
| Name | Type | Description |
|---|---|---|
account_ | address | The address on the settlement layer that will trigger a tx to the roll-up layer. |
Returns
| Name | Type | Description |
|---|---|---|
alias_ | address | The address on the roll-up layer that will be the msg.sender. |
fromAlias
Convert a roll-up layer alias address to settlement layer address.
function fromAlias(address alias_) internal pure returns (address account_);
Parameters
| Name | Type | Description |
|---|---|---|
alias_ | address | The address on the roll-up layer that will be the msg.sender. |
Returns
| Name | Type | Description |
|---|---|---|
account_ | address | The address on the settlement layer that triggered the tx to the roll-up layer. |
ParameterKeys
A parameter key is a string that uniquely identifies a parameter.
State Variables
DELIMITER
The delimiter used to combine key components.
string internal constant DELIMITER = ".";
Functions
getKey
Combines an array of key components into a single key, using the delimiter.
function getKey(string[] memory keyComponents_) internal pure returns (string memory key_);
Parameters
| Name | Type | Description |
|---|---|---|
keyComponents_ | string[] | The key components to combine. |
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The combined key. |
combineKeyComponents
function combineKeyComponents(string memory left_, string memory right_) internal pure returns (string memory key_);
addressToKeyComponent
function addressToKeyComponent(address account_) internal pure returns (string memory keyComponent_);
uint256ToKeyComponent
function uint256ToKeyComponent(uint256 value_) internal pure returns (string memory keyComponent_);
RegistryParameters
Exposes getters, setters, and parsers for parameters stored in a parameter registry.
Functions
setRegistryParameter
function setRegistryParameter(address parameterRegistry_, string memory key_, bytes32 value_) internal;
getRegistryParameters
function getRegistryParameters(address parameterRegistry_, string[] memory keys_)
internal
view
returns (bytes32[] memory value_);
getRegistryParameter
function getRegistryParameter(address parameterRegistry_, string memory key_) internal view returns (bytes32 value_);
getAddressParameter
function getAddressParameter(address parameterRegistry_, string memory key_) internal view returns (address output_);
getBoolParameter
function getBoolParameter(address parameterRegistry_, string memory key_) internal view returns (bool output_);
getUint8Parameter
function getUint8Parameter(address parameterRegistry_, string memory key_) internal view returns (uint8 output_);
getUint16Parameter
function getUint16Parameter(address parameterRegistry_, string memory key_) internal view returns (uint16 output_);
getUint32Parameter
function getUint32Parameter(address parameterRegistry_, string memory key_) internal view returns (uint32 output_);
getUint64Parameter
function getUint64Parameter(address parameterRegistry_, string memory key_) internal view returns (uint64 output_);
getUint96Parameter
function getUint96Parameter(address parameterRegistry_, string memory key_) internal view returns (uint96 output_);
getAddressFromRawParameter
function getAddressFromRawParameter(bytes32 parameter_) internal pure returns (address output_);
SequentialMerkleProofs
A sequential Merkle proof is a proof that leaves appear sequentially in a Merkle tree.
State Variables
EMPTY_TREE_ROOT
bytes32 internal constant EMPTY_TREE_ROOT = 0;
LEAF_PREFIX
The leaf prefix used to hash to a leaf ("leaf|").
bytes5 internal constant LEAF_PREFIX = 0x6c6561667c;
NODE_PREFIX
The node prefix used to hash to a node ("node|").
bytes5 internal constant NODE_PREFIX = 0x6e6f64657c;
ROOT_PREFIX
The root prefix used to hash to a root.
bytes5 internal constant ROOT_PREFIX = 0x726f6f747c;
Functions
verify
Verifies a sequential Merkle proof.
proofElements_[0] is the total number of leaves in the Merkle tree, the rest are the decommitments.
Can also revert with an array out-of-bounds access panic.
function verify(bytes32 root_, uint256 startingIndex_, bytes[] calldata leaves_, bytes32[] calldata proofElements_)
internal
pure;
Parameters
| Name | Type | Description |
|---|---|---|
root_ | bytes32 | The root of the Merkle tree. |
startingIndex_ | uint256 | The index of the first leaf provided. |
leaves_ | bytes[] | The leaves to prove sequential existence from the starting index. |
proofElements_ | bytes32[] | The Merkle proof data. |
getRoot
Gets the root of a sequential Merkle proof.
proofElements_[0] is the total number of leaves in the Merkle tree, the rest are the decommitments.
Can also revert with an array out-of-bounds access panic.
function getRoot(uint256 startingIndex_, bytes[] calldata leaves_, bytes32[] calldata proofElements_)
internal
pure
returns (bytes32 root_);
Parameters
| Name | Type | Description |
|---|---|---|
startingIndex_ | uint256 | The index of the first leaf provided. |
leaves_ | bytes[] | The leaves to prove sequential existence from the starting index. |
proofElements_ | bytes32[] | The Merkle proof data. |
getLeafCount
Extracts the leaf count from a sequential Merkle proof, without verifying the proof.
proofElements_[0] is the total number of leaves in the Merkle tree.
Does not verify the proof. Only extracts the leaf count from the proof elements.
function getLeafCount(bytes32[] calldata proofElements_) internal pure returns (uint32 leafCount_);
Parameters
| Name | Type | Description |
|---|---|---|
proofElements_ | bytes32[] | The Merkle proof data. |
_bitCount32
Counts number of set bits (1's) in 32-bit unsigned integer.
See https://en.wikipedia.org/wiki/Hamming_weight implementation popcount64b.
Literals are inlined as they are very specific to this algorithm/function, and actually improve readability, given their patterns.
function _bitCount32(uint256 n_) internal pure returns (uint256 bitCount_);
Parameters
| Name | Type | Description |
|---|---|---|
n_ | uint256 | The number to count the set bits of. |
Returns
| Name | Type | Description |
|---|---|---|
bitCount_ | uint256 | The number of set bits in n_. |
_roundUpToPowerOf2
Rounds a 32-bit unsigned integer up to the nearest power of 2.
Literals are inlined as they are very specific to this algorithm/function, and actually improve readability, given their patterns.
function _roundUpToPowerOf2(uint256 n_) internal pure returns (uint256 powerOf2_);
Parameters
| Name | Type | Description |
|---|---|---|
n_ | uint256 | The number to round up to the nearest power of 2. |
Returns
| Name | Type | Description |
|---|---|---|
powerOf2_ | uint256 | The nearest power of 2 to n_. |
_getBalancedLeafCount
Gets the balanced leaf count for a sequential Merkle proof.
function _getBalancedLeafCount(uint256 leafCount_) internal pure returns (uint256 balancedLeafCount_);
Parameters
| Name | Type | Description |
|---|---|---|
leafCount_ | uint256 | The number of leaves in the Merkle tree. |
Returns
| Name | Type | Description |
|---|---|---|
balancedLeafCount_ | uint256 | The balanced leaf count. |
_getRoot
Gets the root of a sequential Merkle proof.
proofElements_[0] is the total number of leaves in the Merkle tree, the rest are the decommitments.
function _getRoot(uint256 startingIndex_, bytes32[] memory hashes_, bytes32[] calldata proofElements_)
internal
pure
returns (bytes32 root_);
Parameters
| Name | Type | Description |
|---|---|---|
startingIndex_ | uint256 | The index of the first leaf provided. |
hashes_ | bytes32[] | The leaf hashes (in reverse order) to prove sequential existence from the starting index. |
proofElements_ | bytes32[] | The Merkle proof data. |
_isEven
The following variables are used while iterating through the root reconstruction from the proof.
readIndex_ is the index of hashes_ circular queue currently being read from.
writeIndex_ is the index of hashes_ circular queue currently being written to.
proofIndex_ is the index of proofElements_ array that is to be read from.
upperBound_ is the rightmost tree index, of the current level of the tree, such that all nodes to the
right, if any, are non-existent.
lowestTreeIndex_ is the tree index, of the current level of the tree, of the leftmost node we have.
highestLeafNodeIndex_ is the tree index of the rightmost leaf node we have.
nodeIndex_ is the tree index of the current node we are handling.
nextNodeIndex_ is the tree index of the next node we may be handling.
root_ will temporarily be used as the right part of the node pair hash, it is being used to save
much needed stack space.
left_ is the left part of the node pair hash.
function _isEven(uint256 n_) internal pure returns (bool isEven_);
_isLeftAnExistingHash
Checks if the left part of the hash should be an existing computed hash.
function _isLeftAnExistingHash(uint256 nodeIndex_, uint256 nextNodeIndex_)
internal
pure
returns (bool isLeftAnExistingHash_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeIndex_ | uint256 | The index of the current node in the tree indices array. |
nextNodeIndex_ | uint256 | The index of the next (lower) node in the tree indices array. |
Returns
| Name | Type | Description |
|---|---|---|
isLeftAnExistingHash_ | bool | True if the left part of the hash should be an existing computed hash. |
_hashLeaf
Hashes a leaf of arbitrary size into a 32-byte leaf node.
function _hashLeaf(bytes calldata leaf_) internal pure returns (bytes32 hash_);
Parameters
| Name | Type | Description |
|---|---|---|
leaf_ | bytes | The leaf to hash. |
Returns
| Name | Type | Description |
|---|---|---|
hash_ | bytes32 | The hash of the leaf. |
_hashNodePair
Hashes a pair of 32-byte nodes into a 32-byte parent node.
function _hashNodePair(bytes32 leftNode_, bytes32 rightNode_) internal pure returns (bytes32 hash_);
Parameters
| Name | Type | Description |
|---|---|---|
leftNode_ | bytes32 | The left node to hash. |
rightNode_ | bytes32 | The right node to hash. |
Returns
| Name | Type | Description |
|---|---|---|
hash_ | bytes32 | The hash of the pair of nodes. |
_hashPairlessNode
Hashes a 32-byte node, without a right paired node, into a 32-byte parent node.
function _hashPairlessNode(bytes32 node_) internal pure returns (bytes32 hash_);
Parameters
| Name | Type | Description |
|---|---|---|
node_ | bytes32 | The node to hash. |
Returns
| Name | Type | Description |
|---|---|---|
hash_ | bytes32 | The hash of the node. |
_hashRoot
Hashes the topmost 32-byte node in the tree, combined with the tree's leaf count, into a 32-byte root.
function _hashRoot(uint256 leafCount_, bytes32 node_) internal pure returns (bytes32 hash_);
Parameters
| Name | Type | Description |
|---|---|---|
leafCount_ | uint256 | The number of leaves in the Merkle tree. |
node_ | bytes32 | The topmost node in the tree. |
Returns
| Name | Type | Description |
|---|---|---|
hash_ | bytes32 | The root hash of the tree. |
_getReversedLeafNodesFromLeaves
Get leaf nodes from arbitrary size leaves in calldata, in reverse order.
function _getReversedLeafNodesFromLeaves(bytes[] calldata leaves_)
internal
pure
returns (bytes32[] memory leafNodes_);
Contents
- interfaces
- DepositSplitter
- DistributionManager
- FeeToken
- NodeRegistry
- PayerRegistry
- PayerReportManager
- RateRegistry
- SettlementChainGateway
- SettlementChainParameterRegistry
Contents
- IERC20Like
- IERC20InboxLike
- IAppChainGatewayLike
- INodeRegistryLike
- IPayerRegistryLike
- IPayerReportManagerLike
- IPermitErc20Like
- IFeeTokenLike
- ISettlementChainGatewayLike
- IDepositSplitter
- IDistributionManager
- IFeeToken
- INodeRegistry
- IPayerRegistry
- IPayerReportManager
- IRateRegistry
- ISettlementChainGateway
- ISettlementChainParameterRegistry
IERC20Like
This is the minimal interface needed by contracts within this subdirectory.
Functions
approve
function approve(address spender_, uint256 amount_) external returns (bool success_);
transfer
function transfer(address recipient_, uint256 amount_) external returns (bool success_);
transferFrom
function transferFrom(address sender_, address recipient_, uint256 amount_) external returns (bool success_);
balanceOf
function balanceOf(address account_) external view returns (uint256 balance_);
decimals
function decimals() external view returns (uint8 decimals_);
IERC20InboxLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
sendContractTransaction
Sends a contract transaction to the L2 inbox, with a single-try execution on the L3.
function sendContractTransaction(
uint256 gasLimit_,
uint256 maxFeePerGas_,
address to_,
uint256 value_,
bytes calldata data_
) external returns (uint256 messageNumber_);
createRetryableTicket
Put a message in the L2 inbox that can be re-executed for some fixed amount of time if it reverts.
All tokenTotalFeeAmount will be deposited to callValueRefundAddress on L2.
Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error
In case of native token having non-18 decimals: tokenTotalFeeAmount is denominated in native token's decimals. All other value params - l2CallValue, maxSubmissionCost and maxFeePerGas are denominated in child chain's native 18 decimals.
tokenTotalFeeAmount_ (converted to 18 decimals on the L2) must be greater than or equal to the sum of
gasLimit_ multiplied by maxFeePerGas_ and maxSubmissionCost_.
Retryable ticket's submission fee is not charged when ERC20 token is used to pay for fees (see https://github.com/OffchainLabs/nitro-contracts/blob/v3.1.0/src/bridge/ERC20Inbox.sol#L118).
function createRetryableTicket(
address to_,
uint256 l2CallValue_,
uint256 maxSubmissionCost_,
address excessFeeRefundAddress_,
address callValueRefundAddress_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 tokenTotalFeeAmount_,
bytes calldata data_
) external returns (uint256 messageNumber_);
Parameters
| Name | Type | Description |
|---|---|---|
to_ | address | Destination L2 contract address. |
l2CallValue_ | uint256 | Call value for retryable L2 message. |
maxSubmissionCost_ | uint256 | Max gas deducted from user's L2 balance to cover base submission fee (denominated in app chain's gas token's 18 decimals). |
excessFeeRefundAddress_ | address | The address which receives the difference between execution fee paid and the actual execution cost. In case this address is a contract, funds will be received in its alias on L2. |
callValueRefundAddress_ | address | L2 call value gets credited here on L2 if retryable txn times out or gets cancelled. In case this address is a contract, funds will be received in its alias on L2. |
gasLimit_ | uint256 | Max gas deducted from user's L2 balance to cover L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error). |
maxFeePerGas_ | uint256 | Price bid for L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error). |
tokenTotalFeeAmount_ | uint256 | The amount of fees to be deposited in native token to cover for retryable ticket cost (denominated in native token's decimals). |
data_ | bytes | ABI encoded data of L2 message. |
Returns
| Name | Type | Description |
|---|---|---|
messageNumber_ | uint256 | The message number of the retryable transaction. |
depositERC20
Deposits an ERC20 token into the L2 inbox, to be sent to the L3 where it is the gas token of that chain.
function depositERC20(uint256 amount_) external returns (uint256 messageNumber_);
calculateRetryableSubmissionFee
Calculates the submission fee for a retryable ticket.
function calculateRetryableSubmissionFee(uint256 dataLength_, uint256 baseFee_)
external
view
returns (uint256 submissionFee_);
IAppChainGatewayLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
receiveDeposit
function receiveDeposit(address recipient_) external payable;
receiveParameters
function receiveParameters(uint256 nonce_, string[] calldata keys_, bytes32[] calldata values_) external;
INodeRegistryLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
canonicalNodesCount
function canonicalNodesCount() external view returns (uint8 canonicalNodesCount_);
getIsCanonicalNode
function getIsCanonicalNode(uint32 nodeId_) external view returns (bool isCanonicalNode_);
getSigner
function getSigner(uint32 nodeId_) external view returns (address signer_);
ownerOf
function ownerOf(uint256 nodeId_) external view returns (address owner_);
IPayerRegistryLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
deposit
function deposit(address payer_, uint96 amount_) external;
settleUsage
function settleUsage(bytes32 payerReportId_, PayerFee[] calldata payerFees_) external returns (uint96 feesSettled_);
sendExcessToFeeDistributor
function sendExcessToFeeDistributor() external returns (uint96 excess_);
Structs
PayerFee
struct PayerFee {
address payer;
uint96 fee;
}
IPayerReportManagerLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
getPayerReports
function getPayerReports(uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
view
returns (PayerReport[] memory payerReports_);
Structs
PayerReport
struct PayerReport {
uint64 startSequenceId;
uint64 endSequenceId;
uint96 feesSettled;
uint32 offset;
bool isSettled;
uint16 protocolFeeRate;
bytes32 payersMerkleRoot;
uint32[] nodeIds;
}
IPermitErc20Like
This is the minimal interface needed by contracts within this subdirectory.
Functions
permit
function permit(address owner_, address spender_, uint256 value_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
external;
IFeeTokenLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
deposit
function deposit(uint256 amount_) external;
withdrawTo
function withdrawTo(address recipient_, uint256 amount_) external returns (bool success_);
underlying
function underlying() external view returns (address underlying_);
ISettlementChainGatewayLike
This is the minimal interface needed by contracts within this subdirectory.
Functions
deposit
function deposit(uint256 chainId_, address recipient_, uint256 amount_, uint256 gasLimit_, uint256 maxFeePerGas_)
external;
IDepositSplitter
This interface exposes functionality for splitting deposits between the Payer Registry and App Chain.
Functions
deposit
Deposits payerRegistryAmount_ fee tokens into the Payer Registry for payer_, and appChainAmount_
fee tokens into the App Chain for appChainRecipient_.
function deposit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
payerRegistryAmount_ | uint96 | The amount of fee tokens to deposit into the Payer Registry. |
appChainRecipient_ | address | The address of the recipient on the AppChain. |
appChainAmount_ | uint96 | The amount of fee tokens to deposit into the AppChain. |
appChainGasLimit_ | uint256 | The gas limit for the AppChain deposit. |
appChainMaxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the AppChain deposit. |
depositWithPermit
Deposits payerRegistryAmount_ fee tokens into the Payer Registry for payer_, and appChainAmount_
fee tokens into the App Chain for appChainRecipient_.
function depositWithPermit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
payerRegistryAmount_ | uint96 | The amount of fee tokens to deposit into the Payer Registry. |
appChainRecipient_ | address | The address of the recipient on the AppChain. |
appChainAmount_ | uint96 | The amount of fee tokens to deposit into the AppChain. |
appChainGasLimit_ | uint256 | The gas limit for the AppChain deposit. |
appChainMaxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the AppChain deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFromUnderlying
Deposits payerRegistryAmount_ fee tokens into the Payer Registry for payer_, and appChainAmount_
fee tokens into the App Chain for appChainRecipient_, wrapping them from underlying fee tokens.
function depositFromUnderlying(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
payerRegistryAmount_ | uint96 | The amount of fee tokens to deposit into the Payer Registry. |
appChainRecipient_ | address | The address of the recipient on the AppChain. |
appChainAmount_ | uint96 | The amount of fee tokens to deposit into the AppChain. |
appChainGasLimit_ | uint256 | The gas limit for the AppChain deposit. |
appChainMaxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the AppChain deposit. |
depositFromUnderlyingWithPermit
Deposits payerRegistryAmount_ fee tokens into the Payer Registry for payer_, and appChainAmount_
fee tokens into the App Chain for appChainRecipient_, wrapping them from underlying fee tokens.
function depositFromUnderlyingWithPermit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
payerRegistryAmount_ | uint96 | The amount of fee tokens to deposit into the Payer Registry. |
appChainRecipient_ | address | The address of the recipient on the AppChain. |
appChainAmount_ | uint96 | The amount of fee tokens to deposit into the AppChain. |
appChainGasLimit_ | uint256 | The gas limit for the AppChain deposit. |
appChainMaxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the AppChain deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
appChainId
The app chain ID.
function appChainId() external view returns (uint256 appChainId_);
feeToken
The address of the fee token contract used for deposits.
function feeToken() external view returns (address feeToken_);
payerRegistry
The address of the payer registry.
function payerRegistry() external view returns (address payerRegistry_);
settlementChainGateway
The address of the settlement chain gateway.
function settlementChainGateway() external view returns (address settlementChainGateway_);
Errors
TransferFromFailed
Thrown when the ERC20.transferFrom call fails.
This is an identical redefinition of SafeTransferLib.TransferFromFailed.
error TransferFromFailed();
ZeroFeeToken
Thrown when the fee token is the zero address.
error ZeroFeeToken();
ZeroPayerRegistry
Thrown when the payer registry is the zero address.
error ZeroPayerRegistry();
ZeroSettlementChainGateway
Thrown when the settlement chain gateway is the zero address.
error ZeroSettlementChainGateway();
ZeroAppChainId
Thrown when the app chain ID is zero.
error ZeroAppChainId();
ZeroTotalAmount
Thrown when the total amount is zero.
error ZeroTotalAmount();
IDistributionManager
Inherits: IMigratable, IRegistryParametersErrors
This interface exposes functionality for distributing fees.
Functions
initialize
Initializes the contract.
function initialize() external;
claimProtocolFees
Claims protocol fees.
function claimProtocolFees(uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
returns (uint96 claimed_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeIds_ | uint32[] | The IDs of the originator nodes of the payer reports. |
payerReportIndices_ | uint256[] | The payer report indices for each of the respective originator node IDs. |
Returns
| Name | Type | Description |
|---|---|---|
claimed_ | uint96 | The amount of protocol fees claimed. |
claim
Claims fees for a node for an array of payer reports.
The node IDs in originatorNodeIds_ don't need to be unique.
function claim(uint32 nodeId_, uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
returns (uint96 claimed_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
originatorNodeIds_ | uint32[] | The IDs of the originator nodes of the payer reports. |
payerReportIndices_ | uint256[] | The payer report indices for each of the respective originator node IDs. |
Returns
| Name | Type | Description |
|---|---|---|
claimed_ | uint96 | The amount of fees claimed. |
withdrawProtocolFees
Withdraws protocol fees.
function withdrawProtocolFees() external returns (uint96 withdrawn_);
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of protocol fees withdrawn. |
withdrawProtocolFeesIntoUnderlying
Withdraws protocol fees, unwrapped as underlying token.
function withdrawProtocolFeesIntoUnderlying() external returns (uint96 withdrawn_);
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of protocol fees withdrawn. |
withdraw
Withdraws fees for a node.
function withdraw(uint32 nodeId_, address recipient_) external returns (uint96 withdrawn_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
recipient_ | address | The address to withdraw the fee tokens to. |
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of fee tokens withdrawn. |
withdrawIntoUnderlying
Withdraws fees for a node, unwrapped as underlying fee token.
function withdrawIntoUnderlying(uint32 nodeId_, address recipient_) external returns (uint96 withdrawn_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
recipient_ | address | The address to withdraw the underlying fee tokens to. |
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of fee tokens withdrawn. |
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
updateProtocolFeesRecipient
Updates the protocol fees recipient.
function updateProtocolFeesRecipient() external;
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() external pure returns (string memory key_);
protocolFeesRecipientParameterKey
The parameter registry key used to fetch the protocol fees recipient.
function protocolFeesRecipientParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
nodeRegistry
The address of the node registry.
function nodeRegistry() external view returns (address nodeRegistry_);
payerReportManager
The address of the payer report manager.
function payerReportManager() external view returns (address payerReportManager_);
payerRegistry
The address of the payer registry.
function payerRegistry() external view returns (address payerRegistry_);
feeToken
The address of the fee token.
function feeToken() external view returns (address feeToken_);
protocolFeesRecipient
The address of the protocol fees recipient.
function protocolFeesRecipient() external view returns (address protocolFeesRecipient_);
owedProtocolFees
The amount of claimed protocol fees owed to the protocol.
function owedProtocolFees() external view returns (uint96 owedProtocolFees_);
totalOwedFees
The total amount of fees owed.
function totalOwedFees() external view returns (uint96 totalOwedFees_);
paused
The pause status.
function paused() external view returns (bool paused_);
getOwedFees
Returns the amount of claimed fees owed to a node.
function getOwedFees(uint32 nodeId_) external view returns (uint96 owedFees_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
Returns
| Name | Type | Description |
|---|---|---|
owedFees_ | uint96 | The amount of fees owed. |
areProtocolFeesClaimed
Returns whether protocol fees associated with a settled payer report have been claimed.
function areProtocolFeesClaimed(uint32 originatorNodeId_, uint256 payerReportIndex_)
external
view
returns (bool areClaimed_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The ID of the originator node of the payer report. |
payerReportIndex_ | uint256 | The index of the payer report. |
Returns
| Name | Type | Description |
|---|---|---|
areClaimed_ | bool | Whether protocol fees associated with a settled payer report have been claimed. |
areFeesClaimed
Returns whether a node has claimed fees associated with a settled payer report.
function areFeesClaimed(uint32 nodeId_, uint32 originatorNodeId_, uint256 payerReportIndex_)
external
view
returns (bool areClaimed_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
originatorNodeId_ | uint32 | The ID of the originator node of the payer report. |
payerReportIndex_ | uint256 | The index of the payer report. |
Returns
| Name | Type | Description |
|---|---|---|
areClaimed_ | bool | Whether the node has claimed fees associated with a settled payer report. |
Events
ProtocolFeesClaim
Emitted when protocol fees are claimed.
event ProtocolFeesClaim(uint32 indexed originatorNodeId, uint256 indexed payerReportIndex, uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId | uint32 | The ID of the originator node of the payer report. |
payerReportIndex | uint256 | The index of the payer report. |
amount | uint96 | The amount of protocol fees claimed. |
Claim
Emitted when a claim is made.
event Claim(uint32 indexed nodeId, uint32 indexed originatorNodeId, uint256 indexed payerReportIndex, uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The ID of the node. |
originatorNodeId | uint32 | The ID of the originator node of the payer report. |
payerReportIndex | uint256 | The index of the payer report. |
amount | uint96 | The amount of fees claimed. |
ProtocolFeesWithdrawal
Emitted when protocol fees are withdrawn.
event ProtocolFeesWithdrawal(uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint96 | The amount of protocol fees withdrawn. |
Withdrawal
Emitted when a withdrawal of owed fees is made.
event Withdrawal(uint32 indexed nodeId, uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The ID of the node. |
amount | uint96 | The amount of tokens withdrawn. |
PauseStatusUpdated
Emitted when the pause status is set.
event PauseStatusUpdated(bool indexed paused);
Parameters
| Name | Type | Description |
|---|---|---|
paused | bool | The new pause status. |
ProtocolFeesRecipientUpdated
Emitted when the protocol fees recipient is updated.
event ProtocolFeesRecipientUpdated(address protocolFeesRecipient);
Parameters
| Name | Type | Description |
|---|---|---|
protocolFeesRecipient | address | The new protocol fees recipient. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is being set to zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroNodeRegistry
Thrown when the node registry address is being set to zero (i.e. address(0)).
error ZeroNodeRegistry();
ZeroPayerReportManager
Thrown when the payer report manager address is being set to zero (i.e. address(0)).
error ZeroPayerReportManager();
ZeroPayerRegistry
Thrown when the payer registry address is being set to zero (i.e. address(0)).
error ZeroPayerRegistry();
ZeroFeeToken
Thrown when the fee token address is being set to zero (i.e. address(0)).
error ZeroFeeToken();
NotNodeOwner
Thrown when the caller is not the owner of the specified node.
error NotNodeOwner();
ArrayLengthMismatch
Thrown when the lengths of input arrays don't match.
error ArrayLengthMismatch();
AlreadyClaimed
Thrown when a payer report has already been claimed.
error AlreadyClaimed(uint32 originatorNodeId, uint256 payerReportIndex);
PayerReportNotSettled
Thrown when the payer report is not settled.
error PayerReportNotSettled(uint32 originatorNodeId, uint256 payerReportIndex);
NotInPayerReport
Thrown when the node ID is not in a payer report.
error NotInPayerReport(uint32 originatorNodeId, uint256 payerReportIndex);
ZeroRecipient
Thrown when the recipient address is zero (i.e. address(0)).
error ZeroRecipient();
NoFeesOwed
Thrown when the node has no fees owed.
error NoFeesOwed();
ZeroAvailableBalance
Thrown when the contract's available balance is zero.
error ZeroAvailableBalance();
Paused
Thrown when any pausable function is called when the contract is paused.
error Paused();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
ZeroProtocolFeeRecipient
Thrown when the protocol fees recipient address is zero (i.e. address(0)).
error ZeroProtocolFeeRecipient();
IFeeToken
Inherits: IERC20, IERC20Metadata, IERC20Errors, IMigratable, IRegistryParametersErrors
This interface exposes functionality for wrapping and unwrapping tokens for use as fees in the protocol.
Functions
initialize
Initializes the contract.
function initialize() external;
permit
Sets value_ as the allowance of spender_ over owner_'s tokens, given `owner_'s signed approval.
function permit(address owner_, address spender_, uint256 value_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
external;
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
spender_ | address | The spender of the tokens. |
value_ | uint256 | The value of the tokens. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
deposit
Deposits amount_ of the underlying token.
function deposit(uint256 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of the underlying token to deposit. |
depositWithPermit
Deposits amount_ of the underlying token, given owner_'s signed approval.
The permit signature must be for the underlying token, not for this token.
function depositWithPermit(uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of the underlying token to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFor
Deposits amount_ of the underlying token for recipient_.
This function conforms to ERC20Wrapper.depositFor.
function depositFor(address recipient_, uint256 amount_) external returns (bool success_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying token. |
amount_ | uint256 | The amount of the underlying token to deposit. |
depositForWithPermit
Deposits amount_ of the underlying token for recipient_, given owner_'s signed approval.
The permit signature must be for the underlying token, not for this token.
This function conforms to ERC20Wrapper.depositFor.
function depositForWithPermit(address recipient_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
external
returns (bool success_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying token. |
amount_ | uint256 | The amount of the underlying token to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
withdraw
Withdraws amount_ of the underlying token.
function withdraw(uint256 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of the underlying token to withdraw. |
withdrawTo
Withdraws amount_ of the underlying token for recipient_.
This function conforms to ERC20Wrapper.withdrawTo.
function withdrawTo(address recipient_, uint256 amount_) external returns (bool success_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying token. |
amount_ | uint256 | The amount of the underlying token to withdraw. |
DOMAIN_SEPARATOR
Returns the EIP712 domain separator used in the encoding of a signed digest.
function DOMAIN_SEPARATOR() external view returns (bytes32 domainSeparator_);
PERMIT_TYPEHASH
Returns the EIP712 typehash used in the encoding of a signed digest for a permit.
function PERMIT_TYPEHASH() external pure returns (bytes32 permitTypehash_);
underlying
Returns the address of the underlying token.
function underlying() external view returns (address underlying_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
getPermitDigest
Returns the EIP-712 digest for a permit.
function getPermitDigest(address owner_, address spender_, uint256 value_, uint256 nonce_, uint256 deadline_)
external
view
returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
spender_ | address | The spender of the tokens. |
value_ | uint256 | The value of the tokens. |
nonce_ | uint256 | The nonce of the permit signature. |
deadline_ | uint256 | The deadline of the permit signature. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The EIP-712 digest. |
nonces
Returns the current nonce for owner_ that must be included for the next valid permit signature.
function nonces(address owner_) external view returns (uint256 nonce_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
Returns
| Name | Type | Description |
|---|---|---|
nonce_ | uint256 | The nonce of the owner. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is being set to zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroUnderlying
Thrown when the underlying token address is being set to zero (i.e. address(0)).
error ZeroUnderlying();
ZeroAmount
Thrown when the amount to deposit or withdraw is zero.
error ZeroAmount();
ZeroRecipient
Thrown when the recipient address is zero (i.e. address(0)).
error ZeroRecipient();
TransferFailed
Thrown when the ERC20.transfer call fails.
This is an identical redefinition of SafeTransferLib.TransferFailed.
error TransferFailed();
TransferFromFailed
Thrown when the ERC20.transferFrom call fails.
This is an identical redefinition of SafeTransferLib.TransferFromFailed.
error TransferFromFailed();
INodeRegistry
Inherits: IERC721, IERC721Metadata, IERC721Errors, IMigratable, IRegistryParametersErrors
This interface defines the ERC721-based registry for “nodes” in the system. Each node is minted as an NFT with a unique ID (starting at 100 and increasing by 100 with each new node). In addition to the standard ERC721 functionality, the contract supports node-specific features, including node property updates.
Functions
initialize
Initializes the contract.
function initialize() external;
addNode
Adds a new node to the registry and mints its corresponding ERC721 token.
Node IDs start at 100 and increase by 100 for each new node.
function addNode(address owner_, bytes calldata signingPublicKey_, string calldata httpAddress_)
external
returns (uint32 nodeId_, address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The address that will own the new node node/NFT. |
signingPublicKey_ | bytes | The public key used for node signing/verification. |
httpAddress_ | string | The node’s HTTP address. |
Returns
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the newly added node. |
signer_ | address | The address derived by the signing public key, for convenience. |
addToNetwork
Adds a node to the canonical network.
function addToNetwork(uint32 nodeId_) external;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
removeFromNetwork
Removes a node from the canonical network.
function removeFromNetwork(uint32 nodeId_) external;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
setBaseURI
Set the base URI for the node NFTs.
function setBaseURI(string calldata baseURI_) external;
Parameters
| Name | Type | Description |
|---|---|---|
baseURI_ | string | The new base URI. Has to end with a trailing slash. |
setHttpAddress
Set the HTTP address of an existing node.
function setHttpAddress(uint32 nodeId_, string calldata httpAddress_) external;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
httpAddress_ | string | The new HTTP address. |
updateAdmin
Updates the admin by referring to the admin parameter from the parameter registry.
function updateAdmin() external;
updateMaxCanonicalNodes
Updates the max canonical nodes by referring to the max canonical nodes parameter from the parameter registry.
function updateMaxCanonicalNodes() external;
NODE_INCREMENT
The increment for node IDs, which allows for 100 shard node IDs per node in the future (modulus 100).
function NODE_INCREMENT() external pure returns (uint32 nodeIncrement_);
admin
The address of the admin.
function admin() external view returns (address admin_);
adminParameterKey
The parameter registry key used to fetch the admin.
function adminParameterKey() external pure returns (string memory key_);
maxCanonicalNodesParameterKey
The parameter registry key used to fetch the max canonical nodes.
function maxCanonicalNodesParameterKey() external pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
maxCanonicalNodes
The maximum number of nodes that can be part of the canonical network.
function maxCanonicalNodes() external view returns (uint8 maxCanonicalNodes_);
canonicalNodesCount
The number of nodes that are part of the canonical network.
function canonicalNodesCount() external view returns (uint8 canonicalNodesCount_);
getAllNodes
Gets all nodes regardless of their health status.
function getAllNodes() external view returns (NodeWithId[] memory allNodes_);
Returns
| Name | Type | Description |
|---|---|---|
allNodes_ | NodeWithId[] | An array of all nodes in the registry. |
getAllNodesCount
Gets the total number of nodes in the registry.
function getAllNodesCount() external view returns (uint32 nodeCount_);
Returns
| Name | Type | Description |
|---|---|---|
nodeCount_ | uint32 | The total number of nodes. |
getNode
Retrieves the details of a given node.
function getNode(uint32 nodeId_) external view returns (Node memory node_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
node_ | Node | The Node struct containing the node's details. |
getIsCanonicalNode
Retrieves whether a node is part of the canonical network.
function getIsCanonicalNode(uint32 nodeId_) external view returns (bool isCanonicalNode_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
isCanonicalNode_ | bool | A boolean indicating whether the node is part of the canonical network. |
getSigner
Retrieves the signer of a node.
function getSigner(uint32 nodeId_) external view returns (address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
signer_ | address | The address of the signer. |
Events
AdminUpdated
Emitted when the admin is updated.
event AdminUpdated(address indexed admin);
Parameters
| Name | Type | Description |
|---|---|---|
admin | address | The new admin. |
BaseURIUpdated
Emitted when the base URI is updated.
event BaseURIUpdated(string baseURI);
Parameters
| Name | Type | Description |
|---|---|---|
baseURI | string | The new base URI. |
HttpAddressUpdated
Emitted when the HTTP address for a node is updated.
event HttpAddressUpdated(uint32 indexed nodeId, string httpAddress);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The identifier of the node. |
httpAddress | string | The new HTTP address. |
MaxCanonicalNodesUpdated
Emitted when the maximum number of canonical nodes is updated.
event MaxCanonicalNodesUpdated(uint8 maxCanonicalNodes);
Parameters
| Name | Type | Description |
|---|---|---|
maxCanonicalNodes | uint8 | The new maximum number of canonical nodes. |
NodeAdded
Emitted when a new node is added and its NFT minted.
event NodeAdded(
uint32 indexed nodeId, address indexed owner, address indexed signer, bytes signingPublicKey, string httpAddress
);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The unique identifier for the node (starts at 100, increments by 100). |
owner | address | The address that receives the new node NFT. |
signer | address | The address derived by the signing public key, for convenience. |
signingPublicKey | bytes | The public key used for node signing/verification. |
httpAddress | string | The node’s HTTP endpoint. |
NodeAddedToCanonicalNetwork
Emitted when a node is added to the canonical network.
event NodeAddedToCanonicalNetwork(uint32 indexed nodeId);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The identifier of the node. |
NodeRemovedFromCanonicalNetwork
Emitted when a node is removed from the canonical network.
event NodeRemovedFromCanonicalNetwork(uint32 indexed nodeId);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The identifier of the node. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is being set to zero (i.e. address(0)).
error ZeroParameterRegistry();
FailedToAddNodeToCanonicalNetwork
Thrown when failing to add a node to the canonical network.
error FailedToAddNodeToCanonicalNetwork();
FailedToRemoveNodeFromCanonicalNetwork
Thrown when failing to remove a node from the canonical network.
error FailedToRemoveNodeFromCanonicalNetwork();
InvalidOwner
Thrown when an invalid owner is provided.
error InvalidOwner();
InvalidHttpAddress
Thrown when an invalid HTTP address is provided.
error InvalidHttpAddress();
InvalidSigningPublicKey
Thrown when an invalid signing public key is provided.
error InvalidSigningPublicKey();
InvalidURI
Thrown when an invalid URI is provided.
error InvalidURI();
MaxCanonicalNodesBelowCurrentCount
Thrown when trying to set max canonical nodes below current canonical count.
error MaxCanonicalNodesBelowCurrentCount();
MaxCanonicalNodesReached
Thrown when the maximum number of canonical nodes is reached.
error MaxCanonicalNodesReached();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
NotAdmin
Thrown when the caller is not the admin.
error NotAdmin();
MaxNodesReached
Thrown when the maximum number of nodes is reached.
error MaxNodesReached();
NotNodeOwner
Thrown when the caller is not the node owner.
error NotNodeOwner();
Structs
Node
Struct representing a node in the registry.
struct Node {
address signer;
bool isCanonical;
bytes signingPublicKey;
string httpAddress;
}
Properties
| Name | Type | Description |
|---|---|---|
signer | address | The address derived by the signing public key, for convenience. |
isCanonical | bool | A flag indicating whether the node is part of the canonical network. |
signingPublicKey | bytes | The public key used for node signing/verification. |
httpAddress | string | The HTTP endpoint address for the node. |
NodeWithId
Struct representing a node with its ID.
struct NodeWithId {
uint32 nodeId;
Node node;
}
Properties
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The unique identifier for the node. |
node | Node | The node struct. |
IPayerRegistry
Inherits: IMigratable, IRegistryParametersErrors
This interface exposes functionality:
- for payers to deposit, request withdrawals, and finalize withdrawals of a fee token,
- for some settler contract to settle usage fees for payers,
- for anyone to send excess fee tokens in the contract to the fee distributor.
Functions
initialize
Initializes the contract.
function initialize() external;
deposit
Deposits amount_ fee tokens into the registry for payer_.
function deposit(address payer_, uint96 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of fee tokens to deposit. |
depositWithPermit
Deposits amount_ fee tokens into the registry for payer_, given caller's signed approval.
function depositWithPermit(address payer_, uint96 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of fee tokens to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFromUnderlying
Deposits amount_ fee tokens into the registry for payer_, wrapping them from underlying fee tokens.
function depositFromUnderlying(address payer_, uint96 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of underlying fee tokens to deposit. |
depositFromUnderlyingWithPermit
Deposits amount_ fee tokens into the registry for payer_, wrapping them from underlying fee tokens,
given caller's signed approval.
function depositFromUnderlyingWithPermit(
address payer_,
uint96 amount_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of underlying fee tokens to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
requestWithdrawal
Requests a withdrawal of amount_ fee tokens.
The caller must have enough balance to cover the withdrawal.
function requestWithdrawal(uint96 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint96 | The amount of fee tokens to withdraw. |
cancelWithdrawal
Cancels a pending withdrawal of fee tokens, returning the amount to the balance.
function cancelWithdrawal() external;
finalizeWithdrawal
Finalizes a pending withdrawal of fee tokens, transferring the amount to the recipient.
The caller must not be currently in debt.
function finalizeWithdrawal(address recipient_) external;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to receive the fee tokens. |
finalizeWithdrawalIntoUnderlying
Finalizes a pending withdrawal of fee tokens, unwrapping the amount into underlying fee tokens to the recipient.
The caller must not be currently in debt.
function finalizeWithdrawalIntoUnderlying(address recipient_) external;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to receive the underlying fee tokens. |
settleUsage
Settles the usage fees for a list of payers.
function settleUsage(bytes32 payerReportId_, PayerFee[] calldata payerFees_) external returns (uint96 feesSettled_);
Parameters
| Name | Type | Description |
|---|---|---|
payerReportId_ | bytes32 | The ID of the payer report triggering the settlement. |
payerFees_ | PayerFee[] | An array of structs containing the payer and the fee to settle. |
Returns
| Name | Type | Description |
|---|---|---|
feesSettled_ | uint96 | The total amount of fees settled. |
sendExcessToFeeDistributor
Sends the excess tokens in the contract to the fee distributor.
function sendExcessToFeeDistributor() external returns (uint96 excess_);
Returns
| Name | Type | Description |
|---|---|---|
excess_ | uint96 | The amount of excess tokens sent to the fee distributor. |
updateSettler
Updates the settler of the contract.
Ensures the new settler is not zero (i.e. address(0)).
function updateSettler() external;
updateFeeDistributor
Updates the fee distributor of the contract.
Ensures the new fee distributor is not zero (i.e. address(0)).
function updateFeeDistributor() external;
updateMinimumDeposit
Updates the minimum deposit amount.
Ensures the new minimum deposit is not zero (i.e. address(0)).
function updateMinimumDeposit() external;
updateWithdrawLockPeriod
Updates the withdraw lock period.
function updateWithdrawLockPeriod() external;
updatePauseStatus
Updates the pause status.
function updatePauseStatus() external;
settlerParameterKey
The parameter registry key used to fetch the settler.
function settlerParameterKey() external pure returns (string memory key_);
feeDistributorParameterKey
The parameter registry key used to fetch the fee distributor.
function feeDistributorParameterKey() external pure returns (string memory key_);
minimumDepositParameterKey
The parameter registry key used to fetch the minimum deposit.
function minimumDepositParameterKey() external pure returns (string memory key_);
withdrawLockPeriodParameterKey
The parameter registry key used to fetch the withdraw lock period.
function withdrawLockPeriodParameterKey() external pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() external pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
feeToken
The address of the fee token contract used for deposits and withdrawals.
function feeToken() external view returns (address feeToken_);
settler
The address of the settler that can call settleUsage.
function settler() external view returns (address settler_);
feeDistributor
The address of the fee distributor that receives unencumbered fees from usage settlements.
function feeDistributor() external view returns (address feeDistributor_);
totalDeposits
The sum of all payer balances and pending withdrawals.
function totalDeposits() external view returns (int104 totalDeposits_);
paused
The pause status.
function paused() external view returns (bool paused_);
totalDebt
The sum of all payer debts.
function totalDebt() external view returns (uint96 totalDebt_);
totalWithdrawable
The sum of all withdrawable balances (sum of all positive payer balances and pending withdrawals).
function totalWithdrawable() external view returns (uint96 totalWithdrawable_);
minimumDeposit
The minimum amount required for any deposit.
function minimumDeposit() external view returns (uint96 minimumDeposit_);
withdrawLockPeriod
The withdraw lock period.
function withdrawLockPeriod() external view returns (uint32 withdrawLockPeriod_);
excess
The amount of excess tokens in the contract that are not withdrawable by payers.
function excess() external view returns (uint96 excess_);
getBalance
Returns the balance of a payer.
function getBalance(address payer_) external view returns (int104 balance_);
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
Returns
| Name | Type | Description |
|---|---|---|
balance_ | int104 | The signed balance of the payer (negative if debt). |
getBalances
Returns the balances of an array of payers.
This is a periphery function for nodes, and is not required for the core protocol.
function getBalances(address[] calldata payers_) external view returns (int104[] memory balances_);
Parameters
| Name | Type | Description |
|---|---|---|
payers_ | address[] | An array of payer addresses. |
Returns
| Name | Type | Description |
|---|---|---|
balances_ | int104[] | The signed balances of each payer (negative if debt). |
getPendingWithdrawal
Returns the pending withdrawal of a payer.
function getPendingWithdrawal(address payer_)
external
view
returns (uint96 pendingWithdrawal_, uint32 withdrawableTimestamp_, uint24 nonce_);
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
Returns
| Name | Type | Description |
|---|---|---|
pendingWithdrawal_ | uint96 | The amount of a pending withdrawal, if any. |
withdrawableTimestamp_ | uint32 | The timestamp when the pending withdrawal can be finalized. |
nonce_ | uint24 | The nonce associated with the pending withdrawal. |
Events
SettlerUpdated
Emitted when the settler is updated.
event SettlerUpdated(address indexed settler);
Parameters
| Name | Type | Description |
|---|---|---|
settler | address | The address of the new settler. |
FeeDistributorUpdated
Emitted when the fee distributor is updated.
event FeeDistributorUpdated(address indexed feeDistributor);
Parameters
| Name | Type | Description |
|---|---|---|
feeDistributor | address | The address of the new fee distributor. |
MinimumDepositUpdated
Emitted when the minimum deposit is updated.
event MinimumDepositUpdated(uint96 minimumDeposit);
Parameters
| Name | Type | Description |
|---|---|---|
minimumDeposit | uint96 | The new minimum deposit amount. |
WithdrawLockPeriodUpdated
Emitted when the withdraw lock period is updated.
event WithdrawLockPeriodUpdated(uint32 withdrawLockPeriod);
Parameters
| Name | Type | Description |
|---|---|---|
withdrawLockPeriod | uint32 | The new withdraw lock period. |
Deposit
Emitted when a deposit of fee tokens occurs for a payer.
event Deposit(address indexed payer, uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
payer | address | The address of the payer. |
amount | uint96 | The amount of fee tokens deposited. |
WithdrawalRequested
Emitted when a withdrawal is requested by a payer.
event WithdrawalRequested(address indexed payer, uint96 amount, uint32 withdrawableTimestamp, uint24 nonce);
Parameters
| Name | Type | Description |
|---|---|---|
payer | address | The address of the payer. |
amount | uint96 | The amount of fee tokens requested for withdrawal. |
withdrawableTimestamp | uint32 | The timestamp when the withdrawal can be finalized. |
nonce | uint24 | The nonce associated with the requested withdrawal. |
WithdrawalCancelled
Emitted when a payer's pending withdrawal is cancelled.
event WithdrawalCancelled(address indexed payer, uint24 nonce);
Parameters
| Name | Type | Description |
|---|---|---|
payer | address | The address of the payer. |
nonce | uint24 | The nonce associated with the cancelled withdrawal. |
WithdrawalFinalized
Emitted when a payer's pending withdrawal is finalized.
event WithdrawalFinalized(address indexed payer, uint24 nonce);
Parameters
| Name | Type | Description |
|---|---|---|
payer | address | The address of the payer. |
nonce | uint24 | The nonce associated with the finalized withdrawal. |
UsageSettled
Emitted when a payer's usage is settled.
event UsageSettled(bytes32 indexed payerReportId, address indexed payer, uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
payerReportId | bytes32 | The ID of the payer report triggering the settlement. |
payer | address | The address of the payer. |
amount | uint96 | The amount of fee tokens settled (the fee deducted from their balance). |
ExcessTransferred
Emitted when excess fee tokens are transferred to the fee distributor.
event ExcessTransferred(uint96 amount);
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint96 | The amount of excess fee tokens transferred. |
PauseStatusUpdated
Emitted when the pause status is set.
event PauseStatusUpdated(bool indexed paused);
Parameters
| Name | Type | Description |
|---|---|---|
paused | bool | The new pause status. |
Errors
NotSettler
Thrown when caller is not the settler.
error NotSettler();
ZeroParameterRegistry
Thrown when the parameter registry address is being set to zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroFeeToken
Thrown when the fee token address is being set to zero (i.e. address(0)).
error ZeroFeeToken();
ZeroSettler
Thrown when the settler address is being set to zero (i.e. address(0)).
error ZeroSettler();
ZeroFeeDistributor
Thrown when the fee distributor address is zero (i.e. address(0)).
error ZeroFeeDistributor();
ZeroMinimumDeposit
Thrown when the minimum deposit is being set to 0.
error ZeroMinimumDeposit();
TransferFromFailed
Thrown when the ERC20.transferFrom call fails.
This is an identical redefinition of SafeTransferLib.TransferFromFailed.
error TransferFromFailed();
InsufficientDeposit
Thrown when the deposit amount is less than the minimum deposit.
error InsufficientDeposit(uint96 amount, uint96 minimumDeposit);
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint96 | The amount of fee tokens being deposited. |
minimumDeposit | uint96 | The minimum deposit amount. |
InsufficientBalance
Thrown when a payer has insufficient balance for a withdrawal request.
error InsufficientBalance();
ZeroWithdrawalAmount
Thrown when a withdrawal request of zero is made.
error ZeroWithdrawalAmount();
PendingWithdrawalExists
Thrown when a withdrawal is pending for a payer.
error PendingWithdrawalExists();
NoPendingWithdrawal
Thrown when a withdrawal is not pending for a payer.
error NoPendingWithdrawal();
WithdrawalNotReady
Thrown when trying to finalize a withdrawal before the withdraw lock period has passed.
error WithdrawalNotReady(uint32 timestamp, uint32 withdrawableTimestamp, uint24 nonce);
Parameters
| Name | Type | Description |
|---|---|---|
timestamp | uint32 | The current timestamp. |
withdrawableTimestamp | uint32 | The timestamp when the withdrawal can be finalized. |
nonce | uint24 | The nonce associated with the pending withdrawal. |
PayerInDebt
Thrown when trying to finalize a withdrawal while in debt.
error PayerInDebt();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
Paused
Thrown when any pausable function is called when the contract is paused.
error Paused();
NoExcess
Thrown when there is no excess fee tokens to transfer to the fee distributor.
error NoExcess();
ZeroPayer
Thrown when the payer is the zero address.
error ZeroPayer();
ZeroRecipient
Thrown when the recipient is the zero address.
error ZeroRecipient();
Structs
Payer
Represents a payer in the registry.
struct Payer {
int104 balance;
uint96 pendingWithdrawal;
uint32 withdrawableTimestamp;
uint24 withdrawalNonce;
}
Properties
| Name | Type | Description |
|---|---|---|
balance | int104 | The signed balance of the payer (negative if debt). |
pendingWithdrawal | uint96 | The amount of a pending withdrawal, if any. |
withdrawableTimestamp | uint32 | The timestamp when the pending withdrawal can be finalized. |
withdrawalNonce | uint24 | The nonce associated with the pending withdrawal. Used for offchain tracking. |
PayerFee
Represents a payer and their fee.
struct PayerFee {
address payer;
uint96 fee;
}
Properties
| Name | Type | Description |
|---|---|---|
payer | address | The address a payer. |
fee | uint96 | The fee to settle for the payer. |
IPayerReportManager
Inherits: IMigratable, IERC5267, IRegistryParametersErrors, ISequentialMerkleProofsErrors
This interface exposes functionality for submitting and settling payer reports.
Functions
initialize
Initializes the contract.
function initialize() external;
submit
Submits a payer report.
function submit(
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] calldata nodeIds_,
PayerReportSignature[] calldata signatures_
) external returns (uint256 payerReportIndex_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
startSequenceId_ | uint64 | The start sequence ID. |
endSequenceId_ | uint64 | The end sequence ID. |
endMinuteSinceEpoch_ | uint32 | The timestamp of the message at endSequenceId. |
payersMerkleRoot_ | bytes32 | The payers Merkle root. |
nodeIds_ | uint32[] | The active node IDs during the reporting period. |
signatures_ | PayerReportSignature[] | The signature objects for the payer report. |
Returns
| Name | Type | Description |
|---|---|---|
payerReportIndex_ | uint256 | The index of the payer report in the originator's payer report array. |
settle
Settles a subset of a payer report.
function settle(
uint32 originatorNodeId_,
uint256 payerReportIndex_,
bytes[] calldata payerFees_,
bytes32[] calldata proofElements_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
payerReportIndex_ | uint256 | The payer report index. |
payerFees_ | bytes[] | The sequential payer fees to settle. |
proofElements_ | bytes32[] | The sequential Merkle proof elements for the payer fees to settle. |
updateProtocolFeeRate
Updates the protocol fee rate.
function updateProtocolFeeRate() external;
PAYER_REPORT_TYPEHASH
Returns the EIP712 typehash used in the encoding of a signed digest for a payer report.
function PAYER_REPORT_TYPEHASH() external pure returns (bytes32 payerReportTypehash_);
ONE_HUNDRED_PERCENT
One hundred percent (in basis points).
function ONE_HUNDRED_PERCENT() external pure returns (uint16 oneHundredPercent_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
protocolFeeRateParameterKey
The parameter registry key used to fetch the protocol fee rate.
function protocolFeeRateParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
nodeRegistry
The address of the node registry.
function nodeRegistry() external view returns (address nodeRegistry_);
payerRegistry
The address of the payer registry.
function payerRegistry() external view returns (address payerRegistry_);
protocolFeeRate
The protocol fee rate (in basis points).
function protocolFeeRate() external view returns (uint16 protocolFeeRate_);
getPayerReports
Returns an array of specific payer reports.
The node IDs in originatorNodeIds_ don't need to be unique.
function getPayerReports(uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
view
returns (PayerReport[] memory payerReports_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeIds_ | uint32[] | An array of originator node IDs. |
payerReportIndices_ | uint256[] | An array of payer report indices for each of the respective originator node IDs. |
Returns
| Name | Type | Description |
|---|---|---|
payerReports_ | PayerReport[] | The array of payer reports. |
getPayerReport
Returns a payer report.
function getPayerReport(uint32 originatorNodeId_, uint256 payerReportIndex_)
external
view
returns (PayerReport memory payerReport_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
payerReportIndex_ | uint256 | The payer report index. |
Returns
| Name | Type | Description |
|---|---|---|
payerReport_ | PayerReport | The payer report. |
getPayerReportDigest
Returns the EIP-712 digest for a payer report.
function getPayerReportDigest(
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] calldata nodeIds_
) external view returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
startSequenceId_ | uint64 | The start sequence ID. |
endSequenceId_ | uint64 | The end sequence ID. |
endMinuteSinceEpoch_ | uint32 | The timestamp of the message at endSequenceId. |
payersMerkleRoot_ | bytes32 | The payers Merkle root. |
nodeIds_ | uint32[] | The active node IDs during the reporting period. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The EIP-712 digest. |
Events
PayerReportSubmitted
Emitted when a payer report is submitted.
event PayerReportSubmitted(
uint32 indexed originatorNodeId,
uint256 indexed payerReportIndex,
uint64 startSequenceId,
uint64 indexed endSequenceId,
uint32 endMinuteSinceEpoch,
bytes32 payersMerkleRoot,
uint32[] nodeIds,
uint32[] signingNodeIds
);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId | uint32 | The originator node ID. |
payerReportIndex | uint256 | The index of the newly stored report. |
startSequenceId | uint64 | The start sequence ID. |
endSequenceId | uint64 | The end sequence ID. |
endMinuteSinceEpoch | uint32 | The timestamp of the message at endSequenceId. |
payersMerkleRoot | bytes32 | The payers Merkle root. |
nodeIds | uint32[] | The active node IDs during the reporting period. |
signingNodeIds | uint32[] | The node IDs of the signers of the payer report. |
PayerReportSubsetSettled
Emitted when a subset of a payer report is settled.
event PayerReportSubsetSettled(
uint32 indexed originatorNodeId,
uint256 indexed payerReportIndex,
uint32 count,
uint32 remaining,
uint96 feesSettled
);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId | uint32 | The originator node ID. |
payerReportIndex | uint256 | The payer report index. |
count | uint32 | The number of payer fees settled in this subset. |
remaining | uint32 | The number of payer fees remaining to be settled. |
feesSettled | uint96 | The amount of fees settled in this subset. |
ProtocolFeeRateUpdated
Emitted when the protocol fee rate is updated.
event ProtocolFeeRateUpdated(uint16 protocolFeeRate);
Parameters
| Name | Type | Description |
|---|---|---|
protocolFeeRate | uint16 | The new protocol fee rate. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is being set to zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroNodeRegistry
Thrown when the node registry address is being set to zero (i.e. address(0)).
error ZeroNodeRegistry();
ZeroPayerRegistry
Thrown when the payer registry address is being set to zero (i.e. address(0)).
error ZeroPayerRegistry();
InvalidStartSequenceId
Thrown when the start sequence ID is not the last end sequence ID.
error InvalidStartSequenceId(uint64 startSequenceId, uint64 lastSequenceId);
InvalidSequenceIds
Thrown when the start and end sequence IDs are invalid.
error InvalidSequenceIds();
UnorderedNodeIds
Thrown when the signing node IDs are not ordered and unique.
error UnorderedNodeIds();
InsufficientSignatures
Thrown when the number of valid signatures is insufficient.
error InsufficientSignatures(uint8 validSignatureCount, uint8 requiredSignatureCount);
PayerReportAlreadySubmitted
Thrown when the payer report has already been submitted.
error PayerReportAlreadySubmitted(uint32 originatorNodeId, uint64 startSequenceId, uint64 endSequenceId);
PayerReportIndexOutOfBounds
Thrown when the payer report index is out of bounds.
error PayerReportIndexOutOfBounds();
PayerReportEntirelySettled
Thrown when the payer report has already been entirely settled.
error PayerReportEntirelySettled();
PayerFeesLengthTooLong
Thrown when the length of the payer fees array is too long.
error PayerFeesLengthTooLong();
SettleUsageFailed
Thrown when failing to settle usage via the payer registry.
error SettleUsageFailed(bytes returnData_);
ArrayLengthMismatch
Thrown when the lengths of input arrays don't match.
error ArrayLengthMismatch();
InvalidProtocolFeeRate
Thrown when the protocol fee rate is invalid.
error InvalidProtocolFeeRate();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
NoReportsForOriginator
Thrown when there are no payer reports found for the given originator node ID.
error NoReportsForOriginator(uint32 originatorNodeId);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId | uint32 | The ID of the originator node for which no reports exist. |
NodeIdsLengthMismatch
Thrown when the provided node IDs do not exactly match the registry set.
error NodeIdsLengthMismatch(uint32 expectedCount, uint32 providedCount);
NodeIdAtIndexMismatch
Element at index does not match the canonical node id at that position.
error NodeIdAtIndexMismatch(uint32 expectedId, uint32 actualId, uint32 index);
Structs
PayerReport
Represents a payer report.
struct PayerReport {
uint64 startSequenceId;
uint64 endSequenceId;
uint32 endMinuteSinceEpoch;
uint96 feesSettled;
uint32 offset;
bool isSettled;
uint16 protocolFeeRate;
bytes32 payersMerkleRoot;
uint32[] nodeIds;
}
Properties
| Name | Type | Description |
|---|---|---|
startSequenceId | uint64 | The start sequence ID. |
endSequenceId | uint64 | The end sequence ID. |
endMinuteSinceEpoch | uint32 | The timestamp of the message at endSequenceId. |
feesSettled | uint96 | The total fees already settled for this report. |
offset | uint32 | The next index in the Merkle tree that has yet to be processed/settled. |
isSettled | bool | Whether the payer report is completely processed/settled. |
protocolFeeRate | uint16 | The portion of the fees settled that is reserved for the protocol. |
payersMerkleRoot | bytes32 | The payers Merkle root. |
nodeIds | uint32[] | The active node IDs during the reporting period. |
PayerReportSignature
Represents a payer report signature.
struct PayerReportSignature {
uint32 nodeId;
bytes signature;
}
Properties
| Name | Type | Description |
|---|---|---|
nodeId | uint32 | The node ID. |
signature | bytes | The signature by the node operator. |
IRateRegistry
Inherits: IMigratable, IRegistryParametersErrors
This interface exposes functionality for updating the rates, tracking them historically.
Functions
initialize
Initializes the contract.
function initialize() external;
updateRates
Updates the rates.
function updateRates() external;
getRates
Returns a slice of the Rates list for pagination.
function getRates(uint256 fromIndex_, uint256 count_) external view returns (Rates[] memory rates_);
Parameters
| Name | Type | Description |
|---|---|---|
fromIndex_ | uint256 | Index from which to start (must be < allRates.length). |
count_ | uint256 | The number of items to return. |
Returns
| Name | Type | Description |
|---|---|---|
rates_ | Rates[] | The subset of Rates. |
getRatesCount
The total number of Rates stored.
function getRatesCount() external view returns (uint256 count_);
messageFeeParameterKey
The parameter registry key used to fetch the message fee.
function messageFeeParameterKey() external pure returns (string memory key_);
storageFeeParameterKey
The parameter registry key used to fetch the storage fee.
function storageFeeParameterKey() external pure returns (string memory key_);
congestionFeeParameterKey
The parameter registry key used to fetch the congestion fee.
function congestionFeeParameterKey() external pure returns (string memory key_);
targetRatePerMinuteParameterKey
The parameter registry key used to fetch the target rate per minute.
function targetRatePerMinuteParameterKey() external pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
Events
RatesUpdated
Emitted when the rates are updated.
event RatesUpdated(uint64 messageFee, uint64 storageFee, uint64 congestionFee, uint64 targetRatePerMinute);
Parameters
| Name | Type | Description |
|---|---|---|
messageFee | uint64 | The message fee. |
storageFee | uint64 | The storage fee. |
congestionFee | uint64 | The congestion fee. |
targetRatePerMinute | uint64 | The target rate per minute. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is being set to zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroCount
Thrown when the query count is zero.
error ZeroCount();
FromIndexOutOfRange
Thrown when the fromIndex is out of range.
error FromIndexOutOfRange();
EndIndexOutOfRange
Thrown when the end index (as computed from the fromIndex and count) is out of range.
error EndIndexOutOfRange();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
Structs
Rates
The Rates struct holds the fees and the start time of the rates.
struct Rates {
uint64 messageFee;
uint64 storageFee;
uint64 congestionFee;
uint64 targetRatePerMinute;
uint64 startTime;
}
Properties
| Name | Type | Description |
|---|---|---|
messageFee | uint64 | The message fee. |
storageFee | uint64 | The storage fee. |
congestionFee | uint64 | The congestion fee. |
targetRatePerMinute | uint64 | The target rate per minute. |
startTime | uint64 | The start time when the rates became effective. |
ISettlementChainGateway
Inherits: IMigratable, IRegistryParametersErrors
A SettlementChainGateway exposes the ability to send parameters to any app chain gateways, via their respective inboxes on the settlement chain.
Functions
initialize
Initializes the contract.
function initialize() external;
deposit
Deposits fee tokens as gas token to an app chain.
function deposit(uint256 chainId_, address recipient_, uint256 amount_, uint256 gasLimit_, uint256 maxFeePerGas_)
external;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
depositWithPermit
Deposits fee tokens as gas token to an app chain, given caller's signed approval.
function depositWithPermit(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFromUnderlying
Deposits fee tokens as gas token to an app chain, by wrapping underlying fee tokens.
function depositFromUnderlying(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of underlying fee tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
depositFromUnderlyingWithPermit
Deposits fee tokens as gas token to an app chain, by wrapping underlying fee tokens, given caller's signed approval.
function depositFromUnderlyingWithPermit(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of underlying fee tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
sendParameters
Sends parameters to the app chain as retryable tickets (which may be a direct contract call).
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
amountToSend_ (converted to wei) must be greater or equal to the sum of gasLimit_ multiplied by
maxFeePerGas_, plus the submission fee for the retryable ticket.
The total amount of fee tokens that will be pulled from the caller is chainIds_.length multiplied by
amountToSend_ (which is returned as totalSent_).
function sendParameters(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) external returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens that will be pulled by each inbox. |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
sendParametersWithPermit
Sends parameters to the app chain as retryable tickets (which may be a direct contract call), given caller's signed approval to pull fee tokens.
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
amountToSend_ (converted to wei) must be greater or equal to the sum of gasLimit_ multiplied by
maxFeePerGas_, plus the submission fee for the retryable ticket.
The total amount of fee tokens that will be pulled from the caller is chainIds_.length multiplied by
amountToSend_ (which is returned as totalSent_).
function sendParametersWithPermit(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens that will be pulled by each inbox. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
sendParametersFromUnderlying
Sends parameters to the app chain as retryable tickets (which may be a direct contract call).
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
amountToSend_ (converted to wei) must be greater or equal to the sum of gasLimit_ multiplied by
maxFeePerGas_, plus the submission fee for the retryable ticket.
The total amount of fee tokens that will be pulled from the caller is chainIds_.length multiplied by
amountToSend_ (which is returned as totalSent_).
function sendParametersFromUnderlying(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) external returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens to send with the call to fund the alias on each app chain, which will first be converted from underlying fee tokens. |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
sendParametersFromUnderlyingWithPermit
Sends parameters to the app chain as retryable tickets (which may be a direct contract call), given caller's signed approval to pull underlying fee tokens.
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
amountToSend_ (converted to wei) must be greater or equal to the sum of gasLimit_ multiplied by
maxFeePerGas_, plus the submission fee for the retryable ticket.
The total amount of fee tokens that will be pulled from the caller is chainIds_.length multiplied by
amountToSend_ (which is returned as totalSent_).
function sendParametersFromUnderlyingWithPermit(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens to send with the call to fund the alias on each app chain, which will first be converted from underlying fee tokens. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
updateInbox
Updates the inbox for a chain ID.
function updateInbox(uint256 chainId_) external;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID. |
receiveWithdrawal
Receives withdrawal of fee tokens from the app chain gateway.
function receiveWithdrawal(address recipient_) external returns (uint256 amount_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the tokens. |
Returns
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of fee tokens withdrawn. |
receiveWithdrawalIntoUnderlying
Receives withdrawal of fee tokens from the app chain gateway, and unwraps them into underlying fee tokens.
function receiveWithdrawalIntoUnderlying(address recipient_) external returns (uint256 amount_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying fee tokens. |
Returns
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of fee tokens withdrawn. |
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
inboxParameterKey
The parameter registry key used to fetch the inbox.
function inboxParameterKey() external pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() external pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() external pure returns (string memory key_);
parameterRegistry
The address of the parameter registry.
function parameterRegistry() external view returns (address parameterRegistry_);
appChainGateway
The address of the app chain gateway.
function appChainGateway() external view returns (address appChainGateway_);
appChainAlias
This contract's alias address on the L3 app chain.
function appChainAlias() external view returns (address appChainAlias_);
feeToken
The address of the fee token on the settlement chain, that is used to pay for gas on app chains.
function feeToken() external view returns (address feeToken_);
paused
The pause status.
function paused() external view returns (bool paused_);
calculateMaxDepositFee
Calculates the maximum fees (in wei, 18 decimals) that will be consumed for a deposit to an app chain.
function calculateMaxDepositFee(uint256 chainId_, uint256 gasLimit_, uint256 maxFeePerGas_, uint256 maxBaseFee_)
external
view
returns (uint256 fees_);
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
maxBaseFee_ | uint256 | The maximum base fee of the settlement chain, in wei (18 decimals). |
Returns
| Name | Type | Description |
|---|---|---|
fees_ | uint256 | The maximum fees (in wei, 18 decimals) that will be consumed for a deposit to an app chain. |
getInbox
The inbox address for a chain ID.
function getInbox(uint256 chainId_) external view returns (address inbox_);
Events
Deposit
Emitted when fee tokens have been sent to the app chain (becoming native gas token).
event Deposit(
uint256 indexed chainId, uint256 indexed messageNumber, address indexed recipient, uint256 amount, uint256 maxFees
);
Parameters
| Name | Type | Description |
|---|---|---|
chainId | uint256 | The chain ID of the target app chain. |
messageNumber | uint256 | The message number, unique per inbox. |
recipient | address | The recipient of the tokens on the app chain. |
amount | uint256 | The amount of tokens sent. |
maxFees | uint256 | The maximum fees that will be consumed for the deposit. |
ParametersSent
Emitted when parameters have been sent to the app chain.
event ParametersSent(uint256 indexed chainId, uint256 indexed messageNumber, uint256 nonce, string[] keys);
Parameters
| Name | Type | Description |
|---|---|---|
chainId | uint256 | The chain ID of the target app chain. |
messageNumber | uint256 | The message number, unique per inbox. |
nonce | uint256 | The nonce of the parameter transmission (to prevent out-of-sequence resets). |
keys | string[] | The keys of the parameters. |
InboxUpdated
Emitted when the inbox for a chain ID has been updated.
event InboxUpdated(uint256 indexed chainId, address indexed inbox);
Parameters
| Name | Type | Description |
|---|---|---|
chainId | uint256 | The chain ID. |
inbox | address | The inbox address. |
WithdrawalReceived
Emitted when fee tokens are withdrawn from the app chain.
event WithdrawalReceived(address indexed recipient, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
recipient | address | The recipient of the tokens. |
amount | uint256 | The amount of tokens withdrawn. |
PauseStatusUpdated
Emitted when the pause status is set.
event PauseStatusUpdated(bool indexed paused);
Parameters
| Name | Type | Description |
|---|---|---|
paused | bool | The new pause status. |
Errors
ZeroParameterRegistry
Thrown when the parameter registry address is zero (i.e. address(0)).
error ZeroParameterRegistry();
ZeroAppChainGateway
Thrown when the app chain gateway address is zero (i.e. address(0)).
error ZeroAppChainGateway();
ZeroFeeToken
Thrown when the fee token address is zero (i.e. address(0)).
error ZeroFeeToken();
TransferFromFailed
Thrown when the ERC20.transferFrom call fails.
This is an identical redefinition of SafeTransferLib.TransferFromFailed.
error TransferFromFailed();
NoChainIds
Thrown when no chain IDs are provided.
error NoChainIds();
NoKeys
Thrown when no keys are provided.
error NoKeys();
UnsupportedChainId
Thrown when the chain ID is not supported.
error UnsupportedChainId(uint256 chainId);
Paused
Thrown when any pausable function is called when the contract is paused.
error Paused();
NoChange
Thrown when there is no change to an updated parameter.
error NoChange();
ZeroBalance
Thrown when the balance is zero.
error ZeroBalance();
ZeroAmount
Thrown when the amount is zero.
error ZeroAmount();
ZeroRecipient
Thrown when the recipient is zero (i.e. address(0)).
error ZeroRecipient();
InvalidFeeTokenDecimals
Thrown when the fee token decimals are greater than 18.
error InvalidFeeTokenDecimals();
InsufficientAmount
Thrown when the amount is insufficient to cover the max submission and transaction costs.
error InsufficientAmount(uint256 appChainAmount, uint256 maxTotalCosts);
ISettlementChainParameterRegistry
Inherits: IParameterRegistry
A SettlementChainParameterRegistry is a parameter registry used by the protocol contracts on the settlement chain.
DepositSplitter
Inherits: IDepositSplitter
This contract handles functionality for splitting deposits between the Payer Registry and App Chain.
State Variables
feeToken
The address of the fee token contract used for deposits.
address public immutable feeToken;
payerRegistry
The address of the payer registry.
address public immutable payerRegistry;
settlementChainGateway
The address of the settlement chain gateway.
address public immutable settlementChainGateway;
appChainId
The app chain ID.
uint256 public immutable appChainId;
_underlyingFeeToken
The address of the token underlying the fee token.
address internal immutable _underlyingFeeToken;
Functions
constructor
constructor(address feeToken_, address payerRegistry_, address settlementChainGateway_, uint256 appChainId_);
deposit
function deposit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) external;
depositWithPermit
function depositWithPermit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
depositFromUnderlying
function depositFromUnderlying(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) external;
depositFromUnderlyingWithPermit
function depositFromUnderlyingWithPermit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
_depositFeeToken
Transfers in the total fee tokens from the caller, then performs the required deposit(s).
function _depositFeeToken(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) internal;
_depositFromUnderlying
Transfers in the total underlying fee tokens from the caller, then performs the required deposit(s).
function _depositFromUnderlying(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) internal;
_deposit
Satisfies both deposits, if needed, and reverts if neither are needed.
function _deposit(
address payer_,
uint96 payerRegistryAmount_,
address appChainRecipient_,
uint96 appChainAmount_,
uint256 appChainGasLimit_,
uint256 appChainMaxFeePerGas_
) internal;
_usePermit
Uses a permit to approve the deposit of amount_ of token_ from the caller to this contract.
Silently ignore a failing permit, as it may indicate that the permit was already used and/or the allowance has already been approved.
function _usePermit(address token_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) internal;
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
DistributionManager
Inherits: IDistributionManager, Initializable, Migratable
This contract handles functionality for distributing fees.
State Variables
_ONE_HUNDRED_PERCENT
One hundred percent (in basis points).
uint16 internal constant _ONE_HUNDRED_PERCENT = 10_000;
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
nodeRegistry
The address of the node registry.
address public immutable nodeRegistry;
payerReportManager
The address of the payer report manager.
address public immutable payerReportManager;
payerRegistry
The address of the payer registry.
address public immutable payerRegistry;
feeToken
The address of the fee token.
address public immutable feeToken;
_DISTRIBUTION_MANAGER_STORAGE_LOCATION
bytes32 internal constant _DISTRIBUTION_MANAGER_STORAGE_LOCATION =
0xecaf10aa029fa936ea42e5f15011e2f38c8598ffef434459a36a3d154fde2a00;
Functions
_getDistributionManagerStorage
function _getDistributionManagerStorage() internal pure returns (DistributionManagerStorage storage $);
whenNotPaused
modifier whenNotPaused();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry, node registry, payer report manager, payer registry, and fee token must not be the zero address.
The parameter registry, node registry, payer report manager, payer registry, and fee token are immutable that they are inlined in the contract code, and have minimal gas cost.
constructor(
address parameterRegistry_,
address nodeRegistry_,
address payerReportManager_,
address payerRegistry_,
address feeToken_
);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
nodeRegistry_ | address | The address of the node registry. |
payerReportManager_ | address | The address of the payer report manager. |
payerRegistry_ | address | The address of the payer registry. |
feeToken_ | address | The address of the fee token. |
initialize
Initializes the contract.
function initialize() public initializer;
claimProtocolFees
Claims protocol fees.
function claimProtocolFees(uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
whenNotPaused
returns (uint96 claimed_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeIds_ | uint32[] | The IDs of the originator nodes of the payer reports. |
payerReportIndices_ | uint256[] | The payer report indices for each of the respective originator node IDs. |
Returns
| Name | Type | Description |
|---|---|---|
claimed_ | uint96 | The amount of protocol fees claimed. |
claim
Claims fees for a node for an array of payer reports.
The node IDs in originatorNodeIds_ don't need to be unique.
function claim(uint32 nodeId_, uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
whenNotPaused
returns (uint96 claimed_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
originatorNodeIds_ | uint32[] | The IDs of the originator nodes of the payer reports. |
payerReportIndices_ | uint256[] | The payer report indices for each of the respective originator node IDs. |
Returns
| Name | Type | Description |
|---|---|---|
claimed_ | uint96 | The amount of fees claimed. |
withdrawProtocolFees
Withdraws protocol fees.
function withdrawProtocolFees() external whenNotPaused returns (uint96 withdrawn_);
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of protocol fees withdrawn. |
withdrawProtocolFeesIntoUnderlying
Withdraws protocol fees, unwrapped as underlying token.
function withdrawProtocolFeesIntoUnderlying() external whenNotPaused returns (uint96 withdrawn_);
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of protocol fees withdrawn. |
withdraw
Withdraws fees for a node.
function withdraw(uint32 nodeId_, address recipient_) external whenNotPaused returns (uint96 withdrawn_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
recipient_ | address | The address to withdraw the fee tokens to. |
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of fee tokens withdrawn. |
withdrawIntoUnderlying
Withdraws fees for a node, unwrapped as underlying fee token.
function withdrawIntoUnderlying(uint32 nodeId_, address recipient_)
external
whenNotPaused
returns (uint96 withdrawn_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
recipient_ | address | The address to withdraw the underlying fee tokens to. |
Returns
| Name | Type | Description |
|---|---|---|
withdrawn_ | uint96 | The amount of fee tokens withdrawn. |
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
updateProtocolFeesRecipient
Updates the protocol fees recipient.
function updateProtocolFeesRecipient() external;
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure returns (string memory key_);
protocolFeesRecipientParameterKey
The parameter registry key used to fetch the protocol fees recipient.
function protocolFeesRecipientParameterKey() public pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
protocolFeesRecipient
The address of the protocol fees recipient.
function protocolFeesRecipient() external view returns (address protocolFeesRecipient_);
totalOwedFees
The total amount of fees owed.
function totalOwedFees() external view returns (uint96 totalOwedFees_);
owedProtocolFees
The amount of claimed protocol fees owed to the protocol.
function owedProtocolFees() external view returns (uint96 owedProtocolFees_);
getOwedFees
Returns the amount of claimed fees owed to a node.
function getOwedFees(uint32 nodeId_) external view returns (uint96 owedFees_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
Returns
| Name | Type | Description |
|---|---|---|
owedFees_ | uint96 | The amount of fees owed. |
areProtocolFeesClaimed
Returns whether protocol fees associated with a settled payer report have been claimed.
function areProtocolFeesClaimed(uint32 originatorNodeId_, uint256 payerReportIndex_)
external
view
returns (bool areClaimed_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The ID of the originator node of the payer report. |
payerReportIndex_ | uint256 | The index of the payer report. |
Returns
| Name | Type | Description |
|---|---|---|
areClaimed_ | bool | Whether protocol fees associated with a settled payer report have been claimed. |
areFeesClaimed
Returns whether a node has claimed fees associated with a settled payer report.
function areFeesClaimed(uint32 nodeId_, uint32 originatorNodeId_, uint256 payerReportIndex_)
external
view
returns (bool hasClaimed_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The ID of the node. |
originatorNodeId_ | uint32 | The ID of the originator node of the payer report. |
payerReportIndex_ | uint256 | The index of the payer report. |
Returns
| Name | Type | Description |
|---|---|---|
hasClaimed_ | bool | areClaimed_ Whether the node has claimed fees associated with a settled payer report. |
_makeWithdrawableAmount
Returns the amount of fees that can be withdrawn given an amount owed and the contract's balance, and, if needed, tries to pull any excess fees from the payer registry.
function _makeWithdrawableAmount(uint96 owed_) internal returns (uint96 withdrawable_);
Parameters
| Name | Type | Description |
|---|---|---|
owed_ | uint96 | The amount of fees owed. |
Returns
| Name | Type | Description |
|---|---|---|
withdrawable_ | uint96 | The amount of fees that can be withdrawn. |
_prepareWithdrawal
Prepares a withdrawal of fee tokens, and returns the amount of fee tokens being withdrawn.
function _prepareWithdrawal(uint32 nodeId_, address recipient_) internal returns (uint96 withdrawn_);
_prepareProtocolFeesWithdrawal
Prepares a protocol fees withdrawal of fee tokens, and returns the amount of fee tokens being withdrawn.
function _prepareProtocolFeesWithdrawal(address recipient_) internal returns (uint96 withdrawn_);
_getPayerReports
function _getPayerReports(uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
internal
view
returns (IPayerReportManagerLike.PayerReport[] memory payerReports_);
_getProtocolFees
Returns the protocol fees ensuring no rounding dust when distributing node fees.
If nodeCount_ is 0, all fees are returned as protocol fees since there are no nodes to distribute to.
Node fees are rounded down to a multiple of nodeCount_ to ensure equal distribution without dust.
function _getProtocolFees(uint96 feesSettled_, uint16 protocolFeeRate_, uint256 nodeCount_)
internal
pure
returns (uint96 protocolFees_);
Parameters
| Name | Type | Description |
|---|---|---|
feesSettled_ | uint96 | Total fees collected. |
protocolFeeRate_ | uint16 | Protocol fee rate in basis points. |
nodeCount_ | uint256 | Number of nodes sharing the remaining fees. |
Returns
| Name | Type | Description |
|---|---|---|
protocolFees_ | uint96 | Protocol fees (may be slightly higher than nominal rate due to rounding). |
_isInNodeIds
Returns true if the node ID is in the list of node IDs.
function _isInNodeIds(uint32 nodeId_, uint32[] memory nodeIds_) internal pure returns (bool isInNodeIds_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfNotNodeOwner
function _revertIfNotNodeOwner(uint32 nodeId_) internal view;
_revertIfPaused
function _revertIfPaused() internal view;
Structs
DistributionManagerStorage
The UUPS storage for the distribution manager.
Note: storage-location: erc7201:xmtp.storage.DistributionManager
struct DistributionManagerStorage {
address protocolFeesRecipient;
uint96 owedProtocolFees;
mapping(uint32 originatorNodeId => mapping(uint256 payerReportIndex => bool areClaimed)) areProtocolFeesClaimed;
mapping(uint32 nodeId => uint96 owedFees) owedFees;
mapping(uint32 nodeId => mapping(uint32 originatorNodeId => mapping(uint256 payerReportIndex => bool areClaimed)))
areFeesClaimed;
uint96 totalOwedFees;
bool paused;
}
FeeToken
Inherits: IFeeToken, Migratable, ERC20PermitUpgradeable
This contract exposes functionality for wrapping and unwrapping tokens for use as fees in the protocol.
State Variables
PERMIT_TYPEHASH
Returns the EIP712 typehash used in the encoding of a signed digest for a permit.
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
underlying
Returns the address of the underlying token.
address public immutable underlying;
_FEE_TOKEN_STORAGE_LOCATION
bytes32 internal constant _FEE_TOKEN_STORAGE_LOCATION =
0x5671b09487cb30093710a244e87d44c3076fe3dd19f604be8dafc153e2d9cb00;
Functions
_getFeeTokenStorage
function _getFeeTokenStorage() internal pure returns (FeeTokenStorage storage $);
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry and underlying token must not be the zero address.
The parameter registry and underlying token are immutable so that they are inlined in the contract code, and have minimal gas cost.
constructor(address parameterRegistry_, address underlying_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
underlying_ | address | The address of the underlying token. |
initialize
Initializes the contract.
function initialize() public initializer;
permit
Sets value_ as the allowance of spender_ over owner_'s tokens, given `owner_'s signed approval.
function permit(address owner_, address spender_, uint256 value_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
public
override(IFeeToken, ERC20PermitUpgradeable);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
spender_ | address | The spender of the tokens. |
value_ | uint256 | The value of the tokens. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
deposit
Deposits amount_ of the underlying token.
function deposit(uint256 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of the underlying token to deposit. |
depositWithPermit
Deposits amount_ of the underlying token, given owner_'s signed approval.
function depositWithPermit(uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of the underlying token to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFor
Deposits amount_ of the underlying token for recipient_.
This function conforms to ERC20Wrapper.depositFor.
function depositFor(address recipient_, uint256 amount_) external returns (bool success_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying token. |
amount_ | uint256 | The amount of the underlying token to deposit. |
depositForWithPermit
Deposits amount_ of the underlying token for recipient_, given owner_'s signed approval.
This function conforms to ERC20Wrapper.depositFor.
function depositForWithPermit(address recipient_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
external
returns (bool success_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying token. |
amount_ | uint256 | The amount of the underlying token to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
withdraw
Withdraws amount_ of the underlying token.
function withdraw(uint256 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of the underlying token to withdraw. |
withdrawTo
Withdraws amount_ of the underlying token for recipient_.
This function conforms to ERC20Wrapper.withdrawTo.
function withdrawTo(address recipient_, uint256 amount_) external returns (bool success_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying token. |
amount_ | uint256 | The amount of the underlying token to withdraw. |
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
DOMAIN_SEPARATOR
Returns the EIP712 domain separator used in the encoding of a signed digest.
function DOMAIN_SEPARATOR()
external
view
override(IFeeToken, ERC20PermitUpgradeable)
returns (bytes32 domainSeparator_);
decimals
Returns the decimals places of the token.
function decimals() public pure override(IERC20Metadata, ERC20Upgradeable) returns (uint8 decimals_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
nonces
Returns the current nonce for owner_ that must be included for the next valid permit signature.
function nonces(address owner_) public view override(IFeeToken, ERC20PermitUpgradeable) returns (uint256 nonce_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
Returns
| Name | Type | Description |
|---|---|---|
nonce_ | uint256 | The nonce of the owner. |
getPermitDigest
Returns the EIP-712 digest for a permit.
function getPermitDigest(address owner_, address spender_, uint256 value_, uint256 nonce_, uint256 deadline_)
external
view
returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
spender_ | address | The spender of the tokens. |
value_ | uint256 | The value of the tokens. |
nonce_ | uint256 | The nonce of the permit signature. |
deadline_ | uint256 | The deadline of the permit signature. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The EIP-712 digest. |
_depositWithPermit
function _depositWithPermit(address recipient_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
internal;
_deposit
function _deposit(address recipient_, uint256 amount_) internal;
_withdraw
function _withdraw(address recipient_, uint256 amount_) internal;
_getPermitDigest
Returns the EIP-712 digest for a permit.
function _getPermitDigest(address owner_, address spender_, uint256 value_, uint256 nonce_, uint256 deadline_)
internal
view
returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The owner of the tokens. |
spender_ | address | The spender of the tokens. |
value_ | uint256 | The value of the tokens. |
nonce_ | uint256 | The nonce of the permit signature. |
deadline_ | uint256 | The deadline of the permit signature. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The EIP-712 digest. |
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
Structs
FeeTokenStorage
The UUPS storage for the fee token.
Note: storage-location: erc7201:xmtp.storage.FeeToken
struct FeeTokenStorage {
uint256 __placeholder;
}
NodeRegistry
Inherits: INodeRegistry, Migratable, ERC721Upgradeable
This contract is responsible for minting NFTs and assigning them to node owners. Each node is minted as an NFT with a unique ID (starting at 100 and increasing by 100 with each new node). In addition to the standard ERC721 functionality, the contract supports node-specific features, including node property updates.
All nodes on the network periodically check this contract to determine which nodes they should connect to.
State Variables
NODE_INCREMENT
The increment for node IDs, which allows for 100 shard node IDs per node in the future (modulus 100).
uint32 public constant NODE_INCREMENT = 100;
_FORWARD_SLASH
bytes1 internal constant _FORWARD_SLASH = 0x2f;
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
_NODE_REGISTRY_STORAGE_LOCATION
bytes32 internal constant _NODE_REGISTRY_STORAGE_LOCATION =
0xd48713bc7b5e2644bcb4e26ace7d67dc9027725a9a1ee11596536cc6096a2000;
Functions
_getNodeRegistryStorage
function _getNodeRegistryStorage() internal pure returns (NodeRegistryStorage storage $);
onlyAdmin
modifier onlyAdmin();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry must not be the zero address.
The parameter registry is immutable so that it is inlined in the contract code, and has minimal gas cost.
constructor(address parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
initialize
Initializes the contract.
function initialize() public initializer;
addNode
Adds a new node to the registry and mints its corresponding ERC721 token.
Node IDs start at 100 and increase by 100 for each new node.
function addNode(address owner_, bytes calldata signingPublicKey_, string calldata httpAddress_)
external
onlyAdmin
returns (uint32 nodeId_, address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
owner_ | address | The address that will own the new node node/NFT. |
signingPublicKey_ | bytes | The public key used for node signing/verification. |
httpAddress_ | string | The node’s HTTP address. |
Returns
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the newly added node. |
signer_ | address | The address derived by the signing public key, for convenience. |
addToNetwork
Adds a node to the canonical network.
function addToNetwork(uint32 nodeId_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
removeFromNetwork
Removes a node from the canonical network.
function removeFromNetwork(uint32 nodeId_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
setBaseURI
Set the base URI for the node NFTs.
function setBaseURI(string calldata baseURI_) external onlyAdmin;
Parameters
| Name | Type | Description |
|---|---|---|
baseURI_ | string | The new base URI. Has to end with a trailing slash. |
setHttpAddress
Set the HTTP address of an existing node.
function setHttpAddress(uint32 nodeId_, string calldata httpAddress_) external;
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
httpAddress_ | string | The new HTTP address. |
updateAdmin
Updates the admin by referring to the admin parameter from the parameter registry.
function updateAdmin() external;
updateMaxCanonicalNodes
Updates the max canonical nodes by referring to the max canonical nodes parameter from the parameter registry.
function updateMaxCanonicalNodes() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
admin
The address of the admin.
function admin() external view returns (address admin_);
adminParameterKey
The parameter registry key used to fetch the admin.
function adminParameterKey() public pure returns (string memory key_);
maxCanonicalNodesParameterKey
The parameter registry key used to fetch the max canonical nodes.
function maxCanonicalNodesParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
maxCanonicalNodes
The maximum number of nodes that can be part of the canonical network.
function maxCanonicalNodes() external view returns (uint8 maxCanonicalNodes_);
canonicalNodesCount
The number of nodes that are part of the canonical network.
function canonicalNodesCount() external view returns (uint8 canonicalNodesCount_);
getAllNodes
Gets all nodes regardless of their health status.
function getAllNodes() external view returns (NodeWithId[] memory allNodes_);
Returns
| Name | Type | Description |
|---|---|---|
allNodes_ | NodeWithId[] | An array of all nodes in the registry. |
getAllNodesCount
Gets the total number of nodes in the registry.
function getAllNodesCount() external view returns (uint32 nodeCount_);
Returns
| Name | Type | Description |
|---|---|---|
nodeCount_ | uint32 | The total number of nodes. |
getNode
Retrieves the details of a given node.
function getNode(uint32 nodeId_) external view returns (Node memory node_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
node_ | Node | The Node struct containing the node's details. |
getIsCanonicalNode
Retrieves whether a node is part of the canonical network.
function getIsCanonicalNode(uint32 nodeId_) external view returns (bool isCanonicalNode_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
isCanonicalNode_ | bool | A boolean indicating whether the node is part of the canonical network. |
getSigner
Retrieves the signer of a node.
function getSigner(uint32 nodeId_) external view returns (address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
nodeId_ | uint32 | The unique identifier of the node. |
Returns
| Name | Type | Description |
|---|---|---|
signer_ | address | The address of the signer. |
_baseURI
function _baseURI() internal view override returns (string memory baseURI_);
_getSignerFromPublicKey
Returns the signer address from a public key.
Validates uncompressed public key format: 0x04 + 32 bytes X + 32 bytes Y = 65 bytes total
function _getSignerFromPublicKey(bytes calldata publicKey_) internal pure returns (address signer_);
Parameters
| Name | Type | Description |
|---|---|---|
publicKey_ | bytes | The public key. |
Returns
| Name | Type | Description |
|---|---|---|
signer_ | address | The signer address. |
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfNotAdmin
function _revertIfNotAdmin() internal view;
_revertIfNotNodeOwner
function _revertIfNotNodeOwner(uint32 nodeId_) internal view;
Structs
NodeRegistryStorage
The UUPS storage for the node registry.
Note: storage-location: erc7201:xmtp.storage.NodeRegistry
struct NodeRegistryStorage {
address admin;
uint8 maxCanonicalNodes;
uint8 canonicalNodesCount;
uint32 nodeCount;
mapping(uint32 tokenId => Node node) nodes;
string baseURI;
}
Properties
| Name | Type | Description |
|---|---|---|
admin | address | The admin address. |
maxCanonicalNodes | uint8 | The maximum number of canonical nodes. |
canonicalNodesCount | uint8 | The current number of canonical nodes. |
nodeCount | uint32 | The current number of nodes. |
nodes | mapping(uint32 tokenId => Node node) | A mapping of node/token IDs to nodes. |
baseURI | string | The base component of the token URI. |
PayerRegistry
Inherits: IPayerRegistry, Migratable, Initializable
This contract is responsible for:
- handling deposits, withdrawals, and usage settlements for payers,
- settling usage fees for payers,
- sending excess fee tokens to the fee distributor.
State Variables
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
feeToken
The address of the fee token contract used for deposits and withdrawals.
address public immutable feeToken;
_underlyingFeeToken
The address of the token underlying the fee token.
address internal immutable _underlyingFeeToken;
_PAYER_REGISTRY_STORAGE_LOCATION
bytes32 internal constant _PAYER_REGISTRY_STORAGE_LOCATION =
0x98606aa366980dbfce6aa523610c4eabfe62443511d67e10c2c7afde009fbf00;
Functions
_getPayerRegistryStorage
function _getPayerRegistryStorage() internal pure returns (PayerRegistryStorage storage $);
whenNotPaused
modifier whenNotPaused();
onlySettler
modifier onlySettler();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry and fee token must not be the zero address.
The parameter registry and fee token are immutable so that they are inlined in the contract code, and have minimal gas cost.
constructor(address parameterRegistry_, address feeToken_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
feeToken_ | address | The address of the fee token. |
initialize
Initializes the contract.
function initialize() external initializer;
deposit
Deposits amount_ fee tokens into the registry for payer_.
function deposit(address payer_, uint96 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of fee tokens to deposit. |
depositWithPermit
Deposits amount_ fee tokens into the registry for payer_, given caller's signed approval.
function depositWithPermit(address payer_, uint96 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_)
external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of fee tokens to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFromUnderlying
Deposits amount_ fee tokens into the registry for payer_, wrapping them from underlying fee tokens.
function depositFromUnderlying(address payer_, uint96 amount_) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of underlying fee tokens to deposit. |
depositFromUnderlyingWithPermit
Deposits amount_ fee tokens into the registry for payer_, wrapping them from underlying fee tokens,
given caller's signed approval.
function depositFromUnderlyingWithPermit(
address payer_,
uint96 amount_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
amount_ | uint96 | The amount of underlying fee tokens to deposit. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
requestWithdrawal
Requests a withdrawal of amount_ fee tokens.
The caller must have enough balance to cover the withdrawal.
function requestWithdrawal(uint96 amount_) external whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
amount_ | uint96 | The amount of fee tokens to withdraw. |
cancelWithdrawal
Cancels a pending withdrawal of fee tokens, returning the amount to the balance.
function cancelWithdrawal() external whenNotPaused;
finalizeWithdrawal
Finalizes a pending withdrawal of fee tokens, transferring the amount to the recipient.
The caller must not be currently in debt.
function finalizeWithdrawal(address recipient_) external;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to receive the fee tokens. |
finalizeWithdrawalIntoUnderlying
Finalizes a pending withdrawal of fee tokens, unwrapping the amount into underlying fee tokens to the recipient.
The caller must not be currently in debt.
function finalizeWithdrawalIntoUnderlying(address recipient_) external;
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to receive the underlying fee tokens. |
settleUsage
Settles the usage fees for a list of payers.
function settleUsage(bytes32 payerReportId_, PayerFee[] calldata payerFees_)
external
onlySettler
whenNotPaused
returns (uint96 feesSettled_);
Parameters
| Name | Type | Description |
|---|---|---|
payerReportId_ | bytes32 | The ID of the payer report triggering the settlement. |
payerFees_ | PayerFee[] | An array of structs containing the payer and the fee to settle. |
Returns
| Name | Type | Description |
|---|---|---|
feesSettled_ | uint96 | The total amount of fees settled. |
sendExcessToFeeDistributor
Sends the excess tokens in the contract to the fee distributor.
function sendExcessToFeeDistributor() external whenNotPaused returns (uint96 excess_);
Returns
| Name | Type | Description |
|---|---|---|
excess_ | uint96 | The amount of excess tokens sent to the fee distributor. |
updateSettler
Updates the settler of the contract.
Ensures the new settler is not zero (i.e. address(0)).
function updateSettler() external;
updateFeeDistributor
Updates the fee distributor of the contract.
Ensures the new fee distributor is not zero (i.e. address(0)).
function updateFeeDistributor() external;
updateMinimumDeposit
Updates the minimum deposit amount.
Ensures the new minimum deposit is not zero (i.e. address(0)).
function updateMinimumDeposit() external;
updateWithdrawLockPeriod
Updates the withdraw lock period.
function updateWithdrawLockPeriod() external;
updatePauseStatus
Updates the pause status.
function updatePauseStatus() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
settlerParameterKey
The parameter registry key used to fetch the settler.
function settlerParameterKey() public pure returns (string memory key_);
feeDistributorParameterKey
The parameter registry key used to fetch the fee distributor.
function feeDistributorParameterKey() public pure returns (string memory key_);
minimumDepositParameterKey
The parameter registry key used to fetch the minimum deposit.
function minimumDepositParameterKey() public pure returns (string memory key_);
withdrawLockPeriodParameterKey
The parameter registry key used to fetch the withdraw lock period.
function withdrawLockPeriodParameterKey() public pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
settler
The address of the settler that can call settleUsage.
function settler() external view returns (address settler_);
feeDistributor
The address of the fee distributor that receives unencumbered fees from usage settlements.
function feeDistributor() external view returns (address feeDistributor_);
paused
The pause status.
function paused() external view returns (bool paused_);
totalDeposits
The sum of all payer balances and pending withdrawals.
function totalDeposits() public view returns (int104 totalDeposits_);
totalDebt
The sum of all payer debts.
function totalDebt() public view returns (uint96 totalDebt_);
totalWithdrawable
The sum of all withdrawable balances (sum of all positive payer balances and pending withdrawals).
function totalWithdrawable() external view returns (uint96 totalWithdrawable_);
minimumDeposit
The minimum amount required for any deposit.
function minimumDeposit() external view returns (uint96 minimumDeposit_);
withdrawLockPeriod
The withdraw lock period.
function withdrawLockPeriod() external view returns (uint32 withdrawLockPeriod_);
excess
The amount of excess tokens in the contract that are not withdrawable by payers.
function excess() public view returns (uint96 excess_);
getBalance
Returns the balance of a payer.
function getBalance(address payer_) external view returns (int104 balance_);
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
Returns
| Name | Type | Description |
|---|---|---|
balance_ | int104 | The signed balance of the payer (negative if debt). |
getBalances
Returns the balances of an array of payers.
This is a periphery function for nodes, and is not required for the core protocol.
function getBalances(address[] calldata payers_) external view returns (int104[] memory balances_);
Parameters
| Name | Type | Description |
|---|---|---|
payers_ | address[] | An array of payer addresses. |
Returns
| Name | Type | Description |
|---|---|---|
balances_ | int104[] | The signed balances of each payer (negative if debt). |
getPendingWithdrawal
Returns the pending withdrawal of a payer.
function getPendingWithdrawal(address payer_)
external
view
returns (uint96 pendingWithdrawal_, uint32 withdrawableTimestamp_, uint24 nonce_);
Parameters
| Name | Type | Description |
|---|---|---|
payer_ | address | The address of the payer. |
Returns
| Name | Type | Description |
|---|---|---|
pendingWithdrawal_ | uint96 | The amount of a pending withdrawal, if any. |
withdrawableTimestamp_ | uint32 | The timestamp when the pending withdrawal can be finalized. |
nonce_ | uint24 | The nonce associated with the pending withdrawal. |
_increaseBalance
Increases the balance of payer_ by amount_, and returns the debt repaid.
function _increaseBalance(address payer_, uint96 amount_) internal returns (uint96 debtRepaid_);
_decreaseBalance
Decreases the balance of payer_ by amount_, and returns the additional debt incurred.
function _decreaseBalance(address payer_, uint96 amount_) internal returns (uint96 debtIncurred_);
_depositFeeToken
Transfers amount_ of fee tokens from the caller to this contract to satisfy a deposit for payer_.
function _depositFeeToken(address payer_, uint96 amount_) internal;
_depositFromUnderlying
Transfers amount_ of fee tokens from the caller to this contract to satisfy a deposit for payer_.
function _depositFromUnderlying(address payer_, uint96 amount_) internal;
_deposit
Satisfies a deposit for payer_.
function _deposit(address payer_, uint96 amount_) internal whenNotPaused;
_finalizeWithdrawal
Finalizes a pending withdrawal for the caller.
function _finalizeWithdrawal(address recipient_) internal whenNotPaused returns (uint96 pendingWithdrawal_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The address to send the withdrawal to. |
Returns
| Name | Type | Description |
|---|---|---|
pendingWithdrawal_ | uint96 | The amount of the pending withdrawal. |
_usePermit
Uses a permit to approve the deposit of amount_ of token_ from the caller to this contract.
Silently ignore a failing permit, as it may indicate that the permit was already used and/or the allowance has already been approved.
function _usePermit(address token_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) internal;
_getDebt
Returns the debt represented by a balance, if any.
function _getDebt(int104 balance_) internal pure returns (uint96 debt_);
_getTotalWithdrawable
Returns the sum of all withdrawable balances (sum of all positive payer balances and pending withdrawals).
function _getTotalWithdrawable(int104 totalDeposits_, uint96 totalDebt_)
internal
pure
returns (uint96 totalWithdrawable_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_toInt104
function _toInt104(uint96 input_) internal pure returns (int104 output_);
_revertIfNotSettler
function _revertIfNotSettler() internal view;
_revertIfPaused
function _revertIfPaused() internal view;
Structs
PayerRegistryStorage
The UUPS storage for the payer registry.
Note: storage-location: erc7201:xmtp.storage.PayerRegistry
struct PayerRegistryStorage {
bool paused;
int104 totalDeposits;
uint96 totalDebt;
uint32 withdrawLockPeriod;
uint96 minimumDeposit;
address settler;
address feeDistributor;
mapping(address account => Payer payer) payers;
}
Properties
| Name | Type | Description |
|---|---|---|
paused | bool | The pause status. |
totalDeposits | int104 | The sum of all payer balances and pending withdrawals. |
totalDebt | uint96 | The sum of all payer debts. |
withdrawLockPeriod | uint32 | The withdraw lock period. |
minimumDeposit | uint96 | The minimum deposit. |
settler | address | The address of the settler. |
feeDistributor | address | The address of the fee distributor. |
payers | mapping(address account => Payer payer) | A mapping of payer addresses to payer information. |
PayerReportManager
Inherits: IPayerReportManager, Initializable, Migratable, ERC5267
This contract handles functionality for submitting and settling payer reports.
State Variables
PAYER_REPORT_TYPEHASH
keccak256("PayerReport(uint32 originatorNodeId,uint64 startSequenceId,uint64 endSequenceId,uint32 endMinuteSinceEpoch,bytes32 payersMerkleRoot,uint32[] nodeIds)")
bytes32 public constant PAYER_REPORT_TYPEHASH = 0x3737a2cced99bb28fc5aede45aa81d3ce0aa9137c5f417641835d0d71d303346;
ONE_HUNDRED_PERCENT
One hundred percent (in basis points).
uint16 public constant ONE_HUNDRED_PERCENT = 10_000;
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
nodeRegistry
The address of the node registry.
address public immutable nodeRegistry;
payerRegistry
The address of the payer registry.
address public immutable payerRegistry;
_PAYER_REPORT_MANAGER_STORAGE_LOCATION
bytes32 internal constant _PAYER_REPORT_MANAGER_STORAGE_LOCATION =
0x26b057ee8e4d60685198828fdf1c618ab8e36b0ab85f54a47b18319f6f718e00;
Functions
_getPayerReportManagerStorage
function _getPayerReportManagerStorage() internal pure returns (PayerReportManagerStorage storage $);
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry, node registry, and payer registry must not be the zero address.
The parameter registry, node registry, and payer registry are immutable so that they are inlined in the contract code, and have minimal gas cost.
constructor(address parameterRegistry_, address nodeRegistry_, address payerRegistry_) ERC5267();
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
nodeRegistry_ | address | The address of the node registry. |
payerRegistry_ | address | The address of the payer registry. |
initialize
Initializes the contract.
function initialize() public initializer;
submit
Submits a payer report.
function submit(
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] calldata nodeIds_,
PayerReportSignature[] calldata signatures_
) external returns (uint256 payerReportIndex_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
startSequenceId_ | uint64 | The start sequence ID. |
endSequenceId_ | uint64 | The end sequence ID. |
endMinuteSinceEpoch_ | uint32 | The timestamp of the message at endSequenceId. |
payersMerkleRoot_ | bytes32 | The payers Merkle root. |
nodeIds_ | uint32[] | The active node IDs during the reporting period. |
signatures_ | PayerReportSignature[] | The signature objects for the payer report. |
Returns
| Name | Type | Description |
|---|---|---|
payerReportIndex_ | uint256 | The index of the payer report in the originator's payer report array. |
settle
Settles a subset of a payer report.
function settle(
uint32 originatorNodeId_,
uint256 payerReportIndex_,
bytes[] calldata payerFees_,
bytes32[] calldata proofElements_
) external;
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
payerReportIndex_ | uint256 | The payer report index. |
payerFees_ | bytes[] | The sequential payer fees to settle. |
proofElements_ | bytes32[] | The sequential Merkle proof elements for the payer fees to settle. |
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
updateProtocolFeeRate
Updates the protocol fee rate.
function updateProtocolFeeRate() external;
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
protocolFeeRateParameterKey
The parameter registry key used to fetch the protocol fee rate.
function protocolFeeRateParameterKey() public pure returns (string memory key_);
protocolFeeRate
The protocol fee rate (in basis points).
function protocolFeeRate() external view returns (uint16 protocolFeeRate_);
getPayerReportDigest
Returns the EIP-712 digest for a payer report.
function getPayerReportDigest(
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] calldata nodeIds_
) external view returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
startSequenceId_ | uint64 | The start sequence ID. |
endSequenceId_ | uint64 | The end sequence ID. |
endMinuteSinceEpoch_ | uint32 | The timestamp of the message at endSequenceId. |
payersMerkleRoot_ | bytes32 | The payers Merkle root. |
nodeIds_ | uint32[] | The active node IDs during the reporting period. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The EIP-712 digest. |
getPayerReports
Returns an array of specific payer reports.
The node IDs in originatorNodeIds_ don't need to be unique.
function getPayerReports(uint32[] calldata originatorNodeIds_, uint256[] calldata payerReportIndices_)
external
view
returns (PayerReport[] memory payerReports_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeIds_ | uint32[] | An array of originator node IDs. |
payerReportIndices_ | uint256[] | An array of payer report indices for each of the respective originator node IDs. |
Returns
| Name | Type | Description |
|---|---|---|
payerReports_ | PayerReport[] | The array of payer reports. |
getPayerReport
Returns a payer report.
function getPayerReport(uint32 originatorNodeId_, uint256 payerReportIndex_)
external
view
returns (PayerReport memory payerReport_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The originator node ID. |
payerReportIndex_ | uint256 | The payer report index. |
Returns
| Name | Type | Description |
|---|---|---|
payerReport_ | PayerReport | The payer report. |
_name
function _name() internal pure override returns (string memory name_);
_version
function _version() internal pure override returns (string memory version_);
_getPayerReportDigest
Returns the EIP-712 digest for a payer report.
function _getPayerReportDigest(
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] memory nodeIds_
) internal view returns (bytes32 digest_);
Parameters
| Name | Type | Description |
|---|---|---|
originatorNodeId_ | uint32 | The ID of the node originator. |
startSequenceId_ | uint64 | The start sequence ID. |
endSequenceId_ | uint64 | The end sequence ID. |
endMinuteSinceEpoch_ | uint32 | |
payersMerkleRoot_ | bytes32 | The payers Merkle root. |
nodeIds_ | uint32[] | The active node IDs during the reporting period. |
Returns
| Name | Type | Description |
|---|---|---|
digest_ | bytes32 | The EIP-712 digest. |
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_verifyPayerReportIsUnique
Verifies that a payer report is unique, compared to a payer report at a given index.
function _verifyPayerReportIsUnique(
uint256 lastPayerReportIndex_,
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] calldata nodeIds_
) internal view returns (bool isUnique_);
Parameters
| Name | Type | Description |
|---|---|---|
lastPayerReportIndex_ | uint256 | The index of the last payer report. |
originatorNodeId_ | uint32 | The originator node ID. |
startSequenceId_ | uint64 | The start sequence ID. |
endSequenceId_ | uint64 | The end sequence ID. |
endMinuteSinceEpoch_ | uint32 | The timestamp of the message at endSequenceId. |
payersMerkleRoot_ | bytes32 | The payers Merkle root. |
nodeIds_ | uint32[] | The active node IDs during the reporting period. |
Returns
| Name | Type | Description |
|---|---|---|
isUnique_ | bool | Whether the report is unique. |
_verifySignatures
Verifies that enough of the signatures are valid and provided by canonical node operators and returns the array of valid signing node IDs.
function _verifySignatures(
uint32 originatorNodeId_,
uint64 startSequenceId_,
uint64 endSequenceId_,
uint32 endMinuteSinceEpoch_,
bytes32 payersMerkleRoot_,
uint32[] calldata nodeIds_,
PayerReportSignature[] calldata signatures_
) internal view returns (uint32[] memory validSigningNodeIds_);
_verifySignature
Returns true if the signature is from the signer of a canonical node.
function _verifySignature(bytes32 digest_, uint32 nodeId_, bytes calldata signature_)
internal
view
returns (bool isValid_);
_enforceNodeIdsMatchRegistry
function _enforceNodeIdsMatchRegistry(uint32[] calldata nodeIds_) internal view;
Structs
PayerReportManagerStorage
The UUPS storage for the payer report manager.
Note: storage-location: erc7201:xmtp.storage.PayerReportManager
struct PayerReportManagerStorage {
mapping(uint32 originatorId => PayerReport[] payerReports) payerReportsByOriginator;
uint16 protocolFeeRate;
}
Properties
| Name | Type | Description |
|---|---|---|
payerReportsByOriginator | mapping(uint32 originatorId => PayerReport[] payerReports) | The mapping of arrays of payer reports by originator node ID. |
protocolFeeRate | uint16 |
RateRegistry
Inherits: IRateRegistry, Migratable, Initializable
This contract handles functionality for updating the rates, tracking them historically.
State Variables
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
_RATE_REGISTRY_STORAGE_LOCATION
bytes32 internal constant _RATE_REGISTRY_STORAGE_LOCATION =
0x988e236e2caf5758fdf811320ba1d2fca453cb71bd6049ebba876b68af505000;
Functions
_getRateRegistryStorage
function _getRateRegistryStorage() internal pure returns (RateRegistryStorage storage $);
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry must not be the zero address.
The parameter registry is immutable so that it is inlined in the contract code, and has minimal gas cost.
constructor(address parameterRegistry_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
initialize
Initializes the contract.
function initialize() public initializer;
updateRates
Updates the rates.
function updateRates() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
messageFeeParameterKey
The parameter registry key used to fetch the message fee.
function messageFeeParameterKey() public pure returns (string memory key_);
storageFeeParameterKey
The parameter registry key used to fetch the storage fee.
function storageFeeParameterKey() public pure returns (string memory key_);
congestionFeeParameterKey
The parameter registry key used to fetch the congestion fee.
function congestionFeeParameterKey() public pure returns (string memory key_);
targetRatePerMinuteParameterKey
The parameter registry key used to fetch the target rate per minute.
function targetRatePerMinuteParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
getRates
Returns a slice of the Rates list for pagination.
function getRates(uint256 fromIndex_, uint256 count_) external view returns (Rates[] memory rates_);
Parameters
| Name | Type | Description |
|---|---|---|
fromIndex_ | uint256 | Index from which to start (must be < allRates.length). |
count_ | uint256 | The number of items to return. |
Returns
| Name | Type | Description |
|---|---|---|
rates_ | Rates[] | The subset of Rates. |
getRatesCount
The total number of Rates stored.
function getRatesCount() external view returns (uint256 count_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfNoRateChange
Reverts if none of the rates have changed.
function _revertIfNoRateChange(
uint64 messageFee_,
uint64 storageFee_,
uint64 congestionFee_,
uint64 targetRatePerMinute_
) internal view;
Structs
RateRegistryStorage
The UUPS storage for the rate registry.
Note: storage-location: erc7201:xmtp.storage.RateRegistry
struct RateRegistryStorage {
Rates[] allRates;
}
Properties
| Name | Type | Description |
|---|---|---|
allRates | Rates[] | The array of all historical rates. |
SettlementChainGateway
Inherits: ISettlementChainGateway, Migratable, Initializable
A SettlementChainGateway exposes the ability to send parameters to any app chain gateways, via their respective inboxes on the settlement chain.
State Variables
parameterRegistry
The address of the parameter registry.
address public immutable parameterRegistry;
appChainGateway
The address of the app chain gateway.
address public immutable appChainGateway;
feeToken
The address of the fee token on the settlement chain, that is used to pay for gas on app chains.
address public immutable feeToken;
_underlyingFeeToken
The address of the token underlying the fee token.
address internal immutable _underlyingFeeToken;
_feeTokenDecimals
The number of decimals of the fee token.
uint8 internal immutable _feeTokenDecimals;
_receiveDepositDataLength
The length of the submission data for the receiveDeposit call to the app chain gateway.
uint256 internal immutable _receiveDepositDataLength;
_scale
The precomputed scaling factor between the fee token's decimals and 18 decimals (wei).
uint256 internal immutable _scale;
_SETTLEMENT_CHAIN_GATEWAY_STORAGE_LOCATION
bytes32 internal constant _SETTLEMENT_CHAIN_GATEWAY_STORAGE_LOCATION =
0xa66588577d68bb28d3fa2c7238607341f39141e4eaf5f706037ae5c1c2a15700;
Functions
_getSettlementChainGatewayStorage
function _getSettlementChainGatewayStorage() internal pure returns (SettlementChainGatewayStorage storage $);
whenNotPaused
modifier whenNotPaused();
constructor
Constructor for the implementation contract, such that the implementation cannot be initialized.
The parameter registry, app chain gateway, and fee token must not be the zero address.
The parameter registry, app chain gateway, and fee token are immutable so that they are inlined in the contract code, and have minimal gas cost.
constructor(address parameterRegistry_, address appChainGateway_, address feeToken_);
Parameters
| Name | Type | Description |
|---|---|---|
parameterRegistry_ | address | The address of the parameter registry. |
appChainGateway_ | address | The address of the app chain gateway. |
feeToken_ | address | The address of the fee token on the settlement chain, that is used to pay for gas on app chains. |
initialize
Initializes the contract.
function initialize() external initializer;
deposit
Deposits fee tokens as gas token to an app chain.
function deposit(uint256 chainId_, address recipient_, uint256 amount_, uint256 gasLimit_, uint256 maxFeePerGas_)
external
whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
depositWithPermit
Deposits fee tokens as gas token to an app chain, given caller's signed approval.
function depositWithPermit(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
depositFromUnderlying
Deposits fee tokens as gas token to an app chain, by wrapping underlying fee tokens.
function depositFromUnderlying(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_
) external whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of underlying fee tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
depositFromUnderlyingWithPermit
Deposits fee tokens as gas token to an app chain, by wrapping underlying fee tokens, given caller's signed approval.
function depositFromUnderlyingWithPermit(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
recipient_ | address | The recipient of the tokens. |
amount_ | uint256 | The amount of underlying fee tokens to deposit. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
sendParameters
Sends parameters to the app chain as retryable tickets (which may be a direct contract call).
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
function sendParameters(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) external whenNotPaused returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens that will be pulled by each inbox. |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
sendParametersWithPermit
Sends parameters to the app chain as retryable tickets (which may be a direct contract call), given caller's signed approval to pull fee tokens.
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
function sendParametersWithPermit(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external whenNotPaused returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens that will be pulled by each inbox. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
sendParametersFromUnderlying
Sends parameters to the app chain as retryable tickets (which may be a direct contract call).
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
function sendParametersFromUnderlying(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) external whenNotPaused returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens to send with the call to fund the alias on each app chain, which will first be converted from underlying fee tokens. |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
sendParametersFromUnderlyingWithPermit
Sends parameters to the app chain as retryable tickets (which may be a direct contract call), given caller's signed approval to pull underlying fee tokens.
This will perform an L2->L3 message, where the settlement gateway alias must have enough balance to pay for the function call (IAppChainGateway.receiveParameters), and the gas limit and price must suffice. If not, the message will remain as a retryable ticket on the app chain, that anyone can trigger and pay for.
function sendParametersFromUnderlyingWithPermit(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_,
uint256 deadline_,
uint8 v_,
bytes32 r_,
bytes32 s_
) external whenNotPaused returns (uint256 totalSent_);
Parameters
| Name | Type | Description |
|---|---|---|
chainIds_ | uint256[] | The chain IDs of the target app chains. |
keys_ | string[] | The keys of the parameters. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
amountToSend_ | uint256 | The amount of fee tokens to send with the call to fund the alias on each app chain, which will first be converted from underlying fee tokens. |
deadline_ | uint256 | The deadline of the permit (must be the current or future timestamp). |
v_ | uint8 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
r_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
s_ | bytes32 | An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712). |
Returns
| Name | Type | Description |
|---|---|---|
totalSent_ | uint256 | The total amount of fee tokens sent to all app chains combined. |
updateInbox
Updates the inbox for a chain ID.
function updateInbox(uint256 chainId_) external;
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID. |
updatePauseStatus
Updates the pause status.
Ensures the new pause status is not equal to the old pause status.
function updatePauseStatus() external;
migrate
Initiates a migration of the proxy, in a way defined by the implementation.
Normally, the implementation has a way of determining the migrator that needs to be delegatecalled.
function migrate() external;
receiveWithdrawal
Receives withdrawal of fee tokens from the app chain gateway.
function receiveWithdrawal(address recipient_) external returns (uint256 amount_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the tokens. |
Returns
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of fee tokens withdrawn. |
receiveWithdrawalIntoUnderlying
Receives withdrawal of fee tokens from the app chain gateway, and unwraps them into underlying fee tokens.
function receiveWithdrawalIntoUnderlying(address recipient_) external returns (uint256 amount_);
Parameters
| Name | Type | Description |
|---|---|---|
recipient_ | address | The recipient of the underlying fee tokens. |
Returns
| Name | Type | Description |
|---|---|---|
amount_ | uint256 | The amount of fee tokens withdrawn. |
appChainAlias
This contract's alias address on the L3 app chain.
function appChainAlias() public view returns (address alias_);
inboxParameterKey
The parameter registry key used to fetch the inbox.
function inboxParameterKey() public pure returns (string memory key_);
migratorParameterKey
The parameter registry key used to fetch the migrator.
function migratorParameterKey() public pure returns (string memory key_);
pausedParameterKey
The parameter registry key used to fetch the paused status.
function pausedParameterKey() public pure returns (string memory key_);
paused
The pause status.
function paused() external view returns (bool paused_);
calculateMaxDepositFee
Calculates the maximum fees (in wei, 18 decimals) that will be consumed for a deposit to an app chain.
function calculateMaxDepositFee(uint256 chainId_, uint256 gasLimit_, uint256 maxFeePerGas_, uint256 maxBaseFee_)
external
view
returns (uint256 fees_);
Parameters
| Name | Type | Description |
|---|---|---|
chainId_ | uint256 | The chain ID of the target app chain. |
gasLimit_ | uint256 | The gas limit for the transaction on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the transaction on the app chain. |
maxBaseFee_ | uint256 | The maximum base fee of the settlement chain, in wei (18 decimals). |
Returns
| Name | Type | Description |
|---|---|---|
fees_ | uint256 | The maximum fees (in wei, 18 decimals) that will be consumed for a deposit to an app chain. |
getInbox
The inbox address for a chain ID.
function getInbox(uint256 chainId_) external view returns (address inbox_);
_depositFeeToken
Transfers amount_ of fee tokens from the caller to this contract to satisfy a deposit to an app chain.
function _depositFeeToken(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_
) internal;
_depositFromUnderlying
Transfers amount_ of underlying fee tokens from the caller to this contract to satisfy a deposit to an app
chain.
function _depositFromUnderlying(
uint256 chainId_,
address recipient_,
uint256 amount_,
uint256 gasLimit_,
uint256 maxFeePerGas_
) internal;
_deposit
Deposits fee tokens into an inbox, to be used as native gas token on the app chain.
function _deposit(uint256 chainId_, address recipient_, uint256 amount_, uint256 gasLimit_, uint256 maxFeePerGas_)
internal;
_pullAndConvertUnderlying
Pull the underlying fee tokens from the caller, and convert them to fee tokens.
function _pullAndConvertUnderlying(uint256 amount_) internal;
_sendParametersFromFeeToken
Sends parameters to the app chains via a retryable tickets, pulling fee tokens from the caller.
function _sendParametersFromFeeToken(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) internal returns (uint256 totalSent_);
_sendParametersFromUnderlying
Sends parameters to the app chains via a retryable tickets, pulling underlying fee tokens from the caller.
function _sendParametersFromUnderlying(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) internal returns (uint256 totalSent_);
_sendParameters
Sends parameters to the app chains via a retryable tickets.
function _sendParameters(
uint256[] calldata chainIds_,
string[] calldata keys_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 amountToSend_
) internal;
_createRetryableTicket
Creates a retryable ticket, via the inbox, to perform a call to the app chain gateway (on the app chain).
feeTokenAmount_ (converted to 18 decimals) must be greater or equal to
maxSubmissionCost_ + callValue_ + (gasLimit_ * maxFeePerGas_)
function _createRetryableTicket(
address inbox_,
uint256 callValue_,
uint256 maxSubmissionCost_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 feeTokenAmount_,
bytes memory data_
) internal returns (uint256 messageNumber_);
Parameters
| Name | Type | Description |
|---|---|---|
inbox_ | address | The inbox via which to create a retryable ticket. |
callValue_ | uint256 | The call value (18 decimals) to send with the call to the app chain gateway. |
maxSubmissionCost_ | uint256 | The maximum submission cost (18 decimals) for the retryable ticket. |
gasLimit_ | uint256 | The gas limit for the call to the app chain gateway. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the call to the app chain gateway. |
feeTokenAmount_ | uint256 | The total fee tokens (fee token decimals) that should be pulled by the inbox. |
data_ | bytes | The data to call to call the app chain gateway with. |
Returns
| Name | Type | Description |
|---|---|---|
messageNumber_ | uint256 | The message number of the retryable ticket. |
_usePermit
Uses a permit to approve the deposit of amount_ of token_ from the caller to this contract.
Silently ignore a failing permit, as it may indicate that the permit was already used and/or the allowance has already been approved.
function _usePermit(address token_, uint256 amount_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_) internal;
_prepareWithdrawal
Prepares a withdrawal of fee tokens by querying the available balance and emitting an event.
function _prepareWithdrawal(address recipient_) internal returns (uint256 amount_);
_calculateMaxCosts
Calculates the total fees to submit a retryable ticket and call the app chain gateway on the app chain.
function _calculateMaxCosts(
address inbox_,
uint256 dataLength_,
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 maxBaseFee_
) internal view returns (uint256 maxSubmissionCost_, uint256 maxTransactionCost_);
Parameters
| Name | Type | Description |
|---|---|---|
inbox_ | address | The inbox to the app chain. |
dataLength_ | uint256 | The length of the call data to send to the app chain. |
gasLimit_ | uint256 | The gas limit for the call on the app chain. |
maxFeePerGas_ | uint256 | The maximum fee per gas (EIP-1559) for the call on the app chain. |
maxBaseFee_ | uint256 | The maximum base fee of the settlement chain, in wei (18 decimals). |
Returns
| Name | Type | Description |
|---|---|---|
maxSubmissionCost_ | uint256 | The maximum submission cost for the retryable ticket, in wei (18 decimals). |
maxTransactionCost_ | uint256 | The maximum transaction cost for the call on the app chain, in wei (18 decimals). |
_convertToWei
function _convertToWei(uint256 value_) internal view returns (uint256 wei_);
_convertFromWei
function _convertFromWei(uint256 value_) internal view returns (uint256 newValue_);
_getInboxKey
Returns the inbox-specific key used to query to parameter registry to determine the inbox for a chain ID. The inbox-specific key is the concatenation of the inbox parameter key and the chain ID. For example, if the inbox parameter key is "xmtp.settlementChainGateway.inbox", then the key for chain ID 1 is "xmtp.settlementChainGateway.inbox.1".
function _getInboxKey(string memory inboxParameterKey_, uint256 chainId_) internal pure returns (string memory key_);
_getInbox
function _getInbox(uint256 chainId_) internal view returns (address inbox_);
_isZero
function _isZero(address input_) internal pure returns (bool isZero_);
_revertIfPaused
function _revertIfPaused() internal view;
Structs
SettlementChainGatewayStorage
The UUPS storage for the settlement chain gateway.
Note: storage-location: erc7201:xmtp.storage.SettlementChainGateway
struct SettlementChainGatewayStorage {
bool paused;
uint256 nonce;
mapping(uint256 chainId => address inbox) inboxes;
}
Properties
| Name | Type | Description |
|---|---|---|
paused | bool | |
nonce | uint256 | The nonce of the parameter transmission (to prevent out-of-sequence resets). |
inboxes | mapping(uint256 chainId => address inbox) |
SettlementChainParameterRegistry
Inherits: ISettlementChainParameterRegistry, ParameterRegistry
A SettlementChainParameterRegistry is a parameter registry used by the protocol contracts on the settlement chain.
Functions
migratorParameterKey
The parameter registry key used to fetch the migrator.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function migratorParameterKey()
public
pure
override(IParameterRegistry, ParameterRegistry)
returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the migrator parameter. |
adminParameterKey
The parameter registry key used to fetch the status of an admin.
Uniquely, the parameter registry uses itself, so the key-value pair is stored in the contract itself.
function adminParameterKey() public pure override(IParameterRegistry, ParameterRegistry) returns (string memory key_);
Returns
| Name | Type | Description |
|---|---|---|
key_ | string | The key of the admin parameter, which is a component of the full key, when prefixing an address. |