-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquidation.go
54 lines (46 loc) · 1.86 KB
/
liquidation.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
51
52
53
54
package server
import (
"context"
"github.com/cosmos/cosmos-sdk/telemetry"
"github.com/furyanprotocol/v4-chain/protocol/daemons/liquidation/api"
"github.com/furyanprotocol/v4-chain/protocol/daemons/server/types"
liquidationtypes "github.com/furyanprotocol/v4-chain/protocol/daemons/server/types/liquidations"
"github.com/furyanprotocol/v4-chain/protocol/lib/metrics"
)
// LiquidationServer defines the fields required for liquidation updates.
type LiquidationServer struct {
daemonLiquidationInfo *liquidationtypes.DaemonLiquidationInfo
}
// WithDaemonLiquidationInfo sets the `daemonLiquidationInfo` field.
// This is updated by the liquidation service with a list of potentially liquidatable
// subaccount ids to be processed by the `PerpetualLiquidationsKeeper`.
func (server *Server) WithDaemonLiquidationInfo(
daemonLiquidationInfo *liquidationtypes.DaemonLiquidationInfo,
) *Server {
server.daemonLiquidationInfo = daemonLiquidationInfo
return server
}
// LiquidateSubaccounts stores the list of potentially liquidatable subaccount ids
// in a go-routine safe slice.
func (s *Server) LiquidateSubaccounts(
ctx context.Context,
req *api.LiquidateSubaccountsRequest,
) (
response *api.LiquidateSubaccountsResponse,
err error,
) {
telemetry.ModuleSetGauge(
metrics.LiquidationDaemon,
float32(len(req.LiquidatableSubaccountIds)),
metrics.LiquidatableSubaccountIds,
metrics.Received,
metrics.Count,
)
s.daemonLiquidationInfo.UpdateBlockHeight(req.BlockHeight)
s.daemonLiquidationInfo.UpdateLiquidatableSubaccountIds(req.LiquidatableSubaccountIds)
s.daemonLiquidationInfo.UpdateNegativeTncSubaccountIds(req.NegativeTncSubaccountIds)
s.daemonLiquidationInfo.UpdateSubaccountsWithPositions(req.SubaccountOpenPositionInfo)
// Capture valid responses in metrics.
s.reportValidResponse(types.LiquidationsDaemonServiceName)
return &api.LiquidateSubaccountsResponse{}, nil
}