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

feat(feemarket): add interface and basic mock #2

Merged
merged 9 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
Empty file added x/feemarket/plugins/README.md
Empty file.
79 changes: 79 additions & 0 deletions x/feemarket/plugins/mock/feemarket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package mock

import (
sdk "github.com/cosmos/cosmos-sdk/types"

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

var _ types.FeeMarketImplementation = &MockFeeMarket{}

type MockFeeMarket struct{} //nolint

// ValidateBasic is a no-op.
func (fm *MockFeeMarket) ValidateBasic() error {
return nil
}

// Init which initializes the fee market (in InitGenesis)
func (fm *MockFeeMarket) Init(_ sdk.Context) error {
return nil
}
aljo242 marked this conversation as resolved.
Show resolved Hide resolved

// EndBlockUpdateHandler allows the fee market to be updated
// after every block. This will be added to the EndBlock chain.
func (fm *MockFeeMarket) EndBlockUpdateHandler(_ sdk.Context) types.UpdateHandler {
return nil
}

// EpochUpdateHandler allows the fee market to be updated
// after every given epoch identifier. This maps the epoch
// identifier to the UpdateHandler that should be executed.
func (fm *MockFeeMarket) EpochUpdateHandler(_ sdk.Context) map[string]types.UpdateHandler {
return nil
}
aljo242 marked this conversation as resolved.
Show resolved Hide resolved

// GetMinGasPrice retrieves the minimum gas price(s) needed
// to be included in the block for the given transaction
func (fm *MockFeeMarket) GetMinGasPrice(_ sdk.Context, _ sdk.Tx) sdk.Coins {
return sdk.NewCoins()
}
aljo242 marked this conversation as resolved.
Show resolved Hide resolved

// GetFeeMarketInfo retrieves the fee market's information about
// how to pay for a transaction (min gas price, min tip,
// where the fees are being distributed, etc.).
func (fm *MockFeeMarket) GetFeeMarketInfo(_ sdk.Context) map[string]string {
return nil
}

// GetID returns the identifier of the fee market
func (fm *MockFeeMarket) GetID() string {
return "mock"
}

// FeeAnteHandler will be called in the module AnteHandler.
// Performs no actions.
func (fm *MockFeeMarket) FeeAnteHandler(
_ sdk.Context,
_ sdk.Tx,
_ bool,
next sdk.AnteHandler,
) sdk.AnteHandler {
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
return next(ctx, tx, simulate)
}
}

// FeePostHandler will be called in the module PostHandler
// if PostHandlers are implemented. Performs no actions.
func (fm *MockFeeMarket) FeePostHandler(
_ sdk.Context,
_ sdk.Tx,
_,
_ bool,
next sdk.PostHandler,
) sdk.PostHandler {
return func(ctx sdk.Context, tx sdk.Tx, simulate, success bool) (newCtx sdk.Context, err error) {
return next(ctx, tx, simulate, success)
}
}
70 changes: 70 additions & 0 deletions x/feemarket/types/feemarket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// FeeMarketImplementation represents the interface of various FeeMarket types implemented
// by other modules or packages.
type FeeMarketImplementation interface {
// proto.Message TODO: add

// ValidateBasic does a simple validation check that
// doesn't require access to any other information.
ValidateBasic() error

// ------------------- Fee Market Parameters ------------------- //

// Init which initializes the fee market (in InitGenesis)
Init(ctx sdk.Context) error

// EndBlockUpdateHandler allows the fee market to be updated
// after every block. This will be added to the EndBlock chain.
EndBlockUpdateHandler(ctx sdk.Context) UpdateHandler

// EpochUpdateHandler allows the fee market to be updated
// after every given epoch identifier. This maps the epoch
// identifier to the UpdateHandler that should be executed.
EpochUpdateHandler(ctx sdk.Context) map[string]UpdateHandler

// ------------------- Fee Market Queries ------------------- //

// GetMinGasPrice retrieves the minimum gas price(s) needed
// to be included in the block for the given transaction
GetMinGasPrice(ctx sdk.Context, tx sdk.Tx) sdk.Coins

// GetFeeMarketInfo retrieves the fee market's information about
// how to pay for a transaction (min gas price, min tip,
// where the fees are being distributed, etc.).
GetFeeMarketInfo(ctx sdk.Context) map[string]string

// GetID returns the identifier of the fee market
GetID() string

// ------------------- Fee Market Extraction ------------------- //

// FeeAnteHandler will be called in the module AnteHandler,
// this is where the fee market would extract and distribute
// fees from a given transaction
FeeAnteHandler(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) sdk.AnteHandler

// FeePostHandler will be called in the module PostHandler
// if PostHandlers are implemented. This is another place
// the fee market might refund users
FeePostHandler(
ctx sdk.Context,
tx sdk.Tx,
simulate,
success bool,
next sdk.PostHandler,
) sdk.PostHandler
}

// UpdateHandler is responsible for updating the parameters of the
// fee market plugin. Fees can optionally also be extracted here.
type UpdateHandler func(ctx sdk.Context) error