Skip to main content

SuperTokenV1Library

Library for Token Centric Interface

The SuperTokenV1Library is a solidity library that allows you to interact with the Superfluid Protocol. It is a comprehensive library for Superfluid protocol. It includes all the functions that are required to interact with the Superfluid protocol. It includes functions for interacting with Money Streaming and Distributions. In order to have access to the library, you need to:

  • Import the library in your contract as such:

    import "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";

  • Make sure that you include the using statement in your contract:

    using SuperTokenV1Library for ISuperToken;

Note 1

In the case of interacting with Native Super Tokens you should use using SuperTokenV1Library for ISETH; instead.

Note 2

It is important to "warm up" the cache and cache the host, cfa, gda before calling, this is only applicable to Foundry tests where the vm.expectRevert() will not work as expected. You must use vm.startPrank(account) instead of vm.prank when executing functions if the cache isn't "warmed up" yet. vm.prank impersonates the account only for the first call, which will be used for caching.

Fn createFlow

function createFlow(
contract ISuperToken token,
address receiver,
int96 flowRate
)
internal
returns (bool)

Create flow without userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate

Fn createFlow

function createFlow(
contract ISuperToken token,
address receiver,
int96 flowRate,
bytes userData
)
internal
returns (bool)

Create flow with userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
userDatabytesThe userdata passed along with call

Fn updateFlow

function updateFlow(
contract ISuperToken token,
address receiver,
int96 flowRate
)
internal
returns (bool)

Update flow without userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate

Fn updateFlow (w/userData)

function updateFlow(
contract ISuperToken token,
address receiver,
int96 flowRate,
bytes userData
)
internal
returns (bool)

Update flow with userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
userDatabytesThe userdata passed along with call

Fn deleteFlow

function deleteFlow(
contract ISuperToken token,
address sender,
address receiver
)
internal
returns (bool)

Delete flow without userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow

Fn deleteFlow (w/userData)

function deleteFlow(
contract ISuperToken token,
address sender,
address receiver,
bytes userData
)
internal
returns (bool)

Delete flow with userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
userDatabytesThe userdata passed along with call

Fn setFlowPermissions

function setFlowPermissions(
contract ISuperToken token,
address flowOperator,
bool allowCreate,
bool allowUpdate,
bool allowDelete,
int96 flowRateAllowance
)
internal
returns (bool)

Update permissions for flow operator

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address given flow permissions
allowCreateboolcreation permissions
allowUpdatebool
allowDeletebool
flowRateAllowanceint96The allowance provided to flowOperator

Fn setMaxFlowPermissions

function setMaxFlowPermissions(
contract ISuperToken token,
address flowOperator
)
internal
returns (bool)

Update permissions for flow operator - give operator max permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address given flow permissions

Fn revokeFlowPermissions

function revokeFlowPermissions(
contract ISuperToken token,
address flowOperator
)
internal
returns (bool)

Update permissions for flow operator - revoke all permission

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address given flow permissions

Fn increaseFlowRateAllowance

function increaseFlowRateAllowance(
contract ISuperToken token,
address flowOperator,
int96 addedFlowRateAllowance
)
internal
returns (bool)

Increases the flow rate allowance for flow operator

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is increased
addedFlowRateAllowanceint96amount to increase allowance by

allowing userData to be a parameter here triggered stack too deep error

Fn increaseFlowRateAllowance (w/userData)

function increaseFlowRateAllowance(
contract ISuperToken token,
address flowOperator,
int96 addedFlowRateAllowance,
bytes userData
)
internal
returns (bool)

Increases the flow rate allowance for flow operator

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is increased
addedFlowRateAllowanceint96amount to increase allowance by
userDatabytesThe userdata passed along with call

allowing userData to be a parameter here triggered stack too deep error

Fn decreaseFlowRateAllowance

function decreaseFlowRateAllowance(
contract ISuperToken token,
address flowOperator,
int96 subtractedFlowRateAllowance
)
internal
returns (bool)

Decreases the flow rate allowance for flow operator

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is decreased
subtractedFlowRateAllowanceint96amount to decrease allowance by

allowing userData to be a parameter here triggered stack too deep error

Fn decreaseFlowRateAllowance (w/userData)

function decreaseFlowRateAllowance(
contract ISuperToken token,
address flowOperator,
int96 subtractedFlowRateAllowance,
bytes userData
)
internal
returns (bool)

Decreases the flow rate allowance for flow operator

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is decreased
subtractedFlowRateAllowanceint96amount to decrease allowance by
userDatabytesThe userdata passed along with call

allowing userData to be a parameter here triggered stack too deep error

Fn increaseFlowRateAllowanceWithPermissions

function increaseFlowRateAllowanceWithPermissions(
contract ISuperToken token,
address flowOperator,
uint8 permissionsToAdd,
int96 addedFlowRateAllowance
)
internal
returns (bool)

Increases the flow rate allowance for flow operator and adds the permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is increased
permissionsToAdduint8The permissions to add for the flow operator
addedFlowRateAllowanceint96amount to increase allowance by

allowing userData to be a parameter here triggered stack too deep error

Fn increaseFlowRateAllowanceWithPermissions (w/userData)

function increaseFlowRateAllowanceWithPermissions(
contract ISuperToken token,
address flowOperator,
uint8 permissionsToAdd,
int96 addedFlowRateAllowance,
bytes userData
)
internal
returns (bool)

Increases the flow rate allowance for flow operator and adds the permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is increased
permissionsToAdduint8The permissions to add for the flow operator
addedFlowRateAllowanceint96amount to increase allowance by
userDatabytesThe userdata passed along with call

allowing userData to be a parameter here triggered stack too deep error

Fn decreaseFlowRateAllowanceWithPermissions

function decreaseFlowRateAllowanceWithPermissions(
contract ISuperToken token,
address flowOperator,
uint8 permissionsToRemove,
int96 subtractedFlowRateAllowance
)
internal
returns (bool)

Decreases the flow rate allowance for flow operator and removes the permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is subtracted
permissionsToRemoveuint8The permissions to remove for the flow operator
subtractedFlowRateAllowanceint96amount to subtract allowance by

allowing userData to be a parameter here triggered stack too deep error

Fn decreaseFlowRateAllowanceWithPermissions (w/userData)

function decreaseFlowRateAllowanceWithPermissions(
contract ISuperToken token,
address flowOperator,
uint8 permissionsToRemove,
int96 subtractedFlowRateAllowance,
bytes userData
)
internal
returns (bool)

Decreases the flow rate allowance for flow operator and removes the permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address whose flow rate allowance is subtracted
permissionsToRemoveuint8The permissions to remove for the flow operator
subtractedFlowRateAllowanceint96amount to subtract allowance by
userDatabytesThe userdata passed along with call

allowing userData to be a parameter here triggered stack too deep error

Fn setFlowPermissionsWithCtx

function setFlowPermissionsWithCtx(
contract ISuperToken token,
address flowOperator,
bool allowCreate,
bool allowUpdate,
bool allowDelete,
int96 flowRateAllowance,
bytes ctx
)
internal
returns (bytes newCtx)

Update permissions for flow operator in callback

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address given flow permissions
allowCreateboolcreation permissions
allowUpdatebool
allowDeletebool
flowRateAllowanceint96The allowance provided to flowOperator
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

allowing userData to be a parameter here triggered stack too deep error

Fn setMaxFlowPermissionsWithCtx

function setMaxFlowPermissionsWithCtx(
contract ISuperToken token,
address flowOperator,
bytes ctx
)
internal
returns (bytes newCtx)

Update permissions for flow operator - give operator max permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address given flow permissions
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn revokeFlowPermissionsWithCtx

function revokeFlowPermissionsWithCtx(
contract ISuperToken token,
address flowOperator,
bytes ctx
)
internal
returns (bytes newCtx)

Update permissions for flow operator - revoke all permission

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowOperatoraddressThe address given flow permissions
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn createFlowFrom

function createFlowFrom(
contract ISuperToken token,
address sender,
address receiver,
int96 flowRate
)
internal
returns (bool)

Creates flow as an operator without userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate

Fn createFlowFrom (w/userData)

function createFlowFrom(
contract ISuperToken token,
address sender,
address receiver,
int96 flowRate,
bytes userData
)
internal
returns (bool)

Creates flow as an operator with userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
userDatabytesThe user provided data

Fn updateFlowFrom

function updateFlowFrom(
contract ISuperToken token,
address sender,
address receiver,
int96 flowRate
)
internal
returns (bool)

Updates flow as an operator without userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate

Fn updateFlowFrom (w/userData)

function updateFlowFrom(
contract ISuperToken token,
address sender,
address receiver,
int96 flowRate,
bytes userData
)
internal
returns (bool)

Updates flow as an operator with userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
userDatabytesThe user provided data

Fn deleteFlowFrom

function deleteFlowFrom(
contract ISuperToken token,
address sender,
address receiver
)
internal
returns (bool)

Deletes flow as an operator without userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow

Fn deleteFlowFrom (w/userData)

function deleteFlowFrom(
contract ISuperToken token,
address sender,
address receiver,
bytes userData
)
internal
returns (bool)

Deletes flow as an operator with userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
userDatabytesThe user provided data

Fn createFlowWithCtx

function createFlowWithCtx(
contract ISuperToken token,
address receiver,
int96 flowRate,
bytes ctx
)
internal
returns (bytes newCtx)

Create flow with context and userData

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn createFlowFromWithCtx

function createFlowFromWithCtx(
contract ISuperToken token,
address sender,
address receiver,
int96 flowRate,
bytes ctx
)
internal
returns (bytes newCtx)

Create flow by operator with context

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn updateFlowWithCtx

function updateFlowWithCtx(
contract ISuperToken token,
address receiver,
int96 flowRate,
bytes ctx
)
internal
returns (bytes newCtx)

Update flow with context

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn updateFlowFromWithCtx

function updateFlowFromWithCtx(
contract ISuperToken token,
address sender,
address receiver,
int96 flowRate,
bytes ctx
)
internal
returns (bytes newCtx)

Update flow by operator with context

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe receiver of the flow
receiveraddressThe receiver of the flow
flowRateint96The desired flowRate
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn deleteFlowWithCtx

function deleteFlowWithCtx(
contract ISuperToken token,
address sender,
address receiver,
bytes ctx
)
internal
returns (bytes newCtx)

Delete flow with context

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn deleteFlowFromWithCtx

function deleteFlowFromWithCtx(
contract ISuperToken token,
address sender,
address receiver,
bytes ctx
)
internal
returns (bytes newCtx)

Delete flow by operator with context

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token to flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn getFlowRate

function getFlowRate(
contract ISuperToken token,
address sender,
address receiver
)
internal
returns (int96 flowRate)

get flow rate between two accounts for given token

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow

Return Values

NameTypeDescription
flowRateint96The flow rate

Fn getFlowInfo

function getFlowInfo(
contract ISuperToken token,
address sender,
address receiver
)
internal
returns (uint256 lastUpdated, int96 flowRate, uint256 deposit, uint256 owedDeposit)

get flow info between two accounts for given token

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
senderaddressThe sender of the flow
receiveraddressThe receiver of the flow

Return Values

NameTypeDescription
lastUpdateduint256Timestamp of flow creation or last flowrate change
flowRateint96The flow rate
deposituint256The amount of deposit the flow
owedDeposituint256The amount of owed deposit of the flow

Fn getNetFlowRate

function getNetFlowRate(
contract ISuperToken token,
address account
)
internal
returns (int96 flowRate)

get net flow rate for given account for given token (CFA + GDA)

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token address
accountaddressAccount to query

Return Values

NameTypeDescription
flowRateint96The net flow rate of the account

Fn getCFANetFlowRate

function getCFANetFlowRate(
contract ISuperToken token,
address account
)
internal
returns (int96 flowRate)

get CFA net flow rate for given account for given token

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token address
accountaddressAccount to query

Return Values

NameTypeDescription
flowRateint96The net flow rate of the account

Fn getGDANetFlowRate

function getGDANetFlowRate(
contract ISuperToken token,
address account
)
internal
returns (int96 flowRate)

get GDA net flow rate for given account for given token

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token address
accountaddressAccount to query

Return Values

NameTypeDescription
flowRateint96The net flow rate of the account

Fn getNetFlowInfo

function getNetFlowInfo(
contract ISuperToken token,
address account
)
internal
returns (uint256 lastUpdated, int96 flowRate, uint256 deposit, uint256 owedDeposit)

get the aggregated flow info of the account

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token address
accountaddressAccount to query

Return Values

NameTypeDescription
lastUpdateduint256Timestamp of the last change of the net flow
flowRateint96The net flow rate of token for account
deposituint256The sum of all deposits for account's flows
owedDeposituint256The sum of all owed deposits for account's flows

Fn getBufferAmountByFlowRate

function getBufferAmountByFlowRate(
contract ISuperToken token,
int96 flowRate
)
internal
returns (uint256 bufferAmount)

calculate buffer for a flow rate

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
flowRateint96The flowrate to calculate the needed buffer for

Return Values

NameTypeDescription
bufferAmountuint256The buffer amount based on flowRate, liquidationPeriod and minimum deposit

Fn getFlowPermissions

function getFlowPermissions(
contract ISuperToken token,
address sender,
address flowOperator
)
internal
returns (bool allowCreate, bool allowUpdate, bool allowDelete, int96 flowRateAllowance)

get existing flow permissions

Parameters

NameTypeDescription
tokencontract ISuperTokenThe token used in flow
senderaddresssender of a flow
flowOperatoraddressthe address we are checking permissions of for sender & token

Return Values

NameTypeDescription
allowCreateboolis true if the flowOperator can create flows
allowUpdateboolis true if the flowOperator can update flows
allowDeleteboolis true if the flowOperator can delete flows
flowRateAllowanceint96The flow rate allowance the flowOperator is granted (only goes down)

Fn getIndex

function getIndex(
contract ISuperToken token,
address publisher,
uint32 indexId
)
internal
returns (bool exist, uint128 indexValue, uint128 totalUnitsApproved, uint128 totalUnitsPending)

Gets an index by its ID and publisher.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.

Return Values

NameTypeDescription
existboolTrue if the index exists.
indexValueuint128Total value of the index.
totalUnitsApproveduint128Units of the index approved by subscribers.
totalUnitsPendinguint128Units of teh index not yet approved by subscribers.

Fn calculateDistribution

function calculateDistribution(
contract ISuperToken token,
address publisher,
uint32 indexId,
uint256 amount
)
internal
returns (uint256 actualAmount, uint128 newIndexValue)

Calculates the distribution amount based on the amount of tokens desired to distribute.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
amountuint256Amount of tokens desired to distribute.

Return Values

NameTypeDescription
actualAmountuint256Amount to be distributed with correct rounding.
newIndexValueuint128The index value after the distribution would be called.

Fn listSubscriptions

function listSubscriptions(
contract ISuperToken token,
address subscriber
)
internal
returns (address[] publishers, uint32[] indexIds, uint128[] unitsList)

List all subscriptions of an address

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token used in the indexes listed.
subscriberaddressSubscriber address.

Return Values

NameTypeDescription
publishersaddress[]Publishers of the indices.
indexIdsuint32[]IDs of the indices.
unitsListuint128[]Units owned of the indices.

Fn getSubscription

function getSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber
)
internal
returns (bool exist, bool approved, uint128 units, uint256 pendingDistribution)

Gets subscription by publisher, index id, and subscriber.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber to the index.

Return Values

NameTypeDescription
existboolTrue if the subscription exists.
approvedboolTrue if the subscription has been approved by the subscriber.
unitsuint128Units held by the subscriber
pendingDistributionuint256If not approved, the amount to be claimed on approval.

Fn getSubscriptionByID

function getSubscriptionByID(
contract ISuperToken token,
bytes32 agreementId
)
internal
returns (address publisher, uint32 indexId, bool approved, uint128 units, uint256 pendingDistribution)

Parameters

NameTypeDescription
tokencontract ISuperToken
agreementIdbytes32

Fn getFlowDistributionFlowRate

function getFlowDistributionFlowRate(
contract ISuperToken token,
address from,
contract ISuperfluidPool to
)
internal
returns (int96)

Parameters

NameTypeDescription
tokencontract ISuperToken
fromaddress
tocontract ISuperfluidPool

GDA VIEW FUNCTIONS *************************************

Fn estimateFlowDistributionActualFlowRate

function estimateFlowDistributionActualFlowRate(
contract ISuperToken token,
address from,
contract ISuperfluidPool to,
int96 requestedFlowRate
)
internal
returns (int96 actualFlowRate, int96 totalDistributionFlowRate)

Parameters

NameTypeDescription
tokencontract ISuperToken
fromaddress
tocontract ISuperfluidPool
requestedFlowRateint96

Fn estimateDistributionActualAmount

function estimateDistributionActualAmount(
contract ISuperToken token,
address from,
contract ISuperfluidPool to,
uint256 requestedAmount
)
internal
returns (uint256 actualAmount)

Parameters

NameTypeDescription
tokencontract ISuperToken
fromaddress
tocontract ISuperfluidPool
requestedAmountuint256

Fn isMemberConnected

function isMemberConnected(
contract ISuperToken token,
address pool,
address member
)
internal
returns (bool)

Parameters

NameTypeDescription
tokencontract ISuperToken
pooladdress
memberaddress

Fn createIndex

function createIndex(
contract ISuperToken token,
uint32 indexId
)
internal
returns (bool)

Creates a new index.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.

Fn createIndex

function createIndex(
contract ISuperToken token,
uint32 indexId,
bytes userData
)
internal
returns (bool)

Creates a new index with userData.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
userDatabytesArbitrary user data field.

Fn updateIndexValue

function updateIndexValue(
contract ISuperToken token,
uint32 indexId,
uint128 indexValue
)
internal
returns (bool)

Updates an index value. This distributes an amount of tokens equal to indexValue - lastIndexValue. See distribute for another way to distribute.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
indexValueuint128New TOTAL index value, this will equal the total amount distributed.

Fn updateIndexValue

function updateIndexValue(
contract ISuperToken token,
uint32 indexId,
uint128 indexValue,
bytes userData
)
internal
returns (bool)

Updates an index value with userData. This distributes an amount of tokens equal to indexValue - lastIndexValue. See distribute for another way to distribute.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
indexValueuint128New TOTAL index value, this will equal the total amount distributed.
userDatabytesArbitrary user data field.

Fn distribute

function distribute(
contract ISuperToken token,
uint32 indexId,
uint256 amount
)
internal
returns (bool)

Distributes tokens in a more developer friendly way than updateIndex. Instead of passing the new total index value, you pass the amount of tokens desired to be distributed.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
amountuint256- total number of tokens desired to be distributed
NOTE in many cases, there can be some precision loss
This may cause a slight difference in the amount param specified and the actual amount distributed.
See below for math:
//indexDelta = amount the index will be updated by during an internal call to _updateIndex().
It is calculated like so:
indexDelta = amount / totalUnits
(see the distribute() implementatation in ./agreements/InstantDistributionAgreement.sol)
NOTE Solidity does not support floating point numbers
So the indexDelta will be rounded down to the nearest integer.
This will create a 'remainder' amount of tokens that will not be distributed
(we'll call this the 'distribution modulo')
distributionModulo = amount - indexDelta * totalUnits
NOTE due to rounding, there may be a small amount of tokens left in the publisher's account
This amount is equal to the 'distributionModulo' value
//

Fn distribute (w/userData)

function distribute(
contract ISuperToken token,
uint32 indexId,
uint256 amount,
bytes userData
)
internal
returns (bool)

Distributes tokens in a more developer friendly way than updateIndex (w user data). Instead of passing the new total index value, this function will increase the index value by amount. This takes arbitrary user data.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
amountuint256Amount by which the index value should increase.
userDatabytesArbitrary user data field.

Fn approveSubscription

function approveSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId
)
internal
returns (bool)

Approves a subscription to an index. The subscriber's real time balance will not update until the subscription is approved, but once approved, the balance will be updated with prior distributions.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.

Fn approveSubscription (w/userData)

function approveSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId,
bytes userData
)
internal
returns (bool)

Approves a subscription to an index with user data. The subscriber's real time balance will not update until the subscription is approved, but once approved, the balance will be updated with prior distributions.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
userDatabytesArbitrary user data field.

Fn revokeSubscription

function revokeSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId
)
internal
returns (bool)

Revokes a previously approved subscription.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.

Fn revokeSubscription (w/userData)

function revokeSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId,
bytes userData
)
internal
returns (bool)

Revokes a previously approved subscription. This takes arbitrary user data.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
userDatabytesArbitrary user data field.

Fn updateSubscriptionUnits

function updateSubscriptionUnits(
contract ISuperToken token,
uint32 indexId,
address subscriber,
uint128 units
)
internal
returns (bool)

Updates the units of a subscription. This changes the number of shares the subscriber holds

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address whose units are to be updated.
unitsuint128New number of units the subscriber holds.

Fn updateSubscriptionUnits (w/userData)

function updateSubscriptionUnits(
contract ISuperToken token,
uint32 indexId,
address subscriber,
uint128 units,
bytes userData
)
internal
returns (bool)

Updates the units of a subscription. This changes the number of shares the subscriber holds. This takes arbitrary user data.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address whose units are to be updated.
unitsuint128New number of units the subscriber holds.
userDatabytesArbitrary user data field.

Fn deleteSubscription

function deleteSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber
)
internal
returns (bool)

Deletes a subscription, setting a subcriber's units to zero

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address whose units are to be deleted.

Fn deleteSubscription (w/userData)

function deleteSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber,
bytes userData
)
internal
returns (bool)

Deletes a subscription, setting a subcriber's units to zero. This takes arbitrary userdata.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address whose units are to be deleted.
userDatabytesArbitrary user data field.

Fn claim

function claim(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber
)
internal
returns (bool)

Claims pending distribution. Subscription should not be approved

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address that receives the claim.

Fn claim (w/userData)

function claim(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber,
bytes userData
)
internal
returns (bool)

Claims pending distribution. Subscription should not be approved. This takes arbitrary user data.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address that receives the claim.
userDatabytesArbitrary user data field.

Fn createIndexWithCtx

function createIndexWithCtx(
contract ISuperToken token,
uint32 indexId,
bytes ctx
)
internal
returns (bytes newCtx)

Creates a new index with ctx. Meant for usage in super app callbacks

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn updateIndexValueWithCtx

function updateIndexValueWithCtx(
contract ISuperToken token,
uint32 indexId,
uint128 indexValue,
bytes ctx
)
internal
returns (bytes newCtx)

Updates an index value with ctx. This distributes an amount of tokens equal to indexValue - lastIndexValue. See distribute for another way to distribute. Meant for usage in super app callbakcs

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
indexValueuint128New TOTAL index value, this will equal the total amount distributed.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn distributeWithCtx

function distributeWithCtx(
contract ISuperToken token,
uint32 indexId,
uint256 amount,
bytes ctx
)
internal
returns (bytes newCtx)

Distributes tokens in a more developer friendly way than updateIndex.Instead of passing the new total index value, this function will increase the index value by amount.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
amountuint256Amount by which the index value should increase.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn approveSubscriptionWithCtx

function approveSubscriptionWithCtx(
contract ISuperToken token,
address publisher,
uint32 indexId,
bytes ctx
)
internal
returns (bytes newCtx)

Approves a subscription to an index. The subscriber's real time balance will not update until the subscription is approved, but once approved, the balance will be updated with prior distributions.

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn revokeSubscriptionWithCtx

function revokeSubscriptionWithCtx(
contract ISuperToken token,
address publisher,
uint32 indexId,
bytes ctx
)
internal
returns (bytes newCtx)

Revokes a previously approved subscription. Meant for usage in super apps

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn updateSubscriptionUnitsWithCtx

function updateSubscriptionUnitsWithCtx(
contract ISuperToken token,
uint32 indexId,
address subscriber,
uint128 units,
bytes ctx
)
internal
returns (bytes newCtx)

Updates the units of a subscription. This changes the number of shares the subscriber holds. Meant for usage in super apps

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address whose units are to be updated.
unitsuint128New number of units the subscriber holds.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn deleteSubscriptionWithCtx

function deleteSubscriptionWithCtx(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber,
bytes ctx
)
internal
returns (bytes newCtx)

Deletes a subscription, setting a subcriber's units to zero. Meant for usage in super apps

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address whose units are to be deleted.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn claimWithCtx

function claimWithCtx(
contract ISuperToken token,
address publisher,
uint32 indexId,
address subscriber,
bytes ctx
)
internal
returns (bytes newCtx)

Claims pending distribution. Subscription should not be approved. Meant for usage in super app callbacks

Parameters

NameTypeDescription
tokencontract ISuperTokenSuper Token used with the index.
publisheraddressPublisher of the index.
indexIduint32ID of the index.
subscriberaddressSubscriber address that receives the claim.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn createPool

function createPool(
contract ISuperToken token,
address admin,
struct PoolConfig poolConfig
)
internal
returns (contract ISuperfluidPool pool)

Creates a new Superfluid Pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
adminaddressThe pool admin address.
poolConfigstruct PoolConfigThe pool configuration (see below)

The PoolConfig struct is defined as follows:

struct PoolConfig {
bool transferabilityForUnitsOwner;
bool distributionFromAnyAddress;
}
  • transferabilityForUnitsOwner: If true, the pool members can transfer their owned units, else, only the pool admin can manipulate the units for pool members (not recommended)
  • distributionFromAnyAddress: If true, anyone can execute distributions via the pool, else, only the pool admin can execute distributions via the pool

Return Values

NameTypeDescription
poolcontract ISuperfluidPoolThe address of the deployed Superfluid Pool

Fn updateMemberUnits

function updateMemberUnits(
contract ISuperToken token,
contract ISuperfluidPool pool,
address memberAddress,
uint128 newUnits
)
internal
returns (bool)

Updates the units of a pool member.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to update.
memberAddressaddressThe address of the member to update.
newUnitsuint128The new units of the member.

Return Values

NameTypeDescription
[0]boolbool A boolean value indicating whether the pool was created successfully.

Fn updateMemberUnits (w/userData)

function updateMemberUnits(
contract ISuperToken token,
contract ISuperfluidPool pool,
address memberAddress,
uint128 newUnits,
bytes userData
)
internal
returns (bool)

Updates the units of a pool member.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to update.
memberAddressaddressThe address of the member to update.
newUnitsuint128The new units of the member.
userDatabytesUser-specific data.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the pool was created successfully.

Fn claimAll

function claimAll(
contract ISuperToken token,
contract ISuperfluidPool pool,
address memberAddress
)
internal
returns (bool)

Claims all tokens from the pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to claim from.
memberAddressaddressThe address of the member to claim for.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the claim was successful.

Fn claimAll (w/userData)

function claimAll(
contract ISuperToken token,
contract ISuperfluidPool pool,
address memberAddress,
bytes userData
)
internal
returns (bool)

Claims all tokens from the pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to claim from.
memberAddressaddressThe address of the member to claim for.
userDatabytesUser-specific data.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the claim was successful.

Fn connectPool

function connectPool(
contract ISuperToken token,
contract ISuperfluidPool pool
)
internal
returns (bool)

Connects a pool member to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to connect.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the connection was successful.

Fn connectPool (w/userData)

function connectPool(
contract ISuperToken token,
contract ISuperfluidPool pool,
bytes userData
)
internal
returns (bool)

Connects a pool member to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to connect.
userDatabytesUser-specific data.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the connection was successful.

Fn disconnectPool

function disconnectPool(
contract ISuperToken token,
contract ISuperfluidPool pool
)
internal
returns (bool)

Disconnects a pool member from pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to disconnect.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the disconnection was successful.

Fn disconnectPool (w/userData)

function disconnectPool(
contract ISuperToken token,
contract ISuperfluidPool pool,
bytes userData
)
internal
returns (bool)

Disconnects a pool member from pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to disconnect.
userDatabytesUser-specific data.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the disconnection was successful.

Fn distributeToPool

function distributeToPool(
contract ISuperToken token,
address from,
contract ISuperfluidPool pool,
uint256 requestedAmount
)
internal
returns (bool)

Tries to distribute requestedAmount amount of token from from to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
fromaddressThe address from which to distribute tokens.
poolcontract ISuperfluidPoolThe Superfluid Pool address.
requestedAmountuint256The amount of tokens to distribute.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the distribution was successful.

Fn distribute (w/userData)

function distribute(
contract ISuperToken token,
address from,
contract ISuperfluidPool pool,
uint256 requestedAmount,
bytes userData
)
internal
returns (bool)

Tries to distribute requestedAmount amount of token from from to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
fromaddressThe address from which to distribute tokens.
poolcontract ISuperfluidPoolThe Superfluid Pool address.
requestedAmountuint256The amount of tokens to distribute.
userDatabytesUser-specific data.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the distribution was successful.

Fn distributeFlow

function distributeFlow(
contract ISuperToken token,
address from,
contract ISuperfluidPool pool,
int96 requestedFlowRate
)
internal
returns (bool)

Tries to distribute flow at requestedFlowRate of token from from to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
fromaddressThe address from which to distribute tokens.
poolcontract ISuperfluidPoolThe Superfluid Pool address.
requestedFlowRateint96The flow rate of tokens to distribute.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the distribution was successful.

Fn distributeFlow (w/userData)

function distributeFlow(
contract ISuperToken token,
address from,
contract ISuperfluidPool pool,
int96 requestedFlowRate,
bytes userData
)
internal
returns (bool)

Tries to distribute flow at requestedFlowRate of token from from to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
fromaddressThe address from which to distribute tokens.
poolcontract ISuperfluidPoolThe Superfluid Pool address.
requestedFlowRateint96The flow rate of tokens to distribute.
userDatabytesUser-specific data.

Return Values

NameTypeDescription
[0]boolA boolean value indicating whether the distribution was successful.

Fn updateMemberUnitsWithCtx

function updateMemberUnitsWithCtx(
contract ISuperToken token,
contract ISuperfluidPool pool,
address memberAddress,
uint128 newUnits,
bytes ctx
)
internal
returns (bytes newCtx)

Updates the units of a pool member.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to update.
memberAddressaddressThe address of the member to update.
newUnitsuint128The new units of the member.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn claimAllWithCtx

function claimAllWithCtx(
contract ISuperToken token,
contract ISuperfluidPool pool,
address memberAddress,
bytes ctx
)
internal
returns (bytes newCtx)

Claims all tokens from the pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to claim from.
memberAddressaddressThe address of the member to claim for.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn connectPoolWithCtx

function connectPoolWithCtx(
contract ISuperToken token,
contract ISuperfluidPool pool,
bytes ctx
)
internal
returns (bytes newCtx)

Connects a pool member to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to connect.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn disconnectPoolWithCtx

function disconnectPoolWithCtx(
contract ISuperToken token,
contract ISuperfluidPool pool,
bytes ctx
)
internal
returns (bytes newCtx)

Disconnects a pool member from pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
poolcontract ISuperfluidPoolThe Superfluid Pool to disconnect.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn distributeWithCtx

function distributeWithCtx(
contract ISuperToken token,
address from,
contract ISuperfluidPool pool,
uint256 requestedAmount,
bytes ctx
)
internal
returns (bytes newCtx)

Tries to distribute requestedAmount amount of token from from to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
fromaddressThe address from which to distribute tokens.
poolcontract ISuperfluidPoolThe Superfluid Pool address.
requestedAmountuint256The amount of tokens to distribute.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function

Fn distributeFlowWithCtx

function distributeFlowWithCtx(
contract ISuperToken token,
address from,
contract ISuperfluidPool pool,
int96 requestedFlowRate,
bytes ctx
)
internal
returns (bytes newCtx)

Tries to distribute flow at requestedFlowRate of token from from to pool.

Parameters

NameTypeDescription
tokencontract ISuperTokenThe Super Token address.
fromaddressThe address from which to distribute tokens.
poolcontract ISuperfluidPoolThe Superfluid Pool address.
requestedFlowRateint96The flow rate of tokens to distribute.
ctxbytesContext bytes (see ISuperfluid.sol for Context struct)

Return Values

NameTypeDescription
newCtxbytesThe updated context after the execution of the agreement function