diff --git a/app/app.go b/app/app.go index 9ad4dc8bf..5b1350e28 100644 --- a/app/app.go +++ b/app/app.go @@ -221,7 +221,7 @@ var ( cellarfeestypes.ModuleName: nil, incentivestypes.ModuleName: nil, axelarcorktypes.ModuleName: nil, - auctiontypes.ModuleName: nil, + auctiontypes.ModuleName: {authtypes.Burner}, pubsubtypes.ModuleName: nil, addressestypes.ModuleName: nil, } diff --git a/integration_tests/auction_test.go b/integration_tests/auction_test.go index f5c5d7361..6e15a4218 100644 --- a/integration_tests/auction_test.go +++ b/integration_tests/auction_test.go @@ -21,6 +21,11 @@ func (s *IntegrationTestSuite) TestAuction() { s.Require().NoError(err) auctionQueryClient := types.NewQueryClient(val0ClientCtx) + // Query the total supply of usomm before the auction + bankQueryClient := banktypes.NewQueryClient(val0ClientCtx) + supplyRes, err := bankQueryClient.SupplyOf(context.Background(), &banktypes.QuerySupplyOfRequest{Denom: testDenom}) + s.Require().NoError(err) + // Verify auction created for testing exists auctionQuery := types.QueryActiveAuctionRequest{ AuctionId: uint32(1), @@ -115,7 +120,6 @@ func (s *IntegrationTestSuite) TestAuction() { }, time.Second*30, time.Second*5, "proposal was never accepted") s.T().Log("Proposal approved!") - bankQueryClient := banktypes.NewQueryClient(val0ClientCtx) balanceRes, err := bankQueryClient.AllBalances(context.Background(), &banktypes.QueryAllBalancesRequest{Address: authtypes.NewModuleAddress(types.ModuleName).String()}) s.Require().NoError(err) s.T().Logf("Auction module token balances before bids %v", balanceRes.Balances) @@ -293,6 +297,37 @@ func (s *IntegrationTestSuite) TestAuction() { s.Require().Equal(expectedEndedAuction, *endedAuctionResponse.Auction) s.T().Log("Ended auction stored correctly!") + s.T().Log("Verifying cellarfees module account balance...") + cellarfeesModuleAddress := authtypes.NewModuleAddress(cellarfees.ModuleName).String() + cellarfeesBalanceRes, err := bankQueryClient.AllBalances(context.Background(), &banktypes.QueryAllBalancesRequest{Address: cellarfeesModuleAddress}) + s.Require().NoError(err) + + totalSommPaid := expectedBid1.TotalUsommPaid.Amount.Add(expectedBid2.TotalUsommPaid.Amount) + // default burn rate is 0.5 so 50% of the SOMM paid to the cellarfees module account + expectedCellarfeesSomm := totalSommPaid.Quo(sdk.NewInt(2)) + + found, cellarfeesSommBalance := balanceOfDenom(cellarfeesBalanceRes.Balances, testDenom) + s.Require().True(found, "SOMM balance not present in cellarfees module account") + s.Require().GreaterOrEqual(expectedCellarfeesSomm.Int64(), cellarfeesSommBalance.Amount.Int64(), "Cellarfees module account should have 50% or less of the SOMM received from the auction (less if distributions have occurred)") + s.T().Log("Cellarfees module account balance verified correctly!") + + s.T().Log("Verifying total supply of usomm has been reduced...") + + // Calculate the expected burn amount (50% of total SOMM paid in auction) + expectedBurnAmount := totalSommPaid.Quo(sdk.NewInt(2)) + + // Calculate the expected new total supply + expectedNewSupply := supplyRes.Amount.Amount.Sub(expectedBurnAmount) + + // Query the actual new total supply + newSupplyRes, err := bankQueryClient.SupplyOf(context.Background(), &banktypes.QuerySupplyOfRequest{Denom: testDenom}) + s.Require().NoError(err) + + // Verify that the new supply matches the expected new supply + s.Require().Equal(expectedNewSupply.Int64(), newSupplyRes.Amount.Amount.Int64(), "Total supply of usomm should be reduced by the amount burnt") + + s.T().Log("Total supply of usomm has been correctly reduced!") + s.T().Log("--Test completed successfully--") }) } diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index 4ff230b4e..20aa3243c 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -415,6 +415,7 @@ func (s *IntegrationTestSuite) initGenesis() { // Add an auction for integration testing of the auction module var auctionGenState auctiontypes.GenesisState s.Require().NoError(cdc.UnmarshalJSON(appGenState[auctiontypes.ModuleName], &auctionGenState)) + auctionGenState.Params = auctiontypes.DefaultParams() auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ Denom: testDenom, Exponent: 6, diff --git a/proto/auction/v1/genesis.proto b/proto/auction/v1/genesis.proto index 4eae85c19..689d85ab3 100644 --- a/proto/auction/v1/genesis.proto +++ b/proto/auction/v1/genesis.proto @@ -29,4 +29,8 @@ message Params { (gogoproto.nullable) = false ]; uint64 minimum_auction_height = 6; + string auction_burn_rate = 7 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index 4161cafcf..3b8f06929 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -325,11 +325,25 @@ func (k Keeper) FinishAuction(ctx sdk.Context, auction *types.Auction) error { usommProceeds = usommProceeds.Add(bid.TotalUsommPaid.Amount) } - usommProceedsCoin := sdk.NewCoin(params.BaseCoinUnit, usommProceeds) - - // Send proceeds to their appropriate destination module + // Send proceeds to their appropriate destination if usommProceeds.IsPositive() { - if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, auction.ProceedsModuleAccount, sdk.Coins{usommProceedsCoin}); err != nil { + burnRate := k.GetParamSet(ctx).AuctionBurnRate + finalUsommProceeds := usommProceeds + + if burnRate.GT(sdk.ZeroDec()) { + // Burn portion of USOMM in proceeds + auctionBurn := sdk.NewDecFromInt(usommProceeds).Mul(burnRate).TruncateInt() + auctionBurnCoins := sdk.NewCoin(params.BaseCoinUnit, auctionBurn) + if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(auctionBurnCoins)); err != nil { + return err + } + + finalUsommProceeds = finalUsommProceeds.Sub(auctionBurn) + } + + // Send remaining USOMM to proceeds module + finalUsommProceedsCoin := sdk.NewCoin(params.BaseCoinUnit, finalUsommProceeds) + if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, auction.ProceedsModuleAccount, sdk.Coins{finalUsommProceedsCoin}); err != nil { return err } } diff --git a/x/auction/keeper/keeper_test.go b/x/auction/keeper/keeper_test.go index eaef36bf3..e8f561393 100644 --- a/x/auction/keeper/keeper_test.go +++ b/x/auction/keeper/keeper_test.go @@ -216,8 +216,10 @@ func (suite *KeeperTestSuite) TestHappyPathFinishAuction() { TotalUsommPaid: amountPaid2, }) - // Second transfer to return proceeds from bids - totalUsommExpected := sdk.NewCoin(params.BaseCoinUnit, amountPaid1.Amount.Add(amountPaid2.Amount)) + // Burn and send remaining proceeds from bids + totalBurnExpected := sdk.NewCoin(params.BaseCoinUnit, amountPaid1.Amount.Add(amountPaid2.Amount).Quo(sdk.NewInt(2))) + suite.mockBurnCoins(ctx, auctionTypes.ModuleName, sdk.NewCoins(totalBurnExpected)) + totalUsommExpected := sdk.NewCoin(params.BaseCoinUnit, amountPaid1.Amount.Add(amountPaid2.Amount).Sub(totalBurnExpected.Amount)) suite.mockSendCoinsFromModuleToModule(ctx, auctionTypes.ModuleName, permissionedReciever.GetName(), sdk.NewCoins(totalUsommExpected)) // Change active auction tokens remaining before finishing auction to pretend tokens were sold diff --git a/x/auction/keeper/msg_server_test.go b/x/auction/keeper/msg_server_test.go index 20e56424f..1c39b2029 100644 --- a/x/auction/keeper/msg_server_test.go +++ b/x/auction/keeper/msg_server_test.go @@ -121,7 +121,11 @@ func (suite *KeeperTestSuite) TestHappyPathSubmitBidAndFulfillFully() { // Mock out final keeper calls necessary to finish the auction due to bid draining the available supply suite.mockGetBalance(ctx, authtypes.NewModuleAddress(auctionTypes.ModuleName), saleToken, sdk.NewCoin(saleToken, sdk.NewInt(0))) + totalUsommExpected := sdk.NewCoin(params.BaseCoinUnit, sdk.NewInt(20000000000)) + totalBurnExpected := sdk.NewCoin(params.BaseCoinUnit, totalUsommExpected.Amount.Quo(sdk.NewInt(2))) + totalUsommExpected = sdk.NewCoin(params.BaseCoinUnit, totalUsommExpected.Amount.Sub(totalBurnExpected.Amount)) + suite.mockBurnCoins(ctx, auctionTypes.ModuleName, sdk.NewCoins(totalBurnExpected)) suite.mockSendCoinsFromModuleToModule(ctx, auctionTypes.ModuleName, permissionedReciever.GetName(), sdk.NewCoins(totalUsommExpected)) // Submit the partially fulfillable bid now diff --git a/x/auction/keeper/sdk_module_mocks_test.go b/x/auction/keeper/sdk_module_mocks_test.go index fd7f907d3..b2710eeb0 100644 --- a/x/auction/keeper/sdk_module_mocks_test.go +++ b/x/auction/keeper/sdk_module_mocks_test.go @@ -26,3 +26,7 @@ func (suite *KeeperTestSuite) mockSendCoinsFromAccountToModule(ctx sdk.Context, func (suite *KeeperTestSuite) mockSendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, receiverAcct sdk.AccAddress, amt sdk.Coins) { suite.bankKeeper.EXPECT().SendCoinsFromModuleToAccount(ctx, senderModule, receiverAcct, amt).Return(nil) } + +func (suite *KeeperTestSuite) mockBurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) { + suite.bankKeeper.EXPECT().BurnCoins(ctx, moduleName, amt).Return(nil) +} diff --git a/x/auction/testutil/expected_keepers_mocks.go b/x/auction/testutil/expected_keepers_mocks.go index 8bb35f896..8c0c2a987 100755 --- a/x/auction/testutil/expected_keepers_mocks.go +++ b/x/auction/testutil/expected_keepers_mocks.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: /Users/phil/Desktop/peggyJV/sommelier/x/auction/types/expected_keepers.go +// Source: /Users/atro/source/work/sommelier/x/auction/types/expected_keepers.go // Package mock_types is a generated GoMock package. package mock_types @@ -73,6 +73,20 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { return m.recorder } +// BurnCoins mocks base method. +func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt) + ret0, _ := ret[0].(error) + return ret0 +} + +// BurnCoins indicates an expected call of BurnCoins. +func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amt) +} + // GetAllBalances mocks base method. func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins { m.ctrl.T.Helper() diff --git a/x/auction/types/errors.go b/x/auction/types/errors.go index 199138883..6ef8b9313 100644 --- a/x/auction/types/errors.go +++ b/x/auction/types/errors.go @@ -52,4 +52,5 @@ var ( ErrAuctionBelowMinimumUSDValue = errorsmod.Register(ModuleName, 45, "auction USD value below minimum") ErrInvalidMinimumAuctionHeightParam = errorsmod.Register(ModuleName, 46, "invalid minimum auction height param") ErrAuctionBelowMinimumHeight = errorsmod.Register(ModuleName, 47, "auction block height below minimum") + ErrInvalidAuctionBurnRateParam = errorsmod.Register(ModuleName, 48, "invalid auction burn rate param") ) diff --git a/x/auction/types/expected_keepers.go b/x/auction/types/expected_keepers.go index b289ba1a2..3ba9cb21a 100644 --- a/x/auction/types/expected_keepers.go +++ b/x/auction/types/expected_keepers.go @@ -20,4 +20,5 @@ type BankKeeper interface { GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool) + BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error } diff --git a/x/auction/types/genesis.pb.go b/x/auction/types/genesis.pb.go index ea2469930..19859016e 100644 --- a/x/auction/types/genesis.pb.go +++ b/x/auction/types/genesis.pb.go @@ -115,6 +115,7 @@ type Params struct { AuctionMaxBlockAge uint64 `protobuf:"varint,4,opt,name=auction_max_block_age,json=auctionMaxBlockAge,proto3" json:"auction_max_block_age,omitempty"` AuctionPriceDecreaseAccelerationRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=auction_price_decrease_acceleration_rate,json=auctionPriceDecreaseAccelerationRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"auction_price_decrease_acceleration_rate"` MinimumAuctionHeight uint64 `protobuf:"varint,6,opt,name=minimum_auction_height,json=minimumAuctionHeight,proto3" json:"minimum_auction_height,omitempty"` + AuctionBurnRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,7,opt,name=auction_burn_rate,json=auctionBurnRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"auction_burn_rate"` } func (m *Params) Reset() { *m = Params{} } @@ -186,41 +187,42 @@ func init() { func init() { proto.RegisterFile("auction/v1/genesis.proto", fileDescriptor_a762e9d6ba7af420) } var fileDescriptor_a762e9d6ba7af420 = []byte{ - // 541 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x9b, 0x35, 0x54, 0xcc, 0xdd, 0x34, 0xf0, 0xc6, 0x14, 0x26, 0x91, 0x55, 0x03, 0x4d, - 0xb9, 0x2c, 0x61, 0x03, 0x09, 0x71, 0x6c, 0x34, 0x09, 0x7a, 0x40, 0x9a, 0x32, 0xc6, 0x81, 0x4b, - 0xe4, 0xc6, 0x4f, 0xa9, 0x69, 0x12, 0x47, 0xb1, 0x53, 0x75, 0x5f, 0x80, 0x33, 0x57, 0xbe, 0xd1, - 0x0e, 0x1c, 0x76, 0x44, 0x1c, 0x26, 0xd4, 0x7e, 0x11, 0x64, 0xc7, 0x19, 0xe1, 0xc8, 0x29, 0x4f, - 0xfe, 0xff, 0xde, 0xf3, 0x7b, 0xff, 0x17, 0x23, 0x87, 0xd4, 0x89, 0x64, 0xbc, 0x08, 0x16, 0xa7, - 0x41, 0x0a, 0x05, 0x08, 0x26, 0xfc, 0xb2, 0xe2, 0x92, 0x63, 0x64, 0x14, 0x7f, 0x71, 0x7a, 0xb0, - 0xdb, 0xa1, 0xe4, 0xb2, 0x01, 0x0e, 0xba, 0xa9, 0x2d, 0xdb, 0x28, 0x7b, 0x29, 0x4f, 0xb9, 0x0e, - 0x03, 0x15, 0x35, 0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 0x3f, 0xd7, - 0x6e, 0xef, 0x73, 0xd0, 0xe9, 0xae, 0x84, 0x34, 0xbd, 0xfe, 0xb2, 0x08, 0xd4, 0x5a, 0x20, 0x63, - 0x50, 0x05, 0x8b, 0x37, 0xc1, 0xb2, 0x7d, 0x4b, 0x4d, 0xab, 0xd3, 0x81, 0x7e, 0x3c, 0xaf, 0xfe, - 0x04, 0x00, 0x00, 0xff, 0xff, 0x5e, 0x6a, 0xcf, 0xe9, 0xa9, 0x03, 0x00, 0x00, + // 560 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x8d, 0x13, 0x13, 0xe8, 0xa6, 0x55, 0xe8, 0xa6, 0x54, 0xa6, 0x12, 0x6e, 0x54, 0x50, 0xe5, + 0x4b, 0x6d, 0x52, 0x90, 0x10, 0xc7, 0x58, 0x95, 0x20, 0x07, 0xa4, 0xca, 0xa5, 0x1c, 0x7a, 0xb1, + 0xd6, 0xf6, 0xc8, 0x59, 0xe2, 0x2f, 0x79, 0xd7, 0x51, 0xfa, 0x07, 0x38, 0x73, 0xe5, 0x1f, 0xf0, + 0x53, 0x7a, 0xec, 0x11, 0x71, 0xa8, 0x50, 0xf2, 0x47, 0xd0, 0xae, 0xd7, 0xc5, 0x1c, 0xe1, 0xe4, + 0xd1, 0xbe, 0x37, 0x6f, 0xdf, 0xbc, 0xf1, 0x22, 0x83, 0x54, 0x21, 0xa7, 0x79, 0xe6, 0x2c, 0x27, + 0x4e, 0x0c, 0x19, 0x30, 0xca, 0xec, 0xa2, 0xcc, 0x79, 0x8e, 0x91, 0x42, 0xec, 0xe5, 0xe4, 0x60, + 0xd4, 0x62, 0xf1, 0x55, 0x4d, 0x38, 0x68, 0xb7, 0x36, 0xdc, 0x1a, 0xd9, 0x8b, 0xf3, 0x38, 0x97, + 0xa5, 0x23, 0xaa, 0xfa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dc, + 0xd9, 0xcd, 0xda, 0xd4, 0x6e, 0xd7, 0xa6, 0xf6, 0x6b, 0x6d, 0x6a, 0x5f, 0x37, 0x66, 0xe7, 0x76, + 0x63, 0x76, 0x7e, 0x6c, 0xcc, 0xce, 0x95, 0xd3, 0x92, 0x2c, 0x20, 0x8e, 0xaf, 0x3f, 0x2f, 0x1d, + 0xb1, 0x72, 0x48, 0x28, 0x94, 0xce, 0xf2, 0x8d, 0xb3, 0x6a, 0xde, 0x69, 0xad, 0x1f, 0xf4, 0xe5, + 0xc3, 0x7c, 0xf5, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xcf, 0x5c, 0x26, 0xc1, 0x05, 0x04, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -328,6 +330,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.AuctionBurnRate.Size() + i -= size + if _, err := m.AuctionBurnRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a if m.MinimumAuctionHeight != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.MinimumAuctionHeight)) i-- @@ -439,6 +451,8 @@ func (m *Params) Size() (n int) { if m.MinimumAuctionHeight != 0 { n += 1 + sovGenesis(uint64(m.MinimumAuctionHeight)) } + l = m.AuctionBurnRate.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -844,6 +858,40 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionBurnRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + 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 ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AuctionBurnRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/auction/types/params.go b/x/auction/types/params.go index 5d06e4159..c59ab7983 100644 --- a/x/auction/types/params.go +++ b/x/auction/types/params.go @@ -14,6 +14,7 @@ var ( KeyAuctionMaxBlockAge = []byte("AuctionMaxBlockAge") KeyAuctionPriceDecreaseAccelerationRate = []byte("AuctionPriceDecreaseAccelerationRate") KeyMinimumAuctionHeight = []byte("MinimumAuctionHeight") + KeyAuctionBurnRate = []byte("AuctionBurnRate") ) var _ paramtypes.ParamSet = &Params{} @@ -32,6 +33,7 @@ func DefaultParams() Params { AuctionMaxBlockAge: 864000, // roughly 60 days based on 6 second blocks AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.001"), // 0.1% MinimumAuctionHeight: 0, // do not run auctions before this block height + AuctionBurnRate: sdk.MustNewDecFromStr("0.5"), // 50% } } @@ -44,6 +46,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeyAuctionMaxBlockAge, &p.AuctionMaxBlockAge, validateAuctionMaxBlockAge), paramtypes.NewParamSetPair(KeyAuctionPriceDecreaseAccelerationRate, &p.AuctionPriceDecreaseAccelerationRate, validateAuctionPriceDecreaseAccelerationRate), paramtypes.NewParamSetPair(KeyMinimumAuctionHeight, &p.MinimumAuctionHeight, validateMinimumAuctionHeight), + paramtypes.NewParamSetPair(KeyAuctionBurnRate, &p.AuctionBurnRate, validateAuctionBurnRate), } } @@ -69,6 +72,10 @@ func (p *Params) ValidateBasic() error { return err } + if err := validateAuctionBurnRate(p.AuctionBurnRate); err != nil { + return err + } + return nil } @@ -100,6 +107,10 @@ func validateMinimumSaleTokensUSDValue(i interface{}) error { return errorsmod.Wrapf(ErrInvalidMinimumSaleTokensUSDValue, "invalid minimum sale tokens USD value parameter type: %T", i) } + if minimumSaleTokensUsdValue.IsNil() { + return errorsmod.Wrap(ErrInvalidMinimumSaleTokensUSDValue, "minimum sale tokens USD value cannot be nil") + } + if minimumSaleTokensUsdValue.LT(sdk.MustNewDecFromStr("1.0")) { // Setting this to a minimum of 1.0 USD to ensure we can realistically charge a non-fractional usomm value return errorsmod.Wrapf(ErrInvalidMinimumSaleTokensUSDValue, "minimum sale tokens USD value must be at least 1.0") @@ -123,6 +134,10 @@ func validateAuctionPriceDecreaseAccelerationRate(i interface{}) error { return errorsmod.Wrapf(ErrInvalidAuctionPriceDecreaseAccelerationRateParam, "invalid auction price decrease acceleration rate parameter type: %T", i) } + if auctionPriceDecreaseAccelerationRate.IsNil() { + return errorsmod.Wrap(ErrInvalidAuctionPriceDecreaseAccelerationRateParam, "auction price decrease acceleration rate cannot be nil") + } + if auctionPriceDecreaseAccelerationRate.LT(sdk.MustNewDecFromStr("0")) || auctionPriceDecreaseAccelerationRate.GT(sdk.MustNewDecFromStr("1.0")) { // Acceleration rates could in theory be more than 100% if need be, but we are establishing this as a bound for now return errorsmod.Wrapf(ErrInvalidAuctionPriceDecreaseAccelerationRateParam, "auction price decrease acceleration rate must be between 0 and 1 inclusive (0%% to 100%%)") @@ -139,3 +154,20 @@ func validateMinimumAuctionHeight(i interface{}) error { return nil } + +func validateAuctionBurnRate(i interface{}) error { + auctionBurnRate, ok := i.(sdk.Dec) + if !ok { + return errorsmod.Wrapf(ErrInvalidAuctionBurnRateParam, "invalid auction burn rate parameter type: %T", i) + } + + if auctionBurnRate.IsNil() { + return errorsmod.Wrap(ErrInvalidAuctionBurnRateParam, "auction burn rate cannot be nil") + } + + if auctionBurnRate.LT(sdk.ZeroDec()) || auctionBurnRate.GT(sdk.OneDec()) { + return errorsmod.Wrapf(ErrInvalidAuctionBurnRateParam, "auction burn rate must be between 0 and 1 inclusive (0%% to 100%%)") + } + + return nil +} diff --git a/x/auction/types/params_test.go b/x/auction/types/params_test.go index cc28c74f0..2dc9cb409 100644 --- a/x/auction/types/params_test.go +++ b/x/auction/types/params_test.go @@ -29,6 +29,7 @@ func TestParamsValidate(t *testing.T) { MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), }, expPass: true, err: nil, @@ -41,6 +42,7 @@ func TestParamsValidate(t *testing.T) { MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), }, expPass: false, err: errorsmod.Wrapf(ErrTokenPriceMaxBlockAgeMustBePositive, "value: 0"), @@ -53,6 +55,7 @@ func TestParamsValidate(t *testing.T) { MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("-0.01"), + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), }, expPass: false, err: errorsmod.Wrapf(ErrInvalidAuctionPriceDecreaseAccelerationRateParam, "auction price decrease acceleration rate must be between 0 and 1 inclusive (0%% to 100%%)"), @@ -65,14 +68,68 @@ func TestParamsValidate(t *testing.T) { MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), AuctionMaxBlockAge: uint64(100), AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("1.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), }, expPass: false, err: errorsmod.Wrapf(ErrInvalidAuctionPriceDecreaseAccelerationRateParam, "auction price decrease acceleration rate must be between 0 and 1 inclusive (0%% to 100%%)"), }, + { + name: "Auction burn rate lower bound (0)", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.ZeroDec(), + }, + expPass: true, + err: nil, + }, + { + name: "Auction burn rate upper bound (1)", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.OneDec(), + }, + expPass: true, + err: nil, + }, + { + name: "Auction burn rate slightly below lower bound", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("-0.000000000000000001"), + }, + expPass: false, + err: errorsmod.Wrapf(ErrInvalidAuctionBurnRateParam, "auction burn rate must be between 0 and 1 inclusive (0%% to 100%%)"), + }, + { + name: "Auction burn rate slightly above upper bound", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("1.000000000000000001"), + }, + expPass: false, + err: errorsmod.Wrapf(ErrInvalidAuctionBurnRateParam, "auction burn rate must be between 0 and 1 inclusive (0%% to 100%%)"), + }, } for _, tc := range testCases { err := tc.params.ValidateBasic() + tc := tc if tc.expPass { require.NoError(t, err, tc.name) require.Nil(t, err) @@ -82,3 +139,93 @@ func TestParamsValidate(t *testing.T) { } } } + +func TestParamsValidateBasicUnhappyPath(t *testing.T) { + testCases := []struct { + name string + params Params + expErr error + }{ + { + name: "Invalid minimum sale tokens USD value", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("0.5"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), + }, + expErr: ErrInvalidMinimumSaleTokensUSDValue, + }, + { + name: "Invalid auction burn rate (negative)", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("-0.1"), + }, + expErr: ErrInvalidAuctionBurnRateParam, + }, + { + name: "Invalid auction burn rate (greater than 1)", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("1.1"), + }, + expErr: ErrInvalidAuctionBurnRateParam, + }, + { + name: "Nil MinimumSaleTokensUsdValue", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.Dec{}, + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), + }, + expErr: ErrInvalidMinimumSaleTokensUSDValue, + }, + { + name: "Nil AuctionPriceDecreaseAccelerationRate", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.Dec{}, + AuctionBurnRate: sdk.MustNewDecFromStr("0.1"), + }, + expErr: ErrInvalidAuctionPriceDecreaseAccelerationRateParam, + }, + { + name: "Nil AuctionBurnRate", + params: Params{ + PriceMaxBlockAge: uint64(1000), + MinimumBidInUsomm: uint64(500), + MinimumSaleTokensUsdValue: sdk.MustNewDecFromStr("1.0"), + AuctionMaxBlockAge: uint64(100), + AuctionPriceDecreaseAccelerationRate: sdk.MustNewDecFromStr("0.1"), + AuctionBurnRate: sdk.Dec{}, + }, + expErr: ErrInvalidAuctionBurnRateParam, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := tc.params.ValidateBasic() + require.Error(t, err) + require.ErrorIs(t, err, tc.expErr) + }) + } +}