Pay & Claim Revenue
Learn how to pay an IP Asset and claim revenue in Solidity.
Completed Code
Follow the completed code all the way through.
This section demonstrates how to pay an IP Asset. There are a few reasons you would do this:
- You simply want to “tip” an IP
- You have to because your license terms with an ancestor IP require you to forward a certain % of payment
In either scenario, you would use the below payRoyaltyOnBehalf
function. When this happens, the Royalty Module automatically handles the different payment flows such that parent IP Assets who have negotiated a certain commercialRevShare
with the IPA being paid can claim their due share.
Prerequisites
There are a few steps you have to complete before you can start the tutorial.
- Complete the Setup Your Own Project
- Have a basic understanding of the Royalty Module
- A child IPA and a parent IPA, for which their license terms have a commercial revenue share to make this example work
Before We Start
You can pay an IP Asset using the payRoyaltyOnBehalf
function from the Royalty Module.
You will be paying the IP Asset with MockERC20. Usually you would pay with $WIP, but because we need to mint some tokens to test, we will use MockERC20.
To help with the following scenarios, let’s say we have a parent IP Asset that has negotiated a 50% commercialRevShare
with its child IP Asset.
Whitelisted Revenue Tokens
Only tokens that are whitelisted by our protocol can be used as payment (“revenue”) tokens. MockERC20 is one of those tokens. To see that list, go here.
Paying an IP Asset
We can pay an IP Asset like so:
This will send 10 $MERC20 to the childIpId
’s IP Royalty Vault. From there, the child can claim revenue. In the next section, you’ll see a working version of this.
Important: Approving the Royalty Module
Before you call payRoyaltyOnBehalf
, you have to approve the royalty module to spend the tokens for you. In the section below, you will see that we call MERC20.approve(address(ROYALTY_MODULE), 10);
or else it will not work.
Claim Revenue
When payments are made, they eventually end up in an IP Asset’s IP Royalty Vault. From here, they are claimed/transferred to whoever owns the Royalty Tokens associated with it, which represent a % of revenue share for a given IP Asset’s IP Royalty Vault.
The IP Account (the smart contract that represents the IP Asset) is what holds 100% of the Royalty Tokens when it’s first registered. So usually, it indeed holds most of the Royalty Tokens.
Let’s create a test file under test/5_Royalty.t.sol
to see it work and verify the results:
Contract Addresses
We have filled in the addresses from the Story contracts for you. However you can also find the addresses for them here: Deployed Smart Contracts
Test Your Code!
Run forge build
. If everything is successful, the command should successfully compile.
Now run the test by executing the following command:
Dispute an IP
Congratulations, you claimed revenue using the Royalty Module!
Completed Code
Follow the completed code all the way through.
Now what happens if an IP Asset doesn’t pay their due share? We can dispute the IP on-chain, which we will cover on the next page.