Skip to content

Commit

Permalink
Merge branch 'main' into sai/memo_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 authored Mar 19, 2024
2 parents 07b46ff + 32e7c21 commit 0c91171
Showing 1 changed file with 19 additions and 6 deletions.
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 @@ func (q Querier) MaxWithdraw(
// 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
}
continue
}

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

uToken := sdk.NewCoin(userMaxWithdrawUToken.Denom, sdk.MinInt(userMaxWithdrawUToken.Amount, moduleMaxWithdrawUToken))
if uToken.IsPositive() {
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

0 comments on commit 0c91171

Please sign in to comment.