RoyaltyReceiver.sol

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.

Inherited Contracts


Ownable

RoyaltyReceiver inherits OpenZeppelin's Ownable contract, which provides basic authorization control functions such as onlyOwner modifier and transferring contract ownership.

IDistributor

RoyaltyReceiver implements the IDistributor interface, which requires the implementation of the distribute function.

Key Functions


init

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

The 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

The 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

The distribute function is an implementation of the IDistributor interface. It calls the distributeERC20 function with the provided token and amount.

supportsInterface

The supportsInterface function checks if the contract supports the specified interface. In this case, it checks for the IDistributor interface.

Events


LogSetRecipients

The LogSetRecipients event is emitted when recipients are set or updated. It includes the list of recipient addresses.

LogSetrecipientBPS

The 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

The LogDistributeToken event is emitted when tokens are distributed to a recipient. It includes the token contract address, the recipient address, and the distributed amount.

Usage


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 setRecipientsAndBPS function.