refactor to MsgClaimHardReward (#879)

This commit is contained in:
Denali Marsh 2021-03-15 19:03:15 +01:00 committed by GitHub
parent da5df4637b
commit fa97a7db0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 96 additions and 106 deletions

View File

@ -54,7 +54,7 @@ var (
NewGenesisAccumulationTime = types.NewGenesisAccumulationTime NewGenesisAccumulationTime = types.NewGenesisAccumulationTime
NewGenesisState = types.NewGenesisState NewGenesisState = types.NewGenesisState
NewHardLiquidityProviderClaim = types.NewHardLiquidityProviderClaim NewHardLiquidityProviderClaim = types.NewHardLiquidityProviderClaim
NewMsgClaimHardLiquidityProviderReward = types.NewMsgClaimHardLiquidityProviderReward NewMsgClaimHardReward = types.NewMsgClaimHardReward
NewMsgClaimUSDXMintingReward = types.NewMsgClaimUSDXMintingReward NewMsgClaimUSDXMintingReward = types.NewMsgClaimUSDXMintingReward
NewMultiRewardIndex = types.NewMultiRewardIndex NewMultiRewardIndex = types.NewMultiRewardIndex
NewMultiRewardPeriod = types.NewMultiRewardPeriod NewMultiRewardPeriod = types.NewMultiRewardPeriod
@ -130,7 +130,7 @@ type (
HardKeeper = types.HardKeeper HardKeeper = types.HardKeeper
HardLiquidityProviderClaim = types.HardLiquidityProviderClaim HardLiquidityProviderClaim = types.HardLiquidityProviderClaim
HardLiquidityProviderClaims = types.HardLiquidityProviderClaims HardLiquidityProviderClaims = types.HardLiquidityProviderClaims
MsgClaimHardLiquidityProviderReward = types.MsgClaimHardLiquidityProviderReward MsgClaimHardReward = types.MsgClaimHardReward
MsgClaimUSDXMintingReward = types.MsgClaimUSDXMintingReward MsgClaimUSDXMintingReward = types.MsgClaimUSDXMintingReward
MultiRewardIndex = types.MultiRewardIndex MultiRewardIndex = types.MultiRewardIndex
MultiRewardIndexes = types.MultiRewardIndexes MultiRewardIndexes = types.MultiRewardIndexes

View File

@ -83,7 +83,7 @@ func getCmdClaimHard(cdc *codec.Codec) *cobra.Command {
sender := cliCtx.GetFromAddress() sender := cliCtx.GetFromAddress()
multiplier := args[0] multiplier := args[0]
msg := types.NewMsgClaimHardLiquidityProviderReward(sender, multiplier) msg := types.NewMsgClaimHardReward(sender, multiplier)
err := msg.ValidateBasic() err := msg.ValidateBasic()
if err != nil { if err != nil {
return err return err

View File

@ -76,7 +76,7 @@ func postClaimHardHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return return
} }
msg := types.NewMsgClaimHardLiquidityProviderReward(requestBody.Sender, requestBody.MultiplierName) msg := types.NewMsgClaimHardReward(requestBody.Sender, requestBody.MultiplierName)
if err := msg.ValidateBasic(); err != nil { if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return return

View File

@ -15,8 +15,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
switch msg := msg.(type) { switch msg := msg.(type) {
case types.MsgClaimUSDXMintingReward: case types.MsgClaimUSDXMintingReward:
return handleMsgClaimUSDXMintingReward(ctx, k, msg) return handleMsgClaimUSDXMintingReward(ctx, k, msg)
case types.MsgClaimHardLiquidityProviderReward: case types.MsgClaimHardReward:
return handleMsgClaimHardLiquidityProviderReward(ctx, k, msg) return handleMsgClaimHardReward(ctx, k, msg)
default: default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg) return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", ModuleName, msg)
} }
@ -34,7 +34,7 @@ func handleMsgClaimUSDXMintingReward(ctx sdk.Context, k keeper.Keeper, msg types
}, nil }, nil
} }
func handleMsgClaimHardLiquidityProviderReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimHardLiquidityProviderReward) (*sdk.Result, error) { func handleMsgClaimHardReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimHardReward) (*sdk.Result, error) {
err := k.ClaimHardReward(ctx, msg.Sender, types.MultiplierName(msg.MultiplierName)) err := k.ClaimHardReward(ctx, msg.Sender, types.MultiplierName(msg.MultiplierName))
if err != nil { if err != nil {

View File

@ -75,9 +75,9 @@ func (suite *HandlerTestSuite) TestMsgUSDXMintingClaimReward() {
suite.Require().NotNil(res) suite.Require().NotNil(res)
} }
func (suite *HandlerTestSuite) TestMsgHardLiquidityProviderClaimReward() { func (suite *HandlerTestSuite) TestMsgHardClaimReward() {
suite.addHardLiquidityProviderClaim() suite.addHardLiquidityProviderClaim()
msg := incentive.NewMsgClaimHardLiquidityProviderReward(suite.addrs[0], "small") msg := incentive.NewMsgClaimHardReward(suite.addrs[0], "small")
res, err := suite.handler(suite.ctx, msg) res, err := suite.handler(suite.ctx, msg)
suite.NoError(err) suite.NoError(err)
suite.Require().NotNil(res) suite.Require().NotNil(res)

View File

@ -4,7 +4,7 @@ order: 3
# Messages # Messages
Users claim rewards using `MsgClaimUSDXMintingReward` and `MsgClaimHardLiquidityProviderReward` messages. Users claim rewards using `MsgClaimUSDXMintingReward` and `MsgClaimHardReward` messages.
```go ```go
// MsgClaimUSDXMintingReward message type used to claim USDX minting rewards // MsgClaimUSDXMintingReward message type used to claim USDX minting rewards
@ -13,8 +13,8 @@ type MsgClaimUSDXMintingReward struct {
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"` MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
} }
// MsgClaimHardLiquidityProviderReward message type used to claim Hard liquidity provider rewards // MsgClaimHardReward message type used to claim Hard liquidity provider rewards
type MsgClaimHardLiquidityProviderReward struct { type MsgClaimHardReward struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"` Sender sdk.AccAddress `json:"sender" yaml:"sender"`
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"` MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
} }
@ -22,6 +22,6 @@ type MsgClaimHardLiquidityProviderReward struct {
## State Modifications ## State Modifications
* Accumulated rewards for active claims are transferred from the `kavadist` module account to the users account as vesting coins - Accumulated rewards for active claims are transferred from the `kavadist` module account to the users account as vesting coins
* The number of coins transferred is determined by the multiplier in the message. For example, the multiplier equals 1.0, 100% of the claim's reward value is transferred. If the multiplier equals 0.5, 50% of the claim's reward value is transferred. - The number of coins transferred is determined by the multiplier in the message. For example, the multiplier equals 1.0, 100% of the claim's reward value is transferred. If the multiplier equals 0.5, 50% of the claim's reward value is transferred.
* The corresponding claim object is reset to zero in the store - The corresponding claim object is reset to zero in the store

View File

@ -6,22 +6,12 @@ order: 4
The `x/incentive` module emits the following events: The `x/incentive` module emits the following events:
## ClaimUSDXMintingReward ## ClaimReward
| Type | Attribute Key | Attribute Value | | Type | Attribute Key | Attribute Value |
|----------------------|---------------------|---------------------------| | ------------ | ------------- | -------------------- |
| claim_reward | claimed_by | `{claiming address}' | | claim_reward | claimed_by | `{claiming address}' |
| claim_reward | claim_amount | `{amount claimed}' | | claim_reward | claim_amount | `{amount claimed}' |
| claim_reward | claim_type | `{amount claimed}' | | claim_reward | claim_type | `{amount claimed}' |
| message | module | incentive | | message | module | incentive |
| message | sender | hard_liquidity_provider | | message | sender | claim_reward |
## MsgClaimHardLiquidityProviderReward
| Type | Attribute Key | Attribute Value |
|----------------------|---------------------|---------------------------|
| claim_reward | claimed_by | `{claiming address}' |
| claim_reward | claim_amount | `{amount claimed}' |
| claim_reward | claim_type | `{amount claimed}' |
| message | module | incentive |
| message | sender | usdx_minting |

View File

@ -20,5 +20,5 @@ func RegisterCodec(cdc *codec.Codec) {
// Register msgs // Register msgs
cdc.RegisterConcrete(MsgClaimUSDXMintingReward{}, "incentive/MsgClaimUSDXMintingReward", nil) cdc.RegisterConcrete(MsgClaimUSDXMintingReward{}, "incentive/MsgClaimUSDXMintingReward", nil)
cdc.RegisterConcrete(MsgClaimHardLiquidityProviderReward{}, "incentive/MsgClaimHardLiquidityProviderReward", nil) cdc.RegisterConcrete(MsgClaimHardReward{}, "incentive/MsgClaimHardReward", nil)
} }

View File

@ -9,7 +9,7 @@ import (
// ensure Msg interface compliance at compile time // ensure Msg interface compliance at compile time
var _ sdk.Msg = &MsgClaimUSDXMintingReward{} var _ sdk.Msg = &MsgClaimUSDXMintingReward{}
var _ sdk.Msg = &MsgClaimHardLiquidityProviderReward{} var _ sdk.Msg = &MsgClaimHardReward{}
// MsgClaimUSDXMintingReward message type used to claim USDX minting rewards // MsgClaimUSDXMintingReward message type used to claim USDX minting rewards
type MsgClaimUSDXMintingReward struct { type MsgClaimUSDXMintingReward struct {
@ -50,30 +50,30 @@ func (msg MsgClaimUSDXMintingReward) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender} return []sdk.AccAddress{msg.Sender}
} }
// MsgClaimHardLiquidityProviderReward message type used to claim Hard liquidity provider rewards // MsgClaimHardReward message type used to claim Hard liquidity provider rewards
type MsgClaimHardLiquidityProviderReward struct { type MsgClaimHardReward struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"` Sender sdk.AccAddress `json:"sender" yaml:"sender"`
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"` MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
} }
// NewMsgClaimHardLiquidityProviderReward returns a new MsgClaimHardLiquidityProviderReward. // NewMsgClaimHardReward returns a new MsgClaimHardReward.
func NewMsgClaimHardLiquidityProviderReward(sender sdk.AccAddress, multiplierName string) MsgClaimHardLiquidityProviderReward { func NewMsgClaimHardReward(sender sdk.AccAddress, multiplierName string) MsgClaimHardReward {
return MsgClaimHardLiquidityProviderReward{ return MsgClaimHardReward{
Sender: sender, Sender: sender,
MultiplierName: multiplierName, MultiplierName: multiplierName,
} }
} }
// Route return the message type used for routing the message. // Route return the message type used for routing the message.
func (msg MsgClaimHardLiquidityProviderReward) Route() string { return RouterKey } func (msg MsgClaimHardReward) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags. // Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgClaimHardLiquidityProviderReward) Type() string { func (msg MsgClaimHardReward) Type() string {
return "claim_hard_liquidity_provider_reward" return "claim_hard_reward"
} }
// ValidateBasic does a simple validation check that doesn't require access to state. // ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgClaimHardLiquidityProviderReward) ValidateBasic() error { func (msg MsgClaimHardReward) ValidateBasic() error {
if msg.Sender.Empty() { if msg.Sender.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty") return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
} }
@ -81,12 +81,12 @@ func (msg MsgClaimHardLiquidityProviderReward) ValidateBasic() error {
} }
// GetSignBytes gets the canonical byte representation of the Msg. // GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgClaimHardLiquidityProviderReward) GetSignBytes() []byte { func (msg MsgClaimHardReward) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg) bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz) return sdk.MustSortJSON(bz)
} }
// GetSigners returns the addresses of signers that must sign. // GetSigners returns the addresses of signers that must sign.
func (msg MsgClaimHardLiquidityProviderReward) GetSigners() []sdk.AccAddress { func (msg MsgClaimHardReward) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender} return []sdk.AccAddress{msg.Sender}
} }