diff --git a/CHANGELOG.md b/CHANGELOG.md index c4e74fcf84..85e58b6d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 209d4f6682..ac0ec489ac 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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 diff --git a/x/leverage/keeper/collateral.go b/x/leverage/keeper/collateral.go index ccd77da2da..56e2eb8daa 100644 --- a/x/leverage/keeper/collateral.go +++ b/x/leverage/keeper/collateral.go @@ -29,34 +29,47 @@ func (k Keeper) liquidateCollateral(ctx sdk.Context, borrower, liquidator sdk.Ac // 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 + } 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 + } + 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 + } 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 + } return k.setCollateral(ctx, toAddr, k.GetCollateral(ctx, toAddr, uToken.Denom).Add(uToken)) }