RoyaltyReceiver is a contract that allows for splitting royalties or other payments, such as those from primary sales like NFTMintSale. The contract distributes the payments according to a predefined percentage for each recipient.
RoyaltyReceiver inherits OpenZeppelin's Ownable contract, which provides basic authorization control functions such as
onlyOwner modifier and transferring contract ownership.
RoyaltyReceiver implements the IDistributor interface, which requires the implementation of the
init function is called during contract deployment and initializes the RoyaltyReceiver contract with an initial list of recipients and their respective percentage shares (in basis points). It also verifies that the total percentage adds up to 100% (10,000 basis points).
setRecipientsAndBPS function updates the list of recipients and their respective percentage shares. It can only be called by the contract owner. The function requires that the total percentage shares add up to 100% (10,000 basis points).
distributeERC20 function takes an ERC20 token contract as an argument and distributes the entire balance of the token held by the RoyaltyReceiver contract to the recipients based on their predefined percentage shares.
distribute function is an implementation of the
IDistributor interface. It calls the
distributeERC20 function with the provided token and amount.
supportsInterface function checks if the contract supports the specified interface. In this case, it checks for the IDistributor interface.
LogSetRecipients event is emitted when recipients are set or updated. It includes the list of recipient addresses.
LogSetrecipientBPS event is emitted when the percentage shares (in basis points) for recipients are set or updated. It includes the list of recipient percentage shares.
LogDistributeToken event is emitted when tokens are distributed to a recipient. It includes the token contract address, the recipient address, and the distributed amount.
To use RoyaltyReceiver, deploy the contract and initialize it with a list of recipients and their percentage shares. When payments are received, call the
distributeERC20 function to distribute the funds among the recipients according to their predefined shares. If you need to update the list of recipients or their shares, use the
Updated 4 months ago