Skip to content

Commit a669f39

Browse files
authored
Update README.md
1 parent 6a63a38 commit a669f39

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

Diff for: README.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
1-
## Hypercerts Periphery Contracts
1+
# Hypercerts Periphery Contracts
22

33
[![TEST](https://github.com/hypercerts-org/protocol-periphery/actions/workflows/test.yml/badge.svg)](https://github.com/hypercerts-org/protocol-periphery/actions/workflows/test.yml)
44
[![Slither Analysis](https://github.com/hypercerts-org/protocol-periphery/actions/workflows/slither.yaml/badge.svg)](https://github.com/hypercerts-org/protocol-periphery/actions/workflows/slither.yaml)
5+
6+
## Implementation
7+
8+
### BatchTransferFraction
9+
```mermaid
10+
sequenceDiagram
11+
actor o as Owner
12+
participant h as Hypercert Minter Contract
13+
participant b as BatchTransfer Contract
14+
actor r as Recipients
15+
16+
o ->> h: call splitFraction()
17+
h ->> h: split fraction
18+
o ->> h: call setApprovalForAll()
19+
o ->> b: call batchTransfer()
20+
critical will be reverted if the owner is not the owner of each fractions
21+
b --> h: check if caller is the owner of fraction
22+
b ->> r: safeTransferFrom()
23+
end
24+
25+
```
26+
```solidity
27+
/// @dev msg.sender must be the owner of all the fraction IDs being transferred
28+
/// @dev msg.sender must have approved the contract to transfer the fractions
29+
/// @dev The length of recipients and fractionIds must be the same
30+
/// @param data The encoded data containing the recipients and fraction IDs
31+
function batchTransfer(bytes memory data) external {
32+
require(data.length > 0, INVALID_DATA());
33+
TransferData memory transferData = abi.decode(data, (TransferData));
34+
require(transferData.recipients.length == transferData.fractionIds.length, INVALID_LENGTHS());
35+
36+
_batchTransfer(transferData.recipients, transferData.fractionIds);
37+
}
38+
39+
/// @notice Transfers fractions to multiple recipients
40+
/// @dev The length of recipients and fractionIds must be the same
41+
/// @dev The caller must be the owner of all the fraction IDs being transferred
42+
/// @param recipients The addresses of the recipients
43+
/// @param fractionIds The IDs of the fractions to be transferred
44+
function _batchTransfer(address[] memory recipients, uint256[] memory fractionIds) internal {
45+
for (uint256 i = 0; i < recipients.length; i++) {
46+
address recipient = recipients[i];
47+
uint256 fractionId = fractionIds[i];
48+
require(hypercertToken.ownerOf(fractionId) == msg.sender, INVALID_CALLER(msg.sender));
49+
50+
hypercertToken.safeTransferFrom(msg.sender, recipient, fractionId, 1, "");
51+
}
52+
}
53+
```

0 commit comments

Comments
 (0)