mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 16:25:21 +00:00
refactor to MsgClaimHardReward (#879)
This commit is contained in:
parent
da5df4637b
commit
fa97a7db0e
@ -45,30 +45,30 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// function aliases
|
// function aliases
|
||||||
CalculateTimeElapsed = keeper.CalculateTimeElapsed
|
CalculateTimeElapsed = keeper.CalculateTimeElapsed
|
||||||
NewKeeper = keeper.NewKeeper
|
NewKeeper = keeper.NewKeeper
|
||||||
NewQuerier = keeper.NewQuerier
|
NewQuerier = keeper.NewQuerier
|
||||||
DefaultGenesisState = types.DefaultGenesisState
|
DefaultGenesisState = types.DefaultGenesisState
|
||||||
DefaultParams = types.DefaultParams
|
DefaultParams = types.DefaultParams
|
||||||
GetTotalVestingPeriodLength = types.GetTotalVestingPeriodLength
|
GetTotalVestingPeriodLength = types.GetTotalVestingPeriodLength
|
||||||
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
|
||||||
NewMultiplier = types.NewMultiplier
|
NewMultiplier = types.NewMultiplier
|
||||||
NewParams = types.NewParams
|
NewParams = types.NewParams
|
||||||
NewPeriod = types.NewPeriod
|
NewPeriod = types.NewPeriod
|
||||||
NewQueryHardRewardsParams = types.NewQueryHardRewardsParams
|
NewQueryHardRewardsParams = types.NewQueryHardRewardsParams
|
||||||
NewQueryRewardsParams = types.NewQueryRewardsParams
|
NewQueryRewardsParams = types.NewQueryRewardsParams
|
||||||
NewQueryUSDXMintingRewardsParams = types.NewQueryUSDXMintingRewardsParams
|
NewQueryUSDXMintingRewardsParams = types.NewQueryUSDXMintingRewardsParams
|
||||||
NewRewardIndex = types.NewRewardIndex
|
NewRewardIndex = types.NewRewardIndex
|
||||||
NewRewardPeriod = types.NewRewardPeriod
|
NewRewardPeriod = types.NewRewardPeriod
|
||||||
NewUSDXMintingClaim = types.NewUSDXMintingClaim
|
NewUSDXMintingClaim = types.NewUSDXMintingClaim
|
||||||
ParamKeyTable = types.ParamKeyTable
|
ParamKeyTable = types.ParamKeyTable
|
||||||
RegisterCodec = types.RegisterCodec
|
RegisterCodec = types.RegisterCodec
|
||||||
|
|
||||||
// variable aliases
|
// variable aliases
|
||||||
DefaultActive = types.DefaultActive
|
DefaultActive = types.DefaultActive
|
||||||
@ -114,42 +114,42 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Hooks = keeper.Hooks
|
Hooks = keeper.Hooks
|
||||||
Keeper = keeper.Keeper
|
Keeper = keeper.Keeper
|
||||||
AccountKeeper = types.AccountKeeper
|
AccountKeeper = types.AccountKeeper
|
||||||
BaseClaim = types.BaseClaim
|
BaseClaim = types.BaseClaim
|
||||||
BaseMultiClaim = types.BaseMultiClaim
|
BaseMultiClaim = types.BaseMultiClaim
|
||||||
CDPHooks = types.CDPHooks
|
CDPHooks = types.CDPHooks
|
||||||
CdpKeeper = types.CdpKeeper
|
CdpKeeper = types.CdpKeeper
|
||||||
Claim = types.Claim
|
Claim = types.Claim
|
||||||
Claims = types.Claims
|
Claims = types.Claims
|
||||||
GenesisAccumulationTime = types.GenesisAccumulationTime
|
GenesisAccumulationTime = types.GenesisAccumulationTime
|
||||||
GenesisAccumulationTimes = types.GenesisAccumulationTimes
|
GenesisAccumulationTimes = types.GenesisAccumulationTimes
|
||||||
GenesisState = types.GenesisState
|
GenesisState = types.GenesisState
|
||||||
HARDHooks = types.HARDHooks
|
HARDHooks = types.HARDHooks
|
||||||
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
|
||||||
MultiRewardPeriod = types.MultiRewardPeriod
|
MultiRewardPeriod = types.MultiRewardPeriod
|
||||||
MultiRewardPeriods = types.MultiRewardPeriods
|
MultiRewardPeriods = types.MultiRewardPeriods
|
||||||
Multiplier = types.Multiplier
|
Multiplier = types.Multiplier
|
||||||
MultiplierName = types.MultiplierName
|
MultiplierName = types.MultiplierName
|
||||||
Multipliers = types.Multipliers
|
Multipliers = types.Multipliers
|
||||||
Params = types.Params
|
Params = types.Params
|
||||||
PostClaimReq = types.PostClaimReq
|
PostClaimReq = types.PostClaimReq
|
||||||
QueryHardRewardsParams = types.QueryHardRewardsParams
|
QueryHardRewardsParams = types.QueryHardRewardsParams
|
||||||
QueryRewardsParams = types.QueryRewardsParams
|
QueryRewardsParams = types.QueryRewardsParams
|
||||||
QueryUSDXMintingRewardsParams = types.QueryUSDXMintingRewardsParams
|
QueryUSDXMintingRewardsParams = types.QueryUSDXMintingRewardsParams
|
||||||
RewardIndex = types.RewardIndex
|
RewardIndex = types.RewardIndex
|
||||||
RewardIndexes = types.RewardIndexes
|
RewardIndexes = types.RewardIndexes
|
||||||
RewardPeriod = types.RewardPeriod
|
RewardPeriod = types.RewardPeriod
|
||||||
RewardPeriods = types.RewardPeriods
|
RewardPeriods = types.RewardPeriods
|
||||||
StakingKeeper = types.StakingKeeper
|
StakingKeeper = types.StakingKeeper
|
||||||
SupplyKeeper = types.SupplyKeeper
|
SupplyKeeper = types.SupplyKeeper
|
||||||
USDXMintingClaim = types.USDXMintingClaim
|
USDXMintingClaim = types.USDXMintingClaim
|
||||||
USDXMintingClaims = types.USDXMintingClaims
|
USDXMintingClaims = types.USDXMintingClaims
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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 |
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user