Skip to content

Commit a889789

Browse files
committed
docs: enhance README with detailed usage instructions for BatchTransferFraction
1 parent b537283 commit a889789

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

README.md

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
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)
55

6-
## Implementation
6+
## Table of Contents
77

8-
### BatchTransferFraction
8+
- [Hypercerts Periphery Contracts](#hypercerts-periphery-contracts)
9+
- [Table of Contents](#table-of-contents)
10+
- [BatchTransferFraction](#batchtransferfraction)
11+
- [Implementation](#implementation)
12+
- [Usage](#usage)
13+
- [Deployments](#deployments)
14+
15+
## BatchTransferFraction
16+
17+
### Implementation
918

1019
```mermaid
1120
sequenceDiagram
@@ -55,9 +64,56 @@ end
5564
}
5665
```
5766

58-
## Deployments
67+
### Usage
68+
69+
> [!important]
70+
> make sure you own the hypercerts.
71+
>
72+
> most of hypercerts have **CREATOR ONLY** [transfer restriction](https://github.com/hypercerts-org/hypercerts-protocol/blob/a606868b1f8d0502124428c45a985002170e6fca/contracts/src/protocol/interfaces/IHypercertToken.sol#L9-L19), so make sure you created the hypercerts as well.
73+
74+
1. Encode data with [ethers](https://docs.ethers.org/v5/api/utils/abi/coder) or [viem](https://viem.sh/docs/abi/encodeAbiParameters#encodeabiparameters).
75+
76+
with ethers
77+
78+
```javascript
79+
import { ethers } from "ethers";
80+
...
81+
const recipients = ["0x123....", "0x456...."];
82+
const fractionIds = [BigInt("23894....5301"), BigInt("23894....5302")];
83+
84+
const encodedData = ethers.AbiCoder.defaultAbiCoder().encode(
85+
[`tuple(address[], uint256[])`],
86+
[[recipients, fractionIds]]
87+
);
88+
console.log('Encoded Data:', encodedData);
89+
// e.g. Encoded Data: 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000006aa005386f53ba7b980c61e0d067cabc7602a620000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000c000000000000000000000000000000002
90+
```
91+
92+
with viem
93+
94+
```javascript
95+
import { encodeAbiParameters } from 'viem';
96+
97+
...
98+
const recipients = ["0x123....", "0x456...."];
99+
const fractionIds = [BigInt("23894....5301"), BigInt("23894....5302")];
100+
const abiParams = [
101+
{
102+
type: 'tuple',
103+
components: [{ type: 'address[]' }, { type: 'uint256[]' }],
104+
},
105+
];
106+
const encodedData = encodeAbiParameters(abiParams, [
107+
[recipients, fractionIds],
108+
]);
109+
```
110+
111+
2. In the HypercertsMinter contract on the chain where you want to execute batch transfer, call [setApprovalForAll (0xa22cb465)](https://optimistic.etherscan.io/address/0x822F17A9A5EeCFd66dBAFf7946a8071C265D1d07#writeProxyContract#F17) to approve the batchTransfer contract to send hypercerts.
112+
`operator == BatchTransfer contract address, approved == true`
113+
114+
3. call batchTransfer function
59115

60-
### BatchTransferFraction
116+
### Deployments
61117

62118
| chain | chainId | address |
63119
| ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |

0 commit comments

Comments
 (0)