Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't load all poolmanager params every swap #7074

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions x/poolmanager/taker_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ 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.
func (k Keeper) SetDenomPairTakerFee(ctx sdk.Context, denom0, denom1 string, takerFee osmomath.Dec) {
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)) {
Comment on lines +29 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand the comment. It is valid to override over the default. Instead of storing every taker fee for every pair, we assume every pair is default, and if we pull the value for that pair and its non default, its an override.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code comment is on SetDenomPairTakerFee, for when its being set.

Its saying if you override a taker fee to a value that is default, delete the state entry for this, and make it go to default.

However then if the default changes, this one changes as well, whereas you really wanted it to always stay at the old default value.

(This is independent of the main point of this PR)

store.Delete(types.FormatDenomTradePairKey(denom0, denom1))
return
} else {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion x/protorev/keeper/rebalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
Expand Down