Skip to content

Commit

Permalink
added readme + rename denom_resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
freeelancer committed Sep 8, 2024
1 parent 16c7cd3 commit 551be14
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func New(
app.ModuleManager.RegisterInvariants(app.CrisisKeeper)

// to support multiple denom as fee token
app.FeeMarketKeeper.SetDenomResolver(xfeemarketkeeper.NewTestDenomResolver(app.XFeeMarketKeeper))
app.FeeMarketKeeper.SetDenomResolver(xfeemarketkeeper.NewXFeeMarketDenomResolver(app.XFeeMarketKeeper))

// create the simulation manager and define the order of the modules for deterministic simulations
overrideModules := map[string]module.AppModuleSimulation{
Expand Down
72 changes: 72 additions & 0 deletions x/xfeemarket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# `x/xfeemarket`

## Abstract

This document specifies the `xfeemarket` module of mantrachain.

The `xfeemarket` module is to supplement the `feemarket` module by skip-mev.

It provides an implementation for the `DenomResolver` interface, which is
required to support multiple different fee tokens. It also has a `PostHandler`
that Replaces the default feemarket `PostHandler` to eliminate tips and burn
all fees paid by users.

## Contents

* [DenomResolver](#denomresolver)
* [PostHandler](#posthandler)
* [State](#state)
* [Messages](#messages)

## DenomResolver

The current `DenomResolver` implementation allows an authority account to update a
map of denom => multiplier. This enables the module to calculate gas fees for
different fee tokens based on a multiplier applied to the base denom's gas fee.

Future versions may leverage the skip-mev `connect` module to dynamically fetch
oracle prices for the base fee token and the supplied token, enabling more
accurate gas fee calculations.

## PostHandler

The custom `PostHandler` eliminates tips and burns all fees paid by users.

## State

The `x/xfeemarket` module keeps state of the following primary objects:

1. Denomination Multipliers

In addition, the `x/xfeemarket` module keeps the following indexes to manage the
aforementioned state:

* Denomination Multipliers: `0x1 | byte(denom) -> sdk.DecProto(multiplier)`

## Messages

### MsgUpsertFeeDenom

Upsert a multiplier for denom.

```protobuf reference
https://github.com/MANTRA-Chain/mantrachain/proto/mantrachain/xfeemarket/v1/tx.proto#L41-L46
```

The message handling can fail if:

* signer is not the gov module account address.
* denom Metadata does not exists.

### MsgRemoveFeeDenom

Remove a multiplier for denom.

```protobuf reference
https://github.com/MANTRA-Chain/mantrachain/proto/mantrachain/xfeemarket/v1/tx.proto#L50-L54
```

The message handling can fail if:

* signer is not the gov module account address.
* denom is not stored in the current Denomination Multipliers
12 changes: 6 additions & 6 deletions x/xfeemarket/keeper/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

var _ feemarkettypes.DenomResolver = &DenomResolver{}
var _ feemarkettypes.DenomResolver = &XFeeMarketDenomResolver{}

type DenomResolver struct {
type XFeeMarketDenomResolver struct {
k Keeper
}

func NewTestDenomResolver(k Keeper) *DenomResolver {
return &DenomResolver{k: k}
func NewXFeeMarketDenomResolver(k Keeper) *XFeeMarketDenomResolver {
return &XFeeMarketDenomResolver{k: k}
}

// ConvertToDenom returns "coin.Amount denom" for all coins that are not the denom.
func (r *DenomResolver) ConvertToDenom(ctx sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
func (r *XFeeMarketDenomResolver) ConvertToDenom(ctx sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
if coin.Denom == denom {
return coin, nil
}
Expand All @@ -30,7 +30,7 @@ func (r *DenomResolver) ConvertToDenom(ctx sdk.Context, coin sdk.DecCoin, denom
return sdk.NewDecCoinFromDec(denom, amount), nil
}

func (r *DenomResolver) ExtraDenoms(ctx sdk.Context) ([]string, error) {
func (r *XFeeMarketDenomResolver) ExtraDenoms(ctx sdk.Context) ([]string, error) {
iter, err := r.k.DenomMultipliers.Iterate(ctx, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 551be14

Please sign in to comment.