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 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,762
8
本页面内容由第三方提供。除非另有说明,欧易不是所引用文章的作者,也不对此类材料主张任何版权。该内容仅供参考,并不代表欧易观点,不作为任何形式的认可,也不应被视为投资建议或购买或出售数字资产的招揽。在使用生成式人工智能提供摘要或其他信息的情况下,此类人工智能生成的内容可能不准确或不一致。请阅读链接文章,了解更多详情和信息。欧易不对第三方网站上的内容负责。包含稳定币、NFTs 等在内的数字资产涉及较高程度的风险,其价值可能会产生较大波动。请根据自身财务状况,仔细考虑交易或持有数字资产是否适合您。

