# Spot Hedge Maker

{% hint style="danger" %}
Liquidity provision is whitelisted until initial beta testing has completed
{% endhint %}

## Overview

Spot hedge maker model is based on Hot Tub, vaults developed by Perpetual Protocol during 2022-2023. Spot hedge maker vaults are divided into Base (asset token, e.g. ETH, BTC) and Quote (settlement token, e.g. USDT) vaults.

The basic concept is that all taker trades made via this vault on the perpetual futures DEX are automatically hedged using tokens purchased on spot markets. So if a trader on Perp v3 opens a 1 ETH long, thus creating a 1 ETH short for the maker, the vault will automatically buy 1 ETH on spot markets to hedge the maker's position. The futures trade and the spot hedge occur atomically.

Requests to fill an order (`fillOrder()`) should be made via the [Order Gateway](/nekodex-playground/docs-for-devs/contracts/order-gateway.md).

## SpotHedgeBaseMaker

Each vault accepts liquidity deposits in one base asset (e.g. ETH, BTC), so each market has a distinct vault.

#### Taker opens short

Base vault sells an equal amount of base asset to hedge the maker's long.

<figure><img src="/files/PHWAzFGrW15jpWulddc2" alt=""><figcaption></figcaption></figure>

#### Taker opens long

Base vault buys an equal amount of base asset to hedge the maker's long.

<figure><img src="/files/4Vwrd2flfbVGZ24FCxse" alt=""><figcaption></figcaption></figure>

### Utilization Ratio

{% code overflow="wrap" %}

```solidity
utilRatio = 1 - (assetBalance / assetLiability)

/// @notice Example
///         LP deposits 1 ETH, and taker opens a 1 ETH short
deposit 1 ETH → 
    assetLiability += 1 ETH
    assetBalance += 1 ETH
fillOrder(1 ETH short) → 
swap(1 ETH) →
     assetBalance -= 1 ETH
utilRatio = 1 - (0 ETH / 1 ETH) = 1
```

{% endcode %}

### Maker shares

Liquidity providers receive shares (similar to LP tokens) representing their stake in the liquidity pool. Shares must be redeemed to withdraw funds from the vault.

{% code overflow="wrap" %}

```solidity
totalAsset = assetBalance + accountValueAsAsset

/// @notice `totalShare` is updated on deposit and withdrawal
/// @notice Deposit
totalShare <- totalShare * (1 + deltaAsset / totalAsset)
deltaAsset > 0
assetBalance <- assetBalance + deltaAsset
assetLiability <- assetLiability + deltaAsset

/// @notice Withdraw
deltaAsset = totalAsset * deltaShare / totalShare
deltaShare < 0
deltaAsset < 0
assetBalance <- assetBalance + deltaAsset
totalShare <- totalShare + deltaShare
/// @notice `assetLiability` is updated in a similar way openNotional is updated when reducing position on the Exchange
assetLiability <- assetLiability * (1 - deltaShare / totalShare)
/// @dev Withdraw will revert if
abs(deltaAsset) > assetBalance
vaultMarginRatio < minMarginRatio // after withdrawal
```

{% endcode %}

## SpotHedgeQuoteMaker

{% hint style="warning" %}
Quote maker vaults are not currently available and will launch at a future date.
{% endhint %}

Quote vaults work the same way as base vaults, but in reverse. Each vault accepts liquidity deposits in one quote asset (e.g. USDT), so each market has a distinct vault.

## Circuit Breaker

Maker will stop filling orders if risk thresholds are reached. When called, `fillOrderCallBack()` will check `minMarginRatio` to ensure it is above the set threshold.

For details, see [Circuit Breaker](/nekodex-playground/docs-for-devs/contracts/circuit-breaker.md).

## `fillOrderCallBack()`

In many instances, a maker must withdraw funds from the vault to execute a spot trade. This is managed using the `fillOrderCallBack()` function and is currently executable by whitelisted users only.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nekodex.org/nekodex-playground/docs-for-devs/contracts/maker/spot-hedge-maker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
