From 9f4d21b2e97bcacae44ff08ee5bf933e35df659f Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 15 Nov 2023 12:17:18 -0500 Subject: [PATCH 1/5] proto --- proto/feemarket/feemarket/v1/genesis.proto | 8 +- proto/feemarket/feemarket/v1/params.proto | 5 +- x/feemarket/types/genesis.pb.go | 17 ++-- x/feemarket/types/params.pb.go | 112 +++++++++++++++------ 4 files changed, 100 insertions(+), 42 deletions(-) diff --git a/proto/feemarket/feemarket/v1/genesis.proto b/proto/feemarket/feemarket/v1/genesis.proto index d13cd97..4b89195 100644 --- a/proto/feemarket/feemarket/v1/genesis.proto +++ b/proto/feemarket/feemarket/v1/genesis.proto @@ -45,11 +45,11 @@ message State { // Index is the index of the current block in the block utilization window. uint64 index = 4; - // MaxBlockUtilization is the maximum utilization of a given block. This is denominated - // in the number of gas units consumed per block. + // MaxBlockUtilization is the maximum utilization of a given block. This is + // denominated in the number of gas units consumed per block. uint64 max_block_utilization = 5; - // TargetBlockUtilization is the target utilization of a given block. This is denominated - // in the number of gas units consumed per block. + // TargetBlockUtilization is the target utilization of a given block. This is + // denominated in the number of gas units consumed per block. uint64 target_block_utilization = 6; } diff --git a/proto/feemarket/feemarket/v1/params.proto b/proto/feemarket/feemarket/v1/params.proto index 8b294f3..11bd39e 100644 --- a/proto/feemarket/feemarket/v1/params.proto +++ b/proto/feemarket/feemarket/v1/params.proto @@ -77,7 +77,10 @@ message Params { // over a moving window of blocks. uint64 window = 10; + // FeeDenom is the denom that will be used for all fee payments. + string fee_denom = 11; + // Enabled is a boolean that determines whether the EIP1559 fee market is // enabled. - bool enabled = 11; + bool enabled = 12; } diff --git a/x/feemarket/types/genesis.pb.go b/x/feemarket/types/genesis.pb.go index c7b038e..83bf3ed 100644 --- a/x/feemarket/types/genesis.pb.go +++ b/x/feemarket/types/genesis.pb.go @@ -86,21 +86,22 @@ func (m *GenesisState) GetState() State { // the current base fee, learning rate, and block utilization within the // specified AIMD window. type State struct { - // BaseFee is the current base fee. This is denominated in the fee per gas unit. + // BaseFee is the current base fee. This is denominated in the fee per gas + // unit. BaseFee cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=base_fee,json=baseFee,proto3,customtype=cosmossdk.io/math.Int" json:"base_fee"` // LearningRate is the current learning rate. LearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=learning_rate,json=learningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"learning_rate"` - // Window contains a list of the last blocks' utilization values. This is used to - // calculate the next base fee. This stores the number of units of gas consumed - // per block. + // Window contains a list of the last blocks' utilization values. This is used + // to calculate the next base fee. This stores the number of units of gas + // consumed per block. Window []uint64 `protobuf:"varint,3,rep,packed,name=window,proto3" json:"window,omitempty"` // Index is the index of the current block in the block utilization window. Index uint64 `protobuf:"varint,4,opt,name=index,proto3" json:"index,omitempty"` - // MaxBlockUtilization is the maximum utilization of a given block. This is denominated - // in the number of gas units consumed per block. + // MaxBlockUtilization is the maximum utilization of a given block. This is + // denominated in the number of gas units consumed per block. MaxBlockUtilization uint64 `protobuf:"varint,5,opt,name=max_block_utilization,json=maxBlockUtilization,proto3" json:"max_block_utilization,omitempty"` - // TargetBlockUtilization is the target utilization of a given block. This is denominated - // in the number of gas units consumed per block. + // TargetBlockUtilization is the target utilization of a given block. This is + // denominated in the number of gas units consumed per block. TargetBlockUtilization uint64 `protobuf:"varint,6,opt,name=target_block_utilization,json=targetBlockUtilization,proto3" json:"target_block_utilization,omitempty"` } diff --git a/x/feemarket/types/params.pb.go b/x/feemarket/types/params.pb.go index 7be2a5f..0809db5 100644 --- a/x/feemarket/types/params.pb.go +++ b/x/feemarket/types/params.pb.go @@ -58,9 +58,11 @@ type Params struct { // Window defines the window size for calculating an adaptive learning rate // over a moving window of blocks. Window uint64 `protobuf:"varint,10,opt,name=window,proto3" json:"window,omitempty"` + // FeeDenom is the denom that will be used for all fee payments. + FeeDenom string `protobuf:"bytes,11,opt,name=fee_denom,json=feeDenom,proto3" json:"fee_denom,omitempty"` // Enabled is a boolean that determines whether the EIP1559 fee market is // enabled. - Enabled bool `protobuf:"varint,11,opt,name=enabled,proto3" json:"enabled,omitempty"` + Enabled bool `protobuf:"varint,12,opt,name=enabled,proto3" json:"enabled,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -117,6 +119,13 @@ func (m *Params) GetWindow() uint64 { return 0 } +func (m *Params) GetFeeDenom() string { + if m != nil { + return m.FeeDenom + } + return "" +} + func (m *Params) GetEnabled() bool { if m != nil { return m.Enabled @@ -133,34 +142,36 @@ func init() { } var fileDescriptor_3907de4df2e1c66e = []byte{ - // 430 bytes of a gzipped FileDescriptorProto + // 451 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0xd3, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0x07, 0xf0, 0x46, 0xdb, 0xee, 0xee, 0x28, 0x88, 0xd1, 0x2d, 0xe3, 0x0a, 0xd9, 0xa2, 0x97, - 0x82, 0x6c, 0x42, 0xf5, 0xe2, 0xb9, 0xac, 0x4a, 0x61, 0x05, 0x09, 0x78, 0x11, 0x24, 0xbc, 0xa4, - 0x6f, 0xd3, 0xa1, 0x99, 0x99, 0x90, 0xbc, 0xed, 0x76, 0xfd, 0x14, 0x7e, 0x18, 0x3f, 0xc4, 0x1e, - 0x17, 0x2f, 0x8a, 0x87, 0x22, 0xed, 0x17, 0x91, 0xcc, 0x44, 0x5b, 0xb7, 0xb7, 0xdc, 0xde, 0x9b, - 0x37, 0xff, 0xdf, 0xbc, 0xcb, 0xb0, 0xe7, 0xe7, 0x88, 0x12, 0x8a, 0x19, 0x52, 0xb0, 0xa9, 0xe6, - 0xc3, 0x20, 0x87, 0x02, 0x64, 0xe9, 0xe7, 0x85, 0x26, 0xed, 0xf6, 0xfe, 0x8d, 0xfc, 0x4d, 0x35, - 0x1f, 0x1e, 0x3d, 0x49, 0x74, 0x29, 0x75, 0x19, 0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0x9b, 0x87, 0xf4, 0xea, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7e, 0xef, 0x08, 0x09, 0xb8, + 0x03, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -191,7 +202,14 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0 } i-- - dAtA[i] = 0x58 + dAtA[i] = 0x60 + } + if len(m.FeeDenom) > 0 { + i -= len(m.FeeDenom) + copy(dAtA[i:], m.FeeDenom) + i = encodeVarintParams(dAtA, i, uint64(len(m.FeeDenom))) + i-- + dAtA[i] = 0x5a } if m.Window != 0 { i = encodeVarintParams(dAtA, i, uint64(m.Window)) @@ -321,6 +339,10 @@ func (m *Params) Size() (n int) { if m.Window != 0 { n += 1 + sovParams(uint64(m.Window)) } + l = len(m.FeeDenom) + if l > 0 { + n += 1 + l + sovParams(uint64(l)) + } if m.Enabled { n += 2 } @@ -658,6 +680,38 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeeDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FeeDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 12: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) } From 364aaa1367484f394307e4dd5c39ffa5aea2e7e2 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 15 Nov 2023 12:25:20 -0500 Subject: [PATCH 2/5] add param --- x/feemarket/types/eip1559.go | 23 +++--- x/feemarket/types/eip1559_aimd.go | 18 +++-- x/feemarket/types/params.go | 6 ++ x/feemarket/types/params_test.go | 112 ++++++++++++++++++++---------- 4 files changed, 107 insertions(+), 52 deletions(-) diff --git a/x/feemarket/types/eip1559.go b/x/feemarket/types/eip1559.go index 40ed3ed..b2a2360 100644 --- a/x/feemarket/types/eip1559.go +++ b/x/feemarket/types/eip1559.go @@ -1,6 +1,9 @@ package types -import "cosmossdk.io/math" +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) // Note: We use the same default values as Ethereum for the EIP-1559 // fee market implementation. These parameters do not implement the @@ -13,16 +16,16 @@ var ( DefaultWindow uint64 = 1 // DefaultAlpha is not used in the base EIP-1559 implementation. - DefaultAlpha math.LegacyDec = math.LegacyMustNewDecFromStr("0.0") + DefaultAlpha = math.LegacyMustNewDecFromStr("0.0") // DefaultBeta is not used in the base EIP-1559 implementation. - DefaultBeta math.LegacyDec = math.LegacyMustNewDecFromStr("1.0") + DefaultBeta = math.LegacyMustNewDecFromStr("1.0") // DefaultTheta is not used in the base EIP-1559 implementation. - DefaultTheta math.LegacyDec = math.LegacyMustNewDecFromStr("0.0") + DefaultTheta = math.LegacyMustNewDecFromStr("0.0") // DefaultDelta is not used in the base EIP-1559 implementation. - DefaultDelta math.LegacyDec = math.LegacyMustNewDecFromStr("0.0") + DefaultDelta = math.LegacyMustNewDecFromStr("0.0") // DefaultTargetBlockSize is the default target block utilization. This is the default // on Ethereum. This denominated in units of gas consumed in a block. @@ -35,13 +38,16 @@ var ( // DefaultMinBaseFee is the default minimum base fee. This is the default // on Ethereum. Note that Ethereum is denominated in 1e18 wei. Cosmos chains will // likely want to change this to 1e6. - DefaultMinBaseFee math.Int = math.NewInt(1_000_000_000) + DefaultMinBaseFee = math.NewInt(1_000_000_000) // DefaultMinLearningRate is not used in the base EIP-1559 implementation. - DefaultMinLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.125") + DefaultMinLearningRate = math.LegacyMustNewDecFromStr("0.125") // DefaultMaxLearningRate is not used in the base EIP-1559 implementation. - DefaultMaxLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.125") + DefaultMaxLearningRate = math.LegacyMustNewDecFromStr("0.125") + + // DefaultFeeDenom is the Cosmos SDK default bond denom. + DefaultFeeDenom = sdk.DefaultBondDenom ) // DefaultParams returns a default set of parameters that implements @@ -59,6 +65,7 @@ func DefaultParams() Params { DefaultMinBaseFee, DefaultMinLearningRate, DefaultMaxLearningRate, + DefaultFeeDenom, true, ) } diff --git a/x/feemarket/types/eip1559_aimd.go b/x/feemarket/types/eip1559_aimd.go index 4153739..8cd102d 100644 --- a/x/feemarket/types/eip1559_aimd.go +++ b/x/feemarket/types/eip1559_aimd.go @@ -14,24 +14,24 @@ var ( // DefaultAIMDAlpha is the default alpha value for the learning // rate calculation. This value determines how much we want to additively // increase the learning rate when the target block size is exceeded. - DefaultAIMDAlpha math.LegacyDec = math.LegacyMustNewDecFromStr("0.025") + DefaultAIMDAlpha = math.LegacyMustNewDecFromStr("0.025") // DefaultAIMDBeta is the default beta value for the learning rate // calculation. This value determines how much we want to multiplicatively // decrease the learning rate when the target utilization is not met. - DefaultAIMDBeta math.LegacyDec = math.LegacyMustNewDecFromStr("0.95") + DefaultAIMDBeta = math.LegacyMustNewDecFromStr("0.95") // DefaultAIMDTheta is the default threshold for determining whether // to increase or decrease the learning rate. In this case, we increase // the learning rate if the block utilization within the window is greater // than 0.75 or less than 0.25. Otherwise, we multiplicatively decrease // the learning rate. - DefaultAIMDTheta math.LegacyDec = math.LegacyMustNewDecFromStr("0.25") + DefaultAIMDTheta = math.LegacyMustNewDecFromStr("0.25") // DefaultAIMDDelta is the default delta value for how much we additively // increase or decrease the base fee when the net block utilization within // the window is not equal to the target utilization. - DefaultAIMDDelta math.LegacyDec = math.LegacyMustNewDecFromStr("0.0") + DefaultAIMDDelta = math.LegacyMustNewDecFromStr("0.0") // DefaultAIMDTargetBlockSize is the default target block utilization. This // is the default on Ethereum. This denominated in units of gas consumed in @@ -46,13 +46,16 @@ var ( // DefaultAIMDMinBaseFee is the default minimum base fee. This is the // default on Ethereum. Note that ethereum is denominated in 1e18 wei. // Cosmos chains will likely want to change this to 1e6. - DefaultAIMDMinBaseFee math.Int = math.NewInt(1_000_000_000) + DefaultAIMDMinBaseFee = math.NewInt(1_000_000_000) // DefaultAIMDMinLearningRate is the default minimum learning rate. - DefaultAIMDMinLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.01") + DefaultAIMDMinLearningRate = math.LegacyMustNewDecFromStr("0.01") // DefaultAIMDMaxLearningRate is the default maximum learning rate. - DefaultAIMDMaxLearningRate math.LegacyDec = math.LegacyMustNewDecFromStr("0.50") + DefaultAIMDMaxLearningRate = math.LegacyMustNewDecFromStr("0.50") + + // DefaultAIMDFeeDenom is the Cosmos SDK default bond denom. + DefaultAIMDFeeDenom = DefaultFeeDenom ) // DefaultAIMDParams returns a default set of parameters that implements @@ -71,6 +74,7 @@ func DefaultAIMDParams() Params { DefaultAIMDMinBaseFee, DefaultAIMDMinLearningRate, DefaultAIMDMaxLearningRate, + DefaultAIMDFeeDenom, true, ) } diff --git a/x/feemarket/types/params.go b/x/feemarket/types/params.go index a00f438..4e2d41c 100644 --- a/x/feemarket/types/params.go +++ b/x/feemarket/types/params.go @@ -19,6 +19,7 @@ func NewParams( minBaseFee math.Int, minLearingRate math.LegacyDec, maxLearningRate math.LegacyDec, + feeDenom string, enabled bool, ) Params { return Params{ @@ -32,6 +33,7 @@ func NewParams( TargetBlockUtilization: targetBlockSize, MaxBlockUtilization: maxBlockSize, Window: window, + FeeDenom: feeDenom, Enabled: enabled, } } @@ -86,5 +88,9 @@ func (p *Params) ValidateBasic() error { return fmt.Errorf("min learning rate cannot be greater than max learning rate") } + if p.FeeDenom == "" { + return fmt.Errorf("fee denom must be set") + } + return nil } diff --git a/x/feemarket/types/params_test.go b/x/feemarket/types/params_test.go index 2c44884..a52c322 100644 --- a/x/feemarket/types/params_test.go +++ b/x/feemarket/types/params_test.go @@ -31,102 +31,115 @@ func TestParams(t *testing.T) { expectedErr: true, }, { - name: "nil alpha", - p: types.Params{Window: 1}, + name: "nil alpha", + p: types.Params{ + Window: 1, + FeeDenom: types.DefaultFeeDenom, + }, expectedErr: true, }, { name: "negative alpha", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("-0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("-0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "beta is nil", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "beta is negative", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("-0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("-0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "beta is greater than 1", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("1.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("1.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "theta is nil", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "theta is negative", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("0.1"), - Theta: math.LegacyMustNewDecFromStr("-0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("-0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "theta is greater than 1", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("0.1"), - Theta: math.LegacyMustNewDecFromStr("1.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("1.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "delta is nil", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("0.1"), - Theta: math.LegacyMustNewDecFromStr("0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "delta is negative", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("0.1"), - Theta: math.LegacyMustNewDecFromStr("0.1"), - Delta: math.LegacyMustNewDecFromStr("-0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("0.1"), + Delta: math.LegacyMustNewDecFromStr("-0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, { name: "target block size is zero", p: types.Params{ - Window: 1, - Alpha: math.LegacyMustNewDecFromStr("0.1"), - Beta: math.LegacyMustNewDecFromStr("0.1"), - Theta: math.LegacyMustNewDecFromStr("0.1"), - Delta: math.LegacyMustNewDecFromStr("0.1"), + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("0.1"), + Delta: math.LegacyMustNewDecFromStr("0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -139,6 +152,7 @@ func TestParams(t *testing.T) { Theta: math.LegacyMustNewDecFromStr("0.1"), Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 1, + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -152,6 +166,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 1, + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -165,6 +180,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -179,6 +195,7 @@ func TestParams(t *testing.T) { TargetBlockUtilization: 2, MaxBlockUtilization: 3, MinBaseFee: math.NewInt(-1), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -193,6 +210,7 @@ func TestParams(t *testing.T) { TargetBlockUtilization: 2, MaxBlockUtilization: 3, MinBaseFee: math.NewInt(1), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -208,6 +226,7 @@ func TestParams(t *testing.T) { MaxBlockUtilization: 3, MinBaseFee: math.NewInt(1), MinLearningRate: math.LegacyMustNewDecFromStr("-0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -223,6 +242,7 @@ func TestParams(t *testing.T) { MaxBlockUtilization: 3, MinBaseFee: math.NewInt(1), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -239,6 +259,7 @@ func TestParams(t *testing.T) { MinBaseFee: math.NewInt(1), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("-0.1"), + FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, }, @@ -255,6 +276,23 @@ func TestParams(t *testing.T) { MinBaseFee: math.NewInt(1), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("0.05"), + FeeDenom: types.DefaultFeeDenom, + }, + expectedErr: true, + }, + { + name: "fee denom is empty", + p: types.Params{ + Window: 1, + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("0.1"), + Delta: math.LegacyMustNewDecFromStr("0.1"), + TargetBlockUtilization: 2, + MaxBlockUtilization: 3, + MinBaseFee: math.NewInt(1), + MinLearningRate: math.LegacyMustNewDecFromStr("0.01"), + MaxLearningRate: math.LegacyMustNewDecFromStr("0.05"), }, expectedErr: true, }, From 018da67ed1d0db100eb6bf22b58806cad5185268 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 15 Nov 2023 12:27:42 -0500 Subject: [PATCH 3/5] add get --- x/feemarket/keeper/feemarket.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/x/feemarket/keeper/feemarket.go b/x/feemarket/keeper/feemarket.go index e973736..7c3feac 100644 --- a/x/feemarket/keeper/feemarket.go +++ b/x/feemarket/keeper/feemarket.go @@ -71,3 +71,21 @@ func (k *Keeper) GetLearningRate(ctx sdk.Context) (math.LegacyDec, error) { return state.LearningRate, nil } + +// GetMinGasPrices returns the mininum gas prices as sdk.Coins from the fee market state. +func (k *Keeper) GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) { + baseFee, err := k.GetBaseFee(ctx) + if err != nil { + return sdk.NewCoins(), err + } + + params, err := k.GetParams(ctx) + if err != nil { + return sdk.NewCoins(), err + } + + fee := sdk.NewCoin(params.FeeDenom, baseFee) + minGasPrices := sdk.NewCoins(fee) + + return minGasPrices, nil +} From 81ed0fbb22a60ba4f007a469eac9cfdc4996e7f0 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 15 Nov 2023 12:29:27 -0500 Subject: [PATCH 4/5] test --- x/feemarket/keeper/feemarket_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/x/feemarket/keeper/feemarket_test.go b/x/feemarket/keeper/feemarket_test.go index 5fc0298..f42943d 100644 --- a/x/feemarket/keeper/feemarket_test.go +++ b/x/feemarket/keeper/feemarket_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/skip-mev/feemarket/x/feemarket/types" ) @@ -47,3 +48,27 @@ func (s *KeeperTestSuite) TestGetLearningRate() { s.Require().Equal(lr, gs.State.LearningRate) }) } + +func (s *KeeperTestSuite) TestGetMinGasPrices() { + s.Run("can retrieve min gas prices with default eip-1559", func() { + gs := types.DefaultGenesisState() + s.feemarketKeeper.InitGenesis(s.ctx, *gs) + + expected := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, gs.State.BaseFee)) + + mgp, err := s.feemarketKeeper.GetMinGasPrices(s.ctx) + s.Require().NoError(err) + s.Require().Equal(expected, mgp) + }) + + s.Run("can retrieve min gas prices with aimd eip-1559", func() { + gs := types.DefaultAIMDGenesisState() + s.feemarketKeeper.InitGenesis(s.ctx, *gs) + + expected := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, gs.State.BaseFee)) + + mgp, err := s.feemarketKeeper.GetMinGasPrices(s.ctx) + s.Require().NoError(err) + s.Require().Equal(expected, mgp) + }) +} From 7549ced8304ba4ff33e20513ed1023f013e7c675 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 15 Nov 2023 12:30:47 -0500 Subject: [PATCH 5/5] format --- x/feemarket/keeper/feemarket_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/feemarket/keeper/feemarket_test.go b/x/feemarket/keeper/feemarket_test.go index f42943d..ec074c5 100644 --- a/x/feemarket/keeper/feemarket_test.go +++ b/x/feemarket/keeper/feemarket_test.go @@ -2,6 +2,7 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/feemarket/x/feemarket/types" )