Skip to content

Commit

Permalink
add proposal for set execution fees
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragpg committed Mar 7, 2024
1 parent 719d955 commit d1d5f00
Show file tree
Hide file tree
Showing 12 changed files with 786 additions and 205 deletions.
127 changes: 127 additions & 0 deletions app/ante/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func NewInitApp(
customgov.NewApplySetPoorNetworkMessagesProposalHandler(app.CustomGovKeeper),
customgov.NewApplyResetWholeCouncilorRankProposalHandler(app.CustomGovKeeper),
customgov.NewApplyJailCouncilorProposalHandler(app.CustomGovKeeper),
customgov.NewApplySetExecutionFeesProposalHandler(app.CustomGovKeeper),
tokens.NewApplyUpsertTokenAliasProposalHandler(app.TokensKeeper),
tokens.NewApplyUpsertTokenRatesProposalHandler(app.TokensKeeper),
tokens.NewApplyWhiteBlackChangeProposalHandler(app.TokensKeeper),
Expand Down
6 changes: 6 additions & 0 deletions proto/kira/gov/permission.proto
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,10 @@ enum PermValue {

// PERMISSION_CREATE_DAPP_PROPOSAL_WITHOUT_BOND defines the permission needed to create a dapp proposal without bond
PERMISSION_CREATE_DAPP_PROPOSAL_WITHOUT_BOND = 67 [(gogoproto.enumvalue_customname) = "PermCreateDappProposalWithoutBond"];

// PERMISSION_CREATE_SET_EXECUTION_FEES_PROPOSAL defines the permission needed to create a proposal to set execution fees
PERMISSION_CREATE_SET_EXECUTION_FEES_PROPOSAL = 68 [(gogoproto.enumvalue_customname) = "PermCreateSetExecutionFeesProposal"];

// PERMISSION_VOTE_SET_EXECUTION_FEES_PROPOSAL defines the permission needed to vote on set execution fees proposal
PERMISSION_VOTE_SET_EXECUTION_FEES_PROPOSAL = 69 [(gogoproto.enumvalue_customname) = "PermVoteSetExecutionFeesProposal"];
}
9 changes: 9 additions & 0 deletions proto/kira/gov/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "google/protobuf/any.proto";
import "cosmos_proto/cosmos.proto";
import "kira/gov/role.proto";
import "kira/gov/permission.proto";
import "kira/gov/execution_fee.proto";
import "kira/gov/network_properties.proto";

option go_package = "github.com/KiraCore/sekai/x/gov/types";
Expand Down Expand Up @@ -252,4 +253,12 @@ message ProposalJailCouncilor {
];
string description = 2;
repeated string councilors = 3;
}

message ProposalSetExecutionFees {
bytes proposer = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
];
string description = 2;
repeated ExecutionFee execution_fees = 3 [ (gogoproto.nullable) = false ];
}
12 changes: 12 additions & 0 deletions scripts/sekai-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ PermCreateJailCouncilorProposal=64
# permission needed to vote on jail councilors proposal
PermVoteJailCouncilorProposal=65

# permission needed to create a poll proposal
PermCreatePollProposal=66

# permission needed to create a dapp proposal without bond
PermCreateDappProposalWithoutBond=67

# permission needed to create a proposal to set execution fees
PermCreateSetExecutionFeesProposal=68

# permission needed to vote on set execution fees proposal
PermVoteSetExecutionFeesProposal=69

###################################### transaction_types ######################################
TypeMsgSend="send"
TypeMsgMultiSend="multisend"
Expand Down
1 change: 1 addition & 0 deletions types/Proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
ProposalTypeRemoveUBI = "RemoveUBI"
ProposalTypeResetWholeCouncilorRank = "ResetWholeCouncilorRank"
ProposalTypeJailCouncilor = "JailCouncilor"
ProposalTypeSetExecutionFees = "SetExecutionFees"
ProposalTypeWhitelistAccountPermission = "WhitelistAccountPermission"
ProposalTypeBlacklistAccountPermission = "BlacklistAccountPermission"
ProposalTypeRemoveWhitelistedAccountPermission = "RemoveWhitelistedAccountPermission"
Expand Down
78 changes: 78 additions & 0 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func NewTxProposalCmds() *cobra.Command {
proposalCmd.AddCommand(GetTxProposalSetProposalDurations())
proposalCmd.AddCommand(GetTxProposalResetWholeCouncilorRankCmd())
proposalCmd.AddCommand(GetTxProposalJailCouncilorCmd())
proposalCmd.AddCommand(GetTxProposalSetExecutionFeesCmd())

proposalCmd.AddCommand(accountProposalCmd)
proposalCmd.AddCommand(roleProposalCmd)
Expand Down Expand Up @@ -2314,6 +2315,83 @@ func GetTxProposalJailCouncilorCmd() *cobra.Command {
return cmd
}

// GetTxProposalSetExecutionFeesCmd implement cli command for ProposalSetExecutionFees
func GetTxProposalSetExecutionFeesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "proposal-set-execution-fees [txTypes] [executionFees] [failureFees] [timeouts] [defaultParams]",
Short: "Create a proposal to set execution fees",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
title, err := cmd.Flags().GetString(FlagTitle)
if err != nil {
return fmt.Errorf("invalid title: %w", err)
}
description, err := cmd.Flags().GetString(FlagDescription)
if err != nil {
return fmt.Errorf("invalid description: %w", err)
}

txTypes := strings.Split(args[0], ",")
execFeeStrs := strings.Split(args[1], ",")
failureFeeStrs := strings.Split(args[2], ",")
timeoutStrs := strings.Split(args[3], ",")
defaultParamStrs := strings.Split(args[3], ",")
executionFees := []types.ExecutionFee{}
for i, txType := range txTypes {
execFee, err := strconv.Atoi(execFeeStrs[i])
if err != nil {
return err
}
failureFee, err := strconv.Atoi(failureFeeStrs[i])
if err != nil {
return err
}
timeout, err := strconv.Atoi(timeoutStrs[i])
if err != nil {
return err
}
defaultParams, err := strconv.Atoi(defaultParamStrs[i])
if err != nil {
return err
}
executionFees = append(executionFees, types.ExecutionFee{
TransactionType: txType,
ExecutionFee: uint64(execFee),
FailureFee: uint64(failureFee),
Timeout: uint64(timeout),
DefaultParameters: uint64(defaultParams),
})
}

msg, err := types.NewMsgSubmitProposal(
clientCtx.FromAddress,
title,
description,
types.NewSetExecutionFeesProposal(clientCtx.FromAddress, description, executionFees),
)
if err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().String(FlagTitle, "", "The title of the proposal.")
cmd.MarkFlagRequired(FlagTitle)
cmd.Flags().String(FlagDescription, "", "The description of the proposal, it can be a url, some text, etc.")
cmd.MarkFlagRequired(FlagDescription)

flags.AddTxFlagsToCmd(cmd)
_ = cmd.MarkFlagRequired(flags.FlagFrom)

return cmd
}

// convertAsPermValues convert array of int32 to PermValue array.
func convertAsPermValues(values []int32) []types.PermValue {
var v []types.PermValue
Expand Down
22 changes: 22 additions & 0 deletions x/gov/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,25 @@ func (a ApplyJailCouncilorProposalHandler) Apply(ctx sdk.Context, proposalID uin
}
return nil
}

type ApplySetExecutionFeesHandler struct {
keeper keeper.Keeper
}

func NewApplySetExecutionFeesProposalHandler(keeper keeper.Keeper) *ApplySetExecutionFeesHandler {
return &ApplySetExecutionFeesHandler{
keeper: keeper,
}
}

func (a ApplySetExecutionFeesHandler) ProposalType() string {
return kiratypes.ProposalTypeSetExecutionFees
}

func (a ApplySetExecutionFeesHandler) Apply(ctx sdk.Context, proposalID uint64, proposal types.Content, slash sdk.Dec) error {
p := proposal.(*types.ProposalSetExecutionFees)
for _, executionFee := range p.ExecutionFees {
a.keeper.SetExecutionFee(ctx, executionFee)
}
return nil
}
1 change: 1 addition & 0 deletions x/gov/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&SetProposalDurationsProposal{},
&ProposalResetWholeCouncilorRank{},
&ProposalJailCouncilor{},
&ProposalSetExecutionFees{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
Loading

0 comments on commit d1d5f00

Please sign in to comment.