Skip to content

Commit

Permalink
use execute fns for simulation queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Jul 23, 2024
1 parent 4d540e1 commit 8a9aed7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 62 deletions.
11 changes: 2 additions & 9 deletions x/dex/keeper/grpc_query_estimate_multi_hop_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,16 @@ func (k Keeper) EstimateMultiHopSwap(
ctx := sdk.UnwrapSDKContext(goCtx)
cacheCtx, _ := ctx.CacheContext()

oldBk := k.bankKeeper
k.bankKeeper = NewSimulationBankKeeper(k.bankKeeper)
coinOut, err := k.MultiHopSwapCore(
bestRoute, _, err := k.CalulateMultiHopSwap(
cacheCtx,
req.AmountIn,
req.Routes,
req.ExitLimitPrice,
req.PickBestRoute,
[]byte("caller"),
[]byte("receiver"),
)
if err != nil {
return nil, err
}

//nolint:staticcheck // Should be unnecessary but out of an abundance of caution we restore the old bankkeeper
k.bankKeeper = oldBk

return &types.QueryEstimateMultiHopSwapResponse{CoinOut: coinOut}, nil
return &types.QueryEstimateMultiHopSwapResponse{CoinOut: bestRoute.coinOut}, nil
}
16 changes: 6 additions & 10 deletions x/dex/keeper/grpc_query_estimate_place_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,30 @@ func (k Keeper) EstimatePlaceLimitOrder(
}

ctx := sdk.UnwrapSDKContext(goCtx)
cacheCtx, _ := ctx.CacheContext()

err := msg.ValidateGoodTilExpiration(ctx.BlockTime())
if err != nil {
return nil, err
}

oldBk := k.bankKeeper
k.bankKeeper = NewSimulationBankKeeper(k.bankKeeper)
_, totalInCoin, swapInCoin, swapOutCoin, err := k.PlaceLimitOrderCore(
takerTradePairID, err := types.NewTradePairID(req.TokenIn, req.TokenOut)

Check failure on line 38 in x/dex/keeper/grpc_query_estimate_place_limit_order.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

cacheCtx, _ := ctx.CacheContext()
_, totalIn, swapInCoin, swapOutCoin, _, err := k.ExecutePlaceLimitOrder(
cacheCtx,
req.TokenIn,
req.TokenOut,
takerTradePairID,
req.AmountIn,
req.TickIndexInToOut,
req.OrderType,
req.ExpirationTime,
req.MaxAmountOut,
[]byte("caller"),
[]byte("receiver"),
)
if err != nil {
return nil, err
}

//nolint:staticcheck // Should be unnecessary but out of an abundance of caution we restore the old bankkeeper
k.bankKeeper = oldBk

totalInCoin := sdk.NewCoin(req.TokenIn, totalIn)
return &types.QueryEstimatePlaceLimitOrderResponse{
TotalInCoin: totalInCoin,
SwapInCoin: swapInCoin,
Expand Down
43 changes: 0 additions & 43 deletions x/dex/keeper/simulation_bank_keeper.go

This file was deleted.

0 comments on commit 8a9aed7

Please sign in to comment.