mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 03:17:27 +00:00 
			
		
		
		
	Incentive module: accounts should only be able to claim their own rewards (#826)
* make rewards only claimable by sender * remove 'owner' from cli for incentive claims
This commit is contained in:
		
							parent
							
								
									15da55b451
								
							
						
					
					
						commit
						94999b6b02
					
				@ -11,7 +11,6 @@ import (
 | 
			
		||||
	"github.com/cosmos/cosmos-sdk/client/flags"
 | 
			
		||||
	"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"
 | 
			
		||||
	"github.com/cosmos/cosmos-sdk/x/auth"
 | 
			
		||||
	"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
 | 
			
		||||
@ -32,38 +31,30 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
 | 
			
		||||
	)...)
 | 
			
		||||
 | 
			
		||||
	return incentiveTxCmd
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getCmdClaimCdp(cdc *codec.Codec) *cobra.Command {
 | 
			
		||||
	return &cobra.Command{
 | 
			
		||||
		Use:   "claim-cdp [owner] [multiplier]",
 | 
			
		||||
		Short: "claim CDP rewards for cdp owner and collateral-type",
 | 
			
		||||
		Use:   "claim-cdp [multiplier]",
 | 
			
		||||
		Short: "claim CDP rewards using a given multiplier",
 | 
			
		||||
		Long: strings.TrimSpace(
 | 
			
		||||
			fmt.Sprintf(`Claim any outstanding CDP rewards owned by owner for the input collateral-type and multiplier,
 | 
			
		||||
			fmt.Sprintf(`Claim sender's outstanding CDP rewards using a given multiplier
 | 
			
		||||
 | 
			
		||||
			Example:
 | 
			
		||||
			$ %s tx %s claim-cdp kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw large
 | 
			
		||||
			$ %s tx %s claim-cdp large
 | 
			
		||||
		`, version.ClientName, types.ModuleName),
 | 
			
		||||
		),
 | 
			
		||||
		Args: cobra.ExactArgs(2),
 | 
			
		||||
		Args: cobra.ExactArgs(1),
 | 
			
		||||
		RunE: func(cmd *cobra.Command, args []string) error {
 | 
			
		||||
			inBuf := bufio.NewReader(cmd.InOrStdin())
 | 
			
		||||
			cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc)
 | 
			
		||||
			cliCtx := context.NewCLIContext().WithCodec(cdc)
 | 
			
		||||
			txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
 | 
			
		||||
 | 
			
		||||
			owner, err := sdk.AccAddressFromBech32(args[0])
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			sender := cliCtx.GetFromAddress()
 | 
			
		||||
			if !sender.Equals(owner) {
 | 
			
		||||
				return sdkerrors.Wrapf(types.ErrInvalidClaimOwner, "tx sender %s does not match claim owner %s", sender, owner)
 | 
			
		||||
			}
 | 
			
		||||
			multiplier := args[0]
 | 
			
		||||
 | 
			
		||||
			msg := types.NewMsgClaimUSDXMintingReward(owner, args[1])
 | 
			
		||||
			err = msg.ValidateBasic()
 | 
			
		||||
			msg := types.NewMsgClaimUSDXMintingReward(sender, multiplier)
 | 
			
		||||
			err := msg.ValidateBasic()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
@ -74,33 +65,26 @@ func getCmdClaimCdp(cdc *codec.Codec) *cobra.Command {
 | 
			
		||||
 | 
			
		||||
func getCmdClaimHard(cdc *codec.Codec) *cobra.Command {
 | 
			
		||||
	return &cobra.Command{
 | 
			
		||||
		Use:   "claim-hard [owner] [multiplier]",
 | 
			
		||||
		Short: "claim Hard rewards for deposit/borrow and delegating",
 | 
			
		||||
		Use:   "claim-hard [multiplier]",
 | 
			
		||||
		Short: "claim sender's Hard module rewards using a given multiplier",
 | 
			
		||||
		Long: strings.TrimSpace(
 | 
			
		||||
			fmt.Sprintf(`Claim owner's outstanding Hard rewards using given multiplier multiplier,
 | 
			
		||||
			fmt.Sprintf(`Claim sender's outstanding Hard rewards for deposit/borrow/delegate using given multiplier
 | 
			
		||||
 | 
			
		||||
			Example:
 | 
			
		||||
			$ %s tx %s claim-hard kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw large
 | 
			
		||||
			$ %s tx %s claim-hard large
 | 
			
		||||
		`, version.ClientName, types.ModuleName),
 | 
			
		||||
		),
 | 
			
		||||
		Args: cobra.ExactArgs(2),
 | 
			
		||||
		Args: cobra.ExactArgs(1),
 | 
			
		||||
		RunE: func(cmd *cobra.Command, args []string) error {
 | 
			
		||||
			inBuf := bufio.NewReader(cmd.InOrStdin())
 | 
			
		||||
			cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc)
 | 
			
		||||
			cliCtx := context.NewCLIContext().WithCodec(cdc)
 | 
			
		||||
			txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
 | 
			
		||||
 | 
			
		||||
			owner, err := sdk.AccAddressFromBech32(args[0])
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			sender := cliCtx.GetFromAddress()
 | 
			
		||||
			if !sender.Equals(owner) {
 | 
			
		||||
				return sdkerrors.Wrapf(types.ErrInvalidClaimOwner, "tx sender %s does not match claim owner %s", sender, owner)
 | 
			
		||||
			}
 | 
			
		||||
			multiplier := args[0]
 | 
			
		||||
 | 
			
		||||
			msg := types.NewMsgClaimHardLiquidityProviderReward(owner, args[1])
 | 
			
		||||
			err = msg.ValidateBasic()
 | 
			
		||||
			msg := types.NewMsgClaimHardLiquidityProviderReward(sender, multiplier)
 | 
			
		||||
			err := msg.ValidateBasic()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -8,10 +8,10 @@ import (
 | 
			
		||||
 | 
			
		||||
// Incentive module errors
 | 
			
		||||
var (
 | 
			
		||||
	ErrClaimNotFound                 = sdkerrors.Register(ModuleName, 2, "no claim with input id found for owner and collateral type")
 | 
			
		||||
	ErrClaimNotFound                 = sdkerrors.Register(ModuleName, 2, "no claimable rewards found for user")
 | 
			
		||||
	ErrRewardPeriodNotFound          = sdkerrors.Register(ModuleName, 3, "no reward period found for collateral type")
 | 
			
		||||
	ErrInvalidAccountType            = sdkerrors.Register(ModuleName, 4, "account type not supported")
 | 
			
		||||
	ErrNoClaimsFound                 = sdkerrors.Register(ModuleName, 5, "no claims with collateral type found for address")
 | 
			
		||||
	ErrNoClaimsFound                 = sdkerrors.Register(ModuleName, 5, "no claimable rewards found")
 | 
			
		||||
	ErrInsufficientModAccountBalance = sdkerrors.Register(ModuleName, 6, "module account has insufficient balance to pay claim")
 | 
			
		||||
	ErrAccountNotFound               = sdkerrors.Register(ModuleName, 7, "account not found")
 | 
			
		||||
	ErrInvalidMultiplier             = sdkerrors.Register(ModuleName, 8, "invalid rewards multiplier")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user