Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dang/fix unique kvstore #102

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions x/feeabs/ante/decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions x/feeabs/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions x/feeabs/keeper/proposal.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package keeper

import (

Check failure on line 3 in x/feeabs/keeper/proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/osmosis-labs/fee-abstraction) --custom-order (gci)

Check failure on line 3 in x/feeabs/keeper/proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/osmosis-labs/fee-abstraction) --custom-order (gci)
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/fee-abstraction/v7/x/feeabs/types"

Check failure on line 7 in x/feeabs/keeper/proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/osmosis-labs/fee-abstraction) --custom-order (gci)

Check failure on line 7 in x/feeabs/keeper/proposal.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/osmosis-labs/fee-abstraction) --custom-order (gci)
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)
Expand Down Expand Up @@ -40,7 +45,14 @@
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
}
Expand Down
4 changes: 2 additions & 2 deletions x/feeabs/types/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 1 addition & 0 deletions x/feeabs/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Loading