Skip to content

Commit 93f7342

Browse files
f: add natspec from smells
1 parent 56c86a7 commit 93f7342

File tree

4 files changed

+128
-83
lines changed

4 files changed

+128
-83
lines changed

packages/horizon/contracts/data-service/libraries/DataServiceFeesLib.sol

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ library DataServiceFeesLib {
1010
using ProvisionTracker for mapping(address => uint256);
1111
using LinkedList for LinkedList.List;
1212

13-
// @notice Storage structure for the provision manager
14-
struct ProvisionManagerStorage {
15-
uint256 _minimumProvisionTokens;
16-
uint256 _maximumProvisionTokens;
17-
uint64 _minimumThawingPeriod;
18-
uint64 _maximumThawingPeriod;
19-
uint32 _minimumVerifierCut;
20-
uint32 _maximumVerifierCut;
21-
uint32 _delegationRatio;
22-
}
23-
2413
/**
2514
* @notice Locks stake for a service provider to back a payment.
2615
* Creates a stake claim, which is stored in a linked list by service provider.
@@ -29,6 +18,11 @@ library DataServiceFeesLib {
2918
*
3019
* Emits a {StakeClaimLocked} event.
3120
*
21+
* @param feesProvisionTracker The mapping that tracks the provision tokens for each service provider
22+
* @param claims The mapping that stores stake claims by their ID
23+
* @param claimsLists The mapping that stores linked lists of stake claims by service provider
24+
* @param graphStaking The Horizon staking contract used to lock the tokens
25+
* @param _delegationRatio The delegation ratio to use for the stake claim
3226
* @param _serviceProvider The address of the service provider
3327
* @param _tokens The amount of tokens to lock in the claim
3428
* @param _unlockTimestamp The timestamp when the tokens can be released
@@ -65,6 +59,10 @@ library DataServiceFeesLib {
6559
/**
6660
* @notice Processes a stake claim, releasing the tokens if the claim has expired.
6761
* @dev This function is used as a callback in the stake claims linked list traversal.
62+
* @param feesProvisionTracker The mapping that tracks the provision tokens for each service provider.
63+
* @param claims The mapping that stores stake claims by their ID.
64+
* @param _claimId The ID of the stake claim to process.
65+
* @param _acc The accumulator data, which contains the total tokens claimed and the service provider address.
6866
* @return Whether the stake claim is still locked, indicating that the traversal should continue or stop.
6967
* @return The updated accumulator data
7068
*/

packages/horizon/contracts/data-service/utilities/ProvisionManager.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
205205
emit ThawingPeriodRangeSet(_min, _max);
206206
}
207207

208+
/**
209+
* @notice Checks if a provision of a service provider is valid according
210+
* to the parameter ranges established.
211+
* @param _serviceProvider The address of the service provider.
212+
*/
208213
function _requireValidProvision(address _serviceProvider) internal view {
209214
IHorizonStaking.Provision memory provision = _getProvision(_serviceProvider);
210215
_checkProvisionTokens(provision);
@@ -323,7 +328,12 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
323328
require(_value.isInRange(_min, _max), ProvisionManagerInvalidValue(_revertMessage, _value, _min, _max));
324329
}
325330

326-
function _requireLTE(uint256 _min, uint256 _max) private pure {
327-
require(_min <= _max, ProvisionManagerInvalidRange(_min, _max));
331+
/**
332+
* @notice Requires that a value is less than or equal to another value.
333+
* @param _a The value to check.
334+
* @param _b The value to compare against.
335+
*/
336+
function _requireLTE(uint256 _a, uint256 _b) private pure {
337+
require(_a <= _b, ProvisionManagerInvalidRange(_a, _b));
328338
}
329339
}

packages/horizon/contracts/interfaces/IRecurringCollector.sol

Lines changed: 83 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,88 +13,114 @@ import { IAuthorizable } from "./IAuthorizable.sol";
1313
* recurrent payments.
1414
*/
1515
interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
16-
// @notice The state of an agreement
16+
/// @notice The state of an agreement
1717
enum AgreementState {
1818
NotAccepted,
1919
Accepted,
2020
CanceledByServiceProvider,
2121
CanceledByPayer
2222
}
2323

24-
// @notice The party that can cancel an agreement
24+
/// @notice The party that can cancel an agreement
2525
enum CancelAgreementBy {
2626
ServiceProvider,
2727
Payer,
2828
ThirdParty
2929
}
3030

31-
/// @notice A representation of a signed Recurring Collection Agreement (RCA)
31+
/**
32+
* @notice A representation of a signed Recurring Collection Agreement (RCA)
33+
* @param rca The Recurring Collection Agreement to be signed
34+
* @param signature The signature of the RCA - 65 bytes: r (32 Bytes) || s (32 Bytes) || v (1 Byte)
35+
*/
3236
struct SignedRCA {
33-
// The RCA
3437
RecurringCollectionAgreement rca;
35-
// Signature - 65 bytes: r (32 Bytes) || s (32 Bytes) || v (1 Byte)
3638
bytes signature;
3739
}
3840

39-
/// @notice The Recurring Collection Agreement (RCA)
41+
/**
42+
* @notice The Recurring Collection Agreement (RCA)
43+
* @param agreementId The agreement ID of the RCA
44+
* @param deadline The deadline for accepting the RCA
45+
* @param endsAt The timestamp when the agreement ends
46+
* @param payer The address of the payer the RCA was issued by
47+
* @param dataService The address of the data service the RCA was issued to
48+
* @param serviceProvider The address of the service provider the RCA was issued to
49+
* @param maxInitialTokens The maximum amount of tokens that can be collected in the first collection
50+
* on top of the amount allowed for subsequent collections
51+
* @param maxOngoingTokensPerSecond The maximum amount of tokens that can be collected per second
52+
* except for the first collection
53+
* @param minSecondsPerCollection The minimum amount of seconds that must pass between collections
54+
* @param maxSecondsPerCollection The maximum amount of seconds that can pass between collections
55+
* @param metadata Arbitrary metadata to extend functionality if a data service requires it
56+
*
57+
*/
4058
struct RecurringCollectionAgreement {
41-
// The agreement ID of the RCA
4259
bytes16 agreementId;
43-
// The deadline for accepting the RCA
4460
uint64 deadline;
45-
// The timestamp when the agreement ends
4661
uint64 endsAt;
47-
// The address of the payer the RCA was issued by
4862
address payer;
49-
// The address of the data service the RCA was issued to
5063
address dataService;
51-
// The address of the service provider the RCA was issued to
5264
address serviceProvider;
53-
// The maximum amount of tokens that can be collected in the first collection
54-
// on top of the amount allowed for subsequent collections
5565
uint256 maxInitialTokens;
56-
// The maximum amount of tokens that can be collected per second
57-
// except for the first collection
5866
uint256 maxOngoingTokensPerSecond;
59-
// The minimum amount of seconds that must pass between collections
6067
uint32 minSecondsPerCollection;
61-
// The maximum amount of seconds that can pass between collections
6268
uint32 maxSecondsPerCollection;
63-
// Arbitrary metadata to extend functionality if a data service requires it
6469
bytes metadata;
6570
}
6671

67-
/// @notice A representation of a signed Recurring Collection Agreement Update (RCAU)
72+
/**
73+
* @notice A representation of a signed Recurring Collection Agreement Update (RCAU)
74+
* @param rcau The Recurring Collection Agreement Update to be signed
75+
* @param signature The signature of the RCAU - 65 bytes: r (32 Bytes) || s (32 Bytes) || v (1 Byte)
76+
*/
6877
struct SignedRCAU {
69-
// The RCAU
7078
RecurringCollectionAgreementUpdate rcau;
71-
// Signature - 65 bytes: r (32 Bytes) || s (32 Bytes) || v (1 Byte)
7279
bytes signature;
7380
}
7481

75-
/// @notice The Recurring Collection Agreement Update (RCAU)
82+
/**
83+
* @notice The Recurring Collection Agreement Update (RCAU)
84+
* @param agreementId The agreement ID of the RCAU
85+
* @param deadline The deadline for upgrading the RCA
86+
* @param endsAt The timestamp when the agreement ends
87+
* @param maxInitialTokens The maximum amount of tokens that can be collected in the first collection
88+
* on top of the amount allowed for subsequent collections
89+
* @param maxOngoingTokensPerSecond The maximum amount of tokens that can be collected per second
90+
* except for the first collection
91+
* @param minSecondsPerCollection The minimum amount of seconds that must pass between collections
92+
* @param maxSecondsPerCollection The maximum amount of seconds that can pass between collections
93+
* @param metadata Arbitrary metadata to extend functionality if a data service requires it
94+
*/
7695
struct RecurringCollectionAgreementUpdate {
77-
// The agreement ID
7896
bytes16 agreementId;
79-
// The deadline for upgrading
8097
uint64 deadline;
81-
// The timestamp when the agreement ends
8298
uint64 endsAt;
83-
// The maximum amount of tokens that can be collected in the first collection
84-
// on top of the amount allowed for subsequent collections
8599
uint256 maxInitialTokens;
86-
// The maximum amount of tokens that can be collected per second
87-
// except for the first collection
88100
uint256 maxOngoingTokensPerSecond;
89-
// The minimum amount of seconds that must pass between collections
90101
uint32 minSecondsPerCollection;
91-
// The maximum amount of seconds that can pass between collections
92102
uint32 maxSecondsPerCollection;
93-
// Arbitrary metadata to extend functionality if a data service requires it
94103
bytes metadata;
95104
}
96105

97-
/// @notice The data for an agreement
106+
/**
107+
* @notice The data for an agreement
108+
* @dev This struct is used to store the data of an agreement in the contract
109+
* @param dataService The address of the data service
110+
* @param payer The address of the payer
111+
* @param serviceProvider The address of the service provider
112+
* @param acceptedAt The timestamp when the agreement was accepted
113+
* @param lastCollectionAt The timestamp when the agreement was last collected at
114+
* @param endsAt The timestamp when the agreement ends
115+
* @param maxInitialTokens The maximum amount of tokens that can be collected in the first collection
116+
* on top of the amount allowed for subsequent collections
117+
* @param maxOngoingTokensPerSecond The maximum amount of tokens that can be collected per second
118+
* except for the first collection
119+
* @param minSecondsPerCollection The minimum amount of seconds that must pass between collections
120+
* @param maxSecondsPerCollection The maximum amount of seconds that can pass between collections
121+
* @param canceledAt The timestamp when the agreement was canceled
122+
* @param state The state of the agreement
123+
*/
98124
struct AgreementData {
99125
// The address of the data service
100126
address dataService;
@@ -124,14 +150,17 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
124150
AgreementState state;
125151
}
126152

127-
/// @notice The params for collecting an agreement
153+
/**
154+
* @notice The params for collecting an agreement
155+
* @param agreementId The agreement ID of the RCA
156+
* @param collectionId The collection ID of the RCA
157+
* @param tokens The amount of tokens to collect
158+
* @param dataServiceCut The data service cut in parts per million
159+
*/
128160
struct CollectParams {
129161
bytes16 agreementId;
130-
// The collection ID
131162
bytes32 collectionId;
132-
// The amount of tokens to collect
133163
uint256 tokens;
134-
// The data service cut in PPM
135164
uint256 dataServiceCut;
136165
}
137166

@@ -226,77 +255,77 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
226255
);
227256

228257
/**
229-
* Thrown when accepting an agreement with a zero ID
258+
* @notice Thrown when accepting an agreement with a zero ID
230259
*/
231260
error RecurringCollectorAgreementIdZero();
232261

233262
/**
234-
* Thrown when interacting with an agreement not owned by the message sender
263+
* @notice Thrown when interacting with an agreement not owned by the message sender
235264
* @param agreementId The agreement ID
236265
* @param unauthorizedDataService The address of the unauthorized data service
237266
*/
238267
error RecurringCollectorDataServiceNotAuthorized(bytes16 agreementId, address unauthorizedDataService);
239268

240269
/**
241-
* Thrown when interacting with an agreement with an elapsed deadline
270+
* @notice Thrown when interacting with an agreement with an elapsed deadline
242271
* @param currentTimestamp The current timestamp
243272
* @param deadline The elapsed deadline timestamp
244273
*/
245274
error RecurringCollectorAgreementDeadlineElapsed(uint256 currentTimestamp, uint64 deadline);
246275

247276
/**
248-
* Thrown when the signer is invalid
277+
* @notice Thrown when the signer is invalid
249278
*/
250279
error RecurringCollectorInvalidSigner();
251280

252281
/**
253-
* Thrown when the payment type is not IndexingFee
282+
* @notice Thrown when the payment type is not IndexingFee
254283
* @param invalidPaymentType The invalid payment type
255284
*/
256285
error RecurringCollectorInvalidPaymentType(IGraphPayments.PaymentTypes invalidPaymentType);
257286

258287
/**
259-
* Thrown when the caller is not the data service the RCA was issued to
288+
* @notice Thrown when the caller is not the data service the RCA was issued to
260289
* @param unauthorizedCaller The address of the caller
261290
* @param dataService The address of the data service
262291
*/
263292
error RecurringCollectorUnauthorizedCaller(address unauthorizedCaller, address dataService);
264293

265294
/**
266-
* Thrown when calling collect() with invalid data
295+
* @notice Thrown when calling collect() with invalid data
267296
* @param invalidData The invalid data
268297
*/
269298
error RecurringCollectorInvalidCollectData(bytes invalidData);
270299

271300
/**
272-
* Thrown when calling collect() on a payer canceled agreement
301+
* @notice Thrown when calling collect() on a payer canceled agreement
273302
* where the final collection has already been done
274303
* @param agreementId The agreement ID
275304
* @param finalCollectionAt The timestamp when the final collection was done
276305
*/
277306
error RecurringCollectorFinalCollectionDone(bytes16 agreementId, uint256 finalCollectionAt);
278307

279308
/**
280-
* Thrown when interacting with an agreement that has an incorrect state
309+
* @notice Thrown when interacting with an agreement that has an incorrect state
281310
* @param agreementId The agreement ID
282311
* @param incorrectState The incorrect state
283312
*/
284313
error RecurringCollectorAgreementIncorrectState(bytes16 agreementId, AgreementState incorrectState);
285314

286315
/**
287-
* Thrown when accepting an agreement with an address that is not set
316+
* @notice Thrown when accepting an agreement with an address that is not set
288317
*/
289318
error RecurringCollectorAgreementAddressNotSet();
290319

291320
/**
292-
* Thrown when accepting or upgrading an agreement with an elapsed endsAt
321+
* @notice Thrown when accepting or upgrading an agreement with an elapsed endsAt
293322
* @param currentTimestamp The current timestamp
294323
* @param endsAt The agreement end timestamp
295324
*/
296325
error RecurringCollectorAgreementElapsedEndsAt(uint256 currentTimestamp, uint64 endsAt);
297326

298327
/**
299-
* Thrown when accepting or upgrading an agreement with an elapsed endsAt
328+
* @notice Thrown when accepting or upgrading an agreement with an elapsed endsAt
300329
* @param allowedMinCollectionWindow The allowed minimum collection window
301330
* @param minSecondsPerCollection The minimum seconds per collection
302331
* @param maxSecondsPerCollection The maximum seconds per collection
@@ -308,29 +337,29 @@ interface IRecurringCollector is IAuthorizable, IPaymentsCollector {
308337
);
309338

310339
/**
311-
* Thrown when accepting or upgrading an agreement with an invalid duration
340+
* @notice Thrown when accepting or upgrading an agreement with an invalid duration
312341
* @param requiredMinDuration The required minimum duration
313342
* @param invalidDuration The invalid duration
314343
*/
315344
error RecurringCollectorAgreementInvalidDuration(uint32 requiredMinDuration, uint256 invalidDuration);
316345

317346
/**
318-
* Thrown when calling collect() on an elapsed agreement
347+
* @notice Thrown when calling collect() on an elapsed agreement
319348
* @param agreementId The agreement ID
320349
* @param endsAt The agreement end timestamp
321350
*/
322351
error RecurringCollectorAgreementElapsed(bytes16 agreementId, uint64 endsAt);
323352

324353
/**
325-
* Thrown when calling collect() too soon
354+
* @notice Thrown when calling collect() too soon
326355
* @param agreementId The agreement ID
327356
* @param secondsSinceLast Seconds since last collection
328357
* @param minSeconds Minimum seconds between collections
329358
*/
330359
error RecurringCollectorCollectionTooSoon(bytes16 agreementId, uint32 secondsSinceLast, uint32 minSeconds);
331360

332361
/**
333-
* Thrown when calling collect() too late
362+
* @notice Thrown when calling collect() too late
334363
* @param agreementId The agreement ID
335364
* @param secondsSinceLast Seconds since last collection
336365
* @param maxSeconds Maximum seconds between collections

0 commit comments

Comments
 (0)