ERC777 in Super Tokens
ERC777 is a token standard that extends the existing ERC20 standard to allow send/receive hooks as well as operator accounts.
ERC777 tokens allow senders and recipients to define hooks which enact custom logic upon the sending or receiving of the ERC777 token.
There are two hooks -
tokensToSendis implemented by the sending account
tokensReceivedis implemented by the receiving account.
sendon the ERC777 token is called to move tokens between accounts, the code in these hooks kick in.
You could imagine
tokensToSendcontaining logic that handles what to do when tokens are sent and
tokensReceivedcontaining logic handling what to do when tokens are received.
An account may set operator accounts using the
authorizeOperatorfunction. Operators are able to call the
operatorSendfunction to move tokens on behalf of an account. In doing so, they trigger the
tokensReceivedhooks just like a normal send from a non-operator account.
This is in contrast to how with ERC20 tokens we can give any account an allowance with
approveand that account can use
transferFromto move tokens on your behalf up until a set allowance. An ERC777 operator is able to use
operatorSendto move as many tokens as it sees fit with custom logic set in the
Note that the ability to use approve to set transfer allowances is still available in ERC777, so you can configure both operators as well as allowances.
The Super Token overrides
transferFromon the ERC777 such that it does not trigger any hooks but leaves the
sendfunction as is.
The TOGA Contract lets an account stake their Super Tokens in it to become a Patrician (like a "liquidator of choice") for the Superfluid Protocol.
In order to stake your Super Tokens, you use
sendto move tokens into the TOGA contract. The TOGA contract reacts to the incoming tokens with its
transferFromwill not work!
tokenReceivedhook engages code which determines if your stake was enough to become the Patrician and also picks out some optional user data which lets you customize the exit rate of the position (read more in Liquidations & TOGA).
Ethereum.org's description of the ERC777
More formal description in EIP-777
See the transfer function code on OpenZeppelin's ERC777 contract
See the SuperToken code and how it utilizes ERC777