Query rewards via incentive module (#781)

* query rewards types

* query rewards keeper

* query rewards cli/rest

* query rewards alias

* implement branched query

* mirror changes in rest querier

* clean up rest querier
This commit is contained in:
Denali Marsh 2021-01-27 14:33:36 +01:00 committed by GitHub
parent 3a08fc582b
commit 92a2425668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 284 additions and 203 deletions

View File

@ -23,8 +23,7 @@ const (
ModuleName = types.ModuleName
QuerierRoute = types.QuerierRoute
QueryGetClaimPeriods = types.QueryGetClaimPeriods
QueryGetCdpClaims = types.QueryGetCdpClaims
QueryGetHardClaims = types.QueryGetHardClaims
QueryGetRewards = types.QueryGetRewards
QueryGetParams = types.QueryGetParams
QueryGetRewardPeriods = types.QueryGetRewardPeriods
RestClaimCollateralType = types.RestClaimCollateralType
@ -49,8 +48,7 @@ var (
NewMultiplier = types.NewMultiplier
NewParams = types.NewParams
NewPeriod = types.NewPeriod
NewQueryCdpClaimsParams = types.NewQueryCdpClaimsParams
NewQueryHardClaimsParams = types.NewQueryHardClaimsParams
NewQueryRewardsParams = types.NewQueryRewardsParams
NewRewardIndex = types.NewRewardIndex
NewRewardPeriod = types.NewRewardPeriod
NewUSDXMintingClaim = types.NewUSDXMintingClaim
@ -103,8 +101,7 @@ type (
Multipliers = types.Multipliers
Params = types.Params
PostClaimReq = types.PostClaimReq
QueryCdpClaimsParams = types.QueryCdpClaimsParams
QueryHardClaimsParams = types.QueryHardClaimsParams
QueryRewardsParams = types.QueryRewardsParams
RewardIndex = types.RewardIndex
RewardIndexes = types.RewardIndexes
RewardPeriod = types.RewardPeriod

View File

@ -16,6 +16,11 @@ import (
"github.com/kava-labs/kava/x/incentive/types"
)
const (
flagOwner = "owner"
flagType = "type"
)
// GetQueryCmd returns the cli query commands for the incentive module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
incentiveQueryCmd := &cobra.Command{
@ -25,120 +30,85 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
incentiveQueryCmd.AddCommand(flags.GetCommands(
queryParamsCmd(queryRoute, cdc),
queryCdpClaimsCmd(queryRoute, cdc),
queryHardClaimsCmd(queryRoute, cdc),
queryRewardsCmd(queryRoute, cdc),
)...)
return incentiveQueryCmd
}
const (
flagOwner = "owner"
)
func queryCdpClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func queryRewardsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "cdp-claims",
Short: "query USDX minting claims",
Use: "rewards",
Short: "query claimable rewards",
Long: strings.TrimSpace(
fmt.Sprintf(`Query USDX minting claims with optional flag for finding claims for a specifc owner
fmt.Sprintf(`Query rewards with optional flags for owner and type
Example:
$ %s query %s cdp-claims
$ %s query %s cdp-claims --owner kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
$ %s query %s rewards
$ %s query %s rewards --owner kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
$ %s query %s rewards --type hard
$ %s query %s rewards --type usdx-minting
$ %s query %s rewards --type hard --owner kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
`,
version.ClientName, types.ModuleName, version.ClientName, types.ModuleName)),
version.ClientName, types.ModuleName, version.ClientName, types.ModuleName,
version.ClientName, types.ModuleName, version.ClientName, types.ModuleName,
version.ClientName, types.ModuleName)),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
strOwner := viper.GetString(flagOwner)
page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
strOwner := viper.GetString(flagOwner)
strType := viper.GetString(flagType)
// Prepare params for querier
owner, err := sdk.AccAddressFromBech32(strOwner)
if err != nil {
return err
}
params := types.NewQueryCdpClaimsParams(page, limit, owner)
bz, err := cdc.MarshalJSON(params)
switch strings.ToLower(strType) {
case "hard":
params := types.NewQueryHardRewardsParams(page, limit, owner)
claims, err := executeHardRewardsQuery(queryRoute, cdc, cliCtx, params)
if err != nil {
return err
}
// Query
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetCdpClaims)
res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}
cliCtx = cliCtx.WithHeight(height)
var claims types.USDXMintingClaims
if err := cdc.UnmarshalJSON(res, &claims); err != nil {
return fmt.Errorf("failed to unmarshal claims: %w", err)
}
return cliCtx.PrintOutput(claims)
},
}
cmd.Flags().String(flagOwner, "", "(optional) filter by claim owner address")
cmd.Flags().Int(flags.FlagPage, 1, "pagination page of CDPs to to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of CDPs to query for")
return cmd
}
func queryHardClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "hard-claims",
Short: "query Hard liquidity provider claims",
Long: strings.TrimSpace(
fmt.Sprintf(`Query Hard liquidity provider claims with optional flag for finding claims for a specifc owner
Example:
$ %s query %s hard-claims
$ %s query %s hard-claims --owner kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
`,
version.ClientName, types.ModuleName, version.ClientName, types.ModuleName)),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
strOwner := viper.GetString(flagOwner)
page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
// Prepare params for querier
owner, err := sdk.AccAddressFromBech32(strOwner)
case "usdx-minting":
params := types.NewQueryUSDXMintingRewardsParams(page, limit, owner)
claims, err := executeUSDXMintingRewardsQuery(queryRoute, cdc, cliCtx, params)
if err != nil {
return err
}
params := types.NewQueryHardClaimsParams(page, limit, owner)
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}
// Query
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetHardClaims)
res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return err
}
cliCtx = cliCtx.WithHeight(height)
var claims types.USDXMintingClaims
if err := cdc.UnmarshalJSON(res, &claims); err != nil {
return fmt.Errorf("failed to unmarshal claims: %w", err)
}
return cliCtx.PrintOutput(claims)
default:
paramsHard := types.NewQueryHardRewardsParams(page, limit, owner)
hardClaims, err := executeHardRewardsQuery(queryRoute, cdc, cliCtx, paramsHard)
if err != nil {
return err
}
if len(hardClaims) > 0 {
cliCtx.PrintOutput(hardClaims)
}
paramsUSDXMinting := types.NewQueryUSDXMintingRewardsParams(page, limit, owner)
usdxMintingClaims, err := executeUSDXMintingRewardsQuery(queryRoute, cdc, cliCtx, paramsUSDXMinting)
if err != nil {
return err
}
if len(usdxMintingClaims) > 0 {
cliCtx.PrintOutput(usdxMintingClaims)
}
}
return nil
},
}
cmd.Flags().String(flagOwner, "", "(optional) filter by claim owner address")
cmd.Flags().Int(flags.FlagPage, 1, "pagination page of CDPs to to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of CDPs to query for")
cmd.Flags().String(flagOwner, "", "(optional) filter by owner address")
cmd.Flags().String(flagType, "", "(optional) filter by reward type")
cmd.Flags().Int(flags.FlagPage, 1, "pagination page rewards of to to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of rewards to query for")
return cmd
}
@ -168,3 +138,49 @@ func queryParamsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
},
}
}
func executeHardRewardsQuery(queryRoute string, cdc *codec.Codec, cliCtx context.CLIContext,
params types.QueryHardRewardsParams) (types.HardLiquidityProviderClaims, error) {
bz, err := cdc.MarshalJSON(params)
if err != nil {
return types.HardLiquidityProviderClaims{}, err
}
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetHardRewards)
res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return types.HardLiquidityProviderClaims{}, err
}
cliCtx = cliCtx.WithHeight(height)
var claims types.HardLiquidityProviderClaims
if err := cdc.UnmarshalJSON(res, &claims); err != nil {
return types.HardLiquidityProviderClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
}
return claims, nil
}
func executeUSDXMintingRewardsQuery(queryRoute string, cdc *codec.Codec, cliCtx context.CLIContext,
params types.QueryUSDXMintingRewardsParams) (types.USDXMintingClaims, error) {
bz, err := cdc.MarshalJSON(params)
if err != nil {
return types.USDXMintingClaims{}, err
}
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetUSDXMintingRewards)
res, height, err := cliCtx.QueryWithData(route, bz)
if err != nil {
return types.USDXMintingClaims{}, err
}
cliCtx = cliCtx.WithHeight(height)
var claims types.USDXMintingClaims
if err := cdc.UnmarshalJSON(res, &claims); err != nil {
return types.USDXMintingClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
}
return claims, nil
}

View File

@ -15,12 +15,11 @@ import (
)
func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/%s/cdp-claims", types.ModuleName), queryCdpClaimsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/hard-claims", types.ModuleName), queryHardClaimsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/rewards", types.ModuleName), queryRewardsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/parameters", types.ModuleName), queryParamsHandlerFn(cliCtx)).Methods("GET")
}
func queryCdpClaimsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
func queryRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if err != nil {
@ -42,61 +41,23 @@ func queryCdpClaimsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}
queryParams := types.NewQueryCdpClaimsParams(page, limit, owner)
bz, err := cliCtx.Codec.MarshalJSON(queryParams)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
return
var rewardType string
if x := r.URL.Query().Get(types.RestClaimType); len(x) != 0 {
rewardType = strings.ToLower(strings.TrimSpace(x))
}
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/incentive/%s", types.QueryGetCdpClaims), bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
switch strings.ToLower(rewardType) {
case "hard":
params := types.NewQueryHardRewardsParams(page, limit, owner)
executeHardRewardsQuery(w, cliCtx, params)
case "usdx_minting":
params := types.NewQueryUSDXMintingRewardsParams(page, limit, owner)
executeUSDXMintingRewardsQuery(w, cliCtx, params)
default:
hardParams := types.NewQueryHardRewardsParams(page, limit, owner)
usdxMintingParams := types.NewQueryUSDXMintingRewardsParams(page, limit, owner)
executeBothRewardQueries(w, cliCtx, hardParams, usdxMintingParams)
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryHardClaimsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
var owner sdk.AccAddress
if x := r.URL.Query().Get(types.RestClaimOwner); len(x) != 0 {
ownerStr := strings.ToLower(strings.TrimSpace(x))
owner, err = sdk.AccAddressFromBech32(ownerStr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("cannot parse address from claim owner %s", ownerStr))
return
}
}
queryParams := types.NewQueryHardClaimsParams(page, limit, owner)
bz, err := cliCtx.Codec.MarshalJSON(queryParams)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
return
}
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/incentive/%s", types.QueryGetHardClaims), bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}
@ -119,3 +80,67 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
rest.PostProcessResponse(w, cliCtx, res)
}
}
func executeHardRewardsQuery(w http.ResponseWriter, cliCtx context.CLIContext, params types.QueryHardRewardsParams) {
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
return
}
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/incentive/%s", types.QueryGetHardRewards), bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
func executeUSDXMintingRewardsQuery(w http.ResponseWriter, cliCtx context.CLIContext, params types.QueryUSDXMintingRewardsParams) {
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
return
}
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/incentive/%s", types.QueryGetUSDXMintingRewards), bz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
func executeBothRewardQueries(w http.ResponseWriter, cliCtx context.CLIContext,
hardParams types.QueryHardRewardsParams, usdxMintingParams types.QueryUSDXMintingRewardsParams) {
hardBz, err := cliCtx.Codec.MarshalJSON(hardParams)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
return
}
hardRes, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/incentive/%s", types.QueryGetHardRewards), hardBz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
usdxMintingBz, err := cliCtx.Codec.MarshalJSON(usdxMintingParams)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
return
}
usdxMintingRes, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/incentive/%s", types.QueryGetUSDXMintingRewards), usdxMintingBz)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, append(hardRes, usdxMintingRes...))
}

View File

@ -17,10 +17,10 @@ func NewQuerier(k Keeper) sdk.Querier {
switch path[0] {
case types.QueryGetParams:
return queryGetParams(ctx, req, k)
case types.QueryGetCdpClaims:
return queryGetCdpClaims(ctx, req, k)
case types.QueryGetHardClaims:
return queryGetHardClaims(ctx, req, k)
case types.QueryGetHardRewards:
return queryGetHardRewards(ctx, req, k)
case types.QueryGetUSDXMintingRewards:
return queryGetUSDXMintingRewards(ctx, req, k)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint", types.ModuleName)
}
@ -40,60 +40,70 @@ func queryGetParams(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e
return bz, nil
}
func queryGetCdpClaims(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var requestParams types.QueryCdpClaimsParams
err := k.cdc.UnmarshalJSON(req.Data, &requestParams)
func queryGetHardRewards(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var params types.QueryHardRewardsParams
err := types.ModuleCdc.UnmarshalJSON(req.Data, &params)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
var claims types.USDXMintingClaims
if len(requestParams.Owner) > 0 {
claim, _ := k.GetUSDXMintingClaim(ctx, requestParams.Owner)
claims = append(claims, claim)
} else {
claims = k.GetAllUSDXMintingClaims(ctx)
owner := len(params.Owner) > 0
var hardClaims types.HardLiquidityProviderClaims
switch {
case owner:
hardClaim, foundHardClaim := k.GetHardLiquidityProviderClaim(ctx, params.Owner)
if foundHardClaim {
hardClaims = append(hardClaims, hardClaim)
}
default:
hardClaims = k.GetAllHardLiquidityProviderClaims(ctx)
}
var paginatedClaims types.USDXMintingClaims
start, end := client.Paginate(len(claims), requestParams.Page, requestParams.Limit, 100)
if start < 0 || end < 0 {
paginatedClaims = types.USDXMintingClaims{}
var paginatedHardClaims types.HardLiquidityProviderClaims
startH, endH := client.Paginate(len(hardClaims), params.Page, params.Limit, 100)
if startH < 0 || endH < 0 {
paginatedHardClaims = types.HardLiquidityProviderClaims{}
} else {
paginatedClaims = claims[start:end]
paginatedHardClaims = hardClaims[startH:endH]
}
bz, err := codec.MarshalJSONIndent(k.cdc, paginatedClaims)
// Marshal Hard claims
bz, err := codec.MarshalJSONIndent(k.cdc, paginatedHardClaims)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return bz, nil
}
func queryGetHardClaims(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var requestParams types.QueryHardClaimsParams
err := k.cdc.UnmarshalJSON(req.Data, &requestParams)
func queryGetUSDXMintingRewards(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
var params types.QueryUSDXMintingRewardsParams
err := types.ModuleCdc.UnmarshalJSON(req.Data, &params)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
var claims types.HardLiquidityProviderClaims
if len(requestParams.Owner) > 0 {
claim, _ := k.GetHardLiquidityProviderClaim(ctx, requestParams.Owner)
claims = append(claims, claim)
} else {
claims = k.GetAllHardLiquidityProviderClaims(ctx)
owner := len(params.Owner) > 0
var usdxMintingClaims types.USDXMintingClaims
switch {
case owner:
usdxMintingClaim, foundUsdxMintingClaim := k.GetUSDXMintingClaim(ctx, params.Owner)
if foundUsdxMintingClaim {
usdxMintingClaims = append(usdxMintingClaims, usdxMintingClaim)
}
default:
usdxMintingClaims = k.GetAllUSDXMintingClaims(ctx)
}
var paginatedClaims types.HardLiquidityProviderClaims
start, end := client.Paginate(len(claims), requestParams.Page, requestParams.Limit, 100)
if start < 0 || end < 0 {
paginatedClaims = types.HardLiquidityProviderClaims{}
var paginatedUsdxMintingClaims types.USDXMintingClaims
startU, endU := client.Paginate(len(usdxMintingClaims), params.Page, params.Limit, 100)
if startU < 0 || endU < 0 {
paginatedUsdxMintingClaims = types.USDXMintingClaims{}
} else {
paginatedClaims = claims[start:end]
paginatedUsdxMintingClaims = usdxMintingClaims[startU:endU]
}
bz, err := codec.MarshalJSONIndent(k.cdc, paginatedClaims)
// Marshal USDX minting claims
bz, err := codec.MarshalJSONIndent(k.cdc, paginatedUsdxMintingClaims)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}

View File

@ -77,9 +77,15 @@ func NewUSDXMintingClaim(owner sdk.AccAddress, reward sdk.Coin, rewardIndexes Re
}
}
// GetType returns the claim type, used to identify auctions in event attributes
// GetType returns the claim's type
func (c USDXMintingClaim) GetType() string { return USDXMintingClaimType }
// GetReward returns the claim's reward coin
func (c USDXMintingClaim) GetReward() sdk.Coin { return c.Reward }
// GetOwner returns the claim's owner
func (c USDXMintingClaim) GetOwner() sdk.AccAddress { return c.Owner }
// Validate performs a basic check of a Claim fields
func (c USDXMintingClaim) Validate() error {
if err := c.RewardIndexes.Validate(); err != nil {
@ -143,9 +149,15 @@ func NewHardLiquidityProviderClaim(owner sdk.AccAddress, reward sdk.Coin, supply
}
}
// GetType returns the claim type, used to identify auctions in event attributes
// GetType returns the claim's type
func (c HardLiquidityProviderClaim) GetType() string { return HardLiquidityProviderClaimType }
// GetReward returns the claim's reward coin
func (c HardLiquidityProviderClaim) GetReward() sdk.Coin { return c.Reward }
// GetOwner returns the claim's owner
func (c HardLiquidityProviderClaim) GetOwner() sdk.AccAddress { return c.Owner }
// Validate performs a basic check of a HardLiquidityProviderClaim fields
func (c HardLiquidityProviderClaim) Validate() error {
if err := c.SupplyRewardIndexes.Validate(); err != nil {

View File

@ -17,4 +17,5 @@ var (
ErrInvalidMultiplier = sdkerrors.Register(ModuleName, 8, "invalid rewards multiplier")
ErrZeroClaim = sdkerrors.Register(ModuleName, 9, "cannot claim - claim amount rounds to zero")
ErrClaimExpired = sdkerrors.Register(ModuleName, 10, "claim has expired")
ErrInvalidClaimType = sdkerrors.Register(ModuleName, 11, "invalid claim type")
)

View File

@ -7,41 +7,61 @@ import (
// Querier routes for the incentive module
const (
QueryGetCdpClaims = "cdp-claims"
QueryGetHardClaims = "hard-claims"
RestClaimOwner = "owner"
RestClaimCollateralType = "collateral_type"
QueryGetRewards = "rewards"
QueryGetHardRewards = "hard-rewards"
QueryGetUSDXMintingRewards = "usdx-minting-rewards"
QueryGetParams = "parameters"
QueryGetRewardPeriods = "reward-periods"
QueryGetClaimPeriods = "claim-periods"
RestClaimCollateralType = "collateral_type"
RestClaimOwner = "owner"
RestClaimType = "type"
)
// QueryCdpClaimsParams params for query /incentive/claims
type QueryCdpClaimsParams struct {
// QueryRewardsParams params for query /incentive/rewards
type QueryRewardsParams struct {
Page int `json:"page" yaml:"page"`
Limit int `json:"limit" yaml:"limit"`
Owner sdk.AccAddress
Type string
}
// NewQueryRewardsParams returns QueryRewardsParams
func NewQueryRewardsParams(page, limit int, owner sdk.AccAddress, rewardType string) QueryRewardsParams {
return QueryRewardsParams{
Page: page,
Limit: limit,
Owner: owner,
Type: rewardType,
}
}
// QueryUSDXMintingRewardsParams params for query /incentive/rewards type usdx-minting
type QueryUSDXMintingRewardsParams struct {
Page int `json:"page" yaml:"page"`
Limit int `json:"limit" yaml:"limit"`
Owner sdk.AccAddress
}
// NewQueryCdpClaimsParams returns QueryCdpClaimsParams
func NewQueryCdpClaimsParams(page, limit int, owner sdk.AccAddress) QueryCdpClaimsParams {
return QueryCdpClaimsParams{
// NewQueryUSDXMintingRewardsParams returns QueryUSDXMintingRewardsParams
func NewQueryUSDXMintingRewardsParams(page, limit int, owner sdk.AccAddress) QueryUSDXMintingRewardsParams {
return QueryUSDXMintingRewardsParams{
Page: page,
Limit: limit,
Owner: owner,
}
}
// QueryHardClaimsParams params for query /incentive/claims
type QueryHardClaimsParams struct {
// QueryHardRewardsParams params for query /incentive/rewards type hard
type QueryHardRewardsParams struct {
Page int `json:"page" yaml:"page"`
Limit int `json:"limit" yaml:"limit"`
Owner sdk.AccAddress
}
// NewQueryHardClaimsParams returns QueryHardClaimsParams
func NewQueryHardClaimsParams(page, limit int, owner sdk.AccAddress) QueryHardClaimsParams {
return QueryHardClaimsParams{
// NewQueryHardRewardsParams returns QueryHardRewardsParams
func NewQueryHardRewardsParams(page, limit int, owner sdk.AccAddress) QueryHardRewardsParams {
return QueryHardRewardsParams{
Page: page,
Limit: limit,
Owner: owner,