Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Last active February 21, 2018 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmcli/ec1f3f5841308c8761eac3ce8ce0a958 to your computer and use it in GitHub Desktop.
Save adrianmcli/ec1f3f5841308c8761eac3ce8ce0a958 to your computer and use it in GitHub Desktop.
Concrete use-case examples for b0x.network.

Examples

Please note that WETH and ETH will be used interchangeably in the following discussion.

The b0x network allows anyone with ERC20 tokens to loan it out for interest on a margin trading platform.

Example 1: Alice holds a lot of ETH tokens and instead of letting it sit, she wants to lend it to traders who are looking to borrow money so that they can trade on margin. Alice creates a b0x order specifying the type of token she is lending out (i.e. loanToken) and the type of token that she wants the interest to be paid in (i.e. interestToken).

The lender can specify the specific margin amounts that the borrower must have in order to fill the order and maintain the loan.

Example 2: Alice wants to make sure that whoever ends up borrowing her tokens must put as collateral, 50% the value of the loanToken borrowed. This 50% is called the initialMarginAmount. Alice also wants to make sure to liquidate the loan if the value of the collateral drops below 25% of the borrowed amount. This 25% is called the maintenanceMarginAmount.

The borrower must fulfill certain margin amount requirements in order to fill the loan and keep the loan from being liquidated.

Example 3: If Bob wants to borrow 10 ETH from Alice (at the 50% and 25% initial and maintenance margin amounts specified above), then Bob needs to stake at least 5 ETH worth of ERC20 tokens as collateral. If the value of the collateral suddenly falls 51% (i.e. the collateral is now worth a bit less than half what it was), then the loan is now in danger of liquidation because the margin ratio is now below 25%, the maintenance amount.

When a borrower is filling a lend order, they can choose the type of collateral token and the amount to fill.

Example 4: In the above examples, Alice wants to loan ETH tokens, but Bob only has ZRX tokens. When Bob goes to fill Alice's margin lending order, he is allowed to pick what type of ERC20 token he wants to use as collateral (like ZRX) as well as how much of the order he wants to fill (i.e. how much he wants to actually borrow). The amount of collateral that will actually be locked up in the loan will then depend on the initialMarginAmount and the price of the chosen ERC20 collateral token (in this case, ZRX).

After a borrower borrows tokens from the b0x network, they can choose to change their asset exposure via a 0x trade.

Example 5: Bob borrows ETH from Alice, but he actually wants to use the borrowed funds to invest in MKR instead (Bob is speculating that MKR will go up in price in the near future). In order to do this, Bob goes to a relay or decentralized exchange and finds a 0x order where somebody is selling MKR for ETH. Bob then gets this JSON order object and heads to the b0x portal. On the portal, Bob navigates to the "Borrowing" page and finds his recently opened loan with Alice. Bob then pastes in the 0x JSON order object and the b0x network will become the taker of that 0x trade (and fill it) on Bob's behalf. When this trade is complete, MKR is now held in the b0x contract as opposed to the originally loaned ETH. Bob is now exposed to MKR instead of ETH.

@tomcbean
Copy link

All your examples are valid use cases, except for example 5. The issue is that MKR token has to come from somewhere. There has to be a 3rd party that can sell their MKR. A 3rd party would have created an order to exchange MKR (sell) for ETH/WETH (buy) and this order would live on a relay or DEX waiting for a taker. In our case, the taker would be b0x. The trader would need to send this pre-existing order to b0x for taking, which would mean b0x is selling ETH to buy MKR using the located 0x order. Generally this process of the trader finding the 0x order selling MKR and sending it to b0x would be abstracted way by the relay integrated with b0x.js. Once the trader has opened the loan order in b0x, the relay would simply allow the trader to buy tokens using the loaned funds (ETH). In reality, it is b0x that is buying MKR on behalf of the trader.

@tomcbean
Copy link

It could be the the trader has MKR in their wallet already and creates a 0x order as you suggest. Then sends it to be b0x to be taken on their behalf, exchanging the loaned ETH for MKR. Seems like a weird use of b0x, but there maybe a valid use-case for this. I need to think on it more after some sleep.

@adrianmcli
Copy link
Author

@tomcbean Thanks, I've updated Example 5 to reflect your comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment