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

[DEC-2196] deprecate non-linear margin requirements #836

Merged
merged 8 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,12 @@ export interface LiquidityTierUpsertEventV1 {
* The maximum position size at which the margin requirements are
* not increased over the default values. Above this position size,
* the margin requirements increase at a rate of sqrt(size).
*
* Deprecated since v3.x.
*/

/** @deprecated */

basePositionNotional: Long;
}
/**
Expand Down Expand Up @@ -974,8 +978,12 @@ export interface LiquidityTierUpsertEventV1SDKType {
* The maximum position size at which the margin requirements are
* not increased over the default values. Above this position size,
* the margin requirements increase at a rate of sqrt(size).
*
* Deprecated since v3.x.
*/

/** @deprecated */

base_position_notional: Long;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ export interface LiquidityTier {
* The maximum position size at which the margin requirements are
* not increased over the default values. Above this position size,
* the margin requirements increase at a rate of sqrt(size).
*
* Deprecated since v3.x.
*/

/** @deprecated */

basePositionNotional: Long;
/**
* The impact notional amount (in quote quantums) is used to determine impact
Expand Down Expand Up @@ -237,8 +241,12 @@ export interface LiquidityTierSDKType {
* The maximum position size at which the margin requirements are
* not increased over the default values. Above this position size,
* the margin requirements increase at a rate of sqrt(size).
*
* Deprecated since v3.x.
*/

/** @deprecated */

base_position_notional: Long;
/**
* The impact notional amount (in quote quantums) is used to determine impact
Expand Down
4 changes: 3 additions & 1 deletion proto/dydxprotocol/indexer/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ message LiquidityTierUpsertEventV1 {
// The maximum position size at which the margin requirements are
Copy link
Contributor

@teddyding teddyding Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to explicitly comment this is deprecated since some version, similar to Cosmos SDK style

I think here we should say Deprecated since v3.x?

// not increased over the default values. Above this position size,
// the margin requirements increase at a rate of sqrt(size).
uint64 base_position_notional = 5;
//
// Deprecated since v3.x.
uint64 base_position_notional = 5 [ deprecated = true ];
}

// UpdateClobPairEventV1 message contains all the information about an update to
Expand Down
4 changes: 3 additions & 1 deletion proto/dydxprotocol/perpetuals/perpetual.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ message LiquidityTier {
// The maximum position size at which the margin requirements are
// not increased over the default values. Above this position size,
// the margin requirements increase at a rate of sqrt(size).
uint64 base_position_notional = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an upgrade handler needed for this change? Or will the protocol just ignore this value after the upgrade?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since the field is only marked as deprecated so it's backwards compatible.

//
// Deprecated since v3.x.
uint64 base_position_notional = 5 [ deprecated = true ];

// The impact notional amount (in quote quantums) is used to determine impact
// bid/ask prices and its recommended value is 500 USDC / initial margin
Expand Down
267 changes: 135 additions & 132 deletions protocol/indexer/events/events.pb.go

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions protocol/indexer/events/liquidity_tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ func NewLiquidityTierUpsertEvent(
name string,
initialMarginPpm uint32,
maintenanceFractionPpm uint32,
basePositionNotional uint64,
) *LiquidityTierUpsertEventV1 {
return &LiquidityTierUpsertEventV1{
Id: id,
Name: name,
InitialMarginPpm: initialMarginPpm,
MaintenanceFractionPpm: maintenanceFractionPpm,
BasePositionNotional: basePositionNotional,
}
}
2 changes: 0 additions & 2 deletions protocol/indexer/events/liquidity_tier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ func TestNewLiquidityTierUpsertEvent_Success(t *testing.T) {
"Large-Cap",
50000,
600000,
1000000000000,
)
expectedLiquidityTierUpsertEventProto := &LiquidityTierUpsertEventV1{
Id: 0,
Name: "Large-Cap",
InitialMarginPpm: 50000,
MaintenanceFractionPpm: 600000,
BasePositionNotional: 1000000000000,
}
require.Equal(t, expectedLiquidityTierUpsertEventProto, liquidityTierUpsertEvent)
}
14 changes: 7 additions & 7 deletions protocol/mocks/PerpetualsKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions protocol/testing/e2e/gov/perpetuals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var (
Name: "Test Tier",
InitialMarginPpm: 765_432,
MaintenanceFractionPpm: 345_678,
BasePositionNotional: 123_456,
ImpactNotional: 654_321,
}
)
Expand Down Expand Up @@ -355,7 +354,6 @@ func TestSetLiquidityTier(t *testing.T) {
Name: TEST_LIQUIDITY_TIER.Name,
InitialMarginPpm: TEST_LIQUIDITY_TIER.InitialMarginPpm,
MaintenanceFractionPpm: TEST_LIQUIDITY_TIER.MaintenanceFractionPpm,
BasePositionNotional: TEST_LIQUIDITY_TIER.BasePositionNotional,
ImpactNotional: TEST_LIQUIDITY_TIER.ImpactNotional,
},
},
Expand All @@ -369,7 +367,6 @@ func TestSetLiquidityTier(t *testing.T) {
Name: TEST_LIQUIDITY_TIER.Name,
InitialMarginPpm: TEST_LIQUIDITY_TIER.InitialMarginPpm,
MaintenanceFractionPpm: TEST_LIQUIDITY_TIER.MaintenanceFractionPpm,
BasePositionNotional: TEST_LIQUIDITY_TIER.BasePositionNotional,
ImpactNotional: TEST_LIQUIDITY_TIER.ImpactNotional,
},
},
Expand All @@ -384,7 +381,6 @@ func TestSetLiquidityTier(t *testing.T) {
Name: TEST_LIQUIDITY_TIER.Name,
InitialMarginPpm: 1_000_001,
MaintenanceFractionPpm: TEST_LIQUIDITY_TIER.MaintenanceFractionPpm,
BasePositionNotional: TEST_LIQUIDITY_TIER.BasePositionNotional,
ImpactNotional: TEST_LIQUIDITY_TIER.ImpactNotional,
},
},
Expand All @@ -398,21 +394,6 @@ func TestSetLiquidityTier(t *testing.T) {
Name: TEST_LIQUIDITY_TIER.Name,
InitialMarginPpm: TEST_LIQUIDITY_TIER.InitialMarginPpm,
MaintenanceFractionPpm: 1_000_001,
BasePositionNotional: TEST_LIQUIDITY_TIER.BasePositionNotional,
ImpactNotional: TEST_LIQUIDITY_TIER.ImpactNotional,
},
},
expectCheckTxFails: true,
},
"Failure: base position notional is 0": {
msg: &perptypes.MsgSetLiquidityTier{
Authority: authtypes.NewModuleAddress(perptypes.ModuleName).String(),
LiquidityTier: perptypes.LiquidityTier{
Id: 5678,
Name: TEST_LIQUIDITY_TIER.Name,
InitialMarginPpm: TEST_LIQUIDITY_TIER.InitialMarginPpm,
MaintenanceFractionPpm: TEST_LIQUIDITY_TIER.MaintenanceFractionPpm,
BasePositionNotional: 0,
ImpactNotional: TEST_LIQUIDITY_TIER.ImpactNotional,
},
},
Expand All @@ -426,7 +407,6 @@ func TestSetLiquidityTier(t *testing.T) {
Name: TEST_LIQUIDITY_TIER.Name,
InitialMarginPpm: TEST_LIQUIDITY_TIER.InitialMarginPpm,
MaintenanceFractionPpm: TEST_LIQUIDITY_TIER.MaintenanceFractionPpm,
BasePositionNotional: TEST_LIQUIDITY_TIER.BasePositionNotional,
ImpactNotional: 0,
},
},
Expand All @@ -440,7 +420,6 @@ func TestSetLiquidityTier(t *testing.T) {
Name: "Test Tier",
InitialMarginPpm: 765_432,
MaintenanceFractionPpm: 345_678,
BasePositionNotional: 123_456,
ImpactNotional: 654_321,
},
},
Expand Down
13 changes: 0 additions & 13 deletions protocol/testutil/constants/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,69 @@ var LiquidityTiers = []perptypes.LiquidityTier{
Name: "0",
InitialMarginPpm: 1_000_000,
MaintenanceFractionPpm: 1_000_000,
BasePositionNotional: 1_000_000,
ImpactNotional: 500_000_000,
},
{
Id: 1,
Name: "1",
InitialMarginPpm: 1_000_000,
MaintenanceFractionPpm: 750_000,
BasePositionNotional: 1_000_000,
ImpactNotional: 500_000_000,
},
{
Id: 2,
Name: "2",
InitialMarginPpm: 1_000_000,
MaintenanceFractionPpm: 0,
BasePositionNotional: 1_000_000,
ImpactNotional: 500_000_000,
},
{
Id: 3,
Name: "3",
InitialMarginPpm: 200_000,
MaintenanceFractionPpm: 500_000,
BasePositionNotional: 100_000_000_000,
ImpactNotional: 2_500_000_000,
},
{
Id: 4,
Name: "4",
InitialMarginPpm: 500_000,
MaintenanceFractionPpm: 800_000,
BasePositionNotional: 100_000_000_000,
ImpactNotional: 1_000_000_000,
},
{
Id: 5,
Name: "5",
InitialMarginPpm: 500_000,
MaintenanceFractionPpm: 600_000,
BasePositionNotional: 1_000_000,
ImpactNotional: 1_000_000_000,
},
{
Id: 6,
Name: "6",
InitialMarginPpm: 200_000,
MaintenanceFractionPpm: 900_000,
BasePositionNotional: 1_000_000,
ImpactNotional: 2_500_000_000,
},
{
Id: 7,
Name: "7",
InitialMarginPpm: 0,
MaintenanceFractionPpm: 0,
BasePositionNotional: 100_000_000_000,
ImpactNotional: 1_000_000_000,
},
{
Id: 8,
Name: "8",
InitialMarginPpm: 9_910, // 0.9910%
MaintenanceFractionPpm: 1_000_000,
BasePositionNotional: 100_000_000_000,
ImpactNotional: 50_454_000_000,
},
{
Id: 101,
Name: "101",
InitialMarginPpm: 200_000,
MaintenanceFractionPpm: 500_000,
BasePositionNotional: 1_000_000,
ImpactNotional: 2_500_000_000,
},
}
Expand Down Expand Up @@ -331,23 +321,20 @@ var (
Name: "Large-Cap",
InitialMarginPpm: 200_000,
MaintenanceFractionPpm: 500_000,
BasePositionNotional: 1000_000_000,
ImpactNotional: 2_500_000_000,
},
{
Id: uint32(1),
Name: "Mid-Cap",
InitialMarginPpm: 300_000,
MaintenanceFractionPpm: 600_000,
BasePositionNotional: 500_000_000,
ImpactNotional: 1_667_000_000,
},
{
Id: uint32(2),
Name: "Small-Cap",
InitialMarginPpm: 400_000,
MaintenanceFractionPpm: 700_000,
BasePositionNotional: 250_000_000,
ImpactNotional: 1_250_000_000,
},
},
Expand Down
4 changes: 2 additions & 2 deletions protocol/testutil/keeper/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package keeper

import (
"fmt"
"github.com/dydxprotocol/v4-chain/protocol/lib"
"testing"

"github.com/dydxprotocol/v4-chain/protocol/lib"

pricefeedserver_types "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types/pricefeed"
"github.com/dydxprotocol/v4-chain/protocol/indexer/common"
indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events"
Expand Down Expand Up @@ -174,7 +175,6 @@ func CreateTestLiquidityTiers(t *testing.T, ctx sdk.Context, k *keeper.Keeper) {
l.Name,
l.InitialMarginPpm,
l.MaintenanceFractionPpm,
l.BasePositionNotional,
l.ImpactNotional,
)

Expand Down
7 changes: 0 additions & 7 deletions protocol/testutil/liquidity_tier/liquidity_tier.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ func WithMaintenanceFractionPpm(maintenanceFractionPpm uint32) LtModifierOption
}
}

func WithBasePositionNotional(basePositionNotional uint64) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.BasePositionNotional = basePositionNotional
}
}

func WithImpactNotional(impactNotional uint64) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.ImpactNotional = impactNotional
Expand All @@ -57,7 +51,6 @@ func GenerateLiquidityTier(optionalModifications ...LtModifierOption) *perptypes
Name: "Large-Cap",
InitialMarginPpm: 1_000_000,
MaintenanceFractionPpm: 1_000_000,
BasePositionNotional: 1_000_000,
ImpactNotional: 500_000_000,
}

Expand Down
9 changes: 0 additions & 9 deletions protocol/testutil/sim_helpers/genesis_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ var (
Valid: MaxNumPerpetuals.Valid,
}

MinBasePositionNotional = GenesisParameters[int]{
Reasonable: 10_000_000_000, // 10_000 USDC
Valid: 50_000_000_000, // 50_000 USDC
}
MaxBasePositionNotional = GenesisParameters[int]{
Reasonable: MinBasePositionNotional.Reasonable * 100,
Valid: MinBasePositionNotional.Valid * 100,
}

MinFundingRateClampFactorPpm = GenesisParameters[int]{
Reasonable: 4_000_000, // 400%
Valid: 1_000_000, // 100%
Expand Down
Loading
Loading