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

Loading player…

Instadapp 🛠 Building DeFi dApps on Instadapp Smart Wallet

ETHGlobalMon, Oct 9, 2023, 12:00 AM

Join Shriya, Thrilok Kumar from Instadapp for a workshop titled "Building DeFi dApps on Instadapp Smart Wallet". And that wraps up 2022! ETHIndia 2022⎯the biggest Ethereum hackathon to this date with over 459 projects built within 36 hours. 🫂 2000 attendees from 🌆 321 cities that were 🌱 44% new to web3... ...joined forces in Bengaluru to write history. Thank you for taking part in it 🫶🔥 ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

foreign [Applause] [Music] guys I think we can get started I hope you guys are on channel 2 you are able to hear me and me am I Audible great so hello everyone welcome to the Third Edition of eth India it's really great to see you everyone in person after like long three years due to the covered so here myself three look and my teammate Shreya are here from the team instead app and we are going to show you how to build uh the defy dabs on top of instead of smart wallet I have a question for you so uh so I have a question for you so have some Idol eats lying in my wallet so I was thinking maybe to deposit that in a Lido for some rewards they were mentioning that I'm getting almost four percent so what do you think what's your opinion on that well Turlock you're right Lido is offering around four percent rewards of staking on your eat but how much Idol eat do you have around 100 100 each you're a big Mantra look oh no but although what if I tell you that not just four percent but using your hundred eight you can gain almost as high as seven to eight percent rewards whoa that's really interesting but how is that even possible so tritok it's possible by using a financial strategy called as Leverage so leverages when you sort of increase your exposure to some assets so if you can see that this is how your position will look like in the first case this is you just holding your stake teeth earning the regular four percent APR and in the second case you're going almost 2x leverage earning around seven percent APR whoa that's really interesting but how is this even possible in T5 decentralized Finance so in D5 this is how you should go uh now this is you holding your 100 stake teeth now you can deposit your hundreds take deep into away now on our way you can borrow against your stake deth up to 72 percent so now you borrow some eat from away you swap this eat into steak deed and now you deposit it back so as you can see that your collateral has sort of increased so you can obviously borrow more against your collateral so you borrow 28 to eat more to sort of go to x which is 200 stake teeth you swap it back and you deposit it again so there you have it your two Exposition oh whoa so like this I can earn up to seven percent yes that's right but here if I see it almost took like seven transactions I don't like I think it's will be a bit time taking and for me to research how like I don't think it might be feasible oh well look you're right it is time consuming and don't just get me started this is you going just 2x let's say you want to increase your reward even more and you want to go 3x or even as high as 3.5 x leverage which is the maximum that you can go and if you see that it takes you almost 16 transactions to go 3x leverage but your APR at the same time is going to increase to 10 percent and in 3.5 x you're it's almost as high as 12 percent oh but I would like really like to have more than 11 here but I'm not like not sure if I can do more than 16 transactions so this is where Instagram comes into play instada provides these complex strategies available to the users in just one click and such strategies are available on top of uh so many protocols like uni swap of a compound Etc and you would be shocked to know that Instagram is currently managing around 1.7 billion tvl whoa isn't that very huge guys oh well it is so now let me tell you how you can sort of achieve this transaction uh this strategy available in one click so to achieve this in one click we sort of use something called as a flash loan so now mind you guys you will be just doing one transaction but I will be breaking that down into a set of actions that will be performed sequentially so this is your action stack now again we started with 100 State needs now we flash borrow 100 eighth we swap this to stake teeth we deposit the 200 State D that I now have I bought a hundred eight and using the borrowed amount I pay back the flash loan now since this is a transaction but it has not happened on chain so it has not yet executed so we need to execute this transaction so that your balance get updated on chain so we cast this action stack and this is how your position looks like in the end oh that's real yeah oh that's really cool so if it's really taking one transaction I think it's like doable I would love to see how is that even possible maybe I would try to go by 3.5 x to get maybe the 11th person that you are showing in the previous slide is that even possible uh well yes to look so here's the catch now we just went 2x now even if you have to go as high as 3x or 3.

5 x you can see that your APR is increasing but your number of transaction just stays the same and that is possible because now you're just taking a higher amount of flash loan so now through look I have sort of conceptually explained you how you can achieve this uh will you be able to show our fellow developers how you can code this out sure I think that would be interesting and everyone is looking forward for that so in setup offers a advanced web3 based online editor that lets you to interact your D5 right from your browser and that we call it as playground so in the playground we have typescript and HTML supported too I guess most of you guys would be using vs code or some code like editor right but what if you had the same visualization of a vs code in your browser the the playground is built using the same architecture or the same libraries to give you the same vs code like field and then have you ever wondered you can import your npm packages in your browser it's possible using the esm automated library import and not only that in your browser or in your playground you can use natively big number Library Axiom and then the await the top level of it I hope in blockchain or D5 you guys might have to do a lot of asynchronized calls that you can do it easily and then okay to look so I think you can get started and don't forget to log in using your GitHub or email so you can share me a link and I can cross check whether you have written the right code sure so let's get started with the demo so I'll be showing you guys how to code in just like a 10 minutes how to code a leverage strategy so before that before that I'll just give you an understanding of how what's playground and how the playground is connected with our main application so this is our main application this is our uh instead of main application so in this application we have a feature called something as simulation so when you turn on the simulation you can actually do do all your work like whatever you want to try it without really spending so that means it's like a test net environment you're actually converting your main application into your test net environment so I've turned on the simulation so let's assume that we have turn on the simulation I've turned it on over here and in the same way once this has enabled it will show you that this model that you can do all this like all the transactions like let's assume that you want to uh before using your real funds maybe someone is like putting real money then before doing the all the real transactions you can really test it out on the simulation so now the simulation mode has been turned on and it has it gives you one hour of time to do whatever transaction you want and then this is the playground and here also I'll link the simulation I'll link the uh the main applications uh simulation with the playground so I'll connect like this so once it's connected both the playground the code over here and over here it's connected so let's see so when I go to Ave V2 so do you see any funds over here no right it's currently empty so now this is already pre like the pre-script return that whenever you kind of first time go to it you will be able to see this so what this basically does is that it tries to deposit uh eth this is the eth address that we use to have an uh proper convention and this is the connector so instead of smart wallet so instead of smart wallet can interact with the protocols using something called as a connector a connector is a intermediary contract that helps you that helps the DSA to interact with the protocol so the connector has all the Logics suppose let's say you have to give the allowance and then deposit so the collector handles uh allowance and the deposit for you so you just need to call something like this and also you guys might be wondering why this is in JavaScript and why not in solid and how I'm exactly interacting so the playground is built on top of a DSA connect SDK what it does is that you can interact with your uh DSS smart wallet directly with the JavaScript so you can just write the code this is the character that how you're gonna interact so now here I'm just gonna change the amount maybe let's take one three four I think one I think one three point four five this is the amount that when I run it you don't have balance you need to top it up okay I think I don't have a balance so on simulation we have a feature that you can get the test funds and we just call the top of function over here and then we just put 100 and once that is top up you'll be getting like it's like your test tokens if you have been on a test net or anywhere you will be going to the faucet right so the same way we have our own thing called as top up where you will be able to top up 100 so once this is top up I'll call it and now is showing Caster to spells and the transaction hash so let's see what happens now I'll try to reload the DAP since the internet is a bit slow it's kind of taking time to load it so here if you see as deposited whatever the amount that I've entered over here was exactly deposited over here so you will be able to see so that's how you can connect the playground with the real app and then you have a visualization to also look into it so now I've explained you what's playground and then what's the main application how they both are connected and also one more thing just to give you a short brief of what are the components there on the playground so this is the left side is the online editor right side is the console I if you remember I've said it supports HTML too so when I click on the toggle at the bottom it shows me the HTML editor and the right side the preview of the HTML so for now I'll just turn it off this is the simulation button where you can connect the simulation with the main app and then we have we are supported on five chains here you can see the five chains then a person or the owner can own multiple DSA accounts so since you can own multiple DSA accounts you can toggle between them so now for now what I'll do is that I'll create one more DSA on our main application to get started with the leverage strategy so the me so this is how I'll be creating I'll be just calling the new over here and then it will create a new DSA for me so the new TSA is this actually so this is the ID so you can see the ID over here and this is my DSA address and a DSA can have multiple authorities so this is the address that I'm connect on metamask this is my eoi address and this is my owner so my owner my metamask address controls this DSA there are different types of authorities also I'll explain you later when we when we go on to that slide so now I've created a new DSA let's see here also if it's there here if you see it's three five eight two zero and here also three five sorry it's two three at the end and it's two three at the end so now I'm on the same DSA so let's get started with the leverage transaction before starting as Shreya explained I initially had hundreds take it so let me top up hundreds take it so here it shows we have added hundreds take it so in my balance I should be seeing 100 so now we have a requirement setup let's get started with the coding so I have some uh pre-code written those are just like addresses and all the stuff you can just find it over The Ether scanner anywhere and the amount that I'm gonna start is with the 100. since you all guys know we can't directly use The Ether format of a number or a amount we have to convert it into V so we have converted this amount into V format by multiplying it with the 10 to the power of 18. and now the leverage Factor so in the leverage as we have seen in the diagrams I'm going to explain you with only the leverage factor of 2. so the leverage factor is 2 The Leverage amount so if you guys see over here in the leverage factor of 2 the amount was 200 stake it that is I need to have and the n200s take it so the amount that is going to be over here is going to be to uh the amount in V times this one now now s3i explained first we need to take a flash loan have you ever wondered like what if there was a autocomplete where you just called take flashlight and it automatically gives you the flashlight code you just don't need to remember you can just use it directly see it gives you the auto complete and here is the where you add the Spells so in flashstone you have to mention the address that you want to take the amount and the route the flashlight and everything you can dive deep into it on our docs which is available for now those are set as constant 5 and the Flash loan phase set is to 5 basis point so the flash loan token so here in the example we have taken 100 eighth so in the same way I'm gonna take 100 each also we have the rapid address as autocomplete so if I just type rapid and press enter I get this or else since I have already saved at the top I can just use that one itself and the Flash loan amount so now how much amount do we need we need 100. so the amount in V would be the flash loan amount so that's it so you have the flash loan ready flashlight on spells ready you have to just add the required spells and also once you have taken the flash loan there was a requirement to swap the eth into stake it so now again we use for the swap we use one inch so to use one inch there are like a lot of setup you have to do so we have simplified that on our DSA and also we have a auto complete for swap that's it you can see you have a swap spell also ready you have to just mention the cell token that is what we are going to sell we are going to sell the rapid to stake it and the amount would be the flash loan amount and the amount and the slippage I'm setting it to one person you can increase it according to your requirements and this is the uh swap spell here the swap the swap connector ID so all the connectors on our smart contract level are linked with an unique ID and you have to just mention that so you don't have the hustle of remembering the connector address and stuff we face that in DSA V1 so we made it easy for you so this is the ID and the the name of the action is cell I sell the byte uh sorry uh I'll try to buy rapid I'll sell uh sorry I'll try to buy stake it and I'll try to sell wrap it and the amounts the Uinta and everything you don't need to know right now you can go into it maybe whenever you're diving deep into the docks so now I have the Spells also ready for the swap now I just I think I have only two spells required that would be deposit and borrow so now how will I get the connector ID of our way V2 let's say in the first thing I haven't shown you so you can go to our Docs you can navigate to the connectors the mainnet you can go to away V2 and here you can see a deposit spell the deposit spell the connector ID and then the arguments a description for that is also available so again I'll be using a autocomplete to have the basic structure of the spells to add ready and then I'll be just entering and then after deposit what I'm gonna deposit the stake it did you guys have any question or anything why here it's 200 and why why here it's 100 you have any questions maybe we can do it in the Q a for now uh so we'll be depositing the stake and the amount so the amount would be the leverage amount so we are going to deposit 200.

and then the set ID and get ID is zero you can understand them later maybe once you dive into the docs then the other spell that is required is borrow so I have to borrow 100 eighth so that I can pay back the flash loan so I'll be again calling add spell autocomplete I'll be writing away V2 a borrow and I'll be just mentioning the parameters so these are the parameters now we have our leverage spells ready the only thing here we have also seen ah okay so the the payback of The Flash loan was already added over here when I have used the autocomplete for the flash loan so it's already there so that I've skipped but now since we have her all the Spells ready in a sequence for the leverage strategy now I have to just cast them so executing the action stack or the Spells so here so this is how I cast it and I'll be getting a transaction hash so let's again jump into the away dashboard on our main application here you'll be see it's empty we have hundreds take it all the requirements looking good the next part would be just casting so I'll be calling this and now it tries to cast it and gives me a transaction hash the transaction was successful now let's see what happens what I see over here so here if you see two harness take it and 100 Heat the same thing what shriya has told you that how the position would be looking so in the 2x leverage 200 stake it 200 stake it and then 100 eat and now the API is 7.2 here you can see the net AP y also the rate is currently 7.2 and that's how you can do uh that's how you can build your own strategies or the Spells and then you can connect them or maybe create your own uh application or a defy tab also you guys might be wondering I've said that you can build your dab but there is no UI it's only the script so for now since it's kind of it might take a bit of time me to explain HTML so I already have the pre-code written where if I turn on and I have a UI also ready and then I can share this link with shriya so shriya can actually just enter the amount and will automatically do the 2x leverage for her so now we have built a tap just in few minutes using playground and that's playground well through look the demo was really amazing so as you can know that instead app also had a product also has a product which is the light instead of Light which also uses the same strategy which is the St eth leverage taking and provides around eight to nine percent of APR on the yields it is currently managing around 200 million dollars of tvl and you almost wrote that code around the 70 percent of the same code in just 15 minutes so isn't that amazing um yeah it feels so so yeah so building just on top of insta dap and DSA account is just as easy as this because of the playground and the development environment available so let's switch on to some question and answers if they have yeah if you have any q a you can ask them also um no it's fine so you guys have any questions any doubts just a second let's let us wear the headset then you cannot yeah hello can you hear me uh uh very faint noise can you hear me now uh not eggs I'm not able here hello hello come but the mic that mic is not coming yeah I think it's working hello yeah it's working so I was wondering if uh does the SDK or the playground provide anything that the website does not provide out of the box so can you give me an example of a strategy okay so currently whatever the strategies that we have on our main application are also built using the same SDK that is the DSA connect and the SDK and the application also use the same set of sequence of the Spells so maybe if you want to have a strategy that is not available on our main dashboard could be lot it could be person to person but we have only added the topmost strategies which are which our users were looking for so that's why we have added maybe if you want to build something maybe a new strategy where let's say you want to uh do something like this you want to borrow sorry first let's say you want to deposit uh E theme to come away borrow die and then deposit into compound maybe let's say there was some strategy that was yielding you much higher yields so in this you can just combine them in the sequence of series and then you can build it and then you can share it as I've shown you how to share it I do have another question yep so does the SDK support only the platform supported by Instagram or can I go for a custom platform like uh some other lending protocol okay so that's a nice question over here so basically as I said instead app and the instead of smart wallet and uh the protocols can only interact by the whitelisted connectors that means first we need to build the connector that is written in the solidity or the smart contract and once that is written and uh that has been whitelisted once that's whitelisted and then you will be able to interact so now assume that ins instead app is like a OS so once we have added the connector to this OS platform you can create a n number of combination with the other strategies but we have to add that character because we kind of follow some standards and some security concerns where it where it makes this uh all the things whatever I've shown you make simpler for you guys anything else okay great anyone anyone any other questions oh great okay my question is actually extension of uh like why why um DSA is controlled by an eoa right an owner so why can't owner do any arbitrary transactions from DSA sorry sorry what was the last thing any arbitrary any why can't like right now owner has to do the transactions that from least of connectors so it can only interact with only certain amount of protocols but why can't owner do arbitrary calls to any contract okay okay so now as you all know yoga can do only one transaction per time so eoa is a external own address or the metamask address whatever you see it can only do one transaction like one action because we don't have a bachelor anyway there is no like a a standard that's been followed where you can batch all this thing so instead of has done that for you guys where we have created the standards where all the protocols are said right the connectors follow a standard which makes you composable between different protocols so now uh uh what you say a DSA can be owned by any address any address that can do a small kind of a transaction that could call the DSA the owner can be an eoa the owner can be again also safe or any other smart contract to anything a owner can be anything and then in the authorities you can have different levels of permission this is not available on the uh on the main application yet but but currently we have only one kind of owner that is the full access owner you could have manager guardian and uh the automation the manager is now uh whatever the owner has access right he can have he can access all the connectors that means he can access the security he can access the funds and everything but the manager has only limited amount of access maybe let's say he can just interact only with the compound only with the compound he can't interact with the away so that's a manager type of authority then the Guardian guardian just helps you to recover in case you have lost the owner address let's say your metamask private key maybe the guardian can help you and then the automation automation is just like a thing like whenever the market is crashing or something the position you have seen right in in those cases if it has to save it has a limited uh fixed strategy that it can execute so automation can execute a fixed strategy so that's like an automation Authority so was your doubt clear yeah that's right I just wanted to ask that uh uh is there any way a connector can be added you can connect her uh allows arbitrary calls okay so for the security reasons we haven't added a connector that can do a arbitrary calls like you can't just call any direct or random contract that's for the security reasons so if if you want to maybe in the hackathon if you want to build you can build a connector you can add it uh to the instead app on the test net or on this on the main Network so if you want to building on top of where you need a custom connector then you can build your own connector and then you can just create like a main Network environment and then you can do it but currently the adding of the connector is done by the Dow all right makes sense thank you good any else question any other okay [Music] maybe after this question okay so I think uh we are running out of time uh we'll be at the booth and we'll be around so this is our Discord Channel you can just connect and ask questions there's a Twitter handle and our email address if you are building on top of instead app and if you have any questions or anything will be around or you can email us or you can come on to Discord all right guys all the best for your hack

Automatic transcript — names and jargon may be misspelled.