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

Loading player…

PancakeSwap Workshop - ETHGlobal London 2024

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join Chef Mist from the PancakeSwap team to learn how to build hooks on PancakeSwap v4. For more information, check out their documentation at https://developer.pancakeswap.finance/ Embark on a journey with ETHGlobal London, where innovation thrives, collaboration knows no bounds, and hierarchies fade into self-sovereign ownership. The most skilled web3 developers, designers and product builders from all around the globe come together for a weekend-long adventure to advance the Ethereum ecosystem at ETHGlobal London in March of 2024! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Music] hello everyone I am Chef Momo a product manager at pancake SW today we'll uh discuss uh pancake sw's Journey our latest itation of the protocol that is the version 4 and what's in it for you as developers so uh we launched V1 uh in 2020 end of the year uh we were the first deck on BNB and uh we launched the B2 amm style uh and then shortly after we launched in 2021 the version two which supported the stable swops also implemented the cake buyback and burn and between V1 and V2 we achieved quite a few Milestones uh so we were the first billion dollar liquidity project on BNB chain and then also reached a peak tvl of around $8 billion then also held like 50% market share of the total volume across dexs last year we launched version 3 which supported the clmm uh type curve and expanded multiple chains uh we are on a total of nine chains right now and we also expanded on multiple product product vertical such as gaming derivatives and staking uh on top of this gake turned deflationary last year with meaning that we are now making more Revenue through product verticals as compared to what we're giving out as incentives so today we are here to announce pancakes of of V4 and uh yeah so so let's see why we need a version 4 right so the current version lacks the flexibility and the adaptability to kind of support any pricing curves or add any custom features on the Go without reimplementing the core protocol and it also kind of has huge gas fees and it's not like perfectly optimized so essentially it becomes difficult for developers and D5 protocols to benefit from our user base and deep liquidity and and build upon us so what do we want to achieve with V4 uh we want to become the core liquidity infrastructure to support the defi ecosystem and then simplify product development and Innovation for developers and protocols and also introduce gas optimizations for scalability and mass user adoption and how do we do it through a three- layered modular architecture uh so there like separate modules to implement the amm models and the custom features through the custom layer which is which is the hooks and we have also implemented gas optimization techniques like single turn flash accounting and ERC 6909 support right so we'll look into each of these layers from here the first one is the accounting layer of the Walt where Walt is basically the point of entry and exit for all user operations and it stores all the tokens uh balances in this particular contract so how the work how the how the flow works is that the external contract of the caller require reques the log with the w first and then performs any action such as swapping or liquidity adjustments then further the pool managers executes those actions and then informs The Vault of any balance changes and the net settlement amounts of the currency and then at last The Vault uh kind of settles it back with the caller uh in total right so uh this is how broadly the Vault works and maintains The Ledger of all the transactions and now the gas savings come with flash accounting implementation which we'll discuss later on uh in detail so from here I'll uh like take walk you through like by each step and then maybe with some code Snippets to make it clear on how it works starting with the uh First Step which is acquiring the lock the method lock uh basically helps the caller uh acquire the lock and perform any action like we discussed and then uh if the net Delta you can assume the net Delta is the net set M of the currency which is owed by or to the caller if that is not settled then the transaction is reverted else uh the transaction is completed and the lock is released so this is the method lock the other one is the pool balance Delta which essentially does two things so managing the net uh currency reserves on the pool manager level as well as uh on the Coler level so you can imagine there like multiple pool managers and each are linked to a single vault which has all the token balance so it's important to update the pool manager reserves because they all kind of map it back to the wall right so uh there are two things which are done in this method one is um updating the pool manager results based on the caller action and the other one is Computing the net settlement currency which is owed to or by the caller right so the next one is essentially what how the transaction happens between the Vault and the CER so there are two key methods one is take and the the other one is settled the take is used for callers caller to receive the net settlement from The Vault while the uh settle is used uh by the caller to kind of transfer the net settlement to the wall and now it's also possible to store like Surplus tokens in the world by minting like ERC 6909 so you don't need to kind of transfer tokens to and from your wallet to the Vault you can store it within the wult and you can uh use it sub quently uh later for other transactions so you can Min those ERC 6909 tokens and then burn them later to use it so this reduces a lot of uh redundant uh transfer of tokens between the wallets and uh results in like gas savings now as we discussed Walt also benefits from flash accounting so in short uh firstly let's see what flash accounting means right so in V3 uh the typical flow of a multihop swap works like uh at so let's say you want to swap like token a for B for C right and then uh at each of these sub transactions there there would be a uh movement of token B for example uh from or to the uh pool and with changes in Flash accounting uh which is the V4 where all of these transactions happen at once and then the net balance is finally settled with the callar so as you can see in V4 uh only two token transfers happen which is transfer of token a and receipt of token C while for V3 you can see that token be is received and then transferred again right so this this kind of leads to gas savings uh now the flash accounting also benefits from tangent storage which is enabled by EIP 1153 recently uh a part of the E Denon upgrade so in short what trans storage does is that it uh avoids uh any serialization meaning that you are now able to store the data temporarily which is discarded at the end of the transaction and then you don't need to write or read permanently uh on a on a permanent storage right so that again saves a lot of gas moving on to the next layer which is the pool manager so pool manager is something which has the amm logic and we have different types of pool manager implementation at launch uh the first one is the concered liquidity am and the other one is liquidity book amm uh now the good part is that it's possible to add any other uh future amm designs using this layer without any reimplementation of the code protocol so how it works is that previously in V3 uh there was a factory contact which used to create uh different contacts for each of the pools in V4 all of these pools will sit within the particular pool manager so pools belonging to the clmm pool manager will sit inside that while the belonging to the other amm designs will sit within that that particular contract what does it it it simplifies the management and creation of uh liquidity pools reduces the uh cost of gas creation by 99% and also for multihop transactions because now you don't need to move those tokens between different contracts you can just settle it within the same contract uh and that again leads to a lot of gas saving so the key part here is uh you can add any amm uh Logic on the go uh using this layer now with look at like how pool managers broadly on a high level kind of what's the flow with the pool manager so initially the first thing it does is that we'll check if there's a before swap call back uh implemented so this is basically the hooks which we'll discuss later on but it will check if the before swap call back is implemented according to the flags mentioned initially during pool initialization and then if there's some implementation it will execute that logic within the hook contract otherwise it will just move on to the next step it further will then execute for example we have taken the example of swap in this in this particular uh Cod snippet so it will execute the swap Logic for the respective amm type uh here and then it will like we discussed account for the net uh balance Delta or the net currency that needs to be settled further it will again do the same thing for after sop call back which will uh check if there's a after sop call back implemented in the hook contract and then uh yeah proceed according to that so like we're discussing the callbacks previously uh the hooks here which is the custom layer allows any of uh all so hooks basically are the external contacts which are separate from amm Logics or the code protocol and it can be deployed by by developers right so it can be uh integrated with any of the liquidity pools at initialization and so and it's it's like immutable call back so once you kind of initialize a pool using hooks with whatever call backs then it's not possible bble to change it uh there are five key actions from initialized SWAP add or remove liquidity and donate and then the call backs include before and after each of these actions to offer more granual control uh things you could do with hooks include developing aut types Dynamic fees uh maybe doing some kind of implment loss mitigation and much more right so we'll take an example of uh one of the hook ideas and see how it works so there's like a V cake exclusive access hook and V cake is a derivative token uh which which is received by the user after shaking cake so the idea behind the hook is that for any of the V holders uh only those holders will be able to access this liquidity pools uh for trading or providing liquidity so initially we start with inheriting the base hook contract which is uh uh which is already like you can access that in the hook template we have uh at getup and and then uh it will kind of inherit that and then reuse the helper methods now here like we discussed about implementing the flags for the call backs which is setting it to true or false so for example in this particular example what we need to do is we'll only allow swap uh for any of the traders who are holding the V balance right so thereby we'll uh flag it as true and the rest of the other call backs as as false now for the before so call back we'll Implement a logic uh which will check if the uh user has any of the VK balance and then based upon that it will let the user swap within the liquidity pool or not right uh also on top of it I'm uh delighted to announce pancakes of $500,000 developer program uh it it will consist of haathon ke commission grant program Bounty campaigns ambass program and much more we'll reveal more details soon and yeah this is the biggest program we have done for developers and specifically for V4 uh yeah and then for today's ham we have a price pool of $10,000 uh distributed across three categories the one is more about like developing a creative hook idea to mitigate the pain points uh of users or maybe creating something new uh Innovation integration is uh kind of integrating different D5 protocol ideas using hooks within the pancakes and use pancak shop as a liquidity layer or maybe also having a cross chain liquidity and trading functionality enabled and tooling and ux improvements include uh any data analytics dashboards using uh which has like the metrics because there will be a lot of pools once V4 kicks in given each of the pool will have a different hook so analytics will become a lot of uh will have more importance and will be required by the users uh to kind of take a decision on which pools and which hooks to select from so you can find more details about this on each Global uh price detail page uh on what are the eligibility criterias and what exactly are the maybe some of the project ideas we have shared over there and yeah thank you everyone for time today uh this Chef Momo I have chef burger with me and we'll help you with any [Applause] Q&A any questions I've the sorry I've dra the workshop in the middle uh sorry for that I have a question regarding the hook can you re explain what is it about the hook please yeah okay you want to understand the hooks right okay so hooks are you can assume hooks that previously there's a liquidity pool there's no possibility to add any other feature on top of that liquidity pool right now it's so hooks are externally deployed contact which where you can deploy certain Logics at any of these key actions for example swap right there are two call backs which you can Implement so let's say before you swap before the swap method is called in that particular let's say Sher comes to a pool and wants to shop right there is a Poss possibility and that is what hook hooks enable that you can Implement a logic before shop and after shop you can define a contract which will imp implement this logic and then you can while uh pool creation you can kind of uh mention this hook contact address so ideally every time any of the swap called swap before swap will execute your logic defined in the hook contract and after swap will also do that so it's possible to kind of implement any type of logic for example let's say custom oracles right so you want to let's say uh relay uh you want taking a simple example you want to create a median Oracle which takes the median price of the last last 10 data points for that you need on every swap you will kind of update the latest you you'll fetch the latest uh Pool price remove the last one and then take the median uh whatever price from that right so you can keep on doing that and then you can anyone else can use that particular hook to get the uh so it can work as a Oracle right so you can Implement any of the complex Logics using that so we don't need to do any of the protocol re-implementations and yeah so the possibility these are like endless yes yeah um do you have any example repos for existing hooks that we can use as a template or yes yes you can find that uh at our GitHub uh we have also mentioned that uh in our developer docs as well as the resources under the global uh page dashboard yeah any more questions question yeah why the mask Corona is over it's bre now it's bre yeah yeah if not then uh if you have any questions about V4 or the develop program please reach out to us at a booth it's located just at the entry and then yeah happy to answer anything thanks everyone yeah [Applause] [Music]

Automatic transcript — names and jargon may be misspelled.