1inch Network 🛠️ Deep dive into 1inch Fusion - Nikita Kozlov
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Nikita Kozlov from 1inch Network for a workshop titled "Deep dive into 1inch Fusion". All you want / need to know about 1inch Fusion protocol Thank you to everyone who joined us for ETHGlobal Paris 2023! Paris is the city of light and birthplace of many revolutions. Therefore we were thrilled to be back in one of the most buzzing and free-spirited cities in Europe for ETHGlobal Paris 2023. A lot has changed in the European ecosystem since the last time we hosted a hackathon in 2019. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
foreign [Music] my name is Nick so I'm going to start um I have a back end limit at one inch so today I want to talk about our latest Innovation it's seven inch Fusion maybe you are familiar with unison X right now so we had this before it was a mainstream and let's start with some small introduction uh vanish actually was is one of the leading projects on the markets abolition started at severe New York at the same background as we have right now almost like from ethereum Global team at 2019 by two members right now we have several protocols and we have about 2.8 million users actually a bit more and now it's about 3 million users we have like billions of volumes going through us we have we are leading black segregator and not only that aggregator we have multiple other protocols um we have aggregation protocol limit order protocol manage Fusion protocol and also the recently released from English developer portal for the developers to make it easier to use apis with no limits and more adjustable limits for them as well and also we do have a non-custodial wallet on IOS and Android so let's recap what is vanish aggregation protocol is basically aggregation particle allows you to have continuous swap like experience but with the a bit better rate because we are trying to aggregate liquidity across multiple decks as not only a unisfa but across the access like curve balancer and about 70 more basically every time your track to make a swap we are trying to split your initial token Source token like vanish for example in this example to some small small sub paths and actually trying to actually try to pick the best player token connector token so like let's imagine that we have a vanish token and you need to go to get some die token in the ends but we're trying to build a path across wrap Bitcoin or like rough ethereum for example usdc and only after that we go to the die and the logic of that is because we want to minimize the slippage we are trying to aggregate all the pools rates across multiple dexes and find the way where the red is a bit better so is the best categy if you want to get lower slippage on the markets we have about 220 million volumes during the day actually all the analytics about aggregation protocol and all our particles is open source you can check this out on General analytics one each basic.com basically yeah it's quite transparent here we have a little smaller volume but when I made this screenshot like at 6am so it's a bit yeah it's a bit smaller um how varnish protocol aggregation protocol Works basically is as a developer it's quite easy to integrate that uh basically you need to fill some data it's actually for Source token destination token and the source amount of this token we have an API for that actually it's a backend algo that calculate the best path but it's executed on non-custodial smart contract basically so it's also verified and now edited so by about 700 companies first you need to make a quote basically you're trying to understand what will be the return amount from Source talking to destination token if you are okay with this HR amount you basically call another API handle called Swap and it will return to you the call data that you need to execute with with on-chain transaction to the running aggregation router this is quite simple and that's how you can integrate from each aggregation protocol okay actually or you can also try right now aggregation protocol on developer portal without no with no limits it will be pretty adjustable it's just it's our latest Innovation so latest API aggregation like latest API for developers so check this out please uh we also have boundaries for that today okay we talked about creation protocol I can say that it's one of the best way to sell something on the market price if you'll try to compare something to the decks that's access like binance it's like the the bet it's like market sell for any token so it's just one Atomic transaction with the best potential path but it's only market sell but what about limit others well you want to specify some Target price for any token and you just want to wait until it will be executed it's a bit more advanced and we do have a limited other protocol for that that allows you to do a lot of fancy things for example you can it's all it's first it's gasless so for every user you don't need to pay for gas because basically you don't do anything on chain except approves of tokens sometimes also it allows you to do additional callbacks for example you can use proposed interaction methods to withdraw some liquidity from away for example and only after that interact execute this limit order from parts of the user um it's one of the most optimized protocol on the markets it's open source as well it's also outdated and right now it's a part of aggregation router like contract so uh let's try to understand how it works as well so from one point we have a user basically user um do very basic logic it needs to build you just need to understand which token you want to swap you specify the conditions for swap for example I want to sell if one ethereum 40 000 die and like I have some time constraints for example for one week and what I need to do just create this structure and sign it from your private key and send this signed transaction with the structure to manage limit other apis and that's it uh you can do it with our front ends we implemented basic functions there so everyone can try it can try that can try that out there okay and another part we have a kind of professional micro Market taker who is trying to seal these transactions this is the entity who is trying to pay for gas on chain and actually this is the entity who can make some profits from that potentially we also integrate this Market taker to our aggregation API as well so every time somebody is trying to swap something they can also execute them with other Vertical Limit orders as well on the aggregation part um everyone actually can participate in that and be like a resolver or take care there but there is an issue that it's a you need to understand how it calculates through something like this how to calculate the exit price so you need to take care about the gas price that we'll need to spend to execute the order yeah um why I'm talking about that is just to understand how we are what we have been talking right now that we have a market makers that's basically the users to create something and send it to like like to the entities and the market takers that trying to execute these orders from like trying to field disorders and get some professors like in this case um usually Market Tech is it's like developers it's professional like some companies that doing that and my guess is basically users who have interface for everything so um this is like main scheme how it works so we have users the signing orders signing sending it off chain and some takers that getting a disorders of chain and executing these orders on chain and there is a verification that everything is correct with the signatures and all the rules on this on chain as well so it's kind of permissionless we don't care where you get disorder we only care the like the structure and the data there so that's how a limit order works but there is a small issue that is not very comfortable for users because you basically want to sometimes to sell on the market side but we have a lot of issues right now with me for example if attacks like sandwiches attacks on the multiple blockchains it's also quite expensive and it's but you bet you ask sometimes because of the gas prices so we just questioned us ourselves what if even try to solve all of these issues at the same time what if you want to sell on the market price but we actually don't care too much there will be one Atomic transaction we want to have like just the best market price during some small small time interval like five minutes for example and we also don't want to have some issues with me for attacks for the users because it's extremely painful to explain them what is what is that how to be protect it from it it's quite hard to be natively protected but we want to make it happen and also it must be regardless because it's one of the best experiences that you can get potentially sometimes so we are trying to build something like that and actually this is a one inch Fusion it's our product that helps you to have the same uni swap like experience our previous experience the fabrication router but it allows you to have gasless execution new protection by default and basically in some cases it's almost better prices that we have on the markets because you you have almost Limitless liquidity there because any resolver can accumulate that um just a small example for example if you're trying to swap this is actually the real real life transaction uh it's free free like three thousand ethereum craft ethereum to use DT um so it's actually Dutch auction that we have at the same at Union swap X that allows you to have um during some time interval the price is going down we're starting from the price that is a bit more expensive than on the markets and we are waiting until somebody will be starting to feel it the main point here that there is an open market of competitors that trying to fill it and the the motivation for them to execute this transaction is that when it's going a bit more closer to the market price they are trying to Arbitrage that and get some profits from the from the Arbitrage and yeah so basically that's the main point of it and because of the open competition not because it's one on chain on chain transaction because it's going to be multiple limit order transactions that field that will be executed for one order we have a bit better prices and yeah basically that's the cell the main sense of it we also recently tested that V5 11000 ethereum as well and it was also executed better than one on market prices for Valentine transaction so but this Fusion is very useful for large trades so let's talk a bit about gaza's execution so as I told before like makers basically side do the same as they are doing on limit orders they're just signing some transactions some data that is off chain they don't you don't need to pay for gas except you need to make one smaller proof to one each contract from the token usually most of the tokens support pyramid function so it's also gasless per approved for the conflict you just need to sign this transaction the auction and set it to the back end to the Limit order storage and after that it will be actually shared with the resolvers with the entities they will be fighting for your order trying to feel it and they will be paying for gas so as you can see it's a bit gasless but it's not gas free so actually every user will need to pay a bit in gas but not directly with ethereum but they view the gas rates during the execution of the trade so like every resolver will be executing this transaction not on the market price but sometimes a bit below on because of the gas price then how it works we don't have any magic that makes everything executed for free that's like the main one more that's the case here let's talk about beef protection so it's also not that simple because of course users don't need to think about that right now because we don't have any any unchain activity from the user side but we do have on channel activity on the resolver side on the market taking side so every resolver needs as a professional we do ask him that resolvers on our side like in vanish Fusion are professionals that actually know how to handle math attacks and in this case they have issue with myth attacks but users don't have any decision so we are trying to focus like to trying to allow professionals to solve these issues not users and it's pretty simple point about Limitless liquidity basically because we have a not price auction it's about like about five minutes it's pretty customizable let's imagine we do have some not very liquid token for example some coin and there are some cases when you want to swap this current another coin if you're trying to do this on some dexes in one Atomic transaction it will be pretty high price slippage because let's imagine it's not enough liquidity on this chain but there are some liquidity for example another chain if you have a price auction during like 11 amount like minutes of time some resolver can try to Arbitrage this liquid to bring this liquidity for example from Cross chain and execute this order on better prices that you will have if you will do a one Atomic transaction this is like the main point of auctions that you can accumulate resources during the price execution you have enough time for that as a resolver that's why we have a bit best the best possible issue like so solution for slippage that is like we can imagine right now so the main picture actually looks like that basically users just need to do two things sometimes they need to give a permit or approval to the one inch router contract and sign the off-chain order after that it goes to database shared with the resolvers they are fighting for this other and executed using vanish aggregation router as well uh actually it's quite easy to become an inch resolver we have a pretty non like this is the last way how you can make it one thing that you need to do is just through register as a resolver on the smart contract side and also you need somebody maybe some entity to stay to be to delegate you some unicorn power actually it's a staked one inch token that allows that will bring you to the top 10 resolvers who will be executing the orders from our system so if you want to execute orders of Market takers of users of an inch you just need to get a bit on the top 10 of resolvers um if you want to be in top 10 you need somehow to motivate the users to delegate to your pool and the system works like that you basically can motivate them by sending some token but right now it's only one inch token to the far full Factory and users will have a motivation to stake delegate the tokens to your factory and they will get some rewards on that automatically so it's open like competition who will be on the top 10 that's like the main reason why um legal like that's the main point so that's users will delegate to the only entities that have the maximum API and if mpy changing they will redelegate to other engines here that's why it's always kind of not a very good they they need they are not forced to send reverse but they need to compete with each other for that so that's like an opposition how it was right now there are two options how you can work with vanish Fusion basically the first one trying to integrate it into your app the app or like any D5 app that doesn't mean that's where you need to execute uh like any swaps uh it's quite simple you just need to have a niche Fusion SDK uh right now we have it on typescript there's a lot of the most popular languages in the market right now and there is one more option it's a bit more advanced I'm not sure it's quite useful for the hackathon but it's still pretty profitable as if you want to build some business or doing some Market making it's just become a resolver from each feature Fusion as well so um if you were interested in becoming a resolver you can talk to any Our Community member here we have a large Booth so yeah just talk to us and also if you have any questions to read one institution as I need to get to integrate it to interact it you can just ask me later um right now we are trying to code um just yeah this is like we have a Vanishing Network documentation here with SDK we I will try to cut a bit I absolutely made a small repo with one inch Fusion 101 you can just scan it basically it's everything but what you need to do is there what I will try to show some live examples right now I feel like uh right here but I usually not have enough time you can just launch it on your own only one thing you need there is a Json RPC endpoint there is a default one there but maybe you'll need your own custom endpoint and one more thing you need some ethereum and you need a basically private key there with some ethereum or needs to execute transaction ethereum chain or the ID or any other chain basically again switch between between Network so yeah I'll try to do some live example how it works on just explain how vanish Fusion 101 Works um we'll try it like basically try to emulate the case as a developer trying to integrate from each Fusion to its own apps um yeah it's created on node.js right now but let's imagine you'll try to use a front-end like react or something else I just don't want to focus on that right now or the user interface part because we have quite not enough time so um we do have a pretty basic structure here I like I will try to make it a bit more a bit more invisible one second please um so uh you just need to open index.js file index test file to see the main default picture basically what we do we have here uh we do have uh flow where firstly you can potentially make an approve of source talking to the vanish contract that you want to swap this is the first step um so if I will pull through you'll be it will basically just make a usage 20 approved to manage contracts that's the first step that I just automated uh the second part is more interesting part it's trying to make a quote from using unleash order SDK basically a quote what will be the return amount for the source amount of tokens and the last part is basically do the swap basic crazy increasing execution order that will be like actually a real transaction it will be off chain but it will spend some resources from me up like from your account and yeah in the end of all we're trying to search for all orders that we do have on this address through actually just just database so this is like the main three things that you need to have checking the approve doing that approved for the specific token also quoting some data and that after if you are okay with this data you can execute the Swap and after that you can check the all history of these orders this is like Basics that you need as a developer to integrate with an inch Fusion so um if you will if you take a look on the config site I'll just just it's just simply PC symbols like example I just put everything here uh it's not like production ready code it's just like some ideas brainstorming so we do have here some Hardware tokens I will try to focus on ethereum right now uh so I just picked a network ethereum here I have some hardcore vanish token amount that I will use for quoting and potentially for swap if we have enough time and yeah I have my private key hardcoded as a EnV variable I will not show you my private key but yeah you can just put your own later um so let's try to basically run something I want firstly to run a quote and trying to take a look what will be the return like return from API of the quote uh so for that I just hardcoded some variables for like winning variables to not to do everything at one step and let's just do only quote so a proof and swap is false and quote is true let's lower on some code so we do have here basically the quote it's the first part and lower we just have a history of all orders on this account like let's take a look on the basically there it's all about like the return amount and the structure that we do have we do have from running GPI for the quote what is important here and how we can like work with that later so basically it's just Json file and it's quite large but we don't actually need to focus on everything sometimes you need everything but the main things that we need to see here is basically presets presets is actually this hardcoded way and base how the auction Works uh we have price from rows for you so you don't need to calculate it on your own it is possible to use a custom price mode on auction but it's not available quite soon I think and the main point why we didn't do this right now is like yes it's because it's quite hard to manage the risk in this case and in the custom preset is quite painful and you can lose some assets there uh it will not work as expected in some case you need to be sure that you want to specify this uh like the parameters not as default ones for us like for the execution so in most cases it just doesn't you don't need to do this so let's take a look on the presets and basically the main point here is that we executed a quote for swapping 101 inch tokens to some wrapped ethereum and this is like the return amount that I got here it's calculated in way let's try to understand how like what is the real number here I'll just open Google for that so this is the amount that we got from the quote and we can just double check that we have something the same on the front of alphanage for example so let's take a look how the front that works how what will it will return for the same amount of tokens so we will pick a wrapped ethereum and the swap will be from one inch so it's 101 inch tokens so the return path is quite the same at the as Wiki as we have here it's like 0.
0178 yeah it's quite the same but Precision just is different here we are not showing all the numbers on the UI right now okay so right now let's imagine that we are okay with this trade and when we still want to swap some manage tokens um let's try to make an approve so basically as a developer what you need to do is just to understand the two token amount from The Source token amount that's actually the price that you will get the destination part of the destination token in the amount of that there are some additional data about that you have you can see the prices like from token that like in USD in two token of that like the read like four pure one token actually and the volume of that in USD as well and we do have a parameter called recommended preset is basically the pro you can just use the recommended precell by default and quite often it's a fast preset for the first pops when you have a small amount it's pretty easy to do fast swaps because the price auction is the longer it takes the harder the price formula works and you need to do something with that um because it Go the price can go down significantly if it's not a fast preset so let's try to execute this order and during the moment when I will be doing that I will be happy to ask for any of your questions so if you have any questions just raise your hand I will be turning the swap at that moment so yeah it's quite possible uh right now it's not possible either in in the interface but the using the our code the source code that is MIT based on the GitHub basically you can use Smart contact like not only externally owned account but smart contract or an account to do execute the swaps it's also it works for aggregation router it works for Fusion because it's basically what is Fusion it's it's a fusion of aggregation router as limit order basically you're just creating a limit order and in limit order is quite adjustable protocol and you can do whatever you want there you can use Excel your own account no next story or an account you can actually not only execute limit orders with years to 20 tokens but honestly if any ngt with any token for example with NFC tokens actually you can Implement what you need to do to make it possible you just need to implement a transfer function for the limit order there are several examples in our documentation in our GitHub I just recommend it to everyone if you want to try limit order aggregation protocol or like a fusion SDK you can just also try to take a look on the tests of smart contracts there there are multiple use cases that sometimes are not public for from a user interface but they are already written so you can just use them as a starter uh forget for like for your for your case for example uh it doesn't work like that because the price constantly going down if you will increase the price then we will try to make a formal more complex because because it will be going down more slower because yeah you have a minimum amount that you will return so the auction works like you'll never go go to zero it's like some between some price intervals but because of the market it's it's kind of predicting how it works if the price goes too much uh down during long amount of time you'll get you will just wait too much and it will get you will not get enough tokens it can be it can be failed basically like when we start an auction we're trying to understand okay what is the market price right now let's imagine like 2000 ethereum and we are trying to say okay the starting point will be a bit more above of the market price and let's imagine what can happen what is the minimum return amount that you want to get what is the minimum the lowest rate if you are okay with for example it's like 1950 foreign so during this interval you are okay to swap so we have built a price option like a function leave the that is going down to this to this amount to this rates and let's imagine we have 10 minutes what will happen in this 10 10 minutes is quite hard to predict sometimes the price going down too too fast and if it's below the 900 1950 ethereum 5950 let's die you'll just get nothing because it will be not profitable for resolvers to execute execute the transaction so it's not a fact that it's not the statement is sometimes it works like that it just can iterate a bit more it is quite possible that something can grow better but it's not a guarantee that it will happen so like the interval the more you log the way the more your weight doesn't mean that the price will go to your product to your interval like to do your Target price yeah so the rest will be not definitely better it can be it depends on the amount of money that you have if it's a large amount of money like for example let's say like 100 000 in this case it's much more better to wait a bit more because of the volumes the reason for that is that basically resolvers will need more resources to accumulate uh like to like accumulate to execute this transaction if it's 100 it's quite easy but it's a life is a large sum they need somehow to Arbitrage that and that's why sometimes when the price like is easy the the auction time is a bit longer that's why sometimes the price is better for the watch Mouse but it's only worse with flashmas mostly and there is no any guarantee actually uh partial fuels are possible with user mods so yeah that's one of the main points for how you can save on gas as a user basically it's of chain transaction for you and its own change transaction for each other but actually resolver can batch multiple user transactions into one on chain transactions that BS so basically they share the gas price across multiple transactions a bit more optimized there are multiple ways how we optimize that that's why auction is a bit more gas profitable for the users they are also matching order sometimes so it's a actually quite efficient on the it's an economy of scale the more users you'll get will have the batteries will be working at the most cheapest you'll be working for the users yeah I just want to comment that we just executed the transaction so this is we have as a result of execution executed transaction and we have actually several uh orders and the history before it was one and now it's two transactions we'll try to take a look what's happened on this account uh let me if you have any questions just ping me so yeah yeah let me show it again so basically yeah I think I can modify this picture later but basically it is here um everything started from here this part watching the limit orders part is on chain part is actually that was like the life here all here is on chain because there is almost a few transactions using one inch Network to the using limit products to contract basically and makers basically users are trying to make a proof to the Limit order like convex as well this activity happens on chain and everything else the matching they are like accumulating on all the calculation whatever is profitable happens off chain basically what we do on chain is me we're trying to minimize the efficient like to maximize the efficiency of the context trying to do as minimum as possible on chain the minimum you can do is just to verify that is the the verify the trade is okay and just execute the transaction just send the funds that's like the minimum you can do on chain yeah okay I think we can finally we can finish thank you for everything yeah I will be open there's some funny questions thank you [Applause]
Automatic transcript — names and jargon may be misspelled.