# 🤝 Nibi-Perps

Nibiru Perps Banner

Table of Contents — Nibi-Perps


# Overview

Perps are the most popular financial instrument in the modern day crypto markets. Their trading volume across major exchanges reaches trillions of notional USD value each year.

While most perps exchanges are designed with off-chain order books, perp implementations can differ greatly from exchange to exchange. The Nibiru blockchain powers a decentralized and fully on-chain perpetual futures exchange called NibiPerps. There are several open problems Nibiru seeks to address with this exchange:

  • Minimize latency during periods of high volatility.
  • Minimize the imbalance in open interest.
  • Increase the number of unique traders on the platform.
  • Reduce the bleeding of the Perp Fund: One of the top priorities on the Nibiru Perps protocol it to keep the funding rates of the listed perps at parity to all other perpetual futures exchanges while monitoring the opportunity for arbitrageurs.

Nibi-Perps is currently on private testnet.

# Mark Price and Index Price

A perpetual futures contract, or perp, is a special type of futures contracts that doesn’t have an expiry date. The derivative value of a perp position is represented by its mark price, and the value of the underlying is represented by its index price. Traders can take up to 10x leverage on long or short positions.

Perp positions remain effective until either the trader closes their position or the position goes underwater. This allows traders to speculate on the future price without having to own the underlying asset. More info here (opens new window).

# Leverage and Position Values

Position Size

Suppose a trader wanted exposure to 5 ETH through the purchase of a perpetual contract. On Nibi-Perps, going long on 5 ETH means that the trader buys the ETH perp with a position size of 5. Position size is computed as the position notional mutliplied by the mark price of the asset.

Copy k = baseReserves * quoteReserves notionalDelta = margin * leverage // (notionalDelta is negative if short) baseReservesAfterSwap = k / (quoteReserves + notionalDelta) position_size = baseReserves - baseReservesAfterSwap

Position Notional Value

The notional value of the position, or position notional, is the total value a position controls in units of the quote asset. Notional value expresses the value a derivatives contract theoretically controls. On Nibiru, it is defined more concretely by

Copy positionNotional = abs(quoteReserves - k / (baseReserves + position_size)) leverage = positionNotional / margin.

Let's say that the mark price of ether is $3000 in our previous example. This implies that the trader with a long position of size 5 has a position notional of $15,000. And if the trader has 10x leverage, for example, she must have put down $1500 as margin (collateral backing the position).

# Margin and Margin Ratio

Margin is the amount of collateral used to back a position. Margin is expressed in units of the quote asset. At genesis, Nibi-Perps uses USDC as the primary quote asset.

The margin ratio is defined by:

Copy marginRatio = (margin + unrealizedPnL) / positionNotional

Here, unrealizedPnL is computed using either the mark price or the 15 minute TWAP of mark price; the higher of the two values is used when evaluating liquidation conditions.

When the virtual price is not within the spread tolerance to the index price, the margin ratio used is the highest value between a calculation with the index price (oracle based on underlying) and the mark price (derivative price).

Another good way to think about margin ratio is as the inverse of a position's effective leverage. I.e. if a trader puts down $100 as margin with 5x leverage, the notional is $500 and the margin ratio is 20%, which is equivalent to 1 / leverage.

# Cross Margin versus Isolated Margin

  • In a cross margin model, collateral is shared between open positions that use the same settlement currency. All open positions then have a combined margin ratio.
  • With an isolated margin model, the margin assigned to each open position is considered a separate collateral account.

Current implementation: Nibi-Perps uses isolated margin on each trading pair. This means that excess collateral on one position is not affected by a deficit on another (and vice versa). Positions are siloed in terms of liquidation risks, so an underwater ETH:USD position won't have any effect on an open ATOM:USD position, for instance.

In future upgrade, we'd like to implement a cross margin model and allow traders to select whether to use cross or isolated margin in the trading app. This way, traders could elect to have profits from one position support losses in another.

# Perp AMM Pools

Positions on Nibiru Perps are priced using constant-product liquidity pools with no real liquidity stored inside. In this model, assets are priced using the constant product model (x*y=k) pioneered by Uniswap. Tokens are sent to a clearing house, which stores the collateral in a vault, and perp pools are used for price discovery of the derivatives. This allows for the use of leverage trading and removes the need for liquidity providers, or market makers.

AMM pools enable Nibiru to have clear pricing rules. Each perpetual futures contract specifies the base asset’s quantity delivered for a single contract. For instance, OSMO/USDC, UMEE/USDC and ATOM/USDC futures contracts represent only one unit of the base assets OSMO, UMEE, and ATOM, similar to spot markets.

# Opening Positions

When opening a position, tokens are deposited and locked as margin. Under the hood, these tokens are stored with the clearing house, which uses AMM pools for price discovery and handles accounting for each position.

The exposure a user gets for opening a position is reflected in the change to the reserves of the corresponding AMM pool, which determines the price of the derivative (position) while enabling the use of leverage.

The protocol code also manages funding payments and liquidations of positions that have too much debt.

# Perp: NIBI Token

Holders who stake their NIBI tokens can vote on or propose new ideas to improve the perps protocol. NIBI stakers have the ability vote on exchange improvements, parameter alterations, new feature implementations, chain updates, and changes to reward mechanisms.

# What are the risks? How are they addressed?

Naturally, risks are inherent with any novel project being built. Nibiru’s ecosystem is built to promote the robust decentralization, permissionless creation of perps. As a result, community members can start trading without the supervision of a central authority, meaning the safety of having a facilitating party will not exist to the same degree. That being said, new market proposals will require governance approval for listing and a listing fee in NIBI tokens.

The permissionless state of market creation can drive the protocol to in-solvency in a black swan event. To mitigate against the risk of one market spilling over to others, Nibiru has 3 layers of backstop to account for periods of extreme volatility. In ordered priority, these are the Perp Fund and the Treasury.

# Perp Fund (PF)

The PF is is seeded at the genesis within an initial supply from the community token allocation. The PF doesn’t accrue inflation but instead increases its reserves from (1) the collection of transaction fees on perpetual swaps, (2) fees from liquidations, and (3) investment of excess capital deployed on the platform.

You may see the Perp Fund of Nibi-Perps referred to as the PerpEF in the technical documentation.

Using these revenue streams, the PF steps in to pay funding payments to correct the imbalance paid between long and short traders. If the mark and index prices differ substantially with a large aggregate position size, the PF may pay too much in funding.

And when liquidations don't occur on time, positions can end up with bad debt, which is also covered by the PF. For market crashes and other high volatility events, Nibiru’s liquidation parameters have been based on a ladder based framework taking into account the idiosyncrasies of each asset on the platform.

For example, if an asset has only a spot DEX and Nibiru as its liquidity venues, then such asset can be extremely volatile, warranting different liquidation parameters (such as lower max leverage). Whereas if the assets are BTC or ETH, which are traded on multiple venues CEX/DEX, then the parameters for liquidation are standardized to Perpetual/Drift protocol.