DistributionManager

Git Source

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

NameTypeDescription
parameterRegistry_addressThe address of the parameter registry.
nodeRegistry_addressThe address of the node registry.
payerReportManager_addressThe address of the payer report manager.
payerRegistry_addressThe address of the payer registry.
feeToken_addressThe 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

NameTypeDescription
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

NameTypeDescription
claimed_uint96The 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

NameTypeDescription
nodeId_uint32The 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

NameTypeDescription
claimed_uint96The amount of fees claimed.

withdrawProtocolFees

Withdraws protocol fees.

function withdrawProtocolFees() external whenNotPaused returns (uint96 withdrawn_);

Returns

NameTypeDescription
withdrawn_uint96The amount of protocol fees withdrawn.

withdrawProtocolFeesIntoUnderlying

Withdraws protocol fees, unwrapped as underlying token.

function withdrawProtocolFeesIntoUnderlying() external whenNotPaused returns (uint96 withdrawn_);

Returns

NameTypeDescription
withdrawn_uint96The amount of protocol fees withdrawn.

withdraw

Withdraws fees for a node.

function withdraw(uint32 nodeId_, address recipient_) external whenNotPaused returns (uint96 withdrawn_);

Parameters

NameTypeDescription
nodeId_uint32The ID of the node.
recipient_addressThe address to withdraw the fee tokens to.

Returns

NameTypeDescription
withdrawn_uint96The 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

NameTypeDescription
nodeId_uint32The ID of the node.
recipient_addressThe address to withdraw the underlying fee tokens to.

Returns

NameTypeDescription
withdrawn_uint96The 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

NameTypeDescription
nodeId_uint32The ID of the node.

Returns

NameTypeDescription
owedFees_uint96The 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

NameTypeDescription
originatorNodeId_uint32The ID of the originator node of the payer report.
payerReportIndex_uint256The index of the payer report.

Returns

NameTypeDescription
areClaimed_boolWhether 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

NameTypeDescription
nodeId_uint32The ID of the node.
originatorNodeId_uint32The ID of the originator node of the payer report.
payerReportIndex_uint256The index of the payer report.

Returns

NameTypeDescription
hasClaimed_boolareClaimed_ 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

NameTypeDescription
owed_uint96The amount of fees owed.

Returns

NameTypeDescription
withdrawable_uint96The 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

NameTypeDescription
feesSettled_uint96Total fees collected.
protocolFeeRate_uint16Protocol fee rate in basis points.
nodeCount_uint256Number of nodes sharing the remaining fees.

Returns

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