Originally published at: https://blog.openzeppelin.com/flash-mintable-asset-backed-tokens/
“Anyone can be rich for an instant.” or “Perfect credit from atomicity.”
What are flash-mintable tokens (FMTs)?
Flash-mintable tokens (FMTs) are ERC20-compliant tokens that allow flash minting: the ability for anyone to mint an arbitrary number of new tokens into their account, as long as they also burn the same number of tokens from their account before the end of the same transaction.
You can think of FMTs as “credit tokens”. Flash-minting FMTs is like “running up a tab”, and burning the tokens at the end of the transaction is “paying off your tab”. If you don’t pay off your tab by the end of the transaction, then the transaction is reverted, and it is as if you never ran up a tab to begin with.
Flash-minting is a powerful idea, but only if the tokens themselves have some value.
What are asset-backed tokens?
Asset-backed tokens are ERC20-compliant tokens that are 1-to-1 backed and trustlessly redeemable for some other asset. The canonical example is Wrapped Ether (WETH).
Anyone can send an asset (ETH in this case) to the contract and receive one WETH token in return. The WETH token can be transferred and sold to anyone, just like any other ERC20 token.
More importantly, anyone who holds a WETH token can instantly and trustlessly redeem it for one ETH by sending it back to the contract. This is what makes WETH an asset-backed token.
The most important thing to know about asset-backed tokens is that they have exactly the same market value as their underlying asset. One WETH will always be worth exactly one ETH, and vice versa.
Flash-mintable asset-backed tokens
A flash-mintable asset-backed token is exactly what it sounds like: an ERC20-compliant token that is:
- Asset-backed, so everyone can accept them at full face value knowing that they can always trustlessly redeem them for the underlying asset.
- Flash-mintable, so anyone can mint arbitrarily many unbacked-tokens and spend them at full face value, so long as they destroy all the unbacked tokens (and therefore restore the backing) before the end of the transaction.
To see that flash-mintable asset-backed tokens maintain their market value even during a flashMint — when they are not all backed by assets — consider the following thought experiment for a flash-mintable asset-backed token called FlashWETH (using ETH as the underlying asset).
Suppose you receive a FlashWETH token during a flashMint and consider the following cases:
Case 1: You try to redeem the FlashWETH during the flashMint
If you try to redeem the FlashWETH for ETH by calling withdraw during the execution of flashMint one of two things will happen:
-
Case 1a: Your redeem succeeds
If your attempt succeeds then you got exactly what the FlashWETH was worth (1 ETH). No problem here. -
Case 1b: Your redeem fails
Then the transaction will revert, and it will be as though you never received the FlashWETH in the first place. No harm done. You are not left “holding a bag”.
Case 2: You do not try to redeem the FlashWETH during the flashMint
If you do not try to redeem the FlashWETH for ETH during the same flashMint transaction, then either:
-
Case 2a: The flashMint transaction goes on to succeed
If the flashMint goes on to succeed, then the unbacked tokens all got burned, and so the FlashWETH token you are holding is fully backed. No problem here. -
Case 2b: The flashMint transaction goes on to fail
If the flashMint goes on to fail, then the transaction will be reverted, and it will be as though you never accepted the FlashWETH to begin with. No harm done.
It is impossible for a transaction to end with any FlashWETH tokens being unbacked by ETH.
This means that the only time the FlashWETH tokens are ever unbacked is during the execution of a flashMint.
In short, everyone can always accept FlashWETH at full face value because either it is instantly redeemable for ETH whenever they want, or else the EVM will revert and they’ll have never accepted it in the first place.
Why integrate flash-mintable asset-backed tokens into your project?
Imagine if all of your users were whales.
Integrating flash-mintable asset-backed tokens into your project lets all of your users act like whales. They can have access to as much money as they need to do whatever they want on your platform. If your project makes fees on volume, this is a no-brainer.
Instead of sending them off to some flash-lending pool somewhere, you can serve them directly. Save them gas and fees. Give them access to a virtually unbounded amount of money. Completely remove their dependence on third-party flash-lending platforms.
Other platforms are using the “trustlessness of atomicity” to extend credit to your users via flash-loans, often charging them for the privilege. You can cut out those middlemen and give your users credit directly. And you can do it with no additional code. All you have to do is accept flash-mintable asset-backed tokens the same way you already accept asset-backed tokens such as WETH.
Note that flash-mintable asset-backed tokens don’t require liquidity pools like flash-loans do. Anything users can do on your platform using a $100M flash-loan from a third-party, they can also do using flash-mintable asset-backed tokens once you’ve integrated — even if the flash-mintable asset-backed token contract isn’t holding very much ETH.
Flash-mintable asset-backed tokens are powerful.
Finally
This was a research project by Austin Williams of the OpenZeppelin Research team.
There is a 1-hour video presentation on this project along with slides.
The example FlashWETH contract is on mainnet with the code in GitHub.
Warning: The contracts are simple but have not been audited. Be careful.