diff --git a/x/feemarket/plugins/README.md b/x/feemarket/plugins/README.md new file mode 100644 index 0000000..e69de29 diff --git a/x/feemarket/plugins/mock/feemarket.go b/x/feemarket/plugins/mock/feemarket.go new file mode 100644 index 0000000..bf161e4 --- /dev/null +++ b/x/feemarket/plugins/mock/feemarket.go @@ -0,0 +1,83 @@ +package mock + +import ( + "encoding/json" + + 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 +} + +// Export which exports the fee market (in ExportGenesis) +func (fm *MockFeeMarket) Export(_ sdk.Context) (json.RawMessage, error) { + return nil, nil +} + +// BeginBlockUpdateHandler allows the fee market to be updated +// after every block. This will be added to the BeginBlock chain. +func (fm *MockFeeMarket) BeginBlockUpdateHandler(_ sdk.Context) types.UpdateHandler { + return func(ctx sdk.Context) error { + return nil + } +} + +// 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 func(ctx sdk.Context) error { + return nil + } +} + +// 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) + } +} diff --git a/x/feemarket/types/feemarket.go b/x/feemarket/types/feemarket.go new file mode 100644 index 0000000..3876870 --- /dev/null +++ b/x/feemarket/types/feemarket.go @@ -0,0 +1,70 @@ +package types + +import ( + "encoding/json" + + 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 + + // Export which exports the fee market (in ExportGenesis) + Export(ctx sdk.Context) (json.RawMessage, error) + + // BeginBlockUpdateHandler allows the fee market to be updated + // after every block. This will be added to the BeginBlock chain. + BeginBlockUpdateHandler(ctx sdk.Context) UpdateHandler + + // EndBlockUpdateHandler allows the fee market to be updated + // after every block. This will be added to the EndBlock chain. + EndBlockUpdateHandler(ctx sdk.Context) UpdateHandler + + // ------------------- Fee Market Queries ------------------- // + + // 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