Skip to content

Commit

Permalink
chore: some minor improvements to GraphPayments and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Dec 18, 2024
1 parent 689b6a8 commit 7cc2996
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/horizon/contracts/interfaces/IGraphPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ interface IGraphPayments {
/**
* @notice Collects funds from a payer.
* It will pay cuts to all relevant parties and forward the rest to the receiver.
* Note that the collected amount can be zero.
* @param paymentType The type of payment as defined in {IGraphPayments}
* @param receiver The address of the receiver
* @param tokens The amount of tokens being collected
* @param tokens The amount of tokens being collected.
* @param dataService The address of the data service
* @param dataServiceCut The data service cut in PPM
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/horizon/contracts/payments/GraphPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { GraphDirectory } from "../utilities/GraphDirectory.sol";
contract GraphPayments is Initializable, MulticallUpgradeable, GraphDirectory, IGraphPayments {
using TokenUtils for IGraphToken;
using PPMMath for uint256;

/// @notice Protocol payment cut in PPM
uint256 public immutable PROTOCOL_PAYMENT_CUT;

/**
Expand Down
29 changes: 29 additions & 0 deletions packages/horizon/test/payments/GraphPayments.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,33 @@ contract GraphPaymentsTest is HorizonStakingSharedTest {
);
vm.stopPrank();
}

function testCollect_ViaMulticall(uint256 amount) public useIndexer {
amount = bound(amount, 1, MAX_STAKING_TOKENS / 2); // Divide by 2 as we'll make two calls

address escrowAddress = address(escrow);
mint(escrowAddress, amount * 2);
vm.startPrank(escrowAddress);
approve(address(payments), amount * 2);

bytes[] memory data = new bytes[](2);
data[0] = abi.encodeWithSelector(
payments.collect.selector,
IGraphPayments.PaymentTypes.QueryFee,
users.indexer,
amount,
subgraphDataServiceAddress,
100_000 // 10%
);
data[1] = abi.encodeWithSelector(
payments.collect.selector,
IGraphPayments.PaymentTypes.IndexingFee,
users.indexer,
amount,
subgraphDataServiceAddress,
200_000 // 20%
);

payments.multicall(data);
}
}

0 comments on commit 7cc2996

Please sign in to comment.