Skip to content

Commit

Permalink
feat: inspect query warns on failing addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Nov 29, 2023
1 parent faade06 commit 11e542b
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 119 deletions.
1 change: 1 addition & 0 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ message QueryInspectResponse {
repeated InspectAccount borrowers = 1 [
(gogoproto.nullable) = false
];
repeated string failures = 2;
}

// QueryInspectAccountResponse defines the response structure for the InspectAccount gRPC service handler.
Expand Down
8 changes: 8 additions & 0 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ paths:
description: >-
InspectAccount contains risk and balance info for a single
account for the inspector query.
failures:
type: array
items:
type: string
description: >-
QueryInspectResponse defines the response structure for the
Inspect gRPC service handler.
Expand Down Expand Up @@ -5079,6 +5083,10 @@ definitions:
description: >-
InspectAccount contains risk and balance info for a single account
for the inspector query.
failures:
type: array
items:
type: string
description: >-
QueryInspectResponse defines the response structure for the Inspect gRPC
service handler.
Expand Down
5 changes: 4 additions & 1 deletion x/leverage/keeper/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (q Querier) Inspect(
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
failures := []string{}

// This query is also disabled by default as a safety measure. Enable with liquidator queries.
if !q.Keeper.liquidatorQueryEnabled {
Expand Down Expand Up @@ -73,6 +74,8 @@ func (q Querier) Inspect(
borrowedValue = position.BorrowedValue()
collateralValue = position.CollateralValue()
liquidationThreshold = position.Limit()
} else {
failures = append(failures, addr.String())
}

borrowed := k.GetBorrowerBorrows(ctx, addr)
Expand Down Expand Up @@ -120,7 +123,7 @@ func (q Querier) Inspect(
for _, b := range borrowers {
sortedBorrowers = append(sortedBorrowers, *b)
}
return &types.QueryInspectResponse{Borrowers: sortedBorrowers}, nil
return &types.QueryInspectResponse{Borrowers: sortedBorrowers, Failures: failures}, nil
}

// Separated from grpc_query.go
Expand Down
Loading

0 comments on commit 11e542b

Please sign in to comment.