Skip to content

Commit

Permalink
feat: add default denom resolver (#175)
Browse files Browse the repository at this point in the history
Co-authored-by: Mantrachain Development Support <[email protected]>
  • Loading branch information
freeelancer and mantrachain-support authored Oct 6, 2024
1 parent 3dc7912 commit 8b6e6c6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/MANTRA-Chain/mantrachain/x/tokenfactory"
tokenfactorykeeper "github.com/MANTRA-Chain/mantrachain/x/tokenfactory/keeper"
tokenfactorytypes "github.com/MANTRA-Chain/mantrachain/x/tokenfactory/types"
xfeemarkettypes "github.com/MANTRA-Chain/mantrachain/x/xfeemarket/types"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -579,6 +580,8 @@ func New(
nil,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.FeeMarketKeeper.SetDenomResolver(&xfeemarkettypes.DefaultFeemarketDenomResolver{})

app.MarketMapKeeper = marketmapkeeper.NewKeeper(
runtime.NewKVStoreService(keys[marketmaptypes.StoreKey]),
appCodec,
Expand Down
18 changes: 5 additions & 13 deletions x/xfeemarket/keeper/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@ import (
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

var _ feemarkettypes.DenomResolver = &XFeeMarketDenomResolver{}

type XFeeMarketDenomResolver struct {
k Keeper
}

func NewXFeeMarketDenomResolver(k Keeper) *XFeeMarketDenomResolver {
return &XFeeMarketDenomResolver{k: k}
}
var _ feemarkettypes.DenomResolver = &Keeper{}

// ConvertToDenom returns "coin.Amount denom" for all coins that are not the denom.
func (r *XFeeMarketDenomResolver) ConvertToDenom(ctx sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
func (k Keeper) ConvertToDenom(ctx sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
if coin.Denom == denom {
return coin, nil
}

multiplier, err := r.k.DenomMultipliers.Get(ctx, denom)
multiplier, err := k.DenomMultipliers.Get(ctx, denom)
if err != nil {
return sdk.DecCoin{}, err
}
Expand All @@ -30,8 +22,8 @@ func (r *XFeeMarketDenomResolver) ConvertToDenom(ctx sdk.Context, coin sdk.DecCo
return sdk.NewDecCoinFromDec(denom, amount), nil
}

func (r *XFeeMarketDenomResolver) ExtraDenoms(ctx sdk.Context) ([]string, error) {
iter, err := r.k.DenomMultipliers.Iterate(ctx, nil)
func (k Keeper) ExtraDenoms(ctx sdk.Context) ([]string, error) {
iter, err := k.DenomMultipliers.Iterate(ctx, nil)
if err != nil {
return nil, err
}
Expand Down
25 changes: 25 additions & 0 deletions x/xfeemarket/types/default_resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

var _ feemarkettypes.DenomResolver = &DefaultFeemarketDenomResolver{}

type DefaultFeemarketDenomResolver struct{}

// ConvertToDenom returns "coin.Amount denom" for all coins that are not the denom.
func (r *DefaultFeemarketDenomResolver) ConvertToDenom(_ sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
if coin.Denom == denom {
return coin, nil
}

return sdk.DecCoin{}, fmt.Errorf("error resolving denom")
}

func (r *DefaultFeemarketDenomResolver) ExtraDenoms(_ sdk.Context) ([]string, error) {
return []string{}, nil
}

0 comments on commit 8b6e6c6

Please sign in to comment.