Skip to content

Recurring Payment Manager

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

File: RecurringPaymentManager

Things to know

  1. A logic module to create recurring payment orders and process them using the payment processor of choice.
  2. This enables epoch-based payment order vesting, where all previously valid vested payment orders can be triggered entirely or selectively.
  3. The crux of this module involves a RecurringPayment struct and it is defined as:
uint amount;
uint startEpoch; //in which epoch this should start
uint lastTriggeredEpoch; //When was the last epoch this Payment was triggered
address recipient;

Modifiers

1. validId

modifier validId(uint recurringPaymentId)

The recurringPaymentId should not be an existing recurring payment id.

2. validStartEpoch

modifier validStartEpoch(uint startEpoch)

The startEpoch should not be less than current epoch.

3. startIdBeforeEndId

modifier startIdBeforeEndId(uint startId, uint endId)

The endId has to be greater than the startId.

View Functions

  1. getEpochLength
function getEpochLength() external view returns (uint epochLength);

Returns the length of an epoch.

Return Data

  1. uint epochLength: Length of an epoch in a uint timestamp

  2. getRecurringPaymentInformation

function getRecurringPaymentInformation(uint id)
        external
        view
        returns (RecurringPayment memory);

Returns the RecurringPayment instance with id id.

Parameters

  1. uint id: The id of the RecurringPayment to return.

Return Data

  1. RecurringPayment: RecurringPayment with id id.

  2. listRecurringPaymentIds

function listRecurringPaymentIds() external view returns (uint[] memory);

Returns total list of RecurringPayment ids. The list is in ascending order.

Return Data

  1. uint[]: List of RecurringPayment ids.

  2. getPreviousPaymentId

function getPreviousPaymentId(uint id)
        external
        view
        returns (uint prevId);

Returns the id of previous RecurringPayment.

Parameters

  1. uint id: The id of the RecurringPayment to return.

Return Data

  1. uint prevId: The id of previous RecurringPayment.

  2. isExistingRecurringPaymentId

function isExistingRecurringPaymentId(uint id)
        external
        view
        returns (bool);

Returns whether RecurringPayment with id id exists.

Parameters

  1. uint id: ID of the recurring payment.

Return Data

  1. bool: True if RecurringPayment with id id exists, false otherwise.

  2. getEpochFromTimestamp

function getEpochFromTimestamp(uint timestamp)
        external
        view
        returns (uint epoch);

Calculates the epoch from a given uint timestamp and the calculation is: timestamp divided by epochLength.

Parameters

  1. uint timestamp: a timestamp in a uint format

Return Data

  1. uint epoch: epoch in which timestamp belongs to

  2. getCurrentEpoch

function getCurrentEpoch() external view returns (uint epoch);

Calculates the current epoch and the calculation is: block.timestamp divided by epochLength.

Return Data

  1. uint epoch : epoch in which current timestamp (block.timestamp) belongs to

  2. getFutureEpoch

function getFutureEpoch(uint xEpochsInTheFuture)
        external
        view
        returns (uint futureEpoch);

Calculates a future epoch, x epochs from now. The calculation is: current epoch + X epochs in the future = futureEpoch

Parameters

  1. uint xEpochsInTheFuture : how many epochs from the current epoch

Return Data

  1. uint futureEpoch : epoch in the future

Write Functions

  1. addRecurringPayment
function addRecurringPayment(
        uint amount,
        uint startEpoch,
        address recipient
    ) external returns (uint id);

Adds a recurring payment to the manager. A new id is created for each Payment.

Parameters

  1. uint amount: amount of tokens send to the recipient address
  2. uint startEpoch: epoch in which the payment starts. Use getEpochFromTimestamp() or getCurrentEpoch() to get the appropriate epoch
  3. address recipient: recipient address that should receive tokens

Return Data

  1. uint: id of the newly created recurring payment

  2. removeRecurringPayment

function removeRecurringPayment(uint prevId, uint id) external;

Removes a recurring Payment.

Parameters

  1. uint prevId: id of the previous recurring payment in the payment list

  2. uint id: id of the recurring payment that is to be removed

  3. trigger

function trigger() external;

Triggers the start of the due payments for all recurring payment orders.

  1. triggerFor
function triggerFor(uint startId, uint endId) external;

See trigger() but enables you to determine which ids you want to trigger payment ordes for. This is to being able to bypass the unlikely event of having a runOutOfGas error for the normal trigger function

Parameters

  1. uint startId: id of start position of the recurring payments that should be triggered
  2. uint endId: id of end position of the recurring payments that should be triggered