clmm

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package clmm tracks clmm

Index

Constants

View Source
const (
	PoolStateBodySize = 1536
	AmmConfigBodySize = 109
)

Body sizes (excluding the 8-byte Anchor discriminator).

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 OldSlot in raydium/cpmm for the established precedent of this convention.

Variables

View Source
var (
	DiscPoolState = [8]byte{247, 237, 227, 245, 215, 195, 222, 70}
	DiscAmmConfig = [8]byte{218, 244, 33, 104, 203, 203, 43, 111}
)

Anchor discriminators: sha256("account:<TypeName>")[0..8]

View Source
var ProgramID = sgo.MustPublicKeyFromBase58("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK")
View Source
var Schema string

Functions

func Download

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

func ExportJSON added in v0.4.16

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

ExportJSON writes every liquid raydium_clmm_pool row (joined with its fee config, same filter ReadPools/TopPools already apply) to path, so catscope-rust-bot's build.rs can read this file instead of opening prefetch.db directly. No cap: a real prefetch.db has ~17,900 rows passing this filter, small enough to export in full -- unlike raydium_amm_pool's ~602K (see amm.embedCap's doc comment).

func ReadPools added in v0.4.16

func ReadPools(db *sql.DB, fn func(*PoolRow) bool) error

ReadPools calls fn for each liquid CLMM pool (both vault balances non-zero). Iteration stops early if fn returns false.

Types

type Amm added in v0.4.16

type Amm struct {
	Config *AmmConfig
	MPool  map[sgo.PublicKey]*PoolStateWithToken
}

Amm bundles a parsed AmmConfig with the pools discovered under it. Only referenced by the (currently unpopulated) Configuration type below -- event.go's eventHandler stopped using this shape once pool/vault bookkeeping moved to DB-backed lookups (see isConfigFresh/isPoolFresh/ findPoolByVault).

type AmmConfig

type AmmConfig struct {
	Bump            uint8
	Index           uint16
	Owner           sgo.PublicKey
	ProtocolFeeRate uint32
	TradeFeeRate    uint32
	TickSpacing     uint16
	FundFeeRate     uint32
	FundOwner       sgo.PublicKey
}

AmmConfig mirrors the Raydium CLMM AmmConfig struct (repr(C, packed), 109 bytes after discriminator).

func ParseAmmConfig

func ParseAmmConfig(id sgo.PublicKey, body []byte) (*AmmConfig, error)

ParseAmmConfig deserialises the body of an AmmConfig account (after the 8-byte discriminator).

type Configuration

type Configuration struct {
	List map[sgo.PublicKey]*Amm `json:"list"`
}

Configuration is the result of a completed CLMM pool download.

type DynamicFeeInfo

type DynamicFeeInfo struct {
	FilterPeriod              uint16
	DecayPeriod               uint16
	ReductionFactor           uint16
	DynamicFeeControl         uint32
	MaxVolatilityAccumulator  uint32
	TickSpacingIndexReference int32
	VolatilityReference       uint32
	VolatilityAccumulator     uint32
	LastUpdateTimestamp       uint64
}

DynamicFeeInfo mirrors the Raydium CLMM DynamicFeeInfo struct (repr(C, packed), 80 bytes).

type PoolRow added in v0.4.16

type PoolRow struct {
	Pubkey        sgo.PublicKey `json:"pubkey"`
	TokenMint0    sgo.PublicKey `json:"token_mint0"`
	TokenMint1    sgo.PublicKey `json:"token_mint1"`
	TokenVault0   sgo.PublicKey `json:"token_vault0"`
	TokenVault1   sgo.PublicKey `json:"token_vault1"`
	Token0Balance uint64        `json:"token0_balance"`
	Token1Balance uint64        `json:"token1_balance"`
	TradeFeeRate  uint32        `json:"trade_fee_rate"`
}

PoolRow is a flat view of a CLMM pool joined with its fee config. Json tags let this struct be exported directly (see export.go) instead of via a separate JSON-shaped type.

func TopPools added in v0.4.16

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

TopPools returns the n liquid CLMM pools with the highest liquidity (token0_balance + token1_balance, raw token units), sorted descending.

type PoolState

type PoolState struct {
	Bump                uint8
	AmmConfig           sgo.PublicKey
	Owner               sgo.PublicKey
	TokenMint0          sgo.PublicKey
	TokenMint1          sgo.PublicKey
	TokenVault0         sgo.PublicKey
	TokenVault1         sgo.PublicKey
	ObservationKey      sgo.PublicKey
	MintDecimals0       uint8
	MintDecimals1       uint8
	TickSpacing         uint16
	Liquidity           U128
	SqrtPriceX64        U128
	TickCurrent         int32
	FeeGrowthGlobal0X64 U128
	FeeGrowthGlobal1X64 U128
	ProtocolFeesToken0  uint64
	ProtocolFeesToken1  uint64
	Status              uint8
	FeeOn               uint8
	RewardInfos         [3]RewardInfo
	FundFeesToken0      uint64
	FundFeesToken1      uint64
	OpenTime            uint64
	RecentEpoch         uint64
	DynamicFeeInfo      DynamicFeeInfo
}

PoolState mirrors the Raydium CLMM PoolState struct (repr(C, packed), 1536 bytes after discriminator). Source: https://github.com/raydium-io/raydium-clmm/blob/master/programs/amm/src/states/pool.rs

func ParsePoolState

func ParsePoolState(id sgo.PublicKey, body []byte) (*PoolState, error)

ParsePoolState deserialises the body of a PoolState account (after the 8-byte discriminator).

type PoolStateWithToken

type PoolStateWithToken struct {
	Info        *PoolState
	TokenVault0 *sgotkn.Account
	TokenVault1 *sgotkn.Account
}

PoolStateWithToken bundles a parsed pool state with its fetched vault balances.

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 raydium_clmm_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 -- keeps the model from having to choose between many near-identical per-DEX tools.

func (*Query) TopPools added in v0.4.16

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

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

type RewardInfo

type RewardInfo struct {
	RewardState           uint8
	OpenTime              uint64
	EndTime               uint64
	LastUpdateTime        uint64
	EmissionsPerSecondX64 U128
	RewardTotalEmitted    uint64
	RewardClaimed         uint64
	TokenMint             sgo.PublicKey
	TokenVault            sgo.PublicKey
	Authority             sgo.PublicKey
	RewardGrowthGlobalX64 U128
}

RewardInfo mirrors the Raydium CLMM RewardInfo struct (repr(C, packed), 169 bytes).

type U128

type U128 struct {
	Lo uint64
	Hi uint64
}

U128 holds a little-endian 128-bit unsigned integer split into two 64-bit halves.

Source Files

  • clmm.go
  • event.go
  • export.go
  • query.go
  • read.go
  • schema.go

Jump to

Keyboard shortcuts

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