Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: switch timekeeping from monthly with external lib to time based (0xM L-04) #52

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions contracts/RecurringPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { GelatoManager } from "./GelatoManager.sol";
import { Rescuable } from "./Rescuable.sol";
import { BokkyPooBahsDateTimeLibrary } from "./libs/BokkyPooBahsDateTimeLibrary.sol";

/**
* @title RecurringPayments contract
Expand All @@ -23,10 +22,10 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {

// -- State --

/// @dev Minimum amount of time in months between recurring payment executions
/// @dev Minimum amount of time in seconds between recurring payment executions
uint128 public executionInterval;

/// @dev Minimum amount of time before a recurring payment can be cancelled due to failed execution
/// @dev Minimum amount of time in seconds before a recurring payment can be cancelled due to failed execution
uint128 public expirationInterval;

/// @dev List of recurring payments by user
Expand Down Expand Up @@ -381,7 +380,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {

/**
* @notice Sets the minimum execution interval for recurring payments.
* @param _executionInterval The new execution interval in months. Must be greater than zero.
* @param _executionInterval The new execution interval in seconds. Must be greater than zero.
*/
function setExecutionInterval(uint128 _executionInterval) external onlyGovernor {
_setExecutionInterval(_executionInterval);
Expand All @@ -391,7 +390,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {
* @notice Sets the minimum expiration interval for recurring payments.
* This is the amount of time that has to pass without successful payment execution before the recurring payment
* is automatically cancelled.
* @param _expirationInterval The new expiration interval in months. Must be greater than the `executionInterval`.
* @param _expirationInterval The new expiration interval in seconds. Must be greater than the `executionInterval`.
*/
function setExpirationInterval(uint128 _expirationInterval) external onlyGovernor {
_setExpirationInterval(_expirationInterval);
Expand Down Expand Up @@ -444,8 +443,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {
*/
function getNextExecutionTime(address user) external view returns (uint256) {
RecurringPayment storage recurringPayment = _getRecurringPaymentOrRevert(user);
return
BokkyPooBahsDateTimeLibrary.addMonths(recurringPayment.lastExecutedAt, recurringPayment.executionInterval);
return recurringPayment.lastExecutedAt + recurringPayment.executionInterval;
}

/**
Expand All @@ -457,7 +455,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {
*/
function getExpirationTime(address user) external view returns (uint256) {
RecurringPayment storage recurringPayment = _getRecurringPaymentOrRevert(user);
return BokkyPooBahsDateTimeLibrary.addMonths(recurringPayment.lastExecutedAt, expirationInterval);
return recurringPayment.lastExecutedAt + expirationInterval;
}

/**
Expand Down Expand Up @@ -487,7 +485,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {

/**
* @notice Sets the minimum execution interval for recurring payments.
* @param _executionInterval The new execution interval in months. Must be greater than zero.
* @param _executionInterval The new execution interval in seconds. Must be greater than zero.
*/
function _setExecutionInterval(uint128 _executionInterval) private {
if (_executionInterval == 0 || expirationInterval <= _executionInterval) revert InvalidIntervalValue();
Expand All @@ -499,7 +497,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {
* @notice Sets the minimum expiration interval for recurring payments.
* This is the amount of time that has to pass without successful payment execution before the recurring payment
* is automatically cancelled.
* @param _expirationInterval The new expiration interval in months. Must be greater than the `executionInterval`.
* @param _expirationInterval The new expiration interval in seconds. Must be greater than the `executionInterval`.
*/
function _setExpirationInterval(uint128 _expirationInterval) private {
if (_expirationInterval == 0 || _expirationInterval <= executionInterval) revert InvalidIntervalValue();
Expand All @@ -514,7 +512,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {
* @return True if the recurring payment can be executed
*/
function _canExecute(uint256 lastExecutedAt, uint256 rpExecutionInterval) private view returns (bool) {
return block.timestamp >= BokkyPooBahsDateTimeLibrary.addMonths(lastExecutedAt, rpExecutionInterval);
return block.timestamp >= (lastExecutedAt + rpExecutionInterval);
}

/**
Expand All @@ -524,7 +522,7 @@ contract RecurringPayments is IRecurringPayments, GelatoManager, Rescuable {
* @return True if the recurring payment can be cancelled
*/
function _canCancel(uint256 lastExecutedAt, uint256 rpExpirationInterval) private view returns (bool) {
return block.timestamp >= BokkyPooBahsDateTimeLibrary.addMonths(lastExecutedAt, rpExpirationInterval);
return block.timestamp >= (lastExecutedAt + rpExpirationInterval);
}

/**
Expand Down
Loading
Loading