2021-07-15 14:05:54 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ClaimUSDXMintingReward pays out funds from a claim to a receiver account.
|
|
|
|
// Rewards are removed from a claim and paid out according to the multiplier, which reduces the reward amount in exchange for shorter vesting times.
|
2021-08-04 14:55:29 +00:00
|
|
|
func (k Keeper) ClaimUSDXMintingReward(ctx sdk.Context, owner, receiver sdk.AccAddress, multiplierName string) error {
|
2021-07-15 14:05:54 +00:00
|
|
|
claim, found := k.GetUSDXMintingClaim(ctx, owner)
|
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
2022-09-28 02:46:14 +00:00
|
|
|
multiplier, found := k.GetMultiplierByDenom(ctx, types.USDXMintingRewardDenom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
if !found {
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrapf(types.ErrInvalidMultiplier, "denom '%s' has no multiplier '%s'", types.USDXMintingRewardDenom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
claimEnd := k.GetClaimEnd(ctx)
|
|
|
|
|
|
|
|
if ctx.BlockTime().After(claimEnd) {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimExpired, "block time %s > claim end time %s", ctx.BlockTime(), claimEnd)
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
claim, err := k.SynchronizeUSDXMintingClaim(ctx, claim)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:08:45 +00:00
|
|
|
rewardAmount := sdk.NewDecFromInt(claim.Reward.Amount).Mul(multiplier.Factor).RoundInt()
|
2021-07-15 14:05:54 +00:00
|
|
|
if rewardAmount.IsZero() {
|
|
|
|
return types.ErrZeroClaim
|
|
|
|
}
|
|
|
|
rewardCoin := sdk.NewCoin(claim.Reward.Denom, rewardAmount)
|
2022-01-08 00:39:27 +00:00
|
|
|
length := k.GetPeriodLength(ctx.BlockTime(), multiplier.MonthsLockup)
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
err = k.SendTimeLockedCoinsToAccount(ctx, types.IncentiveMacc, receiver, sdk.NewCoins(rewardCoin), length)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
k.ZeroUSDXMintingClaim(ctx, claim)
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeClaim,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimedBy, owner.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimAmount, claim.Reward.String()),
|
2021-08-10 17:59:19 +00:00
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimType, claim.GetType()),
|
2021-07-15 14:05:54 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClaimHardReward pays out funds from a claim to a receiver account.
|
|
|
|
// Rewards are removed from a claim and paid out according to the multiplier, which reduces the reward amount in exchange for shorter vesting times.
|
2021-08-04 14:55:29 +00:00
|
|
|
func (k Keeper) ClaimHardReward(ctx sdk.Context, owner, receiver sdk.AccAddress, denom string, multiplierName string) error {
|
2022-09-28 02:46:14 +00:00
|
|
|
multiplier, found := k.GetMultiplierByDenom(ctx, denom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
if !found {
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrapf(types.ErrInvalidMultiplier, "denom '%s' has no multiplier '%s'", denom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
claimEnd := k.GetClaimEnd(ctx)
|
|
|
|
|
|
|
|
if ctx.BlockTime().After(claimEnd) {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimExpired, "block time %s > claim end time %s", ctx.BlockTime(), claimEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
k.SynchronizeHardLiquidityProviderClaim(ctx, owner)
|
|
|
|
|
|
|
|
syncedClaim, found := k.GetHardLiquidityProviderClaim(ctx, owner)
|
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
amt := syncedClaim.Reward.AmountOf(denom)
|
|
|
|
|
|
|
|
claimingCoins := sdk.NewCoins(sdk.NewCoin(denom, amt))
|
2023-04-04 00:08:45 +00:00
|
|
|
rewardCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewDecFromInt(amt).Mul(multiplier.Factor).RoundInt()))
|
2021-07-15 14:05:54 +00:00
|
|
|
if rewardCoins.IsZero() {
|
|
|
|
return types.ErrZeroClaim
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
length := k.GetPeriodLength(ctx.BlockTime(), multiplier.MonthsLockup)
|
2021-07-15 14:05:54 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
err := k.SendTimeLockedCoinsToAccount(ctx, types.IncentiveMacc, receiver, rewardCoins, length)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove claimed coins (NOT reward coins)
|
2023-04-04 00:08:45 +00:00
|
|
|
syncedClaim.Reward = syncedClaim.Reward.Sub(claimingCoins...)
|
2021-07-15 14:05:54 +00:00
|
|
|
k.SetHardLiquidityProviderClaim(ctx, syncedClaim)
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeClaim,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimedBy, owner.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimAmount, claimingCoins.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimType, syncedClaim.GetType()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClaimDelegatorReward pays out funds from a claim to a receiver account.
|
|
|
|
// Rewards are removed from a claim and paid out according to the multiplier, which reduces the reward amount in exchange for shorter vesting times.
|
2021-08-04 14:55:29 +00:00
|
|
|
func (k Keeper) ClaimDelegatorReward(ctx sdk.Context, owner, receiver sdk.AccAddress, denom string, multiplierName string) error {
|
2021-07-15 14:05:54 +00:00
|
|
|
claim, found := k.GetDelegatorClaim(ctx, owner)
|
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
2022-09-28 02:46:14 +00:00
|
|
|
multiplier, found := k.GetMultiplierByDenom(ctx, denom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
if !found {
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrapf(types.ErrInvalidMultiplier, "denom '%s' has no multiplier '%s'", denom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
claimEnd := k.GetClaimEnd(ctx)
|
|
|
|
|
|
|
|
if ctx.BlockTime().After(claimEnd) {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimExpired, "block time %s > claim end time %s", ctx.BlockTime(), claimEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
syncedClaim, err := k.SynchronizeDelegatorClaim(ctx, claim)
|
|
|
|
if err != nil {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
amt := syncedClaim.Reward.AmountOf(denom)
|
|
|
|
|
|
|
|
claimingCoins := sdk.NewCoins(sdk.NewCoin(denom, amt))
|
2023-04-04 00:08:45 +00:00
|
|
|
rewardCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewDecFromInt(amt).Mul(multiplier.Factor).RoundInt()))
|
2021-07-15 14:05:54 +00:00
|
|
|
if rewardCoins.IsZero() {
|
|
|
|
return types.ErrZeroClaim
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
length := k.GetPeriodLength(ctx.BlockTime(), multiplier.MonthsLockup)
|
2021-07-15 14:05:54 +00:00
|
|
|
|
|
|
|
err = k.SendTimeLockedCoinsToAccount(ctx, types.IncentiveMacc, receiver, rewardCoins, length)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove claimed coins (NOT reward coins)
|
2023-04-04 00:08:45 +00:00
|
|
|
syncedClaim.Reward = syncedClaim.Reward.Sub(claimingCoins...)
|
2021-07-15 14:05:54 +00:00
|
|
|
k.SetDelegatorClaim(ctx, syncedClaim)
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeClaim,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimedBy, owner.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimAmount, claimingCoins.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimType, syncedClaim.GetType()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClaimSwapReward pays out funds from a claim to a receiver account.
|
|
|
|
// Rewards are removed from a claim and paid out according to the multiplier, which reduces the reward amount in exchange for shorter vesting times.
|
2021-08-04 14:55:29 +00:00
|
|
|
func (k Keeper) ClaimSwapReward(ctx sdk.Context, owner, receiver sdk.AccAddress, denom string, multiplierName string) error {
|
2022-09-28 02:46:14 +00:00
|
|
|
multiplier, found := k.GetMultiplierByDenom(ctx, denom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
if !found {
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrapf(types.ErrInvalidMultiplier, "denom '%s' has no multiplier '%s'", denom, multiplierName)
|
2021-07-15 14:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
claimEnd := k.GetClaimEnd(ctx)
|
|
|
|
|
|
|
|
if ctx.BlockTime().After(claimEnd) {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimExpired, "block time %s > claim end time %s", ctx.BlockTime(), claimEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
syncedClaim, found := k.GetSynchronizedSwapClaim(ctx, owner)
|
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
2021-08-04 14:55:29 +00:00
|
|
|
amt := syncedClaim.Reward.AmountOf(denom)
|
|
|
|
|
|
|
|
claimingCoins := sdk.NewCoins(sdk.NewCoin(denom, amt))
|
2023-04-04 00:08:45 +00:00
|
|
|
rewardCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewDecFromInt(amt).Mul(multiplier.Factor).RoundInt()))
|
2021-07-15 14:05:54 +00:00
|
|
|
if rewardCoins.IsZero() {
|
|
|
|
return types.ErrZeroClaim
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
length := k.GetPeriodLength(ctx.BlockTime(), multiplier.MonthsLockup)
|
2021-07-15 14:05:54 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
err := k.SendTimeLockedCoinsToAccount(ctx, types.IncentiveMacc, receiver, rewardCoins, length)
|
2021-07-15 14:05:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove claimed coins (NOT reward coins)
|
2023-04-04 00:08:45 +00:00
|
|
|
syncedClaim.Reward = syncedClaim.Reward.Sub(claimingCoins...)
|
2021-07-15 14:05:54 +00:00
|
|
|
k.SetSwapClaim(ctx, syncedClaim)
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeClaim,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimedBy, owner.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimAmount, claimingCoins.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimType, syncedClaim.GetType()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
2022-04-01 14:17:03 +00:00
|
|
|
|
|
|
|
// ClaimSavingsReward is a stub method for MsgServer interface compliance
|
|
|
|
func (k Keeper) ClaimSavingsReward(ctx sdk.Context, owner, receiver sdk.AccAddress, denom string, multiplierName string) error {
|
2022-09-28 02:46:14 +00:00
|
|
|
multiplier, found := k.GetMultiplierByDenom(ctx, denom, multiplierName)
|
2022-04-20 11:08:57 +00:00
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrInvalidMultiplier, "denom '%s' has no multiplier '%s'", denom, multiplierName)
|
|
|
|
}
|
|
|
|
|
|
|
|
claimEnd := k.GetClaimEnd(ctx)
|
|
|
|
|
|
|
|
if ctx.BlockTime().After(claimEnd) {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimExpired, "block time %s > claim end time %s", ctx.BlockTime(), claimEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
k.SynchronizeSavingsClaim(ctx, owner)
|
|
|
|
|
|
|
|
syncedClaim, found := k.GetSavingsClaim(ctx, owner)
|
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
|
|
|
amt := syncedClaim.Reward.AmountOf(denom)
|
|
|
|
|
|
|
|
claimingCoins := sdk.NewCoins(sdk.NewCoin(denom, amt))
|
2023-04-04 00:08:45 +00:00
|
|
|
rewardCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewDecFromInt(amt).Mul(multiplier.Factor).RoundInt()))
|
2022-04-20 11:08:57 +00:00
|
|
|
if rewardCoins.IsZero() {
|
|
|
|
return types.ErrZeroClaim
|
|
|
|
}
|
|
|
|
length := k.GetPeriodLength(ctx.BlockTime(), multiplier.MonthsLockup)
|
|
|
|
|
|
|
|
err := k.SendTimeLockedCoinsToAccount(ctx, types.IncentiveMacc, receiver, rewardCoins, length)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove claimed coins (NOT reward coins)
|
2023-04-04 00:08:45 +00:00
|
|
|
syncedClaim.Reward = syncedClaim.Reward.Sub(claimingCoins...)
|
2022-04-20 11:08:57 +00:00
|
|
|
k.SetSavingsClaim(ctx, syncedClaim)
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeClaim,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimedBy, owner.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimAmount, claimingCoins.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimType, syncedClaim.GetType()),
|
|
|
|
),
|
|
|
|
)
|
2022-04-01 14:17:03 +00:00
|
|
|
return nil
|
|
|
|
}
|
2022-09-22 18:26:08 +00:00
|
|
|
|
|
|
|
// ClaimEarnReward pays out funds from a claim to a receiver account.
|
|
|
|
// Rewards are removed from a claim and paid out according to the multiplier, which reduces the reward amount in exchange for shorter vesting times.
|
|
|
|
func (k Keeper) ClaimEarnReward(ctx sdk.Context, owner, receiver sdk.AccAddress, denom string, multiplierName string) error {
|
2022-09-28 02:46:14 +00:00
|
|
|
multiplier, found := k.GetMultiplierByDenom(ctx, denom, multiplierName)
|
2022-09-22 18:26:08 +00:00
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrInvalidMultiplier, "denom '%s' has no multiplier '%s'", denom, multiplierName)
|
|
|
|
}
|
|
|
|
|
|
|
|
claimEnd := k.GetClaimEnd(ctx)
|
|
|
|
|
|
|
|
if ctx.BlockTime().After(claimEnd) {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimExpired, "block time %s > claim end time %s", ctx.BlockTime(), claimEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
syncedClaim, found := k.GetSynchronizedEarnClaim(ctx, owner)
|
|
|
|
if !found {
|
|
|
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "address: %s", owner)
|
|
|
|
}
|
|
|
|
|
|
|
|
amt := syncedClaim.Reward.AmountOf(denom)
|
|
|
|
|
|
|
|
claimingCoins := sdk.NewCoins(sdk.NewCoin(denom, amt))
|
2023-04-04 00:08:45 +00:00
|
|
|
rewardCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewDecFromInt(amt).Mul(multiplier.Factor).RoundInt()))
|
2022-09-22 18:26:08 +00:00
|
|
|
if rewardCoins.IsZero() {
|
|
|
|
return types.ErrZeroClaim
|
|
|
|
}
|
|
|
|
length := k.GetPeriodLength(ctx.BlockTime(), multiplier.MonthsLockup)
|
|
|
|
|
|
|
|
err := k.SendTimeLockedCoinsToAccount(ctx, types.IncentiveMacc, receiver, rewardCoins, length)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove claimed coins (NOT reward coins)
|
2023-04-04 00:08:45 +00:00
|
|
|
syncedClaim.Reward = syncedClaim.Reward.Sub(claimingCoins...)
|
2022-09-22 18:26:08 +00:00
|
|
|
k.SetEarnClaim(ctx, syncedClaim)
|
|
|
|
|
|
|
|
ctx.EventManager().EmitEvent(
|
|
|
|
sdk.NewEvent(
|
|
|
|
types.EventTypeClaim,
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimedBy, owner.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimAmount, claimingCoins.String()),
|
|
|
|
sdk.NewAttribute(types.AttributeKeyClaimType, syncedClaim.GetType()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|