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

epoching: CLI for delegating/undelegating/redelegating requests #138

Merged
merged 8 commits into from
Sep 15, 2022

Conversation

SebastianElvis
Copy link
Member

Fixes BM-172

This PR introduces CLI for submitting delegation/undelegation/redelegation requests from CLI. The code is almost identical to their counterparts in https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/x/staking/client/cli/tx.go.

Example CLIs for delegating stakes

./build/babylond --home $TESTNET_PATH/node0/babylond --chain-id chain-test \
         --keyring-backend test --fees 1stake \
         --from node0 --broadcast-mode block \
         tx epoching delegate bbnvaloper1mply2jalv2050kzxdx0nnp0h48zqwgg6fu7dgp 10stake

so that we get

➜  babylon git:(epoching-cli) ./build/babylond --home $TESTNET_PATH/node0/babylond --chain-id chain-test \
         --keyring-backend test --fees 3stake \
         --from node0 --broadcast-mode block \
         tx epoching delegate bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr 10stake
{"body":{"messages":[{"@type":"/babylon.epoching.v1.MsgWrappedDelegate","msg":{"delegator_address":"bbn1mv7xdmctgxplqtqxgrgea82augcdhxvqk8dzhz","validator_address":"bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr","amount":{"denom":"stake","amount":"10"}}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[{"denom":"stake","amount":"3"}],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
code: 0
codespace: ""
data: 0A290A272F626162796C6F6E2E65706F6368696E672E76312E4D73675772617070656444656C6567617465
events:
- attributes:
  - index: true
    key: c3BlbmRlcg==
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6
  - index: true
    key: YW1vdW50
    value: M3N0YWtl
  type: coin_spent
- attributes:
  - index: true
    key: cmVjZWl2ZXI=
    value: YmJuMTd4cGZ2YWttMmFtZzk2MnlsczZmODR6M2tlbGw4YzVsODhqMzV5
  - index: true
    key: YW1vdW50
    value: M3N0YWtl
  type: coin_received
- attributes:
  - index: true
    key: cmVjaXBpZW50
    value: YmJuMTd4cGZ2YWttMmFtZzk2MnlsczZmODR6M2tlbGw4YzVsODhqMzV5
  - index: true
    key: c2VuZGVy
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6
  - index: true
    key: YW1vdW50
    value: M3N0YWtl
  type: transfer
- attributes:
  - index: true
    key: c2VuZGVy
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6
  type: message
- attributes:
  - index: true
    key: ZmVl
    value: M3N0YWtl
  type: tx
- attributes:
  - index: true
    key: YWNjX3NlcQ==
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6LzM=
  type: tx
- attributes:
  - index: true
    key: c2lnbmF0dXJl
    value: dFp3SXpIMURDRzRwTDBXK0UwSUh5WElOZ3YzYnJvdTBqbUlweWN5Ui9mb09vcXdLWERoZ3pQbGR4MHQyZElkV0xIZEg3RnNxQ1RuZWFSb2VnNy9QVnc9PQ==
  type: tx
- attributes:
  - index: true
    key: YWN0aW9u
    value: L2JhYnlsb24uZXBvY2hpbmcudjEuTXNnV3JhcHBlZERlbGVnYXRl
  type: message
- attributes:
  - index: true
    key: ZGVub20=
    value: InN0YWtlIg==
  - index: true
    key: ZXBvY2hfYm91bmRhcnk=
    value: IjIwIg==
  - index: true
    key: dmFsaWRhdG9yX2FkZHJlc3M=
    value: ImJibnZhbG9wZXIxbXY3eGRtY3RneHBscXRxeGdyZ2VhODJhdWdjZGh4dnF0OThsbXIi
  - index: true
    key: YW1vdW50
    value: IjEwIg==
  type: babylon.epoching.v1.EventWrappedDelegate
gas_used: "77591"
gas_wanted: "200000"
height: "17"
info: ""
logs:
- events:
  - attributes:
    - key: denom
      value: '"stake"'
    - key: epoch_boundary
      value: '"20"'
    - key: validator_address
      value: '"bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr"'
    - key: amount
      value: '"10"'
    type: babylon.epoching.v1.EventWrappedDelegate
  - attributes:
    - key: action
      value: /babylon.epoching.v1.MsgWrappedDelegate
    type: message
  log: ""
  msg_index: 0
raw_log: '[{"events":[{"type":"babylon.epoching.v1.EventWrappedDelegate","attributes":[{"key":"denom","value":"\"stake\""},{"key":"epoch_boundary","value":"\"20\""},{"key":"validator_address","value":"\"bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr\""},{"key":"amount","value":"\"10\""}]},{"type":"message","attributes":[{"key":"action","value":"/babylon.epoching.v1.MsgWrappedDelegate"}]}]}]'
timestamp: ""
tx: null
txhash: B61097E47C2B6B600BDE33D032E6950BB72FAB31887C42786675A9AD26DF7CD4

Examples CLIs for undelegating stakes

$BABYLON_PATH/build/babylond --home $TESTNET_PATH/node0/babylond --chain-id chain-test \
         --keyring-backend test --fees 3stake \
         --from node0 --broadcast-mode block \
         tx epoching unbond bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr 10stake

so that we get

➜  babylon git:(epoching-cli) ./build/babylond --home $TESTNET_PATH/node0/babylond --chain-id chain-test \
         --keyring-backend test --fees 3stake \
         --from node0 --broadcast-mode block \
         tx epoching unbond bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr 10stake
{"body":{"messages":[{"@type":"/babylon.epoching.v1.MsgWrappedUndelegate","msg":{"delegator_address":"bbn1mv7xdmctgxplqtqxgrgea82augcdhxvqk8dzhz","validator_address":"bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr","amount":{"denom":"stake","amount":"10"}}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[{"denom":"stake","amount":"3"}],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
code: 0
codespace: ""
data: 0A2B0A292F626162796C6F6E2E65706F6368696E672E76312E4D736757726170706564556E64656C6567617465
events:
- attributes:
  - index: true
    key: c3BlbmRlcg==
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6
  - index: true
    key: YW1vdW50
    value: M3N0YWtl
  type: coin_spent
- attributes:
  - index: true
    key: cmVjZWl2ZXI=
    value: YmJuMTd4cGZ2YWttMmFtZzk2MnlsczZmODR6M2tlbGw4YzVsODhqMzV5
  - index: true
    key: YW1vdW50
    value: M3N0YWtl
  type: coin_received
- attributes:
  - index: true
    key: cmVjaXBpZW50
    value: YmJuMTd4cGZ2YWttMmFtZzk2MnlsczZmODR6M2tlbGw4YzVsODhqMzV5
  - index: true
    key: c2VuZGVy
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6
  - index: true
    key: YW1vdW50
    value: M3N0YWtl
  type: transfer
- attributes:
  - index: true
    key: c2VuZGVy
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6
  type: message
- attributes:
  - index: true
    key: ZmVl
    value: M3N0YWtl
  type: tx
- attributes:
  - index: true
    key: YWNjX3NlcQ==
    value: YmJuMW12N3hkbWN0Z3hwbHF0cXhncmdlYTgyYXVnY2RoeHZxazhkemh6LzU=
  type: tx
- attributes:
  - index: true
    key: c2lnbmF0dXJl
    value: YWJ5UVUvVmJNS1hnK0JWYitmU1VzYkpvbEovdmFYZnNGMjRuSWhpeThaZzBvUk5YSjhZTVhxUFJDU2FhbzE5V2lLQUs1djRET0dJOGZOdThZSHpNQmc9PQ==
  type: tx
- attributes:
  - index: true
    key: YWN0aW9u
    value: L2JhYnlsb24uZXBvY2hpbmcudjEuTXNnV3JhcHBlZFVuZGVsZWdhdGU=
  type: message
- attributes:
  - index: true
    key: dmFsaWRhdG9yX2FkZHJlc3M=
    value: ImJibnZhbG9wZXIxbXY3eGRtY3RneHBscXRxeGdyZ2VhODJhdWdjZGh4dnF0OThsbXIi
  - index: true
    key: YW1vdW50
    value: IjEwIg==
  - index: true
    key: ZGVub20=
    value: InN0YWtlIg==
  - index: true
    key: ZXBvY2hfYm91bmRhcnk=
    value: IjQwIg==
  type: babylon.epoching.v1.EventWrappedUndelegate
gas_used: "79082"
gas_wanted: "200000"
height: "31"
info: ""
logs:
- events:
  - attributes:
    - key: validator_address
      value: '"bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr"'
    - key: amount
      value: '"10"'
    - key: denom
      value: '"stake"'
    - key: epoch_boundary
      value: '"40"'
    type: babylon.epoching.v1.EventWrappedUndelegate
  - attributes:
    - key: action
      value: /babylon.epoching.v1.MsgWrappedUndelegate
    type: message
  log: ""
  msg_index: 0
raw_log: '[{"events":[{"type":"babylon.epoching.v1.EventWrappedUndelegate","attributes":[{"key":"validator_address","value":"\"bbnvaloper1mv7xdmctgxplqtqxgrgea82augcdhxvqt98lmr\""},{"key":"amount","value":"\"10\""},{"key":"denom","value":"\"stake\""},{"key":"epoch_boundary","value":"\"40\""}]},{"type":"message","attributes":[{"key":"action","value":"/babylon.epoching.v1.MsgWrappedUndelegate"}]}]}]'
timestamp: ""
tx: null
txhash: 91BD229AEA1907F44BBC5302D176BFFB98ED8FD448D5026D5C5228B8DA2E3FCF

Cosmos calls this command unbond rather than undelegate and I follow this convention.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Since you wrote those useful instructions, maybe you can add them in an .md file under x/epoching/docs or something. Also, please include the instruction for redelegation.

fmt.Sprintf(`Delegate an amount of liquid coins to a validator from your wallet.

Example:
$ %s tx epoching delegate %s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --from mykey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace the hardcoded stake with the sdk.DefaultCoinDenom variable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make easier to identify once we upgrade the denoms.

fmt.Sprintf(`Redelegate an amount of illiquid staking tokens from one validator to another.

Example:
$ %s tx epoching redelegate %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj %s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 100stake --from mykey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

fmt.Sprintf(`Unbond an amount of bonded shares from a validator.

Example:
$ %s tx epoching unbond %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from mykey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@SebastianElvis SebastianElvis merged commit 47320c6 into main Sep 15, 2022
@SebastianElvis SebastianElvis deleted the epoching-cli branch September 15, 2022 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants