diff --git a/proto/umee/auction/v1/genesis.proto b/proto/umee/auction/v1/genesis.proto index 4d78d7f917..a8d9b4d02c 100644 --- a/proto/umee/auction/v1/genesis.proto +++ b/proto/umee/auction/v1/genesis.proto @@ -1,8 +1,6 @@ syntax = "proto3"; package umee.auction.v1; -import "google/protobuf/timestamp.proto"; -import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; import "umee/auction/v1/auction.proto"; @@ -16,13 +14,20 @@ message GenesisState { RewardsParams rewards_params = 1 [(gogoproto.nullable) = false]; // Latest active (in bid phase) reward auction. uint32 reward_auction_id = 2; - // Latest highest rewards bid. - Bid highest_rewards_bid = 3 [(gogoproto.nullable) = false]; + // All rewards auctions with ID. + repeated RewardsKV rewards_auctions = 3 [(gogoproto.nullable) = false]; + // Highest bids for all rewards auctions with ID. + repeated BidKV rewards_bids = 4 [(gogoproto.nullable) = false]; +} + +// RewardsKV combines a storage key (id) an value (rewards) +message RewardsKV { + uint32 id = 1; + Rewards rewards = 2 [(gogoproto.nullable) = false]; +} - google.protobuf.Timestamp current_rewards_auction_end = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; - // Tokens collected for the current auction. - repeated cosmos.base.v1beta1.Coin current_rewards = 5 [(gogoproto.nullable) = false]; - // Tokens collected for the next auction, while the current reward auction is still in the - // bid phase. - repeated cosmos.base.v1beta1.Coin next_rewards = 6 [(gogoproto.nullable) = false]; +// BidKV combines a storage key (id) an value (bid) +message BidKV { + uint32 id = 1; + Bid bid = 2 [(gogoproto.nullable) = false]; } diff --git a/x/auction/genesis.go b/x/auction/genesis.go index a9f5de0334..867993839e 100644 --- a/x/auction/genesis.go +++ b/x/auction/genesis.go @@ -1,12 +1,43 @@ package auction +import ( + "errors" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + // DefaultGenesis creates a default genesis state func DefaultGenesis() *GenesisState { - // TODO - return &GenesisState{} + return &GenesisState{ + RewardsParams: RewardsParams{BidDuration: 14 * 24 * 3600}, // 14 days + RewardAuctionId: 0, + RewardsAuctions: []RewardsKV{}, + RewardsBids: []BidKV{}, + } } func (gs *GenesisState) Validate() error { - // TODO + if gs.RewardsParams.BidDuration <= 60 { + return errors.New("RewardsParams.BidDuration must be at least 60s") + } + if gs.RewardsParams.BidDuration >= 180*24*3600 { + return errors.New("RewardsParams.BidDuration must be at most 15552000s = 180days") + } + for _, elem := range gs.RewardsAuctions { + coins := sdk.Coins(elem.Rewards.Rewards) + if err := coins.Validate(); err != nil { + return err + } + if elem.Id > gs.RewardAuctionId { + return fmt.Errorf("rewards_auctions ID must be at most rewards_auction_id") + } + } + for _, elem := range gs.RewardsBids { + if elem.Id > gs.RewardAuctionId { + return fmt.Errorf("rewards_bids ID must be at most rewards_auction_id") + } + } + return nil } diff --git a/x/auction/genesis.pb.go b/x/auction/genesis.pb.go index 267544d214..6ef4b0bcab 100644 --- a/x/auction/genesis.pb.go +++ b/x/auction/genesis.pb.go @@ -5,22 +5,17 @@ package auction import ( fmt "fmt" - types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" - github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" - _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -33,14 +28,10 @@ type GenesisState struct { RewardsParams RewardsParams `protobuf:"bytes,1,opt,name=rewards_params,json=rewardsParams,proto3" json:"rewards_params"` // Latest active (in bid phase) reward auction. RewardAuctionId uint32 `protobuf:"varint,2,opt,name=reward_auction_id,json=rewardAuctionId,proto3" json:"reward_auction_id,omitempty"` - // Latest highest rewards bid. - HighestRewardsBid Bid `protobuf:"bytes,3,opt,name=highest_rewards_bid,json=highestRewardsBid,proto3" json:"highest_rewards_bid"` - CurrentRewardsAuctionEnd time.Time `protobuf:"bytes,4,opt,name=current_rewards_auction_end,json=currentRewardsAuctionEnd,proto3,stdtime" json:"current_rewards_auction_end"` - // Tokens collected for the current auction. - CurrentRewards []types.Coin `protobuf:"bytes,5,rep,name=current_rewards,json=currentRewards,proto3" json:"current_rewards"` - // Tokens collected for the next auction, while the current reward auction is still in the - // bid phase. - NextRewards []types.Coin `protobuf:"bytes,6,rep,name=next_rewards,json=nextRewards,proto3" json:"next_rewards"` + // All rewards auctions with ID. + RewardsAuctions []RewardsKV `protobuf:"bytes,3,rep,name=rewards_auctions,json=rewardsAuctions,proto3" json:"rewards_auctions"` + // Highest bids for all rewards auctions with ID. + RewardsBids []BidKV `protobuf:"bytes,4,rep,name=rewards_bids,json=rewardsBids,proto3" json:"rewards_bids"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -76,40 +67,117 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +// RewardsKV combines a storage key (id) an value (rewards) +type RewardsKV struct { + Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Rewards Rewards `protobuf:"bytes,2,opt,name=rewards,proto3" json:"rewards"` +} + +func (m *RewardsKV) Reset() { *m = RewardsKV{} } +func (m *RewardsKV) String() string { return proto.CompactTextString(m) } +func (*RewardsKV) ProtoMessage() {} +func (*RewardsKV) Descriptor() ([]byte, []int) { + return fileDescriptor_15e83c50dcf6ac7b, []int{1} +} +func (m *RewardsKV) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RewardsKV) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RewardsKV.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RewardsKV) XXX_Merge(src proto.Message) { + xxx_messageInfo_RewardsKV.Merge(m, src) +} +func (m *RewardsKV) XXX_Size() int { + return m.Size() +} +func (m *RewardsKV) XXX_DiscardUnknown() { + xxx_messageInfo_RewardsKV.DiscardUnknown(m) +} + +var xxx_messageInfo_RewardsKV proto.InternalMessageInfo + +// BidKV combines a storage key (id) an value (bid) +type BidKV struct { + Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Bid Bid `protobuf:"bytes,2,opt,name=bid,proto3" json:"bid"` +} + +func (m *BidKV) Reset() { *m = BidKV{} } +func (m *BidKV) String() string { return proto.CompactTextString(m) } +func (*BidKV) ProtoMessage() {} +func (*BidKV) Descriptor() ([]byte, []int) { + return fileDescriptor_15e83c50dcf6ac7b, []int{2} +} +func (m *BidKV) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BidKV) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BidKV.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *BidKV) XXX_Merge(src proto.Message) { + xxx_messageInfo_BidKV.Merge(m, src) +} +func (m *BidKV) XXX_Size() int { + return m.Size() +} +func (m *BidKV) XXX_DiscardUnknown() { + xxx_messageInfo_BidKV.DiscardUnknown(m) +} + +var xxx_messageInfo_BidKV proto.InternalMessageInfo + func init() { proto.RegisterType((*GenesisState)(nil), "umee.auction.v1.GenesisState") + proto.RegisterType((*RewardsKV)(nil), "umee.auction.v1.RewardsKV") + proto.RegisterType((*BidKV)(nil), "umee.auction.v1.BidKV") } func init() { proto.RegisterFile("umee/auction/v1/genesis.proto", fileDescriptor_15e83c50dcf6ac7b) } var fileDescriptor_15e83c50dcf6ac7b = []byte{ - // 415 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4d, 0x6f, 0xd3, 0x30, - 0x18, 0x4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ae, 0xc9, 0x67, 0x82, - 0x99, 0x6b, 0xa9, 0xbe, 0xda, 0x0f, 0xdc, 0xbe, 0xc0, 0x37, 0xfd, 0xbb, 0x28, 0x8e, 0x6d, 0x1d, - 0xcf, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0xbd, 0xb8, 0xc3, 0x79, 0xc0, 0x02, 0x00, 0x00, + // 359 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x4f, 0x4b, 0xc3, 0x30, + 0x18, 0xc6, 0xdb, 0x6e, 0x2a, 0xa6, 0xfb, 0xa3, 0x61, 0x48, 0x19, 0x18, 0xc7, 0x4e, 0x53, 0xb4, + 0x61, 0x15, 0xc4, 0x9b, 0x58, 0x90, 0x21, 0xbb, 0x48, 0x45, 0x0f, 0x5e, 0x46, 0xbb, 0x84, 0x1a, + 0x64, 0xcb, 0x68, 0xba, 0xcd, 0x8f, 0xe1, 0xc5, 0xef, 0xb4, 0xe3, 0x8e, 0x9e, 0x44, 0xb7, 0x2f, + 0x22, 0x4d, 0xd2, 0x21, 0xce, 0xdd, 0xda, 0xf7, 0x79, 0xde, 0xdf, 0xf3, 0xe6, 0xe5, 0x05, 0x87, + 0xe3, 0x01, 0xa5, 0x38, 0x1c, 0xf7, 0x53, 0xc6, 0x87, 0x78, 0xd2, 0xc6, 0x31, 0x1d, 0x52, 0xc1, + 0x84, 0x3b, 0x4a, 0x78, 0xca, 0x61, 0x35, 0x93, 0x5d, 0x2d, 0xbb, 0x93, 0x76, 0xbd, 0x16, 0xf3, + 0x98, 0x4b, 0x0d, 0x67, 0x5f, 0xca, 0x56, 0x5f, 0xa3, 0xe4, 0x1d, 0x52, 0x6e, 0xbe, 0x5b, 0xa0, + 0xd4, 0x51, 0xdc, 0xfb, 0x34, 0x4c, 0x29, 0xec, 0x82, 0x4a, 0x42, 0xa7, 0x61, 0x42, 0x44, 0x6f, + 0x14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2, 0x74, 0xca, 0x93, 0x17, 0xf9, 0x83, 0x27, 0x17, + 0xf8, 0x35, 0x3f, 0x82, 0x68, 0x5b, 0x5e, 0xc1, 0xf9, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdd, + 0xeb, 0xca, 0xf2, 0x6c, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -132,10 +200,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.NextRewards) > 0 { - for iNdEx := len(m.NextRewards) - 1; iNdEx >= 0; iNdEx-- { + if len(m.RewardsBids) > 0 { + for iNdEx := len(m.RewardsBids) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.NextRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.RewardsBids[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -143,13 +211,13 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x32 + dAtA[i] = 0x22 } } - if len(m.CurrentRewards) > 0 { - for iNdEx := len(m.CurrentRewards) - 1; iNdEx >= 0; iNdEx-- { + if len(m.RewardsAuctions) > 0 { + for iNdEx := len(m.RewardsAuctions) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.CurrentRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.RewardsAuctions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -157,19 +225,49 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x1a } } - n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.CurrentRewardsAuctionEnd, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.CurrentRewardsAuctionEnd):]) - if err1 != nil { - return 0, err1 + if m.RewardAuctionId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.RewardAuctionId)) + i-- + dAtA[i] = 0x10 + } + { + size, err := m.RewardsParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } - i -= n1 - i = encodeVarintGenesis(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *RewardsKV) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RewardsKV) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RewardsKV) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l { - size, err := m.HighestRewardsBid.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Rewards.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -177,14 +275,37 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a - if m.RewardAuctionId != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.RewardAuctionId)) + dAtA[i] = 0x12 + if m.Id != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Id)) i-- - dAtA[i] = 0x10 + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *BidKV) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } + return dAtA[:n], nil +} + +func (m *BidKV) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BidKV) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l { - size, err := m.RewardsParams.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Bid.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -192,7 +313,12 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0xa + dAtA[i] = 0x12 + if m.Id != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -218,18 +344,14 @@ func (m *GenesisState) Size() (n int) { if m.RewardAuctionId != 0 { n += 1 + sovGenesis(uint64(m.RewardAuctionId)) } - l = m.HighestRewardsBid.Size() - n += 1 + l + sovGenesis(uint64(l)) - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.CurrentRewardsAuctionEnd) - n += 1 + l + sovGenesis(uint64(l)) - if len(m.CurrentRewards) > 0 { - for _, e := range m.CurrentRewards { + if len(m.RewardsAuctions) > 0 { + for _, e := range m.RewardsAuctions { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.NextRewards) > 0 { - for _, e := range m.NextRewards { + if len(m.RewardsBids) > 0 { + for _, e := range m.RewardsBids { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -237,6 +359,34 @@ func (m *GenesisState) Size() (n int) { return n } +func (m *RewardsKV) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovGenesis(uint64(m.Id)) + } + l = m.Rewards.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func (m *BidKV) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovGenesis(uint64(m.Id)) + } + l = m.Bid.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + func sovGenesis(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -326,7 +476,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field HighestRewardsBid", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardsAuctions", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -353,13 +503,14 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.HighestRewardsBid.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.RewardsAuctions = append(m.RewardsAuctions, RewardsKV{}) + if err := m.RewardsAuctions[len(m.RewardsAuctions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentRewardsAuctionEnd", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardsBids", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -386,13 +537,83 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.CurrentRewardsAuctionEnd, dAtA[iNdEx:postIndex]); err != nil { + m.RewardsBids = append(m.RewardsBids, BidKV{}) + if err := m.RewardsBids[len(m.RewardsBids)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 5: + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RewardsKV) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RewardsKV: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RewardsKV: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentRewards", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Rewards", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -419,14 +640,82 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.CurrentRewards = append(m.CurrentRewards, types.Coin{}) - if err := m.CurrentRewards[len(m.CurrentRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Rewards.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 6: + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *BidKV) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: BidKV: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BidKV: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NextRewards", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Bid", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -453,8 +742,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.NextRewards = append(m.NextRewards, types.Coin{}) - if err := m.NextRewards[len(m.NextRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Bid.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/auction/keeper/genesis.go b/x/auction/keeper/genesis.go index 731e52f17e..ba3a75d549 100644 --- a/x/auction/keeper/genesis.go +++ b/x/auction/keeper/genesis.go @@ -1,14 +1,38 @@ package keeper import ( + "github.com/umee-network/umee/v6/util/store" "github.com/umee-network/umee/v6/x/auction" ) -func (k Keeper) ExportGenesis() *auction.GenesisState { - // TODO - return &auction.GenesisState{} +func (k Keeper) ExportGenesis() (*auction.GenesisState, error) { + rewards, err := k.getAllRewardsAuctions() + if err != nil { + return nil, err + } + bids, err := k.getAllRewardsBids() + if err != nil { + return nil, err + } + return &auction.GenesisState{ + RewardsParams: k.GetRewardsParams(), + RewardAuctionId: k.currentRewardsAuctionID(), + RewardsAuctions: rewards, + RewardsBids: bids, + }, nil } -func (k Keeper) InitGenesis(*auction.GenesisState) { - // TODO +func (k Keeper) InitGenesis(g *auction.GenesisState) error { + if err := k.SetRewardsParams(&g.RewardsParams, false); err != nil { + return err + } + if err := k.storeAllRewardsAuctions(g.RewardsAuctions); err != nil { + return err + } + if err := k.storeAllRewardsBids(g.RewardsBids); err != nil { + return err + } + store.SetInteger(k.store, keyRewardsCurrentID, g.RewardAuctionId) + + return nil } diff --git a/x/auction/keeper/grpc_query.go b/x/auction/keeper/grpc_query.go index 49c568ec7c..615ecfab5f 100644 --- a/x/auction/keeper/grpc_query.go +++ b/x/auction/keeper/grpc_query.go @@ -29,6 +29,7 @@ func (q Querier) RewardsParams(goCtx context.Context, _ *auction.QueryRewardsPar } // RewardsAuction returns params of the x/auction module. +// Bidder and Bid are nul if there is no active auction. func (q Querier) RewardsAuction(goCtx context.Context, msg *auction.QueryRewardsAuction) ( *auction.QueryRewardsAuctionResponse, error, ) { diff --git a/x/auction/keeper/rewards.go b/x/auction/keeper/rewards.go index eeed12242b..c660be7d5e 100644 --- a/x/auction/keeper/rewards.go +++ b/x/auction/keeper/rewards.go @@ -46,13 +46,13 @@ func (k Keeper) FinalizeRewardsAuction() error { return k.storeNewRewardsAuction(id, endsAt, newCoins) } -func (k Keeper) currentRewardsAuction() uint32 { +func (k Keeper) currentRewardsAuctionID() uint32 { id, _ := store.GetInteger[uint32](k.store, keyRewardsCurrentID) return id } func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { - id := k.currentRewardsAuction() + id := k.currentRewardsAuctionID() if id != msg.Id { return errors.New("bad auction ID, can only bid in the current auction = " + strconv.Itoa(int(id))) } @@ -92,26 +92,76 @@ func (k Keeper) rewardsBid(msg *auction.MsgRewardsBid) error { func (k Keeper) getRewardsBid(id uint32) (*auction.Bid, uint32) { if id == 0 { - id = k.currentRewardsAuction() + id = k.currentRewardsAuctionID() } keyMsg := "auction.rewards.bid" key := k.keyRewardsBid(id) return store.GetValue[*auction.Bid](k.store, key, keyMsg), id } -// returns nil if id is not found +func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) { + elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid]( + k.store, keyPrefixRewardsBid) + if err != nil { + return nil, err + } + bids := make([]auction.BidKV, len(elems)) + for i := range elems { + bids[i].Id = uint32(elems[i].Key) + bids[i].Bid = elems[i].Val + } + return bids, nil + +} + +func (k Keeper) storeAllRewardsBids(elems []auction.BidKV) error { + for _, e := range elems { + key := k.keyRewardsBid(e.Id) + if err := store.SetValue(k.store, key, &e.Bid, "auction.store_all_bids"); err != nil { + return err + } + } + return nil +} + +// Returns collected protocol rewards to auction. +// Returns nil if id is not found. func (k Keeper) getRewardsAuction(id uint32) (*auction.Rewards, uint32) { if id == 0 { - id = k.currentRewardsAuction() + id = k.currentRewardsAuctionID() } const keyMsg = "auction.rewards.coins" key := k.keyRewardsCoins(id) return store.GetValue[*auction.Rewards](k.store, key, keyMsg), id } +func (k Keeper) getAllRewardsAuctions() ([]auction.RewardsKV, error) { + elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Rewards]( + k.store, keyPrefixRewardsCoins) + if err != nil { + return nil, err + } + rewards := make([]auction.RewardsKV, len(elems)) + for i := range elems { + rewards[i].Id = uint32(elems[i].Key) + rewards[i].Rewards = elems[i].Val + } + return rewards, nil +} + func (k Keeper) storeNewRewardsAuction(id uint32, endsAt time.Time, coins sdk.Coins) error { newRewards := auction.Rewards{EndsAt: endsAt, Rewards: coins} const keyMsg = "auction.rewards.coins" key := k.keyRewardsCoins(id) return store.SetValue(k.store, key, &newRewards, keyMsg) } + +func (k Keeper) storeAllRewardsAuctions(elems []auction.RewardsKV) error { + for _, e := range elems { + key := k.keyRewardsCoins(e.Id) + if err := store.SetValue(k.store, key, &e.Rewards, "auction.store_all_rewards"); err != nil { + return err + } + } + return nil +} diff --git a/x/auction/module/module.go b/x/auction/module/module.go index 24cfeaa26e..318d9056c2 100644 --- a/x/auction/module/module.go +++ b/x/auction/module/module.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/umee-network/umee/v6/util" "github.com/umee-network/umee/v6/x/auction" // "github.com/umee-network/umee/v6/x/auction/client/cli" "github.com/umee-network/umee/v6/x/auction/keeper" @@ -140,7 +141,8 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the x/auction module's exported genesis state as raw // JSON bytes. func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := am.kb.Keeper(&ctx).ExportGenesis() + genState, err := am.kb.Keeper(&ctx).ExportGenesis() + util.Panic(err) return cdc.MustMarshalJSON(genState) }