Library for Token Centric Interface
The SuperTokenV1Library is a solidity library that allows you to interact with the Tagomi Protocol. It is a comprehensive library for Tagomi protocol. It includes all the functions that are required to interact with the Tagomi 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 "@Tagomi-finance/bsc-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.
Copy function createFlow(
contract ISuperToken token,
address receiver,
int96 flowRate
)
internal
returns (bool) Create flow without userData
Parameters arrow-up-right
Create flow with userData
Parameters arrow-up-right
The userdata passed along with call
Update flow without userData
Parameters arrow-up-right
Update flow with userData
Parameters arrow-up-right
The userdata passed along with call
Delete flow without userData
Parameters arrow-up-right
Delete flow with userData
Parameters arrow-up-right
The userdata passed along with call
Update permissions for flow operator
Parameters arrow-up-right
The address given flow permissions
The allowance provided to flowOperator
Update permissions for flow operator - give operator max permissions
Parameters arrow-up-right
The address given flow permissions
Update permissions for flow operator - revoke all permission
Parameters arrow-up-right
The address given flow permissions
Increases the flow rate allowance for flow operator
Parameters arrow-up-right
The address whose flow rate allowance is increased
amount to increase allowance by
allowing userData to be a parameter here triggered stack too deep error
Increases the flow rate allowance for flow operator
Parameters arrow-up-right
The address whose flow rate allowance is increased
amount to increase allowance by
The userdata passed along with call
allowing userData to be a parameter here triggered stack too deep error
Decreases the flow rate allowance for flow operator
Parameters arrow-up-right
The address whose flow rate allowance is decreased
subtractedFlowRateAllowance
amount to decrease allowance by
allowing userData to be a parameter here triggered stack too deep error
Decreases the flow rate allowance for flow operator
Parameters arrow-up-right
The address whose flow rate allowance is decreased
subtractedFlowRateAllowance
amount to decrease allowance by
The userdata passed along with call
allowing userData to be a parameter here triggered stack too deep error
Increases the flow rate allowance for flow operator and adds the permissions
Parameters arrow-up-right
The address whose flow rate allowance is increased
The permissions to add for the flow operator
amount to increase allowance by
allowing userData to be a parameter here triggered stack too deep error
Fn increaseFlowRateAllowanceWithPermissions (w/userData)
arrow-up-right Increases the flow rate allowance for flow operator and adds the permissions
Parameters arrow-up-right
The address whose flow rate allowance is increased
The permissions to add for the flow operator
amount to increase allowance by
The userdata passed along with call
allowing userData to be a parameter here triggered stack too deep error
Decreases the flow rate allowance for flow operator and removes the permissions
Parameters arrow-up-right
The address whose flow rate allowance is subtracted
The permissions to remove for the flow operator
subtractedFlowRateAllowance
amount to subtract allowance by
allowing userData to be a parameter here triggered stack too deep error
Fn decreaseFlowRateAllowanceWithPermissions (w/userData)
arrow-up-right Decreases the flow rate allowance for flow operator and removes the permissions
Parameters arrow-up-right
The address whose flow rate allowance is subtracted
The permissions to remove for the flow operator
subtractedFlowRateAllowance
amount to subtract allowance by
The userdata passed along with call
allowing userData to be a parameter here triggered stack too deep error
Update permissions for flow operator in callback
Parameters arrow-up-right
The address given flow permissions
The allowance provided to flowOperator
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
allowing userData to be a parameter here triggered stack too deep error
Update permissions for flow operator - give operator max permissions
Parameters arrow-up-right
The address given flow permissions
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Update permissions for flow operator - revoke all permission
Parameters arrow-up-right
The address given flow permissions
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Creates flow as an operator without userData
Parameters arrow-up-right
Creates flow as an operator with userData
Parameters arrow-up-right
Updates flow as an operator without userData
Parameters arrow-up-right
Updates flow as an operator with userData
Parameters arrow-up-right
Deletes flow as an operator without userData
Parameters arrow-up-right
Deletes flow as an operator with userData
Parameters arrow-up-right
Create flow with context and userData
Parameters arrow-up-right
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Create flow by operator with context
Parameters arrow-up-right
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Update flow with context
Parameters arrow-up-right
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Update flow by operator with context
Parameters arrow-up-right
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Delete flow with context
Parameters arrow-up-right
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Delete flow by operator with context
Parameters arrow-up-right
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
get flow rate between two accounts for given token
Parameters arrow-up-right
Return Values arrow-up-right
get flow info between two accounts for given token
Parameters arrow-up-right
Return Values arrow-up-right
Timestamp of flow creation or last flowrate change
The amount of deposit the flow
The amount of owed deposit of the flow
get net flow rate for given account for given token (CFA + GDA)
Parameters arrow-up-right
Return Values arrow-up-right
The net flow rate of the account
get CFA net flow rate for given account for given token
Parameters arrow-up-right
Return Values arrow-up-right
The net flow rate of the account
get GDA net flow rate for given account for given token
Parameters arrow-up-right
Return Values arrow-up-right
The net flow rate of the account
get the aggregated flow info of the account
Parameters arrow-up-right
Return Values arrow-up-right
Timestamp of the last change of the net flow
The net flow rate of token for account
The sum of all deposits for account's flows
The sum of all owed deposits for account's flows
calculate buffer for a flow rate
Parameters arrow-up-right
The flowrate to calculate the needed buffer for
Return Values arrow-up-right
The buffer amount based on flowRate, liquidationPeriod and minimum deposit
get existing flow permissions
Parameters arrow-up-right
the address we are checking permissions of for sender & token
Return Values arrow-up-right
is true if the flowOperator can create flows
is true if the flowOperator can update flows
is true if the flowOperator can delete flows
The flow rate allowance the flowOperator is granted (only goes down)
Gets an index by its ID and publisher.
Parameters arrow-up-right
Super token used with the index.
Return Values arrow-up-right
True if the index exists.
Total value of the index.
Units of the index approved by subscribers.
Units of teh index not yet approved by subscribers.
Calculates the distribution amount based on the amount of tokens desired to distribute.
Parameters arrow-up-right
Super token used with the index.
Amount of tokens desired to distribute.
Return Values arrow-up-right
Amount to be distributed with correct rounding.
The index value after the distribution would be called.
List all subscriptions of an address
Parameters arrow-up-right
Super token used in the indexes listed.
Return Values arrow-up-right
Publishers of the indices.
Units owned of the indices.
Gets subscription by publisher, index id, and subscriber.
Parameters arrow-up-right
Super token used with the index.
Return Values arrow-up-right
True if the subscription exists.
True if the subscription has been approved by the subscriber.
Units held by the subscriber
If not approved, the amount to be claimed on approval.
Parameters arrow-up-right
Parameters arrow-up-right
GDA VIEW FUNCTIONS *************************************
Parameters arrow-up-right
Parameters arrow-up-right
Parameters arrow-up-right
Creates a new index.
Parameters arrow-up-right
Super Token used with the index.
Creates a new index with userData.
Parameters arrow-up-right
Super Token used with the index.
Arbitrary user data field.
Updates an index value. This distributes an amount of tokens equal to indexValue - lastIndexValue . See distribute for another way to distribute.
Parameters arrow-up-right
Super Token used with the index.
New TOTAL index value, this will equal the total amount distributed.
Updates an index value with userData. This distributes an amount of tokens equal to indexValue - lastIndexValue . See distribute for another way to distribute.
Parameters arrow-up-right
Super Token used with the index.
New TOTAL index value, this will equal the total amount distributed.
Arbitrary user data field.
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 arrow-up-right
Super Token used with the index.
- 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.
//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
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 arrow-up-right
Super Token used with the index.
Amount by which the index value should increase.
Arbitrary user data field.
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 arrow-up-right
Super Token used with the index.
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 arrow-up-right
Super Token used with the index.
Arbitrary user data field.
Revokes a previously approved subscription.
Parameters arrow-up-right
Super Token used with the index.
Revokes a previously approved subscription. This takes arbitrary user data.
Parameters arrow-up-right
Super Token used with the index.
Arbitrary user data field.
Updates the units of a subscription. This changes the number of shares the subscriber holds
Parameters arrow-up-right
Super Token used with the index.
Subscriber address whose units are to be updated.
New number of units the subscriber holds.
Updates the units of a subscription. This changes the number of shares the subscriber holds. This takes arbitrary user data.
Parameters arrow-up-right
Super Token used with the index.
Subscriber address whose units are to be updated.
New number of units the subscriber holds.
Arbitrary user data field.
Deletes a subscription, setting a subcriber's units to zero
Parameters arrow-up-right
Super Token used with the index.
Subscriber address whose units are to be deleted.
Deletes a subscription, setting a subcriber's units to zero. This takes arbitrary userdata.
Parameters arrow-up-right
Super Token used with the index.
Subscriber address whose units are to be deleted.
Arbitrary user data field.
Claims pending distribution. Subscription should not be approved
Parameters arrow-up-right
Super Token used with the index.
Subscriber address that receives the claim.
Claims pending distribution. Subscription should not be approved. This takes arbitrary user data.
Parameters arrow-up-right
Super Token used with the index.
Subscriber address that receives the claim.
Arbitrary user data field.
Creates a new index with ctx. Meant for usage in super app callbacks
Parameters arrow-up-right
Super Token used with the index.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
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 arrow-up-right
Super Token used with the index.
New TOTAL index value, this will equal the total amount distributed.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
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 arrow-up-right
Super Token used with the index.
Amount by which the index value should increase.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
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 arrow-up-right
Super Token used with the index.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Revokes a previously approved subscription. Meant for usage in super apps
Parameters arrow-up-right
Super Token used with the index.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Updates the units of a subscription. This changes the number of shares the subscriber holds. Meant for usage in super apps
Parameters arrow-up-right
Super Token used with the index.
Subscriber address whose units are to be updated.
New number of units the subscriber holds.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Deletes a subscription, setting a subcriber's units to zero. Meant for usage in super apps
Parameters arrow-up-right
Super Token used with the index.
Subscriber address whose units are to be deleted.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Claims pending distribution. Subscription should not be approved. Meant for usage in super app callbacks
Parameters arrow-up-right
Super Token used with the index.
Subscriber address that receives the claim.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Creates a new Tagomi Pool.
Parameters arrow-up-right
The pool configuration (see below)
The PoolConfig struct is defined as follows:
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 arrow-up-right
The address of the deployed Tagomi Pool
Updates the units of a pool member.
Parameters arrow-up-right
The Tagomi Pool to update.
The address of the member to update.
The new units of the member.
Return Values arrow-up-right
bool A boolean value indicating whether the pool was created successfully.
Updates the units of a pool member.
Parameters arrow-up-right
The Tagomi Pool to update.
The address of the member to update.
The new units of the member.
Return Values arrow-up-right
A boolean value indicating whether the pool was created successfully.
Claims all tokens from the pool.
Parameters arrow-up-right
The Tagomi Pool to claim from.
The address of the member to claim for.
Return Values arrow-up-right
A boolean value indicating whether the claim was successful.
Claims all tokens from the pool.
Parameters arrow-up-right
The Tagomi Pool to claim from.
The address of the member to claim for.
Return Values arrow-up-right
A boolean value indicating whether the claim was successful.
Connects a pool member to pool .
Parameters arrow-up-right
The Tagomi Pool to connect.
Return Values arrow-up-right
A boolean value indicating whether the connection was successful.
Connects a pool member to pool .
Parameters arrow-up-right
The Tagomi Pool to connect.
Return Values arrow-up-right
A boolean value indicating whether the connection was successful.
Disconnects a pool member from pool .
Parameters arrow-up-right
The Tagomi Pool to disconnect.
Return Values arrow-up-right
A boolean value indicating whether the disconnection was successful.
Disconnects a pool member from pool .
Parameters arrow-up-right
The Tagomi Pool to disconnect.
Return Values arrow-up-right
A boolean value indicating whether the disconnection was successful.
Tries to distribute requestedAmount amount of token from from to pool .
Parameters arrow-up-right
The address from which to distribute tokens.
The amount of tokens to distribute.
Return Values arrow-up-right
A boolean value indicating whether the distribution was successful.
Tries to distribute requestedAmount amount of token from from to pool .
Parameters arrow-up-right
The address from which to distribute tokens.
The amount of tokens to distribute.
Return Values arrow-up-right
A boolean value indicating whether the distribution was successful.
Tries to distribute flow at requestedFlowRate of token from from to pool .
Parameters arrow-up-right
The address from which to distribute tokens.
The flow rate of tokens to distribute.
Return Values arrow-up-right
A boolean value indicating whether the distribution was successful.
Tries to distribute flow at requestedFlowRate of token from from to pool .
Parameters arrow-up-right
The address from which to distribute tokens.
The flow rate of tokens to distribute.
Return Values arrow-up-right
A boolean value indicating whether the distribution was successful.
Updates the units of a pool member.
Parameters arrow-up-right
The Tagomi Pool to update.
The address of the member to update.
The new units of the member.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Claims all tokens from the pool.
Parameters arrow-up-right
The Tagomi Pool to claim from.
The address of the member to claim for.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Connects a pool member to pool .
Parameters arrow-up-right
The Tagomi Pool to connect.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Disconnects a pool member from pool .
Parameters arrow-up-right
The STagomi Pool to disconnect.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Tries to distribute requestedAmount amount of token from from to pool .
Parameters arrow-up-right
The address from which to distribute tokens.
The amount of tokens to distribute.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function
Tries to distribute flow at requestedFlowRate of token from from to pool .
Parameters arrow-up-right
The address from which to distribute tokens.
The flow rate of tokens to distribute.
Context bytes (see ITagomi.sol for Context struct)
Return Values arrow-up-right
The updated context after the execution of the agreement function