mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
Harvest: refactor deposit type to claim type (#716)
* status: refactor deposit type to claim type * refactor all deposit types to claim types * refactor msg withdraw * update module errors * refactor querier and rest * update spec * update tests * update handler, alias * refactor to IterateDepositsByDenom * v0_12 legacy types * fix build
This commit is contained in:
parent
510b7e7c04
commit
df2c4271e4
@ -15,9 +15,9 @@ const (
|
|||||||
AttributeKeyClaimAmount = types.AttributeKeyClaimAmount
|
AttributeKeyClaimAmount = types.AttributeKeyClaimAmount
|
||||||
AttributeKeyClaimHolder = types.AttributeKeyClaimHolder
|
AttributeKeyClaimHolder = types.AttributeKeyClaimHolder
|
||||||
AttributeKeyClaimMultiplier = types.AttributeKeyClaimMultiplier
|
AttributeKeyClaimMultiplier = types.AttributeKeyClaimMultiplier
|
||||||
|
AttributeKeyClaimType = types.AttributeKeyClaimType
|
||||||
AttributeKeyDeposit = types.AttributeKeyDeposit
|
AttributeKeyDeposit = types.AttributeKeyDeposit
|
||||||
AttributeKeyDepositDenom = types.AttributeKeyDepositDenom
|
AttributeKeyDepositDenom = types.AttributeKeyDepositDenom
|
||||||
AttributeKeyDepositType = types.AttributeKeyDepositType
|
|
||||||
AttributeKeyDepositor = types.AttributeKeyDepositor
|
AttributeKeyDepositor = types.AttributeKeyDepositor
|
||||||
AttributeKeyRewardsDistribution = types.AttributeKeyRewardsDistribution
|
AttributeKeyRewardsDistribution = types.AttributeKeyRewardsDistribution
|
||||||
AttributeValueCategory = types.AttributeValueCategory
|
AttributeValueCategory = types.AttributeValueCategory
|
||||||
@ -82,8 +82,7 @@ var (
|
|||||||
DefaultGovSchedules = types.DefaultGovSchedules
|
DefaultGovSchedules = types.DefaultGovSchedules
|
||||||
DefaultLPSchedules = types.DefaultLPSchedules
|
DefaultLPSchedules = types.DefaultLPSchedules
|
||||||
DefaultPreviousBlockTime = types.DefaultPreviousBlockTime
|
DefaultPreviousBlockTime = types.DefaultPreviousBlockTime
|
||||||
DepositTypesClaimQuery = types.DepositTypesClaimQuery
|
ClaimTypesClaimQuery = types.ClaimTypesClaimQuery
|
||||||
DepositTypesDepositQuery = types.DepositTypesDepositQuery
|
|
||||||
DepositsKeyPrefix = types.DepositsKeyPrefix
|
DepositsKeyPrefix = types.DepositsKeyPrefix
|
||||||
ErrAccountNotFound = types.ErrAccountNotFound
|
ErrAccountNotFound = types.ErrAccountNotFound
|
||||||
ErrClaimExpired = types.ErrClaimExpired
|
ErrClaimExpired = types.ErrClaimExpired
|
||||||
@ -91,10 +90,10 @@ var (
|
|||||||
ErrDepositNotFound = types.ErrDepositNotFound
|
ErrDepositNotFound = types.ErrDepositNotFound
|
||||||
ErrGovScheduleNotFound = types.ErrGovScheduleNotFound
|
ErrGovScheduleNotFound = types.ErrGovScheduleNotFound
|
||||||
ErrInsufficientModAccountBalance = types.ErrInsufficientModAccountBalance
|
ErrInsufficientModAccountBalance = types.ErrInsufficientModAccountBalance
|
||||||
ErrInvaliWithdrawAmount = types.ErrInvaliWithdrawAmount
|
ErrInvaliWithdrawAmount = types.ErrInvalidWithdrawAmount
|
||||||
ErrInvalidAccountType = types.ErrInvalidAccountType
|
ErrInvalidAccountType = types.ErrInvalidAccountType
|
||||||
ErrInvalidDepositDenom = types.ErrInvalidDepositDenom
|
ErrInvalidDepositDenom = types.ErrInvalidDepositDenom
|
||||||
ErrInvalidDepositType = types.ErrInvalidDepositType
|
ErrInvalidClaimType = types.ErrInvalidClaimType
|
||||||
ErrInvalidMultiplier = types.ErrInvalidMultiplier
|
ErrInvalidMultiplier = types.ErrInvalidMultiplier
|
||||||
ErrLPScheduleNotFound = types.ErrLPScheduleNotFound
|
ErrLPScheduleNotFound = types.ErrLPScheduleNotFound
|
||||||
ErrZeroClaim = types.ErrZeroClaim
|
ErrZeroClaim = types.ErrZeroClaim
|
||||||
@ -116,7 +115,7 @@ type (
|
|||||||
DelegatorDistributionSchedule = types.DelegatorDistributionSchedule
|
DelegatorDistributionSchedule = types.DelegatorDistributionSchedule
|
||||||
DelegatorDistributionSchedules = types.DelegatorDistributionSchedules
|
DelegatorDistributionSchedules = types.DelegatorDistributionSchedules
|
||||||
Deposit = types.Deposit
|
Deposit = types.Deposit
|
||||||
DepositType = types.DepositType
|
ClaimType = types.ClaimType
|
||||||
DistributionSchedule = types.DistributionSchedule
|
DistributionSchedule = types.DistributionSchedule
|
||||||
DistributionSchedules = types.DistributionSchedules
|
DistributionSchedules = types.DistributionSchedules
|
||||||
GenesisDistributionTime = types.GenesisDistributionTime
|
GenesisDistributionTime = types.GenesisDistributionTime
|
||||||
|
@ -22,7 +22,7 @@ const (
|
|||||||
flagName = "name"
|
flagName = "name"
|
||||||
flagDepositDenom = "deposit-denom"
|
flagDepositDenom = "deposit-denom"
|
||||||
flagOwner = "owner"
|
flagOwner = "owner"
|
||||||
flagDepositType = "deposit-type"
|
flagClaimType = "claim-type"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetQueryCmd returns the cli query commands for the harvest module
|
// GetQueryCmd returns the cli query commands for the harvest module
|
||||||
@ -122,8 +122,8 @@ func queryDepositsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
$ kvcli q harvest deposits
|
$ kvcli q harvest deposits
|
||||||
$ kvcli q harvest deposits --owner kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny --deposit-type lp --deposit-denom bnb
|
$ kvcli q harvest deposits --owner kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny --deposit-denom bnb
|
||||||
$ kvcli q harvest deposits --deposit-type stake --deposit-denom ukava
|
$ kvcli q harvest deposits --deposit-denom ukava
|
||||||
$ kvcli q harvest deposits --deposit-denom btcb`,
|
$ kvcli q harvest deposits --deposit-denom btcb`,
|
||||||
),
|
),
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
@ -131,11 +131,9 @@ func queryDepositsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
var owner sdk.AccAddress
|
var owner sdk.AccAddress
|
||||||
var depositType types.DepositType
|
|
||||||
|
|
||||||
ownerBech := viper.GetString(flagOwner)
|
ownerBech := viper.GetString(flagOwner)
|
||||||
depositDenom := viper.GetString(flagDepositDenom)
|
depositDenom := viper.GetString(flagDepositDenom)
|
||||||
depositTypeStr := viper.GetString(flagDepositType)
|
|
||||||
|
|
||||||
if len(ownerBech) != 0 {
|
if len(ownerBech) != 0 {
|
||||||
depositOwner, err := sdk.AccAddressFromBech32(ownerBech)
|
depositOwner, err := sdk.AccAddressFromBech32(ownerBech)
|
||||||
@ -145,17 +143,10 @@ func queryDepositsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
owner = depositOwner
|
owner = depositOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(depositTypeStr) != 0 {
|
|
||||||
if err := types.DepositType(depositTypeStr).IsValid(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
depositType = types.DepositType(depositTypeStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
page := viper.GetInt(flags.FlagPage)
|
page := viper.GetInt(flags.FlagPage)
|
||||||
limit := viper.GetInt(flags.FlagLimit)
|
limit := viper.GetInt(flags.FlagLimit)
|
||||||
|
|
||||||
params := types.NewQueryDepositParams(page, limit, depositDenom, owner, depositType)
|
params := types.NewQueryDepositParams(page, limit, depositDenom, owner)
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -179,7 +170,6 @@ func queryDepositsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit (max 100)")
|
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit (max 100)")
|
||||||
cmd.Flags().String(flagOwner, "", "(optional) filter for deposits by owner address")
|
cmd.Flags().String(flagOwner, "", "(optional) filter for deposits by owner address")
|
||||||
cmd.Flags().String(flagDepositDenom, "", "(optional) filter for deposits by denom")
|
cmd.Flags().String(flagDepositDenom, "", "(optional) filter for deposits by denom")
|
||||||
cmd.Flags().String(flagDepositType, "", "(optional) filter for deposits by type (lp or staking)")
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +181,8 @@ func queryClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
$ kvcli q harvest claims
|
$ kvcli q harvest claims
|
||||||
$ kvcli q harvest claims --owner kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny --deposit-type lp --deposit-denom bnb
|
$ kvcli q harvest claims --owner kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny --claim-type lp --deposit-denom bnb
|
||||||
$ kvcli q harvest claims --deposit-type stake --deposit-denom ukava
|
$ kvcli q harvest claims --claim-type stake --deposit-denom ukava
|
||||||
$ kvcli q harvest claims --deposit-denom btcb`,
|
$ kvcli q harvest claims --deposit-denom btcb`,
|
||||||
),
|
),
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
@ -200,11 +190,11 @@ func queryClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
|
|
||||||
var owner sdk.AccAddress
|
var owner sdk.AccAddress
|
||||||
var depositType types.DepositType
|
var claimType types.ClaimType
|
||||||
|
|
||||||
ownerBech := viper.GetString(flagOwner)
|
ownerBech := viper.GetString(flagOwner)
|
||||||
depositDenom := viper.GetString(flagDepositDenom)
|
depositDenom := viper.GetString(flagDepositDenom)
|
||||||
depositTypeStr := viper.GetString(flagDepositType)
|
claimTypeStr := viper.GetString(flagClaimType)
|
||||||
|
|
||||||
if len(ownerBech) != 0 {
|
if len(ownerBech) != 0 {
|
||||||
claimOwner, err := sdk.AccAddressFromBech32(ownerBech)
|
claimOwner, err := sdk.AccAddressFromBech32(ownerBech)
|
||||||
@ -214,17 +204,17 @@ func queryClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
owner = claimOwner
|
owner = claimOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(depositTypeStr) != 0 {
|
if len(claimTypeStr) != 0 {
|
||||||
if err := types.DepositType(depositTypeStr).IsValid(); err != nil {
|
if err := types.ClaimType(claimTypeStr).IsValid(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
depositType = types.DepositType(depositTypeStr)
|
claimType = types.ClaimType(claimTypeStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
page := viper.GetInt(flags.FlagPage)
|
page := viper.GetInt(flags.FlagPage)
|
||||||
limit := viper.GetInt(flags.FlagLimit)
|
limit := viper.GetInt(flags.FlagLimit)
|
||||||
|
|
||||||
params := types.NewQueryDepositParams(page, limit, depositDenom, owner, depositType)
|
params := types.NewQueryClaimParams(page, limit, depositDenom, owner, claimType)
|
||||||
bz, err := cdc.MarshalJSON(params)
|
bz, err := cdc.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -248,7 +238,7 @@ func queryClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|||||||
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit (max 100)")
|
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit (max 100)")
|
||||||
cmd.Flags().String(flagOwner, "", "(optional) filter for claims by owner address")
|
cmd.Flags().String(flagOwner, "", "(optional) filter for claims by owner address")
|
||||||
cmd.Flags().String(flagDepositDenom, "", "(optional) filter for claims by denom")
|
cmd.Flags().String(flagDepositDenom, "", "(optional) filter for claims by denom")
|
||||||
cmd.Flags().String(flagDepositType, "", "(optional) filter for claims by type (lp or staking)")
|
cmd.Flags().String(flagClaimType, "", "(optional) filter for claims by type (lp or staking)")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +41,10 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||||||
|
|
||||||
func getCmdDeposit(cdc *codec.Codec) *cobra.Command {
|
func getCmdDeposit(cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "deposit [amount] [deposit-type]",
|
Use: "deposit [amount]",
|
||||||
Short: "deposit coins to harvest",
|
Short: "deposit coins to harvest",
|
||||||
Args: cobra.ExactArgs(2),
|
|
||||||
Example: fmt.Sprintf(
|
Example: fmt.Sprintf(
|
||||||
`%s tx %s deposit 10000000bnb lp --from <key>`, version.ClientName, types.ModuleName,
|
`%s tx %s deposit 10000000bnb --from <key>`, version.ClientName, types.ModuleName,
|
||||||
),
|
),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||||
@ -55,7 +54,7 @@ func getCmdDeposit(cdc *codec.Codec) *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
msg := types.NewMsgDeposit(cliCtx.GetFromAddress(), amount, args[1])
|
msg := types.NewMsgDeposit(cliCtx.GetFromAddress(), amount)
|
||||||
if err := msg.ValidateBasic(); err != nil {
|
if err := msg.ValidateBasic(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -66,11 +65,11 @@ func getCmdDeposit(cdc *codec.Codec) *cobra.Command {
|
|||||||
|
|
||||||
func getCmdWithdraw(cdc *codec.Codec) *cobra.Command {
|
func getCmdWithdraw(cdc *codec.Codec) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "withdraw [amount] [deposit-type]",
|
Use: "withdraw [amount]",
|
||||||
Short: "withdraw coins from harvest",
|
Short: "withdraw coins from harvest",
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(1),
|
||||||
Example: fmt.Sprintf(
|
Example: fmt.Sprintf(
|
||||||
`%s tx %s withdraw 10000000bnb lp --from <key>`, version.ClientName, types.ModuleName,
|
`%s tx %s withdraw 10000000bnb --from <key>`, version.ClientName, types.ModuleName,
|
||||||
),
|
),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||||
@ -80,7 +79,7 @@ func getCmdWithdraw(cdc *codec.Codec) *cobra.Command {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
msg := types.NewMsgWithdraw(cliCtx.GetFromAddress(), amount, args[1])
|
msg := types.NewMsgWithdraw(cliCtx.GetFromAddress(), amount)
|
||||||
if err := msg.ValidateBasic(); err != nil {
|
if err := msg.ValidateBasic(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,6 @@ func queryDepositsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
|
|
||||||
var depositDenom string
|
var depositDenom string
|
||||||
var depositOwner sdk.AccAddress
|
var depositOwner sdk.AccAddress
|
||||||
var depositType types.DepositType
|
|
||||||
|
|
||||||
if x := r.URL.Query().Get(RestDenom); len(x) != 0 {
|
if x := r.URL.Query().Get(RestDenom); len(x) != 0 {
|
||||||
depositDenom = strings.TrimSpace(x)
|
depositDenom = strings.TrimSpace(x)
|
||||||
@ -71,17 +70,7 @@ func queryDepositsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if x := r.URL.Query().Get(RestType); len(x) != 0 {
|
params := types.NewQueryDepositParams(page, limit, depositDenom, depositOwner)
|
||||||
depositTypeStr := strings.ToLower(strings.TrimSpace(x))
|
|
||||||
err := types.DepositType(depositTypeStr).IsValid()
|
|
||||||
if err != nil {
|
|
||||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
depositType = types.DepositType(depositTypeStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
params := types.NewQueryDepositParams(page, limit, depositDenom, depositOwner, depositType)
|
|
||||||
|
|
||||||
bz, err := cliCtx.Codec.MarshalJSON(params)
|
bz, err := cliCtx.Codec.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -115,7 +104,7 @@ func queryClaimsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
|
|
||||||
var depositDenom string
|
var depositDenom string
|
||||||
var claimOwner sdk.AccAddress
|
var claimOwner sdk.AccAddress
|
||||||
var depositType types.DepositType
|
var claimType types.ClaimType
|
||||||
|
|
||||||
if x := r.URL.Query().Get(RestDenom); len(x) != 0 {
|
if x := r.URL.Query().Get(RestDenom); len(x) != 0 {
|
||||||
depositDenom = strings.TrimSpace(x)
|
depositDenom = strings.TrimSpace(x)
|
||||||
@ -131,16 +120,16 @@ func queryClaimsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if x := r.URL.Query().Get(RestType); len(x) != 0 {
|
if x := r.URL.Query().Get(RestType); len(x) != 0 {
|
||||||
depositTypeStr := strings.ToLower(strings.TrimSpace(x))
|
claimTypeStr := strings.ToLower(strings.TrimSpace(x))
|
||||||
err := types.DepositType(depositTypeStr).IsValid()
|
err := types.ClaimType(claimTypeStr).IsValid()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
depositType = types.DepositType(depositTypeStr)
|
claimType = types.ClaimType(claimTypeStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
params := types.NewQueryDepositParams(page, limit, depositDenom, claimOwner, depositType)
|
params := types.NewQueryClaimParams(page, limit, depositDenom, claimOwner, claimType)
|
||||||
|
|
||||||
bz, err := cliCtx.Codec.MarshalJSON(params)
|
bz, err := cliCtx.Codec.MarshalJSON(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,7 +33,7 @@ func postDepositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := types.NewMsgDeposit(req.From, req.Amount, strings.ToLower(req.DepositType))
|
msg := types.NewMsgDeposit(req.From, req.Amount)
|
||||||
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
|
||||||
@ -54,7 +54,7 @@ func postWithdrawHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := types.NewMsgWithdraw(req.From, req.Amount, strings.ToLower(req.DepositType))
|
msg := types.NewMsgWithdraw(req.From, req.Amount)
|
||||||
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
|
||||||
|
@ -30,7 +30,7 @@ func NewHandler(k Keeper) sdk.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgClaimReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimReward) (*sdk.Result, error) {
|
func handleMsgClaimReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimReward) (*sdk.Result, error) {
|
||||||
err := k.ClaimReward(ctx, msg.Sender, msg.Receiver, msg.DepositDenom, types.DepositType(strings.ToLower(msg.DepositType)), types.MultiplierName(strings.ToLower(msg.MultiplierName)))
|
err := k.ClaimReward(ctx, msg.Sender, msg.Receiver, msg.DepositDenom, types.ClaimType(strings.ToLower(msg.ClaimType)), types.MultiplierName(strings.ToLower(msg.MultiplierName)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ func handleMsgClaimReward(ctx sdk.Context, k keeper.Keeper, msg types.MsgClaimRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgDeposit(ctx sdk.Context, k keeper.Keeper, msg types.MsgDeposit) (*sdk.Result, error) {
|
func handleMsgDeposit(ctx sdk.Context, k keeper.Keeper, msg types.MsgDeposit) (*sdk.Result, error) {
|
||||||
err := k.Deposit(ctx, msg.Depositor, msg.Amount, types.DepositType(strings.ToLower(msg.DepositType)))
|
err := k.Deposit(ctx, msg.Depositor, msg.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ func handleMsgDeposit(ctx sdk.Context, k keeper.Keeper, msg types.MsgDeposit) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgWithdraw(ctx sdk.Context, k keeper.Keeper, msg types.MsgWithdraw) (*sdk.Result, error) {
|
func handleMsgWithdraw(ctx sdk.Context, k keeper.Keeper, msg types.MsgWithdraw) (*sdk.Result, error) {
|
||||||
err := k.Withdraw(ctx, msg.Depositor, msg.Amount, types.DepositType(strings.ToLower(msg.DepositType)))
|
err := k.Withdraw(ctx, msg.Depositor, msg.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ func (suite *KeeperTestSuite) TestBorrow() {
|
|||||||
// Deposit coins to harvest
|
// Deposit coins to harvest
|
||||||
depositedCoins := sdk.NewCoins()
|
depositedCoins := sdk.NewCoins()
|
||||||
for _, depositCoin := range tc.args.depositCoins {
|
for _, depositCoin := range tc.args.depositCoins {
|
||||||
err = suite.keeper.Deposit(suite.ctx, tc.args.borrower, depositCoin, types.LP)
|
err = suite.keeper.Deposit(suite.ctx, tc.args.borrower, depositCoin)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
depositedCoins.Add(depositCoin)
|
depositedCoins.Add(depositCoin)
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ClaimReward sends the reward amount to the reward owner and deletes the claim from the store
|
// ClaimReward sends the reward amount to the reward owner and deletes the claim from the store
|
||||||
func (k Keeper) ClaimReward(ctx sdk.Context, claimHolder sdk.AccAddress, receiver sdk.AccAddress, depositDenom string, depositType types.DepositType, multiplier types.MultiplierName) error {
|
func (k Keeper) ClaimReward(ctx sdk.Context, claimHolder sdk.AccAddress, receiver sdk.AccAddress, depositDenom string, claimType types.ClaimType, multiplier types.MultiplierName) error {
|
||||||
|
|
||||||
claim, found := k.GetClaim(ctx, claimHolder, depositDenom, depositType)
|
claim, found := k.GetClaim(ctx, claimHolder, depositDenom, claimType)
|
||||||
if !found {
|
if !found {
|
||||||
return sdkerrors.Wrapf(types.ErrClaimNotFound, "no %s %s claim found for %s", depositDenom, depositType, claimHolder)
|
return sdkerrors.Wrapf(types.ErrClaimNotFound, "no %s %s claim found for %s", depositDenom, claimType, claimHolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := k.validateSenderReceiver(ctx, claimHolder, receiver)
|
err := k.validateSenderReceiver(ctx, claimHolder, receiver)
|
||||||
@ -32,13 +32,13 @@ func (k Keeper) ClaimReward(ctx sdk.Context, claimHolder sdk.AccAddress, receive
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch depositType {
|
switch claimType {
|
||||||
case types.LP:
|
case types.LP:
|
||||||
err = k.claimLPReward(ctx, claim, receiver, multiplier)
|
err = k.claimLPReward(ctx, claim, receiver, multiplier)
|
||||||
case types.Stake:
|
case types.Stake:
|
||||||
err = k.claimDelegatorReward(ctx, claim, receiver, multiplier)
|
err = k.claimDelegatorReward(ctx, claim, receiver, multiplier)
|
||||||
default:
|
default:
|
||||||
return sdkerrors.Wrap(types.ErrInvalidDepositType, string(depositType))
|
return sdkerrors.Wrap(types.ErrInvalidClaimType, string(claimType))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -49,7 +49,7 @@ func (k Keeper) ClaimReward(ctx sdk.Context, claimHolder sdk.AccAddress, receive
|
|||||||
sdk.NewAttribute(sdk.AttributeKeyAmount, claim.Amount.String()),
|
sdk.NewAttribute(sdk.AttributeKeyAmount, claim.Amount.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyClaimHolder, claimHolder.String()),
|
sdk.NewAttribute(types.AttributeKeyClaimHolder, claimHolder.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositDenom, depositDenom),
|
sdk.NewAttribute(types.AttributeKeyDepositDenom, depositDenom),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositType, string(depositType)),
|
sdk.NewAttribute(types.AttributeKeyClaimType, string(claimType)),
|
||||||
sdk.NewAttribute(types.AttributeKeyClaimMultiplier, string(multiplier)),
|
sdk.NewAttribute(types.AttributeKeyClaimMultiplier, string(multiplier)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner sdk.AccAddress
|
claimOwner sdk.AccAddress
|
||||||
receiver sdk.AccAddress
|
receiver sdk.AccAddress
|
||||||
denom string
|
denom string
|
||||||
depositType types.DepositType
|
claimType types.ClaimType
|
||||||
multiplier types.MultiplierName
|
multiplier types.MultiplierName
|
||||||
blockTime time.Time
|
blockTime time.Time
|
||||||
createClaim bool
|
createClaim bool
|
||||||
@ -47,7 +47,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -69,7 +69,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.Stake,
|
claimType: types.Stake,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -113,7 +113,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -135,7 +135,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test2"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test2"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -157,7 +157,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -179,7 +179,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: false,
|
createClaim: false,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -201,7 +201,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2022, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2022, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -223,7 +223,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
claimOwner: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test2"))),
|
receiver: sdk.AccAddress(crypto.AddressHash([]byte("test2"))),
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
createClaim: true,
|
createClaim: true,
|
||||||
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
claimAmount: sdk.NewCoin("hard", sdk.NewInt(100)),
|
||||||
@ -303,17 +303,17 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
suite.keeper = keeper
|
suite.keeper = keeper
|
||||||
|
|
||||||
if tc.args.createClaim {
|
if tc.args.createClaim {
|
||||||
claim := types.NewClaim(tc.args.claimOwner, tc.args.denom, tc.args.claimAmount, tc.args.depositType)
|
claim := types.NewClaim(tc.args.claimOwner, tc.args.denom, tc.args.claimAmount, tc.args.claimType)
|
||||||
suite.Require().NotPanics(func() { suite.keeper.SetClaim(suite.ctx, claim) })
|
suite.Require().NotPanics(func() { suite.keeper.SetClaim(suite.ctx, claim) })
|
||||||
}
|
}
|
||||||
|
|
||||||
err := suite.keeper.ClaimReward(suite.ctx, tc.args.claimOwner, tc.args.receiver, tc.args.denom, tc.args.depositType, tc.args.multiplier)
|
err := suite.keeper.ClaimReward(suite.ctx, tc.args.claimOwner, tc.args.receiver, tc.args.denom, tc.args.claimType, tc.args.multiplier)
|
||||||
if tc.errArgs.expectPass {
|
if tc.errArgs.expectPass {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
acc := suite.getAccount(tc.args.receiver)
|
acc := suite.getAccount(tc.args.receiver)
|
||||||
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
||||||
mAcc := suite.getModuleAccount(types.LPAccount)
|
mAcc := suite.getModuleAccount(types.LPAccount)
|
||||||
if tc.args.depositType == types.Stake {
|
if tc.args.claimType == types.Stake {
|
||||||
mAcc = suite.getModuleAccount(types.DelegatorAccount)
|
mAcc = suite.getModuleAccount(types.DelegatorAccount)
|
||||||
}
|
}
|
||||||
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
||||||
@ -324,7 +324,7 @@ func (suite *KeeperTestSuite) TestClaim() {
|
|||||||
} else {
|
} else {
|
||||||
suite.Require().False(ok)
|
suite.Require().False(ok)
|
||||||
}
|
}
|
||||||
_, f := suite.keeper.GetClaim(ctx, tc.args.claimOwner, tc.args.denom, tc.args.depositType)
|
_, f := suite.keeper.GetClaim(ctx, tc.args.claimOwner, tc.args.denom, tc.args.claimType)
|
||||||
suite.Require().False(f)
|
suite.Require().False(f)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
|
@ -9,26 +9,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Deposit deposit
|
// Deposit deposit
|
||||||
func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.Coin, depositType types.DepositType) error {
|
func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.Coin) error {
|
||||||
|
|
||||||
err := k.ValidateDeposit(ctx, amount, depositType)
|
err := k.ValidateDeposit(ctx, amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch depositType {
|
err = k.supplyKeeper.SendCoinsFromAccountToModule(ctx, depositor, types.ModuleAccountName, sdk.NewCoins(amount))
|
||||||
case types.LP:
|
|
||||||
err = k.supplyKeeper.SendCoinsFromAccountToModule(ctx, depositor, types.ModuleAccountName, sdk.NewCoins(amount))
|
|
||||||
default:
|
|
||||||
return sdkerrors.Wrap(types.ErrInvalidDepositType, string(depositType))
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
deposit, found := k.GetDeposit(ctx, depositor, amount.Denom, depositType)
|
deposit, found := k.GetDeposit(ctx, depositor, amount.Denom)
|
||||||
if !found {
|
if !found {
|
||||||
deposit = types.NewDeposit(depositor, amount, depositType)
|
deposit = types.NewDeposit(depositor, amount)
|
||||||
} else {
|
} else {
|
||||||
deposit.Amount = deposit.Amount.Add(amount)
|
deposit.Amount = deposit.Amount.Add(amount)
|
||||||
}
|
}
|
||||||
@ -41,7 +36,6 @@ func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.Co
|
|||||||
sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()),
|
sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositor, deposit.Depositor.String()),
|
sdk.NewAttribute(types.AttributeKeyDepositor, deposit.Depositor.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositDenom, deposit.Amount.Denom),
|
sdk.NewAttribute(types.AttributeKeyDepositDenom, deposit.Amount.Denom),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositType, string(depositType)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,22 +43,7 @@ func (k Keeper) Deposit(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ValidateDeposit validates a deposit
|
// ValidateDeposit validates a deposit
|
||||||
func (k Keeper) ValidateDeposit(ctx sdk.Context, amount sdk.Coin, depositType types.DepositType) error {
|
func (k Keeper) ValidateDeposit(ctx sdk.Context, amount sdk.Coin) error {
|
||||||
var err error
|
|
||||||
switch depositType {
|
|
||||||
case types.LP:
|
|
||||||
err = k.ValidateLPDeposit(ctx, amount, depositType)
|
|
||||||
default:
|
|
||||||
return sdkerrors.Wrap(types.ErrInvalidDepositType, string(depositType))
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateLPDeposit validates that a liquidity provider deposit
|
|
||||||
func (k Keeper) ValidateLPDeposit(ctx sdk.Context, amount sdk.Coin, depositType types.DepositType) error {
|
|
||||||
params := k.GetParams(ctx)
|
params := k.GetParams(ctx)
|
||||||
for _, lps := range params.LiquidityProviderSchedules {
|
for _, lps := range params.LiquidityProviderSchedules {
|
||||||
if lps.DepositDenom == amount.Denom {
|
if lps.DepositDenom == amount.Denom {
|
||||||
@ -75,22 +54,16 @@ func (k Keeper) ValidateLPDeposit(ctx sdk.Context, amount sdk.Coin, depositType
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Withdraw returns some or all of a deposit back to original depositor
|
// Withdraw returns some or all of a deposit back to original depositor
|
||||||
func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.Coin, depositType types.DepositType) error {
|
func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.Coin) error {
|
||||||
deposit, found := k.GetDeposit(ctx, depositor, amount.Denom, depositType)
|
deposit, found := k.GetDeposit(ctx, depositor, amount.Denom)
|
||||||
if !found {
|
if !found {
|
||||||
return sdkerrors.Wrapf(types.ErrDepositNotFound, "no %s %s deposit found for %s", amount.Denom, depositType, depositor)
|
return sdkerrors.Wrapf(types.ErrDepositNotFound, "no %s deposit found for %s", amount.Denom, depositor)
|
||||||
}
|
}
|
||||||
if !deposit.Amount.IsGTE(amount) {
|
if !deposit.Amount.IsGTE(amount) {
|
||||||
return sdkerrors.Wrapf(types.ErrInvaliWithdrawAmount, "%s>%s", amount, deposit.Amount)
|
return sdkerrors.Wrapf(types.ErrInvalidWithdrawAmount, "%s>%s", amount, deposit.Amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, depositor, sdk.NewCoins(amount))
|
||||||
switch depositType {
|
|
||||||
case types.LP:
|
|
||||||
err = k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, depositor, sdk.NewCoins(amount))
|
|
||||||
default:
|
|
||||||
return sdkerrors.Wrap(types.ErrInvalidDepositType, string(depositType))
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -101,7 +74,6 @@ func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.C
|
|||||||
sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()),
|
sdk.NewAttribute(sdk.AttributeKeyAmount, amount.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositor, depositor.String()),
|
sdk.NewAttribute(types.AttributeKeyDepositor, depositor.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositDenom, amount.Denom),
|
sdk.NewAttribute(types.AttributeKeyDepositDenom, amount.Denom),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositType, string(depositType)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,7 +83,6 @@ func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.C
|
|||||||
types.EventTypeDeleteHarvestDeposit,
|
types.EventTypeDeleteHarvestDeposit,
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositor, depositor.String()),
|
sdk.NewAttribute(types.AttributeKeyDepositor, depositor.String()),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositDenom, amount.Denom),
|
sdk.NewAttribute(types.AttributeKeyDepositDenom, amount.Denom),
|
||||||
sdk.NewAttribute(types.AttributeKeyDepositType, string(depositType)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
k.DeleteDeposit(ctx, deposit)
|
k.DeleteDeposit(ctx, deposit)
|
||||||
@ -125,12 +96,8 @@ func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, amount sdk.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTotalDeposited returns the total amount deposited for the input deposit type and deposit denom
|
// GetTotalDeposited returns the total amount deposited for the input deposit type and deposit denom
|
||||||
func (k Keeper) GetTotalDeposited(ctx sdk.Context, depositType types.DepositType, depositDenom string) (total sdk.Int) {
|
func (k Keeper) GetTotalDeposited(ctx sdk.Context, depositDenom string) (total sdk.Int) {
|
||||||
|
|
||||||
var macc supplyExported.ModuleAccountI
|
var macc supplyExported.ModuleAccountI
|
||||||
switch depositType {
|
macc = k.supplyKeeper.GetModuleAccount(ctx, types.ModuleAccountName)
|
||||||
case types.LP:
|
|
||||||
macc = k.supplyKeeper.GetModuleAccount(ctx, types.ModuleAccountName)
|
|
||||||
}
|
|
||||||
return macc.GetCoins().AmountOf(depositDenom)
|
return macc.GetCoins().AmountOf(depositDenom)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
type args struct {
|
type args struct {
|
||||||
depositor sdk.AccAddress
|
depositor sdk.AccAddress
|
||||||
amount sdk.Coin
|
amount sdk.Coin
|
||||||
depositType types.DepositType
|
|
||||||
numberDeposits int
|
numberDeposits int
|
||||||
expectedAccountBalance sdk.Coins
|
expectedAccountBalance sdk.Coins
|
||||||
expectedModAccountBalance sdk.Coins
|
expectedModAccountBalance sdk.Coins
|
||||||
@ -37,7 +36,6 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
args{
|
args{
|
||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
||||||
depositType: types.LP,
|
|
||||||
numberDeposits: 1,
|
numberDeposits: 1,
|
||||||
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(900)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(900)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
||||||
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
||||||
@ -52,7 +50,6 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
args{
|
args{
|
||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
||||||
depositType: types.LP,
|
|
||||||
numberDeposits: 2,
|
numberDeposits: 2,
|
||||||
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(800)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(800)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
||||||
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(200))),
|
||||||
@ -62,27 +59,11 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
contains: "",
|
contains: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"invalid deposit type",
|
|
||||||
args{
|
|
||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
|
||||||
depositType: types.Stake,
|
|
||||||
numberDeposits: 1,
|
|
||||||
expectedAccountBalance: sdk.Coins{},
|
|
||||||
expectedModAccountBalance: sdk.Coins{},
|
|
||||||
},
|
|
||||||
errArgs{
|
|
||||||
expectPass: false,
|
|
||||||
contains: "invalid deposit type",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"invalid deposit denom",
|
"invalid deposit denom",
|
||||||
args{
|
args{
|
||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
amount: sdk.NewCoin("btcb", sdk.NewInt(100)),
|
amount: sdk.NewCoin("btcb", sdk.NewInt(100)),
|
||||||
depositType: types.LP,
|
|
||||||
numberDeposits: 1,
|
numberDeposits: 1,
|
||||||
expectedAccountBalance: sdk.Coins{},
|
expectedAccountBalance: sdk.Coins{},
|
||||||
expectedModAccountBalance: sdk.Coins{},
|
expectedModAccountBalance: sdk.Coins{},
|
||||||
@ -97,7 +78,6 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
args{
|
args{
|
||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(10000)),
|
||||||
depositType: types.LP,
|
|
||||||
numberDeposits: 1,
|
numberDeposits: 1,
|
||||||
expectedAccountBalance: sdk.Coins{},
|
expectedAccountBalance: sdk.Coins{},
|
||||||
expectedModAccountBalance: sdk.Coins{},
|
expectedModAccountBalance: sdk.Coins{},
|
||||||
@ -141,7 +121,7 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
// run the test
|
// run the test
|
||||||
var err error
|
var err error
|
||||||
for i := 0; i < tc.args.numberDeposits; i++ {
|
for i := 0; i < tc.args.numberDeposits; i++ {
|
||||||
err = suite.keeper.Deposit(suite.ctx, tc.args.depositor, tc.args.amount, tc.args.depositType)
|
err = suite.keeper.Deposit(suite.ctx, tc.args.depositor, tc.args.amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify results
|
// verify results
|
||||||
@ -151,7 +131,7 @@ func (suite *KeeperTestSuite) TestDeposit() {
|
|||||||
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
||||||
mAcc := suite.getModuleAccount(types.ModuleAccountName)
|
mAcc := suite.getModuleAccount(types.ModuleAccountName)
|
||||||
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
||||||
_, f := suite.keeper.GetDeposit(suite.ctx, tc.args.depositor, tc.args.amount.Denom, tc.args.depositType)
|
_, f := suite.keeper.GetDeposit(suite.ctx, tc.args.depositor, tc.args.amount.Denom)
|
||||||
suite.Require().True(f)
|
suite.Require().True(f)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
@ -166,8 +146,6 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
depositor sdk.AccAddress
|
depositor sdk.AccAddress
|
||||||
depositAmount sdk.Coin
|
depositAmount sdk.Coin
|
||||||
withdrawAmount sdk.Coin
|
withdrawAmount sdk.Coin
|
||||||
depositType types.DepositType
|
|
||||||
withdrawType types.DepositType
|
|
||||||
createDeposit bool
|
createDeposit bool
|
||||||
expectedAccountBalance sdk.Coins
|
expectedAccountBalance sdk.Coins
|
||||||
expectedModAccountBalance sdk.Coins
|
expectedModAccountBalance sdk.Coins
|
||||||
@ -190,8 +168,6 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
||||||
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(100)),
|
||||||
depositType: types.LP,
|
|
||||||
withdrawType: types.LP,
|
|
||||||
createDeposit: true,
|
createDeposit: true,
|
||||||
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(900)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(900)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
||||||
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
expectedModAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))),
|
||||||
@ -209,8 +185,6 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
||||||
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
||||||
depositType: types.LP,
|
|
||||||
withdrawType: types.LP,
|
|
||||||
createDeposit: true,
|
createDeposit: true,
|
||||||
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(1000)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
expectedAccountBalance: sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(1000)), sdk.NewCoin("btcb", sdk.NewInt(1000))),
|
||||||
expectedModAccountBalance: sdk.Coins(nil),
|
expectedModAccountBalance: sdk.Coins(nil),
|
||||||
@ -228,27 +202,6 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
||||||
withdrawAmount: sdk.NewCoin("btcb", sdk.NewInt(200)),
|
withdrawAmount: sdk.NewCoin("btcb", sdk.NewInt(200)),
|
||||||
depositType: types.LP,
|
|
||||||
withdrawType: types.LP,
|
|
||||||
createDeposit: true,
|
|
||||||
expectedAccountBalance: sdk.Coins{},
|
|
||||||
expectedModAccountBalance: sdk.Coins{},
|
|
||||||
depositExists: false,
|
|
||||||
finalDepositAmount: sdk.Coin{},
|
|
||||||
},
|
|
||||||
errArgs{
|
|
||||||
expectPass: false,
|
|
||||||
contains: "deposit not found",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"deposit not found invalid deposit type",
|
|
||||||
args{
|
|
||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
|
||||||
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
|
||||||
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
|
||||||
depositType: types.LP,
|
|
||||||
withdrawType: types.Stake,
|
|
||||||
createDeposit: true,
|
createDeposit: true,
|
||||||
expectedAccountBalance: sdk.Coins{},
|
expectedAccountBalance: sdk.Coins{},
|
||||||
expectedModAccountBalance: sdk.Coins{},
|
expectedModAccountBalance: sdk.Coins{},
|
||||||
@ -266,8 +219,6 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
depositor: sdk.AccAddress(crypto.AddressHash([]byte("test"))),
|
||||||
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
depositAmount: sdk.NewCoin("bnb", sdk.NewInt(200)),
|
||||||
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(300)),
|
withdrawAmount: sdk.NewCoin("bnb", sdk.NewInt(300)),
|
||||||
depositType: types.LP,
|
|
||||||
withdrawType: types.LP,
|
|
||||||
createDeposit: true,
|
createDeposit: true,
|
||||||
expectedAccountBalance: sdk.Coins{},
|
expectedAccountBalance: sdk.Coins{},
|
||||||
expectedModAccountBalance: sdk.Coins{},
|
expectedModAccountBalance: sdk.Coins{},
|
||||||
@ -311,11 +262,11 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
suite.keeper = keeper
|
suite.keeper = keeper
|
||||||
|
|
||||||
if tc.args.createDeposit {
|
if tc.args.createDeposit {
|
||||||
err := suite.keeper.Deposit(suite.ctx, tc.args.depositor, tc.args.depositAmount, tc.args.depositType)
|
err := suite.keeper.Deposit(suite.ctx, tc.args.depositor, tc.args.depositAmount)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := suite.keeper.Withdraw(suite.ctx, tc.args.depositor, tc.args.withdrawAmount, tc.args.withdrawType)
|
err := suite.keeper.Withdraw(suite.ctx, tc.args.depositor, tc.args.withdrawAmount)
|
||||||
|
|
||||||
if tc.errArgs.expectPass {
|
if tc.errArgs.expectPass {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
@ -323,7 +274,7 @@ func (suite *KeeperTestSuite) TestWithdraw() {
|
|||||||
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
suite.Require().Equal(tc.args.expectedAccountBalance, acc.GetCoins())
|
||||||
mAcc := suite.getModuleAccount(types.ModuleAccountName)
|
mAcc := suite.getModuleAccount(types.ModuleAccountName)
|
||||||
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
suite.Require().Equal(tc.args.expectedModAccountBalance, mAcc.GetCoins())
|
||||||
testDeposit, f := suite.keeper.GetDeposit(suite.ctx, tc.args.depositor, tc.args.depositAmount.Denom, tc.args.depositType)
|
testDeposit, f := suite.keeper.GetDeposit(suite.ctx, tc.args.depositor, tc.args.depositAmount.Denom)
|
||||||
if tc.args.depositExists {
|
if tc.args.depositExists {
|
||||||
suite.Require().True(f)
|
suite.Require().True(f)
|
||||||
suite.Require().Equal(tc.args.finalDepositAmount, testDeposit.Amount)
|
suite.Require().Equal(tc.args.finalDepositAmount, testDeposit.Amount)
|
||||||
|
@ -75,10 +75,10 @@ func (k Keeper) SetPreviousDelegationDistribution(ctx sdk.Context, distTime time
|
|||||||
store.Set([]byte(denom), k.cdc.MustMarshalBinaryBare(distTime))
|
store.Set([]byte(denom), k.cdc.MustMarshalBinaryBare(distTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeposit returns a deposit from the store for a particular depositor address, deposit denom, and deposit type
|
// GetDeposit returns a deposit from the store for a particular depositor address, deposit denom
|
||||||
func (k Keeper) GetDeposit(ctx sdk.Context, depositor sdk.AccAddress, denom string, depositType types.DepositType) (types.Deposit, bool) {
|
func (k Keeper) GetDeposit(ctx sdk.Context, depositor sdk.AccAddress, denom string) (types.Deposit, bool) {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
||||||
bz := store.Get(types.DepositKey(depositType, denom, depositor))
|
bz := store.Get(types.DepositKey(denom, depositor))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return types.Deposit{}, false
|
return types.Deposit{}, false
|
||||||
}
|
}
|
||||||
@ -91,13 +91,13 @@ func (k Keeper) GetDeposit(ctx sdk.Context, depositor sdk.AccAddress, denom stri
|
|||||||
func (k Keeper) SetDeposit(ctx sdk.Context, deposit types.Deposit) {
|
func (k Keeper) SetDeposit(ctx sdk.Context, deposit types.Deposit) {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
||||||
bz := k.cdc.MustMarshalBinaryBare(deposit)
|
bz := k.cdc.MustMarshalBinaryBare(deposit)
|
||||||
store.Set(types.DepositKey(deposit.Type, deposit.Amount.Denom, deposit.Depositor), bz)
|
store.Set(types.DepositKey(deposit.Amount.Denom, deposit.Depositor), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteDeposit deletes a deposit from the store
|
// DeleteDeposit deletes a deposit from the store
|
||||||
func (k Keeper) DeleteDeposit(ctx sdk.Context, deposit types.Deposit) {
|
func (k Keeper) DeleteDeposit(ctx sdk.Context, deposit types.Deposit) {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
||||||
store.Delete(types.DepositKey(deposit.Type, deposit.Amount.Denom, deposit.Depositor))
|
store.Delete(types.DepositKey(deposit.Amount.Denom, deposit.Depositor))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateDeposits iterates over all deposit objects in the store and performs a callback function
|
// IterateDeposits iterates over all deposit objects in the store and performs a callback function
|
||||||
@ -114,11 +114,10 @@ func (k Keeper) IterateDeposits(ctx sdk.Context, cb func(deposit types.Deposit)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateDepositsByTypeAndDenom iterates over all deposit objects in the store with the matching deposit type and deposit denom and performs a callback function
|
// IterateDepositsByDenom iterates over all deposit objects in the store with the matching deposit denom and performs a callback function
|
||||||
func (k Keeper) IterateDepositsByTypeAndDenom(ctx sdk.Context, depositType types.DepositType, depositDenom string, cb func(deposit types.Deposit) (stop bool)) {
|
func (k Keeper) IterateDepositsByDenom(ctx sdk.Context, depositDenom string, cb func(deposit types.Deposit) (stop bool)) {
|
||||||
|
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.DepositsKeyPrefix)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.DepositTypeIteratorKey(depositType, depositDenom))
|
iterator := sdk.KVStorePrefixIterator(store, types.DepositTypeIteratorKey(depositDenom))
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var deposit types.Deposit
|
var deposit types.Deposit
|
||||||
@ -129,10 +128,10 @@ func (k Keeper) IterateDepositsByTypeAndDenom(ctx sdk.Context, depositType types
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetClaim returns a claim from the store for a particular claim owner, deposit denom, and deposit type
|
// GetClaim returns a claim from the store for a particular claim owner, deposit denom, and claim type
|
||||||
func (k Keeper) GetClaim(ctx sdk.Context, owner sdk.AccAddress, depositDenom string, depositType types.DepositType) (types.Claim, bool) {
|
func (k Keeper) GetClaim(ctx sdk.Context, owner sdk.AccAddress, depositDenom string, claimType types.ClaimType) (types.Claim, bool) {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.ClaimsKeyPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.ClaimsKeyPrefix)
|
||||||
bz := store.Get(types.ClaimKey(depositType, depositDenom, owner))
|
bz := store.Get(types.ClaimKey(claimType, depositDenom, owner))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return types.Claim{}, false
|
return types.Claim{}, false
|
||||||
}
|
}
|
||||||
@ -168,10 +167,10 @@ func (k Keeper) IterateClaims(ctx sdk.Context, cb func(claim types.Claim) (stop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateClaimsByTypeAndDenom iterates over all claim objects in the store with the matching deposit type and deposit denom and performs a callback function
|
// IterateClaimsByTypeAndDenom iterates over all claim objects in the store with the matching claim type and deposit denom and performs a callback function
|
||||||
func (k Keeper) IterateClaimsByTypeAndDenom(ctx sdk.Context, depositType types.DepositType, depositDenom string, cb func(claim types.Claim) (stop bool)) {
|
func (k Keeper) IterateClaimsByTypeAndDenom(ctx sdk.Context, claimType types.ClaimType, depositDenom string, cb func(claim types.Claim) (stop bool)) {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.ClaimsKeyPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.ClaimsKeyPrefix)
|
||||||
iterator := sdk.KVStorePrefixIterator(store, types.DepositTypeIteratorKey(depositType, depositDenom))
|
iterator := sdk.KVStorePrefixIterator(store, types.ClaimTypeIteratorKey(claimType, depositDenom))
|
||||||
defer iterator.Close()
|
defer iterator.Close()
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
var claim types.Claim
|
var claim types.Claim
|
||||||
|
@ -72,27 +72,27 @@ func (suite *KeeperTestSuite) TestGetSetPreviousDelegatorDistribution() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGetSetDeleteDeposit() {
|
func (suite *KeeperTestSuite) TestGetSetDeleteDeposit() {
|
||||||
dep := types.NewDeposit(sdk.AccAddress("test"), sdk.NewCoin("bnb", sdk.NewInt(100)), "lp")
|
dep := types.NewDeposit(sdk.AccAddress("test"), sdk.NewCoin("bnb", sdk.NewInt(100)))
|
||||||
|
|
||||||
_, f := suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"), "bnb", "lp")
|
_, f := suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"), "bnb")
|
||||||
suite.Require().False(f)
|
suite.Require().False(f)
|
||||||
|
|
||||||
suite.keeper.SetDeposit(suite.ctx, dep)
|
suite.keeper.SetDeposit(suite.ctx, dep)
|
||||||
|
|
||||||
testDeposit, f := suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"), "bnb", "lp")
|
testDeposit, f := suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"), "bnb")
|
||||||
suite.Require().True(f)
|
suite.Require().True(f)
|
||||||
suite.Require().Equal(dep, testDeposit)
|
suite.Require().Equal(dep, testDeposit)
|
||||||
|
|
||||||
suite.Require().NotPanics(func() { suite.keeper.DeleteDeposit(suite.ctx, dep) })
|
suite.Require().NotPanics(func() { suite.keeper.DeleteDeposit(suite.ctx, dep) })
|
||||||
|
|
||||||
_, f = suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"), "bnb", "lp")
|
_, f = suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"), "bnb")
|
||||||
suite.Require().False(f)
|
suite.Require().False(f)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestIterateDeposits() {
|
func (suite *KeeperTestSuite) TestIterateDeposits() {
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
dep := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("bnb", sdk.NewInt(100)), "lp")
|
dep := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("bnb", sdk.NewInt(100)))
|
||||||
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, dep) })
|
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, dep) })
|
||||||
}
|
}
|
||||||
var deposits []types.Deposit
|
var deposits []types.Deposit
|
||||||
@ -103,39 +103,39 @@ func (suite *KeeperTestSuite) TestIterateDeposits() {
|
|||||||
suite.Require().Equal(5, len(deposits))
|
suite.Require().Equal(5, len(deposits))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestIterateDepositsByTypeAndDenom() {
|
func (suite *KeeperTestSuite) TestIterateDepositsByDenom() {
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
depA := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("bnb", sdk.NewInt(100)), "lp")
|
depA := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("bnb", sdk.NewInt(100)))
|
||||||
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, depA) })
|
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, depA) })
|
||||||
depB := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("bnb", sdk.NewInt(100)), "gov")
|
depB := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("bnb", sdk.NewInt(100)))
|
||||||
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, depB) })
|
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, depB) })
|
||||||
depC := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("btcb", sdk.NewInt(100)), "lp")
|
depC := types.NewDeposit(sdk.AccAddress("test"+string(i)), sdk.NewCoin("btcb", sdk.NewInt(100)))
|
||||||
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, depC) })
|
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, depC) })
|
||||||
}
|
}
|
||||||
var bnbLPDeposits []types.Deposit
|
|
||||||
suite.keeper.IterateDepositsByTypeAndDenom(suite.ctx, "lp", "bnb", func(d types.Deposit) bool {
|
// Check BNB deposits
|
||||||
bnbLPDeposits = append(bnbLPDeposits, d)
|
var bnbDeposits []types.Deposit
|
||||||
|
suite.keeper.IterateDepositsByDenom(suite.ctx, "bnb", func(d types.Deposit) bool {
|
||||||
|
bnbDeposits = append(bnbDeposits, d)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
suite.Require().Equal(5, len(bnbLPDeposits))
|
suite.Require().Equal(5, len(bnbDeposits))
|
||||||
var bnbGovDeposits []types.Deposit
|
|
||||||
suite.keeper.IterateDepositsByTypeAndDenom(suite.ctx, "gov", "bnb", func(d types.Deposit) bool {
|
// Check BTCB deposits
|
||||||
bnbGovDeposits = append(bnbGovDeposits, d)
|
var btcbDeposits []types.Deposit
|
||||||
|
suite.keeper.IterateDepositsByDenom(suite.ctx, "btcb", func(d types.Deposit) bool {
|
||||||
|
btcbDeposits = append(btcbDeposits, d)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
suite.Require().Equal(5, len(bnbGovDeposits))
|
suite.Require().Equal(5, len(btcbDeposits))
|
||||||
var btcbLPDeposits []types.Deposit
|
|
||||||
suite.keeper.IterateDepositsByTypeAndDenom(suite.ctx, "lp", "btcb", func(d types.Deposit) bool {
|
// Fetch all deposits
|
||||||
btcbLPDeposits = append(btcbLPDeposits, d)
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
suite.Require().Equal(5, len(btcbLPDeposits))
|
|
||||||
var deposits []types.Deposit
|
var deposits []types.Deposit
|
||||||
suite.keeper.IterateDeposits(suite.ctx, func(d types.Deposit) bool {
|
suite.keeper.IterateDeposits(suite.ctx, func(d types.Deposit) bool {
|
||||||
deposits = append(deposits, d)
|
deposits = append(deposits, d)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
suite.Require().Equal(15, len(deposits))
|
suite.Require().Equal(len(bnbDeposits)+len(btcbDeposits), len(deposits))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGetSetDeleteClaim() {
|
func (suite *KeeperTestSuite) TestGetSetDeleteClaim() {
|
||||||
|
@ -84,59 +84,26 @@ func queryGetDeposits(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte,
|
|||||||
}
|
}
|
||||||
depositDenom := len(params.DepositDenom) > 0
|
depositDenom := len(params.DepositDenom) > 0
|
||||||
owner := len(params.Owner) > 0
|
owner := len(params.Owner) > 0
|
||||||
depositType := len(params.DepositType) > 0
|
|
||||||
|
|
||||||
var deposits []types.Deposit
|
var deposits []types.Deposit
|
||||||
switch {
|
switch {
|
||||||
case depositDenom && owner && depositType:
|
case depositDenom && owner:
|
||||||
deposit, found := k.GetDeposit(ctx, params.Owner, params.DepositDenom, params.DepositType)
|
deposit, found := k.GetDeposit(ctx, params.Owner, params.DepositDenom)
|
||||||
if found {
|
if found {
|
||||||
deposits = append(deposits, deposit)
|
deposits = append(deposits, deposit)
|
||||||
}
|
}
|
||||||
case depositDenom && owner:
|
case depositDenom:
|
||||||
for _, dt := range types.DepositTypesDepositQuery {
|
k.IterateDepositsByDenom(ctx, params.DepositDenom, func(deposit types.Deposit) (stop bool) {
|
||||||
deposit, found := k.GetDeposit(ctx, params.Owner, params.DepositDenom, dt)
|
|
||||||
if found {
|
|
||||||
deposits = append(deposits, deposit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case depositDenom && depositType:
|
|
||||||
k.IterateDepositsByTypeAndDenom(ctx, params.DepositType, params.DepositDenom, func(deposit types.Deposit) (stop bool) {
|
|
||||||
deposits = append(deposits, deposit)
|
deposits = append(deposits, deposit)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
case owner && depositType:
|
|
||||||
schedules := k.GetParams(ctx).LiquidityProviderSchedules
|
|
||||||
for _, lps := range schedules {
|
|
||||||
deposit, found := k.GetDeposit(ctx, params.Owner, lps.DepositDenom, params.DepositType)
|
|
||||||
if found {
|
|
||||||
deposits = append(deposits, deposit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case depositDenom:
|
|
||||||
for _, dt := range types.DepositTypesDepositQuery {
|
|
||||||
k.IterateDepositsByTypeAndDenom(ctx, dt, params.DepositDenom, func(deposit types.Deposit) (stop bool) {
|
|
||||||
deposits = append(deposits, deposit)
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
case owner:
|
case owner:
|
||||||
schedules := k.GetParams(ctx).LiquidityProviderSchedules
|
schedules := k.GetParams(ctx).LiquidityProviderSchedules
|
||||||
for _, lps := range schedules {
|
for _, lps := range schedules {
|
||||||
for _, dt := range types.DepositTypesDepositQuery {
|
deposit, found := k.GetDeposit(ctx, params.Owner, lps.DepositDenom)
|
||||||
deposit, found := k.GetDeposit(ctx, params.Owner, lps.DepositDenom, dt)
|
if found {
|
||||||
if found {
|
|
||||||
deposits = append(deposits, deposit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case depositType:
|
|
||||||
schedules := k.GetParams(ctx).LiquidityProviderSchedules
|
|
||||||
for _, lps := range schedules {
|
|
||||||
k.IterateDepositsByTypeAndDenom(ctx, params.DepositType, lps.DepositDenom, func(deposit types.Deposit) (stop bool) {
|
|
||||||
deposits = append(deposits, deposit)
|
deposits = append(deposits, deposit)
|
||||||
return false
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
k.IterateDeposits(ctx, func(deposit types.Deposit) (stop bool) {
|
k.IterateDeposits(ctx, func(deposit types.Deposit) (stop bool) {
|
||||||
@ -169,47 +136,47 @@ func queryGetClaims(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e
|
|||||||
}
|
}
|
||||||
depositDenom := len(params.DepositDenom) > 0
|
depositDenom := len(params.DepositDenom) > 0
|
||||||
owner := len(params.Owner) > 0
|
owner := len(params.Owner) > 0
|
||||||
depositType := len(params.DepositType) > 0
|
claimType := len(params.ClaimType) > 0
|
||||||
|
|
||||||
var claims []types.Claim
|
var claims []types.Claim
|
||||||
switch {
|
switch {
|
||||||
case depositDenom && owner && depositType:
|
case depositDenom && owner && claimType:
|
||||||
claim, found := k.GetClaim(ctx, params.Owner, params.DepositDenom, params.DepositType)
|
claim, found := k.GetClaim(ctx, params.Owner, params.DepositDenom, params.ClaimType)
|
||||||
if found {
|
if found {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
}
|
}
|
||||||
case depositDenom && owner:
|
case depositDenom && owner:
|
||||||
for _, dt := range types.DepositTypesClaimQuery {
|
for _, dt := range types.ClaimTypesClaimQuery {
|
||||||
claim, found := k.GetClaim(ctx, params.Owner, params.DepositDenom, dt)
|
claim, found := k.GetClaim(ctx, params.Owner, params.DepositDenom, dt)
|
||||||
if found {
|
if found {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case depositDenom && depositType:
|
case depositDenom && claimType:
|
||||||
k.IterateClaimsByTypeAndDenom(ctx, params.DepositType, params.DepositDenom, func(claim types.Claim) (stop bool) {
|
k.IterateClaimsByTypeAndDenom(ctx, params.ClaimType, params.DepositDenom, func(claim types.Claim) (stop bool) {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
case owner && depositType:
|
case owner && claimType:
|
||||||
harvestParams := k.GetParams(ctx)
|
harvestParams := k.GetParams(ctx)
|
||||||
switch {
|
switch {
|
||||||
case params.DepositType == types.LP:
|
case params.ClaimType == types.LP:
|
||||||
for _, lps := range harvestParams.LiquidityProviderSchedules {
|
for _, lps := range harvestParams.LiquidityProviderSchedules {
|
||||||
claim, found := k.GetClaim(ctx, params.Owner, lps.DepositDenom, params.DepositType)
|
claim, found := k.GetClaim(ctx, params.Owner, lps.DepositDenom, params.ClaimType)
|
||||||
if found {
|
if found {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case params.DepositType == types.Stake:
|
case params.ClaimType == types.Stake:
|
||||||
for _, dss := range harvestParams.DelegatorDistributionSchedules {
|
for _, dss := range harvestParams.DelegatorDistributionSchedules {
|
||||||
claim, found := k.GetClaim(ctx, params.Owner, dss.DistributionSchedule.DepositDenom, params.DepositType)
|
claim, found := k.GetClaim(ctx, params.Owner, dss.DistributionSchedule.DepositDenom, params.ClaimType)
|
||||||
if found {
|
if found {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case depositDenom:
|
case depositDenom:
|
||||||
for _, dt := range types.DepositTypesClaimQuery {
|
for _, dt := range types.ClaimTypesClaimQuery {
|
||||||
k.IterateClaimsByTypeAndDenom(ctx, dt, params.DepositDenom, func(claim types.Claim) (stop bool) {
|
k.IterateClaimsByTypeAndDenom(ctx, dt, params.DepositDenom, func(claim types.Claim) (stop bool) {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
return false
|
return false
|
||||||
@ -229,16 +196,16 @@ func queryGetClaims(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, e
|
|||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case depositType:
|
case claimType:
|
||||||
harvestParams := k.GetParams(ctx)
|
harvestParams := k.GetParams(ctx)
|
||||||
for _, lps := range harvestParams.LiquidityProviderSchedules {
|
for _, lps := range harvestParams.LiquidityProviderSchedules {
|
||||||
k.IterateClaimsByTypeAndDenom(ctx, params.DepositType, lps.DepositDenom, func(claim types.Claim) (stop bool) {
|
k.IterateClaimsByTypeAndDenom(ctx, params.ClaimType, lps.DepositDenom, func(claim types.Claim) (stop bool) {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, dds := range harvestParams.DelegatorDistributionSchedules {
|
for _, dds := range harvestParams.DelegatorDistributionSchedules {
|
||||||
k.IterateClaimsByTypeAndDenom(ctx, params.DepositType, dds.DistributionSchedule.DepositDenom, func(claim types.Claim) (stop bool) {
|
k.IterateClaimsByTypeAndDenom(ctx, params.ClaimType, dds.DistributionSchedule.DepositDenom, func(claim types.Claim) (stop bool) {
|
||||||
claims = append(claims, claim)
|
claims = append(claims, claim)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
@ -34,7 +34,7 @@ func (k Keeper) ApplyDepositRewards(ctx sdk.Context) {
|
|||||||
if lps.Start.After(ctx.BlockTime()) {
|
if lps.Start.After(ctx.BlockTime()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
totalDeposited := k.GetTotalDeposited(ctx, types.LP, lps.DepositDenom)
|
totalDeposited := k.GetTotalDeposited(ctx, lps.DepositDenom)
|
||||||
if totalDeposited.IsZero() {
|
if totalDeposited.IsZero() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ func (k Keeper) ApplyDepositRewards(ctx sdk.Context) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rewardsDistributed := sdk.ZeroInt()
|
rewardsDistributed := sdk.ZeroInt()
|
||||||
k.IterateDepositsByTypeAndDenom(ctx, types.LP, lps.DepositDenom, func(dep types.Deposit) (stop bool) {
|
k.IterateDepositsByDenom(ctx, lps.DepositDenom, func(dep types.Deposit) (stop bool) {
|
||||||
rewardsShare := sdk.NewDecFromInt(dep.Amount.Amount).Quo(sdk.NewDecFromInt(totalDeposited))
|
rewardsShare := sdk.NewDecFromInt(dep.Amount.Amount).Quo(sdk.NewDecFromInt(totalDeposited))
|
||||||
if rewardsShare.IsZero() {
|
if rewardsShare.IsZero() {
|
||||||
return false
|
return false
|
||||||
@ -52,7 +52,7 @@ func (k Keeper) ApplyDepositRewards(ctx sdk.Context) {
|
|||||||
if rewardsEarned.IsZero() {
|
if rewardsEarned.IsZero() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
k.AddToClaim(ctx, dep.Depositor, dep.Amount.Denom, dep.Type, sdk.NewCoin(lps.RewardsPerSecond.Denom, rewardsEarned))
|
k.AddToClaim(ctx, dep.Depositor, dep.Amount.Denom, types.LP, sdk.NewCoin(lps.RewardsPerSecond.Denom, rewardsEarned))
|
||||||
rewardsDistributed = rewardsDistributed.Add(rewardsEarned)
|
rewardsDistributed = rewardsDistributed.Add(rewardsEarned)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
@ -164,10 +164,10 @@ func (k Keeper) ApplyDelegationRewards(ctx sdk.Context, denom string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddToClaim adds the input amount to an existing claim or creates a new one
|
// AddToClaim adds the input amount to an existing claim or creates a new one
|
||||||
func (k Keeper) AddToClaim(ctx sdk.Context, owner sdk.AccAddress, depositDenom string, depositType types.DepositType, amountToAdd sdk.Coin) {
|
func (k Keeper) AddToClaim(ctx sdk.Context, owner sdk.AccAddress, depositDenom string, claimType types.ClaimType, amountToAdd sdk.Coin) {
|
||||||
claim, found := k.GetClaim(ctx, owner, depositDenom, depositType)
|
claim, found := k.GetClaim(ctx, owner, depositDenom, claimType)
|
||||||
if !found {
|
if !found {
|
||||||
claim = types.NewClaim(owner, depositDenom, amountToAdd, depositType)
|
claim = types.NewClaim(owner, depositDenom, amountToAdd, claimType)
|
||||||
} else {
|
} else {
|
||||||
claim.Amount = claim.Amount.Add(amountToAdd)
|
claim.Amount = claim.Amount.Add(amountToAdd)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func (suite *KeeperTestSuite) TestApplyDepositRewards() {
|
|||||||
depositAmount sdk.Coin
|
depositAmount sdk.Coin
|
||||||
totalDeposits sdk.Coin
|
totalDeposits sdk.Coin
|
||||||
rewardRate sdk.Coin
|
rewardRate sdk.Coin
|
||||||
depositType types.DepositType
|
claimType types.ClaimType
|
||||||
previousBlockTime time.Time
|
previousBlockTime time.Time
|
||||||
blockTime time.Time
|
blockTime time.Time
|
||||||
expectedClaimBalance sdk.Coin
|
expectedClaimBalance sdk.Coin
|
||||||
@ -47,7 +47,7 @@ func (suite *KeeperTestSuite) TestApplyDepositRewards() {
|
|||||||
rewardRate: c("hard", 500),
|
rewardRate: c("hard", 500),
|
||||||
depositAmount: c("bnb", 100),
|
depositAmount: c("bnb", 100),
|
||||||
totalDeposits: c("bnb", 1000),
|
totalDeposits: c("bnb", 1000),
|
||||||
depositType: types.LP,
|
claimType: types.LP,
|
||||||
previousBlockTime: time.Date(2020, 11, 1, 13, 59, 50, 0, time.UTC),
|
previousBlockTime: time.Date(2020, 11, 1, 13, 59, 50, 0, time.UTC),
|
||||||
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
blockTime: time.Date(2020, 11, 1, 14, 0, 0, 0, time.UTC),
|
||||||
expectedClaimBalance: c("hard", 500),
|
expectedClaimBalance: c("hard", 500),
|
||||||
@ -83,7 +83,7 @@ func (suite *KeeperTestSuite) TestApplyDepositRewards() {
|
|||||||
supplyKeeper := tApp.GetSupplyKeeper()
|
supplyKeeper := tApp.GetSupplyKeeper()
|
||||||
supplyKeeper.MintCoins(ctx, types.ModuleAccountName, cs(tc.args.totalDeposits))
|
supplyKeeper.MintCoins(ctx, types.ModuleAccountName, cs(tc.args.totalDeposits))
|
||||||
keeper := tApp.GetHarvestKeeper()
|
keeper := tApp.GetHarvestKeeper()
|
||||||
deposit := types.NewDeposit(tc.args.depositor, tc.args.depositAmount, tc.args.depositType)
|
deposit := types.NewDeposit(tc.args.depositor, tc.args.depositAmount)
|
||||||
keeper.SetDeposit(ctx, deposit)
|
keeper.SetDeposit(ctx, deposit)
|
||||||
suite.app = tApp
|
suite.app = tApp
|
||||||
suite.ctx = ctx
|
suite.ctx = ctx
|
||||||
@ -93,7 +93,7 @@ func (suite *KeeperTestSuite) TestApplyDepositRewards() {
|
|||||||
suite.Require().Panics(func() { suite.keeper.ApplyDepositRewards(suite.ctx) })
|
suite.Require().Panics(func() { suite.keeper.ApplyDepositRewards(suite.ctx) })
|
||||||
} else {
|
} else {
|
||||||
suite.Require().NotPanics(func() { suite.keeper.ApplyDepositRewards(suite.ctx) })
|
suite.Require().NotPanics(func() { suite.keeper.ApplyDepositRewards(suite.ctx) })
|
||||||
claim, f := suite.keeper.GetClaim(suite.ctx, tc.args.depositor, tc.args.denom, tc.args.depositType)
|
claim, f := suite.keeper.GetClaim(suite.ctx, tc.args.depositor, tc.args.denom, tc.args.claimType)
|
||||||
suite.Require().True(f)
|
suite.Require().True(f)
|
||||||
suite.Require().Equal(tc.args.expectedClaimBalance, claim.Amount)
|
suite.Require().Equal(tc.args.expectedClaimBalance, claim.Amount)
|
||||||
}
|
}
|
||||||
|
391
x/harvest/legacy/v0_12/types.go
Normal file
391
x/harvest/legacy/v0_12/types.go
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
package v0_12
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
|
|
||||||
|
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parameter keys and default values
|
||||||
|
var (
|
||||||
|
KeyActive = []byte("Active")
|
||||||
|
KeyLPSchedules = []byte("LPSchedules")
|
||||||
|
KeyDelegatorSchedule = []byte("DelegatorSchedule")
|
||||||
|
DefaultActive = true
|
||||||
|
DefaultGovSchedules = DistributionSchedules{}
|
||||||
|
DefaultLPSchedules = DistributionSchedules{}
|
||||||
|
DefaultDelegatorSchedules = DelegatorDistributionSchedules{}
|
||||||
|
GovDenom = cdptypes.DefaultGovDenom
|
||||||
|
)
|
||||||
|
|
||||||
|
// Params governance parameters for harvest module
|
||||||
|
type Params struct {
|
||||||
|
Active bool `json:"active" yaml:"active"`
|
||||||
|
LiquidityProviderSchedules DistributionSchedules `json:"liquidity_provider_schedules" yaml:"liquidity_provider_schedules"`
|
||||||
|
DelegatorDistributionSchedules DelegatorDistributionSchedules `json:"delegator_distribution_schedules" yaml:"delegator_distribution_schedules"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DistributionSchedule distribution schedule for liquidity providers
|
||||||
|
type DistributionSchedule struct {
|
||||||
|
Active bool `json:"active" yaml:"active"`
|
||||||
|
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
||||||
|
Start time.Time `json:"start" yaml:"start"`
|
||||||
|
End time.Time `json:"end" yaml:"end"`
|
||||||
|
RewardsPerSecond sdk.Coin `json:"rewards_per_second" yaml:"rewards_per_second"`
|
||||||
|
ClaimEnd time.Time `json:"claim_end" yaml:"claim_end"`
|
||||||
|
ClaimMultipliers Multipliers `json:"claim_multipliers" yaml:"claim_multipliers"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDistributionSchedule returns a new DistributionSchedule
|
||||||
|
func NewDistributionSchedule(active bool, denom string, start, end time.Time, reward sdk.Coin, claimEnd time.Time, multipliers Multipliers) DistributionSchedule {
|
||||||
|
return DistributionSchedule{
|
||||||
|
Active: active,
|
||||||
|
DepositDenom: denom,
|
||||||
|
Start: start,
|
||||||
|
End: end,
|
||||||
|
RewardsPerSecond: reward,
|
||||||
|
ClaimEnd: claimEnd,
|
||||||
|
ClaimMultipliers: multipliers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements fmt.Stringer
|
||||||
|
func (ds DistributionSchedule) String() string {
|
||||||
|
return fmt.Sprintf(`Liquidity Provider Distribution Schedule:
|
||||||
|
Deposit Denom: %s,
|
||||||
|
Start: %s,
|
||||||
|
End: %s,
|
||||||
|
Rewards Per Second: %s,
|
||||||
|
Claim End: %s,
|
||||||
|
Active: %t
|
||||||
|
`, ds.DepositDenom, ds.Start, ds.End, ds.RewardsPerSecond, ds.ClaimEnd, ds.Active)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate performs a basic check of a distribution schedule.
|
||||||
|
func (ds DistributionSchedule) Validate() error {
|
||||||
|
if !ds.RewardsPerSecond.IsValid() {
|
||||||
|
return fmt.Errorf("invalid reward coins %s for %s", ds.RewardsPerSecond, ds.DepositDenom)
|
||||||
|
}
|
||||||
|
if !ds.RewardsPerSecond.IsPositive() {
|
||||||
|
return fmt.Errorf("reward amount must be positive, is %s for %s", ds.RewardsPerSecond, ds.DepositDenom)
|
||||||
|
}
|
||||||
|
if ds.RewardsPerSecond.Denom != "hard" {
|
||||||
|
return fmt.Errorf("reward denom should be hard, is %s", ds.RewardsPerSecond.Denom)
|
||||||
|
}
|
||||||
|
if ds.Start.IsZero() {
|
||||||
|
return errors.New("reward period start time cannot be 0")
|
||||||
|
}
|
||||||
|
if ds.End.IsZero() {
|
||||||
|
return errors.New("reward period end time cannot be 0")
|
||||||
|
}
|
||||||
|
if ds.Start.After(ds.End) {
|
||||||
|
return fmt.Errorf("end period time %s cannot be before start time %s", ds.End, ds.Start)
|
||||||
|
}
|
||||||
|
if ds.ClaimEnd.Before(ds.End) {
|
||||||
|
return fmt.Errorf("claim end time %s cannot be before end time %s", ds.ClaimEnd, ds.End)
|
||||||
|
}
|
||||||
|
for _, multiplier := range ds.ClaimMultipliers {
|
||||||
|
if err := multiplier.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DistributionSchedules slice of DistributionSchedule
|
||||||
|
type DistributionSchedules []DistributionSchedule
|
||||||
|
|
||||||
|
// Validate checks if all the LiquidityProviderSchedules are valid and there are no duplicated
|
||||||
|
// entries.
|
||||||
|
func (dss DistributionSchedules) Validate() error {
|
||||||
|
seenPeriods := make(map[string]bool)
|
||||||
|
for _, ds := range dss {
|
||||||
|
if seenPeriods[ds.DepositDenom] {
|
||||||
|
return fmt.Errorf("duplicated distribution provider schedule with deposit denom %s", ds.DepositDenom)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ds.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
seenPeriods[ds.DepositDenom] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements fmt.Stringer
|
||||||
|
func (dss DistributionSchedules) String() string {
|
||||||
|
out := "Distribution Schedules\n"
|
||||||
|
for _, ds := range dss {
|
||||||
|
out += fmt.Sprintf("%s\n", ds)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelegatorDistributionSchedule distribution schedule for delegators
|
||||||
|
type DelegatorDistributionSchedule struct {
|
||||||
|
DistributionSchedule DistributionSchedule `json:"distribution_schedule" yaml:"distribution_schedule"`
|
||||||
|
|
||||||
|
DistributionFrequency time.Duration `json:"distribution_frequency" yaml:"distribution_frequency"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDelegatorDistributionSchedule returns a new DelegatorDistributionSchedule
|
||||||
|
func NewDelegatorDistributionSchedule(ds DistributionSchedule, frequency time.Duration) DelegatorDistributionSchedule {
|
||||||
|
return DelegatorDistributionSchedule{
|
||||||
|
DistributionSchedule: ds,
|
||||||
|
DistributionFrequency: frequency,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate performs a basic check of a reward fields.
|
||||||
|
func (dds DelegatorDistributionSchedule) Validate() error {
|
||||||
|
if err := dds.DistributionSchedule.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if dds.DistributionFrequency <= 0 {
|
||||||
|
return fmt.Errorf("distribution frequency should be positive, got %d", dds.DistributionFrequency)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelegatorDistributionSchedules slice of DelegatorDistributionSchedule
|
||||||
|
type DelegatorDistributionSchedules []DelegatorDistributionSchedule
|
||||||
|
|
||||||
|
// Validate checks if all the LiquidityProviderSchedules are valid and there are no duplicated
|
||||||
|
// entries.
|
||||||
|
func (dds DelegatorDistributionSchedules) Validate() error {
|
||||||
|
seenPeriods := make(map[string]bool)
|
||||||
|
for _, ds := range dds {
|
||||||
|
if seenPeriods[ds.DistributionSchedule.DepositDenom] {
|
||||||
|
return fmt.Errorf("duplicated liquidity provider schedule with deposit denom %s", ds.DistributionSchedule.DepositDenom)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ds.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
seenPeriods[ds.DistributionSchedule.DepositDenom] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiplier amount the claim rewards get increased by, along with how long the claim rewards are locked
|
||||||
|
type Multiplier struct {
|
||||||
|
Name MultiplierName `json:"name" yaml:"name"`
|
||||||
|
MonthsLockup int64 `json:"months_lockup" yaml:"months_lockup"`
|
||||||
|
Factor sdk.Dec `json:"factor" yaml:"factor"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMultiplier returns a new Multiplier
|
||||||
|
func NewMultiplier(name MultiplierName, lockup int64, factor sdk.Dec) Multiplier {
|
||||||
|
return Multiplier{
|
||||||
|
Name: name,
|
||||||
|
MonthsLockup: lockup,
|
||||||
|
Factor: factor,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate multiplier param
|
||||||
|
func (m Multiplier) Validate() error {
|
||||||
|
if err := m.Name.IsValid(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if m.MonthsLockup < 0 {
|
||||||
|
return fmt.Errorf("expected non-negative lockup, got %d", m.MonthsLockup)
|
||||||
|
}
|
||||||
|
if m.Factor.IsNegative() {
|
||||||
|
return fmt.Errorf("expected non-negative factor, got %s", m.Factor.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMultiplier returns the named multiplier from the input distribution schedule
|
||||||
|
func (ds DistributionSchedule) GetMultiplier(name MultiplierName) (Multiplier, bool) {
|
||||||
|
for _, multiplier := range ds.ClaimMultipliers {
|
||||||
|
if multiplier.Name == name {
|
||||||
|
return multiplier, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Multiplier{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multipliers slice of Multiplier
|
||||||
|
type Multipliers []Multiplier
|
||||||
|
|
||||||
|
// NewParams returns a new params object
|
||||||
|
func NewParams(active bool, lps DistributionSchedules, dds DelegatorDistributionSchedules) Params {
|
||||||
|
return Params{
|
||||||
|
Active: active,
|
||||||
|
LiquidityProviderSchedules: lps,
|
||||||
|
DelegatorDistributionSchedules: dds,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultParams returns default params for harvest module
|
||||||
|
func DefaultParams() Params {
|
||||||
|
return NewParams(DefaultActive, DefaultLPSchedules, DefaultDelegatorSchedules)
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements fmt.Stringer
|
||||||
|
func (p Params) String() string {
|
||||||
|
return fmt.Sprintf(`Params:
|
||||||
|
Active: %t
|
||||||
|
Liquidity Provider Distribution Schedules %s
|
||||||
|
Delegator Distribution Schedule %s`, p.Active, p.LiquidityProviderSchedules, p.DelegatorDistributionSchedules)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParamKeyTable Key declaration for parameters
|
||||||
|
func ParamKeyTable() params.KeyTable {
|
||||||
|
return params.NewKeyTable().RegisterParamSet(&Params{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
|
||||||
|
func (p *Params) ParamSetPairs() params.ParamSetPairs {
|
||||||
|
return params.ParamSetPairs{
|
||||||
|
params.NewParamSetPair(KeyActive, &p.Active, validateActiveParam),
|
||||||
|
params.NewParamSetPair(KeyLPSchedules, &p.LiquidityProviderSchedules, validateLPParams),
|
||||||
|
params.NewParamSetPair(KeyDelegatorSchedule, &p.DelegatorDistributionSchedules, validateDelegatorParams),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate checks that the parameters have valid values.
|
||||||
|
func (p Params) Validate() error {
|
||||||
|
if err := validateActiveParam(p.Active); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := validateDelegatorParams(p.DelegatorDistributionSchedules); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateLPParams(p.LiquidityProviderSchedules)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateActiveParam(i interface{}) error {
|
||||||
|
_, ok := i.(bool)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateLPParams(i interface{}) error {
|
||||||
|
dss, ok := i.(DistributionSchedules)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ds := range dss {
|
||||||
|
err := ds.Validate()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateDelegatorParams(i interface{}) error {
|
||||||
|
dds, ok := i.(DelegatorDistributionSchedules)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return dds.Validate()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MultiplierName name for valid multiplier
|
||||||
|
type MultiplierName string
|
||||||
|
|
||||||
|
// DepositType type for valid deposit type strings
|
||||||
|
type DepositType string
|
||||||
|
|
||||||
|
// Valid reward multipliers and reward types
|
||||||
|
const (
|
||||||
|
Small MultiplierName = "small"
|
||||||
|
Medium MultiplierName = "medium"
|
||||||
|
Large MultiplierName = "large"
|
||||||
|
|
||||||
|
LP DepositType = "lp"
|
||||||
|
Stake DepositType = "stake"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Queryable deposit types
|
||||||
|
var (
|
||||||
|
DepositTypesDepositQuery = []DepositType{LP}
|
||||||
|
DepositTypesClaimQuery = []DepositType{LP, Stake}
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsValid checks if the input is one of the expected strings
|
||||||
|
func (mn MultiplierName) IsValid() error {
|
||||||
|
switch mn {
|
||||||
|
case Small, Medium, Large:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid multiplier name: %s", mn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid checks if the input is one of the expected strings
|
||||||
|
func (dt DepositType) IsValid() error {
|
||||||
|
switch dt {
|
||||||
|
case LP, Stake:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid deposit type: %s", dt)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deposit defines an amount of coins deposited into a harvest module account
|
||||||
|
type Deposit struct {
|
||||||
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||||
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
|
Type DepositType `json:"type" yaml:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDeposit returns a new deposit
|
||||||
|
func NewDeposit(depositor sdk.AccAddress, amount sdk.Coin, dtype DepositType) Deposit {
|
||||||
|
return Deposit{
|
||||||
|
Depositor: depositor,
|
||||||
|
Amount: amount,
|
||||||
|
Type: dtype,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Claim defines an amount of coins that the owner can claim
|
||||||
|
type Claim struct {
|
||||||
|
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||||
|
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
||||||
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
|
Type DepositType `json:"type" yaml:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClaim returns a new claim
|
||||||
|
func NewClaim(owner sdk.AccAddress, denom string, amount sdk.Coin, dtype DepositType) Claim {
|
||||||
|
return Claim{
|
||||||
|
Owner: owner,
|
||||||
|
DepositDenom: denom,
|
||||||
|
Amount: amount,
|
||||||
|
Type: dtype,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPeriod returns a new vesting period
|
||||||
|
func NewPeriod(amount sdk.Coins, length int64) vesting.Period {
|
||||||
|
return vesting.Period{Amount: amount, Length: length}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTotalVestingPeriodLength returns the summed length of all vesting periods
|
||||||
|
func GetTotalVestingPeriodLength(periods vesting.Periods) int64 {
|
||||||
|
length := int64(0)
|
||||||
|
for _, period := range periods {
|
||||||
|
length += period.Length
|
||||||
|
}
|
||||||
|
return length
|
||||||
|
}
|
@ -27,7 +27,7 @@ func TestDecodeDistributionStore(t *testing.T) {
|
|||||||
cdc := makeTestCodec()
|
cdc := makeTestCodec()
|
||||||
|
|
||||||
prevBlockTime := time.Now().UTC()
|
prevBlockTime := time.Now().UTC()
|
||||||
deposit := types.NewDeposit(sdk.AccAddress("test"), sdk.NewCoin("bnb", sdk.NewInt(1)), "lp")
|
deposit := types.NewDeposit(sdk.AccAddress("test"), sdk.NewCoin("bnb", sdk.NewInt(1)))
|
||||||
claim := types.NewClaim(sdk.AccAddress("test"), "bnb", sdk.NewCoin("hard", sdk.NewInt(100)), "stake")
|
claim := types.NewClaim(sdk.AccAddress("test"), "bnb", sdk.NewCoin("hard", sdk.NewInt(100)), "stake")
|
||||||
|
|
||||||
kvPairs := kv.Pairs{
|
kvPairs := kv.Pairs{
|
||||||
|
@ -11,14 +11,12 @@ There are three messages in the harvest module. Deposit allows users to deposit
|
|||||||
type MsgDeposit struct {
|
type MsgDeposit struct {
|
||||||
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
DepositType string `json:"deposit_type" yaml:"deposit_type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgWithdraw withdraw from the harvest module.
|
// MsgWithdraw withdraw from the harvest module.
|
||||||
type MsgWithdraw struct {
|
type MsgWithdraw struct {
|
||||||
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
DepositType string `json:"deposit_type" yaml:"deposit_type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgClaimReward message type used to claim HARD tokens
|
// MsgClaimReward message type used to claim HARD tokens
|
||||||
|
@ -17,7 +17,6 @@ The harvest module emits the following events:
|
|||||||
| harvest_deposit | amount | `{amount}` |
|
| harvest_deposit | amount | `{amount}` |
|
||||||
| harvest_deposit | depositor | `{depositor address}` |
|
| harvest_deposit | depositor | `{depositor address}` |
|
||||||
| harvest_deposit | deposit_denom | `{deposit denom}` |
|
| harvest_deposit | deposit_denom | `{deposit denom}` |
|
||||||
| harvest_deposit | deposit_type | `{deposit type}` |
|
|
||||||
|
|
||||||
### MsgWithdraw
|
### MsgWithdraw
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ The harvest module emits the following events:
|
|||||||
| harvest_deposit | deposit_type | `{deposit type}` |
|
| harvest_deposit | deposit_type | `{deposit type}` |
|
||||||
| delete_harvest_deposit | depositor | `{depositor address}` |
|
| delete_harvest_deposit | depositor | `{depositor address}` |
|
||||||
| delete_harvest_deposit | deposit_denom | `{deposit denom}` |
|
| delete_harvest_deposit | deposit_denom | `{deposit denom}` |
|
||||||
| delete_harvest_deposit | deposit_type | `{deposit type}` |
|
|
||||||
|
|
||||||
### MsgClaimReward
|
### MsgClaimReward
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ The harvest module emits the following events:
|
|||||||
| claim_harvest_reward | amount | `{amount}` |
|
| claim_harvest_reward | amount | `{amount}` |
|
||||||
| claim_harvest_reward | claim_holder | `{claim holder address}` |
|
| claim_harvest_reward | claim_holder | `{claim holder address}` |
|
||||||
| claim_harvest_reward | deposit_denom | `{deposit denom}` |
|
| claim_harvest_reward | deposit_denom | `{deposit denom}` |
|
||||||
| claim_harvest_reward | deposit_type | `{deposit type}` |
|
| claim_harvest_reward | claim_type | `{claim type}` |
|
||||||
| claim_harvest_reward | claim_multiplier | `{claim multiplier}` |
|
| claim_harvest_reward | claim_multiplier | `{claim multiplier}` |
|
||||||
|
|
||||||
## BeginBlock
|
## BeginBlock
|
||||||
|
@ -9,15 +9,15 @@ type Claim struct {
|
|||||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||||
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
Type DepositType `json:"type" yaml:"type"`
|
Type ClaimType `json:"claim_type" yaml:"claim_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClaim returns a new claim
|
// NewClaim returns a new claim
|
||||||
func NewClaim(owner sdk.AccAddress, denom string, amount sdk.Coin, dtype DepositType) Claim {
|
func NewClaim(owner sdk.AccAddress, denom string, amount sdk.Coin, claimType ClaimType) Claim {
|
||||||
return Claim{
|
return Claim{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
DepositDenom: denom,
|
DepositDenom: denom,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
Type: dtype,
|
Type: claimType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,12 @@ import (
|
|||||||
type Deposit struct {
|
type Deposit struct {
|
||||||
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
Type DepositType `json:"type" yaml:"type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeposit returns a new deposit
|
// NewDeposit returns a new deposit
|
||||||
func NewDeposit(depositor sdk.AccAddress, amount sdk.Coin, dtype DepositType) Deposit {
|
func NewDeposit(depositor sdk.AccAddress, amount sdk.Coin) Deposit {
|
||||||
return Deposit{
|
return Deposit{
|
||||||
Depositor: depositor,
|
Depositor: depositor,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
Type: dtype,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ var (
|
|||||||
ErrInvalidDepositDenom = sdkerrors.Register(ModuleName, 2, "invalid deposit denom")
|
ErrInvalidDepositDenom = sdkerrors.Register(ModuleName, 2, "invalid deposit denom")
|
||||||
// ErrDepositNotFound error for deposit not found
|
// ErrDepositNotFound error for deposit not found
|
||||||
ErrDepositNotFound = sdkerrors.Register(ModuleName, 3, "deposit not found")
|
ErrDepositNotFound = sdkerrors.Register(ModuleName, 3, "deposit not found")
|
||||||
// ErrInvaliWithdrawAmount error for invalid withdrawal amount
|
// ErrInvalidWithdrawAmount error for invalid withdrawal amount
|
||||||
ErrInvaliWithdrawAmount = sdkerrors.Register(ModuleName, 4, "withdrawal amount exceeds deposit amount")
|
ErrInvalidWithdrawAmount = sdkerrors.Register(ModuleName, 4, "withdrawal amount exceeds deposit amount")
|
||||||
// ErrInvalidDepositType error for invalid deposit type
|
// ErrInvalidClaimType error for invalid claim type
|
||||||
ErrInvalidDepositType = sdkerrors.Register(ModuleName, 5, "invalid deposit type")
|
ErrInvalidClaimType = sdkerrors.Register(ModuleName, 5, "invalid claim type")
|
||||||
// ErrClaimNotFound error for claim not found
|
// ErrClaimNotFound error for claim not found
|
||||||
ErrClaimNotFound = sdkerrors.Register(ModuleName, 6, "claim not found")
|
ErrClaimNotFound = sdkerrors.Register(ModuleName, 6, "claim not found")
|
||||||
// ErrZeroClaim error for claim amount rounded to zero
|
// ErrZeroClaim error for claim amount rounded to zero
|
||||||
|
@ -13,9 +13,9 @@ const (
|
|||||||
AttributeKeyBlockHeight = "block_height"
|
AttributeKeyBlockHeight = "block_height"
|
||||||
AttributeKeyRewardsDistribution = "rewards_distributed"
|
AttributeKeyRewardsDistribution = "rewards_distributed"
|
||||||
AttributeKeyDeposit = "deposit"
|
AttributeKeyDeposit = "deposit"
|
||||||
AttributeKeyDepositType = "deposit_type"
|
|
||||||
AttributeKeyDepositDenom = "deposit_denom"
|
AttributeKeyDepositDenom = "deposit_denom"
|
||||||
AttributeKeyDepositor = "depositor"
|
AttributeKeyDepositor = "depositor"
|
||||||
|
AttributeKeyClaimType = "claim_type"
|
||||||
AttributeKeyClaimHolder = "claim_holder"
|
AttributeKeyClaimHolder = "claim_holder"
|
||||||
AttributeKeyClaimAmount = "claim_amount"
|
AttributeKeyClaimAmount = "claim_amount"
|
||||||
AttributeKeyClaimMultiplier = "claim_multiplier"
|
AttributeKeyClaimMultiplier = "claim_multiplier"
|
||||||
|
@ -41,20 +41,25 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// DepositKey key of a specific deposit in the store
|
// DepositKey key of a specific deposit in the store
|
||||||
func DepositKey(depositType DepositType, denom string, depositor sdk.AccAddress) []byte {
|
func DepositKey(denom string, depositor sdk.AccAddress) []byte {
|
||||||
return createKey([]byte(depositType), sep, []byte(denom), sep, depositor)
|
return createKey([]byte(denom), sep, depositor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DepositTypeIteratorKey returns an interator prefix for interating over deposits by deposit type and denom
|
// DepositTypeIteratorKey returns an interator prefix for interating over deposits by deposit denom
|
||||||
func DepositTypeIteratorKey(depositType DepositType, denom string) []byte {
|
func DepositTypeIteratorKey(denom string) []byte {
|
||||||
return createKey([]byte(depositType), sep, []byte(denom))
|
return createKey([]byte(denom))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClaimKey key of a specific deposit in the store
|
// ClaimKey key of a specific deposit in the store
|
||||||
func ClaimKey(depositType DepositType, denom string, owner sdk.AccAddress) []byte {
|
func ClaimKey(depositType ClaimType, denom string, owner sdk.AccAddress) []byte {
|
||||||
return createKey([]byte(depositType), sep, []byte(denom), sep, owner)
|
return createKey([]byte(depositType), sep, []byte(denom), sep, owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClaimTypeIteratorKey returns an interator prefix for interating over claims by deposit type and denom
|
||||||
|
func ClaimTypeIteratorKey(depositType ClaimType, denom string) []byte {
|
||||||
|
return createKey([]byte(depositType), sep, []byte(denom))
|
||||||
|
}
|
||||||
|
|
||||||
func createKey(bytes ...[]byte) (r []byte) {
|
func createKey(bytes ...[]byte) (r []byte) {
|
||||||
for _, b := range bytes {
|
for _, b := range bytes {
|
||||||
r = append(r, b...)
|
r = append(r, b...)
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
// MultiplierName name for valid multiplier
|
// MultiplierName name for valid multiplier
|
||||||
type MultiplierName string
|
type MultiplierName string
|
||||||
|
|
||||||
// DepositType type for valid deposit type strings
|
// ClaimType type for valid claim type strings
|
||||||
type DepositType string
|
type ClaimType string
|
||||||
|
|
||||||
// Valid reward multipliers and reward types
|
// Valid reward multipliers and reward types
|
||||||
const (
|
const (
|
||||||
@ -20,14 +20,13 @@ const (
|
|||||||
Medium MultiplierName = "medium"
|
Medium MultiplierName = "medium"
|
||||||
Large MultiplierName = "large"
|
Large MultiplierName = "large"
|
||||||
|
|
||||||
LP DepositType = "lp"
|
LP ClaimType = "lp"
|
||||||
Stake DepositType = "stake"
|
Stake ClaimType = "stake"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Queryable deposit types
|
// Queryable claim types
|
||||||
var (
|
var (
|
||||||
DepositTypesDepositQuery = []DepositType{LP}
|
ClaimTypesClaimQuery = []ClaimType{LP, Stake}
|
||||||
DepositTypesClaimQuery = []DepositType{LP, Stake}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsValid checks if the input is one of the expected strings
|
// IsValid checks if the input is one of the expected strings
|
||||||
@ -40,12 +39,12 @@ func (mn MultiplierName) IsValid() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsValid checks if the input is one of the expected strings
|
// IsValid checks if the input is one of the expected strings
|
||||||
func (dt DepositType) IsValid() error {
|
func (dt ClaimType) IsValid() error {
|
||||||
switch dt {
|
switch dt {
|
||||||
case LP, Stake:
|
case LP, Stake:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("invalid deposit type: %s", dt)
|
return fmt.Errorf("invalid claim type: %s", dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure Msg interface compliance at compile time
|
// ensure Msg interface compliance at compile time
|
||||||
@ -58,17 +57,15 @@ var (
|
|||||||
|
|
||||||
// MsgDeposit deposit collateral to the harvest module.
|
// MsgDeposit deposit collateral to the harvest module.
|
||||||
type MsgDeposit struct {
|
type MsgDeposit struct {
|
||||||
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
DepositType string `json:"deposit_type" yaml:"deposit_type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgDeposit returns a new MsgDeposit
|
// NewMsgDeposit returns a new MsgDeposit
|
||||||
func NewMsgDeposit(depositor sdk.AccAddress, amount sdk.Coin, depositType string) MsgDeposit {
|
func NewMsgDeposit(depositor sdk.AccAddress, amount sdk.Coin) MsgDeposit {
|
||||||
return MsgDeposit{
|
return MsgDeposit{
|
||||||
Depositor: depositor,
|
Depositor: depositor,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
DepositType: depositType,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +83,7 @@ func (msg MsgDeposit) ValidateBasic() error {
|
|||||||
if !msg.Amount.IsValid() || msg.Amount.IsZero() {
|
if !msg.Amount.IsValid() || msg.Amount.IsZero() {
|
||||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "deposit amount %s", msg.Amount)
|
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "deposit amount %s", msg.Amount)
|
||||||
}
|
}
|
||||||
return DepositType(strings.ToLower(msg.DepositType)).IsValid()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSignBytes gets the canonical byte representation of the Msg.
|
// GetSignBytes gets the canonical byte representation of the Msg.
|
||||||
@ -105,23 +102,20 @@ func (msg MsgDeposit) String() string {
|
|||||||
return fmt.Sprintf(`Deposit Message:
|
return fmt.Sprintf(`Deposit Message:
|
||||||
Depositor: %s
|
Depositor: %s
|
||||||
Amount: %s
|
Amount: %s
|
||||||
Deposit Type: %s
|
`, msg.Depositor, msg.Amount)
|
||||||
`, msg.Depositor, msg.Amount, msg.DepositType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgWithdraw withdraw from the harvest module.
|
// MsgWithdraw withdraw from the harvest module.
|
||||||
type MsgWithdraw struct {
|
type MsgWithdraw struct {
|
||||||
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
||||||
DepositType string `json:"deposit_type" yaml:"deposit_type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgWithdraw returns a new MsgWithdraw
|
// NewMsgWithdraw returns a new MsgWithdraw
|
||||||
func NewMsgWithdraw(depositor sdk.AccAddress, amount sdk.Coin, depositType string) MsgWithdraw {
|
func NewMsgWithdraw(depositor sdk.AccAddress, amount sdk.Coin) MsgWithdraw {
|
||||||
return MsgWithdraw{
|
return MsgWithdraw{
|
||||||
Depositor: depositor,
|
Depositor: depositor,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
DepositType: depositType,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +133,7 @@ func (msg MsgWithdraw) ValidateBasic() error {
|
|||||||
if !msg.Amount.IsValid() || msg.Amount.IsZero() {
|
if !msg.Amount.IsValid() || msg.Amount.IsZero() {
|
||||||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "deposit amount %s", msg.Amount)
|
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "deposit amount %s", msg.Amount)
|
||||||
}
|
}
|
||||||
return DepositType(strings.ToLower(msg.DepositType)).IsValid()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSignBytes gets the canonical byte representation of the Msg.
|
// GetSignBytes gets the canonical byte representation of the Msg.
|
||||||
@ -158,8 +152,7 @@ func (msg MsgWithdraw) String() string {
|
|||||||
return fmt.Sprintf(`Withdraw Message:
|
return fmt.Sprintf(`Withdraw Message:
|
||||||
Depositor: %s
|
Depositor: %s
|
||||||
Amount: %s
|
Amount: %s
|
||||||
Deposit Type: %s
|
`, msg.Depositor, msg.Amount)
|
||||||
`, msg.Depositor, msg.Amount, msg.DepositType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgClaimReward message type used to claim rewards
|
// MsgClaimReward message type used to claim rewards
|
||||||
@ -168,17 +161,17 @@ type MsgClaimReward struct {
|
|||||||
Receiver sdk.AccAddress `json:"receiver" yaml:"receiver"`
|
Receiver sdk.AccAddress `json:"receiver" yaml:"receiver"`
|
||||||
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
||||||
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
|
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
|
||||||
DepositType string `json:"deposit_type" yaml:"deposit_type"`
|
ClaimType string `json:"claim_type" yaml:"claim_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMsgClaimReward returns a new MsgClaimReward.
|
// NewMsgClaimReward returns a new MsgClaimReward.
|
||||||
func NewMsgClaimReward(sender, receiver sdk.AccAddress, depositDenom, depositType, multiplier string) MsgClaimReward {
|
func NewMsgClaimReward(sender, receiver sdk.AccAddress, depositDenom, claimType, multiplier string) MsgClaimReward {
|
||||||
return MsgClaimReward{
|
return MsgClaimReward{
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Receiver: receiver,
|
Receiver: receiver,
|
||||||
DepositDenom: depositDenom,
|
DepositDenom: depositDenom,
|
||||||
MultiplierName: multiplier,
|
MultiplierName: multiplier,
|
||||||
DepositType: depositType,
|
ClaimType: claimType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +192,7 @@ func (msg MsgClaimReward) ValidateBasic() error {
|
|||||||
if err := sdk.ValidateDenom(msg.DepositDenom); err != nil {
|
if err := sdk.ValidateDenom(msg.DepositDenom); err != nil {
|
||||||
return fmt.Errorf("collateral type cannot be blank")
|
return fmt.Errorf("collateral type cannot be blank")
|
||||||
}
|
}
|
||||||
if err := DepositType(strings.ToLower(msg.DepositType)).IsValid(); err != nil {
|
if err := ClaimType(strings.ToLower(msg.ClaimType)).IsValid(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return MultiplierName(strings.ToLower(msg.MultiplierName)).IsValid()
|
return MultiplierName(strings.ToLower(msg.MultiplierName)).IsValid()
|
||||||
|
@ -17,9 +17,8 @@ type MsgTestSuite struct {
|
|||||||
|
|
||||||
func (suite *MsgTestSuite) TestMsgDeposit() {
|
func (suite *MsgTestSuite) TestMsgDeposit() {
|
||||||
type args struct {
|
type args struct {
|
||||||
depositor sdk.AccAddress
|
depositor sdk.AccAddress
|
||||||
amount sdk.Coin
|
amount sdk.Coin
|
||||||
depositType string
|
|
||||||
}
|
}
|
||||||
addrs := []sdk.AccAddress{
|
addrs := []sdk.AccAddress{
|
||||||
sdk.AccAddress("test1"),
|
sdk.AccAddress("test1"),
|
||||||
@ -34,9 +33,8 @@ func (suite *MsgTestSuite) TestMsgDeposit() {
|
|||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
args: args{
|
args: args{
|
||||||
depositor: addrs[0],
|
depositor: addrs[0],
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
||||||
depositType: "lp",
|
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -44,27 +42,16 @@ func (suite *MsgTestSuite) TestMsgDeposit() {
|
|||||||
{
|
{
|
||||||
name: "valid2",
|
name: "valid2",
|
||||||
args: args{
|
args: args{
|
||||||
depositor: addrs[0],
|
depositor: addrs[0],
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
||||||
depositType: "LP",
|
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "invalid",
|
|
||||||
args: args{
|
|
||||||
depositor: addrs[0],
|
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
|
||||||
depositType: "cat",
|
|
||||||
},
|
|
||||||
expectPass: false,
|
|
||||||
expectedErr: "invalid deposit type",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
suite.Run(tc.name, func() {
|
suite.Run(tc.name, func() {
|
||||||
msg := types.NewMsgDeposit(tc.args.depositor, tc.args.amount, tc.args.depositType)
|
msg := types.NewMsgDeposit(tc.args.depositor, tc.args.amount)
|
||||||
err := msg.ValidateBasic()
|
err := msg.ValidateBasic()
|
||||||
if tc.expectPass {
|
if tc.expectPass {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
@ -78,9 +65,8 @@ func (suite *MsgTestSuite) TestMsgDeposit() {
|
|||||||
|
|
||||||
func (suite *MsgTestSuite) TestMsgWithdraw() {
|
func (suite *MsgTestSuite) TestMsgWithdraw() {
|
||||||
type args struct {
|
type args struct {
|
||||||
depositor sdk.AccAddress
|
depositor sdk.AccAddress
|
||||||
amount sdk.Coin
|
amount sdk.Coin
|
||||||
depositType string
|
|
||||||
}
|
}
|
||||||
addrs := []sdk.AccAddress{
|
addrs := []sdk.AccAddress{
|
||||||
sdk.AccAddress("test1"),
|
sdk.AccAddress("test1"),
|
||||||
@ -95,9 +81,8 @@ func (suite *MsgTestSuite) TestMsgWithdraw() {
|
|||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
args: args{
|
args: args{
|
||||||
depositor: addrs[0],
|
depositor: addrs[0],
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
||||||
depositType: "lp",
|
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -105,27 +90,16 @@ func (suite *MsgTestSuite) TestMsgWithdraw() {
|
|||||||
{
|
{
|
||||||
name: "valid2",
|
name: "valid2",
|
||||||
args: args{
|
args: args{
|
||||||
depositor: addrs[0],
|
depositor: addrs[0],
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
||||||
depositType: "LP",
|
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "invalid",
|
|
||||||
args: args{
|
|
||||||
depositor: addrs[0],
|
|
||||||
amount: sdk.NewCoin("bnb", sdk.NewInt(10000000)),
|
|
||||||
depositType: "cat",
|
|
||||||
},
|
|
||||||
expectPass: false,
|
|
||||||
expectedErr: "invalid deposit type",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
suite.Run(tc.name, func() {
|
suite.Run(tc.name, func() {
|
||||||
msg := types.NewMsgWithdraw(tc.args.depositor, tc.args.amount, tc.args.depositType)
|
msg := types.NewMsgWithdraw(tc.args.depositor, tc.args.amount)
|
||||||
err := msg.ValidateBasic()
|
err := msg.ValidateBasic()
|
||||||
if tc.expectPass {
|
if tc.expectPass {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
@ -139,11 +113,11 @@ func (suite *MsgTestSuite) TestMsgWithdraw() {
|
|||||||
|
|
||||||
func (suite *MsgTestSuite) TestMsgClaim() {
|
func (suite *MsgTestSuite) TestMsgClaim() {
|
||||||
type args struct {
|
type args struct {
|
||||||
sender sdk.AccAddress
|
sender sdk.AccAddress
|
||||||
receiver sdk.AccAddress
|
receiver sdk.AccAddress
|
||||||
denom string
|
denom string
|
||||||
depositType string
|
claimType string
|
||||||
multiplier string
|
multiplier string
|
||||||
}
|
}
|
||||||
addrs := []sdk.AccAddress{
|
addrs := []sdk.AccAddress{
|
||||||
sdk.AccAddress("test1"),
|
sdk.AccAddress("test1"),
|
||||||
@ -158,11 +132,11 @@ func (suite *MsgTestSuite) TestMsgClaim() {
|
|||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
args: args{
|
args: args{
|
||||||
sender: addrs[0],
|
sender: addrs[0],
|
||||||
receiver: addrs[0],
|
receiver: addrs[0],
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: "lp",
|
claimType: "lp",
|
||||||
multiplier: "large",
|
multiplier: "large",
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -170,11 +144,11 @@ func (suite *MsgTestSuite) TestMsgClaim() {
|
|||||||
{
|
{
|
||||||
name: "valid2",
|
name: "valid2",
|
||||||
args: args{
|
args: args{
|
||||||
sender: addrs[0],
|
sender: addrs[0],
|
||||||
receiver: addrs[0],
|
receiver: addrs[0],
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: "stake",
|
claimType: "stake",
|
||||||
multiplier: "small",
|
multiplier: "small",
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -182,11 +156,11 @@ func (suite *MsgTestSuite) TestMsgClaim() {
|
|||||||
{
|
{
|
||||||
name: "valid3",
|
name: "valid3",
|
||||||
args: args{
|
args: args{
|
||||||
sender: addrs[0],
|
sender: addrs[0],
|
||||||
receiver: addrs[1],
|
receiver: addrs[1],
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: "lp",
|
claimType: "lp",
|
||||||
multiplier: "Medium",
|
multiplier: "Medium",
|
||||||
},
|
},
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -194,11 +168,11 @@ func (suite *MsgTestSuite) TestMsgClaim() {
|
|||||||
{
|
{
|
||||||
name: "invalid",
|
name: "invalid",
|
||||||
args: args{
|
args: args{
|
||||||
sender: addrs[0],
|
sender: addrs[0],
|
||||||
receiver: addrs[0],
|
receiver: addrs[0],
|
||||||
denom: "bnb",
|
denom: "bnb",
|
||||||
depositType: "lp",
|
claimType: "lp",
|
||||||
multiplier: "huge",
|
multiplier: "huge",
|
||||||
},
|
},
|
||||||
expectPass: false,
|
expectPass: false,
|
||||||
expectedErr: "invalid multiplier name",
|
expectedErr: "invalid multiplier name",
|
||||||
@ -206,7 +180,7 @@ func (suite *MsgTestSuite) TestMsgClaim() {
|
|||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
suite.Run(tc.name, func() {
|
suite.Run(tc.name, func() {
|
||||||
msg := types.NewMsgClaimReward(tc.args.sender, tc.args.receiver, tc.args.denom, tc.args.depositType, tc.args.multiplier)
|
msg := types.NewMsgClaimReward(tc.args.sender, tc.args.receiver, tc.args.denom, tc.args.claimType, tc.args.multiplier)
|
||||||
err := msg.ValidateBasic()
|
err := msg.ValidateBasic()
|
||||||
if tc.expectPass {
|
if tc.expectPass {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
@ -20,17 +20,15 @@ type QueryDepositParams struct {
|
|||||||
Limit int `json:"limit" yaml:"limit"`
|
Limit int `json:"limit" yaml:"limit"`
|
||||||
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
||||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||||
DepositType DepositType `json:"deposit_type" yaml:"deposit_type"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewQueryDepositParams creates a new QueryDepositParams
|
// NewQueryDepositParams creates a new QueryDepositParams
|
||||||
func NewQueryDepositParams(page, limit int, depositDenom string, owner sdk.AccAddress, depositType DepositType) QueryDepositParams {
|
func NewQueryDepositParams(page, limit int, depositDenom string, owner sdk.AccAddress) QueryDepositParams {
|
||||||
return QueryDepositParams{
|
return QueryDepositParams{
|
||||||
Page: page,
|
Page: page,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
DepositDenom: depositDenom,
|
DepositDenom: depositDenom,
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
DepositType: depositType,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,17 +38,17 @@ type QueryClaimParams struct {
|
|||||||
Limit int `json:"limit" yaml:"limit"`
|
Limit int `json:"limit" yaml:"limit"`
|
||||||
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
|
||||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||||
DepositType DepositType `json:"deposit_type" yaml:"deposit_type"`
|
ClaimType ClaimType `json:"claim_type" yaml:"claim_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewQueryClaimParams creates a new QueryClaimParams
|
// NewQueryClaimParams creates a new QueryClaimParams
|
||||||
func NewQueryClaimParams(page, limit int, depositDenom string, owner sdk.AccAddress, depositType DepositType) QueryClaimParams {
|
func NewQueryClaimParams(page, limit int, depositDenom string, owner sdk.AccAddress, claimType ClaimType) QueryClaimParams {
|
||||||
return QueryClaimParams{
|
return QueryClaimParams{
|
||||||
Page: page,
|
Page: page,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
DepositDenom: depositDenom,
|
DepositDenom: depositDenom,
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
DepositType: depositType,
|
ClaimType: claimType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user