From 8e10ac8291e3e46957ef70a3e9f84e2796d1fa23 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Thu, 8 Jun 2023 21:44:38 +0900 Subject: [PATCH] feat: min_deposit_rate too high --- x/nftbackedloan/keeper/utils.go | 9 +++++++-- x/nftbackedloan/types/errors.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x/nftbackedloan/keeper/utils.go b/x/nftbackedloan/keeper/utils.go index 4b9e4c06f..936d25bd7 100644 --- a/x/nftbackedloan/keeper/utils.go +++ b/x/nftbackedloan/keeper/utils.go @@ -20,10 +20,10 @@ func validateListNftMsg(k Keeper, ctx sdk.Context, msg *types.MsgListNft) error if err != nil { return err } - return checkListNft(k, ctx, sender, msg.NftId, msg.BidToken) + return checkListNft(k, ctx, sender, msg.NftId, msg.BidToken, msg.MinimumDepositRate) } -func checkListNft(k Keeper, ctx sdk.Context, sender sdk.AccAddress, nftId types.NftIdentifier, bidToken string) error { +func checkListNft(k Keeper, ctx sdk.Context, sender sdk.AccAddress, nftId types.NftIdentifier, bidToken string, minimumDepositRate sdk.Dec) error { // check listing already exists _, err := k.GetNftListingByIdBytes(ctx, nftId.IdBytes()) if err == nil { @@ -45,5 +45,10 @@ func checkListNft(k Keeper, ctx sdk.Context, sender sdk.AccAddress, nftId types. for !Contains(params.BidTokens, bidToken) { return types.ErrNotSupportedBidToken } + + if minimumDepositRate.GTE(sdk.MustNewDecFromStr("0.5")) { + return types.ErrMinimumDepositRateTooHigh + } + return nil } diff --git a/x/nftbackedloan/types/errors.go b/x/nftbackedloan/types/errors.go index 2af8827ce..3169c7d00 100644 --- a/x/nftbackedloan/types/errors.go +++ b/x/nftbackedloan/types/errors.go @@ -44,4 +44,5 @@ var ( ErrInsufficientBalance = sdkerrors.Register(ModuleName, 37, "insufficient balance") ErrSmallBiddingPeriod = sdkerrors.Register(ModuleName, 38, "bidding period is too short") ErrNotExistsNft = sdkerrors.Register(ModuleName, 39, "not exists nft") + ErrMinimumDepositRateTooHigh = sdkerrors.Register(ModuleName, 40, "minimum deposit rate too high") )