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

Consider module max withdraw in max_withdraw query #2462

Merged
merged 3 commits into from
Mar 18, 2024
Merged
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
25 changes: 19 additions & 6 deletions x/leverage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,32 @@
// will be nil and the resulting value will be what
// can safely be withdrawn even with missing prices.
// On non-nil error here, max withdraw is zero.
uToken, _, err := q.userMaxWithdraw(ctx, addr, denom)
if err == nil && uToken.IsPositive() {

userMaxWithdrawUToken, _, err := q.Keeper.userMaxWithdraw(ctx, addr, denom)
if err != nil {
if nonOracleError(err) {
return nil, err

Check warning on line 421 in x/leverage/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/grpc_query.go#L420-L421

Added lines #L420 - L421 were not covered by tests
}
continue

Check warning on line 423 in x/leverage/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/grpc_query.go#L423

Added line #L423 was not covered by tests
}

moduleMaxWithdrawUToken, err := q.Keeper.ModuleMaxWithdraw(ctx, userMaxWithdrawUToken)
if err != nil {
if nonOracleError(err) {
return nil, err

Check warning on line 429 in x/leverage/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/grpc_query.go#L428-L429

Added lines #L428 - L429 were not covered by tests
}
continue

Check warning on line 431 in x/leverage/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/grpc_query.go#L431

Added line #L431 was not covered by tests
}

uToken := sdk.NewCoin(userMaxWithdrawUToken.Denom, sdk.MinInt(userMaxWithdrawUToken.Amount, moduleMaxWithdrawUToken))
if uToken.IsPositive() {
toteki marked this conversation as resolved.
Show resolved Hide resolved
token, err := q.ToToken(ctx, uToken)
if err != nil {
return nil, err
}
maxUTokens = maxUTokens.Add(uToken)
maxTokens = maxTokens.Add(token)
}
// Non-price errors will cause the query itself to fail
if nonOracleError(err) {
return nil, err
}
}

return &types.QueryMaxWithdrawResponse{
Expand Down
Loading