@@ -286,7 +286,7 @@ library IndexingAgreement {
286286 *
287287 * Emits {IndexingAgreementUpdated} event
288288 *
289- * @param self The indexing agreement manager storage
289+ * @param self The indexing agreement storage manager
290290 * @param indexer The indexer address
291291 * @param signedRCAU The signed Recurring Collection Agreement Update
292292 */
@@ -324,13 +324,15 @@ library IndexingAgreement {
324324 /**
325325 * @notice Cancel an indexing agreement.
326326 *
327+ * @dev This function allows the indexer to cancel an indexing agreement.
328+ *
327329 * Requirements:
328330 * - Agreement must be active
329331 * - The indexer must be the service provider of the agreement
330332 *
331333 * Emits {IndexingAgreementCanceled} event
332334 *
333- * @param self The indexing agreement manager storage
335+ * @param self The indexing agreement storage manager
334336 * @param indexer The indexer address
335337 * @param agreementId The id of the agreement to cancel
336338 */
@@ -350,11 +352,23 @@ library IndexingAgreement {
350352 );
351353 }
352354
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 {
358372 bytes16 agreementId = self.allocationToActiveAgreementId[_allocationId];
359373 if (agreementId == bytes16 (0 )) {
360374 return ;
@@ -365,9 +379,31 @@ library IndexingAgreement {
365379 return ;
366380 }
367381
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+ );
369391 }
370392
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+ */
371407 function cancelByPayer (StorageManager storage self , bytes16 agreementId ) external {
372408 AgreementWrapper memory wrapper = _get (self, agreementId);
373409 require (_isActive (wrapper), IndexingAgreementNotActive (agreementId));
@@ -455,6 +491,19 @@ library IndexingAgreement {
455491 _manager.termsV1[_agreementId].tokensPerEntityPerSecond = newTerms.tokensPerEntityPerSecond;
456492 }
457493
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+ */
458507 function _cancel (
459508 StorageManager storage _manager ,
460509 bytes16 _agreementId ,
0 commit comments