Diving Into Shallow Markets: Why Liquidity Depth Matters Less Than You Think | Will Fey - Ammalgam
Ethereum Denver·Thu, Oct 9, 2025, 12:00 AM
In shallow markets, reliance on external price oracles is dangerous. Manipulated or delayed data can lead to unfair trades and significant losses. 🚀 Get Ready for ETHDenver 2025! 🚀 We're already hard at work preparing for next year's biggest Web3 event! Keep your eyes peeled for more info on ETHDenver 2025—it’s going to be epic! 🌟
Transcript
[Music] hey everybody how's it going uh I don't know if I've ever spoken in front of a this large of a live live audience so this is this is quite intimidating um getting yelled at okay oh no oh God okay back here all right take two uh so yeah I am going to do a talk on diving into shallow markets and um my name is will I'm the founder of amalgam uh just a quick introduction of why this matters uh to us we're building a DEX and a lending protocol that are both one single primitive so think about a peanut butter jelly sandwich the Dex is the peanut butter The Lending protocol is the jelly and amalgam is the peanut butter and jelly sandwich all right uh one of the problems that we had to solve when doing this is this concept of how to do lending uh with shallow markets and this quote and the title is inspired by a very well-known security research uh currently a paradigm that um wrote a paper on an article on l in and oracles that I would encourage everyone to go read but this quote specifically talks about how uh shallow markets are dangerous to lend against uh and the reason for that is that it's very easy in a shallow Market to change the price and if you can change the price drastically lending becomes problematic um so why should we care uh a few things that's happening in lending right now is it's actually quite centralized in a number of domains uh the first being that in order to have an oracle most lending is done with oracles uh those oracles are mostly sourcing offchain data and that offchain data is coming from a centralized exchange and so you can't get a lending market price feed without first getting an centralized exchange listing that doesn't seem very decentralized another issue issues that many protocols like a use allow lists to limit what tokens Can Be borrowed and traded on those platforms and they do this because they want to protect the market from shallower traded tokens from being manipulated and used to taking the more important assets or the the the rest of the assets and then you know lastly I would also say another bucket here that's not on the slide but is configurations uh you have now other uh lending protocols like Moro that are heavily relying on analytics firms to say hey here are the parameters that make this specific thing able to be borrowed right so a lot of great analytics teams there but you're still trusting somebody else you're trusting some analytics firm to protect you and so ideally in this decentralized world I'm very excited about trying to push the boundaries of what we can do on chain uh with less centralized controls and really being more decentralized so uh another really important thing why this matters uh this is about half a billion dollars in hacks across uh some of the more famous lending attacks that happened because the price was changed drastically so cream Finance uh Bonk mango compound uh and then you know these are some quotes from different articles but we have the highlighted sections in which you can see the the main point is that the price was changed compound there's a 30% increase in price that led to Forest liquidations uh mango had you know I mean that's like a 30X increase going from 3 cents to 91 C and then Bonk you know that this isn't quite a price change it was more of a hey this this is not worth this and the protocol being like okay um and then leading to a huge hack and then uh lastly cream was uh a thinly traded Market um but also there's a little more to it but basically they changed the price and then uh you know profited and so always the same you know formula the art of infinite borrowing is post one asset as collateral change the price for that asset borrow as much as you can and profit and you know these hacks were all the same simple formula how the price was changed might be a little bit different but then once the prices changed it's very easy to just take all the money so I spent uh two and two years two and a half years thinking about this problem uh and decided to try to tell you guys about it in 20 minutes uh and so some of the naive approaches about how you can potentially solve this is is one you know why don't you just slow down the the rate at which you let the price go up right uh make it take longer to update the price right and there's a few drawbacks of this uh if you take a really long time to update the price you may not actually be able to you know execute a liquidation when the assets uh of certain positions have led to the position being completely um you know approaching insolvency right you want to be able to liquidate so you need a price that doesn't move quickly but also moves quickly okay that's that sucks uh then additionally um you know you can maybe rely on Arbitrage right if there's some external Market well we assume if that external Market exists and somebody's trying to manipulate the market that we're using as a source of Truth for what these assets uh cost if you know we we slow things down enough then people's uh cost to attack that price keeps going up and up and up and the reason is because somebody you know on the manipulated price can you know sell their assets there and then buy them on the external price and they can keep doing this and keep making profit over and over again until the prices sink together the problem with this is that if the external Market is very shallow then it may actually be just as easy to manipulate the price on your price feed and the entire market right and so this is this is bad we still have the problem is you can move the price you can create the infinite um money attack so uh yeah so the and then also what if there's no external price your your source of liquidity is the only source of liquidity and so by changing that um it's very easy to then you know do the infinite money attack so what we came up with to solve this is on one hand uh we don't think about price as a single number we think about it as a range so we have some confidence that the price is in this range and that that's defined by a few different lengths uh time weighted average price uh mechanisms so this is a well-known defi thing you know Unis swap has a Time weight at average price or tuwop um and you know you can use a few different of these at different lengths to create a a in interval that you think the price is within that interval right and then one side of the price moves very quickly and the other side doesn't when you change the price because the the longer interval is very sticky it's hard to move whereas the shorter interval moves you know fast enough to allow for liquidation when you need them and then um additionally one way to make these manipulations more expensive is to say hey I think this is an allowable reasonable amount that we can allow the price to move per block and if somebody is moving the block more the price more than that per block we can say oh that that's probably not good we'll just ignore that right so we actually take the price every block and we say oh if it's within in this range then great that's the price and if it's not we're going to ignore that and just you know record this like Max allowed price for that block and just keep on moving and then now all of a sudden if somebody is trying to manipulate the price it is much more expensive because they can only get the the the price to be recorded every block a little bit higher every time with respect to you know if they want to do 30X it will take a lot of blocks to get to a 30X as we saw in the Bon attack uh some other things and this has been used in morph uh Moro is instead of having a Min to manyi relationship for Lending where one asset of the mini could be manipulated and then you take the rest of the mini in the infinite money attack then um instead a better way is to do it one: one right and if you just have this one to one then say you have a to token or somebody rugs some coin and it goes infinitely from some number to zero um this is bad this will be bad for that pool uh but it doesn't affect the entire protocol it just affects the liquidity providers that felt like they should trust the shitcoin to not be worthless and they were wrong uh additionally uh another concept that we came up with is right now all SWAP fees are linear uh and and so they get bigger the bigger the swap you take some percentage of the Swap and you call the fee um and so uh one interesting thing that you could do instead of having a linear fee is have a quadratic fee and so what that means is on small swaps that don't have a huge impact on the price you can charge a really minor fee you know because you actually want that volume that's probably uninformed trading volume that volume is not going to wreck your LPS now when the the trades get much bigger and they are wrecking your LPS they're resulting in permanent loss you know everyone's talking about loss versus rebalancing and everyone's wrecked right you could actually increase the fees for those swaps and so we do this by looking at the effect of a swap to the price and the bigger the effect of the swap to the price the bigger the fee but that growth is quadratic instead of linear and so if you wanted to like you know forx the pool you might pay a 40% fee and then all of a sudden this infinite money attack gets much more expensive so few other things um these are all order out of order but we actually look at each position when we open it and we say how much slippage would get created if this was liquidated and so why don't we just take that number take that increase and add it onto the debt so maybe they want wanted to borrow a million dollar but the slippage would be like 20% so we're saying oh actually you know what you're you're borrowing $1.2 million before we calculate loan to value and what this does is that you know bigger positions require a lot more collateral and um smaller positions don't and this this just helps to protect against the more risky loans uh one interesting thing that you might ask and we also had to solve this question is okay maybe I can't do this really big loan but what if I did a hundred or a thousand small loans that adds up to the big loan how do you protect against that that slippage is smaller so we also had to do a lot of research into that that I won't get into uh but it involved you know trees and figuring out how to do things that should take constant time and linear your time uh and it was it was a lot of brain damage and we're really excited that we figured it out but um anyway uh the last thing um that I will say is that we're really excited about trying to push the boundaries and make a permissionless lending protocol that allows lending on any asset and um you know I'm I'm really excited to bring this thing to Market we will be launching in um probably end of March or beginning of April and uh excited to anyone who is here I think the real the real thing is that if you know what I'm talking about after all this conversation and you want to ride go-karts tomorrow you should come talk to me because we have a great event should come ride go-karts it'll be a lot of fun uh so feel free to ask me any questions about this after the talk and that's all I got so thank you
Automatic transcript — names and jargon may be misspelled.