Super Tokens - Solidity

Interacting with Super Tokens in Solidity

Super Tokens have basic ERC20 functionality, some ERC777 functionality, and several functions to accommodate Superfluid Protocol functionality.

Super Token Contract

Super Token Interface

Remix Example Contract

An example contract that you can deploy to Goerli and use to experiment with Super Tokens in Solidity

Notice that the Super Token interface doesn't appear to show any Super Agreement functionality (i.e. there's no function in them that starts a stream or does a distribution). Why? Basically, Super Agreements are separate contracts! Computing your Super Token balance is a matter of netting the effects of each Super Agreement into your actual balance. This all happens when you view your balance with balanceOf. See this explained in our Super Token In-Depth Explainer,

Getting Set To Interact With Super Tokens

Import the Super Token interface in your .sol file.

ERC20 Functions

Super Tokens offer you all the basic ERC20 features. Learn more about these functions here on OpenZeppelin.

Interface

Example: Calling transfer

ERC20 Wrapping Functions

These are functions for Wrapper Super Tokens to implement such that you can wrap an underlying ERC20 token into and out of the Wrapper Super Token contract. See this quick explainer on Wrapper Super Tokens.

Interface

Example: Using upgrade to wrap tokens into Super Tokens

The upgrade function does the wrapping using transferFrom to pull the underlying ERC20 token from your wallet. As a result, before you can wrap your tokens into Super Tokens, you need to approve the Super Token contract to be able to spend your underlying ERC20.

Example: Calling upgradeTo

Usage of upgradeTo is rare but useful. It allows you to designate another address that will receive the upgraded tokens and call the tokensReceived implementation on it. Essentially, it combines the ERC777 send with plain upgrade.

Example: Using downgrade to unwrap Super Tokens

Unwrap your Super Tokens into the underlying ERC20 tokens.

ERC777 Functions

Super Tokens also have some ERC777 features. Learn more about these functions here on OpenZeppelin. Note that not all ERC777 functionality is available - read more below πŸ‘‡

ERC777 in Super Tokens

Interface

Native Asset Functions

These are functions that only Native Asset Super Tokens possess to allow wrapping and unwrapping of native assets (like MATIC or AVAX). While the interface is named ISETH.sol, it is used for all Native Assets Super Tokens (MATICx, AVAXx, etc.).

Import the ISETH Interface in Your .sol File.

Interface

Example - Wrapping a Native Asset

You can also wrap a native asset by simply transferring it to the appropriate Native Asset Super Token contract where a receive() function is implemented to handle the wrapping on receipt.

Full Super Token Interface

See our GitHub for full comments

Last updated

Was this helpful?