Skip to content

A simple constant product market making method #118

@0xSSoul

Description

@0xSSoul

Although the collateral of this Market Protocol contract is imBTC, the market maker’s funds are all USDT.

Define some symbols as follows:

PRICE: The price of the contract denominated in USD
LONG TOKEN PRICE : The price of the long position token in USD. It should also be equal to the USD value of the IMBTC got by the long position token holder when the contract is settled. Besides, because the Market Protocol contract's price floor is set to 0, PRICE = LONG TOKEN PRICE

The market maker's goal is to place bid/ask orders around some market PRICE.

First, we calculate the INIT PRICE using some model, for example, a model based on FTX hash rate contract. How to calculate the INIT PRICE is beyond this issue.

Second, we calculate the initial X (long position reserve) and Y (collateral token reserve) in the constant product formula.

Let INIT FUND be the initial funds of the market marker, eg $20k-50k.

X = INIT FUND / ( 2 * INIT PRICE)
Y = INIT FUND / 2

Third, we apply the constant product formula: X Y= k, to get the bid/ask order price.

  1. Let Δx be the ask order size, then (X-Δx)(Y+Δy)=X Y,
    ASK PRICE = Δy/Δx = Y/(x-Δx)
    Thus the market maker should put an ask order in the order book with order size is Δx and the order price is ASK PRICE

  2. Let Δx be the bid order size, then (X+Δx)(Y-Δy)=X Y,
    BID PRICE = Δy/Δx = Y/(x+Δx)
    Thus the market maker should put a bid order in the order book with order size is Δx and order price is BID PRICE

Third, update the X and Y:

  1. When the ask order gets filled, update X' = X - Δx,Y'=Y+Δy
  2. When the bid order gets filled, update X' = X +Δx,Y'=Y-Δy

Whenever the market maker has both long position tokens and short position tokens, he should redeem the tokens by Market Protocol.

Hedge

When the market maker is the seller, the buyer pays USDT to the market maker and the market maker uses IMBTC to mint Long and Short token. Thus, the market maker needs to convert some USDT to imBTC before minting and the imBTC locked in the Market Protocol is a risk exposure. We could hedge the imBTC risk exposure in a Perpetual or Futures market if needed.

Optimization

  1. We could artificially enlarge the initial X and initial Y to reduce the slippage. The disadvantage is that the market making depth will become limited. Thus, Let X = p X and Y = p Y. p is a parameter. For example, let p = 10.

  2. We could add an additional fixed discount/premium rate to the bid/ask order to increase the make maker's profit and reduce risk:
    ASK PRICE = Δy/Δx = Y/(x-Δx) * (1 + rate)
    BID PRICE = Δy/Δx = Y/(x+Δx) * (1 - rate)

Roll to new contract

We can continue to use the X and Y values ​​of the old contract in the new contract. This is because the value of the contract has not changed much in two consecutive days.
We can also use the Y/X of the previous day to get the INIT PRICE of the new day. And recalculate the initial X and Y based on the remaining available funds of market maker.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions