@@ -5,7 +5,6 @@ import "./interfaces/IHypercertToken.sol";
5
5
6
6
contract BatchTransferFraction {
7
7
IHypercertToken public immutable hypercertToken;
8
- uint256 internal constant FRACTION_LIMIT = 253 ;
9
8
10
9
error INVALID_LENGTHS ();
11
10
error INVALID_DATA ();
@@ -22,24 +21,35 @@ contract BatchTransferFraction {
22
21
hypercertToken = IHypercertToken (_hypercertToken);
23
22
}
24
23
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
25
28
function batchTransfer (bytes memory data ) external {
26
29
require (data.length > 0 , INVALID_DATA ());
27
30
TransferData memory transferData = abi.decode (data, (TransferData));
28
31
require (transferData.recipients.length == transferData.fractionIds.length , INVALID_LENGTHS ());
29
32
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];
33
45
require (hypercertToken.ownerOf (fractionId) == msg .sender , INVALID_CALLER (msg .sender ));
34
46
35
47
hypercertToken.safeTransferFrom (msg .sender , recipient, fractionId, 1 , "" );
36
48
}
37
49
}
38
50
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
43
53
function getBaseType (uint256 tokenId ) public pure returns (uint256 ) {
44
54
return tokenId & (type (uint256 ).max << 128 );
45
55
}
0 commit comments