Let TAS = Total asset for sale above swan price.

Let TD = Total asset that has been borrowed



onOrderUpdate /// create, cancel, fill

try

push undo state

create, cancel, or fill orders on the book

update TAS

if( TAS < TD )

undo changes and throw

commit changes

catch

execute margin call on least collateralized loan

goto try

The challenge is to create a bond market where lenders can earn interest while being 100% protected against default by the borrowers. This means that at all times the blockchain must be able to cover all loans on the market.This is difficult because it is computationally expensive to calculate the cascade effect of multiple margin calls and this must be done after every market operation.Someone who wants to borrow an asset may do so as long as there exists enough orders on the book to cover their new position and all other open loan positions at the price of the least collateralized loan’s DEBT to COLLATERAL. The least collateralized loan establishes what we call the SWAN PRICE, short for black-swan.Every time a limit order is created, filled, or canceled the blockchain updates a running total of how much of a given asset is available for sale above the SWAN PRICE.Every time a loan position is updated and a new SWAN PRICE is established, the blockchain must also update how much of a given asset is available for sale above the SWAN PRICE.Someone looking to borrow an asset makes a request of the network that includes:1. how much they wish to borrow2. how much collateral they wish back it withThe borrowing request will be filled so long as they post sufficient collateral. The network will automatically bump lower collateralized positions if necessary.A margin call can happen for any of the following reasons:1. If canceling an open order would result in insufficient orders on the books to buy back the debt with the collateral, then a margin call is executed first, then the order is canceled (if it wasn’t used as part of the margin call).2. If filling an order would result in insufficient orders on the books to satisfy all debt at the SWAN PRICE, then the margin call is executed first.3. If someone is looking to borrow, offering more collateral than the SWAN PRICE, and there is insufficient orders above the SWAN price then the least collateralized position is called. This will update the SWAN price to the next best.The impact of these rules is the following:1. The least collateralized position is always at risk of margin call when there is more demand for loans than orders on the book.If there are more orders on the book than demand for loans, then collateral requirements can fall and the least collateralized position is safe from potential margin call2. The ability to move an order, rather than cancel and create a new order must be supported to prevent unnecessary margin calls.Borrowers will post sufficient collateral to ensure sufficient market depth that they are not at risk of being called.3. Increasing collateral lowers SWAN PRICE and increases the number of orders above SWAN and thus increases SUPPLY of asset to be borrowed.Interest Payments4. Everyone with an open order on the books above the SWAN PRICE is effectively lending money to those who wish to borrow. If there is heavy demand for borrowing then the market response should be to pay interest to the lenders.In this algorithm, the network charges a “fixed” interest rate on the variable collateral. In this way the interest charged to borrowers grows along with the collateral requirement. Every open order on the books above the SWAN PRICE receives their pro-rata share of the interest paid by borrowers.Lenders have the ability to “set their interest rate” and “collateral requirement” based upon the price at which they leave their order open on the book. If demand for loans grows enough to find the least collateralized loan (SWAN PRICE) to be above the order price, then the loan is executed and the lender starts earning interest. If the SWAN PRICE never reaches the order price then the loan is not accepted and no interest is paid.The impact of interest is to increase the number of orders on the book above the SWAN price which in turn serves to reduce collateral requirements.The “fixed” interest rate can be configured by the asset issuer. If collateral requirements start to get unreasonably high, then interest rates can increase.Feedback Wanted