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.17K
6
The content on this page is provided by third parties. Unless otherwise stated, OKX is not the author of the cited article(s) and does not claim any copyright in the materials. The content is provided for informational purposes only and does not represent the views of OKX. It is not intended to be an endorsement of any kind and should not be considered investment advice or a solicitation to buy or sell digital assets. To the extent generative AI is utilized to provide summaries or other information, such AI generated content may be inaccurate or inconsistent. Please read the linked article for more details and information. OKX is not responsible for content hosted on third party sites. Digital asset holdings, including stablecoins and NFTs, involve a high degree of risk and can fluctuate greatly. You should carefully consider whether trading or holding digital assets is suitable for you in light of your financial condition.

