From 50604218d3c2fc6e8870a5a38e8a7de33e9b71bd Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Fri, 10 Nov 2023 01:24:04 +0800 Subject: [PATCH 1/2] feat: allow updating of weight range --- docs/proto/proto-docs.md | 1 + proto/alliance/gov.proto | 4 + x/alliance/client/cli/gov.go | 16 +++- x/alliance/keeper/asset.go | 1 + x/alliance/keeper/proposal.go | 1 + x/alliance/keeper/tests/proposal_test.go | 16 ++-- x/alliance/types/gov.go | 16 +++- x/alliance/types/gov.pb.go | 116 ++++++++++++++++------- x/alliance/types/tests/types_test.go | 4 +- 9 files changed, 130 insertions(+), 45 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 77186898..49a87fc2 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -573,6 +573,7 @@ GenesisState defines the module's genesis state. | `take_rate` | [string](#string) | | | | `reward_change_rate` | [string](#string) | | | | `reward_change_interval` | [google.protobuf.Duration](#google.protobuf.Duration) | | | +| `reward_weight_range` | [RewardWeightRange](#alliance.alliance.RewardWeightRange) | | set a bound of weight range to limit how much reward weights can scale. | diff --git a/proto/alliance/gov.proto b/proto/alliance/gov.proto index 6b0668d8..e219b34e 100644 --- a/proto/alliance/gov.proto +++ b/proto/alliance/gov.proto @@ -80,6 +80,10 @@ message MsgUpdateAllianceProposal { (gogoproto.stdduration) = true ]; + // set a bound of weight range to limit how much reward weights can scale. + RewardWeightRange reward_weight_range = 8 [ + (gogoproto.nullable) = false + ]; } message MsgDeleteAllianceProposal { diff --git a/x/alliance/client/cli/gov.go b/x/alliance/client/cli/gov.go index 80481428..6b220897 100644 --- a/x/alliance/client/cli/gov.go +++ b/x/alliance/client/cli/gov.go @@ -118,7 +118,7 @@ func CreateAlliance() *cobra.Command { func UpdateAlliance() *cobra.Command { cmd := &cobra.Command{ - Use: "update-alliance denom reward-weight take-rate reward-change-rate reward-change-interval", + Use: "update-alliance denom reward-weight reward-weight-min reward-weight-max take-rate reward-change-rate reward-change-interval", Args: cobra.ExactArgs(5), Short: "Update an alliance with the specified parameters", RunE: func(cmd *cobra.Command, args []string) error { @@ -143,6 +143,16 @@ func UpdateAlliance() *cobra.Command { return err } + rewardWeightMin, err := sdk.NewDecFromStr(args[2]) + if err != nil { + return err + } + + rewardWeightMax, err := sdk.NewDecFromStr(args[3]) + if err != nil { + return err + } + takeRate, err := sdk.NewDecFromStr(args[2]) if err != nil { return err @@ -175,6 +185,10 @@ func UpdateAlliance() *cobra.Command { description, denom, rewardWeight, + types.RewardWeightRange{ + Min: rewardWeightMin, + Max: rewardWeightMax, + }, takeRate, rewardChangeRate, rewardChangeInterval, diff --git a/x/alliance/keeper/asset.go b/x/alliance/keeper/asset.go index 04bf8cfb..9358ecfb 100644 --- a/x/alliance/keeper/asset.go +++ b/x/alliance/keeper/asset.go @@ -83,6 +83,7 @@ func (k Keeper) UpdateAllianceAsset(ctx sdk.Context, newAsset types.AllianceAsse asset.RewardChangeRate = newAsset.RewardChangeRate asset.RewardChangeInterval = newAsset.RewardChangeInterval asset.LastRewardChangeTime = newAsset.LastRewardChangeTime + asset.RewardWeightRange = newAsset.RewardWeightRange k.SetAsset(ctx, asset) return nil diff --git a/x/alliance/keeper/proposal.go b/x/alliance/keeper/proposal.go index 9c35bf7c..570a1528 100644 --- a/x/alliance/keeper/proposal.go +++ b/x/alliance/keeper/proposal.go @@ -42,6 +42,7 @@ func (k Keeper) UpdateAlliance(ctx context.Context, req *types.MsgUpdateAlliance if !found { return status.Errorf(codes.NotFound, "Asset with denom: %s does not exist", req.Denom) } + asset.RewardWeightRange = req.RewardWeightRange if asset.RewardWeightRange.Min.GT(req.RewardWeight) || asset.RewardWeightRange.Max.LT(req.RewardWeight) { return types.ErrRewardWeightOutOfBound } diff --git a/x/alliance/keeper/tests/proposal_test.go b/x/alliance/keeper/tests/proposal_test.go index 8cfddc38..c29e0b3b 100644 --- a/x/alliance/keeper/tests/proposal_test.go +++ b/x/alliance/keeper/tests/proposal_test.go @@ -103,10 +103,14 @@ func TestUpdateAlliance(t *testing.T) { // WHEN updateErr := app.AllianceKeeper.UpdateAlliance(ctx, &types.MsgUpdateAllianceProposal{ - Title: "", - Description: "", - Denom: "uluna", - RewardWeight: sdk.NewDec(6), + Title: "", + Description: "", + Denom: "uluna", + RewardWeight: sdk.NewDec(11), + RewardWeightRange: types.RewardWeightRange{ + Min: sdk.NewDec(0), + Max: sdk.NewDec(11), + }, TakeRate: sdk.NewDec(7), RewardChangeInterval: 0, RewardChangeRate: sdk.ZeroDec(), @@ -120,8 +124,8 @@ func TestUpdateAlliance(t *testing.T) { Alliances: []types.AllianceAsset{ { Denom: "uluna", - RewardWeight: sdk.NewDec(6), - RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(10)}, + RewardWeight: sdk.NewDec(11), + RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(11)}, TakeRate: sdk.NewDec(7), TotalTokens: sdk.ZeroInt(), TotalValidatorShares: sdk.NewDec(0), diff --git a/x/alliance/types/gov.go b/x/alliance/types/gov.go index 1f87dc94..18387845 100644 --- a/x/alliance/types/gov.go +++ b/x/alliance/types/gov.go @@ -85,7 +85,7 @@ func (m *MsgCreateAllianceProposal) ValidateBasic() error { return nil } -func NewMsgUpdateAllianceProposal(title, description, denom string, rewardWeight, takeRate sdk.Dec, rewardChangeRate sdk.Dec, rewardChangeInterval time.Duration) govtypes.Content { +func NewMsgUpdateAllianceProposal(title, description, denom string, rewardWeight sdk.Dec, rewardWeightRange RewardWeightRange, takeRate sdk.Dec, rewardChangeRate sdk.Dec, rewardChangeInterval time.Duration) govtypes.Content { return &MsgUpdateAllianceProposal{ Title: title, Description: description, @@ -94,6 +94,7 @@ func NewMsgUpdateAllianceProposal(title, description, denom string, rewardWeight TakeRate: takeRate, RewardChangeRate: rewardChangeRate, RewardChangeInterval: rewardChangeInterval, + RewardWeightRange: rewardWeightRange, } } func (m *MsgUpdateAllianceProposal) GetTitle() string { return m.Title } @@ -122,6 +123,19 @@ func (m *MsgUpdateAllianceProposal) ValidateBasic() error { return status.Errorf(codes.InvalidArgument, "Alliance rewardChangeInterval must be strictly a positive number") } + if m.RewardWeightRange.Min.IsNil() || m.RewardWeightRange.Min.LT(sdk.ZeroDec()) || + m.RewardWeightRange.Max.IsNil() || m.RewardWeightRange.Max.LT(sdk.ZeroDec()) { + return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight min and max must be zero or a positive number") + } + + if m.RewardWeightRange.Min.GT(m.RewardWeightRange.Max) { + return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight min must be less or equal to rewardWeight max") + } + + if m.RewardWeight.LT(m.RewardWeightRange.Min) || m.RewardWeight.GT(m.RewardWeightRange.Max) { + return status.Errorf(codes.InvalidArgument, "Alliance rewardWeight must be bounded in RewardWeightRange") + } + return nil } diff --git a/x/alliance/types/gov.pb.go b/x/alliance/types/gov.pb.go index ee9afc9f..fc86701c 100644 --- a/x/alliance/types/gov.pb.go +++ b/x/alliance/types/gov.pb.go @@ -95,6 +95,8 @@ type MsgUpdateAllianceProposal struct { TakeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=take_rate,json=takeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"take_rate"` RewardChangeRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=reward_change_rate,json=rewardChangeRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_change_rate"` RewardChangeInterval time.Duration `protobuf:"bytes,7,opt,name=reward_change_interval,json=rewardChangeInterval,proto3,stdduration" json:"reward_change_interval"` + // set a bound of weight range to limit how much reward weights can scale. + RewardWeightRange RewardWeightRange `protobuf:"bytes,8,opt,name=reward_weight_range,json=rewardWeightRange,proto3" json:"reward_weight_range"` } func (m *MsgUpdateAllianceProposal) Reset() { *m = MsgUpdateAllianceProposal{} } @@ -180,38 +182,37 @@ func init() { func init() { proto.RegisterFile("alliance/gov.proto", fileDescriptor_5518a6f5c90c8452) } var fileDescriptor_5518a6f5c90c8452 = []byte{ - // 481 bytes of a gzipped FileDescriptorProto + // 478 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x94, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x6d, 0x9a, 0x94, 0xf4, 0x5a, 0xa4, 0xf6, 0x88, 0xc0, 0xed, 0x60, 0x47, 0x11, 0xaa, - 0xba, 0xf4, 0x8c, 0x60, 0xeb, 0x86, 0x9b, 0x05, 0x10, 0x12, 0x32, 0x42, 0x88, 0x0a, 0x29, 0xba, + 0x14, 0xc7, 0x6d, 0x48, 0x4a, 0x7a, 0x2d, 0x52, 0x7b, 0x44, 0xe0, 0x76, 0xb0, 0xa3, 0x08, 0x55, + 0x5d, 0x7a, 0x46, 0xb0, 0x75, 0x23, 0xcd, 0x02, 0x08, 0x09, 0x1d, 0x42, 0x88, 0x0a, 0x29, 0xba, 0xd8, 0x8f, 0x8b, 0xd5, 0xb3, 0xcf, 0x3a, 0x5f, 0x5a, 0xf2, 0x01, 0x90, 0x18, 0x19, 0x19, 0xfb, - 0x41, 0xf8, 0x00, 0x1d, 0x3b, 0x22, 0x86, 0x50, 0x25, 0x0b, 0x33, 0x9f, 0x00, 0xdd, 0xd9, 0x49, - 0x5d, 0xd8, 0x32, 0x30, 0xa0, 0x4e, 0x7e, 0xf7, 0xfe, 0x4f, 0xbf, 0x3b, 0xfd, 0xff, 0x4f, 0x46, - 0x98, 0x72, 0x9e, 0xd0, 0x2c, 0x02, 0x9f, 0x89, 0x13, 0x92, 0x4b, 0xa1, 0x04, 0xde, 0x9a, 0xf7, - 0xc8, 0xbc, 0xd8, 0xb9, 0xbf, 0x18, 0x5b, 0x68, 0x66, 0x76, 0xa7, 0xcd, 0x04, 0x13, 0xa6, 0xf4, - 0x75, 0x55, 0x75, 0x5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, 0x1c, 0x0d, 0x4a, 0xb1, 0xbd, 0x54, + 0x66, 0x30, 0x59, 0xfe, 0x7c, 0xc3, 0xf7, 0x17, 0xa5, 0xb5, 0x6a, 0xb8, 0x62, 0x97, 0xfd, 0xe8, + 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x92, 0xda, 0xbf, 0x14, 0xd0, 0x05, 0x00, 0x00, } func (m *MsgCreateAllianceProposal) Marshal() (dAtA []byte, err error) { @@ -326,12 +327,22 @@ func (m *MsgUpdateAllianceProposal) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l - n3, err3 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.RewardChangeInterval, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.RewardChangeInterval):]) - if err3 != nil { - return 0, err3 + { + size, err := m.RewardWeightRange.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + n4, err4 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.RewardChangeInterval, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.RewardChangeInterval):]) + if err4 != nil { + return 0, err4 } - i -= n3 - i = encodeVarintGov(dAtA, i, uint64(n3)) + i -= n4 + i = encodeVarintGov(dAtA, i, uint64(n4)) i-- dAtA[i] = 0x3a { @@ -500,6 +511,8 @@ func (m *MsgUpdateAllianceProposal) Size() (n int) { n += 1 + l + sovGov(uint64(l)) l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.RewardChangeInterval) n += 1 + l + sovGov(uint64(l)) + l = m.RewardWeightRange.Size() + n += 1 + l + sovGov(uint64(l)) return n } @@ -1104,6 +1117,39 @@ func (m *MsgUpdateAllianceProposal) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardWeightRange", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RewardWeightRange.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGov(dAtA[iNdEx:]) diff --git a/x/alliance/types/tests/types_test.go b/x/alliance/types/tests/types_test.go index 03281623..e1266124 100644 --- a/x/alliance/types/tests/types_test.go +++ b/x/alliance/types/tests/types_test.go @@ -62,7 +62,7 @@ func TestProposalsContent(t *testing.T) { str: "title:\"Alliance1\" description:\"Alliance with 1\" denom:\"ibc/denom1\" reward_weight:\"1000000000000000000\" take_rate:\"1000000000000000000\" reward_change_rate:\"1000000000000000000\" reward_change_interval: reward_weight_range: ", }, "msg_update_alliance_proposal": { - p: types.NewMsgUpdateAllianceProposal("Alliance2", "Alliance with 2", "ibc/denom2", sdk.NewDec(2), sdk.NewDec(2), sdk.NewDec(2), time.Hour), + p: types.NewMsgUpdateAllianceProposal("Alliance2", "Alliance with 2", "ibc/denom2", sdk.NewDec(2), types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(5)}, sdk.NewDec(2), sdk.NewDec(2), time.Hour), title: "Alliance2", desc: "Alliance with 2", typ: "msg_update_alliance_proposal", @@ -130,7 +130,7 @@ func TestInvalidProposalsContent(t *testing.T) { typ: "msg_create_alliance_proposal", }, "msg_update_alliance_proposal": { - p: types.NewMsgUpdateAllianceProposal("Alliance2", "Alliance with 2", "ibc/denom2", sdk.NewDec(2), sdk.NewDec(2), sdk.NewDec(2), -time.Hour), + p: types.NewMsgUpdateAllianceProposal("Alliance2", "Alliance with 2", "ibc/denom2", sdk.NewDec(2), types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(5)}, sdk.NewDec(2), sdk.NewDec(2), -time.Hour), title: "Alliance2", desc: "Alliance with 2", typ: "msg_update_alliance_proposal", From 9b41d8702179f2af99270f5ad8eb3c6e9446fb7b Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Fri, 10 Nov 2023 10:31:09 +0800 Subject: [PATCH 2/2] fix: test --- x/alliance/keeper/proposal.go | 1 + x/alliance/keeper/tests/asset_test.go | 4 ++++ x/alliance/types/tests/types_test.go | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/x/alliance/keeper/proposal.go b/x/alliance/keeper/proposal.go index 570a1528..bc665987 100644 --- a/x/alliance/keeper/proposal.go +++ b/x/alliance/keeper/proposal.go @@ -42,6 +42,7 @@ func (k Keeper) UpdateAlliance(ctx context.Context, req *types.MsgUpdateAlliance if !found { return status.Errorf(codes.NotFound, "Asset with denom: %s does not exist", req.Denom) } + asset.RewardWeightRange = req.RewardWeightRange if asset.RewardWeightRange.Min.GT(req.RewardWeight) || asset.RewardWeightRange.Max.LT(req.RewardWeight) { return types.ErrRewardWeightOutOfBound diff --git a/x/alliance/keeper/tests/asset_test.go b/x/alliance/keeper/tests/asset_test.go index 02d8a691..936ba9bc 100644 --- a/x/alliance/keeper/tests/asset_test.go +++ b/x/alliance/keeper/tests/asset_test.go @@ -740,6 +740,7 @@ func TestRewardWeightDecay(t *testing.T) { Description: "", Denom: AllianceDenom, RewardWeight: sdk.MustNewDecFromStr("0.5"), + RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(5)}, TakeRate: sdk.ZeroDec(), RewardChangeRate: sdk.ZeroDec(), RewardChangeInterval: 0, @@ -752,6 +753,7 @@ func TestRewardWeightDecay(t *testing.T) { Description: "", Denom: AllianceDenom, RewardWeight: sdk.MustNewDecFromStr("0.5"), + RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(5)}, TakeRate: sdk.ZeroDec(), RewardChangeRate: sdk.MustNewDecFromStr("0.1"), RewardChangeInterval: decayInterval, @@ -778,6 +780,7 @@ func TestRewardWeightDecay(t *testing.T) { Description: "", Denom: AllianceDenomTwo, RewardWeight: sdk.MustNewDecFromStr("0.5"), + RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(5)}, TakeRate: sdk.ZeroDec(), RewardChangeRate: sdk.MustNewDecFromStr("0.1"), RewardChangeInterval: decayInterval, @@ -1112,6 +1115,7 @@ func TestRewardWeightRateChange(t *testing.T) { Description: "", Denom: alliance.Denom, RewardWeight: alliance.RewardWeight, + RewardWeightRange: types.RewardWeightRange{Min: sdk.NewDec(0), Max: sdk.NewDec(5)}, TakeRate: alliance.TakeRate, RewardChangeRate: sdk.MustNewDecFromStr("1.001"), RewardChangeInterval: time.Minute * 5, diff --git a/x/alliance/types/tests/types_test.go b/x/alliance/types/tests/types_test.go index e1266124..42943b05 100644 --- a/x/alliance/types/tests/types_test.go +++ b/x/alliance/types/tests/types_test.go @@ -66,7 +66,7 @@ func TestProposalsContent(t *testing.T) { title: "Alliance2", desc: "Alliance with 2", typ: "msg_update_alliance_proposal", - str: "title:\"Alliance2\" description:\"Alliance with 2\" denom:\"ibc/denom2\" reward_weight:\"2000000000000000000\" take_rate:\"2000000000000000000\" reward_change_rate:\"2000000000000000000\" reward_change_interval: ", + str: "title:\"Alliance2\" description:\"Alliance with 2\" denom:\"ibc/denom2\" reward_weight:\"2000000000000000000\" take_rate:\"2000000000000000000\" reward_change_rate:\"2000000000000000000\" reward_change_interval: reward_weight_range: ", }, "msg_delete_alliance_proposal": { p: types.NewMsgDeleteAllianceProposal("test", "abcd", "ibc/denom"),