Our Implementation
We run a proxy in front of the sequencer that detects and discards transactions that should have paid royalties, but failed to. This ensures that if the royalty enforcement check returns false, the transaction will revert.
In short: if a transaction is an NFT sale, we will always validate that the proper royalties have been paid on-chain, else a revert takes place.
This opens up two questions, how do we define:
- An NFT Sale
- Proper royalty payment
Defining an NFT Sale
To begin, we can define an NFT sale as a transaction where:
- An NFT (ERC-721 or ERC-1155 token) is transferred from address “0xA” to address “0xB” AND
- ETH and/or ERC20 tokens are transferred from address “0xB”
We can leverage transaction logs to do this. Because the aforementioned transaction hook is triggered after the entirety of EVM transaction execution, we can be sure that the transaction logs are comprehensive.
1. We can detect an NFT transaction from either of these events:
From an ERC721 contract:
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
From an ERC1155 contract:
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value);
2. We can detect “payment” for the NFT if:
The recipient of the NFT successfully sends ERC20 tokens:
event Transfer(address indexed _from, address indexed _to, uint256 _value)
Or: the recipient of the NFT pays ETH (in other words, the NFT was successfully transferred to tx.from
, and tx.value
> 0)
From this information, we can determine the amount of royalties that must be paid, assuming the NFT contract follows the ERC-2981 (opens in a new tab) spec:
For each payment token used in the sale (ie ETH or ERC20s):
receiver, royaltyAmount = ERC2981(contractAddress).royaltyInfo(tokenId, tokensSent)
Finally, we can verify that receiver
has received at least royaltyAmount
for each ERC20 token using either event logs or (in the case of ETH) inspecting the internal transactions.
Royalty Scenarios
In practice, there are three unique royalty scenarios that can occur on RARI Chain based on the origin and current location of an NFT - each producing the following behaviors:
-
NFTs minted on + kept on RARI Chain:
- Royalties are set at the mint interface (e.g. rarible.com (opens in a new tab)), and are enforced appropriately on the sequencer level
-
NFTs minted elsewhere + bridged onto RARI Chain:
- They can be bridged, and have their royalties set on our chain through an associated marketplace (e.g. rarible.com (opens in a new tab)) or ERC2981-compliant interface
-
NFTs minted on + bridged out from RARI Chain:
- NFTs maintain their royalty parameters when bridged out, so these royalties will be acknowledged as long as they're being traded on a royalty-respecting platform.