Clean up leftover Hard module claim types/queries (#775)

* clean up types

* clean up client/rest

* clean up alias

* remove LP/Gov schedule errors

* clean up claim multipliers
This commit is contained in:
Denali Marsh 2021-01-21 18:38:52 +01:00 committed by GitHub
parent 4eef80b47f
commit f89b8797ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 416 deletions

View File

@ -9,10 +9,6 @@ import (
const ( const (
AttributeKeyBlockHeight = types.AttributeKeyBlockHeight AttributeKeyBlockHeight = types.AttributeKeyBlockHeight
AttributeKeyClaimAmount = types.AttributeKeyClaimAmount
AttributeKeyClaimHolder = types.AttributeKeyClaimHolder
AttributeKeyClaimMultiplier = types.AttributeKeyClaimMultiplier
AttributeKeyClaimType = types.AttributeKeyClaimType
AttributeKeyDeposit = types.AttributeKeyDeposit AttributeKeyDeposit = types.AttributeKeyDeposit
AttributeKeyDepositDenom = types.AttributeKeyDepositDenom AttributeKeyDepositDenom = types.AttributeKeyDepositDenom
AttributeKeyDepositor = types.AttributeKeyDepositor AttributeKeyDepositor = types.AttributeKeyDepositor
@ -20,27 +16,20 @@ const (
AttributeValueCategory = types.AttributeValueCategory AttributeValueCategory = types.AttributeValueCategory
DefaultParamspace = types.DefaultParamspace DefaultParamspace = types.DefaultParamspace
DelegatorAccount = types.DelegatorAccount DelegatorAccount = types.DelegatorAccount
EventTypeClaimHardReward = types.EventTypeClaimHardReward
EventTypeDeleteHardDeposit = types.EventTypeDeleteHardDeposit EventTypeDeleteHardDeposit = types.EventTypeDeleteHardDeposit
EventTypeHardDelegatorDistribution = types.EventTypeHardDelegatorDistribution EventTypeHardDelegatorDistribution = types.EventTypeHardDelegatorDistribution
EventTypeHardDeposit = types.EventTypeHardDeposit EventTypeHardDeposit = types.EventTypeHardDeposit
EventTypeHardLPDistribution = types.EventTypeHardLPDistribution EventTypeHardLPDistribution = types.EventTypeHardLPDistribution
EventTypeHardWithdrawal = types.EventTypeHardWithdrawal EventTypeHardWithdrawal = types.EventTypeHardWithdrawal
LP = types.LP
LPAccount = types.LPAccount LPAccount = types.LPAccount
LiquidatorAccount = types.LiquidatorAccount LiquidatorAccount = types.LiquidatorAccount
Large = types.Large
Medium = types.Medium
ModuleAccountName = types.ModuleAccountName ModuleAccountName = types.ModuleAccountName
ModuleName = types.ModuleName ModuleName = types.ModuleName
QuerierRoute = types.QuerierRoute QuerierRoute = types.QuerierRoute
QueryGetClaims = types.QueryGetClaims
QueryGetDeposits = types.QueryGetDeposits QueryGetDeposits = types.QueryGetDeposits
QueryGetModuleAccounts = types.QueryGetModuleAccounts QueryGetModuleAccounts = types.QueryGetModuleAccounts
QueryGetParams = types.QueryGetParams QueryGetParams = types.QueryGetParams
RouterKey = types.RouterKey RouterKey = types.RouterKey
Small = types.Small
Stake = types.Stake
StoreKey = types.StoreKey StoreKey = types.StoreKey
) )
@ -61,16 +50,13 @@ var (
NewInterestRateModel = types.NewInterestRateModel NewInterestRateModel = types.NewInterestRateModel
NewDeposit = types.NewDeposit NewDeposit = types.NewDeposit
NewGenesisState = types.NewGenesisState NewGenesisState = types.NewGenesisState
NewMsgClaimReward = types.NewMsgClaimReward
NewMsgDeposit = types.NewMsgDeposit NewMsgDeposit = types.NewMsgDeposit
NewMsgWithdraw = types.NewMsgWithdraw NewMsgWithdraw = types.NewMsgWithdraw
NewMultiHARDHooks = types.NewMultiHARDHooks NewMultiHARDHooks = types.NewMultiHARDHooks
NewMultiplier = types.NewMultiplier
NewParams = types.NewParams NewParams = types.NewParams
NewPeriod = types.NewPeriod NewPeriod = types.NewPeriod
NewMoneyMarket = types.NewMoneyMarket NewMoneyMarket = types.NewMoneyMarket
NewQueryAccountParams = types.NewQueryAccountParams NewQueryAccountParams = types.NewQueryAccountParams
NewQueryClaimParams = types.NewQueryClaimParams
ParamKeyTable = types.ParamKeyTable ParamKeyTable = types.ParamKeyTable
RegisterCodec = types.RegisterCodec RegisterCodec = types.RegisterCodec
@ -78,21 +64,13 @@ var (
BorrowsKeyPrefix = types.BorrowsKeyPrefix BorrowsKeyPrefix = types.BorrowsKeyPrefix
DefaultActive = types.DefaultActive DefaultActive = types.DefaultActive
DefaultPreviousBlockTime = types.DefaultPreviousBlockTime DefaultPreviousBlockTime = types.DefaultPreviousBlockTime
ClaimTypesClaimQuery = types.ClaimTypesClaimQuery
DepositsKeyPrefix = types.DepositsKeyPrefix DepositsKeyPrefix = types.DepositsKeyPrefix
ErrAccountNotFound = types.ErrAccountNotFound ErrAccountNotFound = types.ErrAccountNotFound
ErrClaimExpired = types.ErrClaimExpired
ErrClaimNotFound = types.ErrClaimNotFound
ErrDepositNotFound = types.ErrDepositNotFound ErrDepositNotFound = types.ErrDepositNotFound
ErrGovScheduleNotFound = types.ErrGovScheduleNotFound
ErrInsufficientModAccountBalance = types.ErrInsufficientModAccountBalance ErrInsufficientModAccountBalance = types.ErrInsufficientModAccountBalance
ErrInvaliWithdrawAmount = types.ErrInvalidWithdrawAmount ErrInvaliWithdrawAmount = types.ErrInvalidWithdrawAmount
ErrInvalidAccountType = types.ErrInvalidAccountType ErrInvalidAccountType = types.ErrInvalidAccountType
ErrInvalidDepositDenom = types.ErrInvalidDepositDenom ErrInvalidDepositDenom = types.ErrInvalidDepositDenom
ErrInvalidClaimType = types.ErrInvalidClaimType
ErrInvalidMultiplier = types.ErrInvalidMultiplier
ErrLPScheduleNotFound = types.ErrLPScheduleNotFound
ErrZeroClaim = types.ErrZeroClaim
GovDenom = types.GovDenom GovDenom = types.GovDenom
KeyActive = types.KeyActive KeyActive = types.KeyActive
ModuleCdc = types.ModuleCdc ModuleCdc = types.ModuleCdc
@ -106,17 +84,11 @@ type (
MoneyMarket = types.MoneyMarket MoneyMarket = types.MoneyMarket
MoneyMarkets = types.MoneyMarkets MoneyMarkets = types.MoneyMarkets
Deposit = types.Deposit Deposit = types.Deposit
ClaimType = types.ClaimType
GenesisState = types.GenesisState GenesisState = types.GenesisState
MsgClaimReward = types.MsgClaimReward
MsgDeposit = types.MsgDeposit MsgDeposit = types.MsgDeposit
MsgWithdraw = types.MsgWithdraw MsgWithdraw = types.MsgWithdraw
Multiplier = types.Multiplier
MultiplierName = types.MultiplierName
Multipliers = types.Multipliers
Params = types.Params Params = types.Params
QueryAccountParams = types.QueryAccountParams QueryAccountParams = types.QueryAccountParams
QueryClaimParams = types.QueryClaimParams
StakingKeeper = types.StakingKeeper StakingKeeper = types.StakingKeeper
SupplyKeeper = types.SupplyKeeper SupplyKeeper = types.SupplyKeeper
) )

View File

@ -18,7 +18,6 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/%s/parameters", types.ModuleName), queryParamsHandlerFn(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/parameters", types.ModuleName), queryParamsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/deposits", types.ModuleName), queryDepositsHandlerFn(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/deposits", types.ModuleName), queryDepositsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/total-deposited", types.ModuleName), queryTotalDepositedHandlerFn(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/total-deposited", types.ModuleName), queryTotalDepositedHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/claims", types.ModuleName), queryClaimsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/accounts", types.ModuleName), queryModAccountsHandlerFn(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/accounts", types.ModuleName), queryModAccountsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/borrows", types.ModuleName), queryBorrowsHandlerFn(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/borrows", types.ModuleName), queryBorrowsHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/total-borrowed", types.ModuleName), queryTotalBorrowedHandlerFn(cliCtx)).Methods("GET") r.HandleFunc(fmt.Sprintf("/%s/total-borrowed", types.ModuleName), queryTotalBorrowedHandlerFn(cliCtx)).Methods("GET")
@ -130,65 +129,6 @@ func queryTotalDepositedHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
} }
} }
func queryClaimsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
// Parse the query height
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}
var denom string
var claimOwner sdk.AccAddress
var claimType types.ClaimType
if x := r.URL.Query().Get(RestDenom); len(x) != 0 {
denom = strings.TrimSpace(x)
}
if x := r.URL.Query().Get(RestOwner); len(x) != 0 {
claimOwnerStr := strings.ToLower(strings.TrimSpace(x))
claimOwner, err = sdk.AccAddressFromBech32(claimOwnerStr)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("cannot parse address from claim owner %s", claimOwnerStr))
return
}
}
if x := r.URL.Query().Get(RestClaimType); len(x) != 0 {
claimTypeStr := strings.ToLower(strings.TrimSpace(x))
err := types.ClaimType(claimTypeStr).IsValid()
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
claimType = types.ClaimType(claimTypeStr)
}
params := types.NewQueryClaimParams(page, limit, denom, claimOwner, claimType)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetClaims)
res, height, err := cliCtx.QueryWithData(route, bz)
cliCtx = cliCtx.WithHeight(height)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
rest.PostProcessResponse(w, cliCtx, res)
}
}
func queryBorrowsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { func queryBorrowsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0) _, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)

View File

@ -11,10 +11,9 @@ import (
// REST variable names // REST variable names
// nolint // nolint
const ( const (
RestOwner = "owner" RestOwner = "owner"
RestDenom = "denom" RestDenom = "denom"
RestClaimType = "claim-type" RestName = "name"
RestName = "name"
) )
// RegisterRoutes registers hard-related REST handlers to a router // RegisterRoutes registers hard-related REST handlers to a router
@ -37,16 +36,6 @@ type PostCreateWithdrawReq struct {
Amount sdk.Coins `json:"amount" yaml:"amount"` Amount sdk.Coins `json:"amount" yaml:"amount"`
} }
// PostClaimReq defines the properties of a claim reward request's body
type PostClaimReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
From sdk.AccAddress `json:"from" yaml:"from"`
Receiver sdk.AccAddress `json:"receiver" yaml:"receiver"`
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
ClaimType string `json:"claim_type" yaml:"claim_type"`
}
// PostBorrowReq defines the properties of a borrow request's body // PostBorrowReq defines the properties of a borrow request's body
type PostBorrowReq struct { type PostBorrowReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`

View File

@ -3,7 +3,6 @@ package rest
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"strings"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -18,7 +17,6 @@ import (
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(fmt.Sprintf("/%s/deposit", types.ModuleName), postDepositHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/%s/deposit", types.ModuleName), postDepositHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/withdraw", types.ModuleName), postWithdrawHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/%s/withdraw", types.ModuleName), postWithdrawHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/claim", types.ModuleName), postClaimHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/borrow", types.ModuleName), postBorrowHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/%s/borrow", types.ModuleName), postBorrowHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/repay", types.ModuleName), postRepayHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/%s/repay", types.ModuleName), postRepayHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/liquidate", types.ModuleName), postLiquidateHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/%s/liquidate", types.ModuleName), postLiquidateHandlerFn(cliCtx)).Methods("POST")
@ -66,27 +64,6 @@ func postWithdrawHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
} }
} }
func postClaimHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Decode POST request body
var req PostClaimReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
req.BaseReq = req.BaseReq.Sanitize()
if !req.BaseReq.ValidateBasic(w) {
return
}
msg := types.NewMsgClaimReward(req.From, req.Receiver, req.DepositDenom, strings.ToLower(req.ClaimType), req.MultiplierName)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
func postBorrowHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { func postBorrowHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
// Decode POST request body // Decode POST request body

View File

@ -14,7 +14,6 @@ func init() {
// RegisterCodec registers the necessary types for hard module // RegisterCodec registers the necessary types for hard module
func RegisterCodec(cdc *codec.Codec) { func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgClaimReward{}, "hard/MsgClaimReward", nil)
cdc.RegisterConcrete(MsgDeposit{}, "hard/MsgDeposit", nil) cdc.RegisterConcrete(MsgDeposit{}, "hard/MsgDeposit", nil)
cdc.RegisterConcrete(MsgWithdraw{}, "hard/MsgWithdraw", nil) cdc.RegisterConcrete(MsgWithdraw{}, "hard/MsgWithdraw", nil)
cdc.RegisterConcrete(MsgBorrow{}, "hard/MsgBorrow", nil) cdc.RegisterConcrete(MsgBorrow{}, "hard/MsgBorrow", nil)

View File

@ -8,71 +8,57 @@ import (
var ( var (
// ErrInvalidDepositDenom error for invalid deposit denoms // ErrInvalidDepositDenom error for invalid deposit denoms
ErrInvalidDepositDenom = sdkerrors.Register(ModuleName, 2, "invalid deposit denom") ErrInvalidDepositDenom = sdkerrors.Register(ModuleName, 1, "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, 2, "deposit not found")
// ErrInvalidWithdrawAmount error for invalid withdrawal amount // ErrInvalidWithdrawAmount error for invalid withdrawal amount
ErrInvalidWithdrawAmount = sdkerrors.Register(ModuleName, 4, "invalid withdrawal amount") ErrInvalidWithdrawAmount = sdkerrors.Register(ModuleName, 3, "invalid withdrawal amount")
// ErrInvalidClaimType error for invalid claim type
ErrInvalidClaimType = sdkerrors.Register(ModuleName, 5, "invalid claim type")
// ErrClaimNotFound error for claim not found
ErrClaimNotFound = sdkerrors.Register(ModuleName, 6, "claim not found")
// ErrZeroClaim error for claim amount rounded to zero
ErrZeroClaim = sdkerrors.Register(ModuleName, 7, "cannot claim - claim amount rounds to zero")
// ErrLPScheduleNotFound error for liquidity provider rewards schedule not found
ErrLPScheduleNotFound = sdkerrors.Register(ModuleName, 8, "no liquidity provider rewards schedule found")
// ErrGovScheduleNotFound error for governance distribution rewards schedule not found
ErrGovScheduleNotFound = sdkerrors.Register(ModuleName, 9, "no governance rewards schedule found")
// ErrInvalidMultiplier error for multiplier not found
ErrInvalidMultiplier = sdkerrors.Register(ModuleName, 10, "invalid rewards multiplier")
// ErrInsufficientModAccountBalance error for module account with innsufficient balance // ErrInsufficientModAccountBalance error for module account with innsufficient balance
ErrInsufficientModAccountBalance = sdkerrors.Register(ModuleName, 11, "module account has insufficient balance to pay reward") ErrInsufficientModAccountBalance = sdkerrors.Register(ModuleName, 4, "module account has insufficient balance to pay reward")
// ErrInvalidAccountType error for unsupported accounts // ErrInvalidAccountType error for unsupported accounts
ErrInvalidAccountType = sdkerrors.Register(ModuleName, 12, "receiver account type not supported") ErrInvalidAccountType = sdkerrors.Register(ModuleName, 5, "receiver account type not supported")
// ErrAccountNotFound error for accounts that are not found in state // ErrAccountNotFound error for accounts that are not found in state
ErrAccountNotFound = sdkerrors.Register(ModuleName, 13, "account not found") ErrAccountNotFound = sdkerrors.Register(ModuleName, 6, "account not found")
// ErrClaimExpired error for expired claims
ErrClaimExpired = sdkerrors.Register(ModuleName, 14, "claim period expired")
// ErrInvalidReceiver error for when sending and receiving accounts don't match // ErrInvalidReceiver error for when sending and receiving accounts don't match
ErrInvalidReceiver = sdkerrors.Register(ModuleName, 15, "receiver account must match sender account") ErrInvalidReceiver = sdkerrors.Register(ModuleName, 7, "receiver account must match sender account")
// ErrMoneyMarketNotFound error for money market param not found // ErrMoneyMarketNotFound error for money market param not found
ErrMoneyMarketNotFound = sdkerrors.Register(ModuleName, 16, "no money market found") ErrMoneyMarketNotFound = sdkerrors.Register(ModuleName, 8, "no money market found")
// ErrDepositsNotFound error for no deposits found // ErrDepositsNotFound error for no deposits found
ErrDepositsNotFound = sdkerrors.Register(ModuleName, 17, "no deposits found") ErrDepositsNotFound = sdkerrors.Register(ModuleName, 9, "no deposits found")
// ErrInsufficientLoanToValue error for when an attempted borrow exceeds maximum loan-to-value // ErrInsufficientLoanToValue error for when an attempted borrow exceeds maximum loan-to-value
ErrInsufficientLoanToValue = sdkerrors.Register(ModuleName, 18, "not enough collateral supplied by account") ErrInsufficientLoanToValue = sdkerrors.Register(ModuleName, 10, "not enough collateral supplied by account")
// ErrMarketNotFound error for when a market for the input denom is not found // ErrMarketNotFound error for when a market for the input denom is not found
ErrMarketNotFound = sdkerrors.Register(ModuleName, 19, "no market found for denom") ErrMarketNotFound = sdkerrors.Register(ModuleName, 11, "no market found for denom")
// ErrPriceNotFound error for when a price for the input market is not found // ErrPriceNotFound error for when a price for the input market is not found
ErrPriceNotFound = sdkerrors.Register(ModuleName, 20, "no price found for market") ErrPriceNotFound = sdkerrors.Register(ModuleName, 12, "no price found for market")
// ErrBorrowExceedsAvailableBalance for when a requested borrow exceeds available module acc balances // ErrBorrowExceedsAvailableBalance for when a requested borrow exceeds available module acc balances
ErrBorrowExceedsAvailableBalance = sdkerrors.Register(ModuleName, 21, "exceeds module account balance") ErrBorrowExceedsAvailableBalance = sdkerrors.Register(ModuleName, 13, "exceeds module account balance")
// ErrBorrowedCoinsNotFound error for when the total amount of borrowed coins cannot be found // ErrBorrowedCoinsNotFound error for when the total amount of borrowed coins cannot be found
ErrBorrowedCoinsNotFound = sdkerrors.Register(ModuleName, 22, "no borrowed coins found") ErrBorrowedCoinsNotFound = sdkerrors.Register(ModuleName, 14, "no borrowed coins found")
// ErrNegativeBorrowedCoins error for when substracting coins from the total borrowed balance results in a negative amount // ErrNegativeBorrowedCoins error for when substracting coins from the total borrowed balance results in a negative amount
ErrNegativeBorrowedCoins = sdkerrors.Register(ModuleName, 23, "subtraction results in negative borrow amount") ErrNegativeBorrowedCoins = sdkerrors.Register(ModuleName, 15, "subtraction results in negative borrow amount")
// ErrGreaterThanAssetBorrowLimit error for when a proposed borrow would increase borrowed amount over the asset's global borrow limit // ErrGreaterThanAssetBorrowLimit error for when a proposed borrow would increase borrowed amount over the asset's global borrow limit
ErrGreaterThanAssetBorrowLimit = sdkerrors.Register(ModuleName, 24, "fails global asset borrow limit validation") ErrGreaterThanAssetBorrowLimit = sdkerrors.Register(ModuleName, 16, "fails global asset borrow limit validation")
// ErrBorrowEmptyCoins error for when you cannot borrow empty coins // ErrBorrowEmptyCoins error for when you cannot borrow empty coins
ErrBorrowEmptyCoins = sdkerrors.Register(ModuleName, 25, "cannot borrow zero coins") ErrBorrowEmptyCoins = sdkerrors.Register(ModuleName, 17, "cannot borrow zero coins")
// ErrBorrowNotFound error for when a user's borrow is not found in the store // ErrBorrowNotFound error for when a user's borrow is not found in the store
ErrBorrowNotFound = sdkerrors.Register(ModuleName, 26, "borrow not found") ErrBorrowNotFound = sdkerrors.Register(ModuleName, 18, "borrow not found")
// ErrPreviousAccrualTimeNotFound error for no previous accrual time found in store // ErrPreviousAccrualTimeNotFound error for no previous accrual time found in store
ErrPreviousAccrualTimeNotFound = sdkerrors.Register(ModuleName, 27, "no previous accrual time found") ErrPreviousAccrualTimeNotFound = sdkerrors.Register(ModuleName, 19, "no previous accrual time found")
// ErrInsufficientBalanceForRepay error for when requested repay exceeds user's balance // ErrInsufficientBalanceForRepay error for when requested repay exceeds user's balance
ErrInsufficientBalanceForRepay = sdkerrors.Register(ModuleName, 28, "insufficient balance") ErrInsufficientBalanceForRepay = sdkerrors.Register(ModuleName, 20, "insufficient balance")
// ErrBorrowNotLiquidatable error for when a borrow is within valid LTV and cannot be liquidated // ErrBorrowNotLiquidatable error for when a borrow is within valid LTV and cannot be liquidated
ErrBorrowNotLiquidatable = sdkerrors.Register(ModuleName, 29, "borrow not liquidatable") ErrBorrowNotLiquidatable = sdkerrors.Register(ModuleName, 21, "borrow not liquidatable")
// ErrInsufficientCoins error for when there are not enough coins for the operation // ErrInsufficientCoins error for when there are not enough coins for the operation
ErrInsufficientCoins = sdkerrors.Register(ModuleName, 30, "unrecoverable state - insufficient coins") ErrInsufficientCoins = sdkerrors.Register(ModuleName, 22, "unrecoverable state - insufficient coins")
// ErrInsufficientBalanceForBorrow error for when the requested borrow exceeds user's balance // ErrInsufficientBalanceForBorrow error for when the requested borrow exceeds user's balance
ErrInsufficientBalanceForBorrow = sdkerrors.Register(ModuleName, 31, "insufficient balance") ErrInsufficientBalanceForBorrow = sdkerrors.Register(ModuleName, 23, "insufficient balance")
// ErrSuppliedCoinsNotFound error for when the total amount of supplied coins cannot be found // ErrSuppliedCoinsNotFound error for when the total amount of supplied coins cannot be found
ErrSuppliedCoinsNotFound = sdkerrors.Register(ModuleName, 32, "no supplied coins found") ErrSuppliedCoinsNotFound = sdkerrors.Register(ModuleName, 24, "no supplied coins found")
// ErrNegativeSuppliedCoins error for when substracting coins from the total supplied balance results in a negative amount // ErrNegativeSuppliedCoins error for when substracting coins from the total supplied balance results in a negative amount
ErrNegativeSuppliedCoins = sdkerrors.Register(ModuleName, 33, "subtraction results in negative supplied amount") ErrNegativeSuppliedCoins = sdkerrors.Register(ModuleName, 25, "subtraction results in negative supplied amount")
// ErrInvalidWithdrawDenom error for when user attempts to withdraw a non-supplied coin type // ErrInvalidWithdrawDenom error for when user attempts to withdraw a non-supplied coin type
ErrInvalidWithdrawDenom = sdkerrors.Register(ModuleName, 34, "no coins of this type deposited") ErrInvalidWithdrawDenom = sdkerrors.Register(ModuleName, 26, "no coins of this type deposited")
// ErrInvalidRepaymentDenom error for when user attempts to repay a non-borrowed coin type // ErrInvalidRepaymentDenom error for when user attempts to repay a non-borrowed coin type
ErrInvalidRepaymentDenom = sdkerrors.Register(ModuleName, 35, "no coins of this type borrowed") ErrInvalidRepaymentDenom = sdkerrors.Register(ModuleName, 27, "no coins of this type borrowed")
) )

View File

@ -7,24 +7,19 @@ const (
EventTypeHardLPDistribution = "hard_lp_distribution" EventTypeHardLPDistribution = "hard_lp_distribution"
EventTypeDeleteHardDeposit = "delete_hard_deposit" EventTypeDeleteHardDeposit = "delete_hard_deposit"
EventTypeHardWithdrawal = "hard_withdrawal" EventTypeHardWithdrawal = "hard_withdrawal"
EventTypeClaimHardReward = "claim_hard_reward"
EventTypeHardBorrow = "hard_borrow" EventTypeHardBorrow = "hard_borrow"
EventTypeDepositLiquidation = "hard_liquidation" EventTypeDepositLiquidation = "hard_liquidation"
EventTypeHardRepay = "hard_repay" EventTypeHardRepay = "hard_repay"
AttributeValueCategory = ModuleName AttributeValueCategory = ModuleName
AttributeKeyBlockHeight = "block_height" AttributeKeyBlockHeight = "block_height"
AttributeKeyRewardsDistribution = "rewards_distributed" AttributeKeyRewardsDistribution = "rewards_distributed"
AttributeKeyDeposit = "deposit" AttributeKeyDeposit = "deposit"
AttributeKeyDepositDenom = "deposit_denom" AttributeKeyDepositDenom = "deposit_denom"
AttributeKeyDepositCoins = "deposit_coins" AttributeKeyDepositCoins = "deposit_coins"
AttributeKeyDepositor = "depositor" AttributeKeyDepositor = "depositor"
AttributeKeyClaimType = "claim_type" AttributeKeyBorrow = "borrow"
AttributeKeyClaimHolder = "claim_holder" AttributeKeyBorrower = "borrower"
AttributeKeyClaimAmount = "claim_amount" AttributeKeyBorrowCoins = "borrow_coins"
AttributeKeyClaimMultiplier = "claim_multiplier" AttributeKeySender = "sender"
AttributeKeyBorrow = "borrow" AttributeKeyRepayCoins = "repay_coins"
AttributeKeyBorrower = "borrower"
AttributeKeyBorrowCoins = "borrow_coins"
AttributeKeySender = "sender"
AttributeKeyRepayCoins = "repay_coins"
) )

View File

@ -2,54 +2,13 @@ package types
import ( import (
"fmt" "fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
) )
// MultiplierName name for valid multiplier
type MultiplierName string
// ClaimType type for valid claim type strings
type ClaimType string
// Valid reward multipliers and reward types
const (
Small MultiplierName = "small"
Medium MultiplierName = "medium"
Large MultiplierName = "large"
LP ClaimType = "lp"
Stake ClaimType = "stake"
)
// Queryable claim types
var (
ClaimTypesClaimQuery = []ClaimType{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 ClaimType) IsValid() error {
switch dt {
case LP, Stake:
return nil
}
return fmt.Errorf("invalid claim type: %s", dt)
}
// ensure Msg interface compliance at compile time // ensure Msg interface compliance at compile time
var ( var (
_ sdk.Msg = &MsgClaimReward{}
_ sdk.Msg = &MsgDeposit{} _ sdk.Msg = &MsgDeposit{}
_ sdk.Msg = &MsgWithdraw{} _ sdk.Msg = &MsgWithdraw{}
_ sdk.Msg = &MsgBorrow{} _ sdk.Msg = &MsgBorrow{}
@ -157,60 +116,6 @@ func (msg MsgWithdraw) String() string {
`, msg.Depositor, msg.Amount) `, msg.Depositor, msg.Amount)
} }
// MsgClaimReward message type used to claim rewards
type MsgClaimReward struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
Receiver sdk.AccAddress `json:"receiver" yaml:"receiver"`
DepositDenom string `json:"deposit_denom" yaml:"deposit_denom"`
MultiplierName string `json:"multiplier_name" yaml:"multiplier_name"`
ClaimType string `json:"claim_type" yaml:"claim_type"`
}
// NewMsgClaimReward returns a new MsgClaimReward.
func NewMsgClaimReward(sender, receiver sdk.AccAddress, depositDenom, claimType, multiplier string) MsgClaimReward {
return MsgClaimReward{
Sender: sender,
Receiver: receiver,
DepositDenom: depositDenom,
MultiplierName: multiplier,
ClaimType: claimType,
}
}
// Route return the message type used for routing the message.
func (msg MsgClaimReward) Route() string { return RouterKey }
// Type returns a human-readable string for the message, intended for utilization within tags.
func (msg MsgClaimReward) Type() string { return "claim_hard_reward" }
// ValidateBasic does a simple validation check that doesn't require access to state.
func (msg MsgClaimReward) ValidateBasic() error {
if msg.Sender.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "sender address cannot be empty")
}
if msg.Receiver.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "receiver address cannot be empty")
}
if err := sdk.ValidateDenom(msg.DepositDenom); err != nil {
return fmt.Errorf("collateral type cannot be blank")
}
if err := ClaimType(strings.ToLower(msg.ClaimType)).IsValid(); err != nil {
return err
}
return MultiplierName(strings.ToLower(msg.MultiplierName)).IsValid()
}
// GetSignBytes gets the canonical byte representation of the Msg.
func (msg MsgClaimReward) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
// GetSigners returns the addresses of signers that must sign.
func (msg MsgClaimReward) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
}
// MsgBorrow borrows funds from the hard module. // MsgBorrow borrows funds from the hard module.
type MsgBorrow struct { type MsgBorrow struct {
Borrower sdk.AccAddress `json:"borrower" yaml:"borrower"` Borrower sdk.AccAddress `json:"borrower" yaml:"borrower"`

View File

@ -111,87 +111,6 @@ func (suite *MsgTestSuite) TestMsgWithdraw() {
} }
} }
func (suite *MsgTestSuite) TestMsgClaim() {
type args struct {
sender sdk.AccAddress
receiver sdk.AccAddress
denom string
claimType string
multiplier string
}
addrs := []sdk.AccAddress{
sdk.AccAddress("test1"),
sdk.AccAddress("test2"),
}
testCases := []struct {
name string
args args
expectPass bool
expectedErr string
}{
{
name: "valid",
args: args{
sender: addrs[0],
receiver: addrs[0],
denom: "bnb",
claimType: "lp",
multiplier: "large",
},
expectPass: true,
expectedErr: "",
},
{
name: "valid2",
args: args{
sender: addrs[0],
receiver: addrs[0],
denom: "bnb",
claimType: "stake",
multiplier: "small",
},
expectPass: true,
expectedErr: "",
},
{
name: "valid3",
args: args{
sender: addrs[0],
receiver: addrs[1],
denom: "bnb",
claimType: "lp",
multiplier: "Medium",
},
expectPass: true,
expectedErr: "",
},
{
name: "invalid",
args: args{
sender: addrs[0],
receiver: addrs[0],
denom: "bnb",
claimType: "lp",
multiplier: "huge",
},
expectPass: false,
expectedErr: "invalid multiplier name",
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
msg := types.NewMsgClaimReward(tc.args.sender, tc.args.receiver, tc.args.denom, tc.args.claimType, tc.args.multiplier)
err := msg.ValidateBasic()
if tc.expectPass {
suite.NoError(err)
} else {
suite.Error(err)
suite.Require().True(strings.Contains(err.Error(), tc.expectedErr))
}
})
}
}
func (suite *MsgTestSuite) TestMsgBorrow() { func (suite *MsgTestSuite) TestMsgBorrow() {
type args struct { type args struct {
borrower sdk.AccAddress borrower sdk.AccAddress

View File

@ -27,40 +27,6 @@ type Params struct {
CheckLtvIndexCount int `json:"check_ltv_index_count" yaml:"check_ltv_index_count"` CheckLtvIndexCount int `json:"check_ltv_index_count" yaml:"check_ltv_index_count"`
} }
// 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
}
// Multipliers slice of Multiplier
type Multipliers []Multiplier
// BorrowLimit enforces restrictions on a money market // BorrowLimit enforces restrictions on a money market
type BorrowLimit struct { type BorrowLimit struct {
HasMaxLimit bool `json:"has_max_limit" yaml:"has_max_limit"` HasMaxLimit bool `json:"has_max_limit" yaml:"has_max_limit"`

View File

@ -10,7 +10,6 @@ const (
QueryGetModuleAccounts = "accounts" QueryGetModuleAccounts = "accounts"
QueryGetDeposits = "deposits" QueryGetDeposits = "deposits"
QueryGetTotalDeposited = "total-deposited" QueryGetTotalDeposited = "total-deposited"
QueryGetClaims = "claims"
QueryGetBorrows = "borrows" QueryGetBorrows = "borrows"
QueryGetTotalBorrowed = "total-borrowed" QueryGetTotalBorrowed = "total-borrowed"
) )
@ -33,26 +32,6 @@ func NewQueryDepositsParams(page, limit int, denom string, owner sdk.AccAddress)
} }
} }
// QueryClaimParams is the params for a filtered claim query
type QueryClaimParams struct {
Page int `json:"page" yaml:"page"`
Limit int `json:"limit" yaml:"limit"`
Denom string `json:"denom" yaml:"denom"`
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
ClaimType ClaimType `json:"claim_type" yaml:"claim_type"`
}
// NewQueryClaimParams creates a new QueryClaimParams
func NewQueryClaimParams(page, limit int, denom string, owner sdk.AccAddress, claimType ClaimType) QueryClaimParams {
return QueryClaimParams{
Page: page,
Limit: limit,
Denom: denom,
Owner: owner,
ClaimType: claimType,
}
}
// QueryAccountParams is the params for a filtered module account query // QueryAccountParams is the params for a filtered module account query
type QueryAccountParams struct { type QueryAccountParams struct {
Page int `json:"page" yaml:"page"` Page int `json:"page" yaml:"page"`