DeFi NFTs on Ethereum with real-time
ETHCC 6 · July 2023 · 29:53
Uttam Singh and Filip Koprivec demonstrate LayerCake for cross-network composability. The workshop transfers ERC-20 tokens to Sepolia, adds them to a Uniswap pool and creates an NFT representing withdrawal rights.
Speakers
Topics
From ETHCC 6, hosted by Ethereum France.
Transcript
[Music] [Applause] [Music] thank you [Music] [Applause] [Music] thank you okay hello uh thanks for attending this I'm Philip I come from from Flair labs and today I'm going to show you how flat Labs developed a layer cake this is a new insured in transit bridge that essentially works on all evm chains and
is able to transport erc20 tokens efficiently efficiently both Capital efficient and both quickly while still preserving this thing that's flare really really really really fights for the decentralization and not having to trust anyone except maybe the code and the validators that read it okay so the title we had is a bit long and also the description is a bit long but we really wanted to emphasize that we're not only bridging something to a new new chain we're not only minting an nft that is able to process some D5 staff we're doing all this in a single transaction so what layer cake enables you it enables you to move funds from one chain to another add additional data and
execute something else on the next stage so without ever having to interact with the secondary chain without ever having to having even gas on the secondary chain you're able to move this execute use this data and then do something more so effectively we're connecting the blockchains in a way that has never been seen before so okay let's just quickly cover the agenda and see what we're going to take a look at so firstly we have a big problem so cross chain connectivity problem we all know bridges are good we use them they're fine everybody uses them even your grandmother although it might be a bit problematic teaching her how to really open this thing here open this thing there sign it correctly and then wait for a soft confirmation then wait for a
little while so that it is confirmed for the second time and all these ergonomics can be problematic but even more the security of the bridges is in question it was in question a month ago it was in question previous week so we know that there is still something that we need to do there and secondly what we can do we can we can use the bridges to connect different chains and layer cake is a good solution here providing you with the ability to bridge both tokens and the data directly and then we'll see the demo how this can be done how we can provide liquidity to another chain how we can use the liquidity on another chain to enrich the first chain use this trustlessly efficiently and then if the time permits we'll do some hacking and see exactly how easy is it to use this
and how quickly both the networks can process this data okay so what's the problem let's take a look at a really really really simple problem you're watching the news and the only thing that's coming at you is some danger there is inflation you've got a bunch of tokens locked and maybe it's even worse you have a debt you have a Dell treasury that's got a bunch of tokens locked and because you can't use them because they don't Network when you can't really tap into all the liquidity tap into all the available things that are there you're effectively losing money not just for yourself but also for somebody else so what you're going to do well you want to do something you want to make those tokens work for you and even for
somebody else so what you can do well you want to bridge them to somewhere else you want to use these tokens in either another protocol or in another chain so and to do this you can use an existing bridge but we've all learned that Bridges can be slow I've seen Bridges operated by human operators and boy was I not happy I've seen bridges that were quickly exploited and if you were maybe on a talk yesterday or two days ago what have you learned from ECC 2020 bridgehag was the most possible word you could guess if you were to guess an answer so bridges are prone to be exploited bridges are most the most of the bridges that work are usually centralized They Don't Really
provide much value they are not collateralized enough so we have a bunch of bridges that should be secured by stake but we've been seeing that this stake is not covering enough of the bridge data or if we get to a bridge that's supposedly working it's hiding beneath some sort of a multi-sik and the multi-sig works perfectly until we have a Black Swan event and we see that it's not working perfectly because of some sort of a distant distant probability that something might get wrong so using Bridges currently is problematic both from a security perspective and also considering all the developer ergonomics so you have rep is on polygon you want to wrap it somehow you're going to transfer it to I don't know to Cosmos
you want to transfer it back to polygon and you have all these prefixes rep Cosmos polygon Cosmos polygon needs and to really use it in some sort of a transaction you either need to have a swap and first do a swap or you really need to go all the other way around and properly unwrap it does costing you both money and time to properly process those bridges so what we want to do well uh we're developing we have already developed the layer cake and what layer cake does layer cake essentially Taps into the possibility of evm machines to more efficiently Bridge the data so this is a kind of rough approximation draft diagram of how layer cake works it's essentially a two
they're essentially two practically similar contracts on each on each Network connecting the network and bridging erc20 tokens and what's making it work are those bandwidth providers in the middle that are immediately executing the transactions that people are requesting so I as a user I start on the left for example on flare deposit some erc20 tokens into the layer cake bridge thus emitting an event and now the bandwidth providers compete to fulfill this this uh this bridging once they relay the tokens on the other side they get a piece of the of the cake they get some cut and that's it I never have to worry how are they relaying it are they partially fulfilling it are they
fully fulfilling it and furthermore I can also add some data up to it what that means that means that I can say okay I'm sending 100 wrapped ethereum from Flair to sepolia or from Flair to Ether and once it arrives there I want to do something with it atomically it's not I'm wrapping some it I'm transferring it over waiting for a few minutes and then hoping that the Arbitrage opportunity is still there I'm doing this immediately immediately executing an Arbitrage immediately swapping something immediately depositing them and if that fails the whole transaction fails and I can simply simply withdrawn them in the beginning and to make all this work from a
security perspective each bandwidth provider can Bridge up to his bandwidth of tokens per specific amount of time so this bandwidth gets refreshed so we can have an efficient bridge but the length of this refreshment period is essentially controlled by how quick net the network is and how often the network reorganizes so if you have a network that is practically never reorganizing we can have the bandwidth bandwidth refresh very often that means that bridge operators the bandwidth providers can essentially Bridge huge amounts of data with only a small stake if you have a network that that has a problematic reorganization's capabilities we might be forced to enlarge this data but most of the time
we can do this pretty efficiently and they only get paid in the collateral in the tokens themselves so what that means from a user perspective we're abstracting away what's happening on the network so you're starting your depth with the user on the left that has no idea what's actually happening on ethereum for example they don't need to have the gas tokens for ethereum they don't even need to have a proper setup wallet on ethereum you're paying for this using just the layer cake bridge in the native tokens that's abstracting quite a bit of different networks away okay so um what are we going to do how are we going to solve the problem of having a debt treasury with too much tokens and not enough use for them well
we can use layer cake to start on flare transport the tokens to ethereum chain where there is a bit more liquidity swap the tokens to some sort of a uni swap pair then deploy then deposit them into a uni swap V2 pool and just start minting some transaction that start minting the fees for swapping the things on uniswap once we do this we've essentially completed the first leg of our transfer so the tokens they're still ours we still can control them but they're somewhere else doing some work and this has all been done using the layer cake as an intermediary and once we're finished we can again instruct the layer cake this time really abusing the
ability of layer cake to transfer data over we push the data over requesting the withdrawal of those tokens we provide I don't know a password we provide additional data for unlocking and the receiving contact on the other end withdraws this liquidity from uni swap swaps it back to the graph ethereum and then transport it back to flare when we get hopefully a bit more of the original tokens without ever touching the second chain and we can extend this composably we can extend this we can compose those things practically in an unlimited fashion so we might be able to then provide a bit of liquidity from ethereum to polygon to somewhere else to somewhere else and then gather them all at the same time and push them back okay so
um let's see the demo I'm just gonna re-mirror this okay so this is the depth that's going to facilitate our demo so as said before we're going to start on question two so this is a test net for flare and we're gonna Bridge our tokens over to sepolia we're going to deposit them to a unisub V2 pool and that's it from there from
then on we hope that uni swap will do the job instead of us okay so what we need to do we need to select the tokens and just I don't know token 4 and token 7. and we need to select the amount of tokens we wish to transfer to the other chain well we can either select the specific amount of tokens in the native currency but it's usually easier for user to select it in dollars it's easier to approximate stuff in dollars so what we can do we can just say okay I'm going to transfer I know thousand dollars of ethereum and the question is how much ethereum do I have to transfer for a thousand dollars well to properly do this our dap will need to query some sort of an external exchange external Oracle but if you run flare as
you initially start you can directly tap into the flares ftso system which is a native Oracle ingrained directly into the network so you can just instruct the smart contract in your app to read directly from flares decentralized Oracle thus limiting the possibility of having this value hacked or having this value manipulated by some external actor so you're totally bypassing anything external you're just saying look smart contract I want to transfer this amount calculate all these directly on chain okay once we have this we just need to deposit it and the deposit is pretty much a simple transaction on flare so we sign this the smart contract here will instruct the layer will will deposit some amount of
funds to the layer cake and provide additional data we assign this and what we now need to do we need to check what's happening and the easiest way to do this is to check on Explorer so what we see here so we executed the transaction start liquidity farming and if we check it a bit more thoroughly we can see that what the transaction really did it transported a bit of wrapped ethereum so the thing we wanted to transport firstly to layer cake and then secondly the layer cake decreased the amount by Sum and send it to the that address as a source of a fee so once we have this the layer cake essentially starts working so with a method
so we're here on the first step we will meet the deposit and now this is getting breached and the receiver contract will soon soon start processing this so how do we know that the receiver contract is processing this well we again can check the block Explorer on the on the on the other side and I guess I'm limited and we can see that some standard operations from 39 seconds ago were being executed so immediately after the event was emitted on the flare side layer cake bandwidth providers picked up the event and started transporting it to the other side and if we check the contract that is receiving this on the on this on this
step we can see that is just a second we can see that we got a bunch of a bunch of transactions and a bunch of tokens transferred to this one okay so uh and what does this means well this this actually means that we're now proud owners of two new tokens on unisop V2 on the contract we own on the other side and to really properly account who's the owner of this well we mint defy nft indicating that this piece of liquidity this small piece of liquidity corresponds to our address why nft well with nft we can control who the owner of the liquidity is and we can easily say
look this nft can be traded this nft can be loaned we can take a deposit on it we can loan it to somebody else and we can or we can totally transfer it and when we're gonna execute the second leg of this transaction the funds will get deposited to whoever the current owner of the nft is okay so this is now so we have this now in the uni swap V2 pool and when we're ready we just need to start the second leg of the transaction start on the start on flare layer input password to the layer cake and initiate a transaction that requests withdrawal so what we do now we start with layer cake we just push over some
information not really a value transfer but this information transfer again interacts with our receiver contract and the contract is able to properly interpret it get the data from uni swap pool remove the liquidity get the data from the nft and in the same transaction that's important in an atomic way again instruct the layer cake but this time in the other direction to start processing and to start moving all these tokens that were removed from the liquidity pool and swapped back back to the original chain so with one transaction on flare we initiate the beginning of liquidity removal and thus instruct the layer character essentially move the funds Twice first
time starting on flare and then removing the full tokens back okay so we're just going to withdraw this again we sign this on flare so we're never really interacting with anything on ethereum all this is done but by the layer cake bandwidth providers all the gas fees on the other side are paid by the bandwidth providers and also the security is such that we can always see how much the bandwidth providers are holding the residual bandwidth okay and that's it so the layer cake has ins the the transaction has gone into the other direction we now hold no tokens on the other side and the tokens are now being moved by the layer cake to the flare side let's just check another thing so one
important thing when considering uh one important thing when considering protocols like this is the security and the availability of the data and how you can really utilize this and if we check here this is a dashboard we use to quickly and efficiently check what's happening with the arrow protocol we can see that both on the destination on the origin and on the destination we've had those two big value transfers so we can easily see what the Bandit providers are doing and how their bandwidth is being depleted so we only made a small transaction so the bandwidth has not depleted but you can see that ours is much bigger than the Bots we're running to keep the layer cake alive and to see if everything is is going on
okay so that's that's mostly it so this is a this is a simple demo dab uh it's currently running live uh on sepolia and constant 2. so both test networks um the code is open source it's available on flare Labs repository and what essentially means is that we can already start building quick and efficient tabs that are utilizing this bridge to transfer to to transfer both value and data so this allows you not only to say okay I'm going to bridge this amount of value and stay there as a dead chain this allows you to bridge the amount of value and request that this value immediately enters into a computation immediately enters into something really bigger and can be
changed so let's say I Bridge something to ethereum I compose it with another Bridge from ethereum to polygon I compose it with the bridge from polygon to Cosmos and I can immediately close the loop make an Arbitrage and do all this atomically so if summer something goes wrong I haven't lost my tokens they're not locked I can just simply withdraw them back from the layer cake all these in a trusted environment without trusting anyone without having a multi-secant relying on somebody not getting hacked somebody not losing their keys and without having to really um having trust into some Central third party okay so that's it for the demo and um since the thing is live and this is a
workshop I think it makes how much time do we have 10 minutes okay so since it's a workshop it makes sense to at least show how to utilize the layer cake really really quickly and pretty much efficiently so here is a here's a QR code you can scan we had a git we have a GitHub repository prepared so you can play around and I'm just gonna open this into the into my visual studio code and make a really really simple transaction so to to just quickly show you how layer cake operates we've seen in explorer that we've had a bunch of store and execute transactions so those
are effectively bandwidth providers communicating with the layer cake by storing the transaction by storing the transaction you instruct the layer cake to emit an event by executing a transaction the Bandit provider effectively signs that this the emittance and the minting of new tokens is signed by the bandwidth provider it is guaranteed by the bandwidth provider up to the bandwidth and allows them to to effectively execute the second leg of the bridge and all this is made by the all this is effectively controlled by this big big struct that has some initial data and some metadata
related to the Bandit provider and each bandwidth providers bandwidth provider effectively also provides an ecdsh signature guaranteeing that the execution of this layer cake operation is signed by them so the security the security level of executing the transaction is exactly the same as the security level of the ethereum transaction so there is no middle ground with transaction being valid on layer cake but not being valid at ethereum it's secured by the same cryptographic protocol okay so let's let's just quickly try to transfer a bunch of funds from my custom to account to my sepoli account [Music]
the things so um see yeah it's pretty easy to use this even the the co-pilot can do it so we're just going to disable it for a while um okay so where do we start so essentially what we need to do we need to first get our address it's pretty standard so um flare and sepolia they're both TVM compatible chains that means the all the existing tooling that exists can be reused so we don't need to explore some new language you don't need to get acquainted to a new tooling you just download hard hat you just use the
existing uh web3 Library suggests to use existing eaters libraries and there you are so no no specific things so what you need to do well firstly you need to you need to get layer cake let's see where this config resides um so we get layer cake and we need to get a token to approve it and to request the token to be sent on stock just to make sure this is correct
okay let's and cast them to okay so we got our token now we only need to approve it need to approve it to the layer cake address and for some amount let's say for I don't know 30 for 30 rep seats or maybe for three and now now the hard
part comes on so how do we instruct the layer cake to do this well we could manually create all destruct but we already provide you with the library that essentially abstract all this away and you only need to provide some some initial values so let's see where this is it's in the helpers so we we have a function called prepare simple transfer when you only provide it with all the required data so how much you're sending what's the fee who you're sending to who you are and who you're sending to and maybe data if you want to execute something on the other chain but that's it so all the other stuff gets calculated automatically so you don't have to work out how to how to make this happen let's go back
so we just need to get the operations okay let's put this so we need to get we need to get an amount let's say we're gonna send one if you're going to send a minimal fee saying there would be me and I'll also be sending to me because that's that's the easiest way and just convert this to big numbers so that it does not complain and that's it so we have this full
operations already prepared and what we now need to do is just need to instruct the layer cake and from there everything is automatic just .tx and see what happens it's taking a while to to do this over that Network okay so we got our transaction and
that's it so if we again check this transaction in Explorer we can see that in that case we've transported one rat ethereum we paid some fee and we went back onto the um to our address on the on another chain uh it's going to that one if you check our address on another chain and wait for a while for the for the sepolia to Mint is to mean this we would see that we would get this newly minted red ethereum to our desk directly there okay that's that's mostly [Music] foreign [Applause]
code if you want to get some test tokens to play around with layer cake we'll be running this uh probably over the weekend so if you want to play around with it just hop on get some tokens and play around okay any questions hey great talk uh you mentioned that the fees are somehow abstracted away in this demo on the ethereum side uh presumably that's absorbed by the bandwidth providers and sensors can be somewhat Dynamic fees how does that sort of uh how do you communicate that to the user on say the flare side yeah okay so
uh the fees for the transfer are paid in the erc20 tokens you're transferring um and yeah so to do this properly you either need some sort of a pricing Oracle to see what the correct fee on the other side would be but um you can easily change the fees if you see that the transaction is being stacked so essentially the transfer um the transaction signing protocol and the bridging protocol functions on the fee side and on the payment side pretty much like uh like a normal transaction on blockchain so if you see that your transaction is stuck in the loop and nobody's nobody is willing to pay that much to execute something that's really expensive on the other side because you provide I don't know a huge amount of call data you can just tap the fee and hope that it will get processed quickly
but yeah you can you can do this pretty cheaply so um so I I get how the kind of liquidity is deposited on the other side and then how you send a transaction basically with call data but no amount to kind of retrieve it back um but so what's the role of the nft like is that uh kind of like a uni swap position in Ft or is that a nft in this kind of Custom Contract now here uh we use uni swap V2 because it much it was
much simpler for demo so we don't have to deal with the liquidity on a specific band the idea of the nft is just to essentially allow the contract on the receiving end to get multiple deposits at the same time and use the nft to um specifically set the the owner of this specific deposit to a single address so and then you would be able to trade this nft and just effectively trade the the claim on this part of liquidity so that you don't deal with the tokens as ESC tokens but with the full amount okay so the the contract on the destination chain is essentially like an aggregator where multiple users can deposit it's not just like one yes exactly okay okay amazing thanks thank you
[Applause] [Music] [Applause] [Music]