Skip to content

Streaming Payment Processor

Rahul Saxena edited this page Aug 11, 2023 · 3 revisions

File: StreamingPaymentProcessor.sol

Things to know

  1. This is another type of payment processor, that is used to process pre-existing payment orders.
  2. It enables Linear Vesting Curve.
  3. The payment module handles the money flow to the paymentReceivers (e.g. how many tokens are sent to which paymentReceiver at what time).
  4. Concurrent streaming allows for several active vestings per destination address.

Modifiers

  1. onlyModule
modifier onlyModule()

Checks whether the caller is an active module or not.

  1. validClient
modifier validClient(IERC20PaymentClient client)

Checks whether the client is calling for itself. The PaymentManager cannot call on other client's orders.

  1. activePaymentReceiver
modifier activePaymentReceiver(address client, address paymentReceiver) 

Checks whether the paymentReceiver actually has something remaining to be claimed or not.

View Functions

1. isActivePaymentReceiver

 function isActivePaymentReceiver(address client, address paymentReceiver)
        external
        view
        returns (bool);

Tells whether a paymentReceiver has any pending payments for a particular client. This function is for convenience and can be easily figured out by other means in the codebase.

Parameters

  1. address client: Address of the payment client
  2. address paymentReceiver: Address of the paymentReceiver

Return Data

  1. bool: Whether paymentReceiver has pending payments or not.

2. startForSpecificWalletId

function startForSpecificWalletId(
        address client,
        address paymentReceiver,
        uint walletId
    ) external view returns (uint);

Getter for the start timestamp of a particular payment order with id = walletId associated with a particular paymentReceiver.

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.
  3. uint walletId: Id of the wallet for which start is fetched

Return Data

  1. uint: the start timestamp of a particular payment order

3. dueToForSpecificWalletId

function dueToForSpecificWalletId(
        address client,
        address paymentReceiver,
        uint walletId
    ) external view returns (uint);

Getter for the vesting dueTo timestamp of a particular payment order with id = walletId associated with a particular paymentReceiver

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.
  3. uint walletId: Id of the wallet for which start is fetched

Return Data

  1. uint: the vesting dueTo timestamp of a particular payment order

4. releasedForSpecificWalletId

function releasedForSpecificWalletId(
        address client,
        address paymentReceiver,
        uint walletId
    ) external view returns (uint);

Getter for the number of tokens already released for a particular payment order with id = walletId associated with a particular paymentReceiver

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.
  3. uint walletId: Id of the wallet for which start is fetched

Return Data

  1. uint: number of tokens already released for a particular payment order

5. vestedAmountForSpecificWalletId

function vestedAmountForSpecificWalletId(
        address client,
        address paymentReceiver,
        uint timestamp,
        uint walletId
    ) external view returns (uint);

Calculates the number of tokens that have already vested for a particular payment order with id = walletId associated with a particular paymentReceiver.

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.
  3. uint timestamp: the time upto which we want the vested amount
  4. uint walletId: Id of the wallet for which start is fetched

Return Data

  1. uint: number of tokens that have already vested

6. releasableForSpecificWalletId

function releasableForSpecificWalletId(
        address client,
        address paymentReceiver,
        uint walletId
    ) external view returns (uint);

Getter for the number of releasable tokens for a particular payment order with id = walletId associated with a particular paymentReceiver.

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.
  3. uint walletId: Id of the wallet for which start is fetched

Return Data

  1. uint: number of releasable tokens for a particular payment order

7. unclaimable

function unclaimable(address client, address paymentReceiver)
        external
        view
        returns (uint);

Getter for the number of tokens that could not be claimed.

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.

Return Data:

  1. uint: number of tokens that could not be claimed.

8. viewAllPaymentOrders

function viewAllPaymentOrders(address client, address paymentReceiver)
        external
        view
        returns (VestingWallet[] memory);

See all active payment orders for a paymentClient associated with a particular paymentReceiver. The paymentReceiver must be an active paymentReceiver for the particular payment client

Parameters

  1. address client: address of the payment client
  2. address paymentReceiver: PaymentReceiver's address.

Return Data:

  1. VestingWallet[]: A VestingWallet struct is used to store the payment order for a particular paymentReceiver by a particular payment client. This is an array of all eligible vesting wallets.

Write Functions

1. init

function init(
        IOrchestrator orchestrator_,
        Metadata memory metadata,
        bytes memory
    ) external override(Module) initializer

Used to initialize the module. Has to be necessarily implemented in all modules.

Parameters

  1. IOrchestrator orchestrator_: Instance of the orchestrator for which this module is being used
  2. Metadata metadata: Metadata about the StreamingPaymentProcessor module

2. claimAll

function claimAll(IERC20PaymentClient client) external;

Claim everything that the paymentClient owes to the _msgSender till the current timestamp. This function should be callable if the _msgSender is either an activePaymentReceiver or has some unclaimedAmounts

Parameters

  1. IERC20PaymentClient client: The {IERC20PaymentClient} instance to process all claims from _msgSender

3. claimForSpecificWalletId

function claimForSpecificWalletId(
        IERC20PaymentClient client,
        uint walletId,
        bool retryForUnclaimableAmounts
    ) external;

Claim the salary uptil block.timestamp from the client for a payment order with id = walletId by _msgSender. If for a specific walletId, the tokens could not be transferred for some reason, it will added to the unclaimableAmounts of the paymentReceiver, and the amount would no longer hold any co-relation with the specific walletId of the paymentReceiver.

Parameters

  1. IERC20PaymentClient client: The {IERC20PaymentClient} instance to process the walletId claim from _msgSender
  2. uint walletId: The ID of the payment order for which claim is being made
  3. bool retryForUnclaimableAmounts: boolean which determines if the function will try to pay the unclaimable amounts from earlier along with the vested salary from the payment order with id = walletId

4. processPayments

function processPayments(IERC20PaymentClient client) external;

Processes all payments from an {IERC20PaymentClient} instance.

Parameters

  1. IERC20PaymentClient client: The {IERC20PaymentClient} instance to process its to payments

5. cancelRunningPayments

function cancelRunningPayments(IERC20PaymentClient client) external;

Parameters

  1. IERC20PaymentClient client: The {IERC20PaymentClient} instance to process its to payments

Cancels all unfinished payments from an {IERC20PaymentClient} instance.

6. removeAllPaymentReceiverPayments

function removeAllPaymentReceiverPayments(
        IERC20PaymentClient client,
        address paymentReceiver
    ) external;

Deletes all payments related to a paymentReceiver & leaves unvested tokens in the ERC20PaymentClient. This function calls _removePayment which goes through all the payment orders for a paymentReceiver. For the payment orders that are completely vested, their details are deleted in the _claimForSpecificWalletId function, and for others it is deleted in the _removePayment function only, leaving the unvested tokens as the balance of the paymentClient itself.

Parameters

  1. IERC20PaymentClient client: The {IERC20PaymentClient} instance from which we will remove the payments
  2. address paymentReceiver: PaymentReceiver's address.

7. removePaymentForSpecificWalletId

function removePaymentForSpecificWalletId(
        IERC20PaymentClient client,
        address paymentReceiver,
        uint walletId,
        bool retryForUnclaimableAmounts
    ) external;

Deletes a specific payment with id = walletId for a paymentReceiver & leaves unvested tokens in the ERC20PaymentClient. The detail of the wallet that is being removed is either deleted in the _claimForSpecificWalletId or later down in this function itself depending on the timestamp of when this function was called.

Parameters

  1. IERC20PaymentClient client: The {IERC20PaymentClient} instance from which we will remove the payment
  2. address paymentReceiver: address of the paymentReceiver whose payment order is to be removed
  3. uint walletId: The ID of the paymentReceiver's payment order which is to be removed
  4. bool retryForUnclaimableAmounts: boolean that determines whether the function would try to return the unclaimableAmounts along with the vested amounts from the payment order with id = walletId to the paymentReceiver
Clone this wiki locally