# MEV Capturing AMMs (McAMMs)

- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2023-10-09
- Duration: 08:19
- Topics: blockchain, smart contracts, distributed ledger, ethereum, Science & Technology
- Watch: https://streameth.org/watch/yt-kK8gt318WeI
- YouTube: https://www.youtube.com/watch?v=kK8gt318WeI

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on Swarm, IPFS and more.
https://archive.devcon.org/archive/watch/6/the-blockchain-bridge-that-you-dream-about/

In the times where scalability of blockchains depends on multiple layers, and when interoperability holds for an essential blockchain feature, bridges become critical infrastructure parts. They are meant to hold liquidity, asked to operate quickly, but they cannot benefit from the security guarantees of an on-chain application, because they inherently contain off-chain components. In this talk, we discuss the properties of a bridge that is secure and meets all the needs for it to be useful.

Speaker(s): Martin Derka
Track: Layer 2s
Keywords: Bridge,Security,L2

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 6 was held in Bogotá, Colombia on Oct 11 - 14, 2022.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

foreign [Music] welcome to my talk today I'm going to talk about a different way to design automated market makers in a way that hopefully is going to capture the Mev that currently is being lost to Miners and other parties by the way is a an online chain exchange that protects you against Meb so what is Mev or maximum effect of value currently block Builders have the responsibility of updating the state of the blockchain so how is this done by including excluding ordering transactions in a block and for this they get paid fees transaction fees and Rewards whoever there are other ways where that that you can use to get money out of the block building process so one very common attack is called the sandwich attack in which uh use a transaction is exploited to extract Mev so let's say that a user is creating a transaction once included in a block to sell on an automated Market maker 100it or 100 000 usdc so as it's usually customary there is an extra slippage added in case the price moves between when the when the transaction is created and executed and normally it shouldn't really matter the user should take the expected price however the point of sandwiching is actually using the slippage against the user so how does it work the block Builder creates two transactions one before and one after the first transactions this first transaction buys usdc and moves the price of the amm to the minimum that would be accepted by the user the user trades anyway because this is according to the slippage still valid and then finally the block Builder can sell back the usdc at the new price basically this is a safe bet for the block Builder because the state update is controlled by the by them but that's not everything there is to it so now we'll talk about an issue for the use for a user transaction but also we don't need to have a transaction to have Mev one new mechanism of tracking value is called loss versus versus rebalancing and it works more or less as follows so let's say that we have an amm on chain and its state is currently well we have a market price what we need is more or less equivalent to 1400 die this could be any market price not necessarily on chain so it could be for example a centralized exchange anywhere and let's say that at the same time an amm is willing to give a 1400 die for one eat the same price some time passes no transactions occur on chain however the market price change unclear why could be some centralized Marketplace to change the price so suddenly there is an Arbitrage opportunity that can be exploited so the amm doesn't know anything about the market price but if you can execute the transaction and you are guaranteed that is going to be finalized you can take this Arbitrage opportunity and this is more or less the essence of loss versus rebalancing the difference in from different information that the amm and the market has so if the IMM had perfect information the IMM would be very happy to use the current market price however this is not the case and this money loss is basically the cost of providing liquidity on an amm currently so important to notice is that also that this is not impermanent loss so it doesn't really depend on how on the relative change in value of the two of assets in the amm this was by the way part of recent research while it's in rough Garden so there are related papers eventually I'm going to give you more information but that's it how can we avoid this so let's actually try to build an amm that avoid that captures Mev so we start from any amm let's say uh uh constant product amm like uniswap and on top of it we create a mechanism where we can auction the the right of executing the first trade on the on the exchange so there is going to be a lead also called lead Searcher which is the highest bidder that is going to take the right to execute the first transaction as we see this is a good way to capture this lvr and the important thing here is that the proceeds don't go too well go to the liquidity providers and this is the Mev that otherwise would be extracted by miners so how can this actually work so to do this we simply we simply say that no user can trade until their lead Searcher has actually traded first so you can see if the leads if the researcher actual trades then all the transactions go through otherwise if the block is organized differently then the trade reverts not really this requires cooperation with the block Builder so the idea is that the block Builder is aware of the structure of the of the cons of the concept of the amm and orders everything accordingly however uh there is an incentive that is needed and the incentive would be the gas used by the transaction if the transaction reverts immediately is going to use less gas and in particular this would help the miner having an advantage the the block Builder having an advantage on Mev only Mev auction so let's analyze some costs so first prophets the prophets are estimated to be nine dollars per block how are they estimated so they're the Eden network is a network that works in a fairly similar way so it also auctions off the right to the first lot in a block and this is more or less the the uh more or less the blue The Profit that comes from the hidden network which is comparable to our structure the costs are estimated to be three dollars per block which is basically the extra gas cost to enforce the rules that we just decided and not that obvious this is based on 40G way Gus price however it would be much lower so already like with this simple scheme we would have uh theoretical captured Mev of six uh dollars per block so I also want to point out that even if the extracted profit now for the amm is six dollars in principle it could be much higher so in this graph I wanted to show the average block reward comparing flashbots which extracts Mev and other parties which don't so you can see in the last two months it's actually fairly consistently 0.1 each reward more which is actually about more than one hundred dollars per block so this is actually a fairly large amount and it could also be extracted with different mechanisms or the mechanisms of amms okay so in conclusion we have that amms have hidden fees because of Mev both for users and for liquidity providers in currently in Current Designs well the these fees go to arbitrary and block builders however we can do better and we can try to design our amms in a way that distributes fees differently and this is what I hope to transmit with this stock so all of this is work in progress is being worked on I would invite you if you're interested to join the discussion and please any opinion is welcome if you are building an amm please extract all the med and after this thank you and thank you again [Applause]
