XFAI & ✨Flash Mintable Tokens✨

ChainlessCoder
XFai-official
Published in
4 min readDec 9, 2021

--

You get a billion! 💰 And you get a billion! 💰 And you get a billion! 💰 Everyone gets a billion!!! 💰💰💰

Wouldn’t it be great to have as much money as you want? Well, flash loans make that possible, even if only for a brief moment in time. A flash loan is a cryptoeconomic primitive used often by arbitrageurs in decentralized finance (DeFi). In conventional loans, lenders usually require up front collateral before giving money to a borrower. Flash loans are different. Here borrowers can take out as much money as they want out of DeFi services without any collateral at all. The catch though is that the borrower has to return the borrowed money (plus a slight interest on top of it) at the end of the same transaction. Wait, what? 🤔

For a normal user this sounds pretty useless, but not for arbitrageurs, the busy workers that make automated market makers (AMMs) possible. First let’s cover some definition: Arbitrage is the process of buying an asset in one market and selling it in another one. If markets price the asset differently, one can take advantage and make a profit. As an example, if you could buy 2 ether in one decentralized exchange (DEX) with only 4k DAI, and sell 2 ether in another DEX for 4.1k DAI, you’d be incentivized to buy that ether using DAI in the first maket and sell it for DAI in the second market, and profit! This is how DEXs update their asset prices. Without arbitrageurs, the price of the same assets would differ across all DEXs. Arbitrageurs that use flash loans don’t need that initial upfront capital (the 4k DAI). They simply ask for as much money as they need from other DeFi services (the flash loan part), perform the arbitrage, give back the borrowed money + some interest, and keep the rest of the profit for themselves. In DeFi, every nerd can be rich for an instant 🤓

That’s cool and all, but we can do better. Why pay an interest at all? That’s where ✨ flash minting✨ comes in. I’ve seen the term “flash minting” for the first time back in 2019 by Austin Williams in his github repoflash mintable asset backed tokens”. The concept is simple: You have a special type of ERC20 token that allows you to mint as many tokens as you want, as long as you burn the same amount of tokens at the end of the transaction. No interest rate, no need to contact a DeFi liquidity pool with an upper bound of liquidity. Austin’s code was designed for a special type of token, known as “asset backed tokens”, more commonly known as wrapped tokens (e.g. WETH). It was a pretty cool concept, but unfortunately it never gained enough traction.

That is, until Xfai came along! At Xfai we decided to generalize Austin’s flash mintable implementation. Instead of requiring an underlying asset (the asset-backed part), our variant is self-backed! That is, the token does not have to be a wrapped one. And to put one’s money where one’s mouth is, we have decided to make Xfai’s DEX bridge token flash mintable. No more interest rates for arbitrageurs! As DEXFAI (Xfai’s soon to be public DEX) financially benefits from every swaps through it’s unique burning mechanism (more on this here), we want to make it as easy and as profitable as possible for arbitrageurs to update the asset prices on our DEX. We could have simply made a DEX flash loan mechanism with zero interest rate, but flash minting sounds cooler 😎 (plus I wouldn’t be surprised if it turns out to be more gas efficient as well).

Below is a non-audited code example for how a flash mintable “self-backed” token would work (we’re going to inherit Openzeppelin’s ERC20 contract to simplify the example):

That’s all to it, it’s a really simple mechanism. For anyone wanting to explore the code in more depth and checkout examples for how to perform a flash mint, feel free to visit my Github repo with code examples.

Bug Bounty

At the current time of writing, this simple contract is not audited. Anyone who manages to exploit the contract, that is, anyone who manages somehow to mint more tokens than they have to burn at the end of a transaction, can win 20,000 USD as a bounty! Turn on your computers and hack away! 💻

So how can I get that XFAI token? 🤔

XFAI is not out yet. The only way one can (permanently) mint XFAI tokens is by staking XFIT through a contract that we’re aiming to launch at the end of December. More information can be found here. I will write a detailed blog post about the staking procedure, as well as about the new Liquid NFT token model that we’ve created, in my next post. In the meanwhile, stay tuned! 🙌

--

--

ChainlessCoder
XFai-official

Interests: Cybernetics, distributed systems, biological systems, economic systems, decentralized machine learning