Skip to content

Commit 8694e06

Browse files
committed
chore: some minor improvements to GraphPayments and tests
Signed-off-by: Tomás Migone <[email protected]>
1 parent 975e6db commit 8694e06

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

packages/horizon/contracts/interfaces/IGraphPayments.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ interface IGraphPayments {
5757
/**
5858
* @notice Collects funds from a payer.
5959
* It will pay cuts to all relevant parties and forward the rest to the receiver.
60+
* Note that the collected amount can be zero.
6061
* @param paymentType The type of payment as defined in {IGraphPayments}
6162
* @param receiver The address of the receiver
62-
* @param tokens The amount of tokens being collected
63+
* @param tokens The amount of tokens being collected.
6364
* @param dataService The address of the data service
6465
* @param dataServiceCut The data service cut in PPM
6566
*/

packages/horizon/contracts/payments/GraphPayments.sol

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { GraphDirectory } from "../utilities/GraphDirectory.sol";
2323
contract GraphPayments is Initializable, MulticallUpgradeable, GraphDirectory, IGraphPayments {
2424
using TokenUtils for IGraphToken;
2525
using PPMMath for uint256;
26+
27+
/// @notice Protocol payment cut in PPM
2628
uint256 public immutable PROTOCOL_PAYMENT_CUT;
2729

2830
/**

packages/horizon/test/payments/GraphPayments.t.sol

+29
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,33 @@ contract GraphPaymentsTest is HorizonStakingSharedTest {
290290
);
291291
vm.stopPrank();
292292
}
293+
294+
function testCollect_ViaMulticall(uint256 amount) public useIndexer {
295+
amount = bound(amount, 1, MAX_STAKING_TOKENS / 2); // Divide by 2 as we'll make two calls
296+
297+
address escrowAddress = address(escrow);
298+
mint(escrowAddress, amount * 2);
299+
vm.startPrank(escrowAddress);
300+
approve(address(payments), amount * 2);
301+
302+
bytes[] memory data = new bytes[](2);
303+
data[0] = abi.encodeWithSelector(
304+
payments.collect.selector,
305+
IGraphPayments.PaymentTypes.QueryFee,
306+
users.indexer,
307+
amount,
308+
subgraphDataServiceAddress,
309+
100_000 // 10%
310+
);
311+
data[1] = abi.encodeWithSelector(
312+
payments.collect.selector,
313+
IGraphPayments.PaymentTypes.IndexingFee,
314+
users.indexer,
315+
amount,
316+
subgraphDataServiceAddress,
317+
200_000 // 20%
318+
);
319+
320+
payments.multicall(data);
321+
}
293322
}

0 commit comments

Comments
 (0)