LogoLogo
  • ๐ŸŒŠSuperfluid
  • Protocol Overview
    • ๐Ÿ’กWhat is Superfluid?
    • ๐Ÿ“„In-Depth Overview
      • Super Tokens
      • Super Agreements
        • ๐ŸšฐMoney Streaming (CFA)
        • โœณ๏ธDistributions (IDA)
        • ๐ŸŒŠStreaming Distributions
      • Super Apps
      • Superfluid Host
    • ๐Ÿง Use Cases
      • Recurring Payments
      • DeFi
      • Social & Community
      • Gaming
    • ๐Ÿ“”Glossary of Terms
  • Developers
    • ๐ŸƒQuickstart
    • ๐Ÿช™Super Tokens
      • Super Tokens - Solidity
      • Super Tokens - SDK Core
      • Super Tokens - Frontend Examples
      • Types of Super Tokens
      • Deploy a Super Token
        • Deploying a Wrapper Super Token
        • Deploying a Self Governed Super Token
        • Deploying a Pure Super Token
      • In-Depth
        • Tracking Super Token Balances
        • ERC777 in Super Tokens
      • Test Super Token Faucet
    • ๐ŸŒŠMoney Streaming (CFA)
      • Solidity
        • Read Methods
          • getFlowInfo
          • getFlowRate
          • getNetFlowRate
        • Write Methods
          • createFlow
          • updateFlow
          • deleteFlow
          • With User Data
          • With Context
      • SDK Core
        • Read Methods
          • getFlow
          • getNetFlow
          • getAccountFlowInfo
        • Write Methods
          • createFlow
          • updateFlow
          • deleteFlow
      • Access Control List (ACL)
        • Solidity
          • createFlowFrom
          • updateFlowFrom
          • deleteFlowFrom
          • setFlowPermissions
          • setMaxFlowPermissions
          • revokeFlowPermissions
          • increaseFlowRateAllowanceWithPermissions
          • decreaseFlowRateAllowanceWithPermissions
          • getFlowPermissions
        • SDK Core
          • createFlowByOperator
          • updateFlowByOperator
          • deleteFlowByOperator
          • updateFlowOperatorPermissions
          • revokeFlowOperatorPermissions
          • increaseFlowRateAllowanceWithPermissions
          • getFlowOperatorData
      • Frontend Examples
      • More...
        • Flow Rate Time Frames
        • Building Batched Streams in Safe
        • Flow NFTs
    • โœณ๏ธDistributions (IDA)
      • IDA - Solidity
      • IDA - SDK Core
      • IDA - Frontend Examples
    • ๐Ÿค–Super Apps
      • Super Apps in Depth
      • Super App Callbacks
        • Calling Agreements In Super Apps
      • User Data
        • NFT Billboard Example
      • SuperAppBaseFlow
      • Super App Examples
      • Super App Deployment Guide
    • ๐ŸงบBatch Calls
      • Batch Calls - SDK Core
      • Batch Calls - Frontend Examples
    • โš™๏ธAutomations
      • Auto-Wrap
        • Dev Guide
      • Stream Scheduler
        • Dev Guide
      • Vesting Scheduler
        • Dev Guide
      • Stream Accounting API
        • Dev Guide
      • Automation Subgraphs
        • Stream Scheduler Subgraph
        • Vesting Scheduler Subgraph
        • Auto Wrap Subgraph
    • ๐Ÿ—๏ธIntegration Guides
      • For Your Integration: The Basics
        • Supporting Super Tokens
        • Supporting Money Streams
        • Supporting Instant Distributions
      • Gating with Superfluid Subscriptions & Guild.xyz
      • Displaying Token Balances
      • Useful Queries for Your Integration
        • Instant Distribution Events
        • Money Streaming Events
        • Super Token Events
        • Other Helpful Queries
      • Constructing Links to The Superfluid Dashboard
    • ๐Ÿ”Superfluid Subscriptions
      • Superfluid Checkout Widget
      • Implementing Subscriptions in your App
    • SDK Core General
      • Initialization
      • Functionality
      • Getting Data
      • Resolver
      • Reference Docs
    • Solidity General
      • Calling Super Agreements
      • Libraries
      • Resolver
    • Testing Guide
      • Hardhat Testing
      • Foundry Testing
      • In-Depth
        • Hardhat Mainnet Fork Testing
        • Super App Testing on Mainnet Forks
    • Subgraph
    • Reference
      • Deploying The Framework
      • EVM Contracts
      • SDK Redux
      • Superfluid Console
      • Superfluid Protocol Addresses
    • Contract Addresses
  • Sentinels
    • ๐Ÿฅ…Liquidations & TOGA
    • ๐Ÿค–Running a Sentinel
    • ๐Ÿ—บ๏ธSolvency Dashboard
  • Resources
    • ๐ŸŒŠSuperfluid Wave Pool
    • ๐Ÿ“œSuperfluid on Ethereum Mainnet
    • ๐Ÿ’ฐBounty Program
    • ๐Ÿ›ก๏ธSecurity & Bug Bounties
    • ๐Ÿ’กProject Ideas
    • ๐Ÿ—ณ๏ธToken Dashboard Submission
    • ๐ŸŽฅVideos
    • Superfluid Deployment Guide
    • Learn about Ethereum
    • Code of Conduct
Powered by GitBook
On this page
  • What is the SuperAppBaseFlow
  • SuperAppBaseFlow Simplifies Callbacks
  • Using the SuperAppBaseFlow
  • Import and Inherit
  • Constructor
  • Token Acceptance
  • Callback Functions

Was this helpful?

  1. Developers
  2. Super Apps

SuperAppBaseFlow

Making building Super Apps easier than ever

PreviousNFT Billboard ExampleNextSuper App Examples

Last updated 2 years ago

Was this helpful?

You may see the name "SuperAppBaseCFA" instead of SuperAppBaseFlow around our . We are in the process or renaming; eventually all mentions of SuperAppBaseCFA will be replaced with SuperAppBaseFlow.

What is the SuperAppBaseFlow

The SuperAppBaseFlow is an inheritable base contract that simplifies writing callbacks and abstracts away the redundancies of writing Super Apps. It can be used in lieu of the SuperAppBase.

SuperAppBaseFlow Code

Example Usage - Growing NFT Example Using SuperAppBaseFlow

SuperAppBaseFlow Simplifies Callbacks

The original SuperAppBase callback function headers are elaborate with unobvious parameter meanings. The SuperAppBaseFlow consolidates all callback development into 3 virtual functions (onFlowCreated, onFlowUpdated, onFlowDeleted) with much more readable parameters, making development easier for you.

Using the SuperAppBaseFlow

Import and Inherit

// Example Code
...
import { SuperAppBaseCFA } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperAppBaseFlow.sol";

contract SomeSuperAppContract is SuperAppBaseCFA {
...

Constructor

constructor(
    ISuperfluid host_,
    bool activateOnCreated,
    bool activateOnUpdated,
    bool activateOnDeleted
)

activateOnCreated - True if the Super App will implement onFlowCreated to react to the creation of streams to it. False otherwise.

activateOnUpdated - True if the Super App will implement onFlowUpdated to react to the updating of streams being sent to it. False otherwise.

activateOnDeleted - True if the Super App will implement onFlowDeleted to react to the deletion of streams being sent to it. False otherwise.

Token Acceptance

The SuperAppBaseFlow exposes a virtual isAcceptedSuperToken function, which can be overridden to specify streams of which Super Tokens the Super App's callbacks can react to.

You can forgo it and just use your own functions/modifiers/etc., but using isAcceptedSuperToken is the simplest and most convenient way to set up Super Token acceptance.

 /**
  * @dev Optional (positive) filter for accepting only specific SuperTokens.
  *      The default implementation accepts all SuperTokens.
  *      Can be overridden by the SuperApp in order to apply arbitrary filters.
  */
 function isAcceptedSuperToken(ISuperToken /*superToken*/) public view virtual returns (bool) {
     return true;
 }

Every Super App ought to have functionality to restrict which Super Tokens can trigger callbacks to protect against vulnerabilities from malicious custom Super Tokens.

Callback Functions

onFlowCreated

Override with custom logic that will trigger when a new flow to the Super App is created.

/// @dev override if the SuperApp shall have custom logic invoked when a new flow
///      to it is created.
function onFlowCreated(
    ISuperToken superToken,
    address sender,
    bytes calldata ctx
) internal virtual returns (bytes memory /*newCtx*/) {
    return ctx;
}
Parameter
Description

superToken

Super Token being streamed to the Super App

sender

Address streaming superToken to the Super App

ctx

Contains the context of the stream being modified to the Super App.

onFlowUpdated

Override with custom logic that will trigger when an existing flow to the Super App is updated.

/// @dev override if the SuperApp shall have custom logic invoked when an existing flow
///      to it is updated (flowrate change).
function onFlowUpdated(
    ISuperToken superToken,
    address sender,
    int96 previousFlowRate,
    uint256 lastUpdated,
    bytes calldata ctx
) internal virtual returns (bytes memory /*newCtx*/) {
    return ctx;
}
Parameter
Description

superToken

Super Token being streamed to the Super App

sender

Address streaming superToken to the Super App

previousFlowRate

The flow rate of the sender's stream to the Super App before the latest update.

lastUpdated

The timestamp of when a sender's stream to the Super App was last modified.

ctx

Contains the context of the stream being modified to the Super App.

onFlowDeleted

Override with custom logic that will trigger when an existing flow to the Super App is deleted.

/// @dev override if the SuperApp shall have custom logic invoked when an existing flow
///      to it is deleted (flow rate set to 0).
///      Unlike the other callbacks, this method is NOT allowed to revert.
///      Failing to satisfy that requirement leads to jailing (defunct SuperApp).
function onFlowDeleted(
    ISuperToken superToken,
    address sender,
    address receiver,
    int96 previousFlowRate,
    uint256 lastUpdated,
    bytes calldata ctx
) internal virtual returns (bytes memory /*newCtx*/) {
    return ctx;
}
Parameter
Description

superToken

Super Token being streamed to the Super App

sender

Address of the account streaming superToken to the Super App (or address of the account streaming superToken to the Super App if the Super App is deleting its own flow) *

receiver

Address of Super App (or address of Super App if Super App is deleting its own flow) *

previousFlowRate

The flow rate of the sender's stream to the Super App before the latest update.

lastUpdated

The timestamp of when a sender's stream to the Super App was last modified.

ctx

Contains the context of the stream being modified to the Super App.

* If a stream is being deleted by the account streaming to the Super App, sender is the streaming account and receiver is the Super App (obviously). However, if the Super App itself is deleting a flow it's receiving, then that triggers onFlowDeleted as well. In this case, it's flipped - sender is the Super App and receiver is the streaming account.

host_ - The address of the Superfluid Host for the network of choice. Find addresses .

The context gets updated when Super Agreement modifications are done in the callback body (). The context must be returned at the end of the callback.

The context gets updated when Super Agreement modifications are done in the callback body (). The context must be returned at the end of the callback.

IfonFlowDeleted ever reverts, your " causing its callbacks to no longer trigger in response to stream modifications. So, write youronFlowDeleted code such that it won't revert! Be careful with your logic and think about using try/catches where necessary.

The context gets updated when Super Agreement modifications are done in the callback body (). The context must be returned at the end of the callback.

๐Ÿค–
here
Example from Tradeable Cashflow Example Project
Example from Growing NFT Example Project
Example from Borrow Against Salary Example Project
learn more
learn more
learn more
super-examples repo
Super App will get "jailed
Example: onFlowCreated is a more intuitive function than afterAgreementCreated
super-examples/Flower.sol at c784d239557d6fb5e56a2c8951ac4353256d611d ยท superfluid-finance/super-examplesGitHub
protocol-monorepo/SuperAppBaseFlow.sol at dev ยท superfluid-finance/protocol-monorepoGitHub
Logo
Logo