Skip to content

Commit 32fec56

Browse files
f: allow short final collection
1 parent f5cbb1c commit 32fec56

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

packages/horizon/contracts/payments/collectors/RecurringCollector.sol

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,16 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
365365
bytes16 _agreementId,
366366
uint256 _tokens
367367
) private view returns (uint256) {
368-
// if canceled by the payer allow collection up to the cancelation time
368+
bool canceledOrElapsed = _agreement.state == AgreementState.CanceledByPayer ||
369+
block.timestamp > _agreement.endsAt;
369370
uint256 canceledOrNow = _agreement.state == AgreementState.CanceledByPayer
370371
? _agreement.canceledAt
371372
: block.timestamp;
372373

373-
// allow collection till endsAt (at most)
374-
uint256 collectionEnd = Math.min(canceledOrNow, _agreement.endsAt);
374+
// if canceled by the payer allow collection till canceledAt
375+
// if elapsed allow collection till endsAt
376+
// if both are true, use the earlier one
377+
uint256 collectionEnd = canceledOrElapsed ? Math.min(canceledOrNow, _agreement.endsAt) : block.timestamp;
375378
uint256 collectionStart = _agreementCollectionStartAt(_agreement);
376379
require(
377380
collectionEnd != collectionStart,
@@ -380,14 +383,18 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
380383
require(collectionEnd > collectionStart, RecurringCollectorFinalCollectionDone(_agreementId, collectionStart));
381384

382385
uint256 collectionSeconds = collectionEnd - collectionStart;
383-
require(
384-
collectionSeconds >= _agreement.minSecondsPerCollection,
385-
RecurringCollectorCollectionTooSoon(
386-
_agreementId,
387-
uint32(collectionSeconds),
388-
_agreement.minSecondsPerCollection
389-
)
390-
);
386+
// Check that the collection window is long enough
387+
// If the agreement is canceled or elapsed, allow a shorter collection window
388+
if (!canceledOrElapsed) {
389+
require(
390+
collectionSeconds >= _agreement.minSecondsPerCollection,
391+
RecurringCollectorCollectionTooSoon(
392+
_agreementId,
393+
uint32(collectionSeconds),
394+
_agreement.minSecondsPerCollection
395+
)
396+
);
397+
}
391398
require(
392399
collectionSeconds <= _agreement.maxSecondsPerCollection,
393400
RecurringCollectorCollectionTooLate(

0 commit comments

Comments
 (0)