@sfpro/sdk

CFA

CFA contract API reference for managing continuous payment streams

The Constant Flow Agreement (CFA) is the core agreement for creating and managing continuous payment streams in Superfluid. It enables real-time, per-second token transfers between accounts.

Overview

The CFA contract handles:

  • Creation, update, and deletion of payment streams
  • Flow rate calculations and accounting
  • ACL (Access Control List) permissions for operators
  • Real-time balance updates

Read Functions

getFlow

Returns flow information between a sender and receiver.

import { useReadCfa } from '@sfpro/sdk/hook/core';

const { data: flow } = useReadCfa({
  address: '0x...',
  functionName: 'getFlow',
  args: [token, sender, receiver],
});
import { cfaAbi } from '@sfpro/sdk/abi/core';

const flow = await client.readContract({
  address: '0x...',
  abi: cfaAbi,
  functionName: 'getFlow',
  args: [token, sender, receiver],
});
import { readCfa } from '@sfpro/sdk/action/core';

const flow = await readCfa(client, {
  address: '0x...',
  functionName: 'getFlow',
  args: [token, sender, receiver],
});

getNetFlow

Returns the net flow rate for an account (inflow - outflow).

getFlowByID

Returns flow information by its unique ID.

getFlowOperatorData

Returns operator permissions for a flow.

Write Functions

createFlow

Creates a new payment stream through the Host contract.

import { useWriteCfa } from '@sfpro/sdk/hook/core';

const { writeContract } = useWriteCfa();

await writeContract({
  address: '0x...',
  functionName: 'createFlow',
  args: [token, sender, receiver, flowRate, userData],
});
import { cfaAbi } from '@sfpro/sdk/abi/core';

// Note: CFA operations must be called through the Host contract
const callData = encodeFunctionData({
  abi: cfaAbi,
  functionName: 'createFlow',
  args: [token, receiver, flowRate, '0x'],
});
// Use the forwarder contract for direct calls
import { writeCfa } from '@sfpro/sdk/action/core';

const hash = await writeCfa(client, {
  address: '0x...',
  functionName: 'createFlow',
  args: [token, sender, receiver, flowRate, userData],
});

updateFlow

Updates the flow rate of an existing stream.

deleteFlow

Terminates a payment stream.

updateFlowOperatorPermissions

Grants or revokes operator permissions for managing flows.