Skip to content

Commit

Permalink
fix: update proto gov v1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 23, 2023
1 parent 6d302c2 commit b0149c1
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 219 deletions.
2 changes: 2 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,8 @@ Params

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `title` | [string](#string) | | the title of the update proposal |
| `description` | [string](#string) | | the description of the proposal |
| `authority` | [string](#string) | | |
| `params` | [Params](#alliance.alliance.Params) | | |

Expand Down
140 changes: 67 additions & 73 deletions proto/alliance/alliance/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,87 @@ package alliance.alliance;

import "alliance/alliance/alliance.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

option go_package = "github.com/terra-money/alliance/x/alliance/types";

message MsgCreateAllianceProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
// Denom of the asset. It could either be a native token or an IBC token
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
// The reward weight specifies the ratio of rewards that will be given to each alliance asset
// It does not need to sum to 1. rate = weight / total_weight
// Native asset is always assumed to have a weight of 1.
string reward_weight = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// A positive take rate is used for liquid staking derivatives. It defines an annualized reward rate that
// will be redirected to the distribution rewards pool
string take_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
option (gogoproto.equal) = false;

string reward_change_rate = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
// Denom of the asset. It could either be a native token or an IBC token
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
// The reward weight specifies the ratio of rewards that will be given to each alliance asset
// It does not need to sum to 1. rate = weight / total_weight
// Native asset is always assumed to have a weight of 1.
string reward_weight = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// A positive take rate is used for liquid staking derivatives. It defines an annualized reward rate that
// will be redirected to the distribution rewards pool
string take_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Duration reward_change_interval = 7 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
string reward_change_rate = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// set a bound of weight range to limit how much reward weights can scale.
RewardWeightRange reward_weight_range = 8 [
(gogoproto.nullable) = false
];
google.protobuf.Duration reward_change_interval = 7 [
(gogoproto.nullable) = false,
(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 MsgUpdateAllianceProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
// Denom of the asset. It could either be a native token or an IBC token
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
// The reward weight specifies the ratio of rewards that will be given to each alliance asset
// It does not need to sum to 1. rate = weight / total_weight
// Native asset is always assumed to have a weight of 1.
string reward_weight = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
message MsgUpdateAllianceProposal {
option (gogoproto.equal) = false;

string take_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
// Denom of the asset. It could either be a native token or an IBC token
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
// The reward weight specifies the ratio of rewards that will be given to each alliance asset
// It does not need to sum to 1. rate = weight / total_weight
// Native asset is always assumed to have a weight of 1.
string reward_weight = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string reward_change_rate = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string take_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Duration reward_change_interval = 7 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
string reward_change_rate = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Duration reward_change_interval = 7 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
}

message MsgDeleteAllianceProposal {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
}

option (gogoproto.equal) = false;

// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
}
8 changes: 6 additions & 2 deletions proto/alliance/alliance/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ message MsgClaimDelegationRewardsResponse {}

message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Params params = 2 [(gogoproto.nullable) = false];
string authority = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
Params params = 4 [(gogoproto.nullable) = false];
}

message MsgUpdateParamsResponse {}
Expand Down
68 changes: 50 additions & 18 deletions x/alliance/types/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,71 @@ package types
import (
"time"

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

const (
ProposalTypeCreateAlliance = "msg_create_alliance_proposal"
ProposalTypeUpdateAlliance = "msg_update_alliance_proposal"
ProposalTypeDeleteAlliance = "msg_delete_alliance_proposal"
ProposalTypeUpdateAllianceParams = "msg_update_alliance_params"
ProposalTypeCreateAlliance = "msg_create_alliance_proposal"
ProposalTypeUpdateAlliance = "msg_update_alliance_proposal"
ProposalTypeDeleteAlliance = "msg_delete_alliance_proposal"
)

var (
_ govtypes.Content = &MsgUpdateParams{}
_ govtypes.Content = &MsgCreateAllianceProposal{}
_ govtypes.Content = &MsgUpdateAllianceProposal{}
_ govtypes.Content = &MsgDeleteAllianceProposal{}
)

func init() {
govtypes.RegisterProposalType(ProposalTypeUpdateAllianceParams)
govtypes.RegisterProposalType(ProposalTypeCreateAlliance)
govtypes.RegisterProposalType(ProposalTypeUpdateAlliance)
govtypes.RegisterProposalType(ProposalTypeDeleteAlliance)
}

func NewMsgUpdateParams(title, description string,
rewardDelayTime, takeRateClaimInterval time.Duration,
lastTakeRateClaimTime time.Time) govtypes.Content {

Check failure on line 36 in x/alliance/types/gov.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
return &MsgUpdateParams{
Title: title,
Description: description,
Params: Params{
RewardDelayTime: rewardDelayTime,
TakeRateClaimInterval: takeRateClaimInterval,
LastTakeRateClaimTime: lastTakeRateClaimTime,
},
}
}

Check failure on line 46 in x/alliance/types/gov.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
func (msg *MsgUpdateParams) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return sdkerrors.Wrap(err, "invalid authority address")
}
if err := ValidatePositiveDuration(msg.Params.RewardDelayTime); err != nil {
return err
}
return ValidatePositiveDuration(msg.Params.TakeRateClaimInterval)
}

func (msg MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Authority)
if err != nil {
panic("Authority is not valid")
}
return []sdk.AccAddress{signer}
}
func (m *MsgUpdateParams) ProposalRoute() string { return RouterKey }

Check warning on line 68 in x/alliance/types/gov.go

View workflow job for this annotation

GitHub Actions / lint

receiver-naming: receiver name m should be consistent with previous receiver name msg for MsgUpdateParams (revive)
func (m *MsgUpdateParams) ProposalType() string { return ProposalTypeCreateAlliance }

Check warning on line 69 in x/alliance/types/gov.go

View workflow job for this annotation

GitHub Actions / lint

receiver-naming: receiver name m should be consistent with previous receiver name msg for MsgUpdateParams (revive)

func NewMsgCreateAllianceProposal(title, description, denom string, rewardWeight sdk.Dec, rewardWeightRange RewardWeightRange, takeRate sdk.Dec, rewardChangeRate sdk.Dec, rewardChangeInterval time.Duration) govtypes.Content {
return &MsgCreateAllianceProposal{
Title: title,
Expand All @@ -39,11 +80,8 @@ func NewMsgCreateAllianceProposal(title, description, denom string, rewardWeight
RewardChangeInterval: rewardChangeInterval,
}
}
func (m *MsgCreateAllianceProposal) GetTitle() string { return m.Title }
func (m *MsgCreateAllianceProposal) GetDescription() string { return m.Description }
func (m *MsgCreateAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgCreateAllianceProposal) ProposalType() string { return ProposalTypeCreateAlliance }

func (m *MsgCreateAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgCreateAllianceProposal) ProposalType() string { return ProposalTypeCreateAlliance }
func (m *MsgCreateAllianceProposal) ValidateBasic() error {
if m.Denom == "" {
return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value")
Expand Down Expand Up @@ -96,11 +134,8 @@ func NewMsgUpdateAllianceProposal(title, description, denom string, rewardWeight
RewardChangeInterval: rewardChangeInterval,
}
}
func (m *MsgUpdateAllianceProposal) GetTitle() string { return m.Title }
func (m *MsgUpdateAllianceProposal) GetDescription() string { return m.Description }
func (m *MsgUpdateAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgUpdateAllianceProposal) ProposalType() string { return ProposalTypeUpdateAlliance }

func (m *MsgUpdateAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgUpdateAllianceProposal) ProposalType() string { return ProposalTypeUpdateAlliance }
func (m *MsgUpdateAllianceProposal) ValidateBasic() error {
if m.Denom == "" {
return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value")
Expand Down Expand Up @@ -132,11 +167,8 @@ func NewMsgDeleteAllianceProposal(title, description, denom string) govtypes.Con
Denom: denom,
}
}
func (m *MsgDeleteAllianceProposal) GetTitle() string { return m.Title }
func (m *MsgDeleteAllianceProposal) GetDescription() string { return m.Description }
func (m *MsgDeleteAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgDeleteAllianceProposal) ProposalType() string { return ProposalTypeDeleteAlliance }

func (m *MsgDeleteAllianceProposal) ProposalRoute() string { return RouterKey }
func (m *MsgDeleteAllianceProposal) ProposalType() string { return ProposalTypeDeleteAlliance }
func (m *MsgDeleteAllianceProposal) ValidateBasic() error {
if m.Denom == "" {
return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value")
Expand Down
Loading

0 comments on commit b0149c1

Please sign in to comment.