49: Add high-level Jupiter position increase operation

This commit is contained in:
2026-08-05 10:12:39 +02:00
parent 40ac60acd1
commit bfda6f01b7
2 changed files with 56 additions and 2 deletions
@@ -1,5 +1,6 @@
package com.r35157.libs.jupiter.perps; package com.r35157.libs.jupiter.perps;
import com.r35157.cryptowallet.solana.SolanaWallet;
import com.r35157.libs.solana.SolanaSignedTransaction; import com.r35157.libs.solana.SolanaSignedTransaction;
import com.r35157.libs.solana.SolanaUnsignedTransaction; import com.r35157.libs.solana.SolanaUnsignedTransaction;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -47,6 +48,33 @@ public interface JupiterPerpsService {
@NotNull Set<JupiterPerpsPosition> getOpenPositions(@NotNull ΩSolanaWalletIdΩ owner) @NotNull Set<JupiterPerpsPosition> getOpenPositions(@NotNull ΩSolanaWalletIdΩ owner)
throws IOException, InterruptedException; throws IOException, InterruptedException;
/**
* Opens or increases a Jupiter Perps position.
*
* <p>The service constructs the transaction, asks the supplied wallet to
* sign it, and submits it to Jupiter.</p>
*
* @param wallet the wallet that owns or will own the position
* @param tradedTokenMint the mint address of the asset being traded
* @param direction whether the position is long or short
* @param inputTokenAmount the amount of USDC to supply as collateral
* @param sizeUsdDelta the requested increase in position size, denominated in USD
* @param maxSlippageBps the maximum accepted slippage, in basis points
* @return the Solana transaction signature
* @throws IllegalArgumentException if an amount, mint, or slippage value is invalid
* @throws IOException if the transaction cannot be constructed, signed, or submitted
* @throws InterruptedException if the calling thread is interrupted
*/
@NotNull
ΩSolanaTransactionSignatureΩ executePositionIncrease(
@NotNull SolanaWallet wallet,
@NotNull ΩSPLMintAddressΩ tradedTokenMint,
@NotNull JupiterPerpsPositionDirection direction,
@NotNull ΩUSDCAmountΩ inputTokenAmount,
@NotNull ΩUSDCAmountΩ sizeUsdDelta,
int maxSlippageBps
) throws IOException, InterruptedException;
/** /**
* Constructs an unsigned Solana transaction for opening or increasing * Constructs an unsigned Solana transaction for opening or increasing
* a Jupiter Perps position. * a Jupiter Perps position.
@@ -152,4 +180,4 @@ public interface JupiterPerpsService {
ΩSolanaTransactionSignatureΩ executePositionDecreaseTransaction( ΩSolanaTransactionSignatureΩ executePositionDecreaseTransaction(
@NotNull SolanaSignedTransaction transaction @NotNull SolanaSignedTransaction transaction
) throws IOException, InterruptedException; ) throws IOException, InterruptedException;
} }
@@ -1,6 +1,7 @@
package com.r35157.libs.jupiter.perps.impl.anchoridl; package com.r35157.libs.jupiter.perps.impl.anchoridl;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.r35157.cryptowallet.solana.SolanaWallet;
import com.r35157.libs.jupiter.perps.JupiterPerpsPosition; import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection; import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection;
import com.r35157.libs.jupiter.perps.JupiterPerpsService; import com.r35157.libs.jupiter.perps.JupiterPerpsService;
@@ -113,6 +114,31 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
return Set.copyOf(positions); return Set.copyOf(positions);
} }
@Override
public @NotNull ΩSolanaTransactionSignatureΩ executePositionIncrease(
@NotNull SolanaWallet wallet,
@NotNull ΩSPLMintAddressΩ tradedTokenMint,
@NotNull JupiterPerpsPositionDirection direction,
@NotNull ΩUSDCAmountΩ inputTokenAmount,
@NotNull ΩUSDCAmountΩ sizeUsdDelta,
int maxSlippageBps
) throws IOException, InterruptedException {
SolanaUnsignedTransaction unsignedTransaction =
buildPositionIncreaseTransaction(
wallet.getAddress(),
tradedTokenMint,
direction,
inputTokenAmount,
sizeUsdDelta,
maxSlippageBps
);
SolanaSignedTransaction signedTransaction =
wallet.signTransaction(unsignedTransaction);
return executePositionIncreaseTransaction(signedTransaction);
}
@Override @Override
public @NotNull SolanaUnsignedTransaction buildPositionIncreaseTransaction( public @NotNull SolanaUnsignedTransaction buildPositionIncreaseTransaction(
@NotNull ΩSolanaWalletIdΩ owner, @NotNull ΩSolanaWalletIdΩ owner,
@@ -764,4 +790,4 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
private final SolanaBlockChain solanaBlockChain; private final SolanaBlockChain solanaBlockChain;
private final AnchorIdlJupiterPerpsPositionDecoder positionDecoder; private final AnchorIdlJupiterPerpsPositionDecoder positionDecoder;
private final AnchorIdlJupiterPerpsCustodyDecoder custodyDecoder; private final AnchorIdlJupiterPerpsCustodyDecoder custodyDecoder;
} }