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

include client ids in vault query #2328

Merged
merged 1 commit into from
Sep 24, 2024
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 @@ -51,6 +51,7 @@ export interface QueryVaultResponse {
equity: Uint8Array;
inventory: Uint8Array;
vaultParams?: VaultParams;
mostRecentClientIds: number[];
}
/** QueryVaultResponse is a response type for the Vault RPC method. */

Expand All @@ -60,6 +61,7 @@ export interface QueryVaultResponseSDKType {
equity: Uint8Array;
inventory: Uint8Array;
vault_params?: VaultParamsSDKType;
most_recent_client_ids: number[];
}
/** QueryAllVaultsRequest is a request type for the AllVaults RPC method. */

Expand Down Expand Up @@ -466,7 +468,8 @@ function createBaseQueryVaultResponse(): QueryVaultResponse {
subaccountId: undefined,
equity: new Uint8Array(),
inventory: new Uint8Array(),
vaultParams: undefined
vaultParams: undefined,
mostRecentClientIds: []
};
}

Expand All @@ -492,6 +495,13 @@ export const QueryVaultResponse = {
VaultParams.encode(message.vaultParams, writer.uint32(42).fork()).ldelim();
}

writer.uint32(50).fork();

for (const v of message.mostRecentClientIds) {
writer.uint32(v);
}

writer.ldelim();
return writer;
},

Expand Down Expand Up @@ -524,6 +534,19 @@ export const QueryVaultResponse = {
message.vaultParams = VaultParams.decode(reader, reader.uint32());
break;

case 6:
if ((tag & 7) === 2) {
const end2 = reader.uint32() + reader.pos;

while (reader.pos < end2) {
message.mostRecentClientIds.push(reader.uint32());
}
} else {
message.mostRecentClientIds.push(reader.uint32());
}

break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -540,6 +563,7 @@ export const QueryVaultResponse = {
message.equity = object.equity ?? new Uint8Array();
message.inventory = object.inventory ?? new Uint8Array();
message.vaultParams = object.vaultParams !== undefined && object.vaultParams !== null ? VaultParams.fromPartial(object.vaultParams) : undefined;
message.mostRecentClientIds = object.mostRecentClientIds?.map(e => e) || [];
return message;
}

Expand Down
1 change: 1 addition & 0 deletions proto/dydxprotocol/vault/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ message QueryVaultResponse {
(gogoproto.nullable) = false
];
VaultParams vault_params = 5 [ (gogoproto.nullable) = false ];
repeated uint32 most_recent_client_ids = 6;
}

// QueryAllVaultsRequest is a request type for the AllVaults RPC method.
Expand Down
11 changes: 6 additions & 5 deletions protocol/x/vault/keeper/grpc_query_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func (k Keeper) Vault(
}

return &types.QueryVaultResponse{
VaultId: vaultId,
SubaccountId: *vaultId.ToSubaccountId(),
Equity: dtypes.NewIntFromBigInt(equity),
Inventory: dtypes.NewIntFromBigInt(inventory),
VaultParams: vaultParams,
VaultId: vaultId,
SubaccountId: *vaultId.ToSubaccountId(),
Equity: dtypes.NewIntFromBigInt(equity),
Inventory: dtypes.NewIntFromBigInt(inventory),
VaultParams: vaultParams,
MostRecentClientIds: k.GetMostRecentClientIds(ctx, vaultId),
}, nil
}

Expand Down
33 changes: 24 additions & 9 deletions protocol/x/vault/keeper/grpc_query_vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestVault(t *testing.T) {
inventory *big.Int
// Vault params.
vaultParams vaulttypes.VaultParams
// Client IDs.
clientIds []uint32
// Query request.
req *vaulttypes.QueryVaultRequest

Expand All @@ -45,6 +47,7 @@ func TestVault(t *testing.T) {
perpId: 0,
inventory: big.NewInt(200),
vaultParams: constants.VaultParams,
clientIds: []uint32{0, 1, 2, 3},
expectedEquity: big.NewInt(500),
},
"Success: close only vault status": {
Expand All @@ -59,6 +62,7 @@ func TestVault(t *testing.T) {
vaultParams: vaulttypes.VaultParams{
Status: vaulttypes.VaultStatus_VAULT_STATUS_CLOSE_ONLY,
},
clientIds: []uint32{},
expectedEquity: big.NewInt(500),
},
"Success: negative inventory and equity": {
Expand All @@ -71,6 +75,7 @@ func TestVault(t *testing.T) {
perpId: 0,
inventory: big.NewInt(-200),
vaultParams: constants.VaultParams,
clientIds: []uint32{77, 88, 99},
expectedEquity: big.NewInt(-300),
},
"Success: non-existent clob pair": {
Expand All @@ -86,6 +91,7 @@ func TestVault(t *testing.T) {
perpId: 0,
inventory: big.NewInt(0),
vaultParams: constants.VaultParams,
clientIds: []uint32{93_213, 212_092},
expectedEquity: big.NewInt(100),
},
"Error: query non-existent vault": {
Expand All @@ -98,6 +104,7 @@ func TestVault(t *testing.T) {
perpId: 0,
inventory: big.NewInt(200),
vaultParams: constants.VaultParams,
clientIds: []uint32{0, 1, 2, 3},
expectedErr: "vault not found",
},
"Error: nil request": {
Expand Down Expand Up @@ -139,27 +146,35 @@ func TestVault(t *testing.T) {
}
},
)
testapp.UpdateGenesisDocWithAppStateForModule(
&genesis,
func(genesisState *vaulttypes.GenesisState) {
genesisState.Vaults = []vaulttypes.Vault{
{
VaultId: tc.vaultId,
VaultParams: tc.vaultParams,
},
}
},
)
return genesis
}).Build()
ctx := tApp.InitChain()
k := tApp.App.VaultKeeper

// Set vault params.
err := k.SetVaultParams(ctx, tc.vaultId, tc.vaultParams)
require.NoError(t, err)

// Check Vault query response is as expected.
response, err := k.Vault(ctx, tc.req)
if tc.expectedErr != "" {
require.ErrorContains(t, err, tc.expectedErr)
} else {
require.NoError(t, err)
expectedResponse := vaulttypes.QueryVaultResponse{
VaultId: tc.vaultId,
SubaccountId: *tc.vaultId.ToSubaccountId(),
Equity: dtypes.NewIntFromBigInt(tc.expectedEquity),
Inventory: dtypes.NewIntFromBigInt(tc.inventory),
VaultParams: tc.vaultParams,
VaultId: tc.vaultId,
SubaccountId: *tc.vaultId.ToSubaccountId(),
Equity: dtypes.NewIntFromBigInt(tc.expectedEquity),
Inventory: dtypes.NewIntFromBigInt(tc.inventory),
VaultParams: tc.vaultParams,
MostRecentClientIds: k.GetMostRecentClientIds(ctx, tc.vaultId),
}
require.Equal(t, expectedResponse, *response)
}
Expand Down
Loading
Loading