Skip to content

Instantly share code, notes, and snippets.

@ScreamingHawk
Last active June 3, 2024 19:57
Show Gist options
  • Save ScreamingHawk/4e5776f6720f72de3e7db29de8a85bd6 to your computer and use it in GitHub Desktop.
Save ScreamingHawk/4e5776f6720f72de3e7db29de8a85bd6 to your computer and use it in GitHub Desktop.
How to set up and use OZ Payment Splitter

This is how to set up and use OpenZeppelin's Payment Splitter.

Deployment

Make a folder / repo.

Add forge.

forge init --no-commit

Install OpenZeppelin via forge.

forge install @openzeppelin/[email protected]

Obtain the payee addresses and decide on the ratio for the payment splitter. The ratio must be in whole numbers. For example, if you want to split payments at 1.5% and 3.5%, you can use the ratio 3 : 7.

Deploy the contract.

forge create -i --rpc-url https://nodes.sequence.app/sepolia lib/openzeppelin-contracts/contracts/finance/PaymentSplitter.sol:PaymentSplitter \
--constructor-args "[0xe8db071f698aBA1d60babaE8e08F5cBc28782108,0xE450ae2D6E1E6c09a0c2e355554Df9EE904B90eA]" "[3, 7]"

Usage

When you need payments split, use the deployed contract address as the payment/fee receiver.

For royalties collected by Sequence's ERC-721/1155, this is done using the setDefaultRoyalty(address receiver, uint96 feeNumerator) function.

cast send -i <token_addr> "setDefaultRoyalty(address,uint96)" <splitter_addr> <fee_numerator>

For other integrations, like OpenSea, you may have to use the provided interface.

The payment splitter works on a "pull" mechanism. Payments made to the splitter are held by the splitter contract until the receiver is ready to pull the payment.

The receiver can pull the payment using the release function. Anyone can call this function to pull payments for the receiver.

cast send -i <splitter_addr> "release(address)" <receiver_addr>

Payments made in ERC-20 tokens use a similar function.

cast send -i <splitter_addr> "release(address,address)" <token_addr> <receiver_addr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment