Skip to content

Instantly share code, notes, and snippets.

@fmorency
Created June 19, 2024 15:07
Show Gist options
  • Save fmorency/82eaf8810bc9548eefb80ca47f703999 to your computer and use it in GitHub Desktop.
Save fmorency/82eaf8810bc9548eefb80ca47f703999 to your computer and use it in GitHub Desktop.
Group creation and proposal

Cosmos x/group creation and proposal

Create a new group and a new group policy

  1. Create the following members.json file

    {
      "members": [
        {
          "address": "[ADDR1]",
          "weight": "1",
          "metadata": "some metadata"
        },
        {
          "address": "[ADDRN]",
          "weight": "1",
          "metadata": "some metadata"
        }
      ]
    }

    where [ADDR1]...[ADDRN] are the manifest1... addresses of users to be part of the group.

  2. Create the following policy.json file

    {
        "@type": "/cosmos.group.v1.ThresholdDecisionPolicy",
        "threshold": "1",
        "windows": {
            "voting_period": "30s",
            "min_execution_period": "0s"
        }
    }

    where threshold is the number of approval required for a group proposal to pass.

  3. Create a new group and group policy where the administrator of the group is the group policy itself

    # manifestd tx group create-group-with-policy [admin] [group-metadata] [group-policy-metadata] members.json policy.json
    manifestd tx group create-group-with-policy [ADDR] "" "" members.json policy.json \
        --group-policy-as-admin \
        --from [ADDR] \
        --yes

    where [ADDR] is the address in your keyring to sign the transaction with.

    Note: The --group-policy-as-admin flag will override the [admin] CLI parameter and use the group policy address as the administrator of the group.

  4. Verify the group was created successfully

    manifestd q group groups
    groups:
    - admin: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
      created_at: "2024-06-19T14:17:12.140814909Z"
      id: "1"
      total_weight: "2"
      version: "2"
    pagination:
      total: "1"
  5. Verify the group, group members and policy information

    # Group info
    manifestd q group group-info 1
    info:
      admin: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
      created_at: "2024-06-19T14:17:12.140814909Z"
      id: "1"
      total_weight: "2"
      version: "2"
    
    # Group members info
    manifestd q group group-members 1
    members:
    - group_id: "1"
      member:
        added_at: "2024-06-19T14:17:12.140814909Z"
        address: [ADDR1]
        metadata: some metadata
        weight: "1"
    - group_id: "1"
      member:
        added_at: "2024-06-19T14:17:12.140814909Z"
        address: [ADDRN]
        metadata: some metadata
        weight: "1"
    pagination:
      total: "2"
      
    # Group policy info
    # Notice that the group administrator is set to the policy address
    manifestd q group group-policy-info manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
    info:
      address: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
      admin: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
      created_at: "2024-06-19T14:17:12.140814909Z"
      decision_policy:
        type: cosmos-sdk/ThresholdDecisionPolicy
        value:
          threshold: "1"
          windows:
            min_execution_period: 0s
            voting_period: 30s
      group_id: "1"
      version: "2"

Submit a group proposal

Now that we have a group with some members and some policy, we are able to submit group proposal to be voted on and executed.

  1. Send some tokens to the group policy

    manifestd tx bank send [ADDR] [GROUP_POLICY_ADDR] 100umfx --from [ADDR] --yes

    where [ADDR] is the address you want to send tokens from and [GROUP_POLICY_ADDR] is the group policy address, e.g., manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr.

  2. Create the proposal.json file with the following

    {
        "group_policy_address": "[GROUP_POLICY_ADDR]",
        "messages": [
        {
            "@type": "/cosmos.bank.v1beta1.MsgSend",
            "from_address": "[GROUP_POLICY_ADDR]",
            "to_address": "[TO_ADDR]",
            "amount":[{"denom": "umfx","amount": "10"}]
        }
        ],
        "metadata": "",
        "title": "Send tokens",
        "summary": "This is a proposal to send 10 umfx to [TO_ADDR]",
        "proposers": ["[PROPOSER_ADDR]"]
    }

    where [GROUP_POLICY_ADDR] is the address of the group policy, [TO_ADDR] is the destination address that will recieve the tokens in the event the proposal passes and [PROPOSER_ADDR] is the address of the proposer submitting the proposal.

    Note: The proposer should be a member of the group.

    The metadata field can be any of base64 encoded, raw text, stringified json, IPFS link to json. E.g.

        "metadata": "4pIMOgIGx1vZGU="

    where 4pIMOgIGx1vZGU= is the base64 encoding of

    {
        "title": "",
        "authors": [""],
        "summary": "",
        "details": "", 
        "proposal_forum_url": "",
        "vote_option_context": "",
    } 
  3. Submit the proposal

    manifestd tx group submit-proposal proposal.json --from [ADDR] --yes

    where [ADDR] is the address used to sign the transaction.

    Note: Because we set the voting period to 30s, you will have 30s to vote on the proposal from the time the proposal is submitted. Go go go!

  4. Verify the group proposal is active

    manifestd q group proposals-by-group-policy [GROUP_POLICY_ADDR]
    ## E.g. output
    # pagination:
    #   total: "1"
    # proposals:
    # - executor_result: 1
    #   final_tally_result:
    #     abstain_count: "0"
    #     no_count: "0"
    #     no_with_veto_count: "0"
    #     yes_count: "0"
    #   group_policy_address: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
    #   group_policy_version: "2"
    #   group_version: "2"
    #   id: "1"
    #   messages:
    #   - type: cosmos-sdk/MsgSend
    #     value:
    #       amount:
    #       - amount: "10"
    #         denom: umfx
    #       from_address: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
    #       to_address: manifest1efd63aw40lxf3n4mhf7dzhjkr453axurm6rp3z
    #   proposers:
    #   - manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct
    #   status: 1
    #   submit_time: "2024-06-19T14:43:19.502096377Z"
    #   summary: This is a proposal to send 10 umfx to manifest1efd63aw40lxf3n4mhf7dzhjkr453axurm6rp3z
    #   title: Send tokens
    #   voting_period_end: "2024-06-24T14:43:19.502096377Z"

    where GROUP_POLICY_ADDR is the address of the group policy to list the proposals from.

  5. Vote on the proposal

    manifestd tx group vote [PROPOSAL_ID] [ADDR] VOTE_OPTION_YES ""

    where [PROPOSAL_ID] is the id of the proposal, e.g., 1 in the above example, and [ADDR] is the user address that will sign the transaction.

    Wait for the voting period to end.

    At this point, the proposal should have passed. You can verify the proposal status with

    manifestd q group proposal [PROPOSAL_ID]
    ## E.g. output
    # proposal:
    #   executor_result: 1
    #   final_tally_result:
    #     abstain_count: "0"
    #     no_count: "0"
    #     no_with_veto_count: "0"
    #     yes_count: "1"
    #   group_policy_address: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
    #   group_policy_version: "2"
    #   group_version: "2"
    #   id: "1"
    #   messages:
    #   - type: cosmos-sdk/MsgSend
    #     value:
    #       amount:
    #       - amount: "10"
    #         denom: umfx
    #       from_address: manifest1dlszg2sst9r69my4f84l3mj66zxcf3umcgujys30t84srg95dgvsmxrlcr
    #       to_address: manifest1efd63aw40lxf3n4mhf7dzhjkr453axurm6rp3z
    #   proposers:
    #   - manifest1hj5fveer5cjtn4wd6wstzugjfdxzl0xp8ws9ct
    #   status: 2
    #   submit_time: "2024-06-19T14:58:24.367434891Z"
    #   summary: This is a proposal to send 10 umfx to manifest1efd63aw40lxf3n4mhf7dzhjkr453axurm6rp3z
    #   title: Send tokens
    #   voting_period_end: "2024-06-19T14:58:54.367434891Z"

    where [PROPOSAL_ID] is the id of the proposal.

  6. Execute the proposal

    manifestd tx group exec [PROPOSAL_ID] --from [ADDR] --yes

    where [PROPOSAL_ID] id the id of the proposal and [ADDR] is the address to sign the transaction with.

  7. Verify proposal execution

    manifestd q bank balance [GROUP_POLICY_ADDR] umfx
    balance:
      amount: "90"
      denom: umfx
      
    manifestd q bank balance [TO_ADDR] umfx
    balance:
      amount: "10"
      denom: umfx
      
    manifestd q group proposals-by-group-policy [GROUP_POLICY_ADDR]
    pagination: {}

    where [GROUP_POLICY_ADDR] is the address of the group policy and [TO_ADDR] is the address receiving the tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment