From 983117e3404e8e9414b6f4e98bd91322cf78e7f9 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Mon, 11 Dec 2023 19:25:19 +0100 Subject: [PATCH] Don't load all params --- x/poolmanager/taker_fee.go | 11 +++++++++-- x/protorev/keeper/rebalance.go | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/x/poolmanager/taker_fee.go b/x/poolmanager/taker_fee.go index e014bb698e1..b1f6857d05e 100644 --- a/x/poolmanager/taker_fee.go +++ b/x/poolmanager/taker_fee.go @@ -13,6 +13,12 @@ import ( txfeestypes "github.com/osmosis-labs/osmosis/v21/x/txfees/types" ) +func (k Keeper) GetDefaultTakerFee(ctx sdk.Context) sdk.Dec { + var defaultTakerFee sdk.Dec + k.paramSpace.Get(ctx, types.KeyDefaultTakerFee, &defaultTakerFee) + return defaultTakerFee +} + // SetDenomPairTakerFee sets the taker fee for the given trading pair. // If the taker fee for this denom pair matches the default taker fee, then // it is deleted from state. @@ -20,7 +26,8 @@ func (k Keeper) SetDenomPairTakerFee(ctx sdk.Context, denom0, denom1 string, tak store := ctx.KVStore(k.storeKey) // if given taker fee is equal to the default taker fee, // delete whatever we have in current state to use default taker fee. - if takerFee.Equal(k.GetParams(ctx).TakerFeeParams.DefaultTakerFee) { + // TODO: This logic is actually wrong imo, where it can be valid to set an override over the default. + if takerFee.Equal(k.GetDefaultTakerFee(ctx)) { store.Delete(types.FormatDenomTradePairKey(denom0, denom1)) return } else { @@ -71,7 +78,7 @@ func (k Keeper) GetTradingPairTakerFee(ctx sdk.Context, denom0, denom1 string) ( return osmomath.Dec{}, err } if !found { - return k.GetParams(ctx).TakerFeeParams.DefaultTakerFee, nil + return k.GetDefaultTakerFee(ctx), nil } return takerFee.Dec, nil diff --git a/x/protorev/keeper/rebalance.go b/x/protorev/keeper/rebalance.go index 27c47cc8dc2..b0e7c722228 100644 --- a/x/protorev/keeper/rebalance.go +++ b/x/protorev/keeper/rebalance.go @@ -8,6 +8,8 @@ import ( "github.com/osmosis-labs/osmosis/v21/x/protorev/types" ) +var zeroInt = osmomath.ZeroInt() + // IterateRoutes checks the profitability of every single route that is passed in // and returns the optimal route if there is one func (k Keeper) IterateRoutes(ctx sdk.Context, routes []RouteMetaData, remainingTxPoolPoints, remainingBlockPoolPoints *uint64) (sdk.Coin, osmomath.Int, poolmanagertypes.SwapAmountInRoutes) { @@ -30,7 +32,7 @@ func (k Keeper) IterateRoutes(ctx sdk.Context, routes []RouteMetaData, remaining } // If the profit is greater than zero, then we convert the profits to uosmo and compare profits in terms of uosmo - if profit.GT(osmomath.ZeroInt()) { + if profit.GT(zeroInt) { profit, err := k.ConvertProfits(ctx, inputCoin, profit) if err != nil { k.Logger(ctx).Error("Error converting profits: " + err.Error())