From 02ef0aeaa757f088d65fc20d9c58e69a4c2d623d Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 16 Feb 2024 08:34:06 -0600 Subject: [PATCH] Minor protorev mutation speedup --- x/protorev/keeper/rebalance.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x/protorev/keeper/rebalance.go b/x/protorev/keeper/rebalance.go index 70cb33bab7f..879e0d9d246 100644 --- a/x/protorev/keeper/rebalance.go +++ b/x/protorev/keeper/rebalance.go @@ -97,7 +97,7 @@ func (k Keeper) ConvertProfits(ctx sdk.Context, inputCoin sdk.Coin, profit osmom // by estimating the amount out given the amount in for the first pool in the route // and then subtracting the amount in from the amount out to get the profit func (k Keeper) EstimateMultihopProfit(ctx sdk.Context, inputDenom string, amount osmomath.Int, route poolmanagertypes.SwapAmountInRoutes) (sdk.Coin, osmomath.Int, error) { - tokenIn := sdk.NewCoin(inputDenom, amount) + tokenIn := sdk.Coin{Denom: inputDenom, Amount: amount} amtOut, err := k.poolmanagerKeeper.MultihopEstimateOutGivenExactAmountIn(ctx, route, tokenIn) if err != nil { return sdk.Coin{}, osmomath.ZeroInt(), err @@ -106,6 +106,8 @@ func (k Keeper) EstimateMultihopProfit(ctx sdk.Context, inputDenom string, amoun return tokenIn, profit, nil } +var oneInt, twoInt = osmomath.OneInt(), osmomath.NewInt(2) + // FindMaxProfitRoute runs a binary search to find the max profit for a given route func (k Keeper) FindMaxProfitForRoute(ctx sdk.Context, route RouteMetaData, remainingTxPoolPoints, remainingBlockPoolPoints *uint64) (sdk.Coin, osmomath.Int, error) { // Track the tokenIn amount/denom and the profit @@ -146,8 +148,8 @@ func (k Keeper) FindMaxProfitForRoute(ctx sdk.Context, route RouteMetaData, rema // Binary search to find the max profit for iteration := 0; curLeft.LT(curRight) && iteration < types.MaxIterations; iteration++ { - curMid := (curLeft.Add(curRight)).Quo(osmomath.NewInt(2)) - curMidPlusOne := curMid.Add(osmomath.OneInt()) + curMid := (curLeft.Add(curRight)).Quo(twoInt) + curMidPlusOne := curMid.Add(oneInt) // Short circuit profit searching if there is an error in the GAMM module tokenInMid, profitMid, err := k.EstimateMultihopProfit(ctx, inputDenom, curMid.Mul(route.StepSize), route.Route)