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

[CLOB-1043] replicate IsLiquidatable logic on daemon #873

Merged
merged 11 commits into from
Dec 19, 2023
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";
Comment on lines 1 to 4
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The provided context from the swagger.yaml file confirms that there are still references to AreSubaccountsLiquidatableResponse and its Result type in the Swagger documentation. These references are part of the API documentation and should be updated or removed to reflect the changes made in the codebase where the corresponding interfaces and functions were removed.

Given this information, the review comment is valid, and the references in the Swagger documentation should be addressed to ensure consistency with the updated codebase.


The removal of interfaces and functions related to AreSubaccountsLiquidatable has not been fully propagated throughout the codebase. References to these entities still exist in the Swagger documentation (swagger.yaml). These should be updated or removed to reflect the changes in the codebase.

  • protocol/client/docs/swagger-ui/swagger.yaml: Contains outdated references to AreSubaccountsLiquidatableResponse and AreSubaccountsLiquidatableResponse.Result.
Analysis chain

Confirm that the removal of interfaces and functions related to AreSubaccountsLiquidatable has been fully propagated throughout the codebase, ensuring no dangling references or calls to these removed entities remain.


The search results indicate that there are still references to AreSubaccountsLiquidatableResponse and its Result in the swagger.yaml file within the protocol/client/docs/swagger-ui directory. These references should be checked and potentially removed or updated to reflect the changes made in the PR.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to the removed interfaces and functions in the codebase.
rg 'AreSubaccountsLiquidatableRequest|AreSubaccountsLiquidatableResponse|AreSubaccountsLiquidatableResponse_Result|createBaseAreSubaccountsLiquidatableRequest'

Length of output: 496



Script:

#!/bin/bash
# Check the swagger.yaml file for the context of the remaining references to ensure they should be removed or updated.
rg -C 5 'AreSubaccountsLiquidatableResponse|AreSubaccountsLiquidatableResponse\.Result' protocol/client/docs/swagger-ui/swagger.yaml

Length of output: 1016

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,
Comment on lines 392 to 394
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The search results indicate that the function createBaseMevNodeToNodeCalculationRequest is indeed referenced in the same file query.ts where it was defined. This suggests that the function was being used to create base requests for MevNodeToNodeCalculationRequest. However, since the function has been removed, these references will now lead to errors.

Given this information, it is clear that the removal of createBaseMevNodeToNodeCalculationRequest impacts the existing functionality, as there are still calls to this function in the codebase.

Here is the concise response:

The function createBaseMevNodeToNodeCalculationRequest has been removed, but there are still references to it in query.ts. This will cause errors since the function no longer exists. The removal of this function impacts existing functionality.

  • Affected location: indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts

A fix would involve either restoring the function or updating the code to remove or replace these references.

Analysis chain

The function createBaseMevNodeToNodeCalculationRequest has been removed. Verify that this function is not used elsewhere in the codebase and that its removal does not impact any existing functionality.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to createBaseMevNodeToNodeCalculationRequest in the codebase.
rg 'createBaseMevNodeToNodeCalculationRequest'

Length of output: 462

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
Loading