Skip to content

Commit c34d56d

Browse files
authored
include client ids in vault query (#2328)
1 parent 5883104 commit c34d56d

File tree

5 files changed

+252
-100
lines changed

5 files changed

+252
-100
lines changed

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface QueryVaultResponse {
5151
equity: Uint8Array;
5252
inventory: Uint8Array;
5353
vaultParams?: VaultParams;
54+
mostRecentClientIds: number[];
5455
}
5556
/** QueryVaultResponse is a response type for the Vault RPC method. */
5657

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

@@ -466,7 +468,8 @@ function createBaseQueryVaultResponse(): QueryVaultResponse {
466468
subaccountId: undefined,
467469
equity: new Uint8Array(),
468470
inventory: new Uint8Array(),
469-
vaultParams: undefined
471+
vaultParams: undefined,
472+
mostRecentClientIds: []
470473
};
471474
}
472475

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

498+
writer.uint32(50).fork();
499+
500+
for (const v of message.mostRecentClientIds) {
501+
writer.uint32(v);
502+
}
503+
504+
writer.ldelim();
495505
return writer;
496506
},
497507

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

537+
case 6:
538+
if ((tag & 7) === 2) {
539+
const end2 = reader.uint32() + reader.pos;
540+
541+
while (reader.pos < end2) {
542+
message.mostRecentClientIds.push(reader.uint32());
543+
}
544+
} else {
545+
message.mostRecentClientIds.push(reader.uint32());
546+
}
547+
548+
break;
549+
527550
default:
528551
reader.skipType(tag & 7);
529552
break;
@@ -540,6 +563,7 @@ export const QueryVaultResponse = {
540563
message.equity = object.equity ?? new Uint8Array();
541564
message.inventory = object.inventory ?? new Uint8Array();
542565
message.vaultParams = object.vaultParams !== undefined && object.vaultParams !== null ? VaultParams.fromPartial(object.vaultParams) : undefined;
566+
message.mostRecentClientIds = object.mostRecentClientIds?.map(e => e) || [];
543567
return message;
544568
}
545569

proto/dydxprotocol/vault/query.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ message QueryVaultResponse {
8989
(gogoproto.nullable) = false
9090
];
9191
VaultParams vault_params = 5 [ (gogoproto.nullable) = false ];
92+
repeated uint32 most_recent_client_ids = 6;
9293
}
9394

9495
// QueryAllVaultsRequest is a request type for the AllVaults RPC method.

protocol/x/vault/keeper/grpc_query_vault.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ func (k Keeper) Vault(
5050
}
5151

5252
return &types.QueryVaultResponse{
53-
VaultId: vaultId,
54-
SubaccountId: *vaultId.ToSubaccountId(),
55-
Equity: dtypes.NewIntFromBigInt(equity),
56-
Inventory: dtypes.NewIntFromBigInt(inventory),
57-
VaultParams: vaultParams,
53+
VaultId: vaultId,
54+
SubaccountId: *vaultId.ToSubaccountId(),
55+
Equity: dtypes.NewIntFromBigInt(equity),
56+
Inventory: dtypes.NewIntFromBigInt(inventory),
57+
VaultParams: vaultParams,
58+
MostRecentClientIds: k.GetMostRecentClientIds(ctx, vaultId),
5859
}, nil
5960
}
6061

protocol/x/vault/keeper/grpc_query_vault_test.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func TestVault(t *testing.T) {
2828
inventory *big.Int
2929
// Vault params.
3030
vaultParams vaulttypes.VaultParams
31+
// Client IDs.
32+
clientIds []uint32
3133
// Query request.
3234
req *vaulttypes.QueryVaultRequest
3335

@@ -45,6 +47,7 @@ func TestVault(t *testing.T) {
4547
perpId: 0,
4648
inventory: big.NewInt(200),
4749
vaultParams: constants.VaultParams,
50+
clientIds: []uint32{0, 1, 2, 3},
4851
expectedEquity: big.NewInt(500),
4952
},
5053
"Success: close only vault status": {
@@ -59,6 +62,7 @@ func TestVault(t *testing.T) {
5962
vaultParams: vaulttypes.VaultParams{
6063
Status: vaulttypes.VaultStatus_VAULT_STATUS_CLOSE_ONLY,
6164
},
65+
clientIds: []uint32{},
6266
expectedEquity: big.NewInt(500),
6367
},
6468
"Success: negative inventory and equity": {
@@ -71,6 +75,7 @@ func TestVault(t *testing.T) {
7175
perpId: 0,
7276
inventory: big.NewInt(-200),
7377
vaultParams: constants.VaultParams,
78+
clientIds: []uint32{77, 88, 99},
7479
expectedEquity: big.NewInt(-300),
7580
},
7681
"Success: non-existent clob pair": {
@@ -86,6 +91,7 @@ func TestVault(t *testing.T) {
8691
perpId: 0,
8792
inventory: big.NewInt(0),
8893
vaultParams: constants.VaultParams,
94+
clientIds: []uint32{93_213, 212_092},
8995
expectedEquity: big.NewInt(100),
9096
},
9197
"Error: query non-existent vault": {
@@ -98,6 +104,7 @@ func TestVault(t *testing.T) {
98104
perpId: 0,
99105
inventory: big.NewInt(200),
100106
vaultParams: constants.VaultParams,
107+
clientIds: []uint32{0, 1, 2, 3},
101108
expectedErr: "vault not found",
102109
},
103110
"Error: nil request": {
@@ -139,27 +146,35 @@ func TestVault(t *testing.T) {
139146
}
140147
},
141148
)
149+
testapp.UpdateGenesisDocWithAppStateForModule(
150+
&genesis,
151+
func(genesisState *vaulttypes.GenesisState) {
152+
genesisState.Vaults = []vaulttypes.Vault{
153+
{
154+
VaultId: tc.vaultId,
155+
VaultParams: tc.vaultParams,
156+
},
157+
}
158+
},
159+
)
142160
return genesis
143161
}).Build()
144162
ctx := tApp.InitChain()
145163
k := tApp.App.VaultKeeper
146164

147-
// Set vault params.
148-
err := k.SetVaultParams(ctx, tc.vaultId, tc.vaultParams)
149-
require.NoError(t, err)
150-
151165
// Check Vault query response is as expected.
152166
response, err := k.Vault(ctx, tc.req)
153167
if tc.expectedErr != "" {
154168
require.ErrorContains(t, err, tc.expectedErr)
155169
} else {
156170
require.NoError(t, err)
157171
expectedResponse := vaulttypes.QueryVaultResponse{
158-
VaultId: tc.vaultId,
159-
SubaccountId: *tc.vaultId.ToSubaccountId(),
160-
Equity: dtypes.NewIntFromBigInt(tc.expectedEquity),
161-
Inventory: dtypes.NewIntFromBigInt(tc.inventory),
162-
VaultParams: tc.vaultParams,
172+
VaultId: tc.vaultId,
173+
SubaccountId: *tc.vaultId.ToSubaccountId(),
174+
Equity: dtypes.NewIntFromBigInt(tc.expectedEquity),
175+
Inventory: dtypes.NewIntFromBigInt(tc.inventory),
176+
VaultParams: tc.vaultParams,
177+
MostRecentClientIds: k.GetMostRecentClientIds(ctx, tc.vaultId),
163178
}
164179
require.Equal(t, expectedResponse, *response)
165180
}

0 commit comments

Comments
 (0)