cpmm

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 cpmm tracks cpmm

Index

Constants

View Source
const (
	PoolStateBodySize = 629
	AmmConfigBodySize = 228
)

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

View Source
const OldSlot = 8 * 60 * 60 * 25 / 10

8 hours

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.

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("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C")
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_cpmm_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 ~1,200 rows passing this filter.

func ReadPools added in v0.4.16

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

ReadPools calls fn for each liquid CPMM pool (lp_supply > 0, both vault balances non-zero). Iteration stops early if fn returns false.

func ReadPoolsByMints added in v0.4.16

func ReadPoolsByMints(db *sql.DB, mintA, mintB sgo.PublicKey, fn func(*PoolRow) bool) error

ReadPoolsByMints calls fn for each liquid CPMM pool matching the given token pair in either mint order. Iteration stops early if fn returns false.

Types

type AmmConfig

type AmmConfig struct {
	Bump              uint8
	DisableCreatePool bool
	Index             uint16
	TradeFeeRate      uint64
	ProtocolFeeRate   uint64
	FundFeeRate       uint64
	CreatePoolFee     uint64
	ProtocolOwner     sgo.PublicKey
	FundOwner         sgo.PublicKey
	CreatorFeeRate    uint64
}

AmmConfig mirrors the Raydium CPMM AmmConfig struct (repr(C, packed), 228 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{}

Configuration is the result of a completed CPMM pool download.

type PoolRow added in v0.4.16

type PoolRow struct {
	Pubkey        sgo.PublicKey `json:"pubkey"`
	AmmConfig     sgo.PublicKey `json:"amm_config"`
	Token0Mint    sgo.PublicKey `json:"token0_mint"`
	Token1Mint    sgo.PublicKey `json:"token1_mint"`
	Token0Vault   sgo.PublicKey `json:"token0_vault"`
	Token1Vault   sgo.PublicKey `json:"token1_vault"`
	LpSupply      uint64        `json:"lp_supply"`
	Token0Balance uint64        `json:"token0_balance"`
	Token1Balance uint64        `json:"token1_balance"`
	TradeFeeRate  uint64        `json:"trade_fee_rate"`
}

PoolRow is a flat view of a CPMM 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 CPMM pools with the highest liquidity (token0_balance + token1_balance, raw token units), sorted descending.

type PoolState

type PoolState struct {
	AmmConfig          sgo.PublicKey
	PoolCreator        sgo.PublicKey
	Token0Vault        sgo.PublicKey
	Token1Vault        sgo.PublicKey
	LpMint             sgo.PublicKey
	Token0Mint         sgo.PublicKey
	Token1Mint         sgo.PublicKey
	Token0Program      sgo.PublicKey // SPL Token or Token-2022 program
	Token1Program      sgo.PublicKey
	ObservationKey     sgo.PublicKey
	AuthBump           uint8
	Status             uint8 // bitmask: deposit | withdraw | swap
	LpMintDecimals     uint8
	Mint0Decimals      uint8
	Mint1Decimals      uint8
	LpSupply           uint64
	ProtocolFeesToken0 uint64
	ProtocolFeesToken1 uint64
	FundFeesToken0     uint64
	FundFeesToken1     uint64
	OpenTime           uint64
	RecentEpoch        uint64
	CreatorFeeOn       uint8
	EnableCreatorFee   bool
	CreatorFeesToken0  uint64
	CreatorFeesToken1  uint64
}

PoolState mirrors the Raydium CPMM PoolState struct (repr(C, packed), 629 bytes after discriminator). Source: https://github.com/raydium-io/raydium-cp-swap/blob/master/programs/cp-swap/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 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_cpmm_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 raydium_cpmm_pool pubkeys, ranked by token0_balance+token1_balance descending, as a semicolon-joined "pubkey=..." list.

type Summary

type Summary struct {
	Pubkey       sgo.PublicKey `json:"pubkey"`
	Mint0        sgo.PublicKey `json:"mint_0"`
	Mint1        sgo.PublicKey `json:"mint_1"`
	TradeFeeRate uint64        `json:"trade_fee_rate"`
}

Summary is the compact, JSON-serialisable view of a CPMM pool.

Source Files

  • cpmm.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