From b47a5b8fc441731fd5a83c3f6fe84ebcebacb845 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Wed, 5 Jun 2024 16:23:44 +0530 Subject: [PATCH 1/7] fix the amount collect to reward auction fee colletor --- x/auction/keeper/rewards.go | 24 +++++++++++++++--------- x/leverage/keeper/oracle.go | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 1ce4914c1b..7275a24b92 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -73,7 +73,7 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { lastBid := store.GetValue[*auction.Bid](k.store, key, keyMsg) minBid := auction.MinRewardsBid if lastBid != nil { - minBid = lastBid.Amount.Add(minBid) + minBid = lastBid.Amount } if err := auction.ValidateMinRewardsBid(minBid, msg.Amount); err != nil { return err @@ -82,18 +82,24 @@ 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 lastBid == nil { 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 + 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 + } } } diff --git a/x/leverage/keeper/oracle.go b/x/leverage/keeper/oracle.go index 872f0a7b2b..88274c1530 100644 --- a/x/leverage/keeper/oracle.go +++ b/x/leverage/keeper/oracle.go @@ -297,7 +297,7 @@ func (k Keeper) fundModules(ctx sdk.Context, toOracle, toAuction sdk.Coins) erro } if !toAuctionCheck.IsZero() { auction.EmitFundRewardsAuction(&ctx, toOracleCheck) - return send(ctx, types.ModuleName, auction.ModuleName, toAuctionCheck) + return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, k.rewardsAuction, toAuctionCheck) } return nil From 6d79cd12ac6983a7fb16c311cf3647dffef8c4e9 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Wed, 5 Jun 2024 16:52:58 +0530 Subject: [PATCH 2/7] update the mid bid to auction bid --- x/auction/keeper/rewards.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 7275a24b92..0c4999cad2 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -73,7 +73,7 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { lastBid := store.GetValue[*auction.Bid](k.store, key, keyMsg) minBid := auction.MinRewardsBid if lastBid != nil { - minBid = lastBid.Amount + minBid = lastBid.Amount.Add(minBid) } if err := auction.ValidateMinRewardsBid(minBid, msg.Amount); err != nil { return err From f7b3f07878290748dd06ba88f71f833da0f8bb78 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Wed, 5 Jun 2024 17:36:25 +0530 Subject: [PATCH 3/7] fix the bidder address on genesis export --- proto/umee/auction/v1/auction.proto | 2 +- proto/umee/auction/v1/query.proto | 3 +- x/auction/auction.pb.go | 70 ++++++++++++++--------------- x/auction/keeper/genesis_test.go | 4 +- x/auction/keeper/grpc_query.go | 2 +- x/auction/keeper/rewards.go | 21 +++++---- x/auction/module/genesis.go | 19 -------- x/auction/query.pb.go | 67 ++++++++++++++------------- 8 files changed, 88 insertions(+), 100 deletions(-) delete mode 100644 x/auction/module/genesis.go diff --git a/proto/umee/auction/v1/auction.proto b/proto/umee/auction/v1/auction.proto index a20a98cbbb..46871e2907 100644 --- a/proto/umee/auction/v1/auction.proto +++ b/proto/umee/auction/v1/auction.proto @@ -17,7 +17,7 @@ message RewardsParams { // Bid records a user bid message Bid { - bytes bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; string amount = 2 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false]; } diff --git a/proto/umee/auction/v1/query.proto b/proto/umee/auction/v1/query.proto index e73af918a8..c2e0f9f498 100644 --- a/proto/umee/auction/v1/query.proto +++ b/proto/umee/auction/v1/query.proto @@ -3,6 +3,7 @@ package umee.auction.v1; import "google/protobuf/timestamp.proto"; import "google/api/annotations.proto"; +import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "umee/auction/v1/auction.proto"; import "cosmos/base/v1beta1/coin.proto"; @@ -42,7 +43,7 @@ message QueryRewardsAuction { message QueryRewardsAuctionResponse { uint32 id = 1; // highest bidder - string bidder = 2; + string bidder = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; cosmos.base.v1beta1.Coin bid = 3 [(gogoproto.nullable) = false]; repeated cosmos.base.v1beta1.Coin rewards = 4 [(gogoproto.nullable) = false]; google.protobuf.Timestamp ends_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; diff --git a/x/auction/auction.pb.go b/x/auction/auction.pb.go index fde9cfb152..a20ee31dfa 100644 --- a/x/auction/auction.pb.go +++ b/x/auction/auction.pb.go @@ -71,7 +71,7 @@ var xxx_messageInfo_RewardsParams proto.InternalMessageInfo // Bid records a user bid type Bid struct { - Bidder []byte `protobuf:"bytes,1,opt,name=bidder,proto3" json:"bidder,omitempty"` + Bidder string `protobuf:"bytes,1,opt,name=bidder,proto3" json:"bidder,omitempty"` Amount cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` } @@ -156,33 +156,33 @@ func init() { func init() { proto.RegisterFile("umee/auction/v1/auction.proto", fileDescriptor_7a7eec280427e7e3) } var fileDescriptor_7a7eec280427e7e3 = []byte{ - // 409 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x52, 0xc1, 0x6e, 0x13, 0x31, - 0x10, 0x5d, 0x13, 0x94, 0x80, 0x53, 0x84, 0xb4, 0x2a, 0x52, 0x1a, 0x09, 0x27, 0xe4, 0x14, 0x84, - 0x62, 0x93, 0x20, 0x21, 0x71, 0xe0, 0xd0, 0x2d, 0x12, 0xea, 0x0d, 0x2d, 0x9c, 0xb8, 0x44, 0x76, - 0x6c, 0xb6, 0x56, 0xb1, 0x5d, 0xd9, 0xde, 0x2d, 0x07, 0x6e, 0xfc, 0x40, 0x3f, 0xa6, 0x1f, 0x91, - 0x63, 0xd5, 0x13, 0xe2, 0x50, 0x20, 0xf9, 0x91, 0xca, 0x6b, 0xef, 0xed, 0xcd, 0xbc, 0x79, 0x3b, - 0x6f, 0xde, 0x1a, 0x3e, 0xaf, 0x95, 0x10, 0x84, 0xd6, 0x1b, 0x2f, 0x8d, 0x26, 0xcd, 0xb2, 0x83, - 0xf8, 0xc2, 0x1a, 0x6f, 0xf2, 0xa7, 0x81, 0xc6, 0x5d, 0xaf, 0x59, 0x8e, 0x27, 0x95, 0x31, 0xd5, - 0x77, 0x41, 0x5a, 0x9a, 0xd5, 0xdf, 0x88, 0x97, 0x4a, 0x38, 0x4f, 0xd5, 0x45, 0x54, 0x8c, 0x0f, - 0x2b, 0x53, 0x99, 0x16, 0x92, 0x80, 0x52, 0xf7, 0x68, 0x63, 0x9c, 0x32, 0x6e, 0x1d, 0x89, 0x58, - 0x24, 0x0a, 0xc5, 0x8a, 0x30, 0xea, 0x04, 0x69, 0x96, 0x4c, 0x78, 0xba, 0x24, 0x1b, 0x23, 0x93, - 0x85, 0xd9, 0x0a, 0x3e, 0x29, 0xc5, 0x25, 0xb5, 0xdc, 0x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, 0x04, 0xfe, - 0xed, 0x10, 0xb8, 0xda, 0xa3, 0xec, 0x66, 0x8f, 0xb2, 0xdf, 0x7b, 0x94, 0x7d, 0x7d, 0x59, 0x49, - 0x7f, 0x56, 0x33, 0xbc, 0x31, 0x8a, 0x84, 0x7f, 0xbc, 0xd0, 0xc2, 0x5f, 0x1a, 0x7b, 0xde, 0x16, - 0xa4, 0x79, 0x4b, 0x7e, 0x74, 0x2f, 0x81, 0xf5, 0xdb, 0x75, 0x6f, 0xee, 0x03, 0x00, 0x00, 0xff, - 0xff, 0xa0, 0x8c, 0xc4, 0xb7, 0x2b, 0x02, 0x00, 0x00, + // 407 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x92, 0xc1, 0x6e, 0x13, 0x31, + 0x10, 0x86, 0xd7, 0x04, 0x25, 0xe0, 0x80, 0x90, 0x56, 0x45, 0x4a, 0x23, 0xe1, 0x94, 0x9c, 0x8a, + 0x50, 0x6c, 0x12, 0x24, 0x24, 0x0e, 0x1c, 0xba, 0x45, 0x42, 0xbd, 0xa1, 0x85, 0x13, 0x97, 0xc8, + 0x5e, 0x9b, 0xad, 0x55, 0x6c, 0x57, 0xb6, 0x77, 0xcb, 0x81, 0x1b, 0x2f, 0xd0, 0x87, 0xe9, 0x43, + 0xe4, 0x58, 0xf5, 0x84, 0x38, 0x04, 0x48, 0x5e, 0x04, 0x79, 0xed, 0xbd, 0xcd, 0xcc, 0x3f, 0xdf, + 0xce, 0x3f, 0xb3, 0x86, 0xcf, 0x1a, 0x25, 0x04, 0xa1, 0x4d, 0xe5, 0xa5, 0xd1, 0xa4, 0x5d, 0xf6, + 0x21, 0xbe, 0xb4, 0xc6, 0x9b, 0xfc, 0x49, 0x90, 0x71, 0x5f, 0x6b, 0x97, 0xd3, 0x59, 0x6d, 0x4c, + 0xfd, 0x4d, 0x90, 0x4e, 0x66, 0xcd, 0x57, 0xe2, 0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, + 0xdf, 0x9f, 0xbf, 0x83, 0x23, 0xa1, 0xb9, 0x5b, 0xd3, 0x68, 0x66, 0xbc, 0x9a, 0xe2, 0x78, 0x7c, + 0xdc, 0x1f, 0x1f, 0x7f, 0xee, 0x8f, 0x5f, 0x3c, 0x08, 0xec, 0xf5, 0x9f, 0x19, 0x28, 0x87, 0x01, + 0x3a, 0xf1, 0xc5, 0x87, 0xcd, 0x3f, 0x94, 0x6d, 0x76, 0x08, 0xdc, 0xee, 0x10, 0xf8, 0xbb, 0x43, + 0xe0, 0x7a, 0x8f, 0xb2, 0xdb, 0x3d, 0xca, 0x7e, 0xed, 0x51, 0xf6, 0xe5, 0x45, 0x2d, 0xfd, 0x79, + 0xc3, 0x70, 0x65, 0x14, 0x09, 0xff, 0x78, 0xa1, 0x85, 0xbf, 0x32, 0xf6, 0xa2, 0x4b, 0x48, 0xfb, + 0x86, 0x7c, 0xef, 0x5f, 0x02, 0x1b, 0x76, 0xe3, 0x5e, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xc9, + 0x8c, 0x9f, 0x2d, 0x2b, 0x02, 0x00, 0x00, } func (m *RewardsParams) Marshal() (dAtA []byte, err error) { @@ -461,7 +461,7 @@ func (m *Bid) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Bidder", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowAuction @@ -471,25 +471,23 @@ func (m *Bid) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthAuction } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthAuction } if postIndex > l { return io.ErrUnexpectedEOF } - m.Bidder = append(m.Bidder[:0], dAtA[iNdEx:postIndex]...) - if m.Bidder == nil { - m.Bidder = []byte{} - } + m.Bidder = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { diff --git a/x/auction/keeper/genesis_test.go b/x/auction/keeper/genesis_test.go index 3b2bf588d0..4e4a445e94 100644 --- a/x/auction/keeper/genesis_test.go +++ b/x/auction/keeper/genesis_test.go @@ -44,8 +44,8 @@ func TestGenesis(t *testing.T) { {4, auction.Rewards{newCoin(412313), randTime()}}, } gs.RewardsBids = []auction.BidKV{ - {1, auction.Bid{accs.Alice, sdkmath.NewInt(153252)}}, - {2, auction.Bid{accs.Alice, sdkmath.NewInt(8521)}}, + {1, auction.Bid{accs.Alice.String(), sdkmath.NewInt(153252)}}, + {2, auction.Bid{accs.Alice.String(), sdkmath.NewInt(8521)}}, } check(gs) } diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index 615ecfab5f..e537594fa9 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -37,7 +37,7 @@ func (q Querier) RewardsAuction(goCtx context.Context, msg *auction.QueryRewards bid, id := q.Keeper(&ctx).getRewardsBid(msg.Id) r := &auction.QueryRewardsAuctionResponse{Id: id} if bid != nil { - r.Bidder = sdk.AccAddress(bid.Bidder).String() + r.Bidder = bid.Bidder r.Bid = coin.UmeeInt(bid.Amount) } rewards, _ := q.Keeper(&ctx).getRewardsAuction(msg.Id) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 0c4999cad2..1fd7984f03 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -1,7 +1,6 @@ package keeper import ( - "bytes" "errors" "fmt" "strconv" @@ -30,7 +29,11 @@ func (k Keeper) FinalizeRewardsAuction() error { newCoins := k.bank.GetAllBalances(*k.ctx, k.accs.RewardsCollect) bid, _ := k.getRewardsBid(id) if bid != nil && len(bid.Bidder) != 0 { - err := k.sendCoins(k.accs.RewardsCollect, bid.Bidder, a.Rewards) + bidderAccAddr, err := sdk.AccAddressFromBech32(bid.Bidder) + if err != nil { + return err + } + err = k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards) if err != nil { return fmt.Errorf("can't send coins to finalize the auction [%w]", err) } @@ -87,9 +90,13 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { return err } } else { - if !bytes.Equal(sender, lastBid.Bidder) { + bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder) + if err != nil { + return err + } + if msg.Sender == lastBid.Bidder { returned := coin.UmeeInt(lastBid.Amount) - if err = k.sendFromModule(lastBid.Bidder, returned); err != nil { + if err = k.sendFromModule(bidderAccAddr, returned); err != nil { return err } if err = k.sendToModule(sender, msg.Amount); err != nil { @@ -103,7 +110,7 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { } } - bid := auction.Bid{Bidder: sender, Amount: msg.Amount.Amount} + bid := auction.Bid{Bidder: msg.Sender, Amount: msg.Amount.Amount} return store.SetValue(k.store, key, &bid, keyMsg) } @@ -117,8 +124,7 @@ func (k Keeper) getRewardsBid(id uint32) (*auction.Bid, uint32) { } func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) { - elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid]( - k.store, keyPrefixRewardsBid) + elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid](k.store, keyPrefixRewardsBid) if err != nil { return nil, err } @@ -128,7 +134,6 @@ func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) { bids[i].Bid = elems[i].Val } return bids, nil - } func (k Keeper) storeAllRewardsBids(elems []auction.BidKV) error { diff --git a/x/auction/module/genesis.go b/x/auction/module/genesis.go deleted file mode 100644 index 4abed50fa0..0000000000 --- a/x/auction/module/genesis.go +++ /dev/null @@ -1,19 +0,0 @@ -package module - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/umee-network/umee/v6/x/incentive" - "github.com/umee-network/umee/v6/x/incentive/keeper" -) - -// InitGenesis initializes the x/incentive module's state from a provided genesis -// state. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState incentive.GenesisState) { - k.InitGenesis(ctx, genState) -} - -// ExportGenesis returns the x/incentive module's exported genesis state. -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *incentive.GenesisState { - return k.ExportGenesis(ctx) -} diff --git a/x/auction/query.pb.go b/x/auction/query.pb.go index 4eeb13a82e..82ec58f5ee 100644 --- a/x/auction/query.pb.go +++ b/x/auction/query.pb.go @@ -6,6 +6,7 @@ package auction import ( context "context" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" @@ -201,38 +202,40 @@ func init() { func init() { proto.RegisterFile("umee/auction/v1/query.proto", fileDescriptor_e1df854d377e58e5) } var fileDescriptor_e1df854d377e58e5 = []byte{ - // 485 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x3f, 0x6f, 0xd4, 0x30, - 0x1c, 0x8d, 0x73, 0xed, 0x15, 0x8c, 0x5a, 0x24, 0x53, 0xa1, 0x90, 0x82, 0xef, 0x08, 0x20, 0x8a, - 0x00, 0x5b, 0x29, 0x12, 0x12, 0x12, 0x0c, 0x3d, 0x06, 0x56, 0x88, 0x98, 0xba, 0x20, 0xe7, 0x62, - 0x82, 0x05, 0x89, 0x43, 0xec, 0x5c, 0x61, 0x65, 0x60, 0x60, 0xaa, 0xc4, 0xcc, 0xf7, 0xb9, 0xb1, - 0x12, 0x0b, 0x13, 0x7f, 0xee, 0xf8, 0x04, 0x7c, 0x02, 0x14, 0xc7, 0xa9, 0xb8, 0x1c, 0xa0, 0xdb, - 0x1c, 0xbf, 0xf7, 0x7e, 0xbf, 0xe7, 0xf7, 0x02, 0x77, 0xaa, 0x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dc, 0xce, 0xb9, 0x3e, 0x94, 0xe5, 0xcb, 0x66, 0xdc, 0xe4, 0x2e, 0x7d, - 0xd3, 0xce, 0x8c, 0xfb, 0xa6, 0x8e, 0x3b, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xda, 0xf4, 0x09, - 0x57, 0xc1, 0x03, 0x00, 0x00, + // 513 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xb6, 0x9d, 0x36, 0x85, 0x43, 0x2d, 0xd2, 0x91, 0xc1, 0x75, 0xc1, 0x09, 0x06, 0x44, 0x11, + 0xf4, 0x0e, 0x17, 0x09, 0x09, 0x09, 0x86, 0x84, 0x81, 0x15, 0x0c, 0x53, 0x97, 0xea, 0x1c, 0x1f, + 0xe6, 0x04, 0xf6, 0x19, 0xdf, 0x39, 0x85, 0x95, 0x81, 0x01, 0x31, 0x54, 0x62, 0xe6, 0xbf, 0xe0, + 0x8f, 0xc8, 0x58, 0xc1, 0xc2, 0xc4, 0x8f, 0x84, 0x3f, 0x04, 0xf9, 0xee, 0x5c, 0x51, 0x07, 0x50, + 0x36, 0xfb, 0x7d, 0xdf, 0xf7, 0xee, 0x7b, 0xdf, 0x7b, 0x60, 0xab, 0xca, 0x28, 0xc5, 0xa4, 0x1a, + 0x4b, 0xc6, 0x73, 0x3c, 0x09, 0xf1, 0xcb, 0x8a, 0x96, 0xaf, 0x51, 0x51, 0x72, 0xc9, 0xe1, 0xd9, + 0x1a, 0x44, 0x06, 0x44, 0x93, 0xd0, 0xeb, 0xa7, 0x9c, 0xa7, 0x2f, 0x28, 0x56, 0x70, 0x5c, 0x3d, + 0xc5, 0x92, 0x65, 0x54, 0x48, 0x92, 0x15, 0x5a, 0xe1, 0x9d, 0x37, 0x04, 0x52, 0x30, 0x4c, 0xf2, + 0x9c, 0x4b, 0x52, 0x4b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 0x03, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. From 4c17664950fadcd6a8b858ef84c924435e817a7c Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Thu, 6 Jun 2024 21:15:48 +0530 Subject: [PATCH 4/7] refactor the bidder code --- x/auction/keeper/rewards.go | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 1fd7984f03..876ea048ae 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/umee-network/umee/v6/util" "github.com/umee-network/umee/v6/util/coin" "github.com/umee-network/umee/v6/util/sdkutil" "github.com/umee-network/umee/v6/util/store" @@ -82,34 +81,32 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { return err } - sender, err := sdk.AccAddressFromBech32(msg.Sender) - util.Panic(err) - - if lastBid == nil { - if err = k.sendToModule(sender, msg.Amount); err != nil { - return err - } - } else { - bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder) - if err != nil { - return err - } + toAuction := msg.Amount + if lastBid != nil { if msg.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(bidderAccAddr, returned); err != nil { - return err - } - if err = k.sendToModule(sender, msg.Amount); err != nil { + bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder) + if err != nil { return err } - } else { - diff := msg.Amount.SubAmount(lastBid.Amount) - if err = k.sendToModule(sender, diff); err != nil { + if err = k.sendFromModule(bidderAccAddr, returned); err != nil { return err } } } + sender, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return err + } + + if err = k.sendToModule(sender, toAuction); err != nil { + return err + } + bid := auction.Bid{Bidder: msg.Sender, Amount: msg.Amount.Amount} return store.SetValue(k.store, key, &bid, keyMsg) } From a2f68904659a16ba76001a0c16537065be104cdf Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Thu, 6 Jun 2024 21:54:04 +0530 Subject: [PATCH 5/7] proto format --- proto/umee/auction/v1/query.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/umee/auction/v1/query.proto b/proto/umee/auction/v1/query.proto index c2e0f9f498..18cc6eb195 100644 --- a/proto/umee/auction/v1/query.proto +++ b/proto/umee/auction/v1/query.proto @@ -43,7 +43,7 @@ message QueryRewardsAuction { message QueryRewardsAuctionResponse { uint32 id = 1; // highest bidder - string bidder = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string bidder = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; cosmos.base.v1beta1.Coin bid = 3 [(gogoproto.nullable) = false]; repeated cosmos.base.v1beta1.Coin rewards = 4 [(gogoproto.nullable) = false]; google.protobuf.Timestamp ends_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; From 447c01f4a4489d59dc842d241e24dd3e99a32a10 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Thu, 6 Jun 2024 22:05:00 +0530 Subject: [PATCH 6/7] fix the remaining rewards to next bid --- x/auction/keeper/rewards.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 876ea048ae..53163dabae 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -25,7 +25,6 @@ func (k Keeper) FinalizeRewardsAuction() error { return nil } - newCoins := k.bank.GetAllBalances(*k.ctx, k.accs.RewardsCollect) bid, _ := k.getRewardsBid(id) if bid != nil && len(bid.Bidder) != 0 { bidderAccAddr, err := sdk.AccAddressFromBech32(bid.Bidder) @@ -44,12 +43,10 @@ func (k Keeper) FinalizeRewardsAuction() error { Id: id, Bidder: sdk.AccAddress(bid.Bidder).String(), }) - } else if len(a.Rewards) != 0 { - // rollover the past rewards if there was no bidder - newCoins = newCoins.Add(a.Rewards...) } - return k.initNewAuction(id+1, newCoins) + remainingRewards := k.bank.GetAllBalances(*k.ctx, k.accs.RewardsCollect) + return k.initNewAuction(id+1, remainingRewards) } func (k Keeper) initNewAuction(id uint32, rewards sdk.Coins) error { From f8b24cc295aa8215572c98d87df0680b7016ae48 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Thu, 6 Jun 2024 22:13:24 +0530 Subject: [PATCH 7/7] address check --- x/auction/keeper/rewards.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index 53163dabae..db98d8cbcd 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -27,11 +27,8 @@ func (k Keeper) FinalizeRewardsAuction() error { bid, _ := k.getRewardsBid(id) if bid != nil && len(bid.Bidder) != 0 { - bidderAccAddr, err := sdk.AccAddressFromBech32(bid.Bidder) - if err != nil { - return err - } - err = k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards) + bidderAccAddr := sdk.MustAccAddressFromBech32(bid.Bidder) + err := k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards) if err != nil { return fmt.Errorf("can't send coins to finalize the auction [%w]", err) } @@ -85,22 +82,15 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { toAuction = msg.Amount.SubAmount(lastBid.Amount) } else { returned := coin.UmeeInt(lastBid.Amount) - bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder) - if err != nil { - return err - } - if err = k.sendFromModule(bidderAccAddr, returned); err != nil { + bidderAccAddr := sdk.MustAccAddressFromBech32(lastBid.Bidder) + if err := k.sendFromModule(bidderAccAddr, returned); err != nil { return err } } } - sender, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { - return err - } - - if err = k.sendToModule(sender, toAuction); err != nil { + sender := sdk.MustAccAddressFromBech32(msg.Sender) + if err := k.sendToModule(sender, toAuction); err != nil { return err }