mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
refactor to MsgClaimHardReward (#879)
This commit is contained in:
parent
da5df4637b
commit
fa97a7db0e
@ -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
|
||||
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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 |
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user