Skip to content

Commit c9b38da

Browse files
f: add MIN_SECONDS_COLLECTION_WINDOW
1 parent 4fa4ca4 commit c9b38da

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { MathUtils } from "../../libraries/MathUtils.sol";
2121
contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringCollector {
2222
using PPMMath for uint256;
2323

24+
uint32 public constant MIN_SECONDS_COLLECTION_WINDOW = 600;
25+
2426
/// @notice The EIP712 typehash for the RecurringCollectionAgreement struct
2527
bytes32 public constant EIP712_RCA_TYPEHASH =
2628
keccak256(
@@ -318,16 +320,17 @@ contract RecurringCollector is EIP712, GraphDirectory, Authorizable, IRecurringC
318320
RecurringCollectorAgreementInvalidParameters("endsAt not in future")
319321
);
320322

321-
// Collection window needs to be at least 2 hours
323+
// Collection window needs to be at least MIN_SECONDS_COLLECTION_WINDOW
322324
require(
323325
_agreement.maxSecondsPerCollection > _agreement.minSecondsPerCollection &&
324-
(_agreement.maxSecondsPerCollection - _agreement.minSecondsPerCollection >= 7200),
326+
(_agreement.maxSecondsPerCollection - _agreement.minSecondsPerCollection >=
327+
MIN_SECONDS_COLLECTION_WINDOW),
325328
RecurringCollectorAgreementInvalidParameters("too small collection window")
326329
);
327330

328331
// Agreement needs to last at least one min collection window
329332
require(
330-
_agreement.endsAt - block.timestamp >= _agreement.minSecondsPerCollection + 7200,
333+
_agreement.endsAt - block.timestamp >= _agreement.minSecondsPerCollection + MIN_SECONDS_COLLECTION_WINDOW,
331334
RecurringCollectorAgreementInvalidParameters("too small agreement window")
332335
);
333336
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ contract RecurringCollectorHelper is AuthorizableHelper, Bounder {
103103
}
104104

105105
function _sensibleDeadline(uint256 _seed) internal view returns (uint64) {
106-
return uint64(bound(_seed, block.timestamp + 1, block.timestamp + 7200)); // between now and 2h
106+
return
107+
uint64(
108+
bound(_seed, block.timestamp + 1, block.timestamp + uint256(collector.MIN_SECONDS_COLLECTION_WINDOW()))
109+
); // between now and +MIN_SECONDS_COLLECTION_WINDOW
107110
}
108111

109112
function _sensibleEndsAt(uint256 _seed, uint32 _maxSecondsPerCollection) internal view returns (uint64) {
@@ -132,10 +135,14 @@ contract RecurringCollectorHelper is AuthorizableHelper, Bounder {
132135
function _sensibleMaxSecondsPerCollection(
133136
uint32 _seed,
134137
uint32 _minSecondsPerCollection
135-
) internal pure returns (uint32) {
138+
) internal view returns (uint32) {
136139
return
137140
uint32(
138-
bound(_seed, _minSecondsPerCollection + 7200, 60 * 60 * 24 * 30) // between minSecondsPerCollection + 2h and 30 days
141+
bound(
142+
_seed,
143+
_minSecondsPerCollection + uint256(collector.MIN_SECONDS_COLLECTION_WINDOW()),
144+
60 * 60 * 24 * 30
145+
) // between minSecondsPerCollection + 2h and 30 days
139146
);
140147
}
141148
}

0 commit comments

Comments
 (0)