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-08-04 14:55:29 +00:00
|
|
|
err := k.ClaimUSDXMintingReward(ctx, msg.Sender, msg.Sender, 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
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
err := k.ClaimUSDXMintingReward(ctx, msg.Sender, msg.Receiver, 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-08-04 14:55:29 +00:00
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
|
|
err := k.ClaimHardReward(ctx, msg.Sender, msg.Sender, selection.Denom, selection.MultiplierName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-26 11:52:34 +00:00
|
|
|
|
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
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
|
|
err := k.ClaimHardReward(ctx, msg.Sender, msg.Receiver, selection.Denom, selection.MultiplierName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-06-07 14:04:32 +00:00
|
|
|
}
|
|
|
|
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-08-04 14:55:29 +00:00
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
|
|
err := k.ClaimDelegatorReward(ctx, msg.Sender, msg.Sender, selection.Denom, selection.MultiplierName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
|
|
err := k.ClaimDelegatorReward(ctx, msg.Sender, msg.Receiver, selection.Denom, selection.MultiplierName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-15 14:05:54 +00:00
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleMsgClaimSwapReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimSwapReward) (*sdk.Result, error) {
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
|
|
err := k.ClaimSwapReward(ctx, msg.Sender, msg.Sender, selection.Denom, selection.MultiplierName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-15 14:05:54 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
2021-08-04 14:55:29 +00:00
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
|
|
err := k.ClaimSwapReward(ctx, msg.Sender, msg.Receiver, selection.Denom, selection.MultiplierName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
}
|
|
|
|
return &sdk.Result{
|
|
|
|
Events: ctx.EventManager().Events(),
|
|
|
|
}, nil
|
|
|
|
}
|