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

fix: fix the msg liquidate tx #2647

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- [2647](https://github.com/umee-network/umee/pull/2647) Quick fix for the Leveraged Liquidate Tx
- [2643](https://github.com/umee-network/umee/pull/2643) Update cosmos-sdk from v0.47.14 to v0.47.15
- [2638](https://github.com/umee-network/umee/pull/2638) Fix the max_withdraw query

## v6.7.1

### Improvements
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The Release Procedure is defined in the [CONTRIBUTING](CONTRIBUTING.md#release-p
Highlights:

- cosmos-sdk update to v0.47.15
- quick fix for leveraged liquidate
- fix the max_withdraw query
- deps upgrade

Expand Down
21 changes: 17 additions & 4 deletions x/leverage/keeper/collateral.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,47 @@
// burnCollateral removes some uTokens from an account's collateral and burns them. This occurs
// during direct liquidations and during donateCollateral.
func (k Keeper) burnCollateral(ctx sdk.Context, addr sdk.AccAddress, uToken sdk.Coin) error {
err := k.setCollateral(ctx, addr, k.GetCollateral(ctx, addr, uToken.Denom).Sub(uToken))
val, err := k.GetCollateral(ctx, addr, uToken.Denom).SafeSub(uToken)
if err != nil {
return err
}
if err = k.setCollateral(ctx, addr, val); err != nil {
return err
}

Check warning on line 38 in x/leverage/keeper/collateral.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/collateral.go#L37-L38

Added lines #L37 - L38 were not covered by tests
if err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(uToken)); err != nil {
return err
}
return k.setUTokenSupply(ctx, k.GetUTokenSupply(ctx, uToken.Denom).Sub(uToken))
uTokenSupply, err := k.GetUTokenSupply(ctx, uToken.Denom).SafeSub(uToken)
if err != nil {
return err
}

Check warning on line 45 in x/leverage/keeper/collateral.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/collateral.go#L44-L45

Added lines #L44 - L45 were not covered by tests
return k.setUTokenSupply(ctx, uTokenSupply)
}

// decollateralize removes fromAddr's uTokens from the module and sends them to toAddr.
// It occurs when decollateralizing uTokens (in which case fromAddr and toAddr are the
// same) as well as during non-direct liquidations, where toAddr is the liquidator.
func (k Keeper) decollateralize(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, uToken sdk.Coin) error {
err := k.setCollateral(ctx, fromAddr, k.GetCollateral(ctx, fromAddr, uToken.Denom).Sub(uToken))
val, err := k.GetCollateral(ctx, fromAddr, uToken.Denom).SafeSub(uToken)
if err != nil {
return err
}
if err = k.setCollateral(ctx, fromAddr, val); err != nil {
return err
}

Check warning on line 59 in x/leverage/keeper/collateral.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/collateral.go#L58-L59

Added lines #L58 - L59 were not covered by tests
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, toAddr, sdk.NewCoins(uToken))
}

// moveCollateral moves collateral from one address to another while keeping the uTokens in the module.
// It occurs during fast liquidations.
func (k Keeper) moveCollateral(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, uToken sdk.Coin) error {
err := k.setCollateral(ctx, fromAddr, k.GetCollateral(ctx, fromAddr, uToken.Denom).Sub(uToken))
val, err := k.GetCollateral(ctx, fromAddr, uToken.Denom).SafeSub(uToken)
if err != nil {
return err
}
if err = k.setCollateral(ctx, fromAddr, val); err != nil {
return err
}

Check warning on line 72 in x/leverage/keeper/collateral.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/collateral.go#L71-L72

Added lines #L71 - L72 were not covered by tests
return k.setCollateral(ctx, toAddr, k.GetCollateral(ctx, toAddr, uToken.Denom).Add(uToken))
}

Expand Down
Loading