-
Notifications
You must be signed in to change notification settings - Fork 48
/
query_slippage_track.go
47 lines (39 loc) · 1.3 KB
/
query_slippage_track.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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/amm/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) SlippageTrack(goCtx context.Context, req *types.QuerySlippageTrackRequest) (*types.QuerySlippageTrackResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
return &types.QuerySlippageTrackResponse{
Track: types.OraclePoolSlippageTrack{
PoolId: req.PoolId,
Timestamp: uint64(ctx.BlockTime().Unix()),
Tracked: k.GetTrackedSlippageDiff(ctx, req.PoolId),
},
}, nil
}
func (k Keeper) SlippageTrackAll(goCtx context.Context, req *types.QuerySlippageTrackAllRequest) (*types.QuerySlippageTrackAllResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
pools := k.GetAllPool(ctx)
tracks := []types.OraclePoolSlippageTrack{}
for _, pool := range pools {
tracks = append(tracks, types.OraclePoolSlippageTrack{
PoolId: pool.PoolId,
Timestamp: uint64(ctx.BlockTime().Unix()),
Tracked: k.GetTrackedSlippageDiff(ctx, pool.PoolId),
})
}
return &types.QuerySlippageTrackAllResponse{
Tracks: tracks,
}, nil
}