Documentation
¶
Overview ¶
Package amm tracks amm
Index ¶
- Constants
- Variables
- func DeriveVaultSigner(market sgo.PublicKey, nonce uint64, marketProgramID sgo.PublicKey) (sgo.PublicKey, error)
- func Download(parentCtx context.Context, stateClient state.Client, db *sql.DB, ...) error
- func ExportJSON(db *sql.DB, path string) error
- func ReadPools(db *sql.DB, fn func(*PoolRow) bool) error
- type AmmInfo
- type AmmInfoWithToken
- type Configuration
- type Fees
- type OpenBookMarket
- type PoolRow
- type Query
- type StateData
- type Summary
- type U128
Constants ¶
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.
const Size = 752
Size is the exact byte length of a serialised AmmInfo account. AmmInfo is repr(C, packed) and loaded on-chain via bytemuck's Pod/Zeroable (see Loadable::load / load_checked in the Raydium source), which the program itself gates on account.data_len() == size_of::<AmmInfo>() — so 752 is the only size that is ever legitimately this account type. Since AmmInfo has no discriminator, anything looser (e.g. "at least Size") would also match other, unrelated account types the program happens to own.
Variables ¶
var ProgramID = sgo.MustPublicKeyFromBase58("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8")
var Schema string
Functions ¶
func DeriveVaultSigner ¶ added in v0.4.16
func DeriveVaultSigner(market sgo.PublicKey, nonce uint64, marketProgramID sgo.PublicKey) (sgo.PublicKey, error)
DeriveVaultSigner recomputes the market's vault-signer PDA. The nonce is stored on the market account itself (VaultSignerNonce), so this is a direct CreateProgramAddress call rather than a bump search.
func Download ¶
func ExportJSON ¶ added in v0.4.16
ExportJSON writes every raydium_amm_pool row whose mints both have a known mint_info decimals row (capped at embedCap, a non-binding safety ceiling -- see that constant's and knownDecimalsPoolQuery's own doc comments) to path, so catscope-rust-bot's build.rs can read this file instead of opening prefetch.db directly. Reuses PoolRow's own json tags verbatim (same scanPool shape TopPools/ReadPools use, just a different query).
Types ¶
type AmmInfo ¶
type AmmInfo struct {
Status uint64 // bitmask: swap/deposit/withdraw/crank enabled
Nonce uint64 // bump used to derive amm_authority
OrderNum uint64
Depth uint64
CoinDecimals uint64
PcDecimals uint64
State uint64 // internal state machine
ResetFlag uint64
MinSize uint64
VolMaxCutRatio uint64
AmountWave uint64
CoinLotSize uint64 // mirrors OpenBook market
PcLotSize uint64
MinPriceMultiplier uint64
MaxPriceMultiplier uint64
SysDecimalValue uint64
Fees Fees
StateData StateData
CoinVault sgo.PublicKey // pool-owned token account for base mint
PcVault sgo.PublicKey // pool-owned token account for quote mint
CoinVaultMint sgo.PublicKey // base mint
PcVaultMint sgo.PublicKey // quote mint
LpMint sgo.PublicKey
OpenOrders sgo.PublicKey // pool's OpenOrders on OpenBook
Market sgo.PublicKey // OpenBook market
MarketProgram sgo.PublicKey // OpenBook program ID
TargetOrders sgo.PublicKey
// padding [u64; 8] in the real struct (64 bytes) — reserved, not two
// more pubkeys. Owner and LpReserve below land on the correct real
// offsets regardless, since this gap is the same size as the two
// pubkeys previously (incorrectly) read here.
Owner sgo.PublicKey // admin (multisig)
LpReserve uint64 // pool's minted LP token supply
}
AmmInfo mirrors the Raydium AMM v4 AmmInfo struct (repr(C, packed), 752 bytes). Source: https://github.com/raydium-io/raydium-amm/blob/master/program/src/state.rs
type AmmInfoWithToken ¶
type Fees ¶
type Fees struct {
MinSeparateNumerator uint64 // 5
MinSeparateDenominator uint64 // 10_000
TradeFeeNumerator uint64 // 25
TradeFeeDenominator uint64 // 10_000
PnlNumerator uint64 // 12 (protocol share of the swap fee)
PnlDenominator uint64 // 100
SwapFeeNumerator uint64 // 25 → 0.25% gross swap fee
SwapFeeDenominator uint64 // 10_000
}
Fees mirrors the Raydium AMM v4 Fees struct (repr(C, packed), 64 bytes).
type OpenBookMarket ¶ added in v0.4.16
type OpenBookMarket struct {
Pubkey sgo.PublicKey
VaultSignerNonce uint64
CoinVault sgo.PublicKey
PcVault sgo.PublicKey
EventQueue sgo.PublicKey
Bids sgo.PublicKey
Asks sgo.PublicKey
}
OpenBookMarket is the subset of a Serum/OpenBook MarketState account needed to build a Raydium AMM v4 swap instruction.
type PoolRow ¶ added in v0.4.16
type PoolRow struct {
Pubkey sgo.PublicKey `json:"pubkey"`
CoinVault sgo.PublicKey `json:"coin_vault"`
PcVault sgo.PublicKey `json:"pc_vault"`
CoinMint sgo.PublicKey `json:"coin_mint"`
PcMint sgo.PublicKey `json:"pc_mint"`
CoinBalance uint64 `json:"coin_balance"`
PcBalance uint64 `json:"pc_balance"`
MarketBids *sgo.PublicKey `json:"market_bids,omitempty"`
MarketAsks *sgo.PublicKey `json:"market_asks,omitempty"`
MarketEventQueue *sgo.PublicKey `json:"market_event_queue,omitempty"`
MarketCoinVault *sgo.PublicKey `json:"market_coin_vault,omitempty"`
MarketPcVault *sgo.PublicKey `json:"market_pc_vault,omitempty"`
MarketVaultSigner *sgo.PublicKey `json:"market_vault_signer,omitempty"`
}
PoolRow is a flat view of an AMM v4 pool. CoinMint/PcMint (and thus a spot price of PcBalance/CoinBalance raw-unit tokens) are only populated once both vault accounts have been fetched — see liquidPoolQuery. The Market* fields (OpenBook market account children, populated once the pool's `market` account has been fetched) are nullable independently of CoinMint/PcMint -- catscope-rust-bot's build.rs needs them for its RAYDIUM_AMM_POOLS embed, which only requires MarketVaultSigner to be set, not CoinMint/PcMint. Json tags let this struct be exported directly (see export.go) instead of via a separate JSON-shaped type.
type Query ¶ added in v0.4.16
type Query struct {
// contains filtered or unexported fields
}
func CreateQuery ¶ added in v0.4.16
CreateQuery prepares the top-pools-by-liquidity statement against raydium_amm_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.
type StateData ¶
type StateData struct {
NeedTakePnlCoin uint64
NeedTakePnlPc uint64
TotalPnlPc uint64
TotalPnlCoin uint64
PoolOpenTime uint64
// padding [u64; 2] in the real struct — reserved, not two real fields.
OrderbookToInitTime uint64
SwapCoinInAmount U128
SwapPcOutAmount U128
SwapAccPcFee uint64
SwapPcInAmount U128
SwapCoinOutAmount U128
SwapAccCoinFee uint64
}
StateData mirrors the Raydium AMM v4 StateData struct (repr(C, packed), 144 bytes). All fields from OrderbookToInitTime onward (including the padding below) are deprecated on-chain — no longer read or updated by the program.
type Summary ¶
Source Files
¶
- amm.go
- event.go
- export.go
- openbook.go
- query.go
- read.go
- schema.go