# IERC20PaymentClientBase\_v1.sol

[Git Source](https://github.com/InverterNetwork/inverter-contracts/blob/649b450f02fc8b735c128ff0821467e71966c666/src/modules/logicModule/interfaces/IERC20PaymentClientBase_v1.sol)

**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. Refer to the implementations contract for more details.

*STRUCTURING OF THE FLAGS AND DATA FIELDS The PaymentOrder struct implements a flag system to manage the information payloads received by the payment processor. It is comprised of a bytes32 value that indicates the number of flags that are active, and a bytes32\[] value that stores the corresponding values. For example: If the value of 'flags' is '0000 \[...] 0000 1011', then that order stores values for the paramters 0, 1 and 3 of the master list. The byte code for simple flag setups might also be represented by hexadecimal values like 0xB, which has the same value as the bit combination above. If a module wants to set flags, it can use bit shifts, in this case 1 << 0, 1 << 1 and 1 << 3. Afterwards, to be correct, the following data variable should contain 3 elements of the type specified in the master list, each stored as bytes32 value.*

### Functions

#### paymentOrders

Returns the list of outstanding payment orders.

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

**Returns**

| Name     | Type             | Description             |
| -------- | ---------------- | ----------------------- |
| `<none>` | `PaymentOrder[]` | list of payment orders. |

#### outstandingTokenAmount

Returns the total outstanding token payment amount.

```solidity
function outstandingTokenAmount(address token_)
    external
    view
    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.*

```solidity
function collectPaymentOrders()
    external
    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.*

*This has to be called by a paymentProcessor.*

```solidity
function amountPaid(address token_, uint amount_) external;
```

**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.

```solidity
function getFlags() external 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.

```solidity
function getFlagCount() external view returns (uint8 flagCount_);
```

**Returns**

| Name         | Type    | Description          |
| ------------ | ------- | -------------------- |
| `flagCount_` | `uint8` | The number of flags. |

### Events

#### PaymentOrderAdded

Added a payment order.

```solidity
event PaymentOrderAdded(
    address indexed recipient,
    address indexed token,
    uint amount,
    uint originChainId,
    uint targetChainId,
    bytes32 flags,
    bytes32[] data
);
```

**Parameters**

| Name            | Type        | Description                                                    |
| --------------- | ----------- | -------------------------------------------------------------- |
| `recipient`     | `address`   | The address that will receive the payment.                     |
| `token`         | `address`   | The token in which to pay.                                     |
| `amount`        | `uint256`   | The amount of tokens the payment consists of.                  |
| `originChainId` | `uint256`   | The id of the origin chain.                                    |
| `targetChainId` | `uint256`   | The id of the target chain.                                    |
| `flags`         | `bytes32`   | Flags that indicate additional data used by the payment order. |
| `data`          | `bytes32[]` | Array of additional data regarding the payment order.          |

#### FlagsSet

Emitted when the flags are set.

```solidity
event FlagsSet(uint8 flagCount, bytes32 newFlags);
```

**Parameters**

| Name        | Type      | Description              |
| ----------- | --------- | ------------------------ |
| `flagCount` | `uint8`   | The number of flags set. |
| `newFlags`  | `bytes32` | The newly set flags.     |

### Errors

#### Module\_\_ERC20PaymentClientBase\_\_CallerNotAuthorized

Function is only callable by authorized address.

```solidity
error Module__ERC20PaymentClientBase__CallerNotAuthorized();
```

#### Module\_\_ERC20PaymentClientBase\_\_TokenTransferFailed

ERC20 token transfer failed.

```solidity
error Module__ERC20PaymentClientBase__TokenTransferFailed();
```

#### Module\_\_ERC20PaymentClientBase\_\_InsufficientFunds

Insufficient funds to fulfill the payment.

```solidity
error Module__ERC20PaymentClientBase__InsufficientFunds(address token);
```

**Parameters**

| Name    | Type      | Description                              |
| ------- | --------- | ---------------------------------------- |
| `token` | `address` | The token in which the payment was made. |

#### Module\_\_ERC20PaymentClientBase\_\_InvalidRecipient

Given recipient invalid.

```solidity
error Module__ERC20PaymentClientBase__InvalidRecipient();
```

#### Module\_\_ERC20PaymentClientBase\_\_InvalidToken

Given token invalid.

```solidity
error Module__ERC20PaymentClientBase__InvalidToken();
```

#### Module\_\_ERC20PaymentClientBase\_\_InvalidAmount

Given amount invalid.

```solidity
error Module__ERC20PaymentClientBase__InvalidAmount();
```

#### Module\_\_ERC20PaymentClientBase\_\_InvalidPaymentOrder

Given paymentOrder is invalid.

```solidity
error Module__ERC20PaymentClientBase__InvalidPaymentOrder();
```

#### Module\_\_ERC20PaymentClientBase\_\_MismatchBetweenFlagCountAndArrayLength

Given mismatch between flag count and supplied array length.

```solidity
error Module__ERC20PaymentClientBase__MismatchBetweenFlagCountAndArrayLength(
    uint8 flagCount, uint arrayLength
);
```

#### Module\_\_ERC20PaymentClientBase\_v1\_\_FlagAmountTooHigh

Given number of flags exceeds the limit.

```solidity
error Module__ERC20PaymentClientBase_v1__FlagAmountTooHigh();
```

### Structs

#### PaymentOrder

Struct used to store information about a payment order.

```solidity
struct PaymentOrder {
    address recipient;
    address paymentToken;
    uint amount;
    uint originChainId;
    uint targetChainId;
    bytes32 flags;
    bytes32[] data;
}
```

**Properties**

| Name            | Type        | Description                                                         |
| --------------- | ----------- | ------------------------------------------------------------------- |
| `recipient`     | `address`   | The recipient of the payment.                                       |
| `paymentToken`  | `address`   | The token in which to pay. Assumed to always be on the local chain. |
| `amount`        | `uint256`   | The amount of tokens to pay.                                        |
| `originChainId` | `uint256`   | The id of the origin chain.                                         |
| `targetChainId` | `uint256`   | The id of the target chain.                                         |
| `flags`         | `bytes32`   | Flags that indicate which information the data array contains.      |
| `data`          | `bytes32[]` | Array of additional data regarding the payment order.               |
