An Introduction to the Mechanisms of Bancor 3

Crypto Valley Conference 2022 · June 2022 · 37:26

Mark Richardson of Bancor leads a master class at Crypto Valley Conference 2022 introducing the mechanisms of Bancor 3, the third version of the Bancor protocol. The session is an introduction to how that version works.

Speakers

Topics

From Crypto Valley Conference 2022, hosted by Crypto Valley Association.

Transcript

right wonderful we are back thank you all for being here um we have one last session before the next coffee break so stay tuned now uh we have mark uh from the manchester foundation that's going to be telling us a little bit about the mechanics of bancor and how everything works so let's yeah give it a round of applause for mark [Music] thank you crypto valley yeah so my name is mark richardson i am the product architect and the head of research at bancorp protocol which is a decentralized liquidity system built on ethereum and i have designed this presentation to sort of appeal to the widest possible spectrum of different assumed knowledges

and also different backgrounds so just be aware that there are going to be some slides which you know i kind of break the golden rule of never displaying any equations because i know that there are people in this audience that will be interested in precisely how bank or version 3 is designed to operate and how it makes liquid markets if your eyes glaze over when someone is showing you and walking you through some of these mathematics just be a little bit patient with me because i have some other more helpful more intuitive ways of demonstrating these systems that i think you will find very helpful now in the spirit of um you know having no assumed knowledge can i just get a quick show of hands who knows who can articulate what a

liquidity pool is okay it's about half the audience for those streaming in so um in these few slides i'm just going to quickly describe what these are at least what i how i would articulate it and i would call a liquidity pool just a smart contract that contains crowdsourced capital right crowdsourced meaning sort of decentralized coming from many individuals rather than from a singular source and i think that this is a helpful generic term for a liquidity pool because it covers all kinds of different use cases for example a lending protocol could be called a liquidity pool or a yield aggregator could be called a liquidity pool and a um you know a

sensible next question then is what is an automatic market maker again quick show of hands who thinks that they could articulate on stage right now what an automatic market maker is okay maybe that 20 of the audience i consider an automatic market maker to be a protocol that allows liquidity pools to exchange cryptocurrencies with each other okay and i hope that that is a a fair enough definition but i think the more interesting question is why are automatic market makers important right why did bancor invent this technology in the first place and that one is maybe slightly more difficult to articulate i won't ask the audience whether or not they could do it but for me automatic market makers are a part of an

emerging decentralized global financial network and what is much more important than just the fact that it has a global financial network behind it and the fact that it's decentralized but it is organic right an automatic market maker is very difficult to trick it doesn't get uh passionate it doesn't get emotional um it doesn't panic when something is happening and with the the way that traditional markets are run you generally have an emotional being behind a computer somewhere that is making decisions that actually have global ramifications at times so for example i remember the 2008 financial crisis when it was revealed that um you know one of the one of the currencies was um

you know partially collateralized in excuse me was partially collateralized in one of the one of the banks stocks that went belly up the market panicked and it's not necessarily because all market participants everywhere in the world all panicked at once but because a few centralized entities got nervous and they kind of panic on our behalf and that is why i think automatic market makers are important because they are algorithmically determined and they do not have emotions and they tend to respond in very predictable ways so why then are they able to work or what makes them work what makes them function

and this is where we're going to get a little bit math heavy but i promise it will be over in you know it will be over fairly efficiently and so just bear with me if you don't like these slides but the method that we are using and bancor developed several different types of bonding codes when it first launched the banco version 3 uses just one of them which is the constant product bonding curve who's seen this picture before right almost everyone terrific but i wonder if anyone could describe what it is or what it does right maybe if you're a geometry student or something you would recognize this as a hyperbola or a current section or something like that but really what it is meant to be portraying is all of the discrete points

where two different reserves have some value so if x and y are two different assets then this line this curve is all of the different ratios that a liquidity pool or an automatic market maker is allowed to have we call this a bonding curve if you don't know the nomenclature and so let's just quickly walk through how a bonding curve operates i'm going to do some of these calculations for you again it's not too much of a headache so let's assume that x and y in this case are the b and t token which is the the native token of the bangkok network the universal numeraire token and why we're going to let be chain-link which is one of our deepest liquidity pools now

the uh bonding curve is about to perform its role right it's going to accept some input from the user perform an exchange and then deliver the token that the user wants back to them so let's assume here that the user wants to swap 10 b t tokens for some number of chain link tokens and it's up to the protocol it's up to the algorithm to determine the outcome of this transaction for the constant product bonding curve we're going to assume two different reserve balances of 100 each which means that under this hypothetical bnt and chain link have the same price now we call this a constant product bonding curve because when you multiply those two reserves together you get some number and the idea is that that number is supposed to remain constant hence

constant product now that's a bit of a misnomer because it's not really constant there is a small commission that allows the constant to slowly drip off over time and i'm going to come back later in this presentation to explain precisely why that is but just remember that it's there for the sake of these calculations i'm actually going to leave it because i expect that some of you may want to refer back to this presentation later maybe for self-study so the protocol's job is to take all of these inputs the state of the bonding curve and the user's request and process that into a trade and this is essentially the mathematics that determines that i'm not going to walk through this but essentially you are taking uh x 0

which is the you know the the first state of one of the reserves with that pool and you're adding x to it which is the amount of tokens that the user was hoping to swap and that is going to deliver a new state for the pool which we're going to call x1 y1 is the same thing slightly different equation but generating another valid output and k we don't generally calculate this on the contracts because it's unnecessary you can deduce it from the state of the curve but if you wanted to calculate it this is exactly how you would do it so these values then become the new state of the pool right this will be the the new balance in the smart contracts in the next block on the ethereum blockchain what about what the user received

so we have an equation to determine that as well and you can actually intuit that this answer must be right right you could write like a unit test or something for this because here you can see that y 0 on the left hand side was 100 and the amount of y 1 that we have calculated below it in blue is 91 and the difference there is nine and that must be the amount of tokens that the user is receiving and so the fact that we have like an independent source of truth for that this swap amount is what the user is receiving is nice but you wouldn't necessarily build that into a protocol because you can deduce one from the other but this is the result we've now completed the swap the algorithm has done its work and the bonding curve is now at a new state the

user has lost all of their bnt tokens and have received the correct number of link tokens now this is the part that i hope that some of you are being patient for which is i know that some of the you know the geometric portrayals of these things the algebra is if not confusing at least boring and so i thought that i would generate for this conference a slightly more intuitive way to think about what it is an automated market maker is doing right what does it mean when you take 10 b t tokens and move down a bonding curve to some other point on it imagine you are a apple merchant and rather than price all of your apples at exactly the same price we're now

going to apply some arbitrary rule this arbitrary rule is a type of algorithm and you could use constant function right you could use something like the constant product or constant sum or whatever it happens to be but in this case we're just going to say the first apple is worth one cent right the first customer that comes into your business and purchases the apple you charge them one cent but as soon as that apple's gone the next apple is gonna cost two cents and so on and so forth fourth apple fourth since fifth apple fifth sense now just reading off this chart you can see that the protocol is always quoting a price that you can buy the next apple for

it's also quoting your press that you can possibly sell the apple back to the merchant for right and these are the two different values so if we kind of let this thing play out you can imagine that whatever the market is determining right however many apples are being bought from this store is driving the price of apples up and then as people sell apples back to that store it drives the price of apples back down and this is that kind of natural breathing in and out of the markets right i hope that many of you would have an appreciation that this is kind of a very elegant you know mathematical demonstration for things like supply and demand as the demand for this for apples is increasing their prices going up but just as a result of the algorithm that we created you don't

need someone to quote it but now think about this situation from the viewpoint of the apple merchant that they've sold these apples and realized some sort of price we can see that at this point in the in the simulation that they have sold four apples uh one two three and four cents for a total of ten cents but the current market price of apples is now four cents and so if you take the number of apples that they sold and multiply it by the number uh by the current market price what you'll find is that they've actually made an apparent loss right it's not a real loss it's a kind of a virtual loss but what it means is

is that if they had instead not set up their apple economy this way and waited for someone else to set it up on their behalf they actually might have made a greater profit than being the thing that actually supported that price discovery in the first place this is a bit of a paradox that's 16 cents by the way i'm going to refer to this as the huddle value which just means the you know the valuation of your portfolio when you decide not to make markets with it and of course the idea is to beat that value right if you are providing liquidity which you know has transaction costs it's got the you know the stress of learning how to use use a new protocol if you're not making additional value out of that activity

then why would users continue to perform that activity which is a big problem because as i just demonstrated in the the slides leading up to this i do think decentralized liquidity markets are critical to making sure cryptocurrencies cryptocurrency markets continue to perform the way that they should so this 60 difference in value we often call an impermanent loss the reason it's impermanent is that if the price of apples goes back to one cent technically the liquidity provider hasn't actually made any any losses and their whole value becomes equal to their um to their market making value now for the more mathematically inclined there is actually a very easy way to describe this which is if you take any two points on the curve be aware that

there is an infinite number of different gradients between any two points on this triangle and you are actually selling all of those infinite number of prices on the way to any other point and so rather than having these like one cent um you know buckets that we were selling apples at it's actually a full continuum which is why we call you know liquidity um liquidity pools and amms a continuous liquidity product so the only thing you need to appreciate is that as the thing that is going down in quantity as it goes down in quantity its value is always increasing and there is a you know these are

redundant statements if the quantity of something is decreasing its value is increasing and as the value of something is increasing as quantity is decreasing these are symmetrical arguments and so if you want to derive an equation to actually calculate it without having to refer to number of apples sold or something like that because you've got an infinite sum there there's actually um you know you can rearrange the or you can define sorry the the value of the automate automatic market make a portfolio this way and the whole portfolio value and then just compare those and you get this expression out and the good thing about this particular equation there's so many different ways i've seen in permanent loss represented is that this one has no knowledge of us

dollars no euros like nurse you know swiss francs it is just the percentage that you would have lost relative to not doing anything at all and it's not denominated in any currency this is a unitless number so the question is how can you make this profitable if you're always losing value no matter which way you're trading on the curve remember the x-axis is arbitrary if you wanted to you could flip that thing 45 degrees and end up with exactly the same bonding curve so it's not that trading in one direction is like no profits and trading on direction is profits it's actually losing value in both directions and that is not necessarily i think a a controversial issue

because finance has already figured that out for us you charge fees for these things right market makers have been doing this for decades so i want to return to this apple merchant model but now looking at what happens when you apply fees to it and i'm going to i've you know curated a very specific example just to demonstrate my point so we're going to start with the same situation but now after that apple is sold for one cent we're going to say that we're adding just a a tenth of a cent on top of it right so one a one over 10 feet which is quite high but i think for you know for the sake of clarity it's the one i chose and we're going to do that for every apple that's ever sold

and so now we're not just saying that you can buy the protocol buy apples from the protocol for the price that's quoted but you have to buy apples from the protocol for the price quoted plus a small commission and if you um take the commission when someone's buying it you have to take commission when someone's selling it as well and this is how market makers make money this is especially how automatic market makers make money it's from volatility not from gross price movements so if we let this uh this simulation play out um again we're looking at people you know selling and buying apples and every time all i'm doing is taking the sum of the cost and then just dividing it by 10 and adding that as a commission and so after a few trades

we end up with a situation where the you know the merchant has collected 30 uh sorry zero point uh sorry three cents in fees um but they've also collected one two and three cents from the gross revenue of selling the apples and so if you add these things together you get um a nine cent overall revenue and if you compare that to the number of apples sold and the current market price for that apple you'll see that these numbers are actually the same right so this is a situation where because we've added a fee and again you know i've deliberately manipulated this but it's a very small number of trades so i don't feel too bad about it but what i've shown is that it's easy to catch up to that hotel value price and

it stands to reason then that you should be able to defeat it as well right it is possible for an amm to um to beat the the hotel condition and in fact they beat it rather regularly the problem is that that opportunity risk is unpredictable for a discrete asset no one knows what the price of ethereum is going to be tomorrow right no one knows what the price of chain link is going to be tomorrow and so if you're comparing it against these other assets and you're trying to work out you know is this a good market-making situation for me you're lying to yourself if you think you've got it figured out right there are very sophisticated market makers in the space that have got much better much more sophisticated ai tools than you do and even they haven't

managed to figure it out because the market is quasi-random but that quasi-randomness combined with things like the law of large numbers means that the more assets that you have in your protocol the larger the protocol is the overall performance of the protocol actually does become predictable you have no idea where the specific losses are going to be you don't know if it's going to be on chain link or bitcoin or ethereum or anything else but you can actually start to forecast how much the protocol's liability is likely to increase over time and that is one of the major um you know realizations behind the design of bancor version 2.1 and continues into the

design of bancor version 3. because we're not just making markets with apples we have all of these different tokens right bancor version 2.1 currently has more than 150 banco version 3 still in a soft launch at the moment only has three tokens but we're on boarding the rest of the catalog probably later next week and because each one of these you know liquidity providers is participating in the system and that they are all worried right that they're not going to be able to beat their hotel value you actually have something like what could be an insurance mutual everyone shares a small part a small part of their fee revenue with the

protocol and the protocol which is not human which has no you know sell motive only uses that revenue that it collects to [Music] pay out liquidity providers when they withdraw if they failed to beat the huddle value that's it and so it means if you're a liquidity provider on bancor you are guaranteed to be made whole on the way out and that is i think really profound and so we call this impermanent loss protection i refer to it as an insurance model and it is you know the the only amm in the space besides thor chain kind of um that's offering this kind of thing um we did develop it on our own we spent more than 18 months

experimenting with it and we are now um you know further refining it so i've established that our protocol protects its users and i think that that is you know i think that we should be proud of what we've done there but what it doesn't address is how the risk is mitigated it's not enough just to say that a risk is predictable because the predictable risk might be catastrophically high right it's like um you know like earthquake insurance there's no premium that anyone can actually pay that would allow for example the entire you know state of california to be rebuilt so that risk has to be mitigated somehow what i did

was study um the uh the protocol uniswap version three i'm sorry that some of the text seems to have been cut off there but this says half of unisop liquidity providers are losing money i uh my research team and i spent a lot of time uh going through every single transaction on uni swap v3 uh late last year every single liquidity provider position and we wrote a a research paper and published it on archive that was immediately picked up by nasdaq and published on on their website that shows that this concentrated liquidity idea it's actually losing money and like i said earlier in my presentation we actually came out with a concentrated uh

liquidity model um that was you know uh was also underperforming the huddle position frequently so this wasn't huge uh news to us but we felt that it was news to the industry and so we decided to spend the time looking at it so how does uni swap v3 do it and why is it losing money so this is the standard bonding curve and you can treat this as someone providing liquidity to it is funding all possible prices right if up to you know positive infinity and down to very close to zero or you know zero plus epsilon what unisot v3 allows you to do is to choose a specific segment of this curve

that you wish to provide liquidity to and so you know it's perfectly dynamic there's no limitation to to where you might provide liquidity and unisop espouses that this is something similar to like a an rfq model or like a limit order function on chain which is a good argument but i want to have a look at if you draw a little box around somewhere you might have provided your liquidity and just blow that up right because a lot of liquidity providers on uni swap provide very very concentrated liquidity very very tight bands if you blow up that one segment it starts to look like a straight line okay and this is very well approximated by something called the constant sum market making algorithm which was

actually first established by m stable and what i'm going to do right now is compare how constant sum compares against constant product with regards to the number of tokens that you lose so for example if we're right in the midpoint of both of these curves they both have 10 x and y tokens each look what happens when we start to move down this curve so in this case a user has spent another 5 x tokens and in the constant sum situation has extracted five y tokens in the process but in the constant product situation has extracted less than that what i want you to realize here is that if you're trading on constant sum as a liquidity provider you are losing tokens

faster you're actually selling tokens at a discount compared to constant product and what if you go all the way to the bottom of the of the axis there right where that line crashes into itself is anyone a liquidity provider on uni swap v3 by the way have you ever been moved out of range that's exactly what's what i'm demonstrating here right that's when the price moves out you end up um entirely in in the underperforming asset and so in this case when we crash into the x-axis there you only have 20x tokens as a liquidity provider but the same situation with the same amount of liquidity on constant product you would still have five of the y tokens and it's pretty clear right if you could just compare these two situations they both have 20x tokens but one of them has zero y the other one still has 5y

that's an interesting realization and this is a calculation you can perform on the back of a envelope the take-home message is that leverage is dangerous right and this way of concentrating liquidity to within tight trading ranges it is a type of leverage and that should come as no surprise the uh the uni swap team has correctly demonstrated that these types of concentrated pools perform like they're a lot deeper than there are right you can have a 50 000 pool behave like it's a 500 million pool but that doesn't mean it's a 500 million pool there are still only 50 000 worth of liquidity there and so if you're pretending right or if you're acting like it's a 500 million pool of course

the market is going to absorb it more quickly so how did they get there right what was the the the genius behind uni swap b3 and by the way i want to be clear i actually admire unison b3 i think it's a really terrific product and you know i i think that the uni swap teams should be extremely proud of what they've accomplished but this is their process if you start with a constant product curve like this one and just blow it up right that is essentially how you end up at the the protocol that uni swap b3 has has created and you can see that it's starting to approximate a straight line there so if this is risky right if this results in greater losses for liquidity

providers what do you think is an intelligent response why don't you just do the opposite instead of blowing up the curve why don't you move it over this we're calling the bangkor 3 infinity pool and what it means is is that as that line is approaching asymptotically one of the axes that there is a buffer zone there which means that essentially the the bank or three liquidity pool it has the option to refuse to make markets with all of the tokens that it has so just let that sink in for a second unisop says we've got a 50 dollar pool that's behaving like a 500 million dollar pool that's great i think that

there are some very good very clever arguments for why a product like that should exist especially if you're a sophisticated trader but if you're not a sophisticated trader this is the break right this is the thing that prevents you from losing catastrophic amounts of money if you're a liquidity provider and if you're a liquidity protocol like us that's ensuring you this is one of the ways that we can actually mitigate the losses that would otherwise be experienced if we made markets with everything that the the that the protocol had access to again it's confusing i get it right this is very non-intuitive if you haven't dealt with the geometry um you know before the effect of moving the the curve over and creating that buffer zone is really

it's difficult to visualize or difficult to anticipate so let's just go back to the apple merchant example and have a look at what these two different approaches do the blowing up the liquid the the bonding curve and the contracting or moving the liquidity curve so the uni swap v3 example the concentrated liquidity example looks like this rather than have you know each apple selling for one cent more each time you let the price adjust more slowly right so in this case you can sell up to three apples for one cent and then up to another three apples for two cents and another three apples for three cents or it's supposed to be and so on and so forth

and so this is effectively that liquidity amplification right that concentrated liquidity effect where the price moves more slowly okay so what about the bank or infinity pool it's exactly the opposite the price moves slightly more quickly which in a way also suggests that the markets might be slightly more volatile or at least trading on bancor might be slightly more volatile which is good because volatility drives fees but here's the demonstration how many apples do you need to sell before you discover a price of x okay like let's say that the market was happy to pay three cents for an apple which one of these methods realizes that price discovery first

in the first one which let's call it constant product you sell three apples before the market says fine we're three cents and this is kind of where price equilibrium is and maybe there's going to be trading back and forth between five cents and four cents or something what about the concentrated liquidity you have to sell eight of them in this case right that's a large number of apples and remember the merchant isn't really making any more money they are still selling apples at a discount leading up to that state and if the aim right if the purpose of a of an amm is at least partly to facilitate price discovery which i think it is then the capital efficiency argument that i've heard for concentrated

liquidity i actually don't think stands up i think that it stands up in cases where we are considering something like uni swap v3 to be like an otc protocol or an rfq protocol but in terms of the efficiency at which it allows the market to determine the price of an asset you actually have to sell a lot more of that asset to arrive at the same conclusion and the bank or infinity pool potentially we can do it with only two apples right we got to three cents much faster and that's where the equilibrium price should be and that means that um because we still have all of these tokens in the in the liquidity pool when the user goes to withdraw the amount of liquidity available to

them to withdraw from is much greater the insurance liability is significantly reduced and uh the overall health and you know of the protocol and happiness of the users is higher if nothing else what i want you to take away from this presentation is that bancor represents the interests of liquidity providers and to my mind this is a niche that we occupy entirely by ourselves and i think that's really sad i do think that decentralized liquidity markets are important and i do think that the type of manipulation that we saw that led to for example the meltdown of the terror ecosystem may be averted if we don't allow

centralized market makers to have as much control over the crypto markets as they currently do and i don't think that it's going to be the last time we see something like this it may not have even been the first i've recently you know been on many threads um some that are extremely credible that are trying to work out just how many times crypto market crashes have been orchestrated and this isn't necessarily you know conspiracy theory tin foil hat wearing nonsense these are people that are actually doing sort of you know forensic accounting and trying to work out where these things go and it's possible that it happens quite frequently and i think that that's extremely sad and i think that liquidity protocols lack ours even like uni swap is the best defense that we have against that type of market manipulation

that's the end of my talk and i really hope that you enjoyed it and if you have any questions and you want to see me after the after the talk i encourage it these are my contact information um please feel free to reach out to me on any of them i'm currently inundated right now because we are in the middle of a product release but i promise i answer every single email every single telegram message every single every single twitter dm um the um yeah i i hope to see you guys at the vip dinner really some of you and um you know i'm going to be hanging around tomorrow we have a booth just outside and so if you would like to come and and have a conversation with me there i encourage it we've got about eight minutes left on the timer if anyone has

any questions and thank you so much for your attention yes [Music] just shout out your question i'll repeat it [Music] yeah absolutely yeah okay so the so the question is

that i spoke briefly about price discovery and um the the audience member wants me to to compare bank course price discovery versus something like balancer balancer is an extremely good choice by the way um so um so bank cause one is is all constant product um you know with this buffer region but still constant product and so what that means is that no matter where you are on the bonding curve the the rate of price change is the same balancer has a much more well a much more let's say elegant way of sort of generalizing the um the constant product algorithm where it's if anyone wants to look it up it's

called the strong invariant and importantly allows for bonding not just two assets but any number of assets so you can have three four or five but even when it's just the two the you you find that the constant product version um is simply the um the a special case of stronger variant where the exponents on both of those numbers are one right so x to the one times y to the one equals k with balances you can screw with those um with those exponents so long as the sum of them is still one so you can have for example x to the power of 0.8 times y to the power of 0.2 equals k and you

still get a type of bonding curve but it's it's skewed and that skew means that price discovery is biased in one direction and that's deliberate right this isn't a this isn't a design flaw this was deliberately built into the protocol by balancer and i think you mentioned bootstrapping right yeah the bootstrapping yeah so the reason why you want that sku sometimes is that when you've got for example a new token it can take a little while for the market to sort of start to uh rest on what the fair price is and so you don't necessarily want violent price discovery in the you know in the beginning stages of it so interestingly

um yeah so i do think the balances model is is terrific um i think that you know the strong invariant has a very specific use case especially for things like index tokens if you want to create like a large bucket of them and that they can all realize that price versus each other without having a common numerator is brilliant for things like initial token price discovery i do think that there might be better mechanisms and i have been investigating these for about a year and so for example there are protocols such as like juice box and dowel maker that have sort of these lock-up systems and use you know um again constant product um but with an incentives model that tries to sort of

adjust the price slowly or at least limit how fast something can be sold or bought and and that's fine but of all of the you know remember what i said about the apples right it's just a rule right we can apply any bonding curve if you can imagine a bonding curve so long it's got a unique point at any um you know at any x and y value then you can make a market using that algorithm and i think that balances one in terms of price discovery for for bootstrapping tokens is good but i don't think that it's you know perfect for all use cases i think starting with something like constant sum which gives for example early investors the ability to get cold feet and leave from their investment

should they want to without impacting the token is actually something that should be investigated i think that you can also then take that um that same principle and slowly bend you know a constant sum curve into a a constant product curve which is exactly the opposite of what i demonstrated here by zooming in on a section instead you would zoom out on it and so you can dial in you know price discovery at a certain rate as a market for a certain token matures balances is good and they can do it as well because you can change the exponents over time um but yeah it's uh it's it's a a burgeoning field right i doubt that we've seen the the last of um you know price discovery mechanisms and i'm looking forward to contributing

a little bit to that myself thank you so much for your question does anyone else however i know it's a long day do you guys want to go [Music] okay thank you so much you