• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Solidity
  • License
    MIT License
  • Created about 4 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An example of a Flash Mint powered arbitrage between a flash mint DEX, Kyber and Uniswap.

Flash Mint Arbitrage

An example of a Flash Mint powered arbitrage executed on the Ropsten testnet between a flash mint DEX, Kyber and Uniswap.

Background

When I first heard about Flash Minting back in Feb 2020 I laughed. Then when I heard about Maker's MIP25 for a flash mint DAI module, I laughed again. But the more I started looking into ways this concept can be gamed, the more I realised the underlying tokenomics actually work. Because at the end of the atomic Tx, no party is out of pocket.

So I forked Austin William's Flash Mint implementation onto Ropsten, along with a Flash Mint compatible DEX and executed a Flash Mint powered arbitrage between FlashMint DEX, Kyber and Uniswap.

The following contracts are on Ropsten:

If this all sounds Greek to you, head over to Austin's Flash Mint presentation which explains this concept in detail.

TLDR

If you just want my TLDR summary, here is what my fork is achieving:

FAQ

How is Flash Minting different to Flash Loans?

Flash Minting is similar to Flash Loans where you don't need any up front capital to access temporary liquidity within an atomic transaction. The difference is you don't flash borrow from a liquidity pool, the tokens are independently minted for your use during the flash mint tx and the same amount of tokens must be burned at the end of the transaction otherwise your transaction will revert like a flash loan.

Aren't you just Brrrrrr'ing like the Federal Reserve?

There's a common perception of leveraging unlimited flash mint funds to wreck havoc across the DeFi landscape. As prompted by @DeFiGod1 on twitter, what you can do with the flash minted tokens is still largely subject to the quantum of liquidity of flash mint friendly DEXs. There might be some difference in the quantum of total lending pool liquidity vs total DEX trading liquidity but I haven't crunched the numbers yet. If you check the Kollateral page (Flash Loan aggregator), the combined Aave/DyDx flash loan liquidity is $200M for ETH as at 24th Oct 2020.

On the other hand, once DeFi lenders start accepting flash mint tokens, then there's a bit more freedom to mint an godly amount and then execute some weird interest rate related strategy that ends up yielding a positive outcome for the minter.

So what benefits does Flash Minting offer?

Speaking hypothetically of course since it's yet to be formally adopted by protocols on mainnet. The benefits should include:

  • Cost: Flash Minting should be much cheaper than Flash Loans, if not close to zero. That's just my personal opinion but obviously a broader discussion is needed.
  • Removal of barriers to entry: The nature of the 'minting' concept means even non-lending projects (or even twitter lol) can become flash minting providers (e.g. build a dapp that interacts with the fWETH contract with simple mint buttons), as long as the fWETH is accepted by at least one DEX or lending protocol. This would remove one barrier of entry into DeFi for external entities and support mainstream adoption.
  • New profitability vectors: It facilitates yet another way to make or save money, be it arbitrage, liquidation, self-liquidation, collateral swap during market downturns...etc
  • Inheritance: In a conceptual sense, flash minting essentially inherits all the benefits that comes with a Flash Loan, such as having access to significant liquidity with zero up front capital, turning your average DeFi consumer into GigaWhales.

Isn't the Flash Mint DEX now rekt because it's left holding a bag of valueless Flash WETH!

At the end of the Tx the 1 Flash WETH that the Flash Mint DEX is holding is actually backed by 1 ETH in the Flash WETH contract. They can call the Flash WETH contract to redeem the underlying ETH.

What if another Flash Mint Demo contract takes the 1 ETH sitting in the Flash WETH contract, doesn't that mean the x Flash WETH held by the Flash Mint DEX is no longer backed?

For anyone to hold Flash WETH, they needed to be flash minted at some point, which means the same amount of Flash WETH needs to be burned at the end of that Tx.

If another contract executes a flash mint, then uses x flash WETH to redeem for x ETH sitting in the FlashWETH contract, and if they do nothing else their flash mint Tx will revert like a flash loan because they no longer have the same amount of originally minted Flash WETH to burn in order to successfully close the Flash Mint Tx. However as Austin Williams explained in his presentation, this is still an experimental concept and there are bound to be exploits afoot. Don't use this in prod without a thorough and holistic audit on how this impacts your whole ecosystem.

What if, during the atomic Tx, something breaks AFTER the Flash Mint DEX accepted the 1 Flash WETH and gave out 1 ETH?

The whole end to end transaction reverts, so it never actually accepted the Flash WETH to begin with, much like a flash loan reversion.

Isn't this dangerous? If this makes it to mainnet it'll be Q1 2020 all over again with the flash loan exploits!

There might be some short term pain as people will inevitably try to game the concept but I personally see this as a net positive long term for the DeFi ecosystem as it will reduce the amount of projects that treat security audits as an afterthought. Flash loans were at one stage considered too hazardous, but now you see users regularly flashing 8 figure DAI loans for breakfast.

Lending protocols and their associated interest rates would be at risk of potential new flash mint powered attack vectors due to the quantum at play. There's bound to be other angles so hopefully the various protocols can pre-emptively guard themselves.

What's the maximum number of tokens I can flash mint?

Anyone can mint up to 2^256-1 WETH, unless additional restrictions are set by the flash mint provider. The folks behind WETH10 deployed their flash mint powered WETH10 onto the testnet with no restrictions so would be interesting to see if anything comes up from testing that necessitates a mint size restriction.

Can you build a version of this for me that makes me money?

To quote Hamlet Act III Scene III line 92........."no".

Setup and Execution

These contracts are Remix friendly so you can just plonk them directly on there, set compiler to sol ^0.5.16 and not have to worry about all the dependencies.

  1. Deploy FlashWETH.sol

  2. Update the Flash WETH address in FlashMintDex.sol

address constant public fWETH = 0xD4f239B1be6a0bdCf7e150AB1E43b453e101EF5a;
  1. Deploy FlashMintDex.sol

  2. Update the IExchange address in FlashMintDemo.sol with the FlashMintDex address

IExchange public exchange = IExchange(0x0D8F5aB7A0f5aA16a9bAAc38205f3E39855486eB);
  1. Deploy FlashMintDex.sol

  2. Provide some liquidity to FlashMintDex e.g. send 1 ether to it so users can swap 1 Flash WETH for 1 ETH

  3. Provide some funds to your FlashMintDemo contract e.g. send 2 ether to it.

  4. Now let's flash mint arb! Call FlashMintDemo's beginFlashMint() with the following paramters

_mintAmount: 1000000000000000000 // flash minting 1 ETH worth of Flash WETH (i.e. 1 Flash WETH)
_flashMintContract: the address of your FlashMintDemo contract so arb profits and remaining balance go back there.
_srcQtyKyber: 1000000000000000000 // trading 1 ETH on kyber for DAI
_erc20UniTrade: 579000000000000000000 // trading 579 DAI on Uniswap back to ETH
  1. Go make some tea, sit back and watch the magic happen.

  2. A successful flash mint arb tx will look like this.

Next Steps

There's a broader discussion needed on whether this type of concept should involve fees. I'd imagine existing flash lending protocols would not be too excited about a zero fee Flash Minting module as it would take business away from their existing flash loan lending pools.

At the same time, from a consumer POV, I don't know how much it'd cost the lenders to allow flash minting out of thin air, other than the intense audits needed to assure the integrity of their ecosystem when introducing flash minting on mainnet. And as mentioned earlier this is still an experimental concept so would be great to hear all the ways this can be exploited.

Food for thought.



If you found this useful and would like to send me some gas money:

0xef03254aBC88C81Cb822b5E4DCDf22D55645bCe6

Thanks, @fifikobayashi