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;
In the case of interacting with Native Super Tokens you should use using SuperTokenV1Library for ISETH;
instead.
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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
Fn createFlow
function createFlow(
contract ISuperToken token,
address receiver,
int96 flowRate,
bytes userData
)
internal
returns (bool)
Create flow with userData
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
userData | bytes | The userdata passed along with call |
Fn updateFlow
function updateFlow(
contract ISuperToken token,
address receiver,
int96 flowRate
)
internal
returns (bool)
Update flow without userData
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
userData | bytes | The userdata passed along with call |
Fn deleteFlow
function deleteFlow(
contract ISuperToken token,
address sender,
address receiver
)
internal
returns (bool)
Delete flow without userData
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
sender | address | The sender of the flow |
receiver | address | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address given flow permissions |
allowCreate | bool | creation permissions |
allowUpdate | bool | |
allowDelete | bool | |
flowRateAllowance | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is increased |
addedFlowRateAllowance | int96 | amount 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is increased |
addedFlowRateAllowance | int96 | amount to increase allowance by |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is decreased |
subtractedFlowRateAllowance | int96 | amount 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is decreased |
subtractedFlowRateAllowance | int96 | amount to decrease allowance by |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is increased |
permissionsToAdd | uint8 | The permissions to add for the flow operator |
addedFlowRateAllowance | int96 | amount 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is increased |
permissionsToAdd | uint8 | The permissions to add for the flow operator |
addedFlowRateAllowance | int96 | amount to increase allowance by |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is subtracted |
permissionsToRemove | uint8 | The permissions to remove for the flow operator |
subtractedFlowRateAllowance | int96 | amount 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address whose flow rate allowance is subtracted |
permissionsToRemove | uint8 | The permissions to remove for the flow operator |
subtractedFlowRateAllowance | int96 | amount to subtract allowance by |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address given flow permissions |
allowCreate | bool | creation permissions |
allowUpdate | bool | |
allowDelete | bool | |
flowRateAllowance | int96 | The allowance provided to flowOperator |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address given flow permissions |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowOperator | address | The address given flow permissions |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
userData | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The receiver of the flow |
receiver | address | The receiver of the flow |
flowRate | int96 | The desired flowRate |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token to flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
Return Values
Name | Type | Description |
---|
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
sender | address | The sender of the flow |
receiver | address | The receiver of the flow |
Return Values
Name | Type | Description |
---|
lastUpdated | uint256 | Timestamp of flow creation or last flowrate change |
flowRate | int96 | The flow rate |
deposit | uint256 | The amount of deposit the flow |
owedDeposit | uint256 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token address |
account | address | Account to query |
Return Values
Name | Type | Description |
---|
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token address |
account | address | Account to query |
Return Values
Name | Type | Description |
---|
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token address |
account | address | Account to query |
Return Values
Name | Type | Description |
---|
flowRate | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token address |
account | address | Account to query |
Return Values
Name | Type | Description |
---|
lastUpdated | uint256 | Timestamp of the last change of the net flow |
flowRate | int96 | The net flow rate of token for account |
deposit | uint256 | The sum of all deposits for account's flows |
owedDeposit | uint256 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
flowRate | int96 | The flowrate to calculate the needed buffer for |
Return Values
Name | Type | Description |
---|
bufferAmount | uint256 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | The token used in flow |
sender | address | sender of a flow |
flowOperator | address | the address we are checking permissions of for sender & token |
Return Values
Name | Type | Description |
---|
allowCreate | bool | is true if the flowOperator can create flows |
allowUpdate | bool | is true if the flowOperator can update flows |
allowDelete | bool | is true if the flowOperator can delete flows |
flowRateAllowance | int96 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
Return Values
Name | Type | Description |
---|
exist | bool | True if the index exists. |
indexValue | uint128 | Total value of the index. |
totalUnitsApproved | uint128 | Units of the index approved by subscribers. |
totalUnitsPending | uint128 | Units 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
amount | uint256 | Amount of tokens desired to distribute. |
Return Values
Name | Type | Description |
---|
actualAmount | uint256 | Amount to be distributed with correct rounding. |
newIndexValue | uint128 | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token used in the indexes listed. |
subscriber | address | Subscriber address. |
Return Values
Name | Type | Description |
---|
publishers | address[] | Publishers of the indices. |
indexIds | uint32[] | IDs of the indices. |
unitsList | uint128[] | 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
Name | Type | Description |
---|
token | contract ISuperToken | Super token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber to the index. |
Return Values
Name | Type | Description |
---|
exist | bool | True if the subscription exists. |
approved | bool | True if the subscription has been approved by the subscriber. |
units | uint128 | Units held by the subscriber |
pendingDistribution | uint256 | If 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
Name | Type | Description |
---|
token | contract ISuperToken | |
agreementId | bytes32 | |
Fn getFlowDistributionFlowRate
function getFlowDistributionFlowRate(
contract ISuperToken token,
address from,
contract ISuperfluidPool to
)
internal
returns (int96)
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | |
from | address | |
to | contract 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
Name | Type | Description |
---|
token | contract ISuperToken | |
from | address | |
to | contract ISuperfluidPool | |
requestedFlowRate | int96 | |
Fn estimateDistributionActualAmount
function estimateDistributionActualAmount(
contract ISuperToken token,
address from,
contract ISuperfluidPool to,
uint256 requestedAmount
)
internal
returns (uint256 actualAmount)
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | |
from | address | |
to | contract ISuperfluidPool | |
requestedAmount | uint256 | |
Fn isMemberConnected
function isMemberConnected(
contract ISuperToken token,
address pool,
address member
)
internal
returns (bool)
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | |
pool | address | |
member | address | |
Fn createIndex
function createIndex(
contract ISuperToken token,
uint32 indexId
)
internal
returns (bool)
Creates a new index.
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
Fn createIndex
function createIndex(
contract ISuperToken token,
uint32 indexId,
bytes userData
)
internal
returns (bool)
Creates a new index with userData.
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
indexValue | uint128 | New 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
indexValue | uint128 | New TOTAL index value, this will equal the total amount distributed. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
amount | uint256 | - 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
amount | uint256 | Amount by which the index value should increase. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
userData | bytes | Arbitrary user data field. |
Fn revokeSubscription
function revokeSubscription(
contract ISuperToken token,
address publisher,
uint32 indexId
)
internal
returns (bool)
Revokes a previously approved subscription.
Parameters
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber address whose units are to be updated. |
units | uint128 | New 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber address whose units are to be updated. |
units | uint128 | New number of units the subscriber holds. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber address whose units are to be deleted. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber address that receives the claim. |
userData | bytes | Arbitrary 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
indexValue | uint128 | New TOTAL index value, this will equal the total amount distributed. |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
amount | uint256 | Amount by which the index value should increase. |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
publisher | address | Publisher of the index. |
indexId | uint32 | ID of the index. |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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
Name | Type | Description |
---|
token | contract ISuperToken | Super Token used with the index. |
indexId | uint32 | ID of the index. |
subscriber | address | Subscriber address whose units are to be updated. |
units | uint128 | New number of units the subscriber holds. |
ctx | bytes | Context bytes (see ISuperfluid.sol for Context struct) |
Return Values
Name | Type | Description |
---|
newCtx | bytes | The 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