@@ -5,7 +5,6 @@ import "./interfaces/IHypercertToken.sol";
55
66contract BatchTransferFraction {
77 IHypercertToken public immutable hypercertToken;
8- uint256 internal constant FRACTION_LIMIT = 253 ;
98
109 error INVALID_LENGTHS ();
1110 error INVALID_DATA ();
@@ -22,24 +21,35 @@ contract BatchTransferFraction {
2221 hypercertToken = IHypercertToken (_hypercertToken);
2322 }
2423
24+ /// @dev msg.sender must be the owner of all the fraction IDs being transferred
25+ /// @dev msg.sender must have approved the contract to transfer the fractions
26+ /// @dev The length of recipients and fractionIds must be the same
27+ /// @param data The encoded data containing the recipients and fraction IDs
2528 function batchTransfer (bytes memory data ) external {
2629 require (data.length > 0 , INVALID_DATA ());
2730 TransferData memory transferData = abi.decode (data, (TransferData));
2831 require (transferData.recipients.length == transferData.fractionIds.length , INVALID_LENGTHS ());
2932
30- for (uint256 i = 0 ; i < transferData.recipients.length ; i++ ) {
31- address recipient = transferData.recipients[i];
32- uint256 fractionId = transferData.fractionIds[i];
33+ _batchTransfer (transferData.recipients, transferData.fractionIds);
34+ }
35+
36+ /// @notice Transfers fractions to multiple recipients
37+ /// @dev The length of recipients and fractionIds must be the same
38+ /// @dev The caller must be the owner of all the fraction IDs being transferred
39+ /// @param recipients The addresses of the recipients
40+ /// @param fractionIds The IDs of the fractions to be transferred
41+ function _batchTransfer (address [] memory recipients , uint256 [] memory fractionIds ) internal {
42+ for (uint256 i = 0 ; i < recipients.length ; i++ ) {
43+ address recipient = recipients[i];
44+ uint256 fractionId = fractionIds[i];
3345 require (hypercertToken.ownerOf (fractionId) == msg .sender , INVALID_CALLER (msg .sender ));
3446
3547 hypercertToken.safeTransferFrom (msg .sender , recipient, fractionId, 1 , "" );
3648 }
3749 }
3850
39- function isFirstIndex (uint256 tokenId ) public pure returns (bool ) {
40- return (tokenId & ((1 << 128 ) - 1 )) == 0 ;
41- }
42-
51+ /// @notice Returns the base type of a token ID
52+ /// @dev The base type is the first 128 bits of the token ID
4353 function getBaseType (uint256 tokenId ) public pure returns (uint256 ) {
4454 return tokenId & (type (uint256 ).max << 128 );
4555 }
0 commit comments