IDA - Solidity

The Super Token Library allows you to work with instant distributions in Solidity

SuperTokenV1Library Contract

Example Code & Guide

Simple contract showing usage of many IDA functions

Agreement Abstraction

The objective of the SuperTokenV1Library is to abstract the code required to call an agreement. Below is a comparative example of how an index might be created with and without the library.

Importing and Initialization

Basic Usage

Once this is initialized, we can use the library to create, read, update, and delete IDAv1 agreements as demonstrated in this createIndex example.

Callback Usage

To use this library inside of a Super App callback, you will need to use the equivalent function with WithCtx at the end of it. For example, instead of creating an index in a callback with createIndex, you should use createIndexWithCtx and return the result, newCtx, of type bytes memory.

API Specification

The following documents the library function's declaration along with the usage the function, assuming the InitData struct is named _idav1Lib.

Each function has four variants:

  1. First is the standard function shown in the Basic Usage section above.

  2. Second is an override of the standard usage to include arbitrary user data.

  3. Third is the WithCtx function shown in the Callback Usage section above.

  4. Fourth is an override of the WithCtx function to include arbitrary user data.

Note that each function below includes the "library function declaration". This is not necessary to write in your own code and is simply there for reference. The code following "usage" is what you would write in your own contract.

For more information on each parameter, please refer to the code comment documentation for each function in the library.

Create Index

Creates an index with a super token and an index id. The function caller is the publisher of the index.

Create Index with User Data

Create Index in a Super App Callback

Update Index Value

Updates the value of the index. This updates the real time balances of all approved subscribers in a single transaction. Notice that this is similar to distribute, except here you must specify the new total index value in the indexValue parameter. This fails if it is not greater than the last index value.

Update Index Value with User Data

Update Index Value in a Super App Callback

Update Index Value in a Super App Callback

Distribute

This function is functionally similar to updateIndexValue, but instead of having to specify the new indexValue, you can pass an amount by which the indexValue should be incremented. This is simply another way to distribute tokens.

Distribute with User Data

Distribute in a Super App Callback

Approve Subscription

Approves a subscription to an index. This is called by the subscriber to the index and can be called even before units are issued to the subscriber, though the index must at least exist first.

Approve Subscription with User Data

Approve Subscription in a Super App Callback

Revoke Subscription

Revokes a previously approved subscription. This is called by the subscriber.

Revoke Subscription with User Data

Revoke Subscription in a Super App Callback

Update Subscription Units

Updates the number of units, or "shares", of the index assigned to a subscriber. This is called by the publisher of the index.

Update Subscription Units with User Data

Update Subscription Units in a Super App Callback

Delete Subscription

Deletes an existing subscription, setting the subscriber's units to zero. This is called by the publsiher.

Delete Subscription with User Data

Delete Subscription in a Super App Callback

Claim

Claims a pending distribution of an index. This is called by the subscriber and updates their real time balance instantly.

Claim with User Data

Claim in a Super App Callback

Last updated

Was this helpful?