diff --git a/x/protorev/keeper/developer_fees.go b/x/protorev/keeper/developer_fees.go index cef9ea51390..cccec716801 100644 --- a/x/protorev/keeper/developer_fees.go +++ b/x/protorev/keeper/developer_fees.go @@ -7,56 +7,33 @@ import ( ) // SendDeveloperFeesToDeveloperAccount sends the developer fees from the module account to the developer account -func (k Keeper) SendDeveloperFeesToDeveloperAccount(ctx sdk.Context) error { +func (k Keeper) SendDeveloperFeesToDeveloperAccount(ctx sdk.Context, profitDenom string, profitAmount sdk.Int) error { // Developer account must be set in order to be able to withdraw developer fees developerAccount, err := k.GetDeveloperAccount(ctx) if err != nil { return err } - coins, err := k.GetAllDeveloperFees(ctx) - if err != nil { - return err - } - - for _, coin := range coins { - // Send the coins to the developer account - if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, developerAccount, sdk.NewCoins(coin)); err != nil { - return err - } - - // Reset the developer fees for the coin - k.DeleteDeveloperFees(ctx, coin.Denom) - } - - return nil -} - -// UpdateDeveloperFees updates the fees that developers can withdraw from the module account -func (k Keeper) UpdateDeveloperFees(ctx sdk.Context, denom string, profit sdk.Int) error { + // Get the days since genesis daysSinceGenesis, err := k.GetDaysSinceModuleGenesis(ctx) if err != nil { return err } + // Initialize the developer profit to 0 + devProfit := sdk.NewCoin(profitDenom, sdk.ZeroInt()) + // Calculate the developer fee if daysSinceGenesis < types.Phase1Length { - profit = profit.MulRaw(types.ProfitSplitPhase1).QuoRaw(100) + devProfit.Amount = profitAmount.MulRaw(types.ProfitSplitPhase1).QuoRaw(100) } else if daysSinceGenesis < types.Phase2Length { - profit = profit.MulRaw(types.ProfitSplitPhase2).QuoRaw(100) + devProfit.Amount = profitAmount.MulRaw(types.ProfitSplitPhase2).QuoRaw(100) } else { - profit = profit.MulRaw(types.ProfitSplitPhase3).QuoRaw(100) - } - - // Get the developer fees for the denom, if not there then set it to 0 and initialize it - currentDeveloperFee, err := k.GetDeveloperFees(ctx, denom) - if err != nil { - currentDeveloperFee = sdk.NewCoin(denom, sdk.ZeroInt()) + devProfit.Amount = profitAmount.MulRaw(types.ProfitSplitPhase3).QuoRaw(100) } - currentDeveloperFee.Amount = currentDeveloperFee.Amount.Add(profit) - // Set the developer fees for the denom - if err = k.SetDeveloperFees(ctx, currentDeveloperFee); err != nil { + // Send the developer profit to the developer account + if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, developerAccount, sdk.NewCoins(devProfit)); err != nil { return err } diff --git a/x/protorev/keeper/genesis.go b/x/protorev/keeper/genesis.go index 83ca0df2733..3de9ef57956 100644 --- a/x/protorev/keeper/genesis.go +++ b/x/protorev/keeper/genesis.go @@ -48,13 +48,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { k.SetDeveloperAccount(ctx, account) } - // Set the developer fees that have been collected. - for _, fee := range genState.DeveloperFees { - if err := k.SetDeveloperFees(ctx, fee); err != nil { - panic(err) - } - } - // Set the number of days since the module genesis. k.SetDaysSinceModuleGenesis(ctx, genState.DaysSinceModuleGenesis) diff --git a/x/protorev/keeper/protorev.go b/x/protorev/keeper/protorev.go index 443884d157a..3fb574b38bd 100644 --- a/x/protorev/keeper/protorev.go +++ b/x/protorev/keeper/protorev.go @@ -218,28 +218,6 @@ func (k Keeper) GetAllDeveloperFees(ctx sdk.Context) ([]sdk.Coin, error) { return fees, nil } -// SetDeveloperFees sets the fees the developers can withdraw from the module account -func (k Keeper) SetDeveloperFees(ctx sdk.Context, developerFees sdk.Coin) error { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixDeveloperFees) - key := types.GetKeyPrefixDeveloperFees(developerFees.Denom) - - bz, err := developerFees.Marshal() - if err != nil { - return err - } - - store.Set(key, bz) - - return nil -} - -// DeleteDeveloperFees deletes the developer fees given a denom -func (k Keeper) DeleteDeveloperFees(ctx sdk.Context, denom string) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixDeveloperFees) - key := types.GetKeyPrefixDeveloperFees(denom) - store.Delete(key) -} - // GetProtoRevEnabled returns whether protorev is enabled func (k Keeper) GetProtoRevEnabled(ctx sdk.Context) bool { params := k.GetParams(ctx) diff --git a/x/protorev/keeper/protorev_test.go b/x/protorev/keeper/protorev_test.go index 37826692cc4..c373238f69a 100644 --- a/x/protorev/keeper/protorev_test.go +++ b/x/protorev/keeper/protorev_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/v15/x/protorev/types" ) @@ -127,67 +125,6 @@ func (suite *KeeperTestSuite) TestGetDaysSinceModuleGenesis() { suite.Require().Equal(uint64(1), daysSinceGenesis) } -// TestGetDeveloperFees tests the GetDeveloperFees, SetDeveloperFees, and GetAllDeveloperFees functions. -func (suite *KeeperTestSuite) TestGetDeveloperFees() { - // Should be initialized to [] on genesis - fees, err := suite.App.ProtoRevKeeper.GetAllDeveloperFees(suite.Ctx) - suite.Require().NoError(err) - suite.Require().Equal(0, len(fees)) - - // Should be no osmo fees on genesis - osmoFees, err := suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, types.OsmosisDenomination) - suite.Require().Error(err) - suite.Require().Equal(sdk.Coin{}, osmoFees) - - // Should be no atom fees on genesis - atomFees, err := suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, "Atom") - suite.Require().Error(err) - suite.Require().Equal(sdk.Coin{}, atomFees) - - // Should be able to set the fees - err = suite.App.ProtoRevKeeper.SetDeveloperFees(suite.Ctx, sdk.NewCoin(types.OsmosisDenomination, sdk.NewInt(100))) - suite.Require().NoError(err) - err = suite.App.ProtoRevKeeper.SetDeveloperFees(suite.Ctx, sdk.NewCoin("Atom", sdk.NewInt(100))) - suite.Require().NoError(err) - err = suite.App.ProtoRevKeeper.SetDeveloperFees(suite.Ctx, sdk.NewCoin("weth", sdk.NewInt(100))) - - // Should be able to get the fees - osmoFees, err = suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, types.OsmosisDenomination) - suite.Require().NoError(err) - suite.Require().Equal(sdk.NewCoin(types.OsmosisDenomination, sdk.NewInt(100)), osmoFees) - atomFees, err = suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, "Atom") - suite.Require().NoError(err) - suite.Require().Equal(sdk.NewCoin("Atom", sdk.NewInt(100)), atomFees) - wethFees, err := suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, "weth") - suite.Require().NoError(err) - suite.Require().Equal(sdk.NewCoin("weth", sdk.NewInt(100)), wethFees) - - fees, err = suite.App.ProtoRevKeeper.GetAllDeveloperFees(suite.Ctx) - suite.Require().NoError(err) - suite.Require().Equal(3, len(fees)) - suite.Require().Contains(fees, osmoFees) - suite.Require().Contains(fees, atomFees) -} - -// TestDeleteDeveloperFees tests the DeleteDeveloperFees function. -func (suite *KeeperTestSuite) TestDeleteDeveloperFees() { - err := suite.App.ProtoRevKeeper.SetDeveloperFees(suite.Ctx, sdk.NewCoin(types.OsmosisDenomination, sdk.NewInt(100))) - suite.Require().NoError(err) - - // Should be able to get the fees - osmoFees, err := suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, types.OsmosisDenomination) - suite.Require().NoError(err) - suite.Require().Equal(sdk.NewCoin(types.OsmosisDenomination, sdk.NewInt(100)), osmoFees) - - // Should be able to delete the fees - suite.App.ProtoRevKeeper.DeleteDeveloperFees(suite.Ctx, types.OsmosisDenomination) - - // Should be no osmo fees after deletion - osmoFees, err = suite.App.ProtoRevKeeper.GetDeveloperFees(suite.Ctx, types.OsmosisDenomination) - suite.Require().Error(err) - suite.Require().Equal(sdk.Coin{}, osmoFees) -} - // TestGetProtoRevEnabled tests the GetProtoRevEnabled and SetProtoRevEnabled functions. func (suite *KeeperTestSuite) TestGetProtoRevEnabled() { // Should be initialized to true on genesis diff --git a/x/protorev/keeper/rebalance.go b/x/protorev/keeper/rebalance.go index fa3bc2b7b71..422ba23ae8a 100644 --- a/x/protorev/keeper/rebalance.go +++ b/x/protorev/keeper/rebalance.go @@ -215,13 +215,8 @@ func (k Keeper) ExecuteTrade(ctx sdk.Context, route poolmanagertypes.SwapAmountI return err } - // Update the developer fees - if err = k.UpdateDeveloperFees(ctx, inputCoin.Denom, profit); err != nil { - return err - } - // Send the developer fees to the developer - if err = k.SendDeveloperFeesToDeveloperAccount(ctx); err != nil { + if err = k.SendDeveloperFeesToDeveloperAccount(ctx, inputCoin.Denom, profit); err != nil { return err }