From 518c6049bca57334c897bea59dfdfad005065629 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:45:49 -0700 Subject: [PATCH] add qualified batch cases --- src/TheCompact.sol | 80 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/src/TheCompact.sol b/src/TheCompact.sol index f547d96..9f135f5 100644 --- a/src/TheCompact.sol +++ b/src/TheCompact.sol @@ -773,6 +773,16 @@ contract TheCompact is ITheCompact, ERC6909, Extsload { return _processSplitClaimWithQualificationAndSponsorDomain(messageHash, qualificationMessageHash, calldataPointer, offsetToId, bytes32(0), operation); } + function _processBatchClaimWithQualification( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return _processBatchClaimWithQualificationAndSponsorDomain(messageHash, qualificationMessageHash, calldataPointer, offsetToId, bytes32(0), operation); + } + function _validate(uint96 allocatorId, bytes32 messageHash, bytes32 qualificationMessageHash, uint256 calldataPointer, bytes32 sponsorDomainSeparator) internal returns (address sponsor) { bytes calldata allocatorSignature; bytes calldata sponsorSignature; @@ -1122,6 +1132,58 @@ contract TheCompact is ITheCompact, ERC6909, Extsload { } } + function usingQualifiedBatchClaim( + function( + bytes32, + bytes32, + uint256, + uint256, + function(address, address, uint256, uint256) internal returns (bool) + ) internal returns (bool) fnIn + ) + internal + pure + returns ( + function( + bytes32, + bytes32, + QualifiedBatchClaim calldata, + uint256, + function(address, address, uint256, uint256) internal returns (bool) + ) internal returns (bool) fnOut + ) + { + assembly { + fnOut := fnIn + } + } + + function usingQualifiedBatchClaimWithWitness( + function( + bytes32, + bytes32, + uint256, + uint256, + function(address, address, uint256, uint256) internal returns (bool) + ) internal returns (bool) fnIn + ) + internal + pure + returns ( + function( + bytes32, + bytes32, + QualifiedBatchClaimWithWitness calldata, + uint256, + function(address, address, uint256, uint256) internal returns (bool) + ) internal returns (bool) fnOut + ) + { + assembly { + fnOut := fnIn + } + } + function usingQualifiedSplitClaimWithWitness( function( bytes32, @@ -1507,14 +1569,7 @@ contract TheCompact is ITheCompact, ERC6909, Extsload { function _processQualifiedBatchClaim(QualifiedBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); - uint96 allocatorId = claimPayload.claims[0].id.toAllocatorId(); - address allocator = allocatorId.fromRegisteredAllocatorIdWithConsumed(claimPayload.nonce); - - _notExpiredAndSignedByBoth(claimPayload.expires, messageHash, claimPayload.sponsor, claimPayload.sponsorSignature, qualificationMessageHash, allocator, claimPayload.allocatorSignature); - - _emitClaim(claimPayload.sponsor, messageHash, allocator); - - return _verifyAndProcessBatchComponents(allocatorId, claimPayload.sponsor, claimPayload.claimant, messageHash, claimPayload.claims, operation); + return usingQualifiedBatchClaim(_processBatchClaimWithQualification)(messageHash, qualificationMessageHash, claimPayload, 0xe0, operation); } function _processBatchClaimWithWitness(BatchClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { @@ -1525,15 +1580,8 @@ contract TheCompact is ITheCompact, ERC6909, Extsload { internal returns (bool) { - uint96 allocatorId = claimPayload.claims[0].id.toAllocatorId(); - address allocator = allocatorId.fromRegisteredAllocatorIdWithConsumed(claimPayload.nonce); (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); - - _notExpiredAndSignedByBoth(claimPayload.expires, messageHash, claimPayload.sponsor, claimPayload.sponsorSignature, qualificationMessageHash, allocator, claimPayload.allocatorSignature); - - _emitClaim(claimPayload.sponsor, messageHash, allocator); - - return _verifyAndProcessBatchComponents(allocatorId, claimPayload.sponsor, claimPayload.claimant, messageHash, claimPayload.claims, operation); + return usingQualifiedBatchClaimWithWitness(_processBatchClaimWithQualification)(messageHash, qualificationMessageHash, claimPayload, 0x120, operation); } function _processBatchPermit2Deposits(