APWine 🛠APWine Devs 101
ETHGlobal·Sun, Oct 9, 2022, 12:00 AM
Join Ulysse Ramage of APWine for a workshop titled "APWine Devs 101." Welcome to APWine Devs 101! This workshop will help you take your first steps with APWine, the protocol for future yield derivatives. Using APWine, you can create unique yield strategies leveraging future yield tokenisation, a new DeFi primitive allowing yield to be retrieved in advance and at a fixed rate. What we will go into: - Overview of the platform, contracts and mechanisms - How to use the APWine SDK to tokenise and trade future yield - Creating your first optimised fixed-rate yield strategy on any supported asset - APWine bounties for ETHAmsterdam 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] cool i think we're ready thank you guys for coming seeing some familiar faces here um so this workshop is going to be on ap one on building derivatives on yield and it gonna be split into three different parts first part is going to be presenting the protocol itself then we're going to see how do we use ap1 using our sdk that we implemented and then there's going to be an outro so first off what is ap1 building derivatives on yield what does that mean we are one of the first protocols to enable yield tokenization so basically getting your yield ahead of time first we need to understand why do we do this if you were here during the device summer of 2020 you may have noticed that there was extremely volatile yield which is still the case today right you're seeing insane three digits apis that are simply not sustainable um so this was the the kind of issue that we noticed and we said okay there's no mean right now to hedge your risk on this apy volatility so how do we enable this this is where ap1 comes in we're a yield tokenization platform so basically this is a new primitive in d5 that enables you to split your deposit and your future yield into two different tokens that i'm going to describe a little bit later on this enables you to buy sell hedge and trade your future yield in advance now we get into the more technical part for you hackers how does it work first you get your interest bearing assets so this is like a die if you're working with ava simply generating yield each second right so this is an interest bearing asset because it generates yield you simply are going to deposit this into ap1 and ap1 is going to split that token into two different ones the first one is the principal token the principal token represents your initial deposit the value of the initial deposit at the time that you deposited on the platform the second one and this is where it gets very interesting and is the future yield token so this is the primitive that we came up with the future yield token is going to represent all the yield generated by the initial deposit so let's say um okay who has some funds on ave right now are you farming on any farms are you familiar with d5 are you farming any strategies let's say right five percent on usdc right that's pretty reasonable now this is going to be if you deposit a hundred dollars on ave you're going to get a pt that represents your hundred dollars plus the fyt that is going to represent all the yield generated by this hundred dollars so at the end of the year if you're getting five percent this fyt is going to be worth five dollars that's how it works once you get this you can build uh amazing strategies with the amm that we built so basically the fyt and the pt can be freely traded at any time on the ap1 automated market maker just like if you are on uni swap so if you sell your fyt you basically get your yield ahead of time that's how it works so our ap1 amm we iterated on a on a few months and we found out the best design that you know we can trade between pt fyt and underlying i'm going to show like why it's very necessary in our case and how you can build very amazing strategies on top of this amm now here are a few strategies that you could build at this hackathon and that could be very interesting to make um first is the pt trading so this is uh remember that the pt is the value of the initial deposit so you know that at the end of each period like at the end of each year one pt is always going to be equal to one die or whatever you deposited and using this very simple fact in the discount that is on our automated market maker you can basically buy pt at a discount so let's say you buy a pt for 0.9 die instead of one die you basically make 10 percent apy at a fixed rate because you know for sure at the end of the year it's going to be a one to one ratio you have also yield sections very interesting strategies to basically compound your yield ahead of time this is something that's only possible with future yield now let's go to today's workshop now that we've presented the protocol a little bit what we're going to build today and what you can also you know improve on your own at the hackathon is going to be fixed rate by selling future yield so how do you do this with ap1 leverage yield tokenization and the ap1 amm to secure a fixed rate on future yield if you want to follow along which i really recommend you to do so you're going to need node.js and yarn installed on your computer as well as cloning the repository so the repository is here github.com ulidev slash ap wine dash workshop if you want to clone it and follow along it's very simple you just need to copy the environment file and then simply install the dependencies once you're done with this and this is what i'm going to do right now with you you can basically start a node so this is starting a local blockchain like a fork of mainnet which is what we're going to build on and then follow the steps one to five so yarn step one five i'm going to show you how this works right now but it's been made to be very easy to follow along so first you're going to want to go into the directory and then just install all the dependencies here i already did it no need to do so and then you just want to start your local blockchain so run node start node and this is using hard hat if you're not using it already it's very very useful for anyone hacking on ethereum all right we got our local blockchain set up now let's go to the workshop i'm going to navigate to the workshop if you have any questions on the way please feel free to ask and enter at any time we're gonna have some time for questions afterwards but you know feel free to interact all right this is the preparation for the step one so the step one is going to be the creation of the sdk basically once you install the dependency the the package on npm is at apy sdk once you install this you get access to the protocol itself plus the amm very easily the first step is going to be creation of the sdk so sdk is equal to new ap1 sdk and then you want to provide your provider signer and the network so here it's going to be mainnet because we're building on a mainnet fork so how does it look there are you know multiple files here so in the src folder you get step one step two step three step four and step five we're gonna go through these so first step is what i just described create the sdk let's see how it looks so i just run this very simply with yarn this is how you can follow along very simply and we're done we initialized our sdk on mainnet in just a few lines now the second step is going to be retrieving all the futures now something that is a little bit more technical is that ap wine on mainnet and on polygon we're currently releasing on two platforms are currently working with 90 day futures so instead of one year like i described earlier it actually works with three months futures this is a middle ground you know between degen yield and more stable yields so this is what we went with all right so how to get the basic information of all the future votes uh by the way what we call the future is a future vault so it's basically you know this smart contract that enables the tokenization of this future yield you're simply going to want to use sdk dodge fetch all future volts and this is going to give you a promise so you know just need to wait for it if you're familiar with typescript you're just going to want to fetch all the addresses and then with all these addresses you can get more detailed information with fetch all future aggregates so this is going to give you like the duration which token does it represent and so on we're gonna see this right now how does it look this time step two so here we fetch the future aggregate you can also pass a specific address if you're interested into this specific vault you can just get all the information for this vote so if we do it step two and this is going to load a little bit uh simply because we just started our local blockchain so it needs to fetch all the information from the mainnet and here we can see that we have many different futures so this was actually in the past because we fetched from a specific block in the past we have xsdt staked eth with light of finance we also have ave ausdt so this is very interesting if you want to do something that plugs onto ave or does something with lens and then on top of one inch like you can get super creative with this we have also sushi wire i know they're sponsoring as well so be on the lookout so many different ibts interest bearing tokens that you can tokenize on ap1 and then you have the end date every time now step three is going to be getting the basic apr so this is going to be by buying the bt like i previously described so basically buying pt at a discount and making sure that the ratio is one two one so you basically secure the fixed rate this is not yield in advance it's just fixed rate which is another thing that you can do with ap1 with this we're just want to want to get sdk dot fetch spot price so specific vault address and then from into so from into is going to be the two tokens that you want to switch for example here it's going to be underlying so underlying asset is die for instance and on the other hand two two is going to be pt all right let's try this how does it look with the basic apr we can currently get at the time of creation of the workshop uh we can currently get 35 percent on the state if future have you ever seen 35 percent on a steak leaf and anyone all right so this is something very interesting that you can do with ap1 making optimized yield strategies now what if i told you that you can optimize this even further one problem with this strategy is that you are basically limited to the amount of liquidity on the platform because you are simply using your if to buy pt so basically using only one pair of the amm but like i previously described there's actually two pairs you can switch between three different assets so this is where you can take full leverage of ap wine's entire liquidity and yield tokenization by simply what we're going to do right now is tokenizing our state eath so depositing on ap wine getting pt fyg like like i said before and then selling fyt not for eth but for pt so it's basically going to go through an entire route and why do we do this if we sell our fyt for eth this is yield in advance because you get eth which is liquid right you can use it for something else reinvest it into usdc whatever now if we sell into eth and we also buy pt at a discount we just maximized our rate and this is where it gets super interesting and this is where you can get creative so let's try that we're going to tokenize our state eve so basically deposit on lido and then on ip1 which is going to give you two tokens and then doing the swap of the foit first step this you can see the the source code but it's very simple you just need to call sdk dot deposit very simple to use uh you know with the with the corresponding future volt that you're interested in so if we try this we can see that so we start with a few eth actually let me let me see here we start with um amount to tokenize is going to be 10 eth so we're playing with 1080 here and we get 9.93 pt and 9.
93 fyt now what happens if we sell our fyt for pt like i said before this can be done using the sdk again so you can do anything tokenize swap anything you can think of sdk dot swap in so you pass the amm and then you go from fyt to pt with your amount it can't get any more simpler this is going to do the automatic routing on the smart contract side and if you want you can also fiddle with the smart contracts this is for javascript but you know we i'm going to present all the smart contracts later on the repository so you can have a look at the code as well so this is going to do fyt pt and then eth automatically it gives a similar result like i said before but lower slippage because we use the full liquidity and much bigger trades can be accomplished with this so let's say if if you know you can't get 10k worth of heath to work with this with the old strategy you can actually get 10 10 times better result with this one and it's very composable you can use fyt pt if you know in any way you want so if we try this method we're going to go to the last step here step five so this is going to do a lot of stuff basically i don't know if you noticed but at every step it does you know the previous step it just repeats right so the first uh step was fetching all the futures computing the basic apr then we tokenize our future yield and then we finally sell our future yield for bt which is going to maximize our rate and by doing this we can see that we just got 10.36 pt now what does that mean anybody has a clue like what does that mean it just means that very simple as i said before one pt will always be equal to one eth at the end of the period so at the end of the you know when we made this workshop it's like one month later or two months later depending on the on the situation so this means that annually if you annualize this rate you know we just got you know 0.36 profit this means that you can get 34 percent apr on the eth which much bigger liquidity that that what i described previously so this strategy is very optimized it's something that is not currently done on the platform so this could very well be an entire hackathon project you know you can build your front end and be like okay what do we do we maximize your apr using any asset you want in reality any asset that ap1 supports which you can see with the sdk right now is your turn i hope that was clear um of course creative strategies always get very rewarded um whether it be through arbitrage you know natural economic rewards just like you're seeing on uni swap or anything so for example if the if the apy is is very low on ap1 and the api is very high on the platform itself you better buy yield because you know it's going to go up so this is one of the things that you may want to think about you can also build trading bots leverage yield as i described before you can sell your guild in advance and then reinvest it so that's basically what we're doing here it can get pretty crazy and what's even more crazy is the prices that we're giving out this weekend i'm going to enumerate these uh the first price is going to get 4 000 for the best yield strategies on top of ap wine you can also plug with any you know other protocol for example if you plug with ave or any yield generating platform such as iron as well you're eligible for this it can be anything from vaults but automated strategies you can build anything you can think of the second one is going to be 2.5 k for the best integration with another protocol so we're actually incentivizing you to try to work out a way to be plugging onto something else an ap1 and the last one is going to be 1.5 k for the most creative strategies um you know that's an open subject there's no really recommendations for this so please surprise us with any strategies that you can think of that's it for now um i hope this workshop was clear enough um i'm also here to answer all your questions during the weekend the ap one team will be here uh to help as well um so i hope you like it we're also hiring so please you know at the end of the hackathon if you really like ap1 and we would also love to work with you guys so please get in touch we will be in touch for sure thank you all for coming thank you for listening we're going to get into the questions now yeah please why would the pt be discounted that's a very good question and actually it makes sense when you think about it because if you could buy pt at a one to one ratio you know you could buy uh one one pt with one eath then what does fyt what is the fyt4 right because the fyt is basically containing the future yield so you would basically be selling or selling your fit for for a loss right um let me clear this up you work with 90 days futures right so at the beginning of the period when you deposit on ap wine let's say you deposit a hundred eth so you get 100 pt 100 fit right if you were able to sell your pt for you know 100 eth then the person buying it would not be very smart because basically you just kept the future yield also right so it's not a neutral ecosystem basically just remember that always one pt plus one fit is always going to be able to withdraw the initial deposit and that's how it works that's how ap wine stays very composable and very flexible pt plus fyt is equal to the initial thing always so you're never locked out yeah the ibt so if it's like one state eath eath is not an ibt because it's not generating yield but staked eath is because it's generating yield just like ave you put a hundred dye into ave it gives you a hundred you know a die and then this a die balance keeps increasing on your wallet this is an interest bearing token because they know for sure that at the end of the period and that's determined by the smart contracts it's always going to be a one-to-one ratio so if you buy pt at 0.
9 eth you know that this 0.9 eath is going to be worth one eath so you basically bought the rate and how does it work on the other hand why would someone sell it at that price yeah so there's many different things but getting out of ap1 you can do it in two different ways either burn your pt and your fyt so destroy them to get your initial deposit right so if you get like one pt one forty you burn these two and you get back one stick teeth this is the first way now what if you already sold your fyt so you don't have the fit anymore how do you get out there's only one way selling your pt and this is why you need to sell it at a discount for the other people buying it because you already sold the future yield right so it's worth less right because if it expires in three months for example and you just sold the yield it means that it's worth less because in three months it's going to be the same value there's like the time factor going into it if that makes sense usually discounted on the amm and is the arbitrage saying the same as pt or is it more risky good one yeah the the the ptfoyt pair on the amm has been made so that the weights are changing during the period so it makes sure that there is no impermanent plus on the liquidity providers and that's how you know this special sauce that we have make sure that the discount at any time is the optimum yeah exactly it's actually very interesting to do both strategies so arbitrage on pt and arbitrage and fyt are two strategies that can be very useful yeah now um yeah i think we're we're good with this so thank you again for coming i hope to to talk with you during the the hackathon and see what you can come up with cool thanks all right back to work [Music] [Applause]
Automatic transcript — names and jargon may be misspelled.