Skip to content

Commit

Permalink
refactor to MsgClaimHardReward (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
denalimarsh committed Mar 15, 2021
1 parent da5df46 commit fa97a7d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 106 deletions.
124 changes: 62 additions & 62 deletions x/incentive/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ const (

var (
// function aliases
CalculateTimeElapsed = keeper.CalculateTimeElapsed
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
DefaultGenesisState = types.DefaultGenesisState
DefaultParams = types.DefaultParams
GetTotalVestingPeriodLength = types.GetTotalVestingPeriodLength
NewGenesisAccumulationTime = types.NewGenesisAccumulationTime
NewGenesisState = types.NewGenesisState
NewHardLiquidityProviderClaim = types.NewHardLiquidityProviderClaim
NewMsgClaimHardLiquidityProviderReward = types.NewMsgClaimHardLiquidityProviderReward
NewMsgClaimUSDXMintingReward = types.NewMsgClaimUSDXMintingReward
NewMultiRewardIndex = types.NewMultiRewardIndex
NewMultiRewardPeriod = types.NewMultiRewardPeriod
NewMultiplier = types.NewMultiplier
NewParams = types.NewParams
NewPeriod = types.NewPeriod
NewQueryHardRewardsParams = types.NewQueryHardRewardsParams
NewQueryRewardsParams = types.NewQueryRewardsParams
NewQueryUSDXMintingRewardsParams = types.NewQueryUSDXMintingRewardsParams
NewRewardIndex = types.NewRewardIndex
NewRewardPeriod = types.NewRewardPeriod
NewUSDXMintingClaim = types.NewUSDXMintingClaim
ParamKeyTable = types.ParamKeyTable
RegisterCodec = types.RegisterCodec
CalculateTimeElapsed = keeper.CalculateTimeElapsed
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
DefaultGenesisState = types.DefaultGenesisState
DefaultParams = types.DefaultParams
GetTotalVestingPeriodLength = types.GetTotalVestingPeriodLength
NewGenesisAccumulationTime = types.NewGenesisAccumulationTime
NewGenesisState = types.NewGenesisState
NewHardLiquidityProviderClaim = types.NewHardLiquidityProviderClaim
NewMsgClaimHardReward = types.NewMsgClaimHardReward
NewMsgClaimUSDXMintingReward = types.NewMsgClaimUSDXMintingReward
NewMultiRewardIndex = types.NewMultiRewardIndex
NewMultiRewardPeriod = types.NewMultiRewardPeriod
NewMultiplier = types.NewMultiplier
NewParams = types.NewParams
NewPeriod = types.NewPeriod
NewQueryHardRewardsParams = types.NewQueryHardRewardsParams
NewQueryRewardsParams = types.NewQueryRewardsParams
NewQueryUSDXMintingRewardsParams = types.NewQueryUSDXMintingRewardsParams
NewRewardIndex = types.NewRewardIndex
NewRewardPeriod = types.NewRewardPeriod
NewUSDXMintingClaim = types.NewUSDXMintingClaim
ParamKeyTable = types.ParamKeyTable
RegisterCodec = types.RegisterCodec

// variable aliases
DefaultActive = types.DefaultActive
Expand Down Expand Up @@ -114,42 +114,42 @@ var (
)

type (
Hooks = keeper.Hooks
Keeper = keeper.Keeper
AccountKeeper = types.AccountKeeper
BaseClaim = types.BaseClaim
BaseMultiClaim = types.BaseMultiClaim
CDPHooks = types.CDPHooks
CdpKeeper = types.CdpKeeper
Claim = types.Claim
Claims = types.Claims
GenesisAccumulationTime = types.GenesisAccumulationTime
GenesisAccumulationTimes = types.GenesisAccumulationTimes
GenesisState = types.GenesisState
HARDHooks = types.HARDHooks
HardKeeper = types.HardKeeper
HardLiquidityProviderClaim = types.HardLiquidityProviderClaim
HardLiquidityProviderClaims = types.HardLiquidityProviderClaims
MsgClaimHardLiquidityProviderReward = types.MsgClaimHardLiquidityProviderReward
MsgClaimUSDXMintingReward = types.MsgClaimUSDXMintingReward
MultiRewardIndex = types.MultiRewardIndex
MultiRewardIndexes = types.MultiRewardIndexes
MultiRewardPeriod = types.MultiRewardPeriod
MultiRewardPeriods = types.MultiRewardPeriods
Multiplier = types.Multiplier
MultiplierName = types.MultiplierName
Multipliers = types.Multipliers
Params = types.Params
PostClaimReq = types.PostClaimReq
QueryHardRewardsParams = types.QueryHardRewardsParams
QueryRewardsParams = types.QueryRewardsParams
QueryUSDXMintingRewardsParams = types.QueryUSDXMintingRewardsParams
RewardIndex = types.RewardIndex
RewardIndexes = types.RewardIndexes
RewardPeriod = types.RewardPeriod
RewardPeriods = types.RewardPeriods
StakingKeeper = types.StakingKeeper
SupplyKeeper = types.SupplyKeeper
USDXMintingClaim = types.USDXMintingClaim
USDXMintingClaims = types.USDXMintingClaims
Hooks = keeper.Hooks
Keeper = keeper.Keeper
AccountKeeper = types.AccountKeeper
BaseClaim = types.BaseClaim
BaseMultiClaim = types.BaseMultiClaim
CDPHooks = types.CDPHooks
CdpKeeper = types.CdpKeeper
Claim = types.Claim
Claims = types.Claims
GenesisAccumulationTime = types.GenesisAccumulationTime
GenesisAccumulationTimes = types.GenesisAccumulationTimes
GenesisState = types.GenesisState
HARDHooks = types.HARDHooks
HardKeeper = types.HardKeeper
HardLiquidityProviderClaim = types.HardLiquidityProviderClaim
HardLiquidityProviderClaims = types.HardLiquidityProviderClaims
MsgClaimHardReward = types.MsgClaimHardReward
MsgClaimUSDXMintingReward = types.MsgClaimUSDXMintingReward
MultiRewardIndex = types.MultiRewardIndex
MultiRewardIndexes = types.MultiRewardIndexes
MultiRewardPeriod = types.MultiRewardPeriod
MultiRewardPeriods = types.MultiRewardPeriods
Multiplier = types.Multiplier
MultiplierName = types.MultiplierName
Multipliers = types.Multipliers
Params = types.Params
PostClaimReq = types.PostClaimReq
QueryHardRewardsParams = types.QueryHardRewardsParams
QueryRewardsParams = types.QueryRewardsParams
QueryUSDXMintingRewardsParams = types.QueryUSDXMintingRewardsParams
RewardIndex = types.RewardIndex
RewardIndexes = types.RewardIndexes
RewardPeriod = types.RewardPeriod
RewardPeriods = types.RewardPeriods
StakingKeeper = types.StakingKeeper
SupplyKeeper = types.SupplyKeeper
USDXMintingClaim = types.USDXMintingClaim
USDXMintingClaims = types.USDXMintingClaims
)
2 changes: 1 addition & 1 deletion x/incentive/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/incentive/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions x/incentive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions x/incentive/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions x/incentive/spec/03_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,15 +13,15 @@ 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"`
}
```

## 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
26 changes: 8 additions & 18 deletions x/incentive/spec/04_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| 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 | claim_reward |
2 changes: 1 addition & 1 deletion x/incentive/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
24 changes: 12 additions & 12 deletions x/incentive/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -50,43 +50,43 @@ 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")
}
return MultiplierName(strings.ToLower(msg.MultiplierName)).IsValid()
}

// 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}
}

0 comments on commit fa97a7d

Please sign in to comment.