mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 16:55:21 +00:00
63c8421a81
* move multipliers to their own file * add multipliers per denom to MsgClaimHardReward * claim with multipliers per denom for hard claims * remove unused error * add multipliers per denom to params connect to to hard claiming * temporary fix migration * update usdx claiming for new multiplier params * claim with multipliers per denom for delegator * claim with multipliers per denom for swap rewards * tidy up multiplier name validation * rename new multipliers field in params * remove old multpliers from params * clear up various TODOs * add tags to new structs * remove dead code
149 lines
4.7 KiB
Go
149 lines
4.7 KiB
Go
package incentive
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
"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) {
|
|
case types.MsgClaimUSDXMintingReward:
|
|
return handleMsgClaimUSDXMintingReward(ctx, k, msg)
|
|
case types.MsgClaimUSDXMintingRewardVVesting:
|
|
return handleMsgClaimUSDXMintingRewardVVesting(ctx, k, msg)
|
|
case types.MsgClaimHardReward:
|
|
return handleMsgClaimHardReward(ctx, k, msg)
|
|
case types.MsgClaimHardRewardVVesting:
|
|
return handleMsgClaimHardRewardVVesting(ctx, k, msg)
|
|
case types.MsgClaimDelegatorReward:
|
|
return handleMsgClaimDelegatorReward(ctx, k, msg)
|
|
case types.MsgClaimDelegatorRewardVVesting:
|
|
return handleMsgClaimDelegatorRewardVVesting(ctx, k, msg)
|
|
case types.MsgClaimSwapReward:
|
|
return handleMsgClaimSwapReward(ctx, k, msg)
|
|
case types.MsgClaimSwapRewardVVesting:
|
|
return handleMsgClaimSwapRewardVVesting(ctx, k, msg)
|
|
default:
|
|
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
|
|
}
|
|
}
|
|
}
|
|
|
|
func handleMsgClaimUSDXMintingReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimUSDXMintingReward) (*sdk.Result, error) {
|
|
err := k.ClaimUSDXMintingReward(ctx, msg.Sender, msg.Sender, msg.MultiplierName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &sdk.Result{
|
|
Events: ctx.EventManager().Events(),
|
|
}, nil
|
|
}
|
|
|
|
func handleMsgClaimUSDXMintingRewardVVesting(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimUSDXMintingRewardVVesting) (*sdk.Result, error) {
|
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
return nil, err
|
|
}
|
|
err := k.ClaimUSDXMintingReward(ctx, msg.Sender, msg.Receiver, msg.MultiplierName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &sdk.Result{
|
|
Events: ctx.EventManager().Events(),
|
|
}, nil
|
|
}
|
|
|
|
func handleMsgClaimHardReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimHardReward) (*sdk.Result, error) {
|
|
for _, selection := range msg.DenomsToClaim {
|
|
err := k.ClaimHardReward(ctx, msg.Sender, msg.Sender, selection.Denom, selection.MultiplierName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
}
|
|
return &sdk.Result{
|
|
Events: ctx.EventManager().Events(),
|
|
}, nil
|
|
}
|
|
|
|
func handleMsgClaimHardRewardVVesting(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimHardRewardVVesting) (*sdk.Result, error) {
|
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
return nil, err
|
|
}
|
|
for _, selection := range msg.DenomsToClaim {
|
|
err := k.ClaimHardReward(ctx, msg.Sender, msg.Receiver, selection.Denom, selection.MultiplierName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
}
|
|
return &sdk.Result{
|
|
Events: ctx.EventManager().Events(),
|
|
}, nil
|
|
}
|
|
|
|
func handleMsgClaimDelegatorReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimDelegatorReward) (*sdk.Result, error) {
|
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
err := k.ClaimDelegatorReward(ctx, msg.Sender, msg.Sender, selection.Denom, selection.MultiplierName)
|
|
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) {
|
|
|
|
if err := k.ValidateIsValidatorVestingAccount(ctx, msg.Sender); err != nil {
|
|
return nil, err
|
|
}
|
|
for _, selection := range msg.DenomsToClaim {
|
|
err := k.ClaimDelegatorReward(ctx, msg.Sender, msg.Receiver, selection.Denom, selection.MultiplierName)
|
|
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) {
|
|
|
|
for _, selection := range msg.DenomsToClaim {
|
|
err := k.ClaimSwapReward(ctx, msg.Sender, msg.Sender, selection.Denom, selection.MultiplierName)
|
|
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
|
|
}
|
|
for _, selection := range msg.DenomsToClaim {
|
|
err := k.ClaimSwapReward(ctx, msg.Sender, msg.Receiver, selection.Denom, selection.MultiplierName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return &sdk.Result{
|
|
Events: ctx.EventManager().Events(),
|
|
}, nil
|
|
}
|