2020-04-24 15:20:34 +00:00
|
|
|
package incentive
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2020-04-24 15:20:34 +00:00
|
|
|
"github.com/kava-labs/kava/x/incentive/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewHandler creates an sdk.Handler for incentive module messages
|
|
|
|
func NewHandler(k keeper.Keeper) sdk.Handler {
|
|
|
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
|
|
|
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
|
|
|
switch msg := msg.(type) {
|
2021-01-18 19:12:37 +00:00
|
|
|
case types.MsgClaimUSDXMintingReward:
|
|
|
|
return handleMsgClaimUSDXMintingReward(ctx, k, msg)
|
2021-06-07 14:04:32 +00:00
|
|
|
case types.MsgClaimUSDXMintingRewardVVesting:
|
|
|
|
return handleMsgClaimUSDXMintingRewardVVesting(ctx, k, msg)
|
2021-03-15 18:03:15 +00:00
|
|
|
case types.MsgClaimHardReward:
|
|
|
|
return handleMsgClaimHardReward(ctx, k, msg)
|
2021-06-07 14:04:32 +00:00
|
|
|
case types.MsgClaimHardRewardVVesting:
|
|
|
|
return handleMsgClaimHardRewardVVesting(ctx, k, msg)
|
2021-07-07 16:50:14 +00:00
|
|
|
case types.MsgClaimDelegatorReward:
|
|
|
|
return handleMsgClaimDelegatorReward(ctx, k, msg)
|
|
|
|
case types.MsgClaimDelegatorRewardVVesting:
|
|
|
|
return handleMsgClaimDelegatorRewardVVesting(ctx, k, msg)
|
2021-07-15 14:05:54 +00:00
|
|
|
case types.MsgClaimSwapReward:
|
|
|
|
return handleMsgClaimSwapReward(ctx, k, msg)
|
|
|
|
case types.MsgClaimSwapRewardVVesting:
|
|
|
|
return handleMsgClaimSwapRewardVVesting(ctx, k, msg)
|
2020-04-24 15:20:34 +00:00
|
|
|
default:
|
|
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 19:12:37 +00:00
|
|
|
func handleMsgClaimUSDXMintingReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimUSDXMintingReward) (*sdk.Result, error) {
|
2021-07-15 14:05:54 +00:00
|
|
|
err := k.ClaimUSDXMintingReward(ctx, msg.Sender, msg.Sender, types.MultiplierName(msg.MultiplierName))
|
2021-01-26 11:52:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:04:32 +00:00
|
|
|
func handleMsgClaimUSDXMintingRewardVVesting(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimUSDXMintingRewardVVesting) (*sdk.Result, error) {
|
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err := k.ClaimUSDXMintingReward(ctx, msg.Sender, msg.Receiver, types.MultiplierName(msg.MultiplierName))
|
2021-06-07 14:04:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:03:15 +00:00
|
|
|
func handleMsgClaimHardReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimHardReward) (*sdk.Result, error) {
|
2021-01-26 11:52:34 +00:00
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
err := k.ClaimHardReward(ctx, msg.Sender, msg.Sender, types.MultiplierName(msg.MultiplierName), msg.DenomsToClaim)
|
2021-01-18 19:12:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
2021-06-07 14:04:32 +00:00
|
|
|
|
|
|
|
func handleMsgClaimHardRewardVVesting(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimHardRewardVVesting) (*sdk.Result, error) {
|
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err := k.ClaimHardReward(ctx, msg.Sender, msg.Receiver, types.MultiplierName(msg.MultiplierName), msg.DenomsToClaim)
|
2021-06-07 14:04:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
|
|
|
|
func handleMsgClaimDelegatorReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimDelegatorReward) (*sdk.Result, error) {
|
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
err := k.ClaimDelegatorReward(ctx, msg.Sender, msg.Sender, types.MultiplierName(msg.MultiplierName), msg.DenomsToClaim)
|
2021-07-07 16:50:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleMsgClaimDelegatorRewardVVesting(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimDelegatorRewardVVesting) (*sdk.Result, error) {
|
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err := k.ClaimDelegatorReward(ctx, msg.Sender, msg.Receiver, types.MultiplierName(msg.MultiplierName), msg.DenomsToClaim)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleMsgClaimSwapReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimSwapReward) (*sdk.Result, error) {
|
|
|
|
|
|
|
|
err := k.ClaimSwapReward(ctx, msg.Sender, msg.Sender, types.MultiplierName(msg.MultiplierName), msg.DenomsToClaim)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleMsgClaimSwapRewardVVesting(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimSwapRewardVVesting) (*sdk.Result, error) {
|
|
|
|
|
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err := k.ClaimSwapReward(ctx, msg.Sender, msg.Receiver, types.MultiplierName(msg.MultiplierName), msg.DenomsToClaim)
|
2021-07-07 16:50:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|