49: Add high-level Jupiter position increase operation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.r35157.libs.jupiter.perps;
|
||||
|
||||
import com.r35157.cryptowallet.solana.SolanaWallet;
|
||||
import com.r35157.libs.solana.SolanaSignedTransaction;
|
||||
import com.r35157.libs.solana.SolanaUnsignedTransaction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -47,6 +48,33 @@ public interface JupiterPerpsService {
|
||||
@NotNull Set<JupiterPerpsPosition> getOpenPositions(@NotNull ΩSolanaWalletIdΩ owner)
|
||||
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
|
||||
* a Jupiter Perps position.
|
||||
@@ -152,4 +180,4 @@ public interface JupiterPerpsService {
|
||||
ΩSolanaTransactionSignatureΩ executePositionDecreaseTransaction(
|
||||
@NotNull SolanaSignedTransaction transaction
|
||||
) throws IOException, InterruptedException;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-1
@@ -1,6 +1,7 @@
|
||||
package com.r35157.libs.jupiter.perps.impl.anchoridl;
|
||||
|
||||
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.JupiterPerpsPositionDirection;
|
||||
import com.r35157.libs.jupiter.perps.JupiterPerpsService;
|
||||
@@ -113,6 +114,31 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
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
|
||||
public @NotNull SolanaUnsignedTransaction buildPositionIncreaseTransaction(
|
||||
@NotNull ΩSolanaWalletIdΩ owner,
|
||||
@@ -764,4 +790,4 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
private final SolanaBlockChain solanaBlockChain;
|
||||
private final AnchorIdlJupiterPerpsPositionDecoder positionDecoder;
|
||||
private final AnchorIdlJupiterPerpsCustodyDecoder custodyDecoder;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user