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.
import { ISuperToken } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperToken.sol";
ERC20 Functions
Super Tokens offer you all the basic ERC20 features. Learn more about these functions here on OpenZeppelin.
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.
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.
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.
// approvingIERC20(underlyingTokenAddress).approve(superTokenAddress, amountToWrap)// using upgradeTo (use "0x" for calldata if you don't want to pass in anything)ISuperToken(superTokenAddress).upgradeTo(receiverAddress, amountToWrap,"0x");
Example: Using downgrade to unwrap Super Tokens
Unwrap your Super Tokens into the underlying ERC20 tokens.
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 ๐
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.).
ISETH(superTokenAddress).{ value : amountToUpgrade }.upgradeByETH()
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.