neutron-org / neutron

Smart Contract platform secured by Cosmos Hub
https://neutron.org
Apache License 2.0
106 stars 83 forks source link

Better CLI UX for governance #223

Open oldremez opened 1 year ago

oldremez commented 1 year ago

Neutron DAO is based on CosmWasm contracts but still is the core part of Neutron chain. This means two things:

  1. There's no CLI support for governance operations.
  2. Regardless of being the part of neutrond binary, DAO contracts are a crucial part of Neutron, and having support for them in neutrond binary is a good thing.

The current process of making a proposal, voting for it, and executing it looks something like that:

neutrond tx wasm execute neutron1hulx7cgvpfcvg83wk5h96sedqgn72n026w6nl47uht554xhvj9nsgs8v0z '{
   "propose":{
      "msg":{
         "propose":{
            "title": "Proposal title",
            "description": "Proposal description",
            "msgs":[
               {
                   ...
                }
            ]
         }
      }
   }
}'

neutrond tx wasm execute neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh \
    '{"vote":{"proposal_id": 1, "vote":"yes"}}'

neutrond tx wasm execute neutron1436kxs0w2es6xlqpp9rd35e3d0cjnw4sv8j3a7483sgks29jqwgshlt6zh \
    '{"execute":{"proposal_id": 1}}'

The user here has to work with obscure addresses of specific contracts which should not be messed up, and also hast to manually craft the jsons for messages for any action. What would be great to have instead is something like that:

neutrond tx neutron-dao propose single-choice --title "Proposal title" --description  "Proposal description" --msgs '[
   {
       ...
    }
]'

neutrond tx neutron-dao vote single-choice 1 yes
neutrond tx neutron-dao execute single-choice 1

The same for queries, etc., etc.

It will require the following:

  1. The code that gets the set of Neutron contracts based on the admin module (the chain admin is Neutron DAO core, all the other contracts can be queried from the core; we already have the code that solves it in the tests (the getDaoContracts function))
  2. The interface code that will transform all human-readable commands to wasm messages to the corresponding contracts.
EskandarAtrakchi commented 6 months ago
// This is only a try 
// neutron-dao module
func ProposeCommand(cliCtx context.CLIContext, title, description string, msgs []Msg) (sdk.TxResponse, error) {
    // Transform user-friendly inputs to wasm messages
    proposeMsg := NewMsgPropose(title, description, msgs)

    // Construct and broadcast the transaction
    return utils.BuildAndBroadcast(cliCtx, []sdk.Msg{proposeMsg})
}

// CLI command registration
var (
    CmdPropose = &cobra.Command{
        Use:   "propose",
        Short: "Propose a governance action",
        RunE: func(cmd *cobra.Command, args []string) error {
            title, _ := cmd.Flags().GetString("title")
            description, _ := cmd.Flags().GetString("description")
            msgs, _ := cmd.Flags().GetString("msgs")

            cliCtx := context.NewCLIContext().WithCodec(appCodec)
            response, err := neutronDao.ProposeCommand(cliCtx, title, description, msgs)
            // Handle response and error
        },
    }
)

// Add flags to the propose command
func init() {
    CmdPropose.Flags().String("title", "", "Proposal title")
    CmdPropose.Flags().String("description", "", "Proposal description")
    CmdPropose.Flags().String("msgs", "", "JSON array of messages")
    // Add other necessary flags here 
    // hmm... My code could be mess and wrong, but that what I came up with after taking a look at some of the files
}