Skip to content

Commit 4a25bab

Browse files
authored
Merge branch 'horizon' into tmigone/trust-fixes-data-service
2 parents 4d62209 + 1109537 commit 4a25bab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2221
-1033
lines changed

packages/horizon/contracts/interfaces/IGraphPayments.sol

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,57 @@ interface IGraphPayments {
2323
* @param payer The address of the payer
2424
* @param receiver The address of the receiver
2525
* @param dataService The address of the data service
26-
* @param tokensReceiver Amount of tokens for the receiver
27-
* @param tokensDelegationPool Amount of tokens for delegators
28-
* @param tokensDataService Amount of tokens for the data service
26+
* @param tokens The total amount of tokens being collected
2927
* @param tokensProtocol Amount of tokens charged as protocol tax
28+
* @param tokensDataService Amount of tokens for the data service
29+
* @param tokensDelegationPool Amount of tokens for delegators
30+
* @param tokensReceiver Amount of tokens for the receiver
3031
*/
31-
event PaymentCollected(
32+
event GraphPaymentCollected(
3233
address indexed payer,
3334
address indexed receiver,
3435
address indexed dataService,
35-
uint256 tokensReceiver,
36-
uint256 tokensDelegationPool,
36+
uint256 tokens,
37+
uint256 tokensProtocol,
3738
uint256 tokensDataService,
38-
uint256 tokensProtocol
39+
uint256 tokensDelegationPool,
40+
uint256 tokensReceiver
3941
);
4042

4143
/**
42-
* @notice Thrown when there are insufficient tokens to pay the required amount
43-
* @param tokens The amount of tokens available
44-
* @param minTokens The amount of tokens being collected
44+
* @notice Thrown when the calculated amount of tokens to be paid out to all parties is
45+
* not the same as the amount of tokens being collected
46+
* @param tokens The amount of tokens being collected
47+
* @param tokensCalculated The sum of all the tokens to be paid out
4548
*/
46-
error GraphPaymentsInsufficientTokens(uint256 tokens, uint256 minTokens);
49+
error GraphPaymentsBadAccounting(uint256 tokens, uint256 tokensCalculated);
4750

4851
/**
4952
* @notice Thrown when the protocol payment cut is invalid
5053
* @param protocolPaymentCut The protocol payment cut
5154
*/
5255
error GraphPaymentsInvalidProtocolPaymentCut(uint256 protocolPaymentCut);
5356

57+
/**
58+
* @notice Thrown when trying to use a cut that is not expressed in PPM
59+
* @param cut The cut
60+
*/
61+
error GraphPaymentsInvalidCut(uint256 cut);
62+
5463
/**
5564
* @notice Collects funds from a payer.
5665
* It will pay cuts to all relevant parties and forward the rest to the receiver.
5766
* @param paymentType The type of payment as defined in {IGraphPayments}
5867
* @param receiver The address of the receiver
5968
* @param tokens The amount of tokens being collected
6069
* @param dataService The address of the data service
61-
* @param tokensDataService The amount of tokens that should be sent to the data service
70+
* @param dataServiceCut The data service cut in PPM
6271
*/
6372
function collect(
6473
PaymentTypes paymentType,
6574
address receiver,
6675
uint256 tokens,
6776
address dataService,
68-
uint256 tokensDataService
77+
uint256 dataServiceCut
6978
) external;
7079
}

packages/horizon/contracts/interfaces/IPaymentsCollector.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ interface IPaymentsCollector {
1919
* @param paymentType The payment type collected as defined by {IGraphPayments}
2020
* @param payer The address of the payer
2121
* @param receiver The address of the receiver
22-
* @param tokensReceiver The amount of tokens received by the receiver
2322
* @param dataService The address of the data service
24-
* @param tokensDataService The amount of tokens received by the data service
23+
* @param tokens The amount of tokens being collected
2524
*/
2625
event PaymentCollected(
2726
IGraphPayments.PaymentTypes indexed paymentType,
2827
address indexed payer,
2928
address receiver,
30-
uint256 tokensReceiver,
3129
address indexed dataService,
32-
uint256 tokensDataService
30+
uint256 tokens
3331
);
3432

3533
/**

packages/horizon/contracts/interfaces/IPaymentsEscrow.sol

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,6 @@ interface IPaymentsEscrow {
2525
uint256 thawEndTimestamp;
2626
}
2727

28-
/// @notice Details for a payer-collector pair
29-
/// @dev Collectors can be removed only after a thawing period
30-
struct Collector {
31-
// Amount of tokens the collector is allowed to collect
32-
uint256 allowance;
33-
// Timestamp at which the collector thawing period ends (zero if not thawing)
34-
uint256 thawEndTimestamp;
35-
}
36-
37-
/**
38-
* @notice Emitted when a payer authorizes a collector to collect funds
39-
* @param payer The address of the payer
40-
* @param collector The address of the collector
41-
* @param addedAllowance The amount of tokens added to the collector's allowance
42-
* @param newTotalAllowance The new total allowance after addition
43-
*/
44-
event AuthorizedCollector(
45-
address indexed payer,
46-
address indexed collector,
47-
uint256 addedAllowance,
48-
uint256 newTotalAllowance
49-
);
50-
51-
/**
52-
* @notice Emitted when a payer thaws a collector
53-
* @param payer The address of the payer
54-
* @param collector The address of the collector
55-
*/
56-
event ThawCollector(address indexed payer, address indexed collector);
57-
58-
/**
59-
* @notice Emitted when a payer cancels the thawing of a collector
60-
* @param payer The address of the payer
61-
* @param collector The address of the collector
62-
*/
63-
event CancelThawCollector(address indexed payer, address indexed collector);
64-
65-
/**
66-
* @notice Emitted when a payer revokes a collector authorization.
67-
* @param payer The address of the payer
68-
* @param collector The address of the collector
69-
*/
70-
event RevokeCollector(address indexed payer, address indexed collector);
71-
7228
/**
7329
* @notice Emitted when a payer deposits funds into the escrow for a payer-collector-receiver tuple
7430
* @param payer The address of the payer
@@ -152,13 +108,6 @@ interface IPaymentsEscrow {
152108
*/
153109
error PaymentsEscrowThawingPeriodTooLong(uint256 thawingPeriod, uint256 maxWaitPeriod);
154110

155-
/**
156-
* @notice Thrown when a collector has insufficient allowance to collect funds
157-
* @param allowance The current allowance
158-
* @param minAllowance The minimum required allowance
159-
*/
160-
error PaymentsEscrowInsufficientAllowance(uint256 allowance, uint256 minAllowance);
161-
162111
/**
163112
* @notice Thrown when the contract balance is not consistent with the collection amount
164113
* @param balanceBefore The balance before the collection
@@ -172,54 +121,6 @@ interface IPaymentsEscrow {
172121
*/
173122
error PaymentsEscrowInvalidZeroTokens();
174123

175-
/**
176-
* @notice Authorize a collector to collect funds from the payer's escrow
177-
* @dev This function can only be used to increase the allowance of a collector.
178-
* To reduce it the authorization must be revoked and a new one must be created.
179-
*
180-
* Requirements:
181-
* - `allowance` must be greater than zero
182-
*
183-
* Emits an {AuthorizedCollector} event
184-
*
185-
* @param collector The address of the collector
186-
* @param allowance The amount of tokens to add to the collector's allowance
187-
*/
188-
function approveCollector(address collector, uint256 allowance) external;
189-
190-
/**
191-
* @notice Thaw a collector's collector authorization
192-
* @dev The thawing period is defined by the `REVOKE_COLLECTOR_THAWING_PERIOD` constant
193-
*
194-
* Emits a {ThawCollector} event
195-
*
196-
* @param collector The address of the collector
197-
*/
198-
function thawCollector(address collector) external;
199-
200-
/**
201-
* @notice Cancel a collector's authorization thawing
202-
* @dev Requirements:
203-
* - `collector` must be thawing
204-
*
205-
* Emits a {CancelThawCollector} event
206-
*
207-
* @param collector The address of the collector
208-
*/
209-
function cancelThawCollector(address collector) external;
210-
211-
/**
212-
* @notice Revoke a collector's authorization.
213-
* Removes the collector from the list of authorized collectors.
214-
* @dev Requirements:
215-
* - `collector` must have thawed
216-
*
217-
* Emits a {RevokeCollector} event
218-
*
219-
* @param collector The address of the collector
220-
*/
221-
function revokeCollector(address collector) external;
222-
223124
/**
224125
* @notice Deposits funds into the escrow for a payer-collector-receiver tuple, where
225126
* the payer is the transaction caller.
@@ -277,8 +178,6 @@ interface IPaymentsEscrow {
277178
* @notice Collects funds from the payer-collector-receiver's escrow and sends them to {GraphPayments} for
278179
* distribution using the Graph Horizon Payments protocol.
279180
* The function will revert if there are not enough funds in the escrow.
280-
* @dev Requirements:
281-
* - `collector` needs to be authorized by the payer and have enough allowance
282181
*
283182
* Emits an {EscrowCollected} event
284183
*
@@ -287,19 +186,20 @@ interface IPaymentsEscrow {
287186
* @param receiver The address of the receiver
288187
* @param tokens The amount of tokens to collect
289188
* @param dataService The address of the data service
290-
* @param tokensDataService The amount of tokens that {GraphPayments} should send to the data service
189+
* @param dataServiceCut The data service cut in PPM that {GraphPayments} should send
291190
*/
292191
function collect(
293192
IGraphPayments.PaymentTypes paymentType,
294193
address payer,
295194
address receiver,
296195
uint256 tokens,
297196
address dataService,
298-
uint256 tokensDataService
197+
uint256 dataServiceCut
299198
) external;
300199

301200
/**
302201
* @notice Get the balance of a payer-collector-receiver tuple
202+
* This function will return 0 if the current balance is less than the amount of funds being thawed.
303203
* @param payer The address of the payer
304204
* @param collector The address of the collector
305205
* @param receiver The address of the receiver

packages/horizon/contracts/interfaces/ITAPCollector.sol

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity 0.8.27;
33

44
import { IPaymentsCollector } from "./IPaymentsCollector.sol";
5+
import { IGraphPayments } from "./IGraphPayments.sol";
56

67
/**
78
* @title Interface for the {TAPCollector} contract
@@ -18,10 +19,14 @@ interface ITAPCollector is IPaymentsCollector {
1819
address payer;
1920
// Timestamp at which thawing period ends (zero if not thawing)
2021
uint256 thawEndTimestamp;
22+
// Whether the signer authorization was revoked
23+
bool revoked;
2124
}
2225

2326
/// @notice The Receipt Aggregate Voucher (RAV) struct
2427
struct ReceiptAggregateVoucher {
28+
// The address of the payer the RAV was issued by
29+
address payer;
2530
// The address of the data service the RAV was issued to
2631
address dataService;
2732
// The address of the service provider the RAV was issued to
@@ -119,6 +124,19 @@ interface ITAPCollector is IPaymentsCollector {
119124
*/
120125
error TAPCollectorSignerNotAuthorizedByPayer(address payer, address signer);
121126

127+
/**
128+
* Thrown when the attempting to revoke a signer that was already revoked
129+
* @param signer The address of the signer
130+
*/
131+
error TAPCollectorAuthorizationAlreadyRevoked(address payer, address signer);
132+
133+
/**
134+
* Thrown when attempting to thaw a signer that is already thawing
135+
* @param signer The address of the signer
136+
* @param thawEndTimestamp The timestamp at which the thawing period ends
137+
*/
138+
error TAPCollectorSignerAlreadyThawing(address signer, uint256 thawEndTimestamp);
139+
122140
/**
123141
* Thrown when the signer is not thawing
124142
* @param signer The address of the signer
@@ -137,6 +155,19 @@ interface ITAPCollector is IPaymentsCollector {
137155
*/
138156
error TAPCollectorInvalidRAVSigner();
139157

158+
/**
159+
* Thrown when the RAV payer does not match the signers authorized payer
160+
* @param authorizedPayer The address of the authorized payer
161+
* @param ravPayer The address of the RAV payer
162+
*/
163+
error TAPCollectorInvalidRAVPayer(address authorizedPayer, address ravPayer);
164+
165+
/**
166+
* Thrown when the RAV is for a data service the service provider has no provision for
167+
* @param dataService The address of the data service
168+
*/
169+
error TAPCollectorUnauthorizedDataService(address dataService);
170+
140171
/**
141172
* Thrown when the caller is not the data service the RAV was issued to
142173
* @param caller The address of the caller
@@ -153,7 +184,15 @@ interface ITAPCollector is IPaymentsCollector {
153184
error TAPCollectorInconsistentRAVTokens(uint256 tokens, uint256 tokensCollected);
154185

155186
/**
156-
* @notice Authorize a signer to sign on behalf of the payer
187+
* Thrown when the attempting to collect more tokens than what it's owed
188+
* @param tokensToCollect The amount of tokens to collect
189+
* @param maxTokensToCollect The maximum amount of tokens to collect
190+
*/
191+
error TAPCollectorInvalidTokensToCollectAmount(uint256 tokensToCollect, uint256 maxTokensToCollect);
192+
193+
/**
194+
* @notice Authorize a signer to sign on behalf of the payer.
195+
* A signer can not be authorized for multiple payers even after revoking previous authorizations.
157196
* @dev Requirements:
158197
* - `signer` must not be already authorized
159198
* - `proofDeadline` must be greater than the current timestamp
@@ -213,4 +252,21 @@ interface ITAPCollector is IPaymentsCollector {
213252
* @return The hash of the RAV.
214253
*/
215254
function encodeRAV(ReceiptAggregateVoucher calldata rav) external view returns (bytes32);
255+
256+
/**
257+
* @notice See {IPaymentsCollector.collect}
258+
* This variant adds the ability to partially collect a RAV by specifying the amount of tokens to collect.
259+
*
260+
* Requirements:
261+
* - The amount of tokens to collect must be less than or equal to the total amount of tokens in the RAV minus
262+
* the tokens already collected.
263+
* @param paymentType The payment type to collect
264+
* @param data Additional data required for the payment collection
265+
* @param tokensToCollect The amount of tokens to collect
266+
*/
267+
function collect(
268+
IGraphPayments.PaymentTypes paymentType,
269+
bytes calldata data,
270+
uint256 tokensToCollect
271+
) external returns (uint256);
216272
}

0 commit comments

Comments
 (0)