# Meteora positions and liquidity

BLOCK CLI prepares direct deposits and withdrawals for existing agent-owned DLMM positions. The official SDK's `rebalanceLiquidity` instruction encodes deposit maxima, withdrawal minima, and a zero active-bin movement allowance. The gateway verifies the simulated position shares and wallet balances before returning unsigned V0 bytes. The agent then reviews, signs and submits locally.

`meteora.positions` takes `owner`, optional `pool`, and optional `commitment` (`confirmed` by default). It filters program-owned PositionV2 headers on-chain and returns at most 100 addresses with their owner and pool. Large result sets fail explicitly; narrow by pool. `meteora.position` takes `position`, optional expected `wallet` and `pool`, and optional `commitment`. It verifies the account and returns its bin range, raw shares per bin, lock, operator and recorded pending fees. Recorded pending fees omit subsequent accrual; this read does not promise an executable token withdrawal amount.

## Preparation inputs

Both `meteora.build_add_liquidity` and `meteora.build_remove_liquidity` take:

| Field | Meaning |
| --- | --- |
| `protocol` | `"dlmm"`; default |
| `pool`, `position`, `wallet` | Exact pool, existing position and its ordinary owner wallet |
| `tokenXMint`, `tokenYMint` | Exact mints in the pool's X/Y ordering |
| `fromBinId`, `toBinId` | Inclusive range inside the existing position, at most 70 bins |
| `maxNetworkFeeLamports` | Positive raw integer string limiting the network fee quote |
| `maxRentLamports` | Nonnegative raw integer string limiting account-creation rent |
| `priorityFeeMicroLamports` | Integer 0–1,000,000; default 0 |
| `commitment` | `"confirmed"` or `"finalized"` |

Deposits additionally take `maxAmountX` and `maxAmountY`, nonnegative raw token integer strings with at least one positive value. The supported `strategy` is `"spot"`. `favorXInActiveBin` defaults to `true`; it determines the token allocated to the active bin. The SDK allocates within the supplied token budgets and may round down or leave an irrelevant side unused. The response identifies the calculated `quote.depositX` and `quote.depositY`. These are deposit caps, not a promise that every raw unit will be used.

Withdrawals additionally take `bps` from 1 to 10,000, and `minAmountX` and `minAmountY` as raw nonnegative integer strings with at least one positive minimum. The selected fraction of each bin's position shares is removed. The current calculated token amounts must cover the minima, and the minima are enforced by the on-chain instruction. Fees and rewards are not claimed.

Native SOL uses `So11111111111111111111111111111111111111112` and lamports. It is wrapped into a separate temporary account, which closes back to the wallet within the transaction. Existing WSOL ATAs are preserved. Other inputs require sufficient balances in the owner's canonical ATAs; missing output ATAs can be created within the explicit rent budget.

## Execution

```sh
block-cli call meteora positions --file work/position-search.json
block-cli call meteora position --file work/position-read.json
block-cli call meteora build_add_liquidity --file work/liquidity-add.json > work/prepared.json
block-cli tx inspect --chain solana --file work/prepared.json --out work/review.json
```

Use `build_remove_liquidity` with withdrawal inputs for removal. After the agent's policy approves the exact message and limits:

```sh
block-cli wallet sign --file work/wallet.enc.json \
  --review work/review.json --approve "$APPROVED_DIGEST" \
  --max-fee 100000 --out work/signed.json
block-cli tx submit --file work/signed.json
block-cli tx status --file work/signed.json
```

The API takes no wallet secrets and produces no signatures. The wallet remains the only signer and rent payer. The response includes the encoded constraints, raw quote amounts, fees/rent, unsigned transaction metadata, simulation evidence, and verified simulated token deltas. Positive deltas are wallet credits; negative deltas are debits.

## Boundaries

Supported positions use the base 8,120-byte PositionV2 account, at most 70 bins, already initialized bin arrays, and an enabled canonical permissionless or customizable DLMM pool with classic SPL tokens. Positions must belong to the supplied wallet. Operators, external fee owners, permissionless-operation flags, active locks and unknown versions are rejected.

The builder does not create, resize or close positions; create bin arrays; claim fees/rewards; trade DAMM v2 pools; or support Token-2022. Deposit share growth and exact withdrawal share reduction are checked in simulation. Shares outside the selected range, position authority and position range must remain unchanged.

Pool state, quotes, rent and fee estimates are snapshots. The active bin must remain unchanged for the prepared instruction to execute; otherwise rebuild. Deposit caps and withdrawal minima are on-chain limits. Network/rent ceilings are preparation checks. A successful simulation does not establish a confirmed liquidity change.

## Verification

On October 20, 2026 UTC, both operations simulated successfully against a public existing SOL/USDC position:

- Withdrawal: slot `459322398`, 28,615 compute units, 939-byte V0.
- Deposit: slot `459322400`, 34,024 compute units, 992-byte V0.

Both used one signer, a 5,000-lamport quoted network fee, and an isolated temporary WSOL account. The check used public owner addresses only and did not load keys, sign or broadcast. Exact inputs and sanitized results are in `meteora-liquidity-live-v0.12.0.json`. The tiny withdrawal minimum in that historical fixture was chosen for an unsigned encoding test; agents must set their own economic limits from a current position and policy.

Focused tests verify official instruction encoding, position identity/ranges, unsupported account modes, share changes, token and SOL bounds, rent, simulation errors and expiry. A real builder result also passes local inspection, digest-approved signing with an unfunded deterministic fixture key and exact-byte mock submission.

Primary references: [Meteora's official DLMM SDK](https://github.com/MeteoraAg/dlmm-sdk), [SDK rebalance implementation](https://github.com/MeteoraAg/dlmm-sdk/tree/main/ts-client/src/dlmm), and the pinned `@meteora-ag/dlmm` 1.9.14 IDL.
