BSIP38: Add target collateral ratio option to short positions


From Abstract of BSIP-38

When a short position is margin called, some of its collateral will be sold and some or all of its debt will be covered accordingly.

However, usually more collateral will be sold, in comparison to the minimum amount required to be sold to maintain the maintenance collateral ratio (MCR) requirement.

This BSIP proposes a protocol change to let shortes (borrowers) have control over selling how much collateral when being margin called.

This BSIP depends on BSIP 31 .

Unit Tests

The “database fixture” is a mock blockchain/database that imitates the internal database tracked by a node on the blockchain.

The modification permits the optional specification by accounts on the blockchain of a target collateral ratio on a short position (call order).

This header has been modified to publicize the optional use of a target collateral ratio for short position (call orders).

This functionality that is tested is used by client software (e.g. CLI, reference wallet, Android wallets) to describe an operation (an “intent”) that will create or update a short position for an account on the blockchain. This operation should be internally consistent with itself and with the validity rules established for this operation. These intents are checked prior to submitting to an RPC node.

The functionality that is tested is used by the blockchain logic when filling orders.

These tests are checking specific logic that occurs when investigating the status of existing short positions on the blockchain. The test investigates different short positions (call orders) given a particular feed price and a given match price (where matches are of a buy and sell order on the books). These different short positions have different collateral ratios some of which are not margin called, some of which need to be margin called yet have sufficient collateral, and some of which need to be margin called yet do not have sufficient collateral (i.e. black swan).

Both tests are checking the matching of orders on the books.

The first test is checking the matching of a taker limit order with multiple maker call orders.

The second test is checking the matching of a maker limit order with multiple taker call orders.

Contributor: @taconater