Saltar a contenido

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

MeteoraAdapter(
    config: MeteoraConfig,
    token_resolver: TokenResolver | None = None,
)

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_lp_open_intent(
    intent: LPOpenIntent,
) -> ActionBundle

Compile an LPOpenIntent to an ActionBundle.

Builds Meteora DLMM initializePosition + addLiquidityByStrategy, serializes into a VersionedTransaction, and wraps in an ActionBundle.

Parameters:

Name Type Description Default
intent LPOpenIntent

The LPOpenIntent to compile.

required

Returns:

Type Description
ActionBundle

ActionBundle containing serialized Solana transaction(s).

compile_lp_close_intent

compile_lp_close_intent(
    intent: LPCloseIntent,
) -> ActionBundle

Compile an LPCloseIntent to an ActionBundle.

Removes all liquidity and closes the position.

Parameters:

Name Type Description Default
intent LPCloseIntent

The LPCloseIntent to compile.

required

Returns:

Type Description
ActionBundle

ActionBundle containing serialized Solana transaction(s).

MeteoraConfig

MeteoraConfig(
    wallet_address: str,
    rpc_url: str = "",
    default_strategy_type: int = 6,
)

Configuration for Meteora adapter.

Attributes:

Name Type Description
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

MeteoraAPIError(
    message: str, status_code: int = 0, endpoint: str = ""
)

Bases: MeteoraError

Error communicating with the Meteora DLMM API.

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

MeteoraBin(
    bin_id: int,
    amount_x: int = 0,
    amount_y: int = 0,
    price: float = 0.0,
)

A single bin in a DLMM pool.

Attributes:

Name Type Description
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.

Attributes:

Name Type Description
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

from_api_response(data: dict[str, Any]) -> MeteoraPool

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.

Attributes:

Name Type Description
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

MeteoraReceiptParser(**kwargs: Any)

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.

Parameters:

Name Type Description Default
**kwargs Any

Keyword arguments from receipt_registry (e.g., chain).

{}

parse_receipt

parse_receipt(receipt: dict[str, Any]) -> dict[str, Any]

Parse a receipt for ReceiptParser protocol compatibility.

Parameters:

Name Type Description Default
receipt dict[str, Any]

Solana transaction receipt dict.

required

Returns:

Type Description
dict[str, Any]

Dict with parsed LP data.

extract_position_id

extract_position_id(receipt: dict[str, Any]) -> str | None

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.

Parameters:

Name Type Description Default
receipt dict[str, Any]

Solana transaction receipt dict.

required

Returns:

Type Description
str | None

Position address (Base58), or None if not found.

extract_liquidity

extract_liquidity(
    receipt: dict[str, Any],
) -> dict[str, Any] | None

Extract liquidity data from an LP open/increase receipt.

Uses balance deltas to determine actual deposited amounts.

Parameters:

Name Type Description Default
receipt dict[str, Any]

Solana transaction receipt dict.

required

Returns:

Type Description
dict[str, Any] | None

Dict with amount_x, amount_y, position_address, or None.

extract_lp_close_data

extract_lp_close_data(
    receipt: dict[str, Any],
) -> dict[str, Any] | None

Extract LP close data from a receipt.

Uses balance deltas to determine received token amounts.

Parameters:

Name Type Description Default
receipt dict[str, Any]

Solana transaction receipt dict.

required

Returns:

Type Description
dict[str, Any] | None

Dict with received amounts, or None.

MeteoraSDK

MeteoraSDK(
    wallet_address: str,
    base_url: str = METEORA_API_BASE_URL,
    timeout: int = 30,
)

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

get_pool(pool_address: str) -> MeteoraPool

Fetch pool information from the Meteora DLMM API.

Parameters:

Name Type Description Default
pool_address str

Pool (lb_pair) account address (Base58).

required

Returns:

Type Description
MeteoraPool

MeteoraPool with current pool data.

Raises:

Type Description
MeteoraPoolError

If pool not found.

MeteoraAPIError

If API request fails.

find_pool

find_pool(token_a: str, token_b: str) -> MeteoraPool | None

Find a DLMM pool by token pair.

Searches the Meteora API for pools matching the token pair and returns the one with highest TVL.

Parameters:

Name Type Description Default
token_a str

Token A mint address.

required
token_b str

Token B mint address.

required

Returns:

Type Description
MeteoraPool | None

Best matching MeteoraPool, or None if not found.

get_active_bin

get_active_bin(pool_address: str) -> dict[str, Any]

Get the active bin for a pool.

Parameters:

Name Type Description Default
pool_address str

Pool address.

required

Returns:

Type Description
dict[str, Any]

Dict with bin_id, price, and amounts.

get_position_pda

get_position_pda(
    lb_pair: Pubkey,
    base: Pubkey,
    lower_bin_id: int,
    width: int,
) -> Pubkey

Derive the position PDA.

seeds: [POSITION_SEED, lb_pair, base, lower_bin_id (i32 LE), width (i32 LE)]

get_event_authority_pda

get_event_authority_pda() -> Pubkey

Derive the event authority PDA.

get_oracle_pda

get_oracle_pda(lb_pair: Pubkey) -> Pubkey

Derive the oracle PDA for a pool.

get_position_state

get_position_state(
    position_address: str, rpc_url: str
) -> MeteoraPosition

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)

Parameters:

Name Type Description Default
position_address str

Position account address (Base58).

required
rpc_url str

Solana RPC endpoint URL.

required

Returns:

Type Description
MeteoraPosition

MeteoraPosition with on-chain state.

Raises:

Type Description
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.

Parameters:

Name Type Description Default
lb_pair Pubkey

Pool address.

required
position_kp Keypair

New keypair for the position account.

required
lower_bin_id int

Lower bin ID.

required
width int

Number of bins in the position.

required

Returns:

Type Description
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)

Parameters:

Name Type Description Default
pool MeteoraPool

Pool information.

required
position Pubkey

Position account address.

required
lower_bin_id int

Min bin ID for strategy parameters.

required
upper_bin_id int

Max bin ID for strategy parameters.

required
amount_x int

Amount of token X in smallest units.

required
amount_y int

Amount of token Y in smallest units.

required
active_id int

Current active bin ID.

required
max_active_bin_slippage int

Max slippage in bins.

5
strategy_type int

Strategy type (default: SpotBalanced=6).

STRATEGY_TYPE_SPOT_BALANCED

Returns:

Type Description
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.

Parameters:

Name Type Description Default
pool MeteoraPool

Pool information.

required
position Pubkey

Position account address.

required
from_bin_id int

Starting bin ID.

required
to_bin_id int

Ending bin ID (inclusive).

required
bps_to_remove int

Basis points of liquidity to remove (10000 = 100%).

10000

Returns:

Type Description
Instruction

Solana instruction.

build_close_position_ix

build_close_position_ix(
    lb_pair: Pubkey, position: Pubkey
) -> Instruction

Build closePosition instruction.

Parameters:

Name Type Description Default
lb_pair Pubkey

Pool address.

required
position Pubkey

Position account address.

required

Returns:

Type Description
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.

Parameters:

Name Type Description Default
pool MeteoraPool

Pool information.

required
lower_bin_id int

Lower bin ID.

required
upper_bin_id int

Upper bin ID.

required
amount_x int

Amount of token X in smallest units.

required
amount_y int

Amount of token Y in smallest units.

required
slippage_bps int

Slippage in basis points (default 100 = 1%).

100
strategy_type int

Strategy type (default: SpotBalanced).

STRATEGY_TYPE_SPOT_BALANCED

Returns:

Type Description
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.

Parameters:

Name Type Description Default
pool MeteoraPool

Pool information.

required
position MeteoraPosition

Position to close.

required

Returns:

Type Description
tuple[list[Instruction], dict[str, Any]]

Tuple of (instructions, metadata).