IPayerRegistry

Git Source

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

NameTypeDescription
payer_addressThe address of the payer.
amount_uint96The 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

NameTypeDescription
payer_addressThe address of the payer.
amount_uint96The amount of fee tokens to deposit.
deadline_uint256The deadline of the permit (must be the current or future timestamp).
v_uint8An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712).
r_bytes32An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712).
s_bytes32An 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

NameTypeDescription
payer_addressThe address of the payer.
amount_uint96The 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

NameTypeDescription
payer_addressThe address of the payer.
amount_uint96The amount of underlying fee tokens to deposit.
deadline_uint256The deadline of the permit (must be the current or future timestamp).
v_uint8An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712).
r_bytes32An ECDSA secp256k1 signature parameter (EIP-2612 via EIP-712).
s_bytes32An 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

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

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

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

NameTypeDescription
payerReportId_bytes32The ID of the payer report triggering the settlement.
payerFees_PayerFee[]An array of structs containing the payer and the fee to settle.

Returns

NameTypeDescription
feesSettled_uint96The total amount of fees settled.

sendExcessToFeeDistributor

Sends the excess tokens in the contract to the fee distributor.

function sendExcessToFeeDistributor() external returns (uint96 excess_);

Returns

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

NameTypeDescription
payer_addressThe address of the payer.

Returns

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

NameTypeDescription
payers_address[]An array of payer addresses.

Returns

NameTypeDescription
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

NameTypeDescription
payer_addressThe address of the payer.

Returns

NameTypeDescription
pendingWithdrawal_uint96The amount of a pending withdrawal, if any.
withdrawableTimestamp_uint32The timestamp when the pending withdrawal can be finalized.
nonce_uint24The nonce associated with the pending withdrawal.

Events

SettlerUpdated

Emitted when the settler is updated.

event SettlerUpdated(address indexed settler);

Parameters

NameTypeDescription
settleraddressThe address of the new settler.

FeeDistributorUpdated

Emitted when the fee distributor is updated.

event FeeDistributorUpdated(address indexed feeDistributor);

Parameters

NameTypeDescription
feeDistributoraddressThe address of the new fee distributor.

MinimumDepositUpdated

Emitted when the minimum deposit is updated.

event MinimumDepositUpdated(uint96 minimumDeposit);

Parameters

NameTypeDescription
minimumDeposituint96The new minimum deposit amount.

WithdrawLockPeriodUpdated

Emitted when the withdraw lock period is updated.

event WithdrawLockPeriodUpdated(uint32 withdrawLockPeriod);

Parameters

NameTypeDescription
withdrawLockPerioduint32The new withdraw lock period.

Deposit

Emitted when a deposit of fee tokens occurs for a payer.

event Deposit(address indexed payer, uint96 amount);

Parameters

NameTypeDescription
payeraddressThe address of the payer.
amountuint96The 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

NameTypeDescription
payeraddressThe address of the payer.
amountuint96The amount of fee tokens requested for withdrawal.
withdrawableTimestampuint32The timestamp when the withdrawal can be finalized.
nonceuint24The nonce associated with the requested withdrawal.

WithdrawalCancelled

Emitted when a payer's pending withdrawal is cancelled.

event WithdrawalCancelled(address indexed payer, uint24 nonce);

Parameters

NameTypeDescription
payeraddressThe address of the payer.
nonceuint24The nonce associated with the cancelled withdrawal.

WithdrawalFinalized

Emitted when a payer's pending withdrawal is finalized.

event WithdrawalFinalized(address indexed payer, uint24 nonce);

Parameters

NameTypeDescription
payeraddressThe address of the payer.
nonceuint24The 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

NameTypeDescription
payerReportIdbytes32The ID of the payer report triggering the settlement.
payeraddressThe address of the payer.
amountuint96The 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

NameTypeDescription
amountuint96The amount of excess fee tokens transferred.

PauseStatusUpdated

Emitted when the pause status is set.

event PauseStatusUpdated(bool indexed paused);

Parameters

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

NameTypeDescription
amountuint96The amount of fee tokens being deposited.
minimumDeposituint96The 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

NameTypeDescription
timestampuint32The current timestamp.
withdrawableTimestampuint32The timestamp when the withdrawal can be finalized.
nonceuint24The 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

NameTypeDescription
balanceint104The signed balance of the payer (negative if debt).
pendingWithdrawaluint96The amount of a pending withdrawal, if any.
withdrawableTimestampuint32The timestamp when the pending withdrawal can be finalized.
withdrawalNonceuint24The nonce associated with the pending withdrawal. Used for offchain tracking.

PayerFee

Represents a payer and their fee.

struct PayerFee {
    address payer;
    uint96 fee;
}

Properties

NameTypeDescription
payeraddressThe address a payer.
feeuint96The fee to settle for the payer.