client

package
v0.0.0-...-cc24d94 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 NewClient

func NewClient(logger log.Logger) *Client

func (*Client) CheckSubaccountCollateralization

func (c *Client) CheckSubaccountCollateralization(
	unsettledSubaccount satypes.Subaccount,
	marketPrices map[uint32]pricestypes.MarketPrice,
	perpetuals map[uint32]perptypes.Perpetual,
	liquidityTiers map[uint32]perptypes.LiquidityTier,
) (
	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,
	marketPricesMap map[uint32]pricestypes.MarketPrice,
	perpetualsMap map[uint32]perptypes.Perpetual,
	liquidityTiersMap map[uint32]perptypes.LiquidityTier,
	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,
	marketPrices map[uint32]pricestypes.MarketPrice,
	perpetuals map[uint32]perptypes.Perpetual,
	liquidityTiers map[uint32]perptypes.LiquidityTier,
) (
	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

func (c *Client) GetPreviousBlockInfo(
	ctx context.Context,
) (
	blockHeight uint32,
	err error,
)

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,
) 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{}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL