Skip to content

Commit 74645a2

Browse files
committed
feat: add collector address to the RAV
Signed-off-by: Tomás Migone <[email protected]>
1 parent 6d1afc0 commit 74645a2

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

packages/horizon/contracts/interfaces/ITAPCollector.sol

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ interface ITAPCollector is IPaymentsCollector {
2929
bytes32 collectionId;
3030
// The address of the payer the RAV was issued by
3131
address payer;
32-
// The address of the data service the RAV was issued to
33-
address dataService;
32+
// The address of the collector where the RAV can be collected
33+
address collector;
3434
// The address of the service provider the RAV was issued to
3535
address serviceProvider;
36+
// The address of the data service the RAV was issued to
37+
address dataService;
3638
// The RAV timestamp, indicating the latest TAP Receipt in the RAV
3739
uint64 timestampNs;
3840
// Total amount owed to the service provider since the beginning of the
@@ -102,6 +104,13 @@ interface ITAPCollector is IPaymentsCollector {
102104
bytes signature
103105
);
104106

107+
/**
108+
* Thrown when attempting to collect a RAV that was not issued to this collector
109+
* @param collector The address of this collector processing the RAV
110+
* @param ravCollector The collector address noted in the RAV
111+
*/
112+
error TAPCollectorInvalidCollector(address collector, address ravCollector);
113+
105114
/**
106115
* Thrown when the signer is already authorized
107116
* @param authorizingPayer The address of the payer authorizing the signer

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
2929
/// @notice The EIP712 typehash for the ReceiptAggregateVoucher struct
3030
bytes32 private constant EIP712_RAV_TYPEHASH =
3131
keccak256(
32-
"ReceiptAggregateVoucher(address payer,address dataService,address serviceProvider,uint64 timestampNs,uint128 valueAggregate,bytes metadata)"
32+
"ReceiptAggregateVoucher(address payer,address collector,address serviceProvider,address dataService,uint64 timestampNs,uint128 valueAggregate,bytes metadata)"
3333
);
3434

3535
/// @notice Authorization details for payer-signer pairs
@@ -166,8 +166,15 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
166166
bytes memory _data,
167167
uint256 _tokensToCollect
168168
) private returns (uint256) {
169-
// Ensure caller is the RAV data service
170169
(SignedRAV memory signedRAV, uint256 dataServiceCut) = abi.decode(_data, (SignedRAV, uint256));
170+
171+
// Ensure the RAV was issued to this collector
172+
require(
173+
signedRAV.rav.collector == address(this),
174+
TAPCollectorInvalidCollector(address(this), signedRAV.rav.collector)
175+
);
176+
177+
// Ensure caller is the RAV data service
171178
require(
172179
signedRAV.rav.dataService == msg.sender,
173180
TAPCollectorCallerNotDataService(msg.sender, signedRAV.rav.dataService)
@@ -259,8 +266,9 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {
259266
abi.encode(
260267
EIP712_RAV_TYPEHASH,
261268
_rav.payer,
262-
_rav.dataService,
269+
_rav.collector,
263270
_rav.serviceProvider,
271+
_rav.dataService,
264272
_rav.timestampNs,
265273
_rav.valueAggregate,
266274
keccak256(_rav.metadata)

packages/horizon/test/payments/tap-collector/collect/collect.t.sol

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ contract TAPCollectorCollectTest is TAPCollectorTest {
4242
function _getRAV(
4343
address _allocationId,
4444
address _payer,
45-
address _indexer,
4645
address _collector,
46+
address _indexer,
47+
address _dataService,
4748
uint128 _tokens
4849
) private pure returns (ITAPCollector.ReceiptAggregateVoucher memory rav) {
4950
return
5051
ITAPCollector.ReceiptAggregateVoucher({
5152
collectionId: bytes32(uint256(uint160(_allocationId))),
5253
payer: _payer,
53-
dataService: _collector,
54+
collector: _collector,
55+
dataService: _dataService,
5456
serviceProvider: _indexer,
5557
timestampNs: 0,
5658
valueAggregate: _tokens,
@@ -109,6 +111,27 @@ contract TAPCollectorCollectTest is TAPCollectorTest {
109111
}
110112
}
111113

114+
function testTAPCollector_Collect_RevertWhen_OtherCollector() public useGateway useSigner {
115+
address otherCollector = makeAddr("otherCollector");
116+
bytes memory data = _getQueryFeeEncodedData(
117+
signerPrivateKey,
118+
users.gateway,
119+
otherCollector,
120+
users.indexer,
121+
users.verifier,
122+
uint128(0)
123+
);
124+
125+
resetPrank(users.verifier);
126+
bytes memory expectedError = abi.encodeWithSelector(
127+
ITAPCollector.TAPCollectorInvalidCollector.selector,
128+
address(tapCollector),
129+
otherCollector
130+
);
131+
vm.expectRevert(expectedError);
132+
tapCollector.collect(IGraphPayments.PaymentTypes.QueryFee, data);
133+
}
134+
112135
function testTAPCollector_Collect_RevertWhen_NoProvision(uint256 tokens) public useGateway useSigner {
113136
tokens = bound(tokens, 1, type(uint128).max);
114137

packages/subgraph-service/test/subgraphService/collect/query/query.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ contract SubgraphServiceRegisterTest is SubgraphServiceTest {
4949
ITAPCollector.ReceiptAggregateVoucher({
5050
collectionId: collectionId,
5151
payer: users.gateway,
52-
dataService: address(subgraphService),
52+
collector: address(tapCollector),
5353
serviceProvider: indexer,
54+
dataService: address(subgraphService),
5455
timestampNs: 0,
5556
valueAggregate: tokens,
5657
metadata: ""

0 commit comments

Comments
 (0)