From 5681fc7265b760ae3a7900a74e806880532d6562 Mon Sep 17 00:00:00 2001 From: GnaD13 Date: Mon, 30 Oct 2023 14:39:36 +0700 Subject: [PATCH 1/4] reduce epoch time --- x/feeabs/types/epoch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/feeabs/types/epoch.go b/x/feeabs/types/epoch.go index 2c99f6cf..568c15df 100644 --- a/x/feeabs/types/epoch.go +++ b/x/feeabs/types/epoch.go @@ -6,8 +6,8 @@ import ( ) const ( - DefaultSwapPeriod time.Duration = time.Minute * 180 - DefaultQueryPeriod time.Duration = time.Minute * 60 + DefaultSwapPeriod time.Duration = time.Minute * 5 + DefaultQueryPeriod time.Duration = time.Minute * 5 DefaultSwapEpochIdentifier string = "swap" DefaultQueryEpochIdentifier string = "query" ) From 8beefb979f77ae685a5d6fcbaa66c23fe1d17f86 Mon Sep 17 00:00:00 2001 From: GnaD13 Date: Mon, 30 Oct 2023 14:57:12 +0700 Subject: [PATCH 2/4] add check hostzone ante handler --- x/feeabs/ante/decorate.go | 5 +++++ x/feeabs/types/errors.go | 1 + 2 files changed, 6 insertions(+) diff --git a/x/feeabs/ante/decorate.go b/x/feeabs/ante/decorate.go index c8fe4552..d74b155e 100644 --- a/x/feeabs/ante/decorate.go +++ b/x/feeabs/ante/decorate.go @@ -253,6 +253,11 @@ func (famfd FeeAbstrationMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk hasHostChainConfig := famfd.feeabsKeeper.HasHostZoneConfig(ctx, feeDenom) if hasHostChainConfig { hostChainConfig, _ := famfd.feeabsKeeper.GetHostZoneConfig(ctx, feeDenom) + // check if hostzone if frozen + if hostChainConfig.Frozen { + return ctx, feeabstypes.ErrHostZoneFrozen + } + nativeCoinsFees, err := famfd.feeabsKeeper.CalculateNativeFromIBCCoins(ctx, feeCoins, hostChainConfig) if err != nil { return ctx, sdkerrors.Wrapf(errorstypes.ErrInsufficientFee, "insufficient fees") diff --git a/x/feeabs/types/errors.go b/x/feeabs/types/errors.go index d941329b..4532da62 100644 --- a/x/feeabs/types/errors.go +++ b/x/feeabs/types/errors.go @@ -9,5 +9,6 @@ var ( ErrInvalidIBCFees = sdkerrors.Register(ModuleName, 2, "invalid ibc fees") ErrHostZoneConfigNotFound = sdkerrors.Register(ModuleName, 3, "host chain config not found") ErrDuplicateHostZoneConfig = sdkerrors.Register(ModuleName, 4, "duplicate config") + ErrHostZoneFrozen = sdkerrors.Register(ModuleName, 5, "hostzone frozen") ErrNotEnoughFundInModuleAddress = sdkerrors.Register(ModuleName, 6, "not have funding yet") ) From 83e6408fbb366e18acbc6c8fa849ccc991f77545 Mon Sep 17 00:00:00 2001 From: GnaD13 Date: Tue, 31 Oct 2023 11:19:00 +0700 Subject: [PATCH 3/4] add check if duplicate host zone --- x/feeabs/keeper/config.go | 6 ++++++ x/feeabs/keeper/proposal.go | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/x/feeabs/keeper/config.go b/x/feeabs/keeper/config.go index 13a7a49d..e3cb0e86 100644 --- a/x/feeabs/keeper/config.go +++ b/x/feeabs/keeper/config.go @@ -27,6 +27,12 @@ func (k Keeper) GetHostZoneConfig(ctx sdk.Context, ibcDenom string) (types.HostC return chainConfig, true } +func (k Keeper) HasHostZoneConfigByOsmosisTokenDenom(ctx sdk.Context, osmosisIbcDenom string) bool { + store := ctx.KVStore(k.storeKey) + key := types.GetKeyHostZoneConfigByOsmosisIBCDenom(osmosisIbcDenom) + return store.Has(key) +} + func (k Keeper) GetHostZoneConfigByOsmosisTokenDenom(ctx sdk.Context, osmosisIbcDenom string) (types.HostChainFeeAbsConfig, bool) { store := ctx.KVStore(k.storeKey) key := types.GetKeyHostZoneConfigByOsmosisIBCDenom(osmosisIbcDenom) diff --git a/x/feeabs/keeper/proposal.go b/x/feeabs/keeper/proposal.go index aa5bec67..ee4fef33 100644 --- a/x/feeabs/keeper/proposal.go +++ b/x/feeabs/keeper/proposal.go @@ -4,12 +4,17 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types" + + errorsmod "cosmossdk.io/errors" ) func (k Keeper) AddHostZoneProposal(ctx sdk.Context, p *types.AddHostZoneProposal) error { - _, found := k.GetHostZoneConfig(ctx, p.HostChainConfig.IbcDenom) - if found { - return types.ErrDuplicateHostZoneConfig + // Check if duplicate host zone + if k.HasHostZoneConfig(ctx, p.HostChainConfig.IbcDenom) { + return errorsmod.Wrapf(types.ErrDuplicateHostZoneConfig, "duplicate IBC denom") + } + if k.HasHostZoneConfigByOsmosisTokenDenom(ctx, p.HostChainConfig.OsmosisPoolTokenDenomIn) { + return errorsmod.Wrapf(types.ErrDuplicateHostZoneConfig, "duplicate Osmosis's IBC denom") } err := k.SetHostZoneConfig(ctx, *p.HostChainConfig) From 0cc89f57547482905af5d716f6f7271968052e56 Mon Sep 17 00:00:00 2001 From: GnaD13 Date: Tue, 31 Oct 2023 11:30:35 +0700 Subject: [PATCH 4/4] fix set hostzone --- x/feeabs/keeper/proposal.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/feeabs/keeper/proposal.go b/x/feeabs/keeper/proposal.go index ee4fef33..44074440 100644 --- a/x/feeabs/keeper/proposal.go +++ b/x/feeabs/keeper/proposal.go @@ -45,7 +45,14 @@ func (k Keeper) SetHostZoneProposal(ctx sdk.Context, p *types.SetHostZoneProposa return types.ErrHostZoneConfigNotFound } - err := k.SetHostZoneConfig(ctx, *p.HostChainConfig) + // Delete all hostzone + err := k.DeleteHostZoneConfig(ctx, p.HostChainConfig.IbcDenom) + if err != nil { + return err + } + + // set new hostzone + err = k.SetHostZoneConfig(ctx, *p.HostChainConfig) if err != nil { return err }