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;
}