Skip to content

Commit

Permalink
[CLOB-1043] replicate IsLiquidatable logic on daemon (#873)
Browse files Browse the repository at this point in the history
* [CLOB-1043] replicate IsLiquidatable logic on daemon

* comments

* comments

* update to return error

* [CLOB-1044] replicate funding settlement on liquidation daemon (#882)

* [CLOB-1043] deprecate unused grpc query (#889)

* [CLOB-1043] deprecate unused grpc query

* fix lint

* [CLOB-1046] populate negative tnc subaccounts in grpc request (#890)

* [CLOB-1046] populate negative tnc subaccounts in grpc request

* [CLOB-1047] populate subaccounts with open positions in grpc request (#892)

* [CLOB-1047] populate subaccounts with open positions in grpc request

* comments
  • Loading branch information
jayy04 authored Dec 19, 2023
1 parent 4a0aad8 commit ece92b4
Show file tree
Hide file tree
Showing 27 changed files with 1,567 additions and 1,650 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Rpc } from "../../helpers";
import * as _m0 from "protobufjs/minimal";
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate";
import { QueryGetClobPairRequest, QueryClobPairResponse, QueryAllClobPairRequest, QueryClobPairAllResponse, AreSubaccountsLiquidatableRequest, AreSubaccountsLiquidatableResponse, MevNodeToNodeCalculationRequest, MevNodeToNodeCalculationResponse, QueryEquityTierLimitConfigurationRequest, QueryEquityTierLimitConfigurationResponse, QueryBlockRateLimitConfigurationRequest, QueryBlockRateLimitConfigurationResponse, QueryLiquidationsConfigurationRequest, QueryLiquidationsConfigurationResponse } from "./query";
import { QueryGetClobPairRequest, QueryClobPairResponse, QueryAllClobPairRequest, QueryClobPairAllResponse, MevNodeToNodeCalculationRequest, MevNodeToNodeCalculationResponse, QueryEquityTierLimitConfigurationRequest, QueryEquityTierLimitConfigurationResponse, QueryBlockRateLimitConfigurationRequest, QueryBlockRateLimitConfigurationResponse, QueryLiquidationsConfigurationRequest, QueryLiquidationsConfigurationResponse } from "./query";
/** Query defines the gRPC querier service. */

export interface Query {
Expand All @@ -10,9 +10,6 @@ export interface Query {
/** Queries a list of ClobPair items. */

clobPairAll(request?: QueryAllClobPairRequest): Promise<QueryClobPairAllResponse>;
/** Returns whether a subaccount is liquidatable. */

areSubaccountsLiquidatable(request: AreSubaccountsLiquidatableRequest): Promise<AreSubaccountsLiquidatableResponse>;
/** Runs the MEV node <> node calculation with the provided parameters. */

mevNodeToNodeCalculation(request: MevNodeToNodeCalculationRequest): Promise<MevNodeToNodeCalculationResponse>;
Expand All @@ -33,7 +30,6 @@ export class QueryClientImpl implements Query {
this.rpc = rpc;
this.clobPair = this.clobPair.bind(this);
this.clobPairAll = this.clobPairAll.bind(this);
this.areSubaccountsLiquidatable = this.areSubaccountsLiquidatable.bind(this);
this.mevNodeToNodeCalculation = this.mevNodeToNodeCalculation.bind(this);
this.equityTierLimitConfiguration = this.equityTierLimitConfiguration.bind(this);
this.blockRateLimitConfiguration = this.blockRateLimitConfiguration.bind(this);
Expand All @@ -54,12 +50,6 @@ export class QueryClientImpl implements Query {
return promise.then(data => QueryClobPairAllResponse.decode(new _m0.Reader(data)));
}

areSubaccountsLiquidatable(request: AreSubaccountsLiquidatableRequest): Promise<AreSubaccountsLiquidatableResponse> {
const data = AreSubaccountsLiquidatableRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.clob.Query", "AreSubaccountsLiquidatable", data);
return promise.then(data => AreSubaccountsLiquidatableResponse.decode(new _m0.Reader(data)));
}

mevNodeToNodeCalculation(request: MevNodeToNodeCalculationRequest): Promise<MevNodeToNodeCalculationResponse> {
const data = MevNodeToNodeCalculationRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.clob.Query", "MevNodeToNodeCalculation", data);
Expand Down Expand Up @@ -97,10 +87,6 @@ export const createRpcQueryExtension = (base: QueryClient) => {
return queryService.clobPairAll(request);
},

areSubaccountsLiquidatable(request: AreSubaccountsLiquidatableRequest): Promise<AreSubaccountsLiquidatableResponse> {
return queryService.areSubaccountsLiquidatable(request);
},

mevNodeToNodeCalculation(request: MevNodeToNodeCalculationRequest): Promise<MevNodeToNodeCalculationResponse> {
return queryService.mevNodeToNodeCalculation(request);
},
Expand Down
192 changes: 0 additions & 192 deletions indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../cosmos/base/query/v1beta1/pagination";
import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount";
import { ValidatorMevMatches, ValidatorMevMatchesSDKType, MevNodeToNodeMetrics, MevNodeToNodeMetricsSDKType } from "./mev";
import { ClobPair, ClobPairSDKType } from "./clob_pair";
import { EquityTierLimitConfiguration, EquityTierLimitConfigurationSDKType } from "./equity_tier_limit_config";
Expand Down Expand Up @@ -51,52 +50,6 @@ export interface QueryClobPairAllResponseSDKType {
clob_pair: ClobPairSDKType[];
pagination?: PageResponseSDKType;
}
/**
* AreSubaccountsLiquidatableRequest is a request message used to check whether
* the given subaccounts are liquidatable.
* The subaccount ids should not contain duplicates.
*/

export interface AreSubaccountsLiquidatableRequest {
subaccountIds: SubaccountId[];
}
/**
* AreSubaccountsLiquidatableRequest is a request message used to check whether
* the given subaccounts are liquidatable.
* The subaccount ids should not contain duplicates.
*/

export interface AreSubaccountsLiquidatableRequestSDKType {
subaccount_ids: SubaccountIdSDKType[];
}
/**
* AreSubaccountsLiquidatableResponse is a response message that contains the
* liquidation status for each subaccount.
*/

export interface AreSubaccountsLiquidatableResponse {
results: AreSubaccountsLiquidatableResponse_Result[];
}
/**
* AreSubaccountsLiquidatableResponse is a response message that contains the
* liquidation status for each subaccount.
*/

export interface AreSubaccountsLiquidatableResponseSDKType {
results: AreSubaccountsLiquidatableResponse_ResultSDKType[];
}
/** Result returns whether a subaccount should be liquidated. */

export interface AreSubaccountsLiquidatableResponse_Result {
subaccountId?: SubaccountId;
isLiquidatable: boolean;
}
/** Result returns whether a subaccount should be liquidated. */

export interface AreSubaccountsLiquidatableResponse_ResultSDKType {
subaccount_id?: SubaccountIdSDKType;
is_liquidatable: boolean;
}
/**
* MevNodeToNodeCalculationRequest is a request message used to run the
* MEV node <> node calculation.
Expand Down Expand Up @@ -436,151 +389,6 @@ export const QueryClobPairAllResponse = {

};

function createBaseAreSubaccountsLiquidatableRequest(): AreSubaccountsLiquidatableRequest {
return {
subaccountIds: []
};
}

export const AreSubaccountsLiquidatableRequest = {
encode(message: AreSubaccountsLiquidatableRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.subaccountIds) {
SubaccountId.encode(v!, writer.uint32(10).fork()).ldelim();
}

return writer;
},

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

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

switch (tag >>> 3) {
case 1:
message.subaccountIds.push(SubaccountId.decode(reader, reader.uint32()));
break;

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

return message;
},

fromPartial(object: DeepPartial<AreSubaccountsLiquidatableRequest>): AreSubaccountsLiquidatableRequest {
const message = createBaseAreSubaccountsLiquidatableRequest();
message.subaccountIds = object.subaccountIds?.map(e => SubaccountId.fromPartial(e)) || [];
return message;
}

};

function createBaseAreSubaccountsLiquidatableResponse(): AreSubaccountsLiquidatableResponse {
return {
results: []
};
}

export const AreSubaccountsLiquidatableResponse = {
encode(message: AreSubaccountsLiquidatableResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.results) {
AreSubaccountsLiquidatableResponse_Result.encode(v!, writer.uint32(10).fork()).ldelim();
}

return writer;
},

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

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

switch (tag >>> 3) {
case 1:
message.results.push(AreSubaccountsLiquidatableResponse_Result.decode(reader, reader.uint32()));
break;

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

return message;
},

fromPartial(object: DeepPartial<AreSubaccountsLiquidatableResponse>): AreSubaccountsLiquidatableResponse {
const message = createBaseAreSubaccountsLiquidatableResponse();
message.results = object.results?.map(e => AreSubaccountsLiquidatableResponse_Result.fromPartial(e)) || [];
return message;
}

};

function createBaseAreSubaccountsLiquidatableResponse_Result(): AreSubaccountsLiquidatableResponse_Result {
return {
subaccountId: undefined,
isLiquidatable: false
};
}

export const AreSubaccountsLiquidatableResponse_Result = {
encode(message: AreSubaccountsLiquidatableResponse_Result, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.subaccountId !== undefined) {
SubaccountId.encode(message.subaccountId, writer.uint32(10).fork()).ldelim();
}

if (message.isLiquidatable === true) {
writer.uint32(16).bool(message.isLiquidatable);
}

return writer;
},

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

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

switch (tag >>> 3) {
case 1:
message.subaccountId = SubaccountId.decode(reader, reader.uint32());
break;

case 2:
message.isLiquidatable = reader.bool();
break;

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

return message;
},

fromPartial(object: DeepPartial<AreSubaccountsLiquidatableResponse_Result>): AreSubaccountsLiquidatableResponse_Result {
const message = createBaseAreSubaccountsLiquidatableResponse_Result();
message.subaccountId = object.subaccountId !== undefined && object.subaccountId !== null ? SubaccountId.fromPartial(object.subaccountId) : undefined;
message.isLiquidatable = object.isLiquidatable ?? false;
return message;
}

};

function createBaseMevNodeToNodeCalculationRequest(): MevNodeToNodeCalculationRequest {
return {
blockProposerMatches: undefined,
Expand Down
25 changes: 0 additions & 25 deletions proto/dydxprotocol/clob/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "dydxprotocol/clob/clob_pair.proto";
import "dydxprotocol/clob/equity_tier_limit_config.proto";
import "dydxprotocol/clob/liquidations_config.proto";
import "dydxprotocol/clob/mev.proto";
import "dydxprotocol/subaccounts/subaccount.proto";

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

Expand All @@ -25,10 +24,6 @@ service Query {
option (google.api.http).get = "/dydxprotocol/clob/clob_pair";
}

// Returns whether a subaccount is liquidatable.
rpc AreSubaccountsLiquidatable(AreSubaccountsLiquidatableRequest)
returns (AreSubaccountsLiquidatableResponse);

// Runs the MEV node <> node calculation with the provided parameters.
rpc MevNodeToNodeCalculation(MevNodeToNodeCalculationRequest)
returns (MevNodeToNodeCalculationResponse) {
Expand Down Expand Up @@ -76,26 +71,6 @@ message QueryClobPairAllResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// AreSubaccountsLiquidatableRequest is a request message used to check whether
// the given subaccounts are liquidatable.
// The subaccount ids should not contain duplicates.
message AreSubaccountsLiquidatableRequest {
repeated dydxprotocol.subaccounts.SubaccountId subaccount_ids = 1
[ (gogoproto.nullable) = false ];
}

// AreSubaccountsLiquidatableResponse is a response message that contains the
// liquidation status for each subaccount.
message AreSubaccountsLiquidatableResponse {
// Result returns whether a subaccount should be liquidated.
message Result {
dydxprotocol.subaccounts.SubaccountId subaccount_id = 1
[ (gogoproto.nullable) = false ];
bool is_liquidatable = 2;
}
repeated Result results = 1 [ (gogoproto.nullable) = false ];
}

// MevNodeToNodeCalculationRequest is a request message used to run the
// MEV node <> node calculation.
message MevNodeToNodeCalculationRequest {
Expand Down
39 changes: 13 additions & 26 deletions protocol/daemons/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ const (
FlagBridgeDaemonLoopDelayMs = "bridge-daemon-loop-delay-ms"
FlagBridgeDaemonEthRpcEndpoint = "bridge-daemon-eth-rpc-endpoint"

FlagLiquidationDaemonEnabled = "liquidation-daemon-enabled"
FlagLiquidationDaemonLoopDelayMs = "liquidation-daemon-loop-delay-ms"
FlagLiquidationDaemonSubaccountPageLimit = "liquidation-daemon-subaccount-page-limit"
FlagLiquidationDaemonRequestChunkSize = "liquidation-daemon-request-chunk-size"
FlagLiquidationDaemonEnabled = "liquidation-daemon-enabled"
FlagLiquidationDaemonLoopDelayMs = "liquidation-daemon-loop-delay-ms"
FlagLiquidationDaemonQueryPageLimit = "liquidation-daemon-query-page-limit"
)

// Shared flags contains configuration flags shared by all daemons.
Expand Down Expand Up @@ -52,9 +51,8 @@ type LiquidationFlags struct {
Enabled bool
// LoopDelayMs configures the update frequency of the liquidation daemon.
LoopDelayMs uint32
// SubaccountPageLimit configures the pagination limit for fetching subaccounts.
SubaccountPageLimit uint64
RequestChunkSize uint64
// QueryPageLimit configures the pagination limit for fetching subaccounts.
QueryPageLimit uint64
}

// PriceFlags contains configuration flags for the Price Daemon.
Expand Down Expand Up @@ -90,10 +88,9 @@ func GetDefaultDaemonFlags() DaemonFlags {
EthRpcEndpoint: "",
},
Liquidation: LiquidationFlags{
Enabled: true,
LoopDelayMs: 1_600,
SubaccountPageLimit: 1_000,
RequestChunkSize: 50,
Enabled: true,
LoopDelayMs: 1_600,
QueryPageLimit: 1_000,
},
Price: PriceFlags{
Enabled: true,
Expand Down Expand Up @@ -160,14 +157,9 @@ func AddDaemonFlagsToCmd(
"Delay in milliseconds between running the Liquidation Daemon task loop.",
)
cmd.Flags().Uint64(
FlagLiquidationDaemonSubaccountPageLimit,
df.Liquidation.SubaccountPageLimit,
"Limit on the number of subaccounts to fetch per query in the Liquidation Daemon task loop.",
)
cmd.Flags().Uint64(
FlagLiquidationDaemonRequestChunkSize,
df.Liquidation.RequestChunkSize,
"Limit on the number of subaccounts per collateralization check in the Liquidation Daemon task loop.",
FlagLiquidationDaemonQueryPageLimit,
df.Liquidation.QueryPageLimit,
"Limit on the number of items to fetch per query in the Liquidation Daemon task loop.",
)

// Price Daemon.
Expand Down Expand Up @@ -235,14 +227,9 @@ func GetDaemonFlagValuesFromOptions(
result.Liquidation.LoopDelayMs = v
}
}
if option := appOpts.Get(FlagLiquidationDaemonSubaccountPageLimit); option != nil {
if v, err := cast.ToUint64E(option); err == nil {
result.Liquidation.SubaccountPageLimit = v
}
}
if option := appOpts.Get(FlagLiquidationDaemonRequestChunkSize); option != nil {
if option := appOpts.Get(FlagLiquidationDaemonQueryPageLimit); option != nil {
if v, err := cast.ToUint64E(option); err == nil {
result.Liquidation.RequestChunkSize = v
result.Liquidation.QueryPageLimit = v
}
}

Expand Down
Loading

0 comments on commit ece92b4

Please sign in to comment.