Super Tokens

Hooks: A Powerful DeFi Building Block

On-chain hooks that react to Super Token events in real time. Get notified when streams are created, updated, or deleted — enabling composable, programmable financial logic on-chain.

How Hooks Work

When a user opens, updates, or closes a stream to an app with Superfluid Hooks, the Superfluid Host contract invokes hook functions on the app before and after the agreement state changes. This lets your contract automatically respond — for example, splitting an incoming stream across multiple recipients, or opening a counter-stream.

Hook Lifecycle

onFlowCreated

Triggered when a new stream is opened to your app. Open counter-streams, update state, or validate the sender.

onFlowUpdated

Called when an existing stream's flow rate changes. Receives both new and previous flow rate for proportional adjustments.

onFlowDeleted

Fired when a stream is closed. Must not revert — a reverting delete hook causes the app to be jailed.

Architecture

1

User calls Host

All stream operations go through the Superfluid Host contract via callAgreement() or batchCall().

2

Host invokes hooks

If the receiver is a registered Hook, the Host calls the app's before/after hooks with the Superfluid context.

3

App executes logic

Your hook can open new streams, distribute tokens, update state — all atomically within the same transaction.

4

Host validates rules

After execution, the Host checks that the app didn't violate any rules (e.g. the jailing rule for reverting deletes).

Building DeFi with Hooks

Hooks allow you to build DeFi applications that natively support money streams, distribution pools, and other Superfluid primitives. Instead of polling or relying on off-chain infrastructure, your smart contracts react automatically to every token event — enabling composable financial logic that was never possible with standard tokens.

Money Streams

React to streams being created, updated, or deleted. Split payments, gate access, or trigger swaps — all in real time, every second.

Distribution Pools

Distribute tokens to thousands of recipients in a single transaction. Proportional rewards, revenue sharing, and airdrops at constant gas cost.

Composable Logic

Chain hooks together to build complex financial applications. One stream event can trigger multiple downstream actions atomically.

Getting Started

Build your first Hook with the CFASuperAppBase contract and the SuperTokenV1Library.

MySuperApp.sol
contract MySuperApp is CFASuperAppBase {
    using SuperTokenV1Library for ISuperToken;

    function onFlowCreated(
        ISuperToken token,
        address sender,
        int96 flowRate,
        bytes calldata ctx
    ) internal override returns (bytes memory) {
        // Split incoming flow 50/50
        int96 half = flowRate / 2;
        ctx = token.createFlowWithCtx(
            recipientA, half, ctx
        );
        ctx = token.createFlowWithCtx(
            recipientB, half, ctx
        );
        return ctx;
    }
}

Register Your Hook

Built a Hook? Register it with the Superfluid ecosystem so it can be discovered and integrated by dashboards and partner applications.

Register Your App