Skip to content

Commit

Permalink
feat: inspect query warns on failing addresses (#2341)
Browse files Browse the repository at this point in the history
* feat: inspect query warns on failing addresses

* changelog

* fix lint

* field comment

---------

Co-authored-by: Robert Zaremba <[email protected]>
  • Loading branch information
toteki and robert-zaremba authored Dec 1, 2023
1 parent 1507d63 commit 0579b5e
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 119 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

- [2299](https://github.com/umee-network/umee/pull/2299) Upgrade Cosmos SDK to v0.47.
- [2301](https://github.com/umee-network/umee/pull/2301) use gov/v1 MinInitialDepositRatio and set it to 0.1.
- [2341](https://github.com/umee-network/umee/pull/2341) inspect query also returns a list of accounts whose positions could not be calculated

### Breaking Changes

Expand Down
2 changes: 2 additions & 0 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ message QueryInspectResponse {
repeated InspectAccount borrowers = 1 [
(gogoproto.nullable) = false
];
// Failures is a list of addresses for which the position calculation failed.
repeated string failures = 2;
}

// QueryInspectAccountResponse defines the response structure for the InspectAccount gRPC service handler.
Expand Down
14 changes: 14 additions & 0 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ paths:
description: >-
InspectAccount contains risk and balance info for a single
account for the inspector query.
failures:
type: array
items:
type: string
description: >-
Failures is a list of addresses for which the position
calculation failed.
description: >-
QueryInspectResponse defines the response structure for the
Inspect gRPC service handler.
Expand Down Expand Up @@ -5079,6 +5086,13 @@ definitions:
description: >-
InspectAccount contains risk and balance info for a single account
for the inspector query.
failures:
type: array
items:
type: string
description: >-
Failures is a list of addresses for which the position calculation
failed.
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 0579b5e

Please sign in to comment.