[Music] How's it going guys? Um my name is Felipe from Flow Foundation and today I'm going to be teaching you about uh new stuff we're bringing here on Flow specifically with the Flowforte network upgrade. Um there's two things I want to show you guys today. Um one of them is Flow actions and the other one is scheduled transactions. So um you know you can check out all the documentation.
It's on it's live on our page and if you want to check it out and have a bit more details. So the first thing we're going to look into is scheduled transactions. It's uh basically cron jobs that are onchain. They live completely onchain and they remove any necessity in order to create external servers you know depending on third parties and making sure that everything is onchain and completely secure and decentralized. Um I'm going to showcase a bit about what we can do with these scheduled transactions.
So um I'm going to go here into our scaffold repo and I in in the interest of time I have already gone through and done most of the steps in order to you know have our emulator account which basically functions as like an anvil if for those who are familiar with solidity especially with Foundry. Um but yes so the first thing we're going to do is uh install our dependencies and initiate our emulator. So while this is happening I'm going to be talking a bit about um what's what we are doing. So we have this emulator running on and we're checking the logs each and every second each and every second. And so basically what we can do now with this is all once again all everything here is in our documentation and you can find it within the scaffold repo as well.
Um so basically what we have here is our emulator that is running in this section over here and we can execute a transaction that will be scheduled in an automatic manner. It is like a cron job. Once again um we will initialize a handler that will execute this for us and then the the base contract we're using here is a counter contract. It's a very simple contract that just you know increases a counter and we execute a transaction in order to increase and then we can execute a script in order to read that data um onchain. So in this case right here we have um uh the emulator running in the background.
So we're just going to go ahead and execute this transaction. Okay, perfect. And as you can see, we have a scheduled transaction to be executed. And then we can see this script. And we can see the counter has increased to one.
Before it was zero. Now it is in one. Now you might say, you know, this is pretty simple. Okay, but you know this is where things start getting very interesting. We can schedule uh these transactions to occur in a loop.
So I'm going to run this next transaction that will basically increase the counter every two seconds. We're going to go back to our emulator. As you can see, it increases the transaction, the counter, sorry, which uh with the scheduled transaction every two seconds. This might be interesting in order to set up a form of um subscription based payments. You know, if you subscribe to a service, you can schedule a transaction that you pay for that service every month.
Um, these are made by you and Nick's uh timestamps. Um, but yeah, and as you can see, like the the only thing you really care about is giving the contract that's executing these transactions enough gas for them to be executing them over and over and over again. And it will go at infinitum if it has enough money. Um, and remember like $1 will basically grant you the ability to deploy 20,000 contracts on flow. So it doesn't really take much gas uh at all to execute these crown jobs.
And this is way cheaper and way more efficient and just simpler to use overall than the you know third party alternatives in which you depend on a server somewhere else which you know it's not very centralized nor safe. Um but yeah uh oh so then we also have this next one where we can schedule a transaction to occur um in in a specific interval. You know we want it to be in a three you know second interval specifically for a specific amount of time and then it's going to end there. So, we're going to execute this transaction and we're going to go back to our emulator to look at the logs. There we go.
So, this is the execution of the scheduled transaction. As you can see, I, you know, restarted the the emulator. So, we're going to see how the count was first at zero. Now it's at one, two, and now three, which is what we specified directly within our transaction. Unlike solidity in cadence, you can specify multiple calls within a single transaction.
You can specify um who has access to what. Uh so in this case, we are specifying that the transaction handler specifically will have access to execute a specific amount. Uh I mean send a specific transaction at a a specific amount. So we really care about granulating the control you know giving access control detail to who uh can do what and this is the beauty of schedule transactions it's simple it's cheap and it's easy um you know this can be also played around a lot with D5 protocols if you want to be able to move around money um for example every x amount of time you want to restake your funds so you can optimize your yield um you can optimize your portfolio in certain ways depending on how you want to harvest your fees Um, but yeah, once again, all this is on the documentation site. Please look at it.
I feel like you guys will have a great time um, playing around with this. Um, all right. Okay. So, the next thing we're going to focus on right now is, uh, flow actions. And basically uh okay so uh the next thing we're going to focus on right now is flow actions.
And these are basically uh five D5 primitives that uh we have worked on here on flow. So instead of having to build you know a connector for every single protocol you want to interact with we have abstracted this away where we only have to use five D5 primitives. You can use you can use source which is one of the primitives sync swap flasher and price oracle. So source you're grabbing funds from somewhere. You're pulling funds from somewhere.
In sync you're depositing funds somewhere. In the swapper it's as it sounds. You swap one asset for another. In the price oracle you're just getting the information uh about the price of an asset. And the flasher it just functions as a normal flasher.
So instead of having to build you know a connector for every single protocol we have abstracted out of the way where in a single transaction you can build and link these complex D5 workloads in a single transaction. What I'm going to show you guys right now is a basically a restaking uh flow action. So I uh I'm going to go here to increment which is one of the protocols D5 protocols in our ecosystem and we have this uh staking pool. So basically what I have done here is I have staked uh uh I have I have you know I had flow and then I zapped into a uh staking position. What this means is that I grab my flow um and then I I put it into this pool of uh to stake it and then I received the LP tokens for staking it and then I can grab those those uh st LP tokens and put them in this farm.
Right. So we have an LP pool right here. um specifically uh this is the amount right now I have staked and this is how much I have earned so far. What I want to do is be able to pull these rewards which is the staked flow. I want to convert it into staked flow and flow so I can put it back into the LP pool.
This way I will have an LP token which I can put it into this LP pool. So once again, I'm sourcing the the funds from this LP pool and then I'm zapping into the the staking uh position and then the LP tokens, I'm putting them back into here. So I'm basically restaking this. It's a it's you know very complex workflow, but you if you're probably doing this, you'll you'll think that you'll do it every day. You won't do it every day.
You'll you'll forget completely. Uh but here you're doing it in a single transaction. So that's what I want to show you guys right now. Um all right so the important thing to do uh to understand here is how transactions work in cadence specifically um for example in this section over here I have a transaction um that is what we are going to execute and I have this user certificate which is a user certificate generated every time you use the the protocol. So um in order to get one you can just run this script within the flow runner.
Once again all this is in the documentation so you don't have to you know try to memorize anything. You just have to run it and then you'll get your user certificate which will live in your account. Um but yes and then we have our pool which is the specific pool we're interacting with. In this case it's this one right here the flow um staked flow pool which is has the number 204. Um, and then we we have our starting stake, the the swap source, right?
Where we're pulling the funds from. Um, and we have these things uh that make us allow us to have more granular control over the security and success of our transactions. We expect to have a specific amount of stake through this operation and if we don't achieve that then the transaction will not occur. So this allows us to make sure that all the funds are being used. There's no dust, you know, remaining and we have a high optimization over our yield.
Um and then finally we have this operation ID um which is basically the way we're going to link these complex positions and workflows so that they can execute in an atomic manner. Um there's three parts to a transaction in on cadence. The first is the prepare. You basically specify who has access to what, what can access what, what can be sent to what. Um and then once we have specified that then we go to the execute phase which is here in which the actual transactions are being executed.
You have multiple calls that can be executed. And finally you have the post phase which is uh you ensure that certain conditions must be met or else the whole transaction will be reverted. Um but specifically let's look a bit into the prepare phase. So here we are uh looking into the pool. We're specifying which pool we are interested in.
We have the pool ID which is this P ID. In this case, it is the number 204. And then we have the starting state, the user certificate, which I mentioned before, and the operation ids. And these are going to be created for each position generated. Um then we just have some fail saves.
So when you enter the LP position, you want to make sure that the proper ordering of tokens is uh executed and if not then it will revert them. So I mean it'll you know change the order so that the transaction will occur and then here is where we are grabbing the rewards from the the um source right so it will be this LP pool specifically we're going to grab those rewards that's going to be our source of funds this is where the funds are coming from once we have that um we're going to zap them into the liquidity position we're going to convert half of that um you know staked uh flow into flow and stake flow so we can enter the LP position and then finally we are going to source the output of that which is going to be the LP tokens itself. We're going to grab that so that we can direct them directly into the farm once again. Um once we have um all of this in in place and we have all the fail safes um that we have then we can just run the transaction. So here this is the transaction I'm going to be running specifically um basically I'm running the uh restake transaction and I have my in the interest of time I've prepared a couple of stuff but basically I specify the network and my specific account and as you can see here this 204 is the pool ID and uh we're going to execute this transaction but first let's make sure uh we see this so um just try to keep this in mind right now um the staking position is 1669.
98 and we have $1,359 with89 worth of assets here and we have earned8750 whatever um in staked flow. So um you know we could claim it here and do this whole thing manually but that's kind of what we want to avoid. Um, so let's just run this. All right. And boom.
Everything happened in an atomic manner. All the funds got received. They got swapped into the um LP position. And then that LP token, we put it back into the farm. Let's look into what happened.
So you see everything you know I'm scrolling scrolling through right here is exactly what happened in atomic everything that we specified. So you can see how powerful this is. A huge you know complex D5 workflow has been done in a single transaction. Just one one transaction was all it takes. Um and then you can you know automize uh automate all of this.
So um yes, basically what you're going to see here through the events is the the specific uh granular controls we are giving out and then the specific transactions we are executing uh you know for example uh you know pulling the funds from the the farm like claiming them and then zapping them then grabbing the LP tokens and putting it back into the farm. And then if we go back here uh we're going to see boom you see this has changed. It was 0.11 before and now it's it's has been reseted because those those rewards we were receiving these these rewards we were grabbing from here we once again rest it. So we autocompounded this whole strategy.
Now I've showcased two things here the scheduled transactions and the flow actions. It you can see how this becomes very powerful when you want to optimize DeFi in general. um instead of having you know 20 different things, 20 different protocols for 20 different assets uh you can start automating these workflows. You can set up a schedule transaction that will execute a flow action. Um and this way you can automate and optimize for your yields.
Um but yes, these are the main things we have uh created here on the Forte upgrade. Um another cool thing is that we now support natively bit 128 uh uh fixed math. So you can have a very granular control of detail uh for calculating interest and for general D5 applications. Um because those who have worked with D5 before uh know how much of a pain in the head it is to be uh calculating those spec that position um uh in destinies. Um but yes, please check out the documentation.
Um I'm sure you guys are going to love it and don't hesitate to contact us if you have any questions related to Forte or flow actions or schedule transactions. Thank you. [Music]
Automatic transcript — names and jargon may be misspelled.