Skip to content

Commit

Permalink
add volatility_bounds_period to LiquidityTier proto and add Volatilit…
Browse files Browse the repository at this point in the history
…yBounds proto
  • Loading branch information
tqin7 committed Dec 11, 2023
1 parent bfd2d4c commit 13a043a
Show file tree
Hide file tree
Showing 5 changed files with 2,554 additions and 45 deletions.
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 @@ -212,6 +213,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 @@ -251,6 +258,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 @@ -532,7 +569,8 @@ function createBaseLiquidityTier(): LiquidityTier {
initialMarginPpm: 0,
maintenanceFractionPpm: 0,
basePositionNotional: Long.UZERO,
impactNotional: Long.UZERO
impactNotional: Long.UZERO,
volatilityBoundsPeriod: undefined
};
}

Expand Down Expand Up @@ -562,6 +600,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 @@ -598,6 +640,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 @@ -615,6 +661,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 @@ -106,4 +107,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

0 comments on commit 13a043a

Please sign in to comment.