From 54cce5a306be53272754a8497a1ddc7adadf4b88 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Fri, 3 May 2024 16:31:41 +0900 Subject: [PATCH] chore: fix to prevent generating swap more than MaxSwaps --- x/fswap/keeper/proposal.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x/fswap/keeper/proposal.go b/x/fswap/keeper/proposal.go index 7f202de690..7ebb8a8df9 100644 --- a/x/fswap/keeper/proposal.go +++ b/x/fswap/keeper/proposal.go @@ -9,6 +9,13 @@ import ( ) func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.Metadata) error { + stats, err := k.getSwapStats(ctx) + if err != nil { + return err + } + if int(stats.SwapCount) >= k.config.MaxSwaps && !k.isUnlimited() { + return types.ErrCanNotHaveMoreSwap.Wrapf("cannot initialize genesis state, there are more than %d swaps", k.config.MaxSwaps) + } isNewSwap := true if _, err := k.getSwap(ctx, swap.FromDenom, swap.ToDenom); err == nil { isNewSwap = false