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

Loading player…

Funding Mechanisms of Perpetual Contract | TSK, Perpetual Protocol | ETHTaipei 2023

ETHTaipeiMon, Oct 9, 2023, 12:00 AM

Transcript

my name is Xiao I'm from Perpetual protocol and today we're going to talk about the funding mechanisms of Perpetual contract so this is the outline of today I'll start with the basics of funding and then dive into the two different genres of funding mechanisms which is periodic and block-based funding and lastly a little bit implementation where there won't be code just some easy math and finally liqueur in section so my name is Xiao or you can call me TSK that's my Cisco handle so I've been a Smart Country engineer at Perpetual protocol for about two and a half year which is not really that long but also long enough to partake in like sound of greatest events in crypto for example like FTX so I call myself a veteran for surviving that and also just taking a piss out of myself out of lab misery and you can also find me on medium and GitHub and I sometimes write some crypto related articles on magnesium and those other things Okay so so um let's start with the basics so I believe most of you have used Perpetual contracts so however maybe some of you don't know what Perpetual contract is so basically Perpetual contracts is like traditional Futures but it doesn't have a expiry that's why it's called Perpetual however because it's perpetual it kind of needs a similar function as the expiry from the traditional Futures and funding is this mechanism so it can be seen as a regular settlement schedule so for example on binance there will be three funding events a day meaning that every eight hours users will be paying or receiving fundings on binance so funding is the regular settlement mechanism of Perpetual contracts and it can also be seen as a reward or cost for holding positions so because on derivative products people can go long and short on these Perpetual contracts so funding is also a mechanism to try to reward or try to charge people from holding their positions and therefore it has the mechanism to align the two prices on a derivative exchange which is the Perpetual price the price that users are trading on lease Perpetual exchanges and also the the underlying assets price so for example this is a screenshot from our Exchange LA the BTC uh Perpetual Market has two prices the first one is the the real-time price that is Traces by users on our Perpetual protocol V2 and there's another price which is not really clear here it's called index price it's the underlying assets Pro price for example on uni Swap and in our cases from chain link so you can see there's the price difference between lows 2 and funding mechanism is the mechanism to draw closer those two because theoretically leads to prices should be really close so that users won't be paying extra on these derivative exchanges and uh before we dive into how we Define funding rate uh funding let's first quickly go through funding rate and Funding payment so funding rate is the level of deviation uh of those two prices so um funding rate describe the percentage of the difference between those two prices and Funding payment is the correspondent payment to funding rate based on a user's Precision size so you can imagine that if a user has 10 BCC long positions then he or she should be paying 10 times Funding payment and those holding only one BTC loan positions yeah that is logical hmm and a really easy cat one line uh a really catchy wine liner is to remember how funding rate works is if funding rate is positive then long Precision holders are going to pay short position holders and vice versa if funding rate is negative then sure position holders is going to pay long Precision holders and we will Define when a funding rate is positive and negative in the next slide but it's worth noting that lease funding payments only occur between Traders so exchange should have been taking a car from this funding settlement unless the exchange itself holds a long or short position otherwise this payment only happened between Traders okay so um in order to understand how funding is calculated we first have to introduce the premium and premium is pretty easy it's just two prices the difference between two prices and the first one we call a market price a market price is the price that is trading on a derivative Exchange in the previous sample um yeah is list price so we call this price the price on a derivative exchange the market price and this is the index price as I said it's the spot prices of this BCC on other spark exchanges so premium is just the difference between those two prices so and this premium is also defined as the Funding payment at a per position size so if we imagine that there's a user having one long ET uh BTC position then the premium is the amount of money he or she has to pay a day because he or she is holding that one BTC position so these are the definition so if you look at an example if the eth market price is a thousand a hundred and index price is a thousand then the premiums is 100 that means the cost of holding this position one eth position is 100 a day so this is called premium and if we Define funding rate funding rate is actually just a degree of deviation of uh market price from index price so premium is market price minus index price so funding rank only describes how deviated market price is from the index price so if you're using the same example then it's actually 10 percent so these are actually quite simple and as I mentioned earlier if there's a positive funding Ray then that means long Precision holders are paying short position holders and the reason why there's a positive funding rate is because layers of positive premium and the reason is the market price is higher than index price that means users on a derivative exchange is actually optimistic about future prices that's why they are trading above the index price they're trading at a higher price than spot exchanges that's why there's a positive premium and lowest passes the funding rate so um this is the full version of the previous little screenshot on all exchange we listed uh the funding rate of the past eight hours but list doesn't have a lot of meaning so we can see that in this situation there is a positive funding rate over the last eight hours although the premium in this screenshot is actually negative but because it's a aggregated version of eight hours so these two things don't necessarily align yeah okay so um we can take a look at the Historical funding rate this is a data from uh terabit terabit is also another exchange and it's the data of BCC uscc Perpetual Market so um this is not the clearest but I guess you can see there are some green bars here you know so several scattered red bars and so green bus stands for positive funding rate and red bars stand for negative funding rates so uh as we might agree might that last bull market is from the middle of 2020 to the end of 2022 around our time so we can observe that during the bull market the funding race were mostly positive which fits the previous definition of funding Ray because oh no sorry because there is a positive premium because during a bull market users were optimistic about the future prices so they're willing to pay a positive funding Ray a positive Funding payment to shore position holders and that's why there's a consistent positive funding rate and after 2022 we could observe several negative funding rates because and this means that users were more pessimistic about the future prices and those are willing to show positions even though they are actually paying uh funding rates to Long positions holders in the bear Market and uh so as we might recall like a month before it was the usdcc pack event and this is also where I shorted so um if you also lost money from the usdcc pack event not because of the packing itself but because your hands felt itchy and you did something on a derivative exchange then you're not alone because I'm part of you yeah okay so now we get into the two genres of uh funding mechanisms implementation okay so um I mentioned before that premium is the Funding payment ate but a day is quite long right because there are like day Traders so uh depending on how the funding is implemented how often the funding payments are settled I'd categorized lemon into two genres the first one is periodic for example like Finance it's every eight hours so I'm actually not sure because I haven't traded on it for a long time so I guess it's 8 A.M 4 P.M and 12 a.m so every 8 hours Traders on finance will be paying fundings or receiving fundings or the defunct FTX uh there used to be I remember once per hour so I'd call them periodic funding mechanism and on our Perpetual protocol V2 or the previous data thereabit uh I'll call them either Block Base or continuous funding events so uh the reason why lyric are two turns is because I guess most people use continuous low it's not necessary case but we do use it as Block Base because we are a decentralized exchange so we kind of want to call it using a more blockchain generics term because blockchain block so the funding is updated every block and those we call it block based funding yeah so actually they're on such a big difference the difference is merely the granularity of settlement frequency so we can imagine that every eight hours that means it's um 60 times 60 times 8 which is a big number so the funding frequency of finance and FTX is many seconds well on terabith it might be every second and on Perpetual protocol V2 it might be every 12 seconds so the difference is actually just a granularity of it however this granular list difference actually leads to some of the pros and cons of least to genres so here's an example of the screenshot of two mechanisms so we can observe that most of things are same however there's a difference I don't know if you can see or not there's a countdown so they go have funding but there's an extra countdown on binance and that means uh until the next funding events it will be another 6 hour and 24 minutes however there is no such thing on Perpetual protocol V2 because it's a block based funding mechanism because there's uh the funding on Perpetual program V2 is settled to every block so it's kind of meaningless for us to show what is the expectation of next funding events because first the funding is really small it's just the portion of 12 seconds out of a day and uh yeah that's the reason okay so uh this is just a repetition of the what I said previously so on periodic funding exchanges users only pay or receive funding only hour or at assess at the time assessment and however on continuous or block based exchanges funding is calculated every block or on every new trade hmm so there's actually a not necessarily a loophole but definitely a room for gaming assistant um periodic funding exchange is that users can actually avoid paying funding or rush to get into a position to receive funding at a last minute so if now it's 7 59 in the morning and I know that if by holding long positions I'll be getting funding then I will want to get in get a long position and wait for one minute and receive the funding and then close it as long as the transaction fee is low enough so on periodic funding exchange there is this little room for gaming assistant or arbit charging however on a block based funding exchange is not necessarily the case at least we haven't observed any arbit charges I'll be charging against funding of every 10 seconds yet um so I've made a little comparison of two mechanisms I intentionally left the right hand side empty select the page one look very messy but you can imagine that the pros of periodic funding is the cons of block based funding and vice versa so we can focus mostly on the right my left hand side your yeah your left hand side too okay so um the first advantage of periodic funding is that it's the implementation of most exchanges so it's mainstream and I also mean that if there are coders that Arbitrage between different exchanges then they're most likely to be arbitrizing between periodic funding exchanges so it's easier for them to integrate with another periodic funding exchange then uh block-based funding Exchange basically just the network effect of this uh adoption and the second point is funding based on more predictable however this predictable doesn't mean that users can predict the future easier on this exchange there's no such thing but rather because as the screenshot suggests on binance or other periodic funding exchange they do tell you the expensive funding rate unlike us is the historical funding rate so users can actually react to this expectation because uh let's wear the room for arbit charging comes in so being predictable means that users can react to least expectations these expected values easier while on block based funding exchange we don't even demonstrate that value because it is kind of meaningless and the third point is since most transactions are going to happen only hour so we can expect that there are definitely more transactions happening on the hour and those higher transaction fees and also smaller price deviation between contract price and also index price but we could all we can only guarantee Liz on the hour but there's no guarantee throughout the entire funding interval for example on balance that be a hours hmm okay so um as for the cons of periodic um so the first disadvantage is that uh I think anxiously this is an extra concern for the Traders at least for non-arbit charges or human Traders because apart from deciding whether I should go long or short on a position I also have to consider the time when I'm opening this position when I'm closing this position because imagine if it's like 7 59 in the morning and after one minute I will be charged of funding if I open a position right now now I definitely want to delay my decision by two minutes in order to avoid paying that funding however this lab means that list mechanisms actually making me factor in more things into my trading decision so anselves history is an extra concern however the later part of this sentence is quite controversial so I believe that periodical funding exchange is less profitable for human Traders and but I'll explain it in the pros of block based funding so let's just leave it for now okay so the second disadvantage of periodic funding is that it is not ideal to be implemented for uni throughout V3 style LPS so some of you might be familiar with uni smart V3 mechanisms so in short it means that LPS on unisart V3 they can provide liquidity to a customized range so if the price gets into the customized range then the balance between two assets let's say it's a ECS and usdc pool then a balance of flows to tokens will fluctuate as long as the price stays in the range however once the price goes out of a range then lists the asset balance remains uh untouched after price goes out so why is it on ideal for periodic exchange to be building on top of Unison B3 and the reason is that oh sorry um so uh as we mentioned for example binance charges funding every eight hours however that means that for a LP a potential scenario is like that LP has no position size from 12 am to 7 59 am so three out of 7 hours and 59 minutes the lp has zero position however at a last minute because they are arbitraging bars want to arbit charge for the funding events and land the arbitrusting bar strike the price into this LP range so that means that the lp is actually paying funding at a last minute while he or she is not earning any fees during the previous 7 hours or 59 minutes so that means that because periodic funding exchange they have a really thick granular of funding frequency so it is quite inaccurate for unisot V3 Styles LPS because the asset balance of layer 2 tokens can fluctuate every second well they are kind of forced to charge for a larger portion of funding payments and I only mention this is because Perpetual protocol V2 are built on user.v3 so it might not be and this this Advantage for other exchanges but it is the reason why we didn't adopt periodic funding in the first place when we're building our second version and the last problem of periodic funding exchanges are uh it's also kind of uh controversial I believe funding rates on periodic exchanges are less accurate because most of the transactions of lease exchanges happen on the hour not maybe not most but there are definitely a lot of transactions happening because that is a time when arbit charges are sure to make some profit so compared to block based funding exchanges Traders will just trade throughout any time because they don't really have to care about funding however on periodic funding exchanges they have to pay attention to the time so um it is kind of less indicative like all the transactions are hap not all some transactions are happening on the hour instead of being spread out evenly throughout any time so I believe that if people are using the funding race charts from an exchange it is best to be a Blog based funding instead of periodic one foreign okay so lastly there's only one thing left which is a controversial uh which one is fairer for the retail users and my answer is block based funding or continuous funding is fairer for users and the reason and this is like a logical disduction of mine so you know you can disagree but I guess the logic is kind of correct so I guess we can all agree that derivative products are zero-sum games so if one person is winning then the other person is definitely losing so I think we can categorize the rules on a derivative exchange into three people three groups of people the first one is is the exchange and the second one is retail users and the third one is let's say arbitrages which means coders who run arbit charging bots so they can trade at highest speed and they can also arbit charge for funding events so if we first take our league change from this discussion because I ideally exchanges should be net positive otherwise they won't be running the exchange so we are not left with the arbit charges and only and Retail users only so if there are only two rules in this system and the also the only reason why there are arbit charging bars is because they are earning money then that definitely means that they're earning money from retail users because there are only two rules in the system so um yeah this is just a logical deduction but there's no evidence because there is not there's not yet an exchange offering two mechanisms on the same market so ideals whether there can be any evidence showing this but this is just my personal opinion and a little shout out to my teammates especially William for helping me to produce this comparison table yeah okay so now we'll get into a little bit implementation of the funding mechanisms it's actually very easy so we'll start with some numerical examples so here we have a list of time funding rate and index price so at Time Zero we're using timestamp here so for example it's time set a thousand and the funding rate is 0.

5 percent and the index price we call it I zero so we can imagine that if there's a user with a position size s then and the position is open between t0 and T3 then the Funding payment should be s times the funding for the time between 1030 and a thousand and the funding for 1045 between 1030 and Etc so um a little explanation for why we're multiplying uh index price here is because we want to get a fair value Fair position value of this position size so for example um if it's eth then we have to end the position size of one then that means the notional value of this position size is the south end or it's a thousand two hundred we have to first guess uh guess the notional value of a position and then multiply it with the time how long it lasts and also the funding rate yeah so this is the implementation of a funding mechanism of how to calculate funding payments however um so so actually no matter whether it's a block based funding exchange or it's a periodic funding exchange they're actually not that different because as I said the only difference is just the granularity of it so you can imagine that that on binance this time difference can be eight hours and our exchange this time difference can be 12 seconds or 20 seconds but the only difference is just the value difference of this timestamp difference and I think some of you are engineers and as an engineer we always know La we have to avoid running Loops all the time so whenever there's a chance to reduce the complexibility meaning not using loose then we have to do it because it's a great boost for the efficiency of the code so instead of running Loops for every users that are that have open positions over a long period we shouldn't be running loose but instead we should be storing a global accumulative value so for example let's define the accumulative value at Time Zero is zero and if it's at time one we add the difference of the timestamp multiplied by the funding rate and the index price and for time 2 it's actually the global cumulative value at Time 1 plus the extra numbers here so this form actually looks very similar to the things on the right hand side so what we are trying to do is to replace the right hand side with global accumulative values no sorry and then we can actually Define Funding payment as Precision size multiplied by the global cumulative value at time closed minus Global accumulating value at time open and let's open and close describe the behavior of a position so in the previous case it's actually the position size multiplied by the difference between the global cumulative values between T3 and t0 so we can also see that this is exactly the global cumulative value at time three and the only reason why we're lacking the global cumulative value at Time Zero is because it's zero in this case so we can actually simplify the Funding payment implementation into only a multiplication and a subtraction and we also need some update rules for this mechanism and so first of course we have to store those cumulative values we have to always store those cumulative values and the after raw of least value is that whenever a user takes action meaning opening a position closing or increasing the position size we have to first settle the existing funding payments of flat user so I have to settle their Funding payment to zero because they want to update the position size so we have to first settle the funding payments of lab position size and then we can update the new position size and a new Global cumulative value because remember that here we always need the global cumulative value when the position is open or updated so this is the this is how we Implement a funding mechanism yep so this applies to both okay this is a mathematical form but it's not really not important however as I mentioned in the comparison table of two approaches uh I mentioned that periodic funding is actually not ideal for exchanges that are built on top of unisot V3 so um low list is not a Perpetual protocol V2 Workshop so I'm just trying to describe some of the challenges we got into when we're building the funding mechanism on top of Unison V3 so um I'm not going to repeat them I'm just going to stay in this slide for a while and if you're interested in the answers to these challenges you can you're welcome to come up to me or any of my team and I've written an article explaining it which is the first URL and I'll be handing out a slide later so if you're interested you can take a look at these articles and uh so actually this talk is actually the second URL in the PPC version yeah and the third URL is the website uh by the teammate William so you can check out the funding rate of many changes on his website okay so now q a section is any [Applause] [Music] hi thank you for the talk um so I'm from Diamond protocol we used to build a basis trading War based on purp what we found out so that's about a year ago so what we found out is the founder rate on purpose actually opposite direction to centralized exchanges so I just want to ask you whether it's still going to be the case for v2 uh so we actually talk about this internally and we believe it's a the reason is that the trading fee on our exchange is generally higher than other centralized exchanges because usually have like VIP programs where for example you buy BMB then you can hire your VIP tier so that you can enjoy a lower take a fee for example I remember it's like 0.03 on binance ontaker's fee so we believe that the reason why there's like a larger price deviation and also opposite side of funding it and the reason is that we generally have a higher trading fee so RV charging bars are less willing to trade on our platform and to you know draw closer the prices so let us our current conclusion yeah um so what we currently build is actually on universal V3 um a leverage liquidity platform so people can avoid being you know short squeeze or long squeeze using traditional derivatives so for v2 Mike for you know Perfect Two my question is do you guys see less chances of Traders getting squeezed around a specific time uh sorry can you repeat do we see do you see so will that be less possibility for a Trader to be squeezed sure squeeze or long squeeze around a specific time especially before just before the funding rate um I think I'm unable to answer this question but we can discuss in privately yeah sure yeah sorry about that no problem hello I I just wondering uh if the funding rate can be predictable or the form the formula is used uh old data um be predictable do you mean General funding right yeah can we predict the future because fundamere is kind of the future right so solar day is is n't let's say it's a which state has already do you mean the funding rates formula the funding rate formula London the number is from is pre is predict or use old oh okay so it's not predicted the phone uh I think it depends on the two genres of funding implementation let me find it so are you describing this one whether it's predictable on Perpetual protocol V2 yes but but I I still for example the example is calculate the time from t0 to T3 yeah so uh the funding rate like uh 0.5 percentage this number is predictable no no it's calculated because funding uh the formula is premium divided by index price right so as long as we have the premium at time two or time three then we can get the premium and as long as we have the index price we can calculate the funding rate so lease funding rates are all calculated for example this point three percent is calculated using the data between T2 and T3 and this point three percent is also calculated using the database in these two so these are all calculators so this is all happened thank you no problem okay um let's run a plus for Xiao again thank you [Applause] [Music]

Automatic transcript — names and jargon may be misspelled.