Skip to content

Commit 6a63a38

Browse files
committed
refactor: streamline batchTransfer function and remove unused isFirstIndex method in BatchTransferFraction contract
1 parent 7f1097f commit 6a63a38

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

Diff for: src/BatchTransferFraction.sol

+18-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import "./interfaces/IHypercertToken.sol";
55

66
contract 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
}

Diff for: test/BatchTransferFraction.t.sol

-9
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ contract BatchTransferFractionTest is Test {
3636
new BatchTransferFraction(address(0));
3737
}
3838

39-
function testIsFirstIndex() public {
40-
assertEq(hypercertToken.unitsOf(FRACTION_ID), 100_000_000, "Owner should have 100M units");
41-
42-
assertEq(batchTransferFraction.isFirstIndex(CLAIM_ID), true);
43-
assertEq(batchTransferFraction.isFirstIndex(FRACTION_ID), false);
44-
45-
vm.stopPrank();
46-
}
47-
4839
function testRevertINVALID_DATA() public {
4940
vm.expectRevert(BatchTransferFraction.INVALID_DATA.selector);
5041
batchTransferFraction.batchTransfer("");

0 commit comments

Comments
 (0)