ERC20PaymentClientBase_v1.sol

ERC20PaymentClientBase_v1

Git Source

Inherits: IERC20PaymentClientBase_v1, Module_v1

Author: Inverter Network

Enables modules within the Inverter Network to create and manage payment orders that can be processed by authorized payment processors, ensuring efficient and secure transactions.

Utilizes {SafeERC20} for token operations and integrates with {IPaymentProcessor_v1} to handle token payments. This abstract contract must be extended by modules that manage {ERC20} payment orders, supporting complex payment scenarios.

State Variables

_orders

The list of oustanding orders.

Emptied whenever orders are collected.

PaymentOrder[] internal _orders;

_outstandingTokenAmounts

The current cumulative amount of tokens outstanding.

mapping(address => uint) internal _outstandingTokenAmounts;

_flagCount

The number of payment processor flags used by this payment client.

uint8 internal _flagCount;

_flags

The payment processor flags used by this payment client.

bytes32 internal _flags;

__gap

Storage gap for future upgrades.

uint[48] private __gap;

Functions

supportsInterface

See {IERC165-supportsInterface}.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(Module_v1)
    returns (bool);

validRecipient

Modifier to guarantee the recipient is valid.

modifier validRecipient(address recipient);

validAmount

Modifier to guarantee the amount is valid.

modifier validAmount(uint amount);

validPaymentOrder

Modifier to guarantee the payment order is valid.

modifier validPaymentOrder(PaymentOrder memory order);

__ERC20PaymentClientBase_v1_init

Initializes the staking contract.

function __ERC20PaymentClientBase_v1_init(uint8[] memory flags_)
    internal
    onlyInitializing;

Parameters

Name
Type
Description

flags_

uint8[]

The flags, represented as an array of uint8 containing the flag IDs between 0 and 255.

_addPaymentOrder

Adds a new {PaymentOrder} to the list of outstanding orders.

function _addPaymentOrder(PaymentOrder memory order)
    internal
    virtual
    validPaymentOrder(order);

Parameters

Name
Type
Description

order

PaymentOrder

The new payment order.

_addPaymentOrders

Adds a set of new {PaymentOrder}s to the list of outstanding orders.

function _addPaymentOrders(PaymentOrder[] memory orders) internal virtual;

Parameters

Name
Type
Description

orders

PaymentOrder[]

The list of new Payment Orders.

_setFlags

Sets the flags for the PaymentOrders.

function _setFlags(uint8 flagCount_, uint8[] memory flags_) internal virtual;

Parameters

Name
Type
Description

flagCount_

uint8

The number of flags.

flags_

uint8[]

The flags, represented as an array of uint8 containing the flag IDs between 0 and 255.

paymentOrders

Returns the list of outstanding payment orders.

function paymentOrders()
    external
    view
    virtual
    returns (PaymentOrder[] memory);

Returns

Name
Type
Description

<none>

PaymentOrder[]

list of payment orders.

outstandingTokenAmount

Returns the total outstanding token payment amount.

function outstandingTokenAmount(address token_)
    external
    view
    virtual
    returns (uint total_);

Parameters

Name
Type
Description

token_

address

The token in which to pay.

Returns

Name
Type
Description

total_

uint256

amount of token to pay.

collectPaymentOrders

Collects outstanding payment orders.

Marks the orders as completed for the client.

function collectPaymentOrders()
    external
    virtual
    returns (
        PaymentOrder[] memory paymentOrders_,
        address[] memory tokens_,
        uint[] memory totalAmounts_
    );

Returns

Name
Type
Description

paymentOrders_

PaymentOrder[]

list of payment orders.

tokens_

address[]

list of token addresses.

totalAmounts_

uint256[]

list of amounts.

amountPaid

Notifies the PaymentClient, that tokens have been paid out accordingly.

Payment Client will reduce the total amount of tokens it will stock up by the given amount.

function amountPaid(address token_, uint amount_) external virtual;

Parameters

Name
Type
Description

token_

address

The token in which the payment was made.

amount_

uint256

amount of tokens that have been paid out.

getFlags

Returns the flags used when creating payment orders in this client.

function getFlags() public view returns (bytes32 flags_);

Returns

Name
Type
Description

flags_

bytes32

The flags this client will use.

getFlagCount

Returns the number of flags this client uses for PaymentOrders.

function getFlagCount() public view returns (uint8 flagCount_);

Returns

Name
Type
Description

flagCount_

uint8

The number of flags.

_ensureValidRecipient

Ensures the recipient is valid.

function _ensureValidRecipient(address recipient) private view;

Parameters

Name
Type
Description

recipient

address

The recipient to check.

_ensureValidAmount

Ensures the amount is valid.

function _ensureValidAmount(uint amount) private pure;

Parameters

Name
Type
Description

amount

uint256

The amount to check.

_ensureValidToken

Ensures the token is valid.

function _ensureValidToken(address token) private pure;

Parameters

Name
Type
Description

token

address

The token to check.

_ensureValidPaymentOrder

Ensures the payment order is valid.

function _ensureValidPaymentOrder(PaymentOrder memory order) private;

Parameters

Name
Type
Description

order

PaymentOrder

The payment order to check.

_ensureTokenBalance

Ensures amount of payment tokens exist in address(this). In case the token being paid out is the FundingManager token, it will trigger a callback to the FundingManager to transfer the tokens to

function _ensureTokenBalance(address token) internal virtual;

_ensureTokenAllowance

Ensures amount of token allowance for payment processor(s).

function _ensureTokenAllowance(IPaymentProcessor_v1 spender, address token)
    internal
    virtual;

_isAuthorizedPaymentProcessor

Returns whether address who is an authorized payment processor.

function _isAuthorizedPaymentProcessor(IPaymentProcessor_v1 who)
    internal
    view
    virtual
    returns (bool);

_assemblePaymentConfig

Returns the payment configuration from a list of supplied flag values. Can be overriden to add additional validation steps.

function _assemblePaymentConfig(bytes32[] memory flagValues_)
    internal
    view
    virtual
    returns (bytes32 flags_, bytes32[] memory data_);

Last updated