/
tx_set_community_pool_rebate.go
61 lines (52 loc) · 1.69 KB
/
tx_set_community_pool_rebate.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
package cli
import (
"errors"
"fmt"
"strings"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"
"github.com/Stride-Labs/stride/v21/x/stakeibc/types"
)
func CmdSetCommunityPoolRebate() *cobra.Command {
cmd := &cobra.Command{
Use: "set-rebate [chain-id] [rebate-rate] [liquid-staked-sttoken-amount]",
Short: "Registers or updates a community pool rebate",
Long: strings.TrimSpace(`Registers a community pool rebate by specifying the rebate percentage (as a decimal)
and the amount liquid staked, denominated in the number of stTokens received.
E.g. to specify a 20% rebate, the rebate rate should be 0.2
If a 0.0 rebate or 0 token liquid stake is specified, the rebate will be deleted.
`),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
chainId := args[0]
rebatePercentage, err := sdk.NewDecFromStr(args[1])
if err != nil {
return fmt.Errorf("unable to parse rebate percentage: %s", err.Error())
}
liquidStakedStTokenAmount, ok := sdkmath.NewIntFromString(args[2])
if !ok {
return errors.New("unable to parse liquid stake amount")
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgSetCommunityPoolRebate(
clientCtx.GetFromAddress().String(),
chainId,
rebatePercentage,
liquidStakedStTokenAmount,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}