-
Notifications
You must be signed in to change notification settings - Fork 201
/
tx_toggle_lsm_proposal.go
112 lines (93 loc) · 2.84 KB
/
tx_toggle_lsm_proposal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package cli
import (
"fmt"
"os"
"strings"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"
govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/spf13/cobra"
"github.com/Stride-Labs/stride/v21/x/stakeibc/types"
)
func parseToggleLSMProposalFile(cdc codec.JSONCodec, proposalFile string) (proposal types.ToggleLSMProposal, err error) {
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}
if err = cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}
action := "Disable"
if proposal.Enabled {
action = "Enable"
}
proposal.Title = fmt.Sprintf("%s LSMLiquidStakes for %s", action, proposal.HostZone)
return proposal, nil
}
func CmdToggleLSMProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "toggle-lsm [proposal-file]",
Short: "Submit an toggle-lsm proposal",
Long: strings.TrimSpace(
fmt.Sprintf(`Submit an toggle-lsm proposal which will either enable or disable
LSMLiquidStakes for the host zone.
Example:
$ %s tx gov submit-legacy-proposal toggle-lsm <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"description": "Proposal to enable LSM for Osmosis",
"hostZone": "osmosis-1",
"enabled": true,
"deposit": "64000000ustrd"
}
`, version.AppName),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := parseToggleLSMProposalFile(clientCtx.Codec, args[0])
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
depositFromFlags, err := cmd.Flags().GetString(govcli.FlagDeposit)
if err != nil {
return err
}
// if deposit from flags is not empty, it overrides the deposit from proposal
if depositFromFlags != "" {
proposal.Deposit = depositFromFlags
}
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
strideDenom, err := sdk.GetBaseDenom()
if err != nil {
return err
}
if len(deposit) != 1 || deposit.GetDenomByIndex(0) != strideDenom {
return errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "Deposit token denom must be %s", strideDenom)
}
msg, err := govtypes.NewMsgSubmitProposal(&proposal, deposit, from)
if err != nil {
return err
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(govcli.FlagDeposit, "", "deposit of proposal")
return cmd
}