Documentation
¶
Index ¶
- func GenerateLiquidateSubaccountsPaginatedRequests(ids []satypes.SubaccountId, blockHeight uint32, pageLimit uint64) []*api.LiquidateSubaccountsRequest
- func GenerateNegativeTNCSubaccountsPaginatedRequests(ids []satypes.SubaccountId, blockHeight uint32, pageLimit uint64) []*api.LiquidateSubaccountsRequest
- func GenerateSubaccountOpenPositionPaginatedRequests(subaccountOpenPositionInfo []clobtypes.SubaccountOpenPositionInfo, ...) []*api.LiquidateSubaccountsRequest
- func StartLiquidationsDaemonTaskLoop(client *Client, ctx context.Context, s SubTaskRunner, flags flags.DaemonFlags, ...)
- type Client
- func (c *Client) CheckSubaccountCollateralization(unsettledSubaccount satypes.Subaccount, perpInfos perptypes.PerpInfos) (isLiquidatable bool, hasNegativeTnc bool, err error)
- func (c *Client) FetchApplicationStateAtBlockHeight(ctx context.Context, blockHeight uint32, liqFlags flags.LiquidationFlags) (subaccounts []satypes.Subaccount, perpInfos perptypes.PerpInfos, err error)
- func (c *Client) GetAllLiquidityTiers(ctx context.Context, pageLimit uint64) (liquidityTiers []perptypes.LiquidityTier, err error)
- func (c *Client) GetAllMarketPrices(ctx context.Context, pageLimit uint64) (marketPrices []pricestypes.MarketPrice, err error)
- func (c *Client) GetAllPerpetuals(ctx context.Context, pageLimit uint64) (perpetuals []perptypes.Perpetual, err error)
- func (c *Client) GetAllSubaccounts(ctx context.Context, pageLimit uint64) (subaccounts []satypes.Subaccount, err error)
- func (c *Client) GetLiquidatableSubaccountIds(subaccounts []satypes.Subaccount, perpInfos perptypes.PerpInfos) (liquidatableSubaccountIds []satypes.SubaccountId, ...)
- func (c *Client) GetPreviousBlockInfo(ctx context.Context) (blockHeight uint32, err error)
- func (c *Client) GetSubaccountOpenPositionInfo(subaccounts []satypes.Subaccount) (subaccountOpenPositionInfo map[uint32]*clobtypes.SubaccountOpenPositionInfo)
- func (c *Client) SendLiquidatableSubaccountIds(ctx context.Context, blockHeight uint32, ...) error
- func (c *Client) Start(ctx context.Context, flags flags.DaemonFlags, appFlags appflags.Flags, ...) error
- type SubTaskRunner
- type SubTaskRunnerImpl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateLiquidateSubaccountsPaginatedRequests ¶
func GenerateLiquidateSubaccountsPaginatedRequests( ids []satypes.SubaccountId, blockHeight uint32, pageLimit uint64, ) []*api.LiquidateSubaccountsRequest
func GenerateNegativeTNCSubaccountsPaginatedRequests ¶
func GenerateNegativeTNCSubaccountsPaginatedRequests( ids []satypes.SubaccountId, blockHeight uint32, pageLimit uint64, ) []*api.LiquidateSubaccountsRequest
func GenerateSubaccountOpenPositionPaginatedRequests ¶
func GenerateSubaccountOpenPositionPaginatedRequests( subaccountOpenPositionInfo []clobtypes.SubaccountOpenPositionInfo, blockHeight uint32, pageLimit uint64, ) []*api.LiquidateSubaccountsRequest
func StartLiquidationsDaemonTaskLoop ¶
func StartLiquidationsDaemonTaskLoop( client *Client, ctx context.Context, s SubTaskRunner, flags flags.DaemonFlags, ticker *time.Ticker, stop <-chan bool, )
StartLiquidationsDaemonTaskLoop contains the logic to periodically run the liquidations daemon task.
Types ¶
type Client ¶
type Client struct {
// Query clients
BlocktimeQueryClient blocktimetypes.QueryClient
SubaccountQueryClient satypes.QueryClient
PerpetualsQueryClient perptypes.QueryClient
PricesQueryClient pricestypes.QueryClient
ClobQueryClient clobtypes.QueryClient
LiquidationServiceClient api.LiquidationServiceClient
// include HealthCheckable to track the health of the daemon.
daemontypes.HealthCheckable
// contains filtered or unexported fields
}
Client implements a daemon service client that periodically calculates and reports liquidatable subaccounts to the protocol.
func (*Client) CheckSubaccountCollateralization ¶
func (c *Client) CheckSubaccountCollateralization( unsettledSubaccount satypes.Subaccount, perpInfos perptypes.PerpInfos, ) ( isLiquidatable bool, hasNegativeTnc bool, err error, )
CheckSubaccountCollateralization performs the same collateralization check as the application using the provided market prices, perpetuals, and liquidity tiers.
Note that current implementation assumes that the only asset is USDC and multi-collateral support is not yet implemented.
func (*Client) FetchApplicationStateAtBlockHeight ¶
func (c *Client) FetchApplicationStateAtBlockHeight( ctx context.Context, blockHeight uint32, liqFlags flags.LiquidationFlags, ) ( subaccounts []satypes.Subaccount, perpInfos perptypes.PerpInfos, err error, )
FetchApplicationStateAtBlockHeight queries a gRPC server and fetches the following information given a block height: - Last committed block height. - Subaccounts including their open positions. - Market prices. - Perpetuals. - Liquidity tiers.
func (*Client) GetAllLiquidityTiers ¶
func (c *Client) GetAllLiquidityTiers( ctx context.Context, pageLimit uint64, ) ( liquidityTiers []perptypes.LiquidityTier, err error, )
GetAllLiquidityTiers queries gRPC server and returns a list of liquidityTiers.
func (*Client) GetAllMarketPrices ¶
func (c *Client) GetAllMarketPrices( ctx context.Context, pageLimit uint64, ) ( marketPrices []pricestypes.MarketPrice, err error, )
GetAllMarketPrices queries gRPC server and returns a list of market prices.
func (*Client) GetAllPerpetuals ¶
func (c *Client) GetAllPerpetuals( ctx context.Context, pageLimit uint64, ) ( perpetuals []perptypes.Perpetual, err error, )
GetAllPerpetuals queries gRPC server and returns a list of perpetuals.
func (*Client) GetAllSubaccounts ¶
func (c *Client) GetAllSubaccounts( ctx context.Context, pageLimit uint64, ) ( subaccounts []satypes.Subaccount, err error, )
GetAllSubaccounts queries a gRPC server and returns a list of subaccounts and their balances and open positions.
func (*Client) GetLiquidatableSubaccountIds ¶
func (c *Client) GetLiquidatableSubaccountIds( subaccounts []satypes.Subaccount, perpInfos perptypes.PerpInfos, ) ( liquidatableSubaccountIds []satypes.SubaccountId, negativeTncSubaccountIds []satypes.SubaccountId, err error, )
GetLiquidatableSubaccountIds verifies collateralization statuses of subaccounts with at least one open position and returns a list of unique and potentially liquidatable subaccount ids.
func (*Client) GetPreviousBlockInfo ¶
GetPreviousBlockInfo queries a gRPC server using `QueryPreviousBlockInfoRequest` and returns the previous block height.
func (*Client) GetSubaccountOpenPositionInfo ¶
func (c *Client) GetSubaccountOpenPositionInfo( subaccounts []satypes.Subaccount, ) ( subaccountOpenPositionInfo map[uint32]*clobtypes.SubaccountOpenPositionInfo, )
GetSubaccountOpenPositionInfo iterates over the given subaccounts and returns a map of perpetual id to open position info.
func (*Client) SendLiquidatableSubaccountIds ¶
func (c *Client) SendLiquidatableSubaccountIds( ctx context.Context, blockHeight uint32, liquidatableSubaccountIds []satypes.SubaccountId, negativeTncSubaccountIds []satypes.SubaccountId, openPositionInfoMap map[uint32]*clobtypes.SubaccountOpenPositionInfo, pageLimit uint64, ) error
SendLiquidatableSubaccountIds sends a list of unique and potentially liquidatable subaccount ids to a gRPC server via `LiquidateSubaccounts`.
func (*Client) Start ¶
func (c *Client) Start( ctx context.Context, flags flags.DaemonFlags, appFlags appflags.Flags, grpcClient daemontypes.GrpcClient, ) error
Start begins a job that periodically: 1) Queries a gRPC server for all subaccounts including their open positions. 2) Checks collateralization statuses of subaccounts with at least one open position. 3) Sends a list of subaccount ids that potentially need to be liquidated to the application.
type SubTaskRunner ¶
type SubTaskRunner interface {
RunLiquidationDaemonTaskLoop(
ctx context.Context,
client *Client,
liqFlags flags.LiquidationFlags,
) error
}
SubTaskRunner provides an interface that encapsulates the liquidations daemon logic to gather and report potentially liquidatable subaccount ids. This interface is used to mock the daemon logic in tests.
type SubTaskRunnerImpl ¶
type SubTaskRunnerImpl struct {
// contains filtered or unexported fields
}
func (*SubTaskRunnerImpl) RunLiquidationDaemonTaskLoop ¶
func (s *SubTaskRunnerImpl) RunLiquidationDaemonTaskLoop( ctx context.Context, daemonClient *Client, liqFlags flags.LiquidationFlags, ) error
RunLiquidationDaemonTaskLoop contains the logic to communicate with various gRPC services to find the liquidatable subaccount ids.