Skip to content

Commit

Permalink
chore: update event and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
8sunyuan committed Apr 19, 2024
1 parent 81c3919 commit f13e1c2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/contracts/core/PaymentCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ contract PaymentCoordinator is
cumulativeClaimed[earner][tokenLeaf.token] = tokenLeaf.cumulativeEarnings;

tokenLeaf.token.safeTransfer(claimer, claimAmount);
emit PaymentClaimed(root.root, tokenLeaf);
emit PaymentClaimed(root.root, earner, claimer, claim.tokenLeaves[i].token, claimAmount);
}
}

Expand Down
21 changes: 12 additions & 9 deletions src/contracts/interfaces/IPaymentCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ interface IPaymentCoordinator {

/**
* Sliding Window for valid RangePayment startTimestamp
*
*
* Scenario A: GENESIS_PAYMENT_TIMESTAMP IS WITHIN RANGE
* <-----MAX_RETROACTIVE_LENGTH-----> t (block.timestamp) <---MAX_FUTURE_LENGTH--->
* <--------------------valid range for startTimestamp------------------------>
* ^
* GENESIS_PAYMENT_TIMESTAMP
*
*
*
* Scenario B: GENESIS_PAYMENT_TIMESTAMP IS OUT OF RANGE
* <-----MAX_RETROACTIVE_LENGTH-----> t (block.timestamp) <---MAX_FUTURE_LENGTH--->
* <------------------------valid range for startTimestamp------------------------>
Expand Down Expand Up @@ -114,7 +114,7 @@ interface IPaymentCoordinator {
* @param tokenLeaves The token leaves to be claimed
* @dev The merkle tree is structured with the merkle root at the top and EarnerTreeMerkleLeaf as internal leaves
* in the tree. Each earner leaf has its own subtree with TokenTreeMerkleLeaf as leaves in the subtree.
* To prove a claim against a specified rootIndex(which specifies the distributionRoot being used),
* To prove a claim against a specified rootIndex(which specifies the distributionRoot being used),
* the claim will first verify inclusion of the earner leaf in the tree against distributionRoots[rootIndex].root.
* Then for each token, it will verify inclusion of the token leaf in the earner's subtree against the earner's earnerTokenRoot.
*/
Expand Down Expand Up @@ -155,15 +155,21 @@ interface IPaymentCoordinator {
event CalculationIntervalSecondsSet(uint32 oldCalculationIntervalSeconds, uint32 newCalculationIntervalSeconds);
event GlobalCommissionBipsSet(uint16 oldGlobalCommissionBips, uint16 newGlobalCommissionBips);
event ClaimerForSet(address indexed earner, address indexed oldClaimer, address indexed claimer);
/// @notice rootIndex is the specific array index of the newly created root in the storage array
/// @notice rootIndex is the specific array index of the newly created root in the storage array
event DistributionRootSubmitted(
uint32 indexed rootIndex,
bytes32 indexed root,
uint32 paymentCalculationEndTimestamp,
uint32 activatedAt
);
/// @notice root is one of the submitted distribution roots that was claimed against
event PaymentClaimed(bytes32 indexed root, TokenTreeMerkleLeaf leaf);
event PaymentClaimed(
bytes32 root,
address indexed earner,
address indexed claimer,
IERC20 indexed token,
uint256 claimedAmount
);

/// VIEW FUNCTIONS ///

Expand Down Expand Up @@ -251,10 +257,7 @@ interface IPaymentCoordinator {
* @param paymentCalculationEndTimestamp The timestamp until which payments have been calculated
* @dev Only callable by the paymentUpdater
*/
function submitRoot(
bytes32 root,
uint32 paymentCalculationEndTimestamp
) external;
function submitRoot(bytes32 root, uint32 paymentCalculationEndTimestamp) external;

/**
* @notice Sets the permissioned `paymentUpdater` address which can post new roots
Expand Down
8 changes: 7 additions & 1 deletion src/test/events/IPaymentCoordinatorEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ interface IPaymentCoordinatorEvents {
uint32 activatedAt
);
/// @notice root is one of the submitted distribution roots that was claimed against
event PaymentClaimed(bytes32 indexed root, IPaymentCoordinator.TokenTreeMerkleLeaf leaf);
event PaymentClaimed(
bytes32 root,
address indexed earner,
address indexed claimer,
IERC20 indexed token,
uint256 claimedAmount
);



Expand Down
28 changes: 24 additions & 4 deletions src/test/unit/PaymentCoordinatorUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,19 @@ contract PaymentCoordinatorUnitTests is EigenLayerUnitTestSetup, IPaymentCoordin
}

function _assertPaymentClaimedEvents(bytes32 root, IPaymentCoordinator.PaymentMerkleClaim memory claim) internal {
address earner = claim.earnerLeaf.earner;
address claimer = paymentCoordinator.claimerFor(earner);
if (claimer == address(0)) {
claimer = earner;
}
IERC20 token;
uint256 claimedAmount;
for (uint256 i = 0; i < claim.tokenLeaves.length; ++i) {
token = claim.tokenLeaves[i].token;
claimedAmount = paymentCoordinator.cumulativeClaimed(earner, token);

cheats.expectEmit(true, true, true, true, address(paymentCoordinator));
emit PaymentClaimed(root, claim.tokenLeaves[i]);
emit PaymentClaimed(root, earner, claimer, token, claim.tokenLeaves[i].cumulativeEarnings - claimedAmount);
}
}

Expand Down Expand Up @@ -283,7 +293,10 @@ contract PaymentCoordinatorUnitTests_initializeAndSetters is PaymentCoordinatorU
cheats.stopPrank();
}

function testFuzz_setCalculationIntervalSeconds_Revert_WhenNotOwner(address caller, uint32 intervalSeconds) public {
function testFuzz_setCalculationIntervalSeconds_Revert_WhenNotOwner(
address caller,
uint32 intervalSeconds
) public filterFuzzedAddressInputs(caller) {
cheats.assume(caller != paymentCoordinator.owner());
cheats.prank(caller);
cheats.expectRevert("Ownable: caller is not the owner");
Expand All @@ -299,7 +312,10 @@ contract PaymentCoordinatorUnitTests_initializeAndSetters is PaymentCoordinatorU
cheats.stopPrank();
}

function testFuzz_setActivationDelay_Revert_WhenNotOwner(address caller, uint32 activationDelay) public filterFuzzedAddressInputs(caller) {
function testFuzz_setActivationDelay_Revert_WhenNotOwner(
address caller,
uint32 activationDelay
) public filterFuzzedAddressInputs(caller) {
cheats.assume(caller != paymentCoordinator.owner());
cheats.prank(caller);
cheats.expectRevert("Ownable: caller is not the owner");
Expand Down Expand Up @@ -958,7 +974,11 @@ contract PaymentCoordinatorUnitTests_payAllForRange is PaymentCoordinatorUnitTes
paymentCoordinator.isRangePaymentForAllHash(payAllSubmitter, rangePaymentHash),
"Range payment hash not submitted"
);
assertEq(currPaymentNonce + 1, paymentCoordinator.paymentNonce(payAllSubmitter), "Payment nonce not incremented");
assertEq(
currPaymentNonce + 1,
paymentCoordinator.paymentNonce(payAllSubmitter),
"Payment nonce not incremented"
);
assertEq(
submitterBalanceBefore - amount,
paymentToken.balanceOf(payAllSubmitter),
Expand Down

0 comments on commit f13e1c2

Please sign in to comment.