Skip to content

Commit 422cd19

Browse files
fix: Remove PaymentType constraint from RecurringCollector
1 parent 7fd8eed commit 422cd19

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,8 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
6262
* @dev Caller must be the data service the RCA was issued to.
6363
*/
6464
function collect(IGraphPayments.PaymentTypes paymentType, bytes calldata data) external returns (uint256) {
65-
require(
66-
paymentType == IGraphPayments.PaymentTypes.IndexingFee,
67-
RecurringCollectorInvalidPaymentType(paymentType)
68-
);
6965
try this.decodeCollectData(data) returns (CollectParams memory collectParams) {
70-
return _collect(collectParams);
66+
return _collect(paymentType, collectParams);
7167
} catch {
7268
revert RecurringCollectorInvalidCollectData(data);
7369
}
@@ -269,10 +265,14 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
269265
*
270266
* Emits {PaymentCollected} and {RCACollected} events.
271267
*
268+
* @param _paymentType The type of payment to collect
272269
* @param _params The decoded parameters for the collection
273270
* @return The amount of tokens collected
274271
*/
275-
function _collect(CollectParams memory _params) private returns (uint256) {
272+
function _collect(
273+
IGraphPayments.PaymentTypes _paymentType,
274+
CollectParams memory _params
275+
) private returns (uint256) {
276276
AgreementData storage agreement = _getAgreementStorage(_params.agreementId);
277277
require(
278278
_isCollectable(agreement),
@@ -289,7 +289,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
289289
tokensToCollect = _requireValidCollect(agreement, _params.agreementId, _params.tokens);
290290

291291
_graphPaymentsEscrow().collect(
292-
IGraphPayments.PaymentTypes.IndexingFee,
292+
_paymentType,
293293
agreement.payer,
294294
agreement.serviceProvider,
295295
tokensToCollect,
@@ -301,7 +301,7 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
301301
agreement.lastCollectionAt = uint64(block.timestamp);
302302

303303
emit PaymentCollected(
304-
IGraphPayments.PaymentTypes.IndexingFee,
304+
_paymentType,
305305
_params.collectionId,
306306
agreement.payer,
307307
agreement.serviceProvider,

packages/horizon/test/unit/payments/recurring-collector/collect.t.sol

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.27;
33

4-
import { IGraphPayments } from "../../../../contracts/interfaces/IGraphPayments.sol";
5-
64
import { IRecurringCollector } from "../../../../contracts/interfaces/IRecurringCollector.sol";
75

86
import { RecurringCollectorSharedTest } from "./shared.t.sol";
@@ -14,32 +12,14 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
1412

1513
/* solhint-disable graph/func-name-mixedcase */
1614

17-
function test_Collect_Revert_WhenInvalidPaymentType(uint8 unboundedPaymentType, bytes memory data) public {
18-
IGraphPayments.PaymentTypes paymentType = IGraphPayments.PaymentTypes(
19-
bound(
20-
unboundedPaymentType,
21-
uint256(type(IGraphPayments.PaymentTypes).min),
22-
uint256(type(IGraphPayments.PaymentTypes).max)
23-
)
24-
);
25-
vm.assume(paymentType != IGraphPayments.PaymentTypes.IndexingFee);
26-
27-
bytes memory expectedErr = abi.encodeWithSelector(
28-
IRecurringCollector.RecurringCollectorInvalidPaymentType.selector,
29-
paymentType
30-
);
31-
vm.expectRevert(expectedErr);
32-
_recurringCollector.collect(paymentType, data);
33-
}
34-
35-
function test_Collect_Revert_WhenInvalidData(address caller, bytes memory data) public {
15+
function test_Collect_Revert_WhenInvalidData(address caller, uint8 unboundedPaymentType, bytes memory data) public {
3616
bytes memory expectedErr = abi.encodeWithSelector(
3717
IRecurringCollector.RecurringCollectorInvalidCollectData.selector,
3818
data
3919
);
4020
vm.expectRevert(expectedErr);
4121
vm.prank(caller);
42-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
22+
_recurringCollector.collect(_paymentType(unboundedPaymentType), data);
4323
}
4424

4525
function test_Collect_Revert_WhenCallerNotDataService(
@@ -61,7 +41,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
6141
);
6242
vm.expectRevert(expectedErr);
6343
vm.prank(notDataService);
64-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
44+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
6545
}
6646

6747
function test_Collect_Revert_WhenUnknownAgreement(FuzzyTestCollect memory fuzzy, address dataService) public {
@@ -74,7 +54,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
7454
);
7555
vm.expectRevert(expectedErr);
7656
vm.prank(dataService);
77-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
57+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
7858
}
7959

8060
function test_Collect_Revert_WhenCanceledAgreementByServiceProvider(FuzzyTestCollect calldata fuzzy) public {
@@ -97,7 +77,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
9777
);
9878
vm.expectRevert(expectedErr);
9979
vm.prank(accepted.rca.dataService);
100-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
80+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
10181
}
10282

10383
function test_Collect_Revert_WhenCollectingTooSoon(
@@ -116,7 +96,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
11696
)
11797
);
11898
vm.prank(accepted.rca.dataService);
119-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
99+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
120100

121101
uint256 collectionSeconds = boundSkip(unboundedCollectionSeconds, 1, accepted.rca.minSecondsPerCollection - 1);
122102
skip(collectionSeconds);
@@ -136,7 +116,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
136116
);
137117
vm.expectRevert(expectedErr);
138118
vm.prank(accepted.rca.dataService);
139-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
119+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
140120
}
141121

142122
function test_Collect_Revert_WhenCollectingTooLate(
@@ -163,7 +143,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
163143
)
164144
);
165145
vm.prank(accepted.rca.dataService);
166-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
146+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
167147

168148
// skip beyond collectable time but still within the agreement endsAt
169149
uint256 collectionSeconds = boundSkip(
@@ -189,7 +169,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
189169
);
190170
vm.expectRevert(expectedErr);
191171
vm.prank(accepted.rca.dataService);
192-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
172+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
193173
}
194174

195175
function test_Collect_OK_WhenCollectingTooMuch(
@@ -219,7 +199,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
219199
)
220200
);
221201
vm.prank(accepted.rca.dataService);
222-
_recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, initialData);
202+
_recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), initialData);
223203
}
224204

225205
// skip to collectable time
@@ -240,7 +220,7 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
240220
);
241221
bytes memory data = _generateCollectData(collectParams);
242222
vm.prank(accepted.rca.dataService);
243-
uint256 collected = _recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
223+
uint256 collected = _recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
244224
assertEq(collected, maxTokens);
245225
}
246226

@@ -258,9 +238,9 @@ contract RecurringCollectorCollectTest is RecurringCollectorSharedTest {
258238
unboundedTokens
259239
);
260240
skip(collectionSeconds);
261-
_expectCollectCallAndEmit(accepted.rca, fuzzy.collectParams, tokens);
241+
_expectCollectCallAndEmit(accepted.rca, _paymentType(fuzzy.unboundedPaymentType), fuzzy.collectParams, tokens);
262242
vm.prank(accepted.rca.dataService);
263-
uint256 collected = _recurringCollector.collect(IGraphPayments.PaymentTypes.IndexingFee, data);
243+
uint256 collected = _recurringCollector.collect(_paymentType(fuzzy.unboundedPaymentType), data);
264244
assertEq(collected, tokens);
265245
}
266246
/* solhint-enable graph/func-name-mixedcase */

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { RecurringCollectorHelper } from "./RecurringCollectorHelper.t.sol";
1616
contract RecurringCollectorSharedTest is Test, Bounder {
1717
struct FuzzyTestCollect {
1818
FuzzyTestAccept fuzzyTestAccept;
19+
uint8 unboundedPaymentType;
1920
IRecurringCollector.CollectParams collectParams;
2021
}
2122

@@ -106,6 +107,7 @@ contract RecurringCollectorSharedTest is Test, Bounder {
106107

107108
function _expectCollectCallAndEmit(
108109
IRecurringCollector.RecurringCollectionAgreement memory _rca,
110+
IGraphPayments.PaymentTypes __paymentType,
109111
IRecurringCollector.CollectParams memory _fuzzyParams,
110112
uint256 _tokens
111113
) internal {
@@ -114,7 +116,7 @@ contract RecurringCollectorSharedTest is Test, Bounder {
114116
abi.encodeCall(
115117
_paymentsEscrow.collect,
116118
(
117-
IGraphPayments.PaymentTypes.IndexingFee,
119+
__paymentType,
118120
_rca.payer,
119121
_rca.serviceProvider,
120122
_tokens,
@@ -126,7 +128,7 @@ contract RecurringCollectorSharedTest is Test, Bounder {
126128
);
127129
vm.expectEmit(address(_recurringCollector));
128130
emit IPaymentsCollector.PaymentCollected(
129-
IGraphPayments.PaymentTypes.IndexingFee,
131+
__paymentType,
130132
_fuzzyParams.collectionId,
131133
_rca.payer,
132134
_rca.serviceProvider,
@@ -193,4 +195,15 @@ contract RecurringCollectorSharedTest is Test, Bounder {
193195
bound(_seed, 0, uint256(IRecurringCollector.CancelAgreementBy.Payer))
194196
);
195197
}
198+
199+
function _paymentType(uint8 _unboundedPaymentType) internal pure returns (IGraphPayments.PaymentTypes) {
200+
return
201+
IGraphPayments.PaymentTypes(
202+
bound(
203+
_unboundedPaymentType,
204+
uint256(type(IGraphPayments.PaymentTypes).min),
205+
uint256(type(IGraphPayments.PaymentTypes).max)
206+
)
207+
);
208+
}
196209
}

0 commit comments

Comments
 (0)