NibiruChain / nibiru

Nibiru Chain: The breakthrough smart contract platform ushering in the next era of money. Nibiru powers an ecosystem of dApps including perps, RWAs, and more.
https://nibiru.fi
Apache License 2.0
183 stars 201 forks source link

feat(vpool): maintenance margin ratio should be modifiable by governance #1065

Closed NibiruHeisenberg closed 1 year ago

NibiruHeisenberg commented 1 year ago

Task Summary

Unique-Divine commented 1 year ago

Suggestion

We should make this a parameter of the virtual pool rather than the module. It's common for different asset pairs to have different maintenance margin requirements and maximum leverage on larger exchanges. Different position change magnitudes can also factor into this.

Benchmark - Binance

Pair Tier Max Leverage
BTC/USDT 1 10x
BTC/DAI 1 3x
AAVE/BTC 1 5x
BNB/USDT 1 10x
DOT/BUSD 1 5x
ATOM/ETH 1 3x
ATOM/BUSD 1 5x

References:

Benchmark - dYdX

Asset Leverage Limit
BTC 20x
ETH 20x
All Other Markets 10x

Reference: Maximum Leverage for Perpetuals. dYdX

Benchmark - Huobi

"Huobi Futures support 1x-100x leverage"

Reference: Contract Leverage Introduction

@NibiruChain/backend

matthiasmatt commented 1 year ago

It's already a parameter for the vpool (#729)

x/vpool/keeper/pool_state.go

// CreatePool creates a pool for a specific pair.
func (k Keeper) CreatePool(
    ctx sdk.Context,
    pair common.AssetPair,
    tradeLimitRatio sdk.Dec, // integer with 6 decimals, 1_000_000 means 1.0
    quoteAssetReserve sdk.Dec,
    baseAssetReserve sdk.Dec,
    fluctuationLimitRatio sdk.Dec,
    maxOracleSpreadRatio sdk.Dec,
    maintenanceMarginRatio sdk.Dec,
    maxLeverage sdk.Dec,
) {
    k.Pools.Insert(ctx, pair, types.VPool{
        Pair:                   pair,
        BaseAssetReserve:       baseAssetReserve,
        QuoteAssetReserve:      quoteAssetReserve,
        TradeLimitRatio:        tradeLimitRatio,
        FluctuationLimitRatio:  fluctuationLimitRatio,
        MaxOracleSpreadRatio:   maxOracleSpreadRatio,
        MaintenanceMarginRatio: maintenanceMarginRatio,
        MaxLeverage:            maxLeverage,
    })

    k.ReserveSnapshots.Insert(
        ctx,
        collections.Join(pair, ctx.BlockTime()),
        types.NewReserveSnapshot(
            pair,
            baseAssetReserve,
            quoteAssetReserve,
            ctx.BlockTime(),
        ),
    )
}
matthiasmatt commented 1 year ago

Ideally all parameters of a vpool (along with the k value) should be adjustable by governance.

I'm wondering if we want to have k slowly adjusting from A->B on a timeframe? Curve does it for their amplification parameter on their stable pools, osmosis does it for their weight change in LBP.

NibiruHeisenberg commented 1 year ago

The objective of this ticket would be to move the vpool fields into the module params so that they are subject to governance proposals. Right now I don't believe there is a way to modify the vpool fields after the chain goes live.