Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
NibiruHeisenberg opened this issue Nov 15, 2022 · 4 comments · Fixed by #1074
Closed
2 tasks done

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

NibiruHeisenberg opened this issue Nov 15, 2022 · 4 comments · Fixed by #1074
Assignees

Comments

@NibiruHeisenberg
Copy link
Contributor

NibiruHeisenberg commented Nov 15, 2022

Task Summary

  • Since maintenance margin ratio is an attribute of a Vpool, it can be removed from the genesis.
  • Add tx to edit vpools
@Unique-Divine
Copy link
Member

Unique-Divine commented Nov 15, 2022

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
Copy link
Contributor

matthiasmatt commented Nov 15, 2022

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
Copy link
Contributor

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
Copy link
Contributor Author

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.

@Unique-Divine Unique-Divine self-assigned this Nov 15, 2022
NibiruHeisenberg pushed a commit that referenced this issue Nov 23, 2022
… ratio modifiable by governance (#1074)

* refactor!(vpool): Remove ReserveSnapshot from genesis since snapshots are done in CreatePool

* change log

* chore(dependencies): re-run go mod tidy

* refactor(vpool): Use VPool.ToSnapshot

* revert go mod tidy changes since it breaks things

* test: Use minimum UTC time rather than 0 for the lowest possible snapshot time

* linter

* docs: fix comment

* refactor(vpool): Use VpoolConfig type for less type repetition | DRY improvement

* refactor: finish VpoolConfig update. All tests green again

* feat(vpool): proposal handler for EditVpoolConfig #wip

* changelog

* run golangci-lint

* feat(testutil): util function for getting a blank context

* fix: account for nil sdk.Dec values in Validate

* test: unit tests for ToSnapshot

* test(gov_test.go): Lots of tests for gov proposal types and marshaling

* feat,test: EditPoolConfig keeper fn and corresponding tests

* feat(vpool/client): CLI command and and handler for the EditPoolConfigProposal

* refactor(vpool): run golangci-lint

* test(vpool/client): Integration test for EditPoolConfigProposal

* fix(dependencies): Revert any automatic go.mod changes to fix the x/oracle integration tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants