Deploying an AMM with time evolving bonding curve / Viraz Malhotra
Prague DeFi Summit 2023 · June 2023 · 27:40
Viraz Malhotra runs a workshop on automated market makers (AMMs) built on a time-evolving bonding curve, where the curve that sets an asset's price changes over time. After explaining how AMMs and bonding curve mechanics work, he deploys one and follows how the price evolves, then discusses the challenges and opportunities of the design, including the potential for more liquidity and more efficient price discovery.
Speakers
Topics
From Prague DeFi Summit 2023, hosted by Prague DeFi Summit 2023.
Transcript
okay guys in this talk we are going to explain what an evolving curve is what it's good for and then we're going to do a demo of how they work um but first let's pop over to the shell app and do a quick huh oh yeah so we're gonna like pop over we're going to do a quick sneak peek right now it's kind of like a sandwich demo okay you want to do you want to narrate this yeah full screen
hi everyone so for the demo we are going to Showcase how the price of an nft in an nft based amm decreases over so the example that we're taking and then once the presentation we will see how the price has decreased over time and we'll also like dive into the code okay yeah okay uh so I'm just gonna select one here so this is the shell interface and I'm going to select one a 210 nft that I want to buy right now
you know let me get this presentation mode do you know how to get this in presentation mode [Music] okay whatever I'll just start yes please Okay so let's start with some big questions um big brain questions what does launching a new nft collection have in
common with managing your univ3 LP position well both can be solved with an evolving bonding curve um yeah all right we're going to go over what an evolving bonding curve is what it's good for and how it works I promise let's just do it like yep yeah okay so quick review of amms the most well-known amm is the constant product mm
um this algorithm is good for low volume High volatility token pairs these curves never run out of Reserves and they always have liquidity regardless of the price so the formula is x times y equals k the product K of the two Reserve assets is constant before and after every swap so you can visualize the bonding curve like that um however it has some big limitations first of all um poor Capital utilization so suppose a pool has 100 x tokens and 100 y tokens
Alice wants to swap 10x tokens with the pool this swap will actually move the amm's price by about 20 percent um therefore only small trades are viable which means only a small percent of the a M's Capital can be used at any given time um so instead we encourage you or yeah basically you can concentrate your liquidity over a narrow price range and instead of offering swaps at any rate you can focus on swaps for example between a dollar and 1.25 or whatever you want to optimize for instead instead of using only 10 percent of the post capital for the swap you can now
use almost a hundred percent of the liquidity concentrated liquidity was univ3's big innovation congratulations we've just reinvented it and by letting LPS concentrate liquidity in active price ranges the amm can actually achieve much higher Capital utilization however prices don't stay constant they move around so what do you do if the price changes and that brings us to limitation number two oh it should um well one of the limitations it's like it's really difficult to hit hook up the laptop to a screen
okay we got it no no okay I'll just keep going um so in unity liquidity was evenly spread across all possible prices but with unib3 LPS need to move their position as the price changes um this is difficult because it makes you vulnerable to Med attacks and also it's expensive it costs gas every time you want to make an update so there's a need for an Mev resistant way to update liquidity concentration however there is yet another limitation of static amms like constant product and unib3 I will pause here for a second
is everyone having a good conference this always happens to me it's probably my fault shall I just keep going
no stress I appreciate you okay so the third limitation um these static curves are bad for launching new tokens when you launch a token three things matter the first is price Discovery so figuring out what a token is worth the second is making sure that the launch is fair to retail Traders and the third thing is make it so that their project can raise Capital efficiently constant product like you need to be and unit V3 fail on all three accounts um the implicit value of reserves in a constant product pool is split 50 50.
so the value of the X tokens would equal the value of the Y tokens and at least according yeah that's at least according to the amm's internal prices however you won't know what the token is worth before you launch and you don't we're assuming you don't have much ease to pair with the token so you end up starting your pool at token launch with like a token that is grossly Enterprise it's the projector it's not our fault yeah okay where was I huh
good you should see all the wires back here okay so you end up starting your own pool at token launch with a token that is grossly underpriced so if you only have 10K if then um all the supply of tokens in the pool are implicitly worth only 10K initially Mev buds come along snipe the initial liquidity causing prices to spike these Bots turn around and dump on retail traders who want to support your project the retail Traders lose out because they can't buy the tokens at a fair price so the project in the end loses out because they don't raise as much as they could
maybe I could just show like my laptop okay okay our solution is called progress Proteus is an amm engine um Proteus solves all the three problems um okay so how does it work Proteus is an algorithm that can replicate any shape bonding curve it works by deforming con product curves to be bigger or smaller depending on how we want to concentrate liquidity so when we
stretch the curve to be bigger we're concentrating liquidity in that region when we shrink the curve we're reducing liquidity concentration in that region mathematically this is equivalent to unib3 so that's how it solves the capital utilization problem however the implementation with Proteus is very different from unib3 um there's an equation that I would show you um okay there's an equation that we'll get to it's not a very difficult equation I could read it to you okay
um yeah should I just send you the link yeah is the internet working [Laughter] Mega struggling with you um well where how should I share the link with you yeah okay um all right guys I'm Eliza groxs oh that's a good idea okay wait but I don't know if I have the
shared link on my phone okay wait hold on I can do this I mean we could also like I'll cut like huddle up around the laptop you know this is sues okay well like
completely where was I don't even remember okay all right guys it's in the main chat Prague defy Summit that's the right that's the right telegram chat right this isn't live streaming right
yeah but it's recorded okay [Laughter] I don't remember where I was so in the meantime how was your internet connection in the meantime Prague D5 Summit you got it as well all right
okay that is strong 2023 yeah yeah okay yeah awesome I feel like we all deserve pops for this all right where was I as soon as I remember what slide I was on okay maybe skip to slide number ten
what sorry oh the equation yeah let's go to the slide with the equation Okay so this is the equation for a proteus curve using only one constant product slice it's possible to have over 10 slices as you can see the equation uses two parameters A and B to determine the shape of the curve oh my God we're back okay JK um if we want to change the shape of the
curve we'd change the values of B why is this a big deal recall that the shape of the bonding curve determines the liquidity concentration so if we want to move our concentration along with market prices we can simply adjust a and b but wait can't we already move our concentration with unib3 the key is that Proteus lets us evolve the values of A and B continually every block basically every block the curve and hence the loops change slightly moving liquidity concentration through many small changes turns out to be Mev resistant
um in other words it's a lot easier and cheaper to evolve your curve over time than to make big and sudden changes because every time there's a big Sudden Change in your amm's behavior the Mev Bots will smell an opportunity yeah basically key Point proteos lets LPS evolve their liquidity concentration gradually every block which protects them from Med okay let's talk about auctions now um what does any of this have to do with token launches auctions um here's a wonderful definition from Investopedia an auction business Salem which buyers compete for an asset by playing plating bids
auctions are used when we have something where we aren't sure about the prices we solicit from potential buyers whoever bids the most wins the auction type relevant to this talk is a Dutch auction in which the price of a token starts high and then decreases over time the first person to bid will win the auction this ensures that buyers are competing with each other because if you wait too long for a lower price someone else might buy the token before you do we can it turns out use Proteus like an involving Proteus amm to run a Dodge auction how's this work uh so we start by concentrated liquidity at a high price range then we evolve our concentration progressively lower
a standard Dutch auction does exactly this concentrates all the liquidity at a single price why does this matter for token launches um so if you recall the three objectives of a token launch price Discovery so figuring out what the token is worth um makes it make it fair for retail Traders and efficiently raise capital the the amm Dutch auction will ensure price discovery that is the whole point of an auction figuring out what buyers are willing to pay um and yeah okay so because we sell the tokens at the price buyers are willing to pay we can ensure that the project doesn't leave too much money on the table when selling their token and
buying the token is as fair for retail Traders as doing any swap with slippage protection so all three objectives are accomplished um okay so what about like liquidity bootstrapping pools um the big difference is that with Proteus you can evolve with concentrated liquidity so lbps are lbps are liquidity bootstrapping pools they're super cool um and the first example of using and of all the amm as a Dutch auction however they're generalized versions of constant
product therefore they do not concentrate liquidity but instead spread it out across a wide range of prices so if a buyer tries to make a large purchase during the auction they'll move the price a lot with Proteus is liquidity concentration abilities we can customize the auction parameters to result in a better experience for buyers which is basically the three was such an improvement on univ too okay let's do a quick review um involving Proteus fixes the following three shortcomings improved Capital utilization so by concentrating liquidity we can allocate our Capital where it matters most updating the
liquidity concentration over time because Proteus can gradually evolve over time so LPS can move their concentration without having to worry about Med attacks and launching new tokens Proteus can be used to create a Dutch auction which leads to Better Price Discovery and it's fair for retail traders who want to support the protocol and now we'll show you a demo of how of evolving Proteus works so oh wait because we have to open oh okay sorry that's you know very important slide so let's set up the scenario we want to do an nft uh yeah
I want to launch a governance token we want to launch an nft and we can use evolving Proteus actually to launch nfts by using an nft amm let's discuss the behavior that we want we want the nft price to decrease over time which is actually the scenario that was set up at the very beginning all the crazy stuff happened um so let's go back now can you yeah sorry [Music] there we go yeah guys uh so uh before we started the presentation the price for one 2K nft for this nft pool was uh
0.006430 now let's see what the price is now so it should have decreased over time and now I'll I'm just gonna see yeah check yeah so voila the price has uh decreased from uh 0.006 to 0.005 without us uh updating the balances of the pool so as uh so basically we set up set a duration through which the pools don't uh evolve the curve is going to evolve and then nft starts at a higher price and it can it will decrease over time and you can like we can configure the parameters whatever way we want in this uh example like we Alisa mentioned we uh configured it in such a way that the price of the
nft will decrease over time now I'm gonna dive into the code apart a bit and then just show how do we uh what parameters that we used and how does uh the smart contract looks like can I oh yeah okay yes so the prices that we uh the prices that we used are from a line 15 to 18. so as you can see there are like two axis of
course uh the y-axis uh asset is eth so that price we have kept it as constant for the turf but if you notice the it's access price that is decreasing over time so the initial value that we use is pretty high and then uh the final value that we have is low right so the idea is that the nft price which is on the uh the nft asset which is on the x-axis that price should decrease over time and that's how we configure and the duration for evolving the pool that we've used is eight hours in this case right so basically what this means is that the Curve will evolve up till eight hours from deployment and after that the price is gonna be constant so after eight hours the price won't decrease the price will go to a minimum and it will stay
there uh now I'm just gonna uh go into the truth side of things uh okay okay yeah okay yep yeah yeah so uh if you see uh this is our uh Constructor looks like these are the five parameters like I mentioned that we were using while we deployed the pool so if you notice uh in this contract we are not to using any storage so with all of the computation because
of the dynamic curve happens real time so we are not uh storing anything uh on chain uh per se in this contract so uh that's why we save on uh you know the gas costs as well uh because we do the competition uh Real Time with the equation that Elisa mentioned before so we have a library here which is this uh where all the equations are defined in and uh if we uh yeah if we grow here so you have the A and B values that we have mentioned here which are derived again using the equation that we mentioned in the slides so uh basically what this means is whenever any swap or any you know trade Hub any liquidity addition happens or
withdrawals happen we update we calculate and compute A and B real time which are the uh which basically Define how the curve evolves and then basically you can do any operation uh you know all the operations that are done on the pool basically modify a and b real time and we use those values to you know identify what the curve looks like now and then uh calculate the lp amounts or the amounts you get on Swap accordingly right so yeah so all these functions that you see to swap uh you know or deposit everything uses the A and B values internally and uh and yeah so everything uses A and B
values uh right like I mentioned and we determine the final point in the curve uh the fine the price during that uh you know after uh the transaction ends I mean at the end we determine the price or the position in the curve and the curve evolves accordingly so this is how uh this uh the evolving Proteus Pool Works and like we mentioned before this is only one slice so we have only one curve which evolves over time and after that duration it evolves over a duration and after that it stays constant so yeah this is uh evolving produce uh happy to answer any questions okay I think that's it guys
[Applause] thank you both for uh this in-depth session about shell vertical [Music] foreign [Music]