1 inch Network 🛠A dive into 1 inch Limit Order Protocol and API
ETHGlobal·Sun, Oct 9, 2022, 12:00 AM
Join Kirill Kuznetsov and Nikita Kozlov of 1 inch Network for a workshop titled "A dive into 1 inch Limit Order Protocol and API." In this technical workshop, we'll cover how web3 video applications can disrupt existing video platforms like Youtube and Twitch. We'll also look at some tools for developers to build these exciting new applications. 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] hello hello everyone my name is nick i'm from one inch network and today i want to talk a bit about our api and our limit orders api as well so let's start from one inch i just want to repeat a bit uh what we are doing and what is our value proposition so basically uh vanity is a dexa guy aggregator so we aggregate multiple dexes when we want to swap a coil into alcohol so we have much more liquidity than any other decks and also we have algorithm called pathfinder so actually we build specific uh the app that allows you to swap currently any other coin based on the path that we calculated and it's pretty good path so you get much more coins return amount than using any other decks or any other decks or a deck segregator the aggregator as well it's like a small example uh for example let's i for example i want to swap 500k ethereum to die see a lot of money does just a demo so basically you can see the path here so we just allow you to it's just one transaction so you can swap uh through multiple polls and multiple daxes and all of that will be atomic and the return amount will be the largest one compared to unisof for example and basically the awesome thing is that you can access our api that allows you to integrate all the liquidity of our decks to your app it's available via document our documentation i already opened this one and i just want to show you one of the most more important two quotes that you need to handle that you need to use if you want to integrate a like just a router api uh the first quote the first is called quote you can see that there is a network chain id here you can pass any chain id that we support right now we support multiple networks uh all of them are supported right now and we are working on all other ibm chains right now as well so basically the first the first handle is quote uh this head allows you to just find the best vote for the specific pair of coins and for the specific amounts uh so it's more for preview for your wallet for example to show the quote for user and uh let's dive into some specific uh query params here um the most important one and the most there are only three params that you require to pass here so it's just uh from token address it could be any token error c20 token and also you need to talk an address as well you can pass any any of it but you need to pay attention that some of them can be not so don't have so much liquidity than other one so just just keep it in mind and also you need uh from a mount as well you need to pass from arrow from amount as well to this handle and basically it will work let's let's just try to pass default params so that's the response like from one from ethereum to one inch so you can see uh two token amount from takitana amount and also you can see the protocols that we are using for this swap and also estimated gas that we need for this transaction in future um let's talk more about additional query params that we have its protocols basically there are about 70 protocols on ethereum chain and if you want to specify specific daxes that you need for swap sometimes it's very useful you can just pass them via this handle by default we support all of them another param is fee we support referral fee so you need to pass its percents few percents that will be returned to the referral address uh of the wallet of the of the provider of referral so it can be from zero to three percent and by default it's zero also we have a gas limit i think it's pretty pretty obvious what is it and actually depends on the gas limit we can be we can we can have different roads uh optimizing for low gas limits for example if you user don't have enough ethereum or native coin for swap also we have uh connector tokens param basically if by default we have our own list of connector tokens is the most liquid tokens on the market right now but in some cases connected tokens is tokens like this one during the road path for example during swapping ethereum to die my conductor tokens are usdt and usdc here so basically uh we're trying to handle it on our own but in some cases um when we are talking about specific coins with smaller liquidity it's much more better to provide specific connector tokens for specific pools so you can have much more better return amount the maximum maximum amount of it is five and also we have complexity level complexity level for the path uh basically uh let's talk about example here current complexity level here is just two so the swap goes through usdc to die and after that it goes to the so it goes to the die yeah um it it can be up to free uh it also you need to pay attention that depends on the complexity level uh the gas will be much more high to with the higher complexity level if you will pass zero it will be just direct swap for a specific pool let's talk about main road parts and the parts params so it's much more easier to explain it on the picture so basically uh parts it's uh this stuff it's uh usdc for example usdt part and dipart and it's minor parts and parts it's uh parts inside the main part for example here it's sushi swap units for part by percentage so you can pass all of these params for api sometimes it's very important to pass specific amount of them for the optimism for the gas optimization for example and also gas price is pretty obvious but if you want to estimate your transaction with another gas price you can pause it and we will build a road basing on this on the gas price that you need but i recommend to use fast so uh let's continue with swap so for example firstly you show user your return amount for the specific token and right now you need to swap to implement a swap for this user uh basically when you will execute swap handle you will get not you will get not only the price you will get the call data that you need to pass to your transaction for the one inch router and so user can execute it and make a swap basically we have a bit more required parameters here let's talk about additional ones that we can see here the first one is from address amount token address and from back in address are pretty the same as for quote so from address is the the address of the user who will be calling the advantage contract sometimes it can be another contract and there are additional things that you need to pay attention when you are using another another contract for the one inch swap it is also possible but just pay some additional attention about it and one of the most important parameters is slippage it's also like percentage of amount of the price how much it can be dropped uh it's important to pay attention that on the most liquid part mostly to liquid coins you don't need to put very high slippage parameter but sometimes if you will pass very small slippage parameter as well transaction can be failed so sometimes the best it will be like something like one percent a user also can pick uh this parameter so basically it's important to give give user an option to change slippers for kim but pay attention how users change changes during the swap also we have protocols which are the same also we have destination receiver so basically you can swap coins and get another destination receiver address for swapping we also have a reference address it's very important to pay attention about this when you are providing fee it must be the same fee percent as for as product quote so if you have a referral address you can create this one you will get an additional profit from positive slippage uh during the swap uh if user will have positive slippage as well actually so also we have one interesting parameter it's called disable estimate it's very important to use it when you are trying to build something with another contract on one each when the when the router will will be called through another contract sometimes it's useful to say to pass disable estimate to so we will not check the that trend that transaction can be executed right now so you can change it a bit later and run it a bit later if you need it we also support permit so if you're talking if the token supports e2 62012 you can use permit signature and pass it here so it will be instant swap if during one transaction with alone with approve um i also want to talk about uh allow partial field parameter um sometimes uh during swaps uh some of the paths are outdated and the rate field can be changed dramatically but there are some cases when you want to swap at with this rate at least some per amount that you have for example in this case let it be like 60 of the path will be successful and 30 of this path will be unsuccessful it will be the prices will be up they outdated but you still want to get a t until at least 60 percent with the rate that you have right now uh in this case you can turn a lower partial field uh to true and uh after that if you finish vanished router will transaction in that way that the transaction can be filled just partially so uh all other options all other queries we already discussed before in other another handle so we also have much more information about how to integrate vanish api to the your app so i definitely recommend you to take a look at our documentation um and also i want to add something about our limit orders basically vanish supports not only swap direct swaps instant direct swaps but allows you to use limit orders the main difference here is that limit order is not executed instantly we don't have we don't support black market cell but it's pretty the same vibe and pretty the same logic as uh classical limit order so you can specify specify the speed the price and the rate for the tokens that you need do you want to sell and you also can set up expiration for your order and the most awesome about it is that actually you will not pay for the gas for this transaction uh you will be the transaction will be filled automatically and the market taker will pay for the gas so for users it's free and for market takers it's uh actually not free that's how it works also actually when you make creating creating a order you don't pay for gas because we don't send this order structure to the smart contract it's just stored on the layer like another layer another network and anyone can get this order uh we just need to sign it so when you send you can actually execute this order via smart contract and fill them amount on a taker side that's the point how it works so because of that actually um anyone anyone can execute it at any time if it's okay for this person to pay for the gas and uh that the person is okay with the return amount that person will get we also have a lot of additional features of a limit order that i want to share basically one inch limit order is not only limit order you can build a lot of additional logic over it there are three main points firstly it's conditional conditional execution for example you you can specify additional params and it's called pyramid and for example sometimes it's very important it's okay for you to swap because some oracle price of the another asset is uh like is okay for you and sometimes oracle price of this asset is not okay for you and depends on the price you are okay with swap with executing this order or not so basically you can add additional params for your order so the price will be changing and the order will be valid or valid during time a default example is expiration you can pass you can add expiration uh for your order and if you are okay that it will be executed like in 10 years or like in 10 seconds only uh you could make it on limit order very fast also we have uh like average reprice discovery i will tell a bit more about it when i will show you the structure of limit order and also we have a custom callback during execution it's very awesome thing uh for example you can we use this function before fonts will be transferred to the taker address and during uh this fallback you can implement for example you can for example farm tokens on some protocol before during creating payment order for the maker and after the moment when order will be filled um you can actually use these tokens and claim them and stake them from the farming pool and use them in the limit order as a liquidity yeah so let's take a look at the order structure so i just want to pay attention to some specific params most of them are pretty obvious the most important that i want to start is predicate it's like the third one on the last predicate actually allows you to it's a structure that allows you to set up some rules for your order as i already said for example expiration time we also support permit by default on the v2 limit orders so you can just make gusless you don't need to approve token for the one inch limit order contract by separate transaction if you have this token supports permits we also have interaction interaction is a function that allows you is a you need to pass data here that will be called before transfer from a function that will be called during order execution so let's talk more about order execution if you want to execute order you need to like actually use field order function so basically most important is about is signal share and you also need to verify that this order is correct and it's to estimate it before executing it on the smart contract also i want to talk about predicates right now a bit more uh we have basic predicates on uh vanish on financial limit order that you can combine between each other for example you can add multiple params during using function at we use by default some of these functions some of this predicates for example we use nons one important thing about nons is that each time user create a transaction in you you create a limit order we use nons because for example if user wants to cancel all limit orders instantly you can just adjust nons on his account on user account and after that all limit orders that have nons less than current nons will be invalidated so let's talk more about get maker and can taker amount basically get maker can take your amount it's functions that give you a rate for swap for the order and you can the was this awesome that you can actually build uh your additional functions you know your this interface implement this interface on a data smart contract and use these functions to have more adjustable price during um your limit order execution for example depends how much it will be swapped you can actually use any formula for it it's very important it can be useful for nft for example uh so actually using our limit orders you can build nfc uh market and this is just like small example how uh this make it get maker amount get they care about functions uh i implemented by default and how they are called um so i also want to add a bit more about how they are called on our smart contract basically it's just arbitrary static call uh it's so it's secured let's talk a bit more about maker address sometimes you want to use additional smart contract as a maker address so like a smart contract is a creator of this order of this order and if you are using smart contract address as a maker address you need to implement additional function it's called israelite signature and this signature is this function is called before on the check when we fill order there are two parameters here it's orders limit order hash and also a field called signature but basically it can be any data that you need to validate this order on your smart on the smart contract site so just don't think about it about this as signature only signature can be any data and let's talk about it interaction it's a final function that's called before transfer from during limit order execution and it's that's how actually you can implement this function so you just need to implement function called nutify field order and uh with these parameters that you can see here it's a message center by basic parameters actually message sender make your asset take your asset making the amount and also interaction data and actually interaction data can be any data so that you can so you need just to parse this data on your own contract and specify like the length of this data so it can be any data that you need for your logic you can know a bit more about limit orders as well we have a good documentation and we also all this stuff is open sourced it's open on the github so it we are happy to answer all your questions and i hope that you get a bit more information about our api and limit order thank you if you have you will have any questions i will be nearby also you can come to one inch stands we will try to be there all the time you can also contact us on the telegram or ask for ethereum global team if you have any questions as well [Music] [Applause] [Music] you
Automatic transcript — names and jargon may be misspelled.