Tom Bean ~ DeFi Development: Buidl with bZx
Ethereum Denver·Wed, Oct 9, 2019, 12:00 AM
Transcript
What's up everybody? Thanks for coming over to the build middle stage. This kicks off our two sessions segment on decentralized finance which um in my humble opinion is one of the coolest things to really sort of come to fruition or at least get traction over the past year or so. We're kind of what you've seen this Cambrian explosion of innovative things happening. I think Maker and I kind of kicked things off but now you have new ways of of lending with compound.
You have different ways of creating derivatives on the blockchain. There's a lot of regulatory insanity there but despite that projects keep moving forward and in building. So it's a I think it's a under the radar for a lot of people but not you guys cuz you're about to learn more. So that said I'm happy to introduce Tom and he's going to tell you about decentralized margin trading. All right, thank you.
So I'm Tom Bean. I'm co-founder and CEO of BZX and I don't know if any of you were at the Melonport conference or saw my saw the live stream that was a week ago. So that if you did the this presentation will be somewhat of a rehash but we are going to touch on some more things. So BZX we're we're a like to call it a radically permissionless margin lending protocol where a network of smart contracts on the Ethereum blockchain. We've been live on main net since you know a little bit past middle of last year and we facilitate trustless and decentralized margin loans and those who don't know a margin loan is a a loan that's backed up by assets you might have in your wallet.
Like you put up collateral and you borrow some other asset and you can you can short it or um you can uh you know, pull it out to your wallet if you're doing a over collateralized loan. So, I'll touch on some more of those things in a bit. Um So, let's jump right in. So, yeah. So, we we facilitate peer-to-peer margin loans.
Uh it's fully trustless. There's no um accounts to set up or KYC. You do it directly from your wallet. Um We also, you know, facilitate shorting, which you kind of need need margin for. And um we have very fast uh on-chain liquidations.
And we also are full solution for DEXes. So, uh many of you are familiar with 0x. We're kind of we're we're similar to 0x, but we're for for leverage trades and shorting. So, we have a a toolkit for integrating with uh 0x relay and or you could create a standalone BZX like BZX relay where you have funding and borrowing um uh um order books. So, and like I said um we support very fast margin calls.
So, you know, lent protecting lender funds is very important. So, uh some of the other solutions out there might have like a use a Dutch auction or some other method. Our our liquidations happen very fast on chain. Uh we have a network of bounty hunters and we call them margin callers that are monitoring positions and uh if a position goes underwater, it gets liquidated in one atomic transaction. So, they're very fast.
And uh kind of like 0x, we support uh off-chain signaling, on-chain settlement, or we have fully on-chain order books. And we're also integrated with on-chain liquidity providers like Kyber, Bancor, Oasis DEX and others. And that And the reason for that is for um real-time price discovery on chain and for you know, liquidation liquidity and also trade bars can manage their positions. Uh they can change their exposure to the market by doing a using our on-chain providers or providing a 0x order. So So, two types of loans.
Uh overcollateralized. Those of you are familiar with Compound or some of the other solutions, you you put up more collateral than you're borrowing. So, you might want to uh you might put up 150% and borrow 100%. Like you put up 150% in value of an asset and borrow 100% and then you can pull it out to your wallet, send it to an exchange, pay your bills, whatever you want to do with it. But the more interesting use case that we facilitate is undercollateralized loans.
So, you could borrow like 4 or 5x ETH. Like you put up uh put up $25 worth and borrow $100 worth of ETH or something like that. And then um that lets you trade with you know, that that lets you take out leveraged trades. So, you know, it it amplifies your your losses and your gains. And when for undercollateralized loans, we escrow the funds cuz we don't really have a uh a way to uh you know, we don't have a way to enforce payment or repayment because it is trustless.
So, overcollateralized, it it doesn't matter. We have more than We have more than 100% value of the loan. So, if they don't pay back, then we just keep their collateral and uh make the lender whole. If undercollateralized though, we have to escrow the funds. So, in if you put up uh less than the value of your loan and you uh it goes into our smart contracts and then we provide all the functions you need to manage your exposure, change your collateral, uh you know, take profits if you're a lender, interest accrues, so you can pull out your interest, stuff like that.
And we we support a uh uh I mean, we're We support all ERC-20s. Technically, we're we're agnostic to that, but we're we're kind of restricted to our on-chain providers. Kyber provides has supports many ERC-20s, all the popular ones. So, uh Kyber was the first liquidity provider we integrated. So, anything that's on Kyber, on Kyber Swap, we also support for margin lending and trading.
So, yeah, radically permissionless basically means that it I mean, it's an open protocol, so we don't you can anyone can open loans without accounts or KYC. Anyone can initiate margin calls and liquidate positions. So, what how that works is, like I mentioned, people are monitoring positions and liquidating. That That's also a decentralized network of people. So, if someone sees a position has is bankrupt and needs to be liquidated, they call into our contract to liquidate.
And uh we have to verify that on chain. So, we we go and check the prices on Kyber or one of our other providers. And if it actually is underwater, we we liquidate immediately and then refund, you know, the lender gets back the full amount plus interest that they've of the principal. And um also, you know, a couple other ways it's permissionless is uh liquidity for margin calls. You can kind of supply your own liquidity uh you can run a Kyber reserve or you can supply a Kyber reserve to uh kind of front-run margin call like liquidity for margin calls if you're a liquidity provider.
And um also, it's very easy to build on us. There's uh it we have a um as I'll touch on, we have an oracle layer that you can actually you can extend the protocol in, you know, interesting new ways. Uh if you didn't um if you wanted to create a um like a Dutch auction-type liquidation system on us, you could. So, uh and I'll we'll talk about some of our uh buildable ideas and uh uh you know, suggestions for people that want to build on us, and we are offering some bounties at this hackathon. So, So, touch on that in a bit.
So, I kind of touched on uh you know the the players in the ecosystem are borrowers and and lenders and also builders, integrators, and and others that um you know, want to use the protocol in different ways. So, briefly on the life cycle of the loan uh the order can be the loan order is set up by a lender or a borrower. You they go and they they define all the parameters like what they want to lend out, the length of the loan, the initial initial margin level which is the level of collateral that's required to actually enter the loan. So, it could be at like 20 25%. That means that you're basically a 4x loan.
You put up $25, you get $100, something like that. And then the um margin or the maintenance level is the level that it gets liquidated. So, it might be like a like a 2x loan might be 50% initial, 25% for maintenance. And if if the position is open and it falls to that level, like say you say you borrow ETH and you swap it for DAI. Basically effectively taking a short position on ETH.
So, you're you're hoping that it's going to ETH is going to drop in price or or DAI is going to go up in price relative to ETH. So, um if it goes the other way though and the and the the margin falls to that maintenance level, that's when it should get liquidated very fast. So, you know, that minimizes losses for the for the borrower and uh you know, ensures the lender gets back the full amount that they they um they loaned out. So, once the order is created, uh similar to 0x, it gets hashed and signed by the the makers uh with their with their private key and then it can get distributed through any arbitrary means. Like it can go on a off-chain relay or um you know, or or DEX or it can just be you know, it can be sent anywhere over the internet.
It's safe. And then once it's filled, is the opening phase is when it's filled. So, a borrower finds a loan on a a DEX that they like, and they like all the terms. So, then they fill it, it gets sent to our smart contracts. We We verify that nothing is that I mean, it's immutable once it's made.
So, if any any of the parameters have gotten altered by anyone, it invalidates the order. So, once the order is validated, the the funds from the lender and the borrower from the lender, it's obviously the the principal, it's what they're lending. The borrower, it's collateral and interest for the over the full life of the loan get escrowed in our smart contracts. If it's an over-collateralized loan, the it gets withdrawn to the borrower's wallet the loan funds. And then once that happens, it's, you know, moves into maintenance phase.
And as I've kind of mentioned, the full function of uh position management is available to the borrower, and they can you know, they could swap in and out of assets very easily. They want to change their exposure or or close out their exposure. Say you borrow ETH and you short it, but you want to close that out temporarily, you can swap back into ETH without closing the loan. And then, you know, closure, the borrower can close the loan early or lender or you know, the position goes underwater, it gets liquidated. So, we're going to talk about a new product, couple new products we have coming out that we're really excited about is uh First is iTokens.
So, this is a protocol extension. It's It's basically a tokenized version of of a loan. So, a lender you So, for all all the all the supported tokens, we're going to have these iToken contracts. So, there's ETH, you know, iETH. So, with what you would do with iETH, you would send your ETH into the iETH contract.
It becomes a global lending pool. Anyone can borrow against that for you know, normal loans or under-collateralized loans for margin trading. You could take it like a a forex loan against that as a borrower and um lenders have it are are earning interest. So, the value of that is always climbing up. You you're all you'll always get at least the value uh the asset that you put in.
So, you you know you deposit 10 ETH, you're going to get back more than 10 ETH when you actually pull it out because it's uh it's always accruing interest. So, this opens up like a like a really like a wide variety of use cases in DeFi. So, it's any of you're familiar with Maker DAO CDPs, like they're going to have a multi-collateral DAI product coming out. So, when they do, you could potentially have uh collateralize it with iETH. So, rather than ETH.
I mean, it's it's it's the same as ETH, but you know, it's going to be going it's always going to be accruing interest and you know, the interest rates on CDPs are so low. So, you could offset that with the interest you earn. So, it could be basically a a free CDP or CDP that's you actually make a profit on. So, you know, and these will be, you know, fully fully compliant ERC-20 tokens, so they can be traded and and um you know, freely traded. So, oh, and another interesting thing is the price is always the price is determined algorithmic algorithmically based on um supply the supply and demand plus the accrued interest.
So, they can always be queried in real time against the contract see exactly uh how much uh of an iToken you'll get back from your deposit. So, um we're pretty excited about this and it should be out the next uh couple months probably. So, that uh we're Yeah. So, okay. So, I Yeah, I kind of mentioned some of these things.
It's uh you know, it earns you passive interest forever. So, if there's if we're integrated with say a wallet that you could check a uh you know, tick a check box and uh your your ETH that you're just holding in your wallet could be earning you interest. It it'll would get behind the scenes get deposited into iETH and uh uh you have uh you know you're profiting on the um the time value of your assets. And uh it's a unified liquidity pool. There's just one contract like for for ETH there's one global lending pool rather and you don't have to uh loans that are taken out from them uh anyone can continuously borrow against them and loans roll over so there's no uh need to deploy new contracts.
Uh it's just one one iETH and um we actually you know on ENS we're going to have iETH token dot um dot ETH and you could just send your ETH into that and get iTokens back. And uh real simple to enter entry and exit. You can uh you can burn the tokens to get the the funds back or you can sell them on exchange and to get tokens you just deposit your ETH and or you buy them on an exchange. So the other thing we're going to release is pTokens and um some of you may be familiar with DYDX's margin tokens. So this is similar but our tokens uh again don't have to be re-minted each month.
It's just uh loans last 28 days and roll over. So it's it's uh kind of an improvement on the UX in where you don't always have like loans that are are tokens that are expiring. You just have one like 4x short ETH token and um that's the only token you that's the only contract you have to deal with. And again price is updated queryable on the contract itself. And uh we'll have we'll have pTokens out for uh varying degrees of of leverage and varying assets.
So you know like a 4x short ETH token a 3x ETH short short ETH token uh you know 4x long token stuff like that. Um so we'll we'll cover all the um all the popular um you know types of loans people want to take. So there's a lot of use cases for our protocol. Asset managers can, you know, monetize and hedge their hedge their positions. Uh you know, some of those products that we're you know, we we're talking to are you know, Melonport, Regal Block, you know, BZRX, CoTrader and others.
Uh exchange it we're we're very well suited for integrating with exchanges cuz we have a you know, a front end BZRX.js library that makes it really easy to add for DEXes to add our our order books and full margin trading decentralized margin trading functionality. So, those are some of the platforms. Uh you know, and and then lending products like Maker, you know, MakerDAO CDPs, ETHlend, Dharma and others. And I And like I mentioned wallet integrations are really interesting, too.
Just Just by holding your Just your idle assets can be earning you interest through our protocol. So, uh I'll touch on a bit on getting started. Uh I I mentioned that we're you know, a a complex network of smart contracts that handle all the margin trading and lending functionality. And we also have a it And well, there's there's a couple layers of that. The base layer is all the the core logic of the protocol.
And then the oracle contracts are the are contracts that are you know, where you can extend the protocol and also all our third-party integrations are handled with oracles like Kyber and and um OasisDEX. Uh and you know, they're basically you can plug in new functionality and new ways of of um of liquidating assets, stuff like that. Uh and then we have a uh asynchronous JavaScript library. Um it's it's promise based BZRX.js.
It makes it really easy for uh DEXes and other front end builders to build on our protocol. They don't really have to deal with our smart contracts directly. Uh of course, they can, but um that's what that's for. So, really easy to get started. You know, you can install it um with node package manager and you can just initialize.
You pass in the uh web3 object and uh you're good to go. And then we have docs that show you all the different functions that are available through the um JavaScript library. Some of the key functions uh this is not a uh not exhaustive list that uh are up there. Basically anything I I the full margin trading functions for uh you know, creating orders, filling orders, managing your your exposure to the market, uh collateral, profit taking, loan closure, etc. And uh here's some helpful resources um that uh you know, anyone's going to that wants to build on us will definitely definitely should check out our docs.
And uh our all our code is open source, so you can check out our mono repo and uh there's lots of code in different packages in there you can check out. Some of them are you know, contracts are all the smart contracts, BZX.js. We have a portal dapp that um demonstrates all the functionality of the protocol. That's not typically where people would be using us.
They'd be using us on like a on a third-party builder like a a DEX uh or exchange, but they can go to our our portal, open loans, uh manage their assets, all everything that you can do through the protocol. And then we have a starter project that is really good if uh if you intend to build on us. There's sample code on there and different interactions with the protocol um that could be useful to you. And then we also for relays, uh similar to 0x, we have a BZX standard relayer API. So, if you're actually building a relay, it'd be really good to integrate using our standard relayer API so that you can kind of share liquidity with other relays and uh it'll make it makes it really easy for people to pass in to create loans and then pass in those loan orders to your relay.
So, uh Kyle, you want to come up and uh other co-founder Kyle, he's going to tell about some of our the buildle bittle odd ideas for this hackathon. Yeah, so uh we created a wish list of different ideas uh in case uh you wanted to build on top of the protocol. It's uh It's up right now in more detail on uh the Cowrie post. Uh you know, we uh we have some bounties. Um so, you can create your own uh generic bZx relay.
So, if you want to create your own uh 0x relay and add on bZx to that to add uh basically um decentralized long and short, that's one way to go about it. You can also uh create your own bZx relay that uses Kyber Swap as uh your liquidity provider. So, um the bZx relay lets you get into loans and then you use Kyber Swap to let people manage uh their positions. Uh dark pool relays, so there aren't a lot of those right now, but you could essentially um use a matching order book um and then just uh give just-in-time quotes. Um you could uh use uh like a protocol like Republic in order to um allow um dark pools.
Uh so, you combine Republic with uh our own protocol to have uh dark pools for shorting. Um you could create a ShapeShift-like relay, one that's uh has the front end hosted on IPFS that uh kind of has another level of decentralization. Um a mobile relay, um a a front end for our iTokens that's available right now if you go on our Kovan testnet and our portal, you can play around with those right now and see how those work. You could create like a a nicer front end for that if you wanted um that sort of relay. Um Let's see.
So, um you know, different different liquidity providers that could be integrated and allow to allow borrowers to manage their positions are your aggregators like totally and fetch protocols like AirSwap. Uh you could create uh a Hydro like protocol for bZx. So, like Hydro right now is um for 0x or they were before they forked it. Um basically an incentive structure uh middle middleware layer that allows exchanges to coordinate and compensate each other for the liquidity that they're sharing with each other in order to fix incentives um that bigger relays might have with sharing uh liquidity with smaller relays. Um you could create a Paradigm market wrapper contract for bZx.
So, we're really excited about Paradigm and uh the um relayer protocol that they're coming out with. Um this uh provides possibly another layer of decentralization. Um it could be an trading interface for um market makers um that makes it easy for them to interact with the APIs. You could um create a number of different uh liquidation layers um on the second layer. So, some examples of that are the DutchX um that Gnosis has.
So, you could uh use the DutchX contract to basically um wind down margin positions using Dutch auctions. You could use Chainlink to uh query prices and uh draw in liquidity from uh third parties. You could uh use Chainlink to uh just draw in a centralized price feed and then enforce uh or and bring in liquidity using a similar system as like Compound or Dharma Lever, where people just bid on assets and get a 5% discount on them based on the price that the centralized price feed is showing. Um you could use Aztec protocol. One of one of the really exciting use cases we talked to Aztec about are um zero zero knowledge margin liquidation proofs.
So, basically um you you create the zero knowledge order and you pass it off to Kyber, and you feed it into the order object. And what this does is when margin callers query an account, they don't know what level you get liquidated at. There's just a proof that allows the oracle to come back and give a boolean yes or no, is this ready to be liquidated? Um response. So, this way you can you can kind of combine this with dark pools, right?
So, dark pools, they let you put an order on an order book and not and not have the size of the order and the asset and all this be revealed. But, once you're actually enter into a position, you might want people to not know what the size of your position is, where your liquidation level is, so that somebody doesn't come and stop hunt you, so that you're not communicating um information to the market at large when you put your order down or you enter your position. You know, recently somebody was using Compound, and they loaned out a huge amount of REP and borrowed a huge amount of DAI, and they made those those rates take a huge spikes and drops, and they used that DAI that DAI to collateralize the CDP that they had. But, you know, this was all exposed uh to the entire ecosystem. So, the people on Twitter were like, "Hey, look at where this guy who owns CDP number 335, look at what he's doing.
Look at where these funds are coming from. He did this on Compound. He borrowed that. He And then that money flowed there." Using, you know, zero knowledge uh proofs for uh your margin positions using dark relays, nobody has to know exactly what you're doing so that uh open finance can have a little bit of privacy.
Automatic transcript — names and jargon may be misspelled.