Defi Algorithms: Value Flows - ETHGlobal Brussels 2024
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join Anton Bukov from 1inch Network, for a workshop titled, “Defi Algorithms: Value Flows.” In his talk, Anton, 1inch co-founder, will discuss infinitely scalable algorithms for value distribution between a large number of DeFi participants. This workshop took place during ETHGlobal Brussels, a 3-day hackathon held in Brussels, Belgium from July 12 to 14, 2024. ETHGlobal Brussels brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ---------------- Follow us: x.com/ethglobal Website: https://ethglobal.com Email us at: hello@ethglobal.com
Transcript
[Music] hi everyone uh my name is Anon bukov I'm co-founder of 1 inch and uh I'm going to tell you today about some interesting algorithms in defy which I find the most interesting ones and I'll tell you why so we we can see the fire computations are very limited and this is happening for many years and we all wait till blockchain adoption and we believe that blockchain computations will scale eventually with the sharding or anything else but you know uh I'm in this industry for like seven years or something developing protocols and I don't see that capacity computational capacity is actually increasing so yeah we we should work with what we already have and uh I believe we still can have uh highly scalable or infinite scalable protocols in current state of Defi and blockchains so yeah that's what I'm going to show you some algorithms in their projects and I will describe how exactly they work and yeah this is not only for uh developers hikers uh builders this is also for understanding how different are those projects from each other and how they are different from other projects which do not use for example such cool scalable algorithms so first of all here you can see there is a classification uh you can see it's like um Distributing value it's about value redistribution among multiple participants so it can happen in the same value or in the another value different asset it could happen instant or it could happen gradually over time each second each block something like that and it could depend on Direction it could be dispensing value or collecting value from big number of users so here I have examples of some projects which already have those algorithms and I classified them so yeah let's start from the beginning you can see that same asset instant dispensing you can find amm's Logos so what does it mean whenever someone uses amm pool for swap swap fee is being accounted in being redistributed among infinite amount of liquidity providers it does not matter if it's like 10 providers or thousand or million or even billion providers computational cost for this is is the same because this algorithm have constant complexity so next one in this table is same asset gradual dispensing uh let's start with this slide so how money markets usually work so those who borrowed liquidity their depth is increasing every second or every block it's being accounted like that and they like you can say paying some annual yield for lenders it looks the opposite lenders get value also accounted every second or every block depending on the implementation but it's happening gradually and the thing how it works inside uh you you could think that it's like collecting values and dispensing values here but actually implementation of money market is different they're using same algorithm in both sides they're dispensing depth and dispensing collateral so that's why they all uh money markets are listed there in gradual and projects like maker which are all I I mean they have similar algorithms and apply them similarly so yeah one more corner here is same method install instant collection so there is a joke about drug pool it's happens instantly and collecting money from every participant but also protocols here is opium logo but there could be much more many projects which are actually like Insurance protocols or options or other derivatives protocols so whenever settlements happens they're collecting uh funds from pool of participants that's what I meant and you can see that the different asset is not really popular among different projects but I'm not sure that I have all the five projects here for sure I can't be aware of every project but it's for the most popular so if you have uh projects which are not here but like should be here or here let me know I will add them for the next next time I will have similar presentation so yeah different asset gradual dispensing is something what we called farming and it was initially used in synthetics protocol and now it's being used among many protocols moreover this primitive of dispensing different asset gradually could be used inside of many other protocols so let me check what is the next slide uh yeah and I I forgot about this interesting use case right here you can see same asset gradual collection I found only one project which is doing that it's called papaya and it's infinite scaling money streams how does it work so you could set up streams which are actually constant streams like uh how many assets are being transferred in one second in one minute in week it's being constant so you can open a limited amount of outgoing streams but for sure you can have infinite amount of incoming streams so this protocol found a way to have settlement without enumeration of incoming streams so it doesn't matter if you have 1,000 incoming streams or one million or even one billion of streams you can get money from all those streams within one short transaction how does it work this protocol stores total speeds of incoming and outgoing streams for every account whenever someone's open new stream or close stream or change stream these numbers are being recalculated for involved participants and then you can count your next balance based on your previous balance how much time passed in this moment and your total speed so sounds basic but that's what allow you to have infinite scaling money streams actually if we will see Netflix or YouTube or Twitter or only funds or patreon or anything else on blockchain they should use accounting like that so you they will be able to charge millions or billions of streams with constant complexity gas cost will be the same for any amount of subscriptions so yeah one more Point here is that whenever you see something is happening instantly inside blockchain it it's also there is a room for manipulation here and uh they by default those protocols they are vulnerable to front running and sandwich attacks uh for example whenever someone see that huge swap is coming to amm uh and huge commission will be earned by liquidity providers there is a possibility to inject your liquidity right before this swap to get significant share of those fees and then remove your liquidity that's what's happening uh jet liquidity just in time liquidity so on this slide you could see for for example your liquidity provider with three millions of three different assets D usdt and usdc and there are three different pools it's like Unis version two or maybe curve or any anything similar so whenever you see huge swap coming to one of those pools you could inject your liquidity you could inject 2 Millions out of your 3 Millions so that's how you can simulate six millions of liquidity but you only have three if you would use more assets and involve much more pools your coefficient will be much higher here is like uh double doubling virtually doubling your liquidity amount but for sure you will will spend some uh money on uh fees for making those transactions so it's not passive participation in amm it's more active participation but it have own benefits and on some networks where those transactions are like super cheap it's more than feasible and yeah those uh those projects which do this instantly they have possibility to protect from this for sure this can be done is in two step for example projects in same asset instant collection such as uh Insurance protocol derivatives protocol they lock user funds and whenever settlement is happening they charge users so it's not possible to run away before settlement yeah but some things like amm are still vulnerable and yeah but for example for UNIS swap you can do Unis swap V4 hook for those who provide liquidity you can make it as a two-step action first step to commit your deposit and then you have to wait few minutes and then you can deposit something like that I mean you could have some algorithmic protection from this if you consider this this is something you want to solve and that's it [Applause] uh any questions easy yeah that's why I'm talking about it because it's easy to understand that some protocols already utilize algorithms with constant complexity and that's actually huge benefit for them because they are already ready for Mass adoption because they ready for millions or billions on of users because each of these users will make transactions only when they need to do like real actions when you need to borrow or lend or you need provide liquidity or you need Swap and you don't need any extra transactions for accounting you don't need to uh collect funds for example from millions of subscribers because uh it will be nightmare you will no no I don't know if any blockchain can allow this like if Netflix going to have uh uh subscriptions on blockchain I I don't believe that they going to do hundreds of millions transactions every month we don't have such blockchains yet and I don't believe we will have such blockchains in 10 years and uh yeah yeah we have questions yeah guys ask me to repeat questions before answering them so yeah in short you ask it about uh this slide where I told about uh instant actions instant distributions of of values and you asked about Unis swap V4 hook that you heard that there is a bounty for something similar to this yeah I think it's possible to make protection from just in time liquidity provide providing and you can make it the only way you can protect from this is making it to step but yeah it's not that simple if you would make it simple to step like commit that you will deposit and then deposit people will commit and then wait till something is happening and then they will deposit but yeah you could came up to something not very it will be not very difficult but I think you can came up to something what would work fine for this yes yeah okay I'll repeat your question because I was asking to do this so yeah uh I I uh I talk it about computational complexity but for sure there are other complexities for other parameters of those algorithms as uh memory consuming comp uh notation and other things uh yeah I I think uh this is also important but I never met protocols which have uh which store much more data than actions they're happening I mean like for one uh storage slot for few storage slots for like some actions for some users you do not like explode on data which you need to store in smart contracts because it's actually the the most the most expensive thing in blockchains it's like in it costs insanely more comparing to computations like for like numbers uh agent numbers is like two or three gas while storing new slot is 20,000 of gas updating existing slot five is 5,000 so numbers are really wild for storage yeah one more thing regarding uh complexities is that uh whenever you consider those complexities for your algorithms um anything which is like linear to number of participants or something like that is very dangerous because when you write smart contracts you should always think about computational complexities because your computation is actually limited by the block size if you if you need to perform like Loop in your code over participants or something like that it will stuck whenever you have few thousand of users because this Loop will consume more and 30 millions of gas in ethereum Manet and yeah I mean uh the size of block is mostly comparable for the most of blockchains so I I don't believe we have any blockchains which have which have like billions of gas or something but yeah this is something what Auditors will tell you if they will see you have a loop over something which can grow dramatically which is not limited in terms of its size yeah Auditors will usually let you know this that this is would not work and you can split this by uh having this Loop in multiple transactions but I would suggest you to reconsider algorithms you use to don't have those Loops at all yeah that that's probably one of the reasons why this farming smart contract became so popular in 2020 because uh yeah any amount of participants can be participating in this farming and they can all join get out at any point of time and values will be distributed among participants in a fair way and all those methods to join get out claim they will all cost the same cost doesn't matter how many participants are participating uh okay you asked about as synchronous and nonatomic blockchains which are probably sharded or something like that that uh and you asked how it will be affected those ideas of uh scaling and uh computational complexity I think it will be the same uh I mean making things asynchronous or nonatomic will not make it easier for you it will be even it will actually cost more because it will be like a separate transactions not like an actions inside one transaction so yeah hopefully you have to consider your algorith how it works on a different level so yeah this presentation is also about how people should build new protocols uh think how they should consider new algorithms which are being used inside their protocols and yeah one more point is for people who are trying to understand how different projects are correlate with each other which one is better for this which one is more suitable for this because yeah we can see in D5 the huge variety of different protocols but they all have different implementations and they are being optimized for a little bit different things yes uh could you repeat ah yeah uh potentially yes because when we are talking about the declarative uh programming languages I always start thinking about SQL because that's one of the most popular ones and the idea behind declarative uh languages I think so it was to make some optimizations which is hard to achieve with imperative language for example with uh SQL query you to use indexes to boost uh complexity of your query but you are not aware of those indexes actually you do not use them implicitly you explicitly you use them implicitly and uh potentially some things could be integrated I mean we could see some declarative uh programming language for smart contract which incorporate some ideas of indexing to achieve something I think it's probably possible yeah something like that yeah the difference between imperative and declarative thing is in imperative you tell what exactly is happening in your code in declarative things you uh like it's like intents you ask for what you want to get what you want to achieve and uh actual things which are happening they're happening under the the hood probably under the compiler or something it depends on the implementation thank you for the question thank you guys [Music]
Automatic transcript — names and jargon may be misspelled.