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
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
transferERC20 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
upgrade to wrap tokens into Super TokensThe 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
upgradeToUsage 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
downgrade to unwrap Super TokensUnwrap 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 TokensInterface
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
Full Super Token Interface
See our GitHub for full comments
Last updated
Was this helpful?


