Skip to content

Commit 8d8695d

Browse files
f - add events
1 parent 8776a18 commit 8d8695d

File tree

5 files changed

+122
-2
lines changed

5 files changed

+122
-2
lines changed

IndexingPaymentsTodo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Economics
55
* If service wants to collect more than collector allows. Collector limits but doesn't tell the service?
66
* Since an allocation is required for collecting, do we want to expect that the allocation is not stale? Do we want to add code to collect rewards as part of the collection of fees? Make sure allocation is more than one epoch old if we attempt this.
7-
* What happens if the escrow doesn't have enough funds? Since you can't collect that means you lose out forever?
7+
* What should happen if the escrow doesn't have enough funds?
88
* Don't pay for entities on initial collection? Where did we land in terms of payment terms?
99
* Should we set a different param for initial collection time max? Some subgraphs take a lot to catch up.
1010
* How do we solve for the case where an indexer has reached their max expected payout for the initial sync but haven't reached the current epoch (thus their POI is incorrect)?
@@ -14,7 +14,6 @@
1414
* If an indexer closes an allocation, what should happen to the accepeted agreement?
1515
* test_SubgraphService_CollectIndexingFee_Integration fails with PaymentsEscrowInconsistentCollection
1616
* Reduce the number of errors declared and returned
17-
* Missing events for accept, cancel, upgrade RCAs.
1817
* Switch `duration` for `endsAt`?
1918

2019
# Done
@@ -28,3 +27,4 @@
2827
* DONE: ~~Maybe IRecurringCollector.cancel(address payer, address serviceProvider, bytes16 agreementId) should only take in agreementId?~~
2928
* DONE: ~~Unify to one error in Decoder.sol~~
3029
* DONE: ~~Built-in upgrade path to indexing agreements v2~~
30+
* DONE: ~~Missing events for accept, cancel, upgrade RCAs.~~

packages/horizon/contracts/interfaces/IRecurringCollector.sol

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,58 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
115115
uint256 dataServiceCut;
116116
}
117117

118+
/**
119+
* @notice Emitted when an agreement is accepted
120+
* @param dataService The address of the data service
121+
* @param payer The address of the payer
122+
* @param serviceProvider The address of the service provider
123+
*/
124+
event AgreementAccepted(
125+
address indexed dataService,
126+
address indexed payer,
127+
address indexed serviceProvider,
128+
bytes16 agreementId,
129+
uint256 acceptedAt,
130+
uint256 duration,
131+
uint256 maxInitialTokens,
132+
uint256 maxOngoingTokensPerSecond,
133+
uint32 minSecondsPerCollection,
134+
uint32 maxSecondsPerCollection
135+
);
136+
137+
/**
138+
* @notice Emitted when an agreement is canceled
139+
* @param dataService The address of the data service
140+
* @param payer The address of the payer
141+
* @param serviceProvider The address of the service provider
142+
*/
143+
event AgreementCanceled(
144+
address indexed dataService,
145+
address indexed payer,
146+
address indexed serviceProvider,
147+
bytes16 agreementId,
148+
uint256 canceledAt
149+
);
150+
151+
/**
152+
* @notice Emitted when an agreement is upgraded
153+
* @param dataService The address of the data service
154+
* @param payer The address of the payer
155+
* @param serviceProvider The address of the service provider
156+
*/
157+
event AgreementUpgraded(
158+
address indexed dataService,
159+
address indexed payer,
160+
address indexed serviceProvider,
161+
bytes16 agreementId,
162+
uint256 upgradedAt,
163+
uint256 duration,
164+
uint256 maxInitialTokens,
165+
uint256 maxOngoingTokensPerSecond,
166+
uint32 minSecondsPerCollection,
167+
uint32 maxSecondsPerCollection
168+
);
169+
118170
/**
119171
* @notice Emitted when an RCA is collected
120172
* @param dataService The address of the data service

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
102102
agreement.minSecondsPerCollection = signedRCA.rca.minSecondsPerCollection;
103103
agreement.maxSecondsPerCollection = signedRCA.rca.maxSecondsPerCollection;
104104
_requireValidAgreement(agreement, signedRCA.rca.agreementId);
105+
106+
emit AgreementAccepted(
107+
agreement.dataService,
108+
agreement.payer,
109+
agreement.serviceProvider,
110+
signedRCA.rca.agreementId,
111+
agreement.acceptedAt,
112+
agreement.duration,
113+
agreement.maxInitialTokens,
114+
agreement.maxOngoingTokensPerSecond,
115+
agreement.minSecondsPerCollection,
116+
agreement.maxSecondsPerCollection
117+
);
105118
}
106119

107120
/**
@@ -117,6 +130,14 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
117130
RecurringCollectorDataServiceNotAuthorized(agreementId, msg.sender)
118131
);
119132
agreement.acceptedAt = CANCELED;
133+
134+
emit AgreementCanceled(
135+
agreement.dataService,
136+
agreement.payer,
137+
agreement.serviceProvider,
138+
agreementId,
139+
block.timestamp
140+
);
120141
}
121142

122143
/**
@@ -147,6 +168,19 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
147168
agreement.minSecondsPerCollection = signedRCAU.rcau.minSecondsPerCollection;
148169
agreement.maxSecondsPerCollection = signedRCAU.rcau.maxSecondsPerCollection;
149170
_requireValidAgreement(agreement, signedRCAU.rcau.agreementId);
171+
172+
emit AgreementUpgraded(
173+
agreement.dataService,
174+
agreement.payer,
175+
agreement.serviceProvider,
176+
signedRCAU.rcau.agreementId,
177+
block.timestamp,
178+
agreement.duration,
179+
agreement.maxInitialTokens,
180+
agreement.maxOngoingTokensPerSecond,
181+
agreement.minSecondsPerCollection,
182+
agreement.maxSecondsPerCollection
183+
);
150184
}
151185

152186
/**

packages/horizon/test/payments/recurring-collector/shared.t.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,34 @@ contract RecurringCollectorSharedTest is Test, Bounder {
6363
_recurringCollectorHelper.authorizeSignerWithChecks(_rca.payer, _signerKey);
6464
IRecurringCollector.SignedRCA memory signedRCA = _recurringCollectorHelper.generateSignedRCA(_rca, _signerKey);
6565

66+
vm.expectEmit(address(_recurringCollector));
67+
emit IRecurringCollector.AgreementAccepted(
68+
_rca.dataService,
69+
_rca.payer,
70+
_rca.serviceProvider,
71+
_rca.agreementId,
72+
block.timestamp,
73+
_rca.duration,
74+
_rca.maxInitialTokens,
75+
_rca.maxOngoingTokensPerSecond,
76+
_rca.minSecondsPerCollection,
77+
_rca.maxSecondsPerCollection
78+
);
6679
vm.prank(_rca.dataService);
6780
_recurringCollector.accept(signedRCA);
6881

6982
return signedRCA;
7083
}
7184

7285
function _cancel(IRecurringCollector.RecurringCollectionAgreement memory _rca) internal {
86+
vm.expectEmit(address(_recurringCollector));
87+
emit IRecurringCollector.AgreementCanceled(
88+
_rca.dataService,
89+
_rca.payer,
90+
_rca.serviceProvider,
91+
_rca.agreementId,
92+
block.timestamp
93+
);
7394
vm.prank(_rca.dataService);
7495
_recurringCollector.cancel(_rca.agreementId);
7596
}

packages/horizon/test/payments/recurring-collector/upgrade.t.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ contract RecurringCollectorUpgradeTest is RecurringCollectorSharedTest {
127127
signerKey
128128
);
129129

130+
vm.expectEmit(address(_recurringCollector));
131+
emit IRecurringCollector.AgreementUpgraded(
132+
rca.dataService,
133+
rca.payer,
134+
rca.serviceProvider,
135+
rcau.agreementId,
136+
block.timestamp,
137+
rcau.duration,
138+
rcau.maxInitialTokens,
139+
rcau.maxOngoingTokensPerSecond,
140+
rcau.minSecondsPerCollection,
141+
rcau.maxSecondsPerCollection
142+
);
130143
vm.prank(rca.dataService);
131144
_recurringCollector.upgrade(signedRCAU);
132145

0 commit comments

Comments
 (0)