@@ -365,13 +365,16 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
365
365
bytes16 _agreementId ,
366
366
uint256 _tokens
367
367
) 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;
369
370
uint256 canceledOrNow = _agreement.state == AgreementState.CanceledByPayer
370
371
? _agreement.canceledAt
371
372
: block .timestamp ;
372
373
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 ;
375
378
uint256 collectionStart = _agreementCollectionStartAt (_agreement);
376
379
require (
377
380
collectionEnd != collectionStart,
@@ -380,14 +383,18 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
380
383
require (collectionEnd > collectionStart, RecurringCollectorFinalCollectionDone (_agreementId, collectionStart));
381
384
382
385
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
+ }
391
398
require (
392
399
collectionSeconds <= _agreement.maxSecondsPerCollection,
393
400
RecurringCollectorCollectionTooLate (
0 commit comments