Skip to content

Commit

Permalink
fix: fix the msg liquidate tx (#2647)
Browse files Browse the repository at this point in the history
* fix: fix the msg liquidate tx

* update the changelog

* update the release notes
  • Loading branch information
gsk967 authored Dec 17, 2024
1 parent 14b0e03 commit bcff9ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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 @@ 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))
}

Expand Down

0 comments on commit bcff9ed

Please sign in to comment.