bitshares / bitshares/bsips

BSIP78: Asset Feature - MLP2 (Market Liquidity Pool)

Open
#213 17 comments 4 reactions 0 assignees View on GitHub
chain utility profitability / fees
Dominant language
No language data
Stars
59
Forks
86
PR merge metrics
No merged PRs in 30d

Description

```
BSIP: 078
Title: Asset Feature - MLP2 (Market Liquidity Pool Version 2)
Author: [bench]
Status: Draft
Type: Protocol
Created: 2020-06-11
```

# Abstract
- MLP2 is an asset lending feature, to provide liquidity for asset exchanges, at the current price level
- Simplified version of the [Bancor Protocol](https://storage.googleapis.com/website-bancor/2018/04/01ba8253-bancor_protocol_whitepaper_en.pdf) without connector weight
- Stepless liquidity with no order book for any asset pair
- Blockchain as borrower and liquidity provider
- BTS as central node and base currency
- Market fees are shared to asset lender and blockchain

# Motivation
- User has no easy way to provide liquidity to markets
- Most order books have low liquidity and high market spread
- Order books are dependent on certain price levels

# Rationale
- Provide an easy, effective and robust liquidity feature for every user, asset and asset pair on the protocol level
- Generate demand for BTS and income for BitShares Blockchain
- The market fee provides the buy/sell spread to generates a profit on every asset swap
- One asset deposit removes the counterpart risk of the other market pair

# Solution
- Every `asset` pair can have the `MLP2` asset feature
- The `MLP2` asset feature is based on the [x * y = k modell](https://github.com/bitshares/bsips/issues/213)
- `x` = `amount_asset_X`, `y` = `amount_asset_Y`, `k` = `invariant`
- `MLP2` is separated in passive and active liquidity, to allow one asset deposit/withdraw

## Exchange
- The ratio of `amount_asset_X`/ `amount_asset_Y` or `price_asset` defines the asset exchange rate
- The `invariant` is not changed during the asset exchange
- `amount_asset_X` * sqrt(`price_X`) = `amount_asset_Y` * sqrt(`price_Y`)

## Passive liquidity
- Passive liquidity gets created, when there is an unequal amount of assets, because only one asset was removed/added from/to the `MLP2`.
- Passive liquidity needs an equal amount of the corresponding asset, to become active liquidity.
- Passive liquidity, which was created by removing assets from `MLP2`, are prioritized for active liquidity over newly added assets.
- The reduction of passive liquidity is defined by the smaller order of both assets.

## Add/remove asset(s) from MLP2
### Add an equivalent amount of both assets
- No passive liquidity
- No waiting time
- Highest market fee share

![add2-assets](https://user-images.githubusercontent.com/40874087/84789049-1ce4f400-aff0-11ea-9508-e38fc3879509.png)

### Remove an equivalent amount of both assets
- Passive liquidity is not changed

![remove2-assets](https://user-images.githubusercontent.com/40874087/84789118-30905a80-aff0-11ea-8d2a-f8f2e930962f.png)

### Add only one asset
- Instantly, when it is the inverse asset of the passive liquidity
- Waiting time, when it is the asset of the passive liquidity
- Lower market fee share

![add1-assets](https://user-images.githubusercontent.com/40874087/84789165-3ede7680-aff0-11ea-9466-6aadf6d937a6.png)

### Remove only one asset
- No waiting time
- Active liquidity gets reduced
- Passive liquidity can get increased or decreased

![remove1-asset](https://user-images.githubusercontent.com/40874087/84789200-4a31a200-aff0-11ea-9beb-c0d581d12da0.png)

## MLP2 start values
![MLP2-price1](https://user-images.githubusercontent.com/40874087/84722107-947c3a00-af82-11ea-8ac4-9220451a0273.png)

## MLP2 after quadruple BTS price or asset sell for half amount_BTS
![MLP2-price2](https://user-images.githubusercontent.com/40874087/84719855-bb377200-af7c-11ea-9df1-862ec5b486a7.png)

## MLP2 Charts
- `amount_BTS` * `amount_asset` = `invariant`
- sqrt(`price_BTS`) * `amount_BTS` = constant
- sqrt(`price_asset`) * `amount_asset` = constant
- `price_BTS` * `price_asset` = 1

![MLP-price-chart](https://user-images.githubusercontent.com/40874087/84720118-7c55ec00-af7d-11ea-8588-b219543eb246.png)

## Fee structure
The asset owner, defines the fee structure for the `MLP2`
The `market fee share to network` is defined by the network.

### BTS market pairs
- Only paid in BTS
- Only for BTS -> `asset` trading
- Added partial after the exchange to the `MLP2`
- Shared to both assets lenders

### Other market pairs
- Paid in both assets
- Paid in both directions
- Added both partial after the exchange to the `MLP2`
- Shared to both asset lenders
- Network cut gets settled by the corresponding BTS market pair

### Example fee schedule
0.6% BTS -> asset market fee
- 75% for the MLP2 asset holder (= 0.45%)
- 5% for referral system (= 0.03%)
- 5% for the reserve pool (= 0.03%)
- 15% for the asset owner (= 0.09%)

0.3% asset -> asset market fee
- 75% for the MLP2 asset holder (= 0.225%)
- 5% for referral system (= 0.015%)
- 5% for the reserve pool (= 0.015%)
- 15% for the asset owner (= 0.045%)

### Price Distribution
![MLP2-price-gau](https://user-images.githubusercontent.com/40874087/84720474-698fe700-af7e-11ea-9773-a3af405be246.png)

## Network Example with different MLP asset features
![MLP2-network](https://user-images.githubusercontent.com/40874087/84720581-b673bd80-af7e-11ea-9a4b-628d51398f66.png)

# Market Dynamics
- Every asset exchange uses the full inventory of the `MLP2` asset feature
- Every `asset` is backed by same value of the other `asset`
- When BTS price decreases, demand for BTS is increased

## MLP2 price changes
**ROS** = (Relative Order Size) = amount_order/active_mlp
**Premium** on the exchange rate compared to the current `price_asset`

ROS | Premium | delta_price_asset
------------ | ------------- | -------------
0.1% | 0.1% | 0.2%
1% | 1% | 2%
5% | 5% | 11%
10% | 11% | 23%
20% | 25% | 56%
50% | 100% | 400%

## Orderbook
- Supported with extra liquidity
- Reduced market spread
- Any trading pair can have liquidity with BTS as central node
- Asymmetric `market fee` reduces `asset`/`asset` market spread

## Price feed
The `MLP2` asset feature is not only exchange feature, but also a price feed indicator, which oscillates around the market price.

### Manipulation
- Shorting BTS on `MLP2` generates `market fee` and market spread
- Shorting BTS generates extra demand for BTS
- Arbitrage pays no `market fee` and gets an advantage to increase BTS price on DEX

# Comparison
## Lending options
Case | [MPLP](https://github.com/BitShares/bsips/issues/182) | `MLP2` | [BSIP-70](https://github.com/BitShares/bsips/issues/170)
------------ | ------------- | ------------- | -------------
Motivation | interest rate | market fee | interest rate
Borrower | peer | blockchain | peer
Input | debt asset | any asset or asset pair | any asset
Purpose | increase `CR` & `debt` | increase liquidity | lending/trading
Collateral | no | no | yes
Order book | no | no | yes

## Implementation
Case | `MLP2` | Uniswap2
------------ | ------------- | -------------
Market fee | a-/symmetric | symmetric
Assets | BTS assets | ERC-20
Non-core markets | yes | yes
One asset support | yes | no
Fee share | yes | no

# Specifications
## Network_parameter
- `fee_share_for_reserve`

## MLP_parameters
- `asset_id`
- `mlp_fee_rate`
- `fee_share_asset`
- `fee_share_mlp`
- `fee_share_referral`

## MLP_object
- `asset_id`
- `delta_asset_balance`
- `user_id`
- `mlp_function_id`

## MLP_asset_functions
`x` = `active_amount_asset_X`
`y` = `active_amount_asset_Y`

`x_p` = `passive_amount_asset_X`
`y_p` = `passive_amount_asset_Y`

### Add both assets
if (`y`/`x` == `delta_asset_X` / `delta_asset_Y`) {
`x` += `delta_asset_X`
`y` += `delta_asset_Y`
}

### Add one asset
if (`delta_asset` == `passive_asset`) {
mlp_passive += `delta_asset`
}

if (`delta_asset_1` != `passive_asset`) {
mlp_passive -= `delta_asset_2`
mlp_active += `delta_asset_1`
}

### Remove both assets
`x` -= `delta_asset_X` + `market_fee_share_X`
`y` -= `delta_asset_Y` + `market_fee_share_Y`

`market_fee_share` = ∫(`market_fees` * `mlp_share`)dn

### Remove one asset
if (`delta_asset_1` == `passive_asset`) {
`mlp_active` -= (`delta_asset_1` + `market_fee_share_1`)
`mlp_passive` += `delta_asset_2`
}

if (`delta_asset_1` != `passive_asset`) {
`mlp_active` -= (`delta_asset_1` + `market_fee_share_1`)
`mlp_passive` -= `delta_asset_2`
}

`market_fee_share` = ∫(`mlp_fee_rate` * `fee_share_mlp` * `mlp_active/(mlp_active + mlp_passive)`)dn

### Exchange BTS to asset
`mlp_fee` = `amount_BTS` * `fee_rate_mlp` * `fee_share_mlp` // calculate fee cut for MLP2
`x` += `mlp_fee` // add fee to MLP2
`k` = `x` * `y` // calculate invariant
`x` += `amount_BTS` * (1 - `fee_rate_mlp`) // amount to exchange
`amount_asset` = `y` - `k` / `x` // amount to return

### Exchange asset to BTS
`k` = `x` * `y` // calculate invariant
`y` += `amount_asset` // amount to exchange
`amount_BTS` = `x` - `k` / `y` // amount to return

### Exchange asset_1 to asset_2
`mlp_fee` = `amount_asset_1` * `fee_rate_mlp` * `fee_share_mlp` // calculate fee cut for MLP2
`x` += `mlp_fee` // add fee to MLP2
`k` = `x` * `y` // calculate invariant
`x` += `amount_asset_1` * (1 - `fee_rate_mlp`) // amount to exchange
`amount_asset_2` = `y` - `k` / `x` // amount to return

## Flow Chart
![MLP2-flow](https://user-images.githubusercontent.com/40874087/84789992-202caf80-aff1-11ea-9557-5295e184d1c8.png)

# Discussion and Summary for Shareholders
- This is a very important feature, to strengthen our infrastructure, use case and core token value
- This enables every user to take part in value creation and earning market fees at the same time

## Risks
- The MLP2 can be seen as a fully automated exchange, which earns profits by market fees on every trade. When the exchange runs completely on blockchain, the risks are not higher, than the blockchain by itself.
- The fixed connector weight ensures, there is no option to extract any value from the pool. When the pool price is different from market price, the arbitrage bots earn the difference minus corresponding fees.
- With one asset deposit function on MLP2, there is no extra risk involved in holding the other trading pair. Through different supply and demand, one asset could be part of passive liquidity, which earn less market fees, than the other one.

# Copyright
This document is placed in the public domain.

# See Also
- [Dynamic price feeds based on EMAs and smartcoin metrics](https://github.com/bitshares/baips/issues/7)
- #182 - Debt Asset Feature - MPLP (Margin Position Liquidity Pool)
- #164 - BSIP74: Margin Call Fee Ratio
- #194 - Share market fees to network
- [Bitshares Equilibrium](https://steemit.com/bitshares/@funkit/bitshares-equilibrium-smartcoins-on-steroids)
- [Autobridging a way to improve liquidity](https://bitsharestalk.org/index.php/topic,21781.msg283706.html)
- [How to use Committee Funds](https://bitsharestalk.org/index.php?topic=29616.0)
- [Price feed from DEX market](https://steemit.com/bitshares/@blocktrades/using-a-bitshares-decentralized-exchange-dex-market-for-bitusd-and-bitcny-pricefeeds)
- [Uniswap risk analyse](https://medium.com/nexus-mutual/understanding-risks-in-defi-1-uniswap-e5e790692635)

# Sources
- [Uniswap Whitepaper](https://hackmd.io/C-DvwDSfSxuh-Gd4WKE_ig)
- [x * y = k modell](https://github.com/runtimeverification/verified-smart-contracts/blob/uniswap/uniswap/x-y-k.pdf)
- [Uniswap — A Unique Exchange](https://medium.com/scalar-capital/uniswap-a-unique-exchange-f4ef44f807bf)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.