-
Notifications
You must be signed in to change notification settings - Fork 16
Recurring Payment Manager
File: RecurringPaymentManager
- A logic module to create recurring payment orders and process them using the payment processor of choice.
- This enables epoch-based payment order vesting, where all previously valid vested payment orders can be triggered entirely or selectively.
- 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;
modifier validId(uint recurringPaymentId)
The recurringPaymentId
should not be an existing recurring payment id.
modifier validStartEpoch(uint startEpoch)
The startEpoch
should not be less than current epoch.
modifier startIdBeforeEndId(uint startId, uint endId)
The endId
has to be greater than the startId
.
- getEpochLength
function getEpochLength() external view returns (uint epochLength);
Returns the length of an epoch.
-
uint epochLength: Length of an epoch in a uint timestamp
-
getRecurringPaymentInformation
function getRecurringPaymentInformation(uint id)
external
view
returns (RecurringPayment memory);
Returns the RecurringPayment instance with id id
.
- uint id: The id of the RecurringPayment to return.
-
RecurringPayment: RecurringPayment with id
id
. -
listRecurringPaymentIds
function listRecurringPaymentIds() external view returns (uint[] memory);
Returns total list of RecurringPayment
ids. The list is in ascending order.
-
uint[]: List of RecurringPayment ids.
-
getPreviousPaymentId
function getPreviousPaymentId(uint id)
external
view
returns (uint prevId);
Returns the id of previous RecurringPayment.
- uint id: The id of the RecurringPayment to return.
-
uint prevId: The id of previous RecurringPayment.
-
isExistingRecurringPaymentId
function isExistingRecurringPaymentId(uint id)
external
view
returns (bool);
Returns whether RecurringPayment with id id
exists.
- uint id: ID of the recurring payment.
-
bool: True if RecurringPayment with id
id
exists, false otherwise. -
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.
- uint timestamp: a timestamp in a uint format
-
uint epoch: epoch in which timestamp belongs to
-
getCurrentEpoch
function getCurrentEpoch() external view returns (uint epoch);
Calculates the current epoch and the calculation is: block.timestamp divided by epochLength.
-
uint epoch : epoch in which current timestamp (block.timestamp) belongs to
-
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
- uint xEpochsInTheFuture : how many epochs from the current epoch
- uint futureEpoch : epoch in the future
- 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.
- uint amount: amount of tokens send to the recipient address
- uint startEpoch: epoch in which the payment starts. Use getEpochFromTimestamp() or getCurrentEpoch() to get the appropriate epoch
- address recipient: recipient address that should receive tokens
-
uint: id of the newly created recurring payment
-
removeRecurringPayment
function removeRecurringPayment(uint prevId, uint id) external;
Removes a recurring Payment.
-
uint prevId: id of the previous recurring payment in the payment list
-
uint id: id of the recurring payment that is to be removed
-
trigger
function trigger() external;
Triggers the start of the due payments for all recurring payment orders.
- 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
- uint startId: id of start position of the recurring payments that should be triggered
- uint endId: id of end position of the recurring payments that should be triggered