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

[CORE-829] add volatility_bounds_period to LiquidityTier proto and add VolatilityBounds proto #871

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,3 +1,4 @@
import { Duration, DurationSDKType } from "../../google/protobuf/duration";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial, Long } from "../../helpers";
/** Perpetual represents a perpetual on the dYdX exchange. */
Expand Down Expand Up @@ -216,6 +217,12 @@ export interface LiquidityTier {
*/

impactNotional: Long;
/**
* This duration specifies how fast volatility bounds recover.
* A longer duration leads to a longer (slower) recovery time.
*/

volatilityBoundsPeriod?: Duration;
}
/** LiquidityTier stores margin information. */

Expand Down Expand Up @@ -259,6 +266,36 @@ export interface LiquidityTierSDKType {
*/

impact_notional: Long;
/**
* This duration specifies how fast volatility bounds recover.
* A longer duration leads to a longer (slower) recovery time.
*/

volatility_bounds_period?: DurationSDKType;
}
/**
* VolatilityBounds stores lower and upper bounds of volatility for a perpeutal.
* A perpetual's variable margin fraction is computed with
* `VolatilityBounds.Min` and `VolatilityBounds.Max` as (let `o` be oracle price
* of the corresponding market and `mmf` be margin maintenance fraction):
* max((VolatilityBounds.Max - o) / o, (o - VolatilityBounds.Min) / o) + mmf
*/

export interface VolatilityBounds {
min: Long;
max: Long;
}
/**
* VolatilityBounds stores lower and upper bounds of volatility for a perpeutal.
* A perpetual's variable margin fraction is computed with
* `VolatilityBounds.Min` and `VolatilityBounds.Max` as (let `o` be oracle price
* of the corresponding market and `mmf` be margin maintenance fraction):
* max((VolatilityBounds.Max - o) / o, (o - VolatilityBounds.Min) / o) + mmf
*/

export interface VolatilityBoundsSDKType {
min: Long;
max: Long;
}

function createBasePerpetual(): Perpetual {
Expand Down Expand Up @@ -540,7 +577,8 @@ function createBaseLiquidityTier(): LiquidityTier {
initialMarginPpm: 0,
maintenanceFractionPpm: 0,
basePositionNotional: Long.UZERO,
impactNotional: Long.UZERO
impactNotional: Long.UZERO,
volatilityBoundsPeriod: undefined
};
}

Expand Down Expand Up @@ -570,6 +608,10 @@ export const LiquidityTier = {
writer.uint32(48).uint64(message.impactNotional);
}

if (message.volatilityBoundsPeriod !== undefined) {
Duration.encode(message.volatilityBoundsPeriod, writer.uint32(58).fork()).ldelim();
}

return writer;
},

Expand Down Expand Up @@ -606,6 +648,10 @@ export const LiquidityTier = {
message.impactNotional = (reader.uint64() as Long);
break;

case 7:
message.volatilityBoundsPeriod = Duration.decode(reader, reader.uint32());
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -623,6 +669,62 @@ export const LiquidityTier = {
message.maintenanceFractionPpm = object.maintenanceFractionPpm ?? 0;
message.basePositionNotional = object.basePositionNotional !== undefined && object.basePositionNotional !== null ? Long.fromValue(object.basePositionNotional) : Long.UZERO;
message.impactNotional = object.impactNotional !== undefined && object.impactNotional !== null ? Long.fromValue(object.impactNotional) : Long.UZERO;
message.volatilityBoundsPeriod = object.volatilityBoundsPeriod !== undefined && object.volatilityBoundsPeriod !== null ? Duration.fromPartial(object.volatilityBoundsPeriod) : undefined;
return message;
}

};

function createBaseVolatilityBounds(): VolatilityBounds {
return {
min: Long.UZERO,
max: Long.UZERO
};
}

export const VolatilityBounds = {
encode(message: VolatilityBounds, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (!message.min.isZero()) {
writer.uint32(8).uint64(message.min);
}

if (!message.max.isZero()) {
writer.uint32(16).uint64(message.max);
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): VolatilityBounds {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseVolatilityBounds();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.min = (reader.uint64() as Long);
break;

case 2:
message.max = (reader.uint64() as Long);
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<VolatilityBounds>): VolatilityBounds {
const message = createBaseVolatilityBounds();
message.min = object.min !== undefined && object.min !== null ? Long.fromValue(object.min) : Long.UZERO;
message.max = object.max !== undefined && object.max !== null ? Long.fromValue(object.max) : Long.UZERO;
return message;
}

Expand Down
16 changes: 16 additions & 0 deletions proto/dydxprotocol/perpetuals/perpetual.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package dydxprotocol.perpetuals;

import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";

option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types";

Expand Down Expand Up @@ -108,4 +109,19 @@ message LiquidityTier {
// - Impact ask price = average execution price for a market buy of the
// impact notional value.
uint64 impact_notional = 6;

// This duration specifies how fast volatility bounds recover.
// A longer duration leads to a longer (slower) recovery time.
google.protobuf.Duration volatility_bounds_period = 7
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
}

// VolatilityBounds stores lower and upper bounds of volatility for a perpeutal.
// A perpetual's variable margin fraction is computed with
// `VolatilityBounds.Min` and `VolatilityBounds.Max` as (let `o` be oracle price
// of the corresponding market and `mmf` be margin maintenance fraction):
// max((VolatilityBounds.Max - o) / o, (o - VolatilityBounds.Min) / o) + mmf
message VolatilityBounds {
uint64 min = 1;
uint64 max = 2;
}
2 changes: 1 addition & 1 deletion protocol/client/docs/statik/statik.go

Large diffs are not rendered by default.

Loading
Loading