Building Programmable Cashflows
Super Apps allow us to build smart contracts that are fully integrated with Superfluid at the protocol level.
The Tradeable Cashflow NFT
For example, the tradeable cashflow NFT contract receives a stream, and then uses special callbacks within the SuperApp to automatically open up a new stream from the NFT to the owner of the NFT.
The contract 'listens' for a call to a Superfluid super agreement contract (in this example, the Constant Flow Agreement contract), and runs a single callback function in response to the following 3 actions:
- 1.A flow is opened with the Super App as the
- 2.A flow is updated which has the Super App as the
- 3.A flow is closed by the Super App's counter party (i.e. if either the sender of a flow into the Super app or the recipient of a flow from the Super App deleted the flow, a callback will be run). As of today, this is only relevant for the case of canceled flows.
When a stream is created into a Super App, the
afterAgreementCreatedcallback may be run. These callbacks can execute any arbitrary logic, as long as this logic fits within the rules of standard smart contract development and the rules of Super Apps (which are explained further later on in this section).
In the case of the tradable cashflow contract, the logic we include inside of the
afterAgreementCreatedcallback will open up a money stream from the app to the NFT's owner in an amount that is equal to the
flowRateinto the app.
Super Apps like the tradable cashflow example keep their callback logic simple, while others get more advanced and leverage items like
userDatafor additional functionality.
Some of the most interesting projects in our ecosystem, such as Ricochet Exchange, make heavy use of Super App callbacks.