Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update proto gov v1 compatibility #271

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 @@
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
Loading