Ok everyone! Time for an actual builder update ⏳ Yes, I am still building... 👨‍🏭🤠 🧵
The tragicomedy of why I haven't shipped a Multiswap update in over two years will make a great Netflix series some day. Back in April last year, I was introduced to the @avantprotocol team (before they were Avant) and we had early talks about using Multiswap for their launch...
@avantprotocol At the time, I had just fixed some of the issues that plagued our "beta" launch (more like "alpha") in Sep 2023 (the year before). I had the contracts re-audited and was ready to deploy, but Avant needed a stableswap and the constant weight beta was not great for stables.
@avantprotocol I knew the Multiswap math was flexible enough to support stableswaps via changing weights, similar to how Curve works, but the beta was constant weight so I needed something new. Allowing weights to be dynamic opens an entirely new design space and I went deep into a rabbit hole.
@avantprotocol I realized we didn't need a separate StableMultiswap. The math was general enough to support stable AND volatile swaps in the same pool 🤯 Maybe I should have launched the constant weight version. It is already 100x better than Uv2, but I decided to focus on the new Multiswap.
@avantprotocol Over the next several months, I experimented with several candidate dynamic weight models until I settled on something I liked. The model was coded up, tested and ready for audits, but this time I planned to have a CavalRe token... 🕳️🐇
@avantprotocol In typical "me" fashion, our token launch would not be like anything seen before so I designed a new token launch mechanism that morphed into an entirely new kind of launch pad 🚀
@avantprotocol But... is having a token enough to incentive liquidity? Not really. We need a proper incentive model. Looking around at other DEXs that were gaining market share, I was lead to ve(3,3) only to learn that these things are monstrosities that would make Madoff blush...
@avantprotocol I spent the next couple months working on documentation, whitepaper, etc., taking me up to March this year. My partners/advisors and I decided to try to quietly launch a stripped down version of the new Multiswap without the staking-rewards model. We thought that we be faster 😅
@avantprotocol That is when I learned how horrible my research code was. My modules were not very modular. Modules unrelated to the staking reward model had dependencies on the staking reward, so I couldn't easily just strip it out. I had to refactor everything 🤦‍♂️
@avantprotocol By the end of May, I had depleted every source of funds available to me and was close to not being able to pay rent 😅 So I did some contract work to pay some bills in June and July (thank you!). By August, I was determined to "ship or die". No more distractions!
@avantprotocol Then, on Tuesday (11/11) I got the quotes working again 🥳🎉 BUT... while testing, I realized the new model, which involves inverting a cubic polynomial in closed form (😱) had numerical issues at some key points that could not be ignored. Panic! 🚨🚨🚨
@avantprotocol I tried a bunch of ugly things such as splitting the region up and handle the special challenging regions separately. I knew that Curve has a similar issue, i.e. solving a nonlinear invariant, and they use an iterative method, which I was trying to avoid...
@avantprotocol However, the new Multiswap invariant is actually nicely behaved and perfectly suited for solving via Newton so I decided to give up the closed-form solution and go with a Newton iterative solver. PS: Newton was an absolute 🐐
@avantprotocol However, ditching the closed-form for an iterative solver unlocked some addition superpowers 🦸‍♂️
Holy shitake mushrooms. My mind is blown. The new Multiswap just gained ANOTHER superpower.
@avantprotocol When I first started working on StableMultiswap, I came up with a model that had a "stableness" integer parameter n. As you increase n, the prices become more stable, i.e. less price impact. If you set n=0, it corresponds to our original "beta" model with constant weights...
@avantprotocol The new Multiswap corresponds to n = 2. The reason I stopped at n = 2 was that only n = 0 and n = 2 (n must be even) can be solved in closed form. With n > 2, we need an iterative solver, BUT since we are using an iterative solver now, there is no reason to stop at n = 2!!
@avantprotocol For reference, here is value flow (red) and price impact (black) as a function of trade size when n = 0 (our "beta"). Note that there is no flat region around x = 0 (small trades). There is price impact for any size trade. This is not great for stables.
@avantprotocol Here is value flow (red) and price impact (black) for n = 2, i.e. our new model. Note the price impact is flat up to about 10%. This means we can trade up to 10% of reserves with close to zero price impact. This is similar to Curve (at its best).
@avantprotocol But since we're using an iterative solver now, why not go nuts? 🍿😎 Here is value flow (red) and price impact (black) for n = 4. We can trade over 20% of the reserves with close to zero price impact. This completely destroys Curve and we're just getting started...
@avantprotocol With n = 6, we can trade ~40% of the reserves with close to zero impact.
@avantprotocol Here is n = 60. With n = 60, you can trade up to 90% of the pool reserves with close to zero price impact.
@avantprotocol Ok. So what is this "target weight" all about? Here is n = 6 but with target weight 15% and actual weight 20% so the pool is 5% overweight this asset. Now there is some asymmetry in the price impact...
@avantprotocol When your trade takes you towards the target, there is less price impact. In this case, the asset is already overweight, so if you try to deposit more, you experience more price impact. The price impact for wrong-direction trades get worse the more over/underweight the asset is.
@avantprotocol Here is n = 6 with target weight 10% and actual weight 20% so the asset is 10% overweight. Trying to deposit more of an already overweight asset comes with a severe price impact penalty.
@avantprotocol As an extreme example, here is n = 6 with target weight 1% and actual weight 20% so it is 19% overweight. In this case, you can dump an infinite amount of coins in the pool and still extract nothing because the price you get is zero.
@avantprotocol Target weight is a huge risk management feature protecting LPs. Under normal market conditions, it creates incentives so that the actual weight should hover randomly close to the target weight. The actual weight changes with every trade so it is a lot like a Brownian motion.
@avantprotocol I am very happy with where we landed and all the twists and turns along the way were needed to get us to this spot. I'm still here. I never left you!
1.33 K
7
El contenido al que estás accediendo se ofrece por terceros. A menos que se indique lo contrario, OKX no es autor de la información y no reclama ningún derecho de autor sobre los materiales. El contenido solo se proporciona con fines informativos y no representa las opiniones de OKX. No pretende ser un respaldo de ningún tipo y no debe ser considerado como un consejo de inversión o una solicitud para comprar o vender activos digitales. En la medida en que la IA generativa se utiliza para proporcionar resúmenes u otra información, dicho contenido generado por IA puede ser inexacto o incoherente. Lee el artículo enlazado para más detalles e información. OKX no es responsable del contenido alojado en sitios de terceros. Los holdings de activos digitales, incluidos stablecoins y NFT, suponen un alto nivel de riesgo y pueden fluctuar mucho. Debes considerar cuidadosamente si el trading o holding de activos digitales es adecuado para ti según tu situación financiera.