Skip to main content

Money Streaming (SDK)

The ConstantFlowAgreementV1 class in the Superfluid SDK Core allows you to interact with the ConstantFlowAgreementV1 (for Money Streaming) smart contract. This guide will walk you through accessing and using this class either via the Framework class (sf.cfaV1) or as a standalone class.

Accessing the CFAv1 Contract

Using SDK Core Framework Object

To access the cfaV1 object and get a flow via the Framework class:

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider: /* Replace with your provider */
});

// Access the cfaV1 object and get a flow
const flowInfo = await sf.cfaV1.getFlow({
superToken: "0x...", // Replace with the Super Token address
sender: "0x...", // Replace with the sender's address
receiver: "0x...", // Replace with the receiver's address
providerOrSigner: /* Replace with provider or signer */
});

Direct Initialization

Alternatively, you can directly initialize the ConstantFlowAgreementV1 class:

import { ConstantFlowAgreementV1 } from "@superfluid-finance/sdk-core";

const hostAddress = "0x3E14dC1b13c488a8d5D310918780c983bD5982E7";
const cfaV1Address = "0x6EeE6060f715257b970700bc2656De21dEdF074C";
const cfaV1ForwarderAddress = "0xcfA132E353cB4E398080B9700609bb008eceB125";

const cfaV1 = new ConstantFlowAgreementV1(hostAddress, cfaV1Address, cfaV1ForwarderAddress);

// Get a flow via the standalone class
const flowInfo = await cfaV1.getFlow({
superToken: "0x...", // Replace with the Super Token address
sender: "0x...", // Replace with the sender's address
receiver: "0x...", // Replace with the receiver's address
providerOrSigner: /* Replace with provider or signer */
});

Methods

Read Methods

  • getFlow: Retrieves data on a stream between two accounts.
  • getNetFlow: Fetches the net flow rate of an account for a specific Super Token.
  • getSummedFlowData: Gathers summed flow data of an account for a specific Super Token.

Write Methods

Create, Update, Delete

  • createFlow: Initiates a stream from a sender to a chosen receiver.
  • updateFlow: Modifies an existing stream from a sender to a chosen receiver.
  • deleteFlow: Terminates an existing stream from a sender to a chosen receiver.

Create, Update, Delete with ACL Permissions

  • createFlowWithACL: Starts a stream between two accounts using ACL permissions.
  • updateFlowWithACL: Adjusts a stream between two accounts using ACL permissions.
  • deleteFlowWithACL: Removes a stream between two accounts using ACL permissions.

Manage ACL Permissions

  • setACLPermissions: Allows a sender to set the ACL permissions for another account.
  • revokeAllACLPermissions: Revokes all ACL permissions that an account has over the sender's account.

Example Usage

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const provider = new ethers.providers.InfuraProvider(
"matic",
"<INFURA_API_KEY>"
);

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider
});

const daix = await sf.loadSuperToken("DAIx");

// Read example
const flowInfo = await daix.getFlow({
sender: "0x...", // Replace with the sender's address
receiver: "0x...", // Replace with the receiver's address
providerOrSigner: provider
});
console.log("flowInfo", flowInfo);

// Write operation example
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });
const createFlowOperation = daix.createFlow({
sender: "0x...", // Replace with the sender's address
receiver: "0x...", // Replace with the receiver's address
flowRate: "1000000000" // Replace with the desired flow rate
});
const txnResponse = await createFlowOperation.exec(signer);
const txnReceipt = await txnResponse.wait();
// Transaction complete when code reaches here

This guide covers the essential methods and usage of the ConstantFlowAgreementV1 class within the Superfluid SDK Core. Replace placeholders with actual values specific to your project and use case.