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
NewGenesisState = types.NewGenesisState
NewHardLiquidityProviderClaim = types.NewHardLiquidityProviderClaim
NewMsgClaimHardLiquidityProviderReward = types.NewMsgClaimHardLiquidityProviderReward
NewMsgClaimHardReward = types.NewMsgClaimHardReward
NewMsgClaimUSDXMintingReward = types.NewMsgClaimUSDXMintingReward
NewMultiRewardIndex = types.NewMultiRewardIndex
NewMultiRewardPeriod = types.NewMultiRewardPeriod
@ -130,7 +130,7 @@ type (
HardKeeper = types.HardKeeper
HardLiquidityProviderClaim = types.HardLiquidityProviderClaim
HardLiquidityProviderClaims = types.HardLiquidityProviderClaims
MsgClaimHardLiquidityProviderReward = types.MsgClaimHardLiquidityProviderReward
MsgClaimHardReward = types.MsgClaimHardReward
MsgClaimUSDXMintingReward = types.MsgClaimUSDXMintingReward
MultiRewardIndex = types.MultiRewardIndex
MultiRewardIndexes = types.MultiRewardIndexes

View File

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

View File

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

View File

@ -15,8 +15,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
switch msg := msg.(type) {
case types.MsgClaimUSDXMintingReward:
return handleMsgClaimUSDXMintingReward(ctx, k, msg)
case types.MsgClaimHardLiquidityProviderReward:
return handleMsgClaimHardLiquidityProviderReward(ctx, k, msg)
case types.MsgClaimHardReward:
return handleMsgClaimHardReward(ctx, k, msg)
default:
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
}
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))
if err != nil {

View File

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

View File

@ -4,7 +4,7 @@ order: 3
# Messages
Users claim rewards using `MsgClaimUSDXMintingReward` and `MsgClaimHardLiquidityProviderReward` messages.
Users claim rewards using `MsgClaimUSDXMintingReward` and `MsgClaimHardReward` messages.
```go
// MsgClaimUSDXMintingReward message type used to claim USDX minting rewards
@ -13,8 +13,8 @@ type MsgClaimUSDXMintingReward struct {
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
}
// MsgClaimHardLiquidityProviderReward message type used to claim Hard liquidity provider rewards
type MsgClaimHardLiquidityProviderReward struct {
// MsgClaimHardReward message type used to claim Hard liquidity provider rewards
type MsgClaimHardReward struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
}
@ -22,6 +22,6 @@ type MsgClaimHardLiquidityProviderReward struct {
## State Modifications
* 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 corresponding claim object is reset to zero in the store
- 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 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:
## ClaimUSDXMintingReward
## ClaimReward
| 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 | hard_liquidity_provider |
## 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 |
| message | sender | claim_reward |

View File

@ -20,5 +20,5 @@ func RegisterCodec(cdc *codec.Codec) {
// Register msgs
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
var _ sdk.Msg = &MsgClaimUSDXMintingReward{}
var _ sdk.Msg = &MsgClaimHardLiquidityProviderReward{}
var _ sdk.Msg = &MsgClaimHardReward{}
// MsgClaimUSDXMintingReward message type used to claim USDX minting rewards
type MsgClaimUSDXMintingReward struct {
@ -50,30 +50,30 @@ func (msg MsgClaimUSDXMintingReward) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
}
// MsgClaimHardLiquidityProviderReward message type used to claim Hard liquidity provider rewards
type MsgClaimHardLiquidityProviderReward struct {
// MsgClaimHardReward message type used to claim Hard liquidity provider rewards
type MsgClaimHardReward struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
}
// NewMsgClaimHardLiquidityProviderReward returns a new MsgClaimHardLiquidityProviderReward.
func NewMsgClaimHardLiquidityProviderReward(sender sdk.AccAddress, multiplierName string) MsgClaimHardLiquidityProviderReward {
return MsgClaimHardLiquidityProviderReward{
// NewMsgClaimHardReward returns a new MsgClaimHardReward.
func NewMsgClaimHardReward(sender sdk.AccAddress, multiplierName string) MsgClaimHardReward {
return MsgClaimHardReward{
Sender: sender,
MultiplierName: multiplierName,
}
}
// 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.
func (msg MsgClaimHardLiquidityProviderReward) Type() string {
return "claim_hard_liquidity_provider_reward"
func (msg MsgClaimHardReward) Type() string {
return "claim_hard_reward"
}
// 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() {
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.
func (msg MsgClaimHardLiquidityProviderReward) GetSignBytes() []byte {
func (msg MsgClaimHardReward) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// 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}
}