Skip to content

Commit

Permalink
remove BaseDenom from genState
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Feb 16, 2024
1 parent 1297bec commit 0b723b4
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 100 deletions.
19 changes: 10 additions & 9 deletions proto/osmosis/protorev/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ message GenesisState {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"token_pair_arb_routes\""
];
// The base denominations being used to create cyclic arbitrage routes via the
// highest liquidity method.
// DEPRECATED: The base denominations being used to create cyclic arbitrage
// routes via the highest liquidity method. This field is deprecated and will
// be removed in a future version.
repeated BaseDenom base_denoms = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"base_denoms\""
(gogoproto.moretags) = "yaml:\"base_denoms\"",
deprecated = true
];
// The pool weights that are being used to calculate the weight (compute cost)
// of each route.
//
// DEPRECATED: This field is deprecated and will be removed in the next
// release. It is replaced by the `info_by_pool_type` field.
// DEPRECATED: The pool weights that are being used to calculate the weight
// (compute cost) of each route. This field is deprecated and will be removed
// in the next release. It is replaced by the `info_by_pool_type` field.
PoolWeights pool_weights = 4 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"pool_weights\""
(gogoproto.moretags) = "yaml:\"pool_weights\"",
deprecated = true
];
// The number of days since module genesis.
uint64 days_since_module_genesis = 5
Expand Down
9 changes: 0 additions & 9 deletions x/protorev/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
}
}

// Configure the initial base denoms used for cyclic route building. The order of the list of base
// denoms is the order in which routes will be prioritized i.e. routes will be built and simulated in a
// first come first serve basis that is based on the order of the base denoms.
k.SetBaseDenoms(ctx, genState.BaseDenoms)

// Update the pools on genesis.
if err := k.UpdatePools(ctx); err != nil {
panic(err)
Expand Down Expand Up @@ -119,10 +114,6 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
}
genesis.TokenPairArbRoutes = routes

// Export the base denoms used for cyclic route building.
baseDenoms := k.GetAllBaseDenoms(ctx)
genesis.BaseDenoms = baseDenoms

// Export the developer fees that have been collected.
fees, err := k.GetAllDeveloperFees(ctx)
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions x/protorev/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ func (s *KeeperTestSuite) TestInitGenesis() {
s.Require().Contains(tokenPairArbRoutes, route)
}

baseDenoms := s.App.ProtoRevKeeper.GetAllBaseDenoms(s.Ctx)
s.Require().Equal(len(baseDenoms), len(exportedGenesis.BaseDenoms))
for _, baseDenom := range exportedGenesis.BaseDenoms {
s.Require().Contains(baseDenoms, baseDenom)
}

params := s.App.ProtoRevKeeper.GetParams(s.Ctx)
s.Require().Equal(params, exportedGenesis.Params)

Expand Down
3 changes: 0 additions & 3 deletions x/protorev/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ func (m MsgServer) SetBaseDenoms(c context.Context, msg *types.MsgSetBaseDenoms)
m.k.DeleteAllPoolsForBaseDenom(ctx, baseDenom.Denom)
}

// // Delete the old base denoms
// m.k.DeleteBaseDenoms(ctx)

m.k.SetBaseDenoms(ctx, msg.BaseDenoms)

// Update all of the pools
Expand Down
7 changes: 4 additions & 3 deletions x/protorev/keeper/protorev.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ func (k Keeper) DeprecatedSetBaseDenoms(ctx sdk.Context, baseDenoms []types.Base
return nil
}

// GetAllBaseDenoms returns all of the base denoms (sorted by priority in descending order) used to build cyclic arbitrage routes
func (k Keeper) GetAllBaseDenoms(ctx sdk.Context) []types.BaseDenom {
return k.GetParams(ctx).BaseDenoms
}

// SetBaseDenoms sets all of the base denoms used to build cyclic arbitrage routes. The base denoms priority
// order is going to match the order of the base denoms in the slice.
func (k Keeper) SetBaseDenoms(ctx sdk.Context, newBaseDenoms []types.BaseDenom) {
params := k.GetParams(ctx)
params.BaseDenoms = newBaseDenoms
k.SetParams(ctx, params)
k.SetParam(ctx, types.ParamStoreKeyBaseDenoms, newBaseDenoms)
}

// DeprecatedDeleteBaseDenoms deletes all of the base denoms.
Expand Down
11 changes: 6 additions & 5 deletions x/protorev/keeper/protorev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ func (s *KeeperTestSuite) TestGetAllBaseDenoms() {
s.Require().Equal(baseDenoms[2].Denom, "ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7")

// Should be able to set the base denoms
s.App.ProtoRevKeeper.SetBaseDenoms(s.Ctx, []types.BaseDenom{{Denom: types.OsmosisDenomination}, {Denom: "atom"}, {Denom: "weth"}})
newBaseDenoms := []types.BaseDenom{
{Denom: types.OsmosisDenomination, StepSize: osmomath.NewInt(1_000_000)},
{Denom: "atom", StepSize: osmomath.NewInt(1_000_000)},
{Denom: "weth", StepSize: osmomath.NewInt(1_000_000)}}
s.App.ProtoRevKeeper.SetBaseDenoms(s.Ctx, newBaseDenoms)
baseDenoms = s.App.ProtoRevKeeper.GetAllBaseDenoms(s.Ctx)
s.Require().Equal(3, len(baseDenoms))
s.Require().Equal(baseDenoms[0].Denom, types.OsmosisDenomination)
s.Require().Equal(baseDenoms[1].Denom, "atom")
s.Require().Equal(baseDenoms[2].Denom, "weth")
s.Require().Equal(newBaseDenoms, baseDenoms)
}

// TestGetPoolForDenomPair tests the GetPoolForDenomPair, SetPoolForDenomPair, and DeleteAllPoolsForBaseDenom functions.
Expand Down
6 changes: 0 additions & 6 deletions x/protorev/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
TokenPairArbRoutes: DefaultTokenPairArbRoutes,
BaseDenoms: DefaultBaseDenoms,
InfoByPoolType: DefaultPoolTypeInfo,
DaysSinceModuleGenesis: DefaultDaysSinceModuleGenesis,
DeveloperFees: DefaultDeveloperFees,
Expand All @@ -71,11 +70,6 @@ func (gs GenesisState) Validate() error {
return err
}

// Validate the base denoms
if err := ValidateBaseDenoms(gs.BaseDenoms); err != nil {
return err
}

// Validate the pool type information
if err := gs.InfoByPoolType.Validate(); err != nil {
return err
Expand Down
119 changes: 60 additions & 59 deletions x/protorev/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions x/protorev/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ func (p Params) Validate() error {
return fmt.Errorf("invalid admin account address: %s", p.Admin)
}

if err := ValidateBoolean(p.Enabled); err != nil {
return err
}

if err := ValidateAccount(p.Admin); err != nil {
return err
}

if err := ValidateBaseDenoms(p.BaseDenoms); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 0b723b4

Please sign in to comment.