# Jupiter Perps local execution

BLOCK CLI prepares Solana mainnet Jupiter Perps market **requests**. Agents review and sign the exact transaction locally with their own wallet, then submit it through the existing Solana transaction driver. The hosted API never receives private keys.

A confirmed transaction creates a request for Jupiter's keepers. It does **not** mean a position opened, closed, or changed. Keepers may execute, reject, or expire a request. Market request accounts close after both successful execution and rejection, so absence cannot establish success or make a retry safe.

## Supported actions

| Action | Behavior |
| --- | --- |
| `jupiter_perps.build_increase` | Open or increase SOL, ETH, or BTC notional with an exact collateral deposit. `sizeUsdDelta: "0"` deposits collateral into an existing open position. |
| `jupiter_perps.build_increase_with_swap` | Fund an open/increased position or collateral deposit with a different supported input token, signing its exact input and minimum target-collateral output. |
| `jupiter_perps.build_decrease` | Reduce notional, request a full close, or withdraw collateral from an existing open position. |
| `jupiter_perps.build_tpsl` | Create a take-profit or stop-loss request for an exact fixed notional of an existing position. |
| `jupiter_perps.build_limit` | Prepare a same-collateral limit entry for the dedicated partial-signing and keeper co-sign flow; see [limit execution](/guides/jupiter-perps-limit-execution.md). |
| `jupiter_perps.build_cancel_request` | Cancel a supported pending request as its owner and return its escrow/rent to that wallet. |
| `jupiter_perps.request_status` | Verify a program-owned request account, its wallet, market, position and PDA at the requested commitment. |

Longs use the corresponding asset as collateral. Shorts use USDC. Bounded funding swaps can convert SOL, ETH, BTC or USDC into that position collateral. This does not convert an existing position to another collateral type. There are no output swaps, USDT shorts, automatic leverage sizing, referral fees or instant market execution. Limit entries use the separately verified [dedicated co-sign flow](/guides/jupiter-perps-limit-execution.md). Classic SPL Token is supported; Token-2022, delegated or frozen accounts are rejected.

SOL-long deposits wrap the exact requested amount of native SOL. A newly created funding ATA closes after that deposit; an existing ATA is preserved. SOL-long decrease requests receive wrapped SOL into the wallet's canonical ATA, which remains open for later keeper fulfillment. This path does not automatically unwrap the eventual proceeds.

## Exact inputs

The market builders require `walletAddress`, `asset` (`SOL`, `ETH`, `BTC`), `side` (`long`, `short`), `sizeUsdDelta`, `priceLimitUsd`, `requestCounter`, `maxNetworkFeeLamports`, and `maxRentLamports`. Optional `commitment` is `confirmed` or `finalized` (default `confirmed`); optional `priorityFeeMicroLamports` is an integer from 0 through 1,000,000 (default 0), with a fixed 500,000 compute-unit ceiling.

Amounts and counters are canonical decimal strings bounded to u64. USD inputs use **6 decimals**. A `sizeUsdDelta` of `"50000000"` means $50 of position notional. It does not mean 50 tokens or $50 of margin.

`build_increase` additionally requires positive `collateralAmount` in raw collateral-token units: SOL 9 decimals, ETH/BTC 8, USDC 6. Collateral-only deposits require an existing open position. Zero-collateral leverage increases are outside this scope.

`build_increase_with_swap` replaces `collateralAmount` with positive `inputAmount`, `inputToken` (`SOL`, `ETH`, `BTC`, `USDC`) and positive `minimumCollateralOut`. Input amounts use the input token decimals; minimum output uses the position collateral decimals. The two tokens must differ. The builder signs `jupiterMinimumOut` into the request; it is not a USD value or a provider quote. Native SOL inputs are wrapped for the exact deposit. `sizeUsdDelta: "0"` funds an existing position without increasing its notional. The escrow initially holds the input token; the keeper swap and position fulfillment happen later. Preparation does not claim that either happened. Select minimum output from independently reviewed current market information.

`build_decrease` additionally requires nonnegative `collateralUsdDelta` (USD6) and boolean `entirePosition`. Full close uses `entirePosition: true` and both deltas `"0"`. Otherwise, at least one delta must be positive. A zero size and positive collateral delta requests collateral withdrawal. The requested reductions cannot exceed the current position amounts. Use full-close mode rather than a partial request equal to the entire position size.

`priceLimitUsd` is an absolute execution price, not basis points or a quote:

| Request | Bound |
| --- | --- |
| Increase long | Maximum price |
| Increase short | Minimum price |
| Decrease long | Minimum price |
| Decrease short | Maximum price |

Choose limits from independently reviewed intent and current market information. Market/API prices are indicative and do not guarantee fulfillment. Protocol fees, funding and realized PnL remain Jupiter program calculations; the builder does not guarantee final collateral proceeds or leverage.

Allocate a fresh `requestCounter` for each distinct intent. The counter forms part of the request PDA and is serialized without JavaScript-number rounding. Existing request or escrow accounts cause preparation to fail. Do not use a new counter to blindly retry an ambiguous submission: reconcile the original transaction and position first.

## Take profit, stop loss and cancellation

`build_tpsl` requires `walletAddress`, `asset`, `side`, positive `sizeUsdDelta`, `triggerType` (`take_profit` or `stop_loss`), positive `triggerPriceUsd`, `allowUnboundedExecutionPrice: true`, `requestCounter`, `maxNetworkFeeLamports`, and `maxRentLamports`. Amounts and prices use raw USD6 strings. Priority fee and commitment options match the market builders. The size cannot exceed the currently verified position size; it remains fixed if the position later grows. No `entirePosition` option is accepted.

The explicit acknowledgment is required because the trigger threshold is **not a fill-price limit**. TP long / SL short triggers at or above the threshold; TP short / SL long triggers at or below. This builder uses the current program's trigger request path with `priceSlippage: None`, and does not claim a minimum or maximum eventual fill price. There is no market-request timeout attached to a TP/SL request.

`build_cancel_request` requires `walletAddress`, `positionRequest`, `maxNetworkFeeLamports`, and `maxRentLamports`, with optional `priorityFeeMicroLamports` and `commitment`. It validates the exact owner, position, market, request PDA/counter, escrow, and canonical refund address. It refuses executed, intermediate-swapped, referral and unsupported requests. A bounded funding-swap request can be cancelled before an intermediate swap is recorded, refunding the escrow input token rather than assuming a target-collateral amount. The current `closePositionRequest2` instruction returns native SOL escrow and account rent directly to the owner; nonnative collateral returns to the owner's canonical token account, creating that account only within the rent ceiling.

Cancellation preparation simulates exact refunds, closure of request and escrow, and unchanged position bytes. It returns `execution.stage: "unsigned_cancellation"` and `execution.cancelled: false`. The cancellation can still race a keeper, and market requests may be subject to the program's cancellation delay (45 seconds in the observed live configuration). Simulation enforces current program rules. A missing request after submission does not distinguish a cancellation from a keeper execution; retain and inspect the cancellation transaction.

## Verification and signing

Preparation pins the mainnet genesis hash, Jupiter program and pool, custody/mint identities, position/request seeds, and the requested wallet as sole signer. It verifies program ownership, account discriminators and supported layouts, protocol permission flags, classic token ownership and state, balance sufficiency, fee/rent estimates, a fresh blockhash, and the complete locally generated message. It accepts no provider-supplied instructions, extra signers, or lookup tables.

The transaction is simulated unsigned. The builder checks the resulting request's exact owner, market, side, deltas, price, counter, option flags and PDA; exact escrow collateral; receiving/funding account balances; and bounded SOL debit. Simulation errors, blockhash replacements, excessive compute, stale slots and blockhash expiry fail closed. A successful simulation is a snapshot, not a guarantee of future acceptance or fulfillment.

`costs.upfrontRentLamports` includes request and escrow rent, plus any new position or wallet ATA. It includes temporary SOL ATA rent even when that ATA closes in the same transaction. Current rent and network-fee caps are **offchain preparation checks**, not encoded guards. Recheck fees, rent and balances when signing after a delay. Token collateral, notional and execution-price values are encoded in the Jupiter instruction.

The prepared output contains:

- `transactionBase64`: exact unsigned transaction for generic `tx inspect`, `wallet sign`, and `tx submit`.
- `request.positionRequest`, `request.position`, and `request.counter`: retain these for reconciliation.
- `request.priceLimitDirection`, exact size/collateral fields, `costs`, `constraints`, and the verified simulation slot.
- `execution.stage: "unsigned_request"` and `execution.positionExecuted: false`.

Follow the exact-byte approval workflow in [local execution](/guides/local-execution.md). A signature or confirmed transaction alone must never change application state to “position executed.”

## Request reconciliation

Call `jupiter_perps.request_status` with `{ "walletAddress": "...", "positionRequest": "...", "commitment": "confirmed" }`.

| `status` | Meaning |
| --- | --- |
| `unknown` | Account is absent or closed. `executed` is `null`; execution, rejection, cancellation, expiry, and never-created requests cannot be distinguished. |
| `pending_or_unresolved` | A verified request account exists with `executed: false`. Presence alone cannot prove keeper acceptance or distinguish waiting from expiry. |
| `executed` | A verified program-owned account carries `executed: true` at the selected commitment. This is not a recomputed trade receipt, PnL, or finality guarantee. |

Funding-swap requests additionally expose `swap.minimumCollateralOut`, `swap.currentEscrowMint`, `swap.positionCollateralMint` and `swap.intermediateSwapRecorded`. These are request-account observations; `collateralSwapCompletionVerified` remains false. A partially progressed swap requires reconciliation before cancellation or another funding attempt.

Every result returns `retrySafe: false`. Use transaction history, verified position state and provider order history to resolve missing requests before resubmitting. `positions` remains a separately labelled provider-reported API read; it does not acquire independent onchain verification from the new builders.

## Implementation references and evidence

The official [Jupiter account documentation](https://developers.jup.ag/docs/perps/position-request-account) describes keeper requests and account closure behavior. The official [Perps developer index](https://developers.jup.ag/docs/perps) links the [reference IDL and examples](https://github.com/julianfssen/jupiter-perps-anchor-idl-parsing). Current layouts and instruction behavior were verified against mainnet accounts and unsigned simulations, not assumed from historical documentation.

The official [Jupiter CLI client](https://github.com/jup-ag/cli/blob/main/src/clients/PerpsClient.ts) uses API v2. Its live instant transactions can require the wallet plus two keeper signatures. This implementation uses the documented local wallet-only request instructions instead:

- `createIncreasePositionMarketRequest` for increases and collateral deposits.
- `createDecreasePositionRequest2` for full closes and partial notional reductions; current oracle validation uses custody `dovesAgOracle`.
- `createDecreasePositionMarketRequest` for zero-size collateral-only withdrawals. Live `request2` rejects this mode, so the dedicated market instruction is necessary.
- `createDecreasePositionRequest2` with trigger request type, fixed size and explicit threshold for TP/SL.
- `closePositionRequest2` for owner cancellation. The earlier `closePositionRequest` discriminator is no longer accepted by the observed mainnet program.

`jupiter-perps-live-v0.11.0.json` (evidence record in the source checkout) records successful unsigned mainnet preparation and simulation for open/increase, short and long full-close, partial reduction, collateral deposit and collateral withdrawal. No funded wallet was signed or submitted during verification. Automated tests additionally cover all six market/side combinations, malformed accounts, input bounds, simulation mutation, status ambiguity, and actual builder output through local fixture signing and mock submission.

`jupiter-perps-controls-live-v0.12.0.json` (evidence record in the source checkout) adds unsigned TP/SL creation, direct cancellation of an existing USDC request, and one unsigned native SOL trigger-create-plus-cancel simulation. Tests also run actual TP and native/nonnative cancellation bytes through fixture-only local signing and mock submission. These are preparation and simulation proofs, not real keeper fills or executed cancellations.

Limit entries use `instantCreateLimitOrder` with owner, keeper and API-keeper signatures. The dedicated [limit-entry validator and local execution flow](/guides/jupiter-perps-limit-execution.md) verifies every instruction, canonical oracle account and signed payload, then adds the owner signature locally. Its explicit submission calls the official co-sign-and-broadcast endpoint. `jupiter-perps-limit-live-v0.12.0.json` (evidence record in the source checkout) covers unsigned native SOL long and USDC short requests; fixture tests cover partial signing and mock co-sign submission. The generic sole-signer path continues to reject these artifacts.


`jupiter-perps-swap-funding-live-v0.12.0.json` (evidence record in the source checkout) records real unsigned mainnet simulations for USDC input into a SOL-long request and native SOL input into a USDC-collateral short request. Tests exercise all 18 supported different-input market/side combinations, signed minimum-out bytes, exact escrow funding, local signing/mock submission, and both native and token refunds. These checks verify the request path, not future keeper routing or fills.
