Skip to content

Commit

Permalink
Minimal code change to send dev profit after every trade
Browse files Browse the repository at this point in the history
- Not optimal because it still stores state, but want to show minimal working version
- All tests pass after setting dev account for the tests, no new tests added
  • Loading branch information
NotJeremyLiu committed Apr 3, 2023
1 parent df18e54 commit 5bacd9e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 0 additions & 4 deletions x/protorev/keeper/epoch_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ func (h EpochHooks) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, ep
func (h EpochHooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
if h.k.GetProtoRevEnabled(ctx) {
switch epochIdentifier {
case "week":
// Distribute developer fees to the developer account. We do not error check because the developer account
// may not have been set by this point (gets set by the admin account after module genesis)
_ = h.k.SendDeveloperFeesToDeveloperAccount(ctx)
case "day":
// Increment number of days since module genesis to properly calculate developer fees after cyclic arbitrage trades
if daysSinceGenesis, err := h.k.GetDaysSinceModuleGenesis(ctx); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions x/protorev/keeper/posthandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

"github.com/osmosis-labs/osmosis/v15/app/apptesting"
gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
"github.com/osmosis-labs/osmosis/v15/x/protorev/keeper"
Expand Down Expand Up @@ -89,6 +90,10 @@ func (suite *KeeperTestSuite) TestAnteHandle() {
acc1 := suite.App.AccountKeeper.NewAccountWithAddress(suite.Ctx, addr0)
suite.App.AccountKeeper.SetAccount(suite.Ctx, acc1)

// Set protorev developer account
devAccount := apptesting.CreateRandomAccounts(1)[0]
suite.App.ProtoRevKeeper.SetDeveloperAccount(suite.Ctx, devAccount)

// Keep testing order consistent to make adding tests easier
// Add all tests that are not expected to execute a trade first
// Then track number of trades and profits for the rest of the tests
Expand Down
5 changes: 5 additions & 0 deletions x/protorev/keeper/rebalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ func (k Keeper) ExecuteTrade(ctx sdk.Context, route poolmanagertypes.SwapAmountI
return err
}

// Send the developer fees to the developer
if err = k.SendDeveloperFeesToDeveloperAccount(ctx); err != nil {
return err
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions x/protorev/keeper/rebalance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v15/app/apptesting"
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
protorevtypes "github.com/osmosis-labs/osmosis/v15/x/protorev/keeper"
"github.com/osmosis-labs/osmosis/v15/x/protorev/types"
Expand Down Expand Up @@ -324,6 +325,10 @@ func (suite *KeeperTestSuite) TestExecuteTrade() {
expectedProfit sdk.Int
}

// Set protorev developer account
devAccount := apptesting.CreateRandomAccounts(1)[0]
suite.App.ProtoRevKeeper.SetDeveloperAccount(suite.Ctx, devAccount)

tests := []struct {
name string
param param
Expand Down

0 comments on commit 5bacd9e

Please sign in to comment.