Interact On-Chain
This guide delves into the specifics of Superfluid's smart contract functions, offering step-by-step guidance and practical insights for developers looking to integrate Superfluid Money Streaming into their applications.
Building on top of the Superfluid's Money Streaming involves interacting with Super Tokens. Remember, Superfluid is a token-centric protocol, and all of the primitives are centered around Super Tokens.
When interacting with Super Tokens on-chain, you can use the Superfluid's SuperTokenV1Library to access the core functions.
Direct Interaction Functions
Read functions
These functions from the SuperTokenV1Library allow direct interactions with Super Tokens, providing real-time information about ongoing flows.
- getFlowInfo
- getFlowRate
- getNetFlowRate
function getFlowInfo(ISuperToken token, address sender, address receiver)
internal view
returns(uint256 lastUpdated, int96 flowRate, uint256 deposit, uint256 owedDeposit)
Usage: Retrieve flow information, such as the rate and deposit details, between two accounts for a given Super Token. Useful for tracking and auditing ongoing streams.
function getFlowRate(ISuperToken token, address sender, address receiver)
internal view returns(int96 flowRate)
Usage: Use this function to quickly check the current flow rate between two accounts. Ideal for applications that need to display or make calculations based on live flow rates.
function getNetFlowRate(ISuperToken token, address account)
internal view returns (int96 flowRate)
Usage: Determine the net flow rate (inflow minus outflow) of a specific account. Essential for balancing and solvability assessment.
Write functions
These functions allow direct interactions with Super Tokens, providing real-time information about ongoing flows.
- createFlow
- updateFlow
- deleteFlow
function createFlow(ISuperToken token, address receiver, int96 flowRate)
internal returns (bool)
Usage: Create a flow to a receiver while specifying a flowRate.
function updateFlow(ISuperToken token, address receiver, int96 flowRate)
internal returns (bool)
Usage: Update the flow of a receiver.
function deleteFlow(ISuperToken token, address sender, address receiver)
internal returns (bool)
Usage: Delete a flow from a sender to a receiver.
Check our specific guide for Create, Update, and Delete Flow Functions for more details on these functions.
Functions with User Data and Context
User Data Overload
These advanced functions allow passing additional userData
for custom operations.
// Same function call just with additional parameter for user data
token.createFlow(address receiver, int96 flowRate, bytes memory userData);
token.updateFlow(address receiver, int96 flowRate, bytes memory userData);
token.deleteFlow(address sender, address receiver, bytes memory userData);
Usage: Attach custom userData
to your flow transactions. This feature is crucial for applications that require additional data to be transmitted or stored with each flow operation.
Context in Super App Callbacks
These functions allow passing additional ctx
for custom operations related to Super App callbacks.
function onFlowCreated(ISuperToken superToken, address sender, bytes calldata ctx)
internal override returns (bytes memory /*newCtx*/) {
// ... callback logic
}
Usage: In Super App callbacks, use context (ctx
) to manage state throughout the flow lifecycle. This is particularly important for apps that react to flow creations, updates, or deletions.
Access Control List Functions
The Access Control List (ACL) in Superfluid allows any account (either an external account or a smart contract) to configure permissions for another account to manage streams on its behalf. It's akin to the money streaming version of the ERC20 approval mechanism. For more details, check our ACL guide.
- setFlowPermissions
- setMaxFlowPermissions
- revokeFlowPermissions
setFlowPermissions
function setFlowPermissions(
ISuperToken token,
address flowOperator,
bool allowCreate,
bool allowUpdate,
bool allowDelete,
int96 flowRateAllowance
) internal returns (bool)
Usage: Grant specific flow permissions to an operator. This function is key for delegating flow management responsibilities, similar to setting allowances in ERC20 tokens.
setMaxFlowPermissions
function setMaxFlowPermissions(
ISuperToken token,
address flowOperator
) internal returns (bool)
Usage: Quickly grant an operator maximum permissions over your Super Token flows. Ideal for trusted operators where maximum flexibility is required.
revokeFlowPermissions
function revokeFlowPermissions(
ISuperToken token,
address flowOperator
) internal returns (bool)
Usage: Use this function to revoke previously granted permissions, enhancing security and control over your Super Token flows.