A walkthrough of different generation DEXs and AMMs

ETHCC 4 · July 2021 · 29:34

Shresth Agrawal traces the evolution from early order-book DEXs to AMMs and newer exchanges optimized for capital efficiency and gas use. He considers cross-chain designs and systems that aggregate liquidity from other exchanges.

Speakers

Topics

From ETHCC 4, hosted by Ethereum France.

Transcript

can you see my screen so hello everyone i am trace and i am a back in dev and algorithm designer at paraswap which is a decentralized exchange aggregator and today we're gonna have a walk through of different generations of dexa and am and how they have evolved and what can be built next so let's get started uh before we start i would like to give a special thanks to muner founder of parasoc michael from curve fernando from balancer as while i was preparing for my presentation i thought the best way to get insights about

nexus and emm is to ask the founders themselves who have built them so yeah i've got a lot of very useful insights and thanks a lot for that so a quick into what are dexes and emm's so a one liner of dexes would be that is our decentralized exchanges where you can swap tokens directly from your wallet to your wallet without using without transferring your tokens to a third party so you always have the authority of your tokens and amms are types of dexes where the pricing logic itself is programmed into the smart contract so it's automatic now let's jump into the

generation one of the taxes i call it the beginning and the first is ether delta i think this is the first major decks it was an order book based x and i think that was the major issue maintaining an order book on chain is very expensive as well as the ux i mean it was the first deck so the ux was not very good it also had some hacks and after that was the 2017 ico era and during that time a lot of projects were funded and i think three of them were dexes and i would like to point out 0x

bancor and kyber 0x and kyber they were also similar to ether delta as they also had order book based text while bancor wasn't i think the first emm as far as i know and the way bank or work was bank or work was using constant product formula and let's look let's look into how the pricing works for for bank firm so let's suppose you have a pool of token a and token b the the main idea is to maintain this variant that the product should be constant

so the the reserve of token b times token a should be constant let's look into an example so let's suppose you have a pool of avocado and apple avocados and apples and initially you have six apples and eight avocados so your constant product invariant would say you should always have 48 fruits now let's suppose you want to swap using this pool and you put two apples to get avocados and as soon as you put two apples the total number of apples in the pool is eight apples so you would get out six avocados you would get out two avocados to maintain the variant that later on the pool you would have eight apple times six avocado equals to

48 fruits but let's suppose that you you have you swap four more apples so then you would have 12 apples in the pool and you would get only two more avocados out so you see that for swapping for getting two first two avocados you only require two apples but for the next two avocados you required four apples so if you look the price per unit curve of this of the constant product invariant it looks something like this and just this like the simple pricing equation was programmed into the bank or amm

um i think the second major important factor about amm itself is the incentive to provide liquidity with uh order book based dex you have to continuously put orders but with a with an amm you can just passively provide liquidity and you receive fees over that liquidity so i think a mms definitely have an edge over the order book exchange and bank car was first of the first in there but still it did not get as much adoption as it could i think the major issue behind that was it was because all the pools were paired with the bank or token which was

i think slightly greedy approach so every time you had to swap from token a to token b you had to go from token a to bank or and then bank or to token b also the gas was not very optimized so yeah so in summary the generation one dexes were i mean the order book was expensive order book base texas were ex were expensive to use uh they didn't had good enough ux there was not enough incentive to put liquidity and bnt pairing even though banker was a good amm the bnt pairing was a very greedy approach then comes the generation two taxes i think

this was the inflection point and i would like to point out the first one as unison p1 i'm not sure if this is the logo for unisoft v1 because i did not find what's like i found like two different logos and i was like okay maybe this is the one uh and the main idea so unicorn p1 was similar to bangkok but the major difference here was it was much more optimized in terms of gas and second it used eat as a pairing and i think that was quite it was better than pairing using bangkok

and then the second major decks in generation two was curve and the main issue that curve saw was to when you want to swap too stable asset and if you use the constant product formula you can incur high price impact if you swap big volume but using curve uh you can do that with very low price impact and the weight curve works and let's understand how the waker works so before we do that we need to understand another invariant which is the constant sum invariant and i think this is the most natural pricing curve so it's basically you fix

a particular ratio between the two tokens and it would look like you know a straight line so if you move along the curve like the the slope is same so the pricing is same the main issue behind the constant sum invariant is if the price inside the pool is different from the price outside the pool you can end up with just one one of the token like like just one of the token in the pool and there will be no incentive to rebalance with the constant product invariant that we initially discuss if the price is different in the pool and the price outside then it's there is an arbitrage situation and the arbitrage basically

makes sure that the pool price is automatically rebalanced so with curve what was proposed was something in middle so the dotted line is the is the curve for the curve and it is basically a curve which is which is in between of the constant like a constant invariant like constant sum and we are in a constant product invariant and seems out that that worked pretty well and if you look at the price per unit curve for that you will see that it will be this the price will not move drastically when you are when when you are near to the pricing

curve and only when you buy very huge amounts that's when your price follows the constant product so after the generation like after the curve i think the most important is balancer and to understand before we get into how a balancer works it's important to understand in permanent loss and let's let's look into the previous example that i gave with apples and avocados so in the previous example where you had like let's suppose you were the initial liquidity depositor in this pool and you deposited

six apples and eight avocados and let's suppose initially the price of all the apples were one dollar each so the the idea with the constant product invariant is you deposit the equal you deposit the equal value into the pool so the price of per avocado would be calculated six by eight so that it will be equal to six dollar each so you have six dollar worth of apples and six dollar worth of avocados which is basically 12 worth of liquidity that you initially provided then let's suppose that avocados got more expensive people want to get more fit so avocados are less in the

market so now you have 12 apples in the pool and four avocados you can see the invariant is still maintained so 12 times four is 48. but and the apple prices are still the same so you have 12 times one is 12 but if you calculate the price of avocado it will be 12 divided by four as we know that the value of both should be same you just have four avocados and so it will be 12x4 but if you look into the initial portfolio that you had before you deposited you can see the worth of that portfolio in the current situation is higher so it would be basically six apples which is six dollars

and then twelve twelve by four times eight which will be which will give you a total of thirty dollars so you have six dollars higher than your initial like then what if you would have deposited so when so there is a risk involved when you deposit to an amm and with with the uni swap and the bank or model you had equal risk on both the both the tokens or both the assets that you deposit but with balancer you can have a much diverse portfolio with different ratios so you can say okay i want to have

30 exposure in 20 exposure and die and rest in wbtc and you can create pools with maximum i think five tokens and you can have a portfolio which is self-balancing so that is the main thing that balance has brought into the decks um then came uni swap v2 and the main difference between unisof v1 and v2 was it removed the pairing with e so now you could have both tokens to be arbitrary and second the ux was also improved so we had much simpler like the ui was

better and you could basically just take arbitrary tokens and then just give approval and simply swap so i think and then the next important decks was sushi swap um i think the the launch of sushi swap is very interesting because it used something called as a vampire attack the way vampire attack worked was it basically incentivized the uni swap lp providers liquidity providers to deposit their liquidity into sushi swap and the way they did it was so people who deposit liquidity in uni swap

they received lp tokens the liquidity token like the pool liquidity token they can take this token and deposit into sushi master contract and then they can receive high sushi rewards for that and internally the sushi master contract has rights to basically migrate the liquidity from municipal sushi and this basically made uh sushi swap to grow liquidity pretty quickly and after basically we had like the launch of sushi sushi token i think unisop also saw benefits in having its own token like providing incentive to to provide liquidity and that's when we

like there was the uni swap airdrop and also there was unisoft liquidity and i think during that time was the main inflection point for nexus i took just a charge from d bank for the total traded volume and you can see in the late 2020 we see like the volume started growing drastically and this was just the time when you needed the airdrop and there was this sushi swap launch and i think at this point uh also in the generation two texas i think it's it's important to mention dex aggregators and uh i would like to of course advertise parasol here

so you know when you have liquidity distributed in so many different indexes it would be it would get it would get very hard to actually swap when you when you swap from one ticket to another because you would have to go to different taxes and compare prices to swap and that's when you can actually use a text aggregator you can simply just put the from into token and the dex aggregator so parasol here would basically find you the optimal route even using multiple token and multiple exchanges at the same time so yeah at this point dex aggregators were also in the boom and in summary the generation to texas had much better ux

they had incentive to provide passive liquidity and we had high performing pools for stable asset but we still had issues with generation two the i think the two major issues was was were low utilization of liquidity for non-stable asset pools and because there were so many d5 protocols there was basically a gas was on fire because there was a lot of congestion in the ethereum mainland and let's start by solving problem two so i think uh the problem to itself with gas i think it needs to be solved from the layer layer one

basically and a quick solution that that we saw was the rise of side chains and that was basically bsc polygon and phantom i would say these were basically partial layer 2 side chains as layer 2 itself the real layer twos were delayed and these were evm compatible so people could quickly just take contracts from mainnet and deploy here and as the transaction congestion was way lower on these side chain the gases was also way lower i mean it's still very less like you can do a swap in in polygon in less than cents while

you need i don't know what's the gas price now but during during that time you would need at least 40 dollars to do a swap in uni swap and uh i just made a fun picture of all the uni swap forks so all of like all these side chains actually just had forks of the projects that were there on the main net and the most of the forks were unisoft works and as as i'm working in a text acquirer i have to deal with adding all of these decks and i think there was so many different indexes with so many funny names it was quite interesting to make this particular slide i would say and of course using taxes on side chains

using a text aggregator is much better because you can you can swap using multiple indexes while only needing very less gas so you can see dex aggregate dex aggregators would be much more handy with with lower gas and now we come to generation three taxes and uh what's the time i hope i'm not getting more time okay i have time um yeah so generation three dexes were majorly focused on optimizing the liquidity so we saw like with curve you could swap two stable assets with low price impact but

you with uni swap with the constant product invariant you if you want to swap high volume you would need to have very high liquidity otherwise you will have very high price impact and this was the major pain point that we solved with the generation three dexes and the first one i would like to mention is dodo dodo uses a similar pricing curve like the stable swap in variant but it works for non-pegged assets and the way it does it is using an external pricing oracle and the b the idea is you can move the stable swap in variant near the peg price based on the external pricing and there's the catch here that

because it uses an external pricing morocco the pricing oracle can be front run so you could look at the transaction that's going to move the price and do an arbitrage using that so the second major decks in the generation 3 is uni swap v3 the main idea that uni swap v3 brings i mean it's very latest now is basically the concentrated liquidity and instead of so with unison v2 where you provided liquidity for the whole price range here you only provide liquidity

for a small range of price so whenever the price is between whenever the current price is between your range where you provide the liquidity uh your liquidity will be used in a concentrated way but as soon as it moves outside the range all the liquidity that you provided will be swapped into the other token and this definitely was a breakthrough because it is i mean it is a breakthrough because it definitely utilizes the liquidity in a much better way and people can have higher fees but it comes with a few catch catches i would say

first of all first one is liquidity providing is no more passive so you would have to actively maintain your liquidity position which is much tough like it is for a for a normal user who who is not a market maker is not very easy to move the the price like the the price basically and also the pool tokens are no more erc20 so providing incentive for liquidity mining is much harder because it is it is in form of an nft so you cannot quantify whose liquidity is higher or lower uh then the major generation three decks

is balancer v2 and the main idea that balancer v2 brings is to abstract out the pool pricing logic from the main balancer wall so now you can deposit all your token in a single world and you can have different pricing logic so currently like the balancer v2 was using the constant product invariant and as we know that constant product in variant is not optimized for stable assets so we can have a different pool implementation where you have stable swap in variant using the same balancer world

so that that was that's pretty good also it is much more optimized in terms of gas so you can use multiple pools and you would use way less gas as you would do in balance 32 and then i think is the most important is curve v2 i think this is the killer i because i think it solves most of the problems uh it still uses the stable soft invariant but it works for the non non-pegged assets and the way it does it is by it doesn't use an external pricing oracle it moves the peg on chain so it calculates the profit and

it moves the peg of the stable swap invariant on chain i think the best way to understand more is look into the curve v2 white paper it's very interesting um yeah so after looking into the generation three dexes you might be thinking what lies ahead what can be built in indexes and um these are some of the points that i i got while i was talking to different founders as well as some of the points that i have personally while working in the texas a m space and the first one is improved pools for non-stable assets so even though curve went quite ahead

uh on on or having highly optimized pools for non-stable assets i think there is still a way to go second is getting rid of impermanent losses completely yeah it will be super good if we don't have impairment losses at all for non-stable assets third is composable cross chain pools as we see that we are having a lot of different chains coming coming along and in future i think there will be multiple chains it would be good to have exchanges that were crushed chained i think there are already quite some efforts done by any swap and torsion which are which are trying to do

stuff like that and then i think this is slightly non-technical but very important is clarity in legal regulation regarding dexter and eminence i think this is one of the biggest problems that most of the founders they mentioned to me and then i would like to personally see collaboration across dexes to solve bigger issues so i think we are still way smaller than like in trading volume as compared to the centralized exchanges and there is i think a lot of scope for improvement and i think those can only be done when we have collaboration across texas rather than comparison between the taxes

so yeah that's it and i would like to say that i missed out some of the interest indexes but just because to keep it short and yeah thanks a lot and i'm open for questions sure sure so uh

i would so first of all like i am i don't know a lot of details about the math but i can give you a general idea of how it works so there so you have so you have the stable swap in variant and which is similar to what what you have with the curve v1 but the stable swap invariant one like needs a pick price where it went where it has a similar price to the constant price and variant and this spec price um the main idea is somehow you need to calculate this like the movement of this prep price on chain and you need to do that in such a way that the liquidity providers itself they

don't incur any loss and that's basically what the curve v2 brings us basic is they they have a way to calculate the profit of the of the liquidity providers and then they they try to move the peg in such a way that you don't you don't incur loss so that's that's the basic idea behind that uh no you would still have impermanent loss i think uh so with v1 you would have

less impermanent loss because in in v1 you you are just around the stable peg always so you will like so in v1 because you you just have stable assets you will have definitely less impermanent loss than what you would have in v2 because here your prices are not not stable anymore right so you still move yes we do support uh multiple chains we

have polygon spot as well as vsc and yeah i would look for i'm looking forward to have swaps cross chain but we don't have any road map for that yet uh no no we we don't have that yet but i think i i think it's possible to build that um using something like polygon bridge at least one side um but yeah there is there is i mean we are looking into that but there isn't

any specific plans yet we are definitely looking into that does that answer your question thank you you