twozoracle

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Metrics names.
	MetricNameErrors           = "doublezero_monitor_twozoracle_errors_total"
	MetricNameHealthNotHealthy = "doublezero_monitor_twozoracle_health_not_healthy_total"
	MetricNameSwapRate         = "doublezero_monitor_twozoracle_swap_rate"
	MetricNameSOLPriceUSD      = "doublezero_monitor_twozoracle_sol_price_usd"
	MetricNameTwoZPriceUSD     = "doublezero_monitor_twozoracle_twoz_price_usd"
	MetricNameHealthResponse   = "doublezero_monitor_twozoracle_health_responses_total"
	MetricNameSwapRateResponse = "doublezero_monitor_twozoracle_swap_rate_responses_total"

	// Labels.
	MetricLabelErrorType  = "error_type"
	MetricLabelStatusCode = "status_code"

	// Error types.
	MetricErrorTypeGetHealth         = "get_health"
	MetricErrorTypeGetSwapRate       = "get_swap_rate"
	MetricErrorTypeParseSOLPriceUSD  = "parse_sol_price_usd"
	MetricErrorTypeParseTwoZPriceUSD = "parse_twoz_price_usd"
)

Variables

View Source
var (
	MetricErrors = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: MetricNameErrors,
			Help: "Number of errors encountered",
		},
		[]string{MetricLabelErrorType, MetricLabelStatusCode},
	)

	MetricHealthResponse = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: MetricNameHealthResponse,
			Help: "Number of health responses",
		},
		[]string{MetricLabelStatusCode},
	)

	MetricSwapRateResponse = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: MetricNameSwapRateResponse,
			Help: "Number of swap rate responses",
		},
		[]string{MetricLabelStatusCode},
	)

	MetricHealthNotHealthy = promauto.NewCounter(
		prometheus.CounterOpts{
			Name: MetricNameHealthNotHealthy,
			Help: "Number of health not healthy",
		},
	)

	MetricSwapRate = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: MetricNameSwapRate,
			Help: "Swap rate",
		},
	)

	MetricSOLPriceUSD = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: MetricNameSOLPriceUSD,
			Help: "SOL price USD",
		},
	)

	MetricTwoZPriceUSD = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: MetricNameTwoZPriceUSD,
			Help: "2Z price USD",
		},
	)
)

Functions

This section is empty.

Types

type CircuitBreaker

type CircuitBreaker struct {
	State             string `json:"state"`
	LastFailureReason string `json:"lastFailureReason"`
}

type Config

type Config struct {
	Logger   *slog.Logger
	Interval time.Duration
	Client   TwoZOracleClient
}

func (*Config) Validate

func (c *Config) Validate() error

type HealthCheck

type HealthCheck struct {
	ServiceType     string `json:"serviceType"`
	Status          string `json:"status"`
	HermesConnected bool   `json:"hermes_connected"`
	CacheConnected  bool   `json:"cache_connected"`
	LastPriceUpdate string `json:"last_price_update"`
}

type HealthResponse

type HealthResponse struct {
	Healthy        bool           `json:"healthy"`
	HealthChecks   []HealthCheck  `json:"healthChecks"`
	CircuitBreaker CircuitBreaker `json:"circuitBreaker"`
	Timestamp      string         `json:"timestamp"`
}

type SwapRateResponse

type SwapRateResponse struct {
	SwapRate     float64 `json:"swapRate"`
	Timestamp    int64   `json:"timestamp"`
	Signature    string  `json:"signature"`
	SOLPriceUSD  string  `json:"solPriceUsd"`
	TwoZPriceUSD string  `json:"twozPriceUsd"`
	CacheHit     bool    `json:"cacheHit"`
}

type TwoZOracleClient

type TwoZOracleClient interface {
	SwapRate(ctx context.Context) (SwapRateResponse, int, error)
	Health(ctx context.Context) (HealthResponse, int, error)
}

func NewTwoZOracleClient

func NewTwoZOracleClient(httpClient *http.Client, baseURL string) TwoZOracleClient

type TwoZOracleWatcher

type TwoZOracleWatcher struct {
	// contains filtered or unexported fields
}

func NewTwoZOracleWatcher

func NewTwoZOracleWatcher(cfg *Config) (*TwoZOracleWatcher, error)

func (*TwoZOracleWatcher) Name

func (w *TwoZOracleWatcher) Name() string

func (*TwoZOracleWatcher) Run

func (w *TwoZOracleWatcher) Run(ctx context.Context) error

func (*TwoZOracleWatcher) Tick

func (w *TwoZOracleWatcher) Tick(ctx context.Context) error

Jump to

Keyboard shortcuts

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