Add support for building and executing Jupiter Perps position decrease transactions #38

Closed
opened 2026-07-24 12:10:26 +02:00 by minimons · 0 comments
Owner

Background

JupiterPerpsService currently supports increasing a position through:

  • buildPositionIncreaseTransaction(...)
  • executePositionIncreaseTransaction(...)

We need the corresponding API and implementation for decreasing an existing Jupiter Perps position.

A decrease is identified by the existing Jupiter Perps position account. Unlike an increase, the request therefore does not need the wallet address, traded asset, or position direction.

Proposed API

Add the following methods to JupiterPerpsService:

@NotNull SolanaUnsignedTransaction buildPositionDecreaseTransaction(
        @NotNull ΩJupiterPerpsPositionAccountΩ positionAccount,
        @NotNull ΩSPLMintAddressΩ receiveTokenMint,
        @NotNull ΩUSDCAmountΩ sizeUsdDelta,
        int maxSlippageBps
) throws IOException, InterruptedException;
@NotNull ΩSolanaTransactionSignatureΩ executePositionDecreaseTransaction(
        @NotNull SolanaSignedTransaction transaction
) throws IOException, InterruptedException;

As with the existing increase flow, transaction signing remains the responsibility of a compatible wallet and is not performed by JupiterPerpsService.

Implementation

Implement the methods in AnchorIdlJupiterPerpsServiceImpl.

Building the transaction should call:

POST https://perps-api.jup.ag/v2/positions/decrease

The protocol request contains:

  • positionPubkey
  • receiveToken
  • sizeUsdDelta
  • maxSlippageBps

The response contains:

  • positionPubkey
  • serializedTxBase64
  • txMetadata

The returned serializedTxBase64, blockhash, and last valid block height should be exposed as a SolanaUnsignedTransaction, following the existing increase implementation.

Executing the signed transaction should use the existing transaction-execution endpoint:

POST https://perps-api.jup.ag/v2/transaction/execute

with the action:

decrease-position

Validation

The implementation should reject:

  • A missing position account
  • An unsupported receive-token mint
  • A position-size delta that is zero or negative
  • A slippage value outside the accepted basis-point range
  • Missing or blank serialized transactions
  • Jupiter responses without the required transaction or metadata fields

Scope

This issue covers partial position decreases only.

Closing an entire position using entirePosition = true, closing all positions, and wallet signing are outside the scope of this issue.

Acceptance criteria

  • JupiterPerpsService exposes both decrease methods.
  • A partial decrease transaction can be constructed as a SolanaUnsignedTransaction.
  • The transaction can be signed by the existing Solana wallet implementation.
  • A signed decrease transaction can be submitted through executePositionDecreaseTransaction(...).
  • The returned Solana transaction signature is exposed as ΩSolanaTransactionSignatureΩ.
  • Existing position-increase functionality continues to work.
  • The project compiles successfully.

References

## Background `JupiterPerpsService` currently supports increasing a position through: * `buildPositionIncreaseTransaction(...)` * `executePositionIncreaseTransaction(...)` We need the corresponding API and implementation for decreasing an existing Jupiter Perps position. A decrease is identified by the existing Jupiter Perps position account. Unlike an increase, the request therefore does not need the wallet address, traded asset, or position direction. ## Proposed API Add the following methods to `JupiterPerpsService`: ```java @NotNull SolanaUnsignedTransaction buildPositionDecreaseTransaction( @NotNull ΩJupiterPerpsPositionAccountΩ positionAccount, @NotNull ΩSPLMintAddressΩ receiveTokenMint, @NotNull ΩUSDCAmountΩ sizeUsdDelta, int maxSlippageBps ) throws IOException, InterruptedException; ``` ```java @NotNull ΩSolanaTransactionSignatureΩ executePositionDecreaseTransaction( @NotNull SolanaSignedTransaction transaction ) throws IOException, InterruptedException; ``` As with the existing increase flow, transaction signing remains the responsibility of a compatible wallet and is not performed by `JupiterPerpsService`. ## Implementation Implement the methods in `AnchorIdlJupiterPerpsServiceImpl`. Building the transaction should call: ```text POST https://perps-api.jup.ag/v2/positions/decrease ``` The protocol request contains: * `positionPubkey` * `receiveToken` * `sizeUsdDelta` * `maxSlippageBps` The response contains: * `positionPubkey` * `serializedTxBase64` * `txMetadata` The returned `serializedTxBase64`, blockhash, and last valid block height should be exposed as a `SolanaUnsignedTransaction`, following the existing increase implementation. Executing the signed transaction should use the existing transaction-execution endpoint: ```text POST https://perps-api.jup.ag/v2/transaction/execute ``` with the action: ```text decrease-position ``` ## Validation The implementation should reject: * A missing position account * An unsupported receive-token mint * A position-size delta that is zero or negative * A slippage value outside the accepted basis-point range * Missing or blank serialized transactions * Jupiter responses without the required transaction or metadata fields ## Scope This issue covers partial position decreases only. Closing an entire position using `entirePosition = true`, closing all positions, and wallet signing are outside the scope of this issue. ## Acceptance criteria * `JupiterPerpsService` exposes both decrease methods. * A partial decrease transaction can be constructed as a `SolanaUnsignedTransaction`. * The transaction can be signed by the existing Solana wallet implementation. * A signed decrease transaction can be submitted through `executePositionDecreaseTransaction(...)`. * The returned Solana transaction signature is exposed as `ΩSolanaTransactionSignatureΩ`. * Existing position-increase functionality continues to work. * The project compiles successfully. ## References * https://github.com/jup-ag/cli/blob/main/src/clients/PerpsClient.ts * https://github.com/jup-ag/cli/blob/main/docs/perps.md
minimons added the enhancement label 2026-07-24 12:10:26 +02:00
minimons self-assigned this 2026-07-24 12:10:26 +02:00
minimons added this to the AssetAZ project 2026-07-24 12:10:26 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: r35157/com_r35157_nenjim-hubd-impl_ref#38