New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Composable Leverage as a Service

ETHGlobalSun, Oct 9, 2022, 12:00 AM

Join Mikael Lazarev of Gearbox Protocol for a workshop titled "Composable Leverage as a Service" How to integrate your favorite third-party protocol to allow DeFi-native leverage on it. This workshop is part of ETHAmsterdam, the first in-person hackathon for ETHGlobal since ETHLondon in 2019. Join over 800 likeminded engineers, designers, and creators to build and learn over one full weekend at the Beurs Van Berlage in Amsterdam. ETHAmsterdam is taking place as part of Devconnect, the week-long in-person gathering in Amsterdam. We're back to build, we hope you'll join us. ---------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Music] [Applause] so hello to everyone so great to see you here and especially on s global hackathon maybe you know that gearbox originally was a finalist one year ago and really i so appreciate the hackers who create something interesting something new in the fy space so pretty happy to be here and to be honest we are very very open so uh feel free during hackathon to ask me or my teammates to help you everywhere because we are burned from hackathons so it's pretty native to be there and let's start talking about gearbox and what we are working on so gearbox mission is to bring capital efficiency in device space and we create the way how to create uh composable leverage in defi so at the moment in the second version we can achieve x12 leverage and we provide leverage as a service so we do not focus on make immm with leverage or a service which could help you to open short or long position instead of that we create a really interesting protocol which could provide you ability to use leverage funds across the five protocols and this feature opened a really amazing opportunities because you can create a lot of new composable strategies and another thing which very very significant at this market that there is no funding raise so let's start and make hence jerzy from architecture side so as you can see gearbox is two side protocol on the left side you can see liquidity providers these people who are looking for passive strategy they just provide liquidity to get high apy and it's available they are looking for they are not willing to sit at the computer 24 to 7 find best strategy and so on and so on and to be honest i am a trader if i go and believe that bitcoin will go up it will immediately go down and so on and so on so for people like me liquidity providing is a good value because i shouldn't spend my time i want to put money and that's all but what is really interesting is the right part and here you can see a trader this guy want to be a more capital efficient so trader could open a credit account credit account is in unify primitive this is isolated smart contract so when traders send funds to this credit account this credit account could immediately take margin loan from the pool and after opening this credit account trader could send different financial orders or transactions in our way to get this could be executed on behalf of credit account on third party protocol so let's check how it works step by step so on the first point as i said you as a trader could open credit account and here you can see trader provide 10 s and takes 9s from the pool so after opening credit account trader has 100 s each credit account is nominated in one asset so here you can see credit account which is nominated an easy room which simply means that debt interest rate and fees are also in s and then when you open credit account you can use it across different protocol however you have no direct access to the funds so basically you can't put money into your pocket however you can use it for different strategies on different protocols and let's check how it works so from the technical side as a trader you sent a transaction and usually transaction is address and the call data but instead of send sending this transaction to uniswap for example you send the same call data to a special smart contract which is called adapters so basically you have uni swap three adapter uni swappy to adapter curve adapter and so on and so on and sending transaction to such a contract this transaction would be executed and credit account funds would be involved so basically from developer side you send the same transaction to credit account likewise you want to use and then your funds would be executed so we have a few checks to understand that pool funds are safe the first one we should be really ensured that the contract you want to interact is white listed i think it's a pretty simple the second point that we want to understand that the token which you could get as a result could be used as collateral pretty simple if you want to swap s to die it's okay if you want to swap s to some coin it's not good for us because you as a trader use not only your own funds you use some pool funds and we should be insured and the last check after transaction was done we checked that health factor is more than one which means that we have enough collateral to pay debt back maybe any questions at this point it's clear okay so now let's check what means this health factor and how credit account could be uh could be considered so basically on the right side you can see credit account as a list of different assets and each asset has quantity and price which is taken from chain link price oracle so basically we can compute pretty simple values the first one is portfolio value we can multiply each other quantity to price summarize and get how much money in underlying asset which is as in our case we can get if we swap everything immediately it's pretty clear yeah the next point which is called threshold weighted value or tvv at this page means threshold weighted value so basically liquidation takes time yeah and during degradation time price can go down so we could make a over characterization however in our it's a huge over collateralization like 50 percent more in gearbox we use a parameter which is liquidation threshold lti on this slide which represent maximum expected price drop during liquidation time so basically it works as is price is going down health factor becomes one so this credit account could be liquidated by third party liquidators however we have a liquidation threshold which becomes a buffer to have enough funds to send them back to the pool and this liquidation threshold could be close to one for two stable coins for example die and usdc because we do not expect in a few more blocks that the price between die and usdc would be dramatically changed correct by the way as opposite if we have two assets like bitcoin and die of course bitcoin price could go down drastically at this space liquidation threshold could be 0.6 or 0.7 to create enough buffer to be liquidated and after liquidation have enough funds to pay back debt and interest rate and as liquidator you just get a discount from portfolio value so you as a liquidator because everything computed with changing price fee which looks like pretty fair prices get five percent discount so basically if portfolio costs if portfolio cost 100 s you can take it from 95 s and 5s would be your profit to swap everything back and pay to the pool and simply health factor is just the ratio between treshold weighted value and borrow amount plus interest rate and it's pretty clear that if health factor is less than one that means that threshold weighted value is less than borrow amount and this account could be liquidated any questions at the moment guys do not hesitate because it's pretty complex or not or is clear okay it's okay it's okay okay cool yeah so basically yeah you you can really imagine that credit account have a few boxes with different coins and each your transaction then you put coins from one box and put into other box and then we recompute the value and understand is it enough for us money to pay back so each transaction i know it's a pretty strange word but even if you put something into a farm you get some lp tokens so basically you uh subtract from one token and increase the quantity of lp token so basically gearbox then you switch in tokens between these boxes or these boxes could be viewed like a table like credit account and then this pretty simple must help us to keep your credit account to be able to pay this debt back and it's really create a good things for us so basically as i mentioned this this credit accounts you can work on behalf of them with many defy protocols so what we should really do with you is to write a simple contract which is called which is called wrapper which is called adapter and this adapter has the same api like original one if you want to write adapter for uniswap v2 this adapter will have the same api like original smart contract and all stuff would be encapsulated so if you want to use funds from crazy account on gearbox you create the same transaction like for original uniswap just make call and methods like create interface in hard hat dot get called data and write methods and parameters you get call data and send it not the original one to adapter and it would be executed so it's a pretty simple integration and another part which is also pretty interesting based on that because credit accounts are really isolated smart contracts each of them has their own balance so you as a user could definitely go to other scan figure out your credit account and get balances and there are one more interesting feature which we implemented with wallet connect because you can connect uh gearbox as standalone application with some native interface like uniswap or urn or something like that to get direct interaction and this uniswap or earn a curve would really believe that you behave on uh behalf of this credit account so a short video we use wallet connect for this purposes and here you can see we enter this wallet connect link then we go to uniswap interface and now it connected to our smart contract and then because we provide the same programmatic interface you have balances from native way and you can really sign transaction as originally so it's totally a native experience for end users whoever funds are used from created account smart contracts so basically you sign up through meta mask and all magic happens because it looks like your metamask credit account may be a good example i tried to say it's like a credit card in real world you can open it once and use across many different uh shops or restaurants the same logic here you open your credit account as another smart contract and then you can be half and then you can execute any transaction and build strategies in a more native way so just a few questions and a few comments here if you talk about gearbox it's a pretty interesting way because uh we really address different segments here for liquidity providers as i mentioned this is a passive uh people who are looking for passive strategies they just provide funds and that's all and on the trader sides it's people who are really could create more value through their strategies trading positions and so on and so on and it create a good market for us because there is no funding create and if you compare us for example this perp which also works on leverage or square is on the both sides of this protocol you can see pro players and if it's a bull run everybody wants to buy ethereum because we expect that as price will go up it's why funding rate could also increase because nobody's want to be other side correct and gearbox total opposite because we do not compete we do not play each against other because this uh guys on liquidity side take value from just providing liquidity for high apy and guys who work on the trader side on credit accounts are pro guys who know how to trade how to make profitable strategies how to earn money and gearbox could be considered like a platform which shares money from people which they helped for capital efficiency and provide to lp site and basically maybe the solution as i said i'm a sheet trader how to provide money and get some some part of profits and let's check how it works maybe on let me check on programmatic say any questions at this moment guys please do not hesitate because it's a pretty complex stuff i know it's maybe not so so basically to understand how to works programmatically with gearbox we have a website dev gear boxify and you can check all these explanations and basically as you can see here we have a lot of such things which connects pools and credit managers which simply a contract which simplify all operations there are another layer which is called core contracts and if you want to get everything you maybe can go to contract discovery option and understand how to figure out and how to take these uh contracts but if you go to the credit account sites what i believe are pretty interesting maybe it's how it works so from technical point we have a user and user could send transaction to adapters and credit facade which just an interface to work with other stuff like open and close credit accounts provide additional collateral and so on and so on and when you send a transaction it goes through a filter you can see then the call transitioned to this credit account and then it executed on behalf on it on third party protocol in v2 we support uh seven major defy protocols it's uni swap v2 uni swap v3 sushi swap curve careful p tokens as well uh convex urn and lido and basically let me share i think maybe it's more interesting for you strategy you can build so maybe it's not the latest presentation but here you can see here some interesting things like ill generation short long position so here you can take x10 leverage then you can go to open credit account and drop btc then you swap to usdc and then you can open short position and put your stable coins into urn so what's impossible because there are a lot of leverage protocols in the space when you can just short and do nothing with this stable coin in gearbox you can simply put it to earn to generate additional apy and it makes your position more profitable and if you found sometimes that it's not profitable you simply could switch from wire to convex to get more apy and it has pretty low overhead because your funds on credit account and you manage them as your native wallet another possible way is to work with lidar with the same things you can get x10 leverage then open a zero credit account so your debt is always in s then you really take this s and put it into convex and you can get around 40 percent apy because as i said totally is composable you can move funds back and forth to get more api and create pretty complex strategies and we really do not want to show maybe all things i really believe that you can create a lot of stuff what could be used for gearbox and maybe a few ideas here uh that it's how it work from uh feature which we designed for v2 which is called multical so basically what you should do is just to write an array of things you want to execute on gearbox you can see here i want to make a swap so i uh generate call data for this call so i want to execute function which is called swap tokens for exact tokens it's pretty well known for uni swap v2 i provide amounts what i want i provide path which should be used then and address of credit account however it's automatically replace it to existing one and deadline then i create a list of calls and just call function which is called multi-core and it's done so the easiest way to build strategy you just explain the system what you want to get and they say do all this stuff and only one collateral check so basically overhead in gas cost could be close to you do everything manually through metamask and then you will pay around 200k it depends how many assets you have for full control check and that's all and you get x10 leverage which is pretty cool from my opponent uh what's more we have some strategies and ideas about ribbon and so on and let me check from here yeah so basically we try to explain all stuff and provide some additional information how it could be executed so feel free to check here if you have any questions and as i said from gearbox our best goal is to create great developer experience i believe it's a complex stuff so feel free to provide us feedback which things should be really explained more especially from documentation domain it's a pretty significant for us and maybe a little bit more about things and limits what we have we work with token which have channeling price oracles sometimes people asking can i add my coin or not not unfortunately because it have no price fee and it definitely depends price chaining price fit because now we have some conversation with our maker and market leaders to clarify what's the best solution to get price fits on chain in 2022 and chain link is a leader at the moment maybe maker has owned uh their own um price fees but by the way it's a pretty simple when you start new token and even if it's traded on binance it doesn't mean that it have enough liquidity and if we start to use it as collateral and you as an owner of this token have 90 percent of supply it's pretty simple to change the rate chain link will provide the same diet data but at the end of the day it could not be considered as good collateral the second limit gearbox yet works only with erc20 tokens which also pretty uh understandable and the latest things that uh to add new protocol to a system we use dao and gearbox dao is a very very active so feel free to go there a lot of people could help you and tell and provide support so basically that's all if you have any questions let's discuss and i will be happy to answer or it could be in person during the hackathon good question you talked a bit about the dao and i noticed that there was a graph with the insurance part so yeah cool thanks for question yeah you talk about this insurance yeah now treasury yeah so basically uh this question is related how gearbox earn money because we take two kind of fees the first fee is like some overhead for interest rates so uh we take a difference between interest rate for lp providers and traders and it's like 10 percent so basically if you have four person on the pool it would cost 4.4 to trader and all these funds would go to dow to the pool back but what is interesting we do not provide this fees directly to the dow treasury instead of that we reinvest this funds to the pool and then put lp tokens which is called diesel tokens into dow treasury and this approach has a very good three advantages the first one we increase pool tvl by putting fees there the second point tokens which are in doubt treasury generate more income because lp tokens and lp rate is going up with usage of gearbox and the third part if liquidation was a little bit later than expected and we have some loss to keep this lp token rate on the same level because lp earned money then rate of this lp token goes up each time we get money back on the interest rate we burn some token from doubt burn some of the talking from dow treasury and cover this laws so gearbox has automatically working insurance for the pools however of course we need maybe more time to generate enough lp tokens in doubt treasury but they really behaves like automatic insurance for all our operations which create additional level of safety but thanks for these questions amazing more questions yep so with that mechanism there's increased liquidity in the pool however if there's ever a late liquidation would everyone suffer including the treasury uh not in treasury so basically treasury holds lp token from each pool now we have four different pools so this picture could be replicated four times we have die usdc os and rabbit ec basically each pool generates lp tokens when you close your credit account all fees are transferred there so if we have some late liquidation on some particular pool this lp token which correspondingly connects would be burned automatically if we have not enough balance this insurance wouldn't work of course we consider this way and by the way i believe it's totally honest because it creates a good responsibility from the downside to create really realistic parameters because dao manage these parameters about uh interest rate about interest rate model and so on and so on and thou should take responsibility with their funds to set up these parameters pretty correct if they would be pretty high nobody would come and now could not generate more fees if they could be pretty low it could be a lot of late liquidations and dao would really leave money through this mechanism so it's create a good feedback for doubt to be focused on parameters with responsibility and maybe a few things which could be really done maybe during the hackathon two days it's not much to generate i totally understand that so visit him we have a few ideas what could be done of course the first point is to build some adapters and just to show you how it works uh basically i don't know i think we should have yeah so it's not a surprisingly and extremely difficult so basically you can see how it works line by line it's an adapter for units of rp3 can you hear font or i can make a little bit bigger let's try yeah is it better yeah nice thanks so basically it's how to build uni swap v3 adapter parameter so we take original function which is called exact input single with parameters and all these data structures was taken from original unislavi3 we provide the same interface like original uniswap and as i said if you send this call data to original contracts your own fund would be involved if you send to gearbox adapter the sample data it would be uh executed with credit account funds then the first point we get your own credit account so there is pretty simple function which called credit account or reward if you have no credit account yet sorry you will be reverted if you had we will definitely get address of this isolated smart contract which holds your funds and which funds should be executed the next point we really call to credit manager to check that this transaction has enough allowance because it's like automatic improvement and we have to policy for some contracts which we really trust like uni swap we can create max in for some contracts we do not trust we increase this allowance and after transaction we set it to zero but union swap e3 we totally trust if something happens with uni swap it would be end of defy and we can go to build mobile applications for pizza delivery or something like that so no worrying then we really update the recipient of transactions so we want to get money back on credit account not to send somewhere just for security reason then you can see we really prepare uh call data with updated parameters and then it's pretty interesting we check balances of two tokens which would be swap before just getting this balance off function then we really call function which called execute order and this function translate your call data to credit manager which translate to credit account execute on behalf and return uh bytes which decode it to amounts out and then you just should run pretty simple function which is called check collateral change and this function do all other magic it compares how many collateral it was before and how many collateral you have at the moment just comparing the difference as i said gearbox is like you move assets between different boxes and if it's enough cultural it's okay it's done if there is some lack of credit your transaction would be reverted it's how we keep things so as you can see it's a pretty simple to build an adapter for third party protocols and start to work there another point which we really definitely believe could be interesting is to build oh is it clear at the moment or any questions yes another point which is also could be pretty interesting is to build organize funds upon credit account because sometimes people special institutionals they do not want to behave from one account basically these people you can really make some strategies on credit accounts side and provide tokens for people who trust you as a trader it's also an option like a shares of future profits it also could be interesting and of course different strategies how to invest this money how to get earn from convex from um air and so on and so on a few days ago uh ilgis our co-founder has a really interesting strategy to invest a part of money in the white dx because it was a negative interest rate and some of them into gearbox and this difference could also generate additional yields so it's do we do not limit it only this gearbox you can be totally creative here and maybe some infrastructure things uh people also asked for so we want to eliminate liquidations when someone is liquidated it's not well for this person and for the protocol too of course we take liquidation fee but it's not we are willing to create nobody could build a reliable business on liquidations as a protocol so maybe any things like connection with protocols who could provide additional collateral like device saver you can build your own boat which could emergency send funds to you you can simply swap some assets for example as i said there is a liquidation threshold so if you ho if you have debt in stable coin and you have wrapped btc of course because liquidation threats hold around round 0.7 it's low valuated and maybe as emergency thinks you can swap btc back to stablecoin which would increase health factors result maybe something's there because we definitely want to reduce the quantity of liquidations and maybe ivan has ivan can you really say hello yeah yeah but basically you can provide some additional info about strategies he is a very well experienced guy in strategies and how to earn money very successful guys so basically if you have any information about defy and all the protocols he could also consult you more questions yeah how many positions can there become because like the yeah so basically we have such a things which called all over talking list it limits this 2256 tokens because to reduce gas cost to compute this portfolio value we have a few ideas the first one we keep inside the contract like a bit mask and one as a bit means that this uh token has non-zero balance and we should check it because each computation like uh quantity of token multiplied to price requires ice to go to price feed requires us to go to token contract and of course on scale it could be not well so basically at this point we have optimization to keep this bit mask to be more gas efficient another point which was implemented in v2 if we found that we have enough health factor we stopped to check in because we do not we do not need to know how many house factor you have we should just prove that it's more than one so it also and as i said because we use bitmask in 256 we have 256 tokens in v1 we have i think around 15 tokens in v2 it would be around 50 tokens as well so many things and basically up to you i think it's cool if you won't even have a lot of them because basically liquidation price and to make liquidation profitable it more depends on minimum allowed borrow amount if you have a huge credit account taking five percent could cover a lot of expenses if you have like 100 dollar take uh taking five percent it's just a five bucks and there is no way for you to make this liquidation profitable yeah so pretty cool questions thanks for asking yeah so just a little bit sure about so we have a oracle things we have a special contract which is called price oracle it's a core contract which create like a service uh for other credit managers to compute such stuff basically for basic assets we use this chain link and for lp tokens we have a special contracts which compute this prices based on chaining price fees so let me show an example [Music] yes so this is an example how we compute for example why your uh how we compute why yarn price so as you can see our price oracle has the same interface like original chain link price feed so when you call latest round date which is done by price oracle it really get at first underlying asset of iron then we get price per share from bayern pool five year volt then we have limits to be more safety because sometimes maybe someone could find the way to manipulate this price per share so to really uh reduce this risk we compare and if this price per share is out of bounds we immediately reverse and then we simply multiply to provide such a thing so basically this approach could be really used for earn for curve lp and for convex as well so we do all this stuff for you however if you are willing to integrate new protocol maybe you should start to consider how to compute some prices for tokens which you get as i'll be talking there yep uh yeah yes basically uh as you can see using our you can get up to x3 leverage that's the best case in gearbox you can get x10 which is much more efficient and another point which is also pretty cool so let's consider how it work if we start to think about competition so basically let's assume that traders start different strategies some of them provide more profits some of them provide lower profits and it create demand for pools so interest rate goes up and this interest rate makes some strategies less profitable so people should really switch to most profitable ones so for example if you open as a trader earn position when it was four percentage then the price go down it you have to really switch to convex to generate more apy and it's why we create pretty cool interest rate for liquidity providers because liquidity providers [Music] get like a part of your profits here if you found a good way to get six percent api from convex it means that you will get four or five on the liquidity providers pool and it's okay more and more guys could go there provide their money for passive strategies gearbox like a money market which can find good market equilibrium with extern leverage i think it's pretty cool at the moment yeah absolutely because gerbos has a limited assets you ask if we have a limited asset in our you can really provide 1s get i don't know 0.

8 usdc and it's not a leverage at all but by the way you are definitely can work with this usd service all protocols in a space in gearbox we have limited uh protocols however even adding these seven major defy protocols could cover maybe eighty percent of needs of traders and strategies but we are pretty open as i show you on uni swap three adapter it's pretty simple to build such an adapter and connect more and more things i believe we have maybe some lack of the five protocols which we could trust because of course we have some serious attention to security and if this protocol do not pass a few um goods if it this protocol do not get some security audits from well-known firm we simply as a dao i believe do not connect it because it's a high risk and maybe using our funds you can do that but in gearbox we create more safe way in connecting things have some conversation to go to another chains but at the moment we want to focus on zero main net at the beginning we are still very very gas efficient view more gas efficient than our so if you want to open some um short long position gearbox would be like 13 percent gas efficiency cheaper so we focus on that but when we would have enough liquidity find better pmf strategy and people who use gearbox on everyday basis of course we can ask them which network are really needed for you to make more money and we will follow real needs not just to be deployed on 10 networks and then have a few users everywhere so i believe we should really solve customer problems that just to go and check what's going on on other networks any more questions what's about timing ivan we have one hour 50 minutes so if you have no questions as i said we really definitely believe that we want to create a great developer experience so feel free if you get stuck ask me i think you can find yeah maybe some interesting ideas is to share what things can be done compulsively so that hackers can qualify for a few things at a time you know like the cross nomination with other sponsors like oh yeah it's it's totally possible uh can you maybe provide some additional information on twitter so yes like for example notification with epns may be uh based trading with uitx rates as you mentioned adapter for one age something with other also yeah i i think it's a good point because as i i started gearbox is about composability so we do not want to compete with other staff instead of that we try to combine and really work together so i think it's a pretty cool idea to be integrated with more sponsors and create more value for end users because in v2 it's also pretty interesting way we create this feature called multi-core as i mentioned so you can wrap a lot of stuff in one transaction and basically you create a widget for third-party site you just go to lida and you can see you can get stake s or you can press a button and get staked as with leverage when you press this button it opens a widget you can set up how many uh how much leverage you want enter amount and then in one click it opens your position or increase existing one if you have over the open credit account and for end user it create a very smooth ux because you shouldn't definitely go to our website either you can really go to third party website make a one click and it's done and now you have x10 lido position which could generate a lot of stuff so basically we are really looking for developers who would be happy to create such uh things to work together and to be truly composable it's a good point um so i i think i would maybe yeah let me show if you yeah wait a second you can go to gearbox.fi to check uh so all things you can go to our channel on discord for s global or to go to dow because a lot of supporters zeros and gearbox dials are pretty active to help you will be here in person so feel free to ask and one more question today i have from developer about test nets so i as from my experience i participate in many blockchain hackathons if a project could be shared by a link so you can provide an ability for person just open your application and it works on test net it create a good experience for people and for jury as well so basically we have v1 deployed on coven and to fulfill this needs we create a special service which sync unislock pairs it syncs chaining price oracle as well so you have prices updated with current mynet and we i got the same problems when we deploy the first version it was like 1s cost 400 bucks and people say oh it doesn't work it's buggy there is no prices in a system like 400 bucks after that we create these things so if you need extra tokens covensurum as well we can support you and provide wherever you want to be deployed connected uh feel free and at the end of the day you can make a really working application colon and i believe today we will deploy the second version requires much more syncing contracts because we are going to think earn convex and curve as well to provide a really smooth experience so deploying on common playground you will have the same services the same protocols like on mainnet i think yeah i think time is up here thanks so much thanks guys thank you for your attention and i hope today we will and this weekend will be something really interesting thank you bye [Music] [Applause] [Music] you

Automatic transcript — names and jargon may be misspelled.