Meteora¶
Connector for Meteora protocol.
almanak.framework.connectors.meteora
¶
Meteora DLMM concentrated liquidity connector.
Provides LP operations on Meteora DLMM pools on Solana: - Open concentrated liquidity positions (discrete bins) - Close positions (remove liquidity + close account)
Unlike Raydium CLMM (NFT positions, continuous ticks), Meteora DLMM uses: - Discrete price bins instead of continuous ticks - Non-transferable Keypair-based position accounts (not NFTs) - SpotBalanced strategy for even liquidity distribution
MeteoraAdapter
¶
Adapter for Meteora DLMM integration with the Intent system.
Converts LP intents to ActionBundles containing serialized Solana VersionedTransactions built from Meteora DLMM instructions.
Example
config = MeteoraConfig(wallet_address="your-solana-pubkey") adapter = MeteoraAdapter(config)
intent = LPOpenIntent( protocol="meteora_dlmm", pool="pool-address", amount0=Decimal("1"), amount1=Decimal("150"), range_lower=Decimal("100"), range_upper=Decimal("200"), ) bundle = adapter.compile_lp_open_intent(intent)
compile_lp_open_intent
¶
Compile an LPOpenIntent to an ActionBundle.
Builds Meteora DLMM initializePosition + addLiquidityByStrategy, serializes into a VersionedTransaction, and wraps in an ActionBundle.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
intent
|
LPOpenIntent
|
The LPOpenIntent to compile. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
ActionBundle
|
ActionBundle containing serialized Solana transaction(s). |
compile_lp_close_intent
¶
Compile an LPCloseIntent to an ActionBundle.
Removes all liquidity and closes the position.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
intent
|
LPCloseIntent
|
The LPCloseIntent to compile. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
ActionBundle
|
ActionBundle containing serialized Solana transaction(s). |
MeteoraConfig
¶
Configuration for Meteora adapter.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
wallet_address |
Solana wallet public key (Base58). |
|
rpc_url |
Solana RPC endpoint URL (for position queries). |
|
default_strategy_type |
Default strategy type (6=SpotBalanced). |
MeteoraAPIError
¶
MeteoraError
¶
Bases: Exception
Base exception for Meteora operations.
MeteoraPoolError
¶
Bases: MeteoraError
Error with pool state or operations.
MeteoraPositionError
¶
Bases: MeteoraError
Error with position state or operations.
MeteoraBin
dataclass
¶
A single bin in a DLMM pool.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
bin_id |
int
|
Bin identifier. |
amount_x |
int
|
Amount of token X in smallest units. |
amount_y |
int
|
Amount of token Y in smallest units. |
price |
float
|
Price at this bin (token Y per token X). |
MeteoraPool
dataclass
¶
MeteoraPool(
address: str,
mint_x: str,
mint_y: str,
symbol_x: str = "",
symbol_y: str = "",
decimals_x: int = 9,
decimals_y: int = 6,
bin_step: int = 10,
active_bin_id: int = 0,
current_price: float = 0.0,
tvl: float = 0.0,
reserve_x: str = "0",
reserve_y: str = "0",
fee_bps: int = 0,
vault_x: str = "",
vault_y: str = "",
oracle_address: str = "",
raw_response: dict[str, Any] = dict(),
)
Meteora DLMM pool information.
Can be constructed from the DLMM API response.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
address |
str
|
Pool (lb_pair) account address (Base58). |
mint_x |
str
|
Token X mint address. |
mint_y |
str
|
Token Y mint address. |
symbol_x |
str
|
Token X symbol (e.g., "SOL"). |
symbol_y |
str
|
Token Y symbol (e.g., "USDC"). |
decimals_x |
int
|
Token X decimals. |
decimals_y |
int
|
Token Y decimals. |
bin_step |
int
|
Bin step in basis points. |
active_bin_id |
int
|
Currently active bin ID. |
current_price |
float
|
Current price of token X in terms of token Y. |
tvl |
float
|
Total value locked in USD. |
reserve_x |
str
|
Token X reserve in pool. |
reserve_y |
str
|
Token Y reserve in pool. |
fee_bps |
int
|
Base fee in basis points. |
vault_x |
str
|
Token X vault address. |
vault_y |
str
|
Token Y vault address. |
oracle_address |
str
|
Oracle PDA address. |
raw_response |
dict[str, Any]
|
Full API response dict. |
from_api_response
classmethod
¶
Create from Meteora DLMM API response.
Works with both /pair/{address} and /pair/all_with_pagination items.
MeteoraPosition
dataclass
¶
MeteoraPosition(
position_address: str,
lb_pair: str,
owner: str = "",
lower_bin_id: int = 0,
upper_bin_id: int = 0,
bins: list[MeteoraBin] = list(),
total_x: int = 0,
total_y: int = 0,
)
Meteora DLMM position state (on-chain).
Unlike Raydium CLMM (NFT-based), Meteora positions are non-transferable program accounts identified by their address.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
position_address |
str
|
Position account address (Base58). |
lb_pair |
str
|
Pool address. |
owner |
str
|
Owner wallet address. |
lower_bin_id |
int
|
Lower bin ID of the position range. |
upper_bin_id |
int
|
Upper bin ID of the position range. |
bins |
list[MeteoraBin]
|
List of bins with amounts. |
total_x |
int
|
Total token X in position. |
total_y |
int
|
Total token Y in position. |
MeteoraReceiptParser
¶
Parser for Meteora DLMM transaction receipts.
Extracts position IDs, liquidity amounts, and token balances from Solana transaction receipts.
Supports the extraction methods required by ResultEnricher: - extract_position_id(receipt) -> str | None - extract_liquidity(receipt) -> dict | None - extract_lp_close_data(receipt) -> dict | None
Extraction approach: 1. Parse log messages for Meteora program events 2. Use preTokenBalances/postTokenBalances for actual amounts 3. Look for position address in ActionBundle metadata
Initialize MeteoraReceiptParser.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
**kwargs
|
Any
|
Keyword arguments from receipt_registry (e.g., chain). |
{}
|
parse_receipt
¶
Parse a receipt for ReceiptParser protocol compatibility.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
receipt
|
dict[str, Any]
|
Solana transaction receipt dict. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any]
|
Dict with parsed LP data. |
extract_position_id
¶
Extract the position address from a Meteora LP open receipt.
Meteora positions are Keypair-based accounts (not NFTs). The position address is typically in the ActionBundle metadata, but we also look in the transaction's account keys for new writable accounts.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
receipt
|
dict[str, Any]
|
Solana transaction receipt dict. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
str | None
|
Position address (Base58), or None if not found. |
extract_liquidity
¶
Extract liquidity data from an LP open/increase receipt.
Uses balance deltas to determine actual deposited amounts.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
receipt
|
dict[str, Any]
|
Solana transaction receipt dict. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any] | None
|
Dict with amount_x, amount_y, position_address, or None. |
extract_lp_close_data
¶
Extract LP close data from a receipt.
Uses balance deltas to determine received token amounts.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
receipt
|
dict[str, Any]
|
Solana transaction receipt dict. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any] | None
|
Dict with received amounts, or None. |
MeteoraSDK
¶
SDK for building Meteora DLMM instructions.
Provides methods to: - Fetch pool data from the Meteora DLMM API - Build Solana instructions for LP operations - Compute PDAs for positions, bin arrays, etc.
Example
sdk = MeteoraSDK(wallet_address="your-pubkey") pool = sdk.get_pool("pool-address") ixs, position_kp = sdk.build_open_position_transaction( pool=pool, lower_bin_id=8388600, upper_bin_id=8388620, amount_x=1_000_000, amount_y=500_000_000, )
get_pool
¶
Fetch pool information from the Meteora DLMM API.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pool_address
|
str
|
Pool (lb_pair) account address (Base58). |
必需 |
返回:
| 类型 | 描述 |
|---|---|
MeteoraPool
|
MeteoraPool with current pool data. |
引发:
| 类型 | 描述 |
|---|---|
MeteoraPoolError
|
If pool not found. |
MeteoraAPIError
|
If API request fails. |
find_pool
¶
Find a DLMM pool by token pair.
Searches the Meteora API for pools matching the token pair and returns the one with highest TVL.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
token_a
|
str
|
Token A mint address. |
必需 |
token_b
|
str
|
Token B mint address. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
MeteoraPool | None
|
Best matching MeteoraPool, or None if not found. |
get_active_bin
¶
Get the active bin for a pool.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pool_address
|
str
|
Pool address. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any]
|
Dict with bin_id, price, and amounts. |
get_position_pda
¶
Derive the position PDA.
seeds: [POSITION_SEED, lb_pair, base, lower_bin_id (i32 LE), width (i32 LE)]
get_position_state
¶
Query on-chain position state for a Meteora DLMM position.
Meteora PositionV2 layout (Anchor, 8-byte discriminator): [0:8] discriminator [8:40] lb_pair (Pubkey) [40:72] owner (Pubkey) [72:76] lower_bin_id (i32 LE) [76:80] upper_bin_id (i32 LE)
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
position_address
|
str
|
Position account address (Base58). |
必需 |
rpc_url
|
str
|
Solana RPC endpoint URL. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
MeteoraPosition
|
MeteoraPosition with on-chain state. |
引发:
| 类型 | 描述 |
|---|---|
MeteoraPositionError
|
If position account not found or data invalid. |
build_initialize_position_ix
¶
build_initialize_position_ix(
lb_pair: Pubkey,
position_kp: Keypair,
lower_bin_id: int,
width: int,
) -> Instruction
Build initializePosition instruction.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
lb_pair
|
Pubkey
|
Pool address. |
必需 |
position_kp
|
Keypair
|
New keypair for the position account. |
必需 |
lower_bin_id
|
int
|
Lower bin ID. |
必需 |
width
|
int
|
Number of bins in the position. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Instruction
|
Solana instruction. |
build_add_liquidity_by_strategy_ix
¶
build_add_liquidity_by_strategy_ix(
pool: MeteoraPool,
position: Pubkey,
lower_bin_id: int,
upper_bin_id: int,
amount_x: int,
amount_y: int,
active_id: int,
max_active_bin_slippage: int = 5,
strategy_type: int = STRATEGY_TYPE_SPOT_BALANCED,
) -> Instruction
Build addLiquidityByStrategy instruction.
LiquidityParameterByStrategy layout
amount_x: u64 amount_y: u64 active_id: i32 max_active_bin_slippage: i32 strategy_parameters: min_bin_id: i32 max_bin_id: i32 strategy_type: u8 parameters: [u8; 64] (zeroed for SpotBalanced)
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pool
|
MeteoraPool
|
Pool information. |
必需 |
position
|
Pubkey
|
Position account address. |
必需 |
lower_bin_id
|
int
|
Min bin ID for strategy parameters. |
必需 |
upper_bin_id
|
int
|
Max bin ID for strategy parameters. |
必需 |
amount_x
|
int
|
Amount of token X in smallest units. |
必需 |
amount_y
|
int
|
Amount of token Y in smallest units. |
必需 |
active_id
|
int
|
Current active bin ID. |
必需 |
max_active_bin_slippage
|
int
|
Max slippage in bins. |
5
|
strategy_type
|
int
|
Strategy type (default: SpotBalanced=6). |
STRATEGY_TYPE_SPOT_BALANCED
|
返回:
| 类型 | 描述 |
|---|---|
Instruction
|
Solana instruction. |
build_remove_liquidity_by_range_ix
¶
build_remove_liquidity_by_range_ix(
pool: MeteoraPool,
position: Pubkey,
from_bin_id: int,
to_bin_id: int,
bps_to_remove: int = 10000,
) -> Instruction
Build removeLiquidityByRange instruction.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pool
|
MeteoraPool
|
Pool information. |
必需 |
position
|
Pubkey
|
Position account address. |
必需 |
from_bin_id
|
int
|
Starting bin ID. |
必需 |
to_bin_id
|
int
|
Ending bin ID (inclusive). |
必需 |
bps_to_remove
|
int
|
Basis points of liquidity to remove (10000 = 100%). |
10000
|
返回:
| 类型 | 描述 |
|---|---|
Instruction
|
Solana instruction. |
build_close_position_ix
¶
Build closePosition instruction.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
lb_pair
|
Pubkey
|
Pool address. |
必需 |
position
|
Pubkey
|
Position account address. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Instruction
|
Solana instruction. |
build_open_position_transaction
¶
build_open_position_transaction(
pool: MeteoraPool,
lower_bin_id: int,
upper_bin_id: int,
amount_x: int,
amount_y: int,
slippage_bps: int = 100,
strategy_type: int = STRATEGY_TYPE_SPOT_BALANCED,
) -> tuple[list[Instruction], Keypair, dict[str, Any]]
Build a complete open position transaction.
Creates initializePosition + addLiquidityByStrategy instructions.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pool
|
MeteoraPool
|
Pool information. |
必需 |
lower_bin_id
|
int
|
Lower bin ID. |
必需 |
upper_bin_id
|
int
|
Upper bin ID. |
必需 |
amount_x
|
int
|
Amount of token X in smallest units. |
必需 |
amount_y
|
int
|
Amount of token Y in smallest units. |
必需 |
slippage_bps
|
int
|
Slippage in basis points (default 100 = 1%). |
100
|
strategy_type
|
int
|
Strategy type (default: SpotBalanced). |
STRATEGY_TYPE_SPOT_BALANCED
|
返回:
| 类型 | 描述 |
|---|---|
tuple[list[Instruction], Keypair, dict[str, Any]]
|
Tuple of (instructions, position_keypair, metadata). |
build_close_position_transaction
¶
build_close_position_transaction(
pool: MeteoraPool, position: MeteoraPosition
) -> tuple[list[Instruction], dict[str, Any]]
Build instructions to fully close a position.
removeLiquidityByRange (100%) + closePosition.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pool
|
MeteoraPool
|
Pool information. |
必需 |
position
|
MeteoraPosition
|
Position to close. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
tuple[list[Instruction], dict[str, Any]]
|
Tuple of (instructions, metadata). |