orca

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package orca preloads Orca Whirlpool trading pools.

Index

Constants

View Source
const SevenDaysOfSlots = 7 * 24 * 60 * 60 * 25 / 10 // 1,512,000 slots

SevenDaysOfSlots assumes ~400ms/slot (2.5 slots/sec), the same fallback bot/state/clock.go itself uses before real slot-timing data arrives -- see raydium/cpmm's own OldSlot for the established precedent of this convention.

Variables

View Source
var (
	ProgramID     = sgo.MustPublicKeyFromBase58("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc")
	CheckPoolID   = sgo.MustPublicKeyFromBase58("Czfq3xZZDmsdGdUyrNLtRhGc47cXcZtLG4crryfu44zE")
	CheckConfigID = sgo.MustPublicKeyFromBase58("2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ")
)
View Source
var (
	DiscriminatorWhirlpoolConfig = [8]uint8{157, 20, 49, 224, 217, 87, 193, 254}
	DiscriminatorWhirlpool       = [8]uint8{63, 149, 209, 12, 225, 128, 99, 9}
	DiscriminatorTickArray       = [8]uint8{69, 97, 189, 190, 110, 7, 66, 187}
)
View Source
var Schema string

Functions

func ExportJSON added in v0.4.16

func ExportJSON(db *sql.DB, path string) error

ExportJSON writes every orca_whirlpool_pool row to path.

Types

type Orca

type Orca struct {
	Pools []*Whirlpool
	// contains filtered or unexported fields
}

Orca holds all Whirlpool pools loaded at startup.

func Create

func Create(ctx context.Context, stateClient state.Client, db *sql.DB, maxSubscriptionCount int, force bool, mintTracker *mintinfo.Tracker) (*Orca, error)

Create queries the graph at depth 2 from the Orca program ID (program → WhirlpoolConfig → Whirlpool) and parses every pool account found, persisting results to db (orca_whirlpool_pool). If db already has pools from a previous run, they're loaded back instead of re-fetching, unless force is true.

func (*Orca) Args

func (orca *Orca) Args(args []string) ([]string, error)

func (*Orca) Env

func (orca *Orca) Env(mEnv map[string]string) error

func (*Orca) Find

func (orca *Orca) Find(poolID sgo.PublicKey) *Whirlpool

func (*Orca) String

func (orca *Orca) String() string

type PoolJSON added in v0.4.16

type PoolJSON struct {
	Pubkey        sgo.PublicKey `json:"pubkey"`
	MintA         sgo.PublicKey `json:"mint_a"`
	MintB         sgo.PublicKey `json:"mint_b"`
	VaultA        sgo.PublicKey `json:"vault_a"`
	VaultB        sgo.PublicKey `json:"vault_b"`
	VaultABalance *int64        `json:"vault_a_balance,omitempty"`
	VaultBBalance *int64        `json:"vault_b_balance,omitempty"`
	SqrtPriceLo   int64         `json:"sqrt_price_lo"`
	SqrtPriceHi   int64         `json:"sqrt_price_hi"`
	LiquidityLo   int64         `json:"liquidity_lo"`
	LiquidityHi   int64         `json:"liquidity_hi"`
}

PoolJSON is one orca_whirlpool_pool row, JSON-shaped for catscope-rust-bot's build.rs to read instead of opening prefetch.db directly. Exported unfiltered (no WHERE clause) -- build.rs's three consumers (the router-graph BFS, the ORCA_WHIRLPOOL_POOLS embed re-query, and top_pools_data.rs) apply three different filters/orderings of their own, and unlike raydium_amm_pool this table has no nullable mint/vault columns and a manageable row count (~150K), so there's no reason to filter or cap on the Go side -- see amm.embedCap's doc comment for the contrasting case where that mattered.

type Query added in v0.4.16

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

func CreateQuery added in v0.4.16

func CreateQuery(db *sql.DB) (*Query, error)

CreateQuery prepares the top-pools-by-liquidity statement against orca_whirlpool_pool. Callers wrap the result as one dispatch case of a single, consolidated "get top pools" tool (see prefetch/prompttool.go) rather than exposing their own separate tool.

func (*Query) TopPools added in v0.4.16

func (q *Query) TopPools(ctx context.Context, count int) (string, error)

TopPools returns up to count orca_whirlpool_pool pubkeys, ranked by liquidity_hi descending, as a semicolon-joined "pubkey=..." list.

type Whirlpool

type Whirlpool struct {
	Pubkey           sgo.PublicKey
	WhirlpoolsConfig sgo.PublicKey
	TokenMintA       sgo.PublicKey
	TokenMintB       sgo.PublicKey
	VaultA           sgo.PublicKey
	VaultB           sgo.PublicKey
	SqrtPriceHi      uint64 // high 64 bits of Q64.64 sqrt price
	SqrtPriceLo      uint64 // low 64 bits of Q64.64 sqrt price
	LiquidityLo      uint64 // low 64 bits of active liquidity u128
	LiquidityHi      uint64 // high 64 bits of active liquidity u128
	TickCurrentIndex int32
	TickSpacing      uint16
	FeeRate          uint16 // hundredths of a basis point (3000 = 0.3%)
}

Whirlpool is the parsed state of an Orca Whirlpool concentrated-liquidity pool.

func TopPools added in v0.4.16

func TopPools(db *sql.DB, n int) ([]*Whirlpool, error)

TopPools returns the n Whirlpool pools with the highest active liquidity (the Uniswap-v3-style u128 L, not a raw token-amount sum — Orca pools don't have vault balances in this schema), sorted descending.

liquidity_lo/liquidity_hi are stored as bit-reinterpreted int64s of a u128 split in two, so a plain "ORDER BY liquidity_hi DESC, liquidity_lo DESC" would sort wrong wherever the top bit is set (a huge unsigned value would look negative and sort as small). "(x < 0) DESC, x DESC" fixes that: it puts values whose sign bit is set (true unsigned magnitude >= 2^63) ahead of those without, and within each group signed-descending order already matches unsigned-descending order.

func (*Whirlpool) FeeBps

func (w *Whirlpool) FeeBps() uint16

FeeBps returns the fee in basis points.

func (*Whirlpool) LiquidityUsd added in v0.4.14

func (w *Whirlpool) LiquidityUsd(prices map[sgo.PublicKey]float64, decimals map[sgo.PublicKey]uint8) float64

LiquidityUsd returns a rough USD estimate of active liquidity using virtual reserves derived from the pool's active liquidity L and sqrt price.

virtualA = L / sqrt_price (raw units of token A) virtualB = L * sqrt_price (raw units of token B)

prices maps each mint to its USD price per human-readable token unit. decimals maps each mint to the number of decimal places (e.g. USDC → 6).

func (*Whirlpool) SpotPrice

func (w *Whirlpool) SpotPrice() float64

SpotPrice returns token_b raw units per token_a raw unit.

func (*Whirlpool) String

func (w *Whirlpool) String() string

type WhirlpoolConfig added in v0.4.16

type WhirlpoolConfig struct {
	Pubkey                        sgo.PublicKey
	FeeAuthority                  sgo.PublicKey
	CollectProtocolFeesAuthority  sgo.PublicKey
	RewardEmissionsSuperAuthority sgo.PublicKey
	DefaultProtocolFeeRate        uint16
}

WhirlpoolConfig is the parsed state of an Orca WhirlpoolsConfig account.

Source Files

  • event.go
  • export.go
  • liquidity.go
  • loader.go
  • orca.go
  • print.go
  • query.go
  • schema.go
  • store.go
  • top.go
  • whirlpool.go

Jump to

Keyboard shortcuts

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