From 370b08467c02c5274e919b83f8286ea598614ed2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 6 Jun 2024 17:11:54 +0200 Subject: [PATCH] fix(auction): last bid --- x/auction/keeper/rewards.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 1ce4914c1b..6e7c8086c7 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -82,20 +82,21 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { sender, err := sdk.AccAddressFromBech32(msg.Sender) util.Panic(err) - if !bytes.Equal(sender, lastBid.Bidder) { - returned := coin.UmeeInt(lastBid.Amount) - if err = k.sendFromModule(lastBid.Bidder, returned); err != nil { - return err - } - if err = k.sendToModule(sender, msg.Amount); err != nil { - return err - } - } else { - diff := msg.Amount.SubAmount(lastBid.Amount) - if err = k.sendToModule(sender, diff); err != nil { - return err + toAuction := msg.Amount + if lastBid != nil { + if bytes.Equal(sender, lastBid.Bidder) { + // bidder updates his last bid: send only diff + toAuction = msg.Amount.SubAmount(lastBid.Amount) + } else { + returned := coin.UmeeInt(lastBid.Amount) + if err = k.sendFromModule(lastBid.Bidder, returned); err != nil { + return err + } } } + if err = k.sendToModule(sender, toAuction); err != nil { + return err + } bid := auction.Bid{Bidder: sender, Amount: msg.Amount.Amount} return store.SetValue(k.store, key, &bid, keyMsg)