Skip to content

Commit

Permalink
fix: when extending make sure user does not pay for time in the past
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
  • Loading branch information
tmigone committed Sep 12, 2023
1 parent 27776ab commit 199d51d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contracts/contracts/Subscriptions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ contract Subscriptions is Ownable {
/// @notice Extends a subscription's end time.
/// The time the subscription will be extended by is calculated as `amount / rate`, where
/// `rate` is the existing subscription rate and `amount` is the new amount of tokens provided.
/// The new end time must be in the future.
/// If the subscription was expired the extension will start from the current block timestamp.
/// @dev The function's name, `addTo`, is used to comply with the `IPayment` interface for recurring payments.
/// @param user Subscription owner.
/// @param amount Total amount to be added to the subscription.
Expand All @@ -280,7 +280,7 @@ contract Subscriptions is Ownable {
require(sub.start != 0, 'no subscription found');
require(sub.rate != 0, 'cannot extend a zero rate subscription');

uint64 oldEnd = sub.end;
uint64 oldEnd = uint64(Math.max(sub.end, block.timestamp));
uint64 newEnd = oldEnd + uint64(amount / sub.rate);
require(block.timestamp < newEnd, 'new end cannot be in the past');

Expand Down

0 comments on commit 199d51d

Please sign in to comment.