@@ -286,7 +286,7 @@ library IndexingAgreement {
286
286
*
287
287
* Emits {IndexingAgreementUpdated} event
288
288
*
289
- * @param self The indexing agreement manager storage
289
+ * @param self The indexing agreement storage manager
290
290
* @param indexer The indexer address
291
291
* @param signedRCAU The signed Recurring Collection Agreement Update
292
292
*/
@@ -324,13 +324,15 @@ library IndexingAgreement {
324
324
/**
325
325
* @notice Cancel an indexing agreement.
326
326
*
327
+ * @dev This function allows the indexer to cancel an indexing agreement.
328
+ *
327
329
* Requirements:
328
330
* - Agreement must be active
329
331
* - The indexer must be the service provider of the agreement
330
332
*
331
333
* Emits {IndexingAgreementCanceled} event
332
334
*
333
- * @param self The indexing agreement manager storage
335
+ * @param self The indexing agreement storage manager
334
336
* @param indexer The indexer address
335
337
* @param agreementId The id of the agreement to cancel
336
338
*/
@@ -350,11 +352,23 @@ library IndexingAgreement {
350
352
);
351
353
}
352
354
353
- function cancelForAllocation (
354
- StorageManager storage self ,
355
- address _allocationId ,
356
- IRecurringCollector.CancelAgreementBy by
357
- ) external {
355
+ /**
356
+ * @notice Cancel an allocation's indexing agreement if it exists.
357
+ *
358
+ * @dev This function is to be called by the data service when an allocation is closed.
359
+ *
360
+ * Requirements:
361
+ * - The allocation must have an active agreement
362
+ * - Agreement must be active
363
+ *
364
+ * Emits {IndexingAgreementCanceled} event
365
+ *
366
+ * @param self The indexing agreement storage manager
367
+ * @param _allocationId The allocation ID
368
+ * @param stale Whether the allocation is stale or not
369
+ *
370
+ */
371
+ function onCloseAllocation (StorageManager storage self , address _allocationId , bool stale ) external {
358
372
bytes16 agreementId = self.allocationToActiveAgreementId[_allocationId];
359
373
if (agreementId == bytes16 (0 )) {
360
374
return ;
@@ -365,9 +379,31 @@ library IndexingAgreement {
365
379
return ;
366
380
}
367
381
368
- _cancel (self, agreementId, wrapper.agreement, wrapper.collectorAgreement, by);
382
+ _cancel (
383
+ self,
384
+ agreementId,
385
+ wrapper.agreement,
386
+ wrapper.collectorAgreement,
387
+ stale
388
+ ? IRecurringCollector.CancelAgreementBy.ThirdParty
389
+ : IRecurringCollector.CancelAgreementBy.ServiceProvider
390
+ );
369
391
}
370
392
393
+ /**
394
+ * @notice Cancel an indexing agreement by the payer.
395
+ *
396
+ * @dev This function allows the payer to cancel an indexing agreement.
397
+ *
398
+ * Requirements:
399
+ * - Agreement must be active
400
+ * - The caller must be authorized to cancel the agreement in the collector on the payer's behalf
401
+ *
402
+ * Emits {IndexingAgreementCanceled} event
403
+ *
404
+ * @param self The indexing agreement storage manager
405
+ * @param agreementId The id of the agreement to cancel
406
+ */
371
407
function cancelByPayer (StorageManager storage self , bytes16 agreementId ) external {
372
408
AgreementWrapper memory wrapper = _get (self, agreementId);
373
409
require (_isActive (wrapper), IndexingAgreementNotActive (agreementId));
@@ -455,6 +491,19 @@ library IndexingAgreement {
455
491
_manager.termsV1[_agreementId].tokensPerEntityPerSecond = newTerms.tokensPerEntityPerSecond;
456
492
}
457
493
494
+ /**
495
+ * @notice Cancel an indexing agreement.
496
+ *
497
+ * @dev This function does the actual agreement cancelation.
498
+ *
499
+ * Emits {IndexingAgreementCanceled} event
500
+ *
501
+ * @param _manager The indexing agreement storage manager
502
+ * @param _agreementId The id of the agreement to cancel
503
+ * @param _agreement The indexing agreement state
504
+ * @param _collectorAgreement The collector agreement data
505
+ * @param _cancelBy The entity that is canceling the agreement
506
+ */
458
507
function _cancel (
459
508
StorageManager storage _manager ,
460
509
bytes16 _agreementId ,
0 commit comments