What Are Liquidity Pools?
Crypto Valley Conference 2021 · October 2021 · 22:07
Mark Richardson of Bancor gives an introductory talk at Crypto Valley Conference 2021 titled What Are Liquidity Pools? The session explains liquidity pools, a building block of decentralized exchanges and DeFi trading.
Speakers
Topics
From Crypto Valley Conference 2021, hosted by Crypto Valley Association.
Transcript
[Applause] [Music] mark richardson i'm the head of research at bangkok actually i used to be a an organic synthetic chemist and a research scientist uh i actually joined um the the banco protocol as a dow member back in october of 2020 and after collaborating with the re the bancor founders and some other community members um the bangkok foundation offered me a position with uh permanently leading uh the research efforts at the protocol so i'm very excited um to be here talking with you today i'm sorry i can't be there in
person but hopefully we'll have an opportunity in the in the future to to meet each other this uh presentation is actually geared towards people that are sort of new to uh to defy okay so i have a i've taken an approach of very minimal um assumes knowledge and i'm going to walk you through some of the things that that automated market makers like bangkok do and i think that this should give you a pretty strong foundation in understanding one of the the major financial and economic primitives that are currently operating on on the blockchain so bancor is a an automated market maker it lives on the ethereum blockchain for
now but we're likely going to go multi-chain and onto layer 2 relatively soon and it uses smart contracts and logic called liquidity pools and so i think it makes sense to begin first by asking the question what is a liquidity pool a liquidity pool is just a a store of crowd-sourced capital uh smart contracts are you know exclusive to to the blockchain environment and they're special because uh anyone who has any amount of money can kind of contribute to it um and most of the sorry
the profits that the liquidity pool uh generates are always shared pro-rata to all of the users that contributed so a liquidity pool is really just a container that contains contains assets an automated market maker is a much more sophisticated piece of technology and automated market makers make use of liquidity pools in order to achieve exchange so um if there are two different liquidity pools that contain um different types of assets then an automated market maker is the logic right the computer program that sits over the top of these liquidity pools that determines um how much of one asset
can be exchanged for another and what the the fair price for those assets are and um automated uh market makers have become you know something of a goliath industry onto their onto themselves bank hall was the first um you know it had a fairly successful ico uh fundraising uh back in 2017 but since then the idea has been iterated on many times and it's now one of the the most prominent uh technologies in in d5 and it's it's very popular uh quite profitable for for some and um i think it's becoming or it's beginning to show us
that it has the capacity to really start fueling the world's global financial needs and the reasons for this is that these um these protocols these automated market makers they are doing what they do uh despite not having any government or regulatory oversight and for the most part um they only ever do what the uh what its users expect them to do there are some sort of fringe cases where naive project developers have implemented you know less than sound code or you know there have been some deliberate um
deliberate scams and other things that have made off with with uh with community members money but those are really few and far between for the most part um the the oldest protocols like bangkok like ave like um like uni swap and kaiba swap these are all very legitimate um very legitimate uh enterprises and they are continuing to do what they do um without anyone uh sort of policing it which i think is a a a really strong indication that this uh this idea certainly has the the fortitude to continue so the rest of this presentation i'm really going to be taking a deep dive
into precisely how automated market makers work and this used to be a much more simple question than it is since uh bancor introduced the um the first iteration of the market maker back in 2017 there have been multiple iterations on the idea and there are now uh several different flavors types you know the uh the programs that has evolved in such a way that there is now identifiable sort of species of of amms and they all operate according to a slightly different principle some are specialized at achieving uh trades of predictable value others are more well-suited to um to volatile asset
pairs and things um but today i'm really just going to be focusing on that um that seminal idea which is the idea of a constant function pricing algorithm and we're going to be looking specifically at the constant product pricing algorithm so this is a this is what we call a bonding curve if you're new to the industry you might have heard this word thrown around without anyone ever actually explaining what it is it is simply the graphical representation of a pricing curve that a an amm would utilize and so in this case um the this curve this hyperbola or current section
it is the uh every single point that uh the ratio of the two assets inside the liquidity pool must adhere to um all of the points that are outside of this curve um are are considered illegitimate and so this is a just a a way that anyone who is using the protocol can be certain of exactly what its behavior is going to be um it gives them the the confidence of of the price quoting um and uh and and yeah it is the fundamental um function that that drives all the the pricing behavior that um the users are exposed to
so now we're going to use this bonding curve in order to achieve an exchange so we have a user here who wishes to exchange some x tokens or some x asset for a y asset and they're going to be using the bonding curve to do this so let's assume that they have 10 of whatever x is and they're going to be exchanging that for some number of y tokens now we don't know ahead of time um what uh what number of white tokens they're going to get until we have a look at how the automatic market maker processes that input um in order to generate the the correct output so for this example we're going to assume a bonding curve with 100 of each of x and y and these are going to be x 0
and y 0 and if you multiply those two numbers together you get 10 000 and this is the the product right this is the constant part of the pricing algorithm and somewhat unhelpfully uh that's also a mystery the product is actually allowed to change very slightly and the reason for this is that it allows the the liquidity pool where these assets are providing exchange liquidity to accumulate value over time and so you can think of this as like a fee or a commission paid by traders true liquidity providers um for the service of supporting liquidity for their for their trade the protocol
like i said before is the the layer that sits on top of this liquidity pool that has all of the logic and all of the functions inside of it that determines the behavior of the um of the the exchange okay so it's going to basically take in all of these inputs the current state of the liquidity pool and the uh the traders request and it's going to process those to generate a bunch of outputs in this particular case if we take um if we are trying to analyze what's going to happen to the liquidity pool we have a look at these three equations the simple one is just what happens to the x balance inside the liquidity for so when we update the balance to x1 all
we need to do is add the amount of x tokens that the uh that the trader was hoping to sell right so the the liquidity pool absorbs all of those x tokens we just add them together so 110 um adds together to 410. um the y balance is more interesting though so remember this is a constant product algorithm it means that whatever number of y tokens remain inside the liquidity pool at the end of the trade when multiplied by the balance of x should equal some constant in this case 10 000.
however we're going to be iterating that um that constant a little bit um to compensate for the fact that a fee is being paid okay so that the the liquidity inside the pool is accumulating um at some rate and so using one percent just as a convenient number and representing that with the uh the greek letter delta you can see how the uh the balance of y tokens inside the liquidity pool are changing um with this uh this function in the middle and also how the product is changing and so these equations they literally do sit inside the smart contract and are executed every single time a trader wants to perform a trade and the liquidity providers essentially
agree to using this logic when they provide liquidity to a uh to the to the protocol so these now are the the outputs that are associated with the the final state right the state of liquidity pull after the trade but we also need another output which is the the number of y tokens that the trader is going to receive and for that there's a another function which just calculates the the y value that the um that the the trader should receive and luckily you know you can see here with a quick sanity check that the um y0 number minus the y1 number which were you know y1 was determined by its own
function is equal to 9 and this function here is also generating 9. so it makes sense but i just wanted to find out that there is a function that handles this exclusively and so what what is happening here is that essentially the liquidity pool says okay i'm accepting these 10 x tokens from the trader and i'm going to um then send the trader nine of the y tokens and that completes the exchange so at the end of this process the the trader no longer has any x opens they they sold 10 of them and they have bought nine of the y tokens and the state of the pool has now been changed such that it has ten extra uh x tokens that it
started with and nine less white terms than i started with and it's um interesting to point out here that the ratio of x to y inside the liquidity pool has now changed and that means that the price of y is also changing so we can see what that looks like if we zoom in a little bit we know that the trader added a certain number of x tokens in order to extract a certain number of y tokens and so you know using the common uh financial linger we're just saying that they are selling x and purchasing y and what you can see here is that you know simply by um by dividing the amount of y tokens extracted by the amount of x
tokens uh deposited you can um you can crunch an effective press for the for this trade and that's completely legitimate but note that it takes into account the slippage right which is a word that we use in d5 means the same thing as spread essentially what you might get on an order book but it basically means that it accounts for the fact that the price of y has changed as a result of the trade being executed and this is why um amms are so powerful right they have intrinsically the ability to change the price of a token versus another token you can generalize this without having to uh you know without having to uh perform an
actual trade this way or even emulate or simulate one of these trades and just know the spot price right the uh the price quoted by the by the amm at any point in time just by having a look at the reserve ratio is contained inside it so for example if we rearrange the um the bonding curve formula to make why the subject and then perform a uh if we then take the inverse negative differential of of the curve we can generate a pricing formula which in this case is just x squared of k and that is fortuitous because it means that at any point x along the curve we can know that the spot price of of y which is really
helpful and the uh the reason why uh this method is so robust for the constant product in particular is that it's acid topic right the the hyperbola will never actually touch either the x or y axis which means that any um any ratio of tokens will generate a specific price so tokens that have a a very close price or you know a value relative to each other that's relatively close we'll sort of sit close together but then we can also price tokens that have dramatically different values so for example we can price something like usdc which is a uh an erc representation of the us dollar on ethereum um versus something
like bitcoin which is worth now sixty five thousand dollars so the uh the balance of the assets inside the liquidity pool will always readjust right in order to in order to reflect where the the actual market rate it's worth noting though that in order to achieve this um someone has to trade with the pool right they actually have to move the um the the relative ratio of these two assets in order to achieve that price and that of course is performed by arbitrage so this brings in a concept that is extremely important to a mns called impermanent loss and we're going to spend a little bit of time discussing it right now but i think that it is poorly understood and there aren't
really any good reasons for it to be poorly understood think of it this way if the um if you're always trying to to drive the price of y ins inside your bonding curve to higher values then there has to be less of y right that is actually what the bonding curve uh means it's an inescapable reality of how this pricing curve operates so as the value of y is increasing it means that its relative quantity is decreasing another way to say that it's exactly the same statement just in slightly different terms if the relative quantity of y is decreasing then that means its value is increasing what this means is that if there is an
asset that's extremely valuable that traders are interested in purchasing then as its value is increasing your exposure to it is decreasing as a liquidity provider you're essentially accumulating the um the the underperforming asset and selling off the the more performant asset and this is very difficult to deal with and so i like to think of it as a a type of seller's remorse but in a quantitative financial sense you can calculate it pretty easily um just by having a look at terms that we already get out of the bonding curve so it's relatively trivial to demonstrate that the automatic market maker portfolio value at any time is always twice either one of the reserves
right in a constant product um in the standard 50 50 pool as we call it um you can just take one of the reserves and just multiply it by two and the reason for this is that um both reserves have an equal value um even if they don't have the the same number of tokens inside them a hotel value means um to uh to imagine that rather than provide liquidity with tokens at some point in time that we kind of created an alternate history where the liquidity provider instead did nothing at all right they just held their tokens in a cold wallet or something like that and didn't provide liquidity this means that they're not earning any passive revenue right so there is no fees accumulating on their tokens but they're
also not exposed to this divergence this divergence risk that the the liquidity providers under an amm are and so then impermanent loss is essentially the ratio of of these two values and then you subtract one at the end just so that we get a negative number if you're in loss and a positive number if you if you're in profit you can then uh take the the terms associated with both of those and generate this function um which is a really helpful way to to analyze profits and losses on a m strategies so the important part here is that the x1 and y1 values they increase over time as as trade volumes
increase on on the liquidity pool so it's possible that even if the prices are diverging that the fees paid by traders can easily offset the impermanent loss and for um for most cases this is actually the case the um the impermanent losses is negligible compared to the fees earned and this is why amms can still be a winning strategy despite the exposure to this however there are certain token pairs where the the impermanent lost exposure is catastrophic this can often be heartbreaking because many in the community uh provide liquidity with tokens that they have a deep belief will outperform the market and don't really realize that they're kind of
hedging against it it's a type of option straddle if you like by by providing by providing it as liquidity on an amm and so as their token becomes performance they end up selling it off and that's that's that's sad and so what bancor is doing is kind of trying to challenge that this is something that that liquidity providers need to be exposed to at all we are the only amm that has an insurance policy in place that protects liquidity providers against this happening so if you are providing liquidity with a token that goes like 100x in value or 500x in value which in cryptocurrency is not unheard of then you are protected for the um the
full exposure to that asset so you even if you had to sell off some of that asset in providing liquidity bancor basically has an internal mechanism that refunds you that that difference and we think that this is going to be really important to um to creating stability in dfine especially the um the amm space we this is really deeply important to us right we we don't think that um this uh tendency for protocol creators to gravitate towards things like leveraged um leveraged strategies and things to try and mitigate impermanent loss is very healthy and um we already have ample evidence
that these kinds of strategies are having a negative impact on the space so for example this is a tweet from just a few days ago where a liquidity provider on uni swap b3 which is one of these leveraged amm protocols um actually caused the the the token price for which he's providing liquidity with um to drop considerably to about 10 in a few minutes and the reason was that they were forced to withdraw their position as it was out of range no longer earning fees and then sell half of that position in order to reprovide liquidity if they were on a standard bonding curve that was non-leveraged then they would never had to to do that and so the market would have been spared um spared this effect so i do think that this is a
conversation that we need to be more mindful of and um and bancor will be having it right as we enter into next year you can expect to hear a lot more from us we are releasing a lot of our internal research now on on how different amms perform and the the good news is that um this kind of hyper efficient leveraged you know risky strategy is not any more profitable than the um than the the the stable lazy strategy which is the one that we are um advocating for and so thank you so much for your time um if you have any questions i do encourage you to reach out to me telegram is um the best place to to reach me uh but you can also uh contact me at marketbancor.network especially if
you would like to organize a meeting that's the best place to to do it and please consider following me on twitter and