-
Notifications
You must be signed in to change notification settings - Fork 79
/
grpc_query_estimate_multi_hop_swap.go
50 lines (41 loc) · 1.18 KB
/
grpc_query_estimate_multi_hop_swap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/neutron-org/neutron/v4/x/dex/types"
)
// TODO: This doesn't run ValidateBasic() checks.
func (k Keeper) EstimateMultiHopSwap(
goCtx context.Context,
req *types.QueryEstimateMultiHopSwapRequest,
) (*types.QueryEstimateMultiHopSwapResponse, error) {
msg := types.MsgMultiHopSwap{
Creator: req.Creator,
Receiver: req.Receiver,
Routes: req.Routes,
AmountIn: req.AmountIn,
ExitLimitPrice: req.ExitLimitPrice,
PickBestRoute: req.PickBestRoute,
}
if err := msg.Validate(); err != nil {
return nil, err
}
ctx := sdk.UnwrapSDKContext(goCtx)
cacheCtx, _ := ctx.CacheContext()
callerAddr := sdk.MustAccAddressFromBech32(req.Creator)
receiverAddr := sdk.MustAccAddressFromBech32(req.Receiver)
coinOut, err := k.MultiHopSwapCore(
cacheCtx,
req.AmountIn,
req.Routes,
req.ExitLimitPrice,
req.PickBestRoute,
callerAddr,
receiverAddr,
)
if err != nil {
return nil, err
}
// NB: Critically, we do not write the best route's buffered state context since this is only an estimate.
return &types.QueryEstimateMultiHopSwapResponse{CoinOut: coinOut}, nil
}