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 π
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.).
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.
function getUnderlyingToken() external view returns(address tokenAddr);
function upgrade(uint256 amount) external;
function upgradeTo(address to, uint256 amount, bytes calldata data) external;
function downgrade(uint256 amount) external;
// approving
IERC20(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");