From 24a05ff382bf0b32f8bf31179cc78b4b0e805c954d0315f790c10f0023fea4c6 Mon Sep 17 00:00:00 2001 From: Minimons Date: Sat, 4 Jul 2026 13:35:02 +0200 Subject: [PATCH] X: Move non-conflicting interface classes from API project --- .../com/r35157/libs/codec/Base58Codec.tjava | 5 + .../jupiter/perps/JupiterPerpsPosition.tjava | 27 +++ .../perps/JupiterPerpsPositionDirection.tjava | 9 + .../jupiter/perps/JupiterPerpsService.tjava | 45 +++++ .../r35157/libs/solana/SolanaBlockChain.tjava | 167 ++++++++++++++++++ .../SolanaProgramAccountMemcmpFilter.tjava | 17 ++ .../valuetypes/WellKnownCurrencyTypes.tjava | 52 ++++++ .../libs/valuetypes/basic/MoneyPrice.tjava | 8 + 8 files changed, 330 insertions(+) create mode 100644 src/main/tjava/com/r35157/libs/codec/Base58Codec.tjava create mode 100644 src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPosition.tjava create mode 100644 src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPositionDirection.tjava create mode 100644 src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsService.tjava create mode 100644 src/main/tjava/com/r35157/libs/solana/SolanaBlockChain.tjava create mode 100644 src/main/tjava/com/r35157/libs/solana/SolanaProgramAccountMemcmpFilter.tjava create mode 100644 src/main/tjava/com/r35157/libs/solana/valuetypes/WellKnownCurrencyTypes.tjava create mode 100644 src/main/tjava/com/r35157/libs/valuetypes/basic/MoneyPrice.tjava diff --git a/src/main/tjava/com/r35157/libs/codec/Base58Codec.tjava b/src/main/tjava/com/r35157/libs/codec/Base58Codec.tjava new file mode 100644 index 0000000..e3bc6ab --- /dev/null +++ b/src/main/tjava/com/r35157/libs/codec/Base58Codec.tjava @@ -0,0 +1,5 @@ +package com.r35157.libs.codec; + +public interface Base58Codec { + String encode(byte[] input); +} diff --git a/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPosition.tjava b/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPosition.tjava new file mode 100644 index 0000000..f831c43 --- /dev/null +++ b/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPosition.tjava @@ -0,0 +1,27 @@ +package com.r35157.libs.jupiter.perps; + +import java.math.BigDecimal; + +/** + * Represents a Jupiter Perps position. + * + *

A Jupiter Perps position is represented on-chain by a Solana account owned by + * the Jupiter Perps program. This record contains the public API view of such a + * position.

+ * + * @param positionAccount the Solana account address of the Jupiter Perps position + * @param entryPrice the entry price of the position, denominated in USDC + * @param direction whether the position is long or short + * @param tradedTokenMint the mint address of the token being traded + * @param sizeUsd the size of this position in USD + * @param collateralUsd the amount of USD representing the collateral for this position + */ +public record JupiterPerpsPosition( + ΩJupiterPerpsPositionAccountΩ positionAccount, + ΩUSDCPriceΩ entryPrice, + JupiterPerpsPositionDirection direction, + ΩSPLMintAddressΩ tradedTokenMint, + ΩUSDCAmountΩ sizeUsd, + ΩUSDCAmountΩ collateralUsd +) { +} \ No newline at end of file diff --git a/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPositionDirection.tjava b/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPositionDirection.tjava new file mode 100644 index 0000000..05c4066 --- /dev/null +++ b/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsPositionDirection.tjava @@ -0,0 +1,9 @@ +package com.r35157.libs.jupiter.perps; + +/** + * Direction of a Jupiter Perps position. + */ +public enum JupiterPerpsPositionDirection { + LONG, + SHORT +} \ No newline at end of file diff --git a/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsService.tjava b/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsService.tjava new file mode 100644 index 0000000..c513c2d --- /dev/null +++ b/src/main/tjava/com/r35157/libs/jupiter/perps/JupiterPerpsService.tjava @@ -0,0 +1,45 @@ +package com.r35157.libs.jupiter.perps; + +import java.io.IOException; +import java.util.Set; + +/** + * Service for reading Jupiter Perps data. + * + *

This service is read-only. It does not open, close, modify, or sign transactions + * for Jupiter Perpetual Contracts.

+ * + *

NOTICE: The first supported operation is reading a known Jupiter Perps position account + * and returning its decoded position data.

+ */ +public interface JupiterPerpsService { + /** + * Reads a Jupiter Perps position from a known position account. + * + *

The supplied account must be the Solana account that stores the Jupiter Perps + * position state. It is not the wallet address, token account, custody account, pool + * account, or position request account.

+ * + * @param positionAccount the Solana account address of the Jupiter Perps position + * @return the decoded Jupiter Perps position + * @throws IOException if the position account could not be fetched or decoded + * @throws InterruptedException if the calling thread is interrupted while fetching + * the position account + */ + JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount) + throws IOException, InterruptedException; + + /** + * Finds open Jupiter Perps positions owned by a wallet. + * + *

This method returns decoded Jupiter Perps position objects. It does not return + * raw Solana accounts or account ids.

+ * + * @param owner the wallet address that owns the Jupiter Perps positions + * @return the open Jupiter Perps positions owned by the wallet + * @throws IOException if the position accounts could not be fetched or decoded + * @throws InterruptedException if the calling thread is interrupted while fetching positions + */ + Set getOpenPositions(ΩSolanaWalletIdΩ owner) + throws IOException, InterruptedException; +} \ No newline at end of file diff --git a/src/main/tjava/com/r35157/libs/solana/SolanaBlockChain.tjava b/src/main/tjava/com/r35157/libs/solana/SolanaBlockChain.tjava new file mode 100644 index 0000000..982aea0 --- /dev/null +++ b/src/main/tjava/com/r35157/libs/solana/SolanaBlockChain.tjava @@ -0,0 +1,167 @@ +package com.r35157.libs.solana; + +import com.r35157.libs.solana.valuetypes.SolanaProgramDerivedAddress; +import com.r35157.libs.solana.valuetypes.economic.SolanaSPLTokenProgram; +import com.r35157.libs.valuetypes.basic.MoneyAmount; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Provides read-oriented access to the Solana blockchain. + * + *

This interface exposes the Solana operations needed by higher-level + * integrations. It can fetch native SOL balances, SPL token holdings, NFT-like + * token holding candidates, account information and program derived addresses.

+ * + *

The interface is intentionally generic and does not contain Raydium-specific + * logic. Higher-level integrations are expected to interpret Solana accounts, + * token holdings and derived addresses according to their own domain rules.

+ */ +public interface SolanaBlockChain { + /** + * Fetches the native SOL balance for a Solana address. + * + * @param address the Solana address to inspect + * @return the native SOL balance for the address + * @throws IOException if the balance could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching the balance + */ + ΩSolanaAmountΩ getBalanceInSolana(ΩSolanaAddressΩ address) throws IOException, InterruptedException; + + /** + * Fetches the native SOL balance for a Solana address in lamports. + * + *

Lamports are the smallest unit of native SOL.

+ * + * @param address the Solana address to inspect + * @return the native SOL balance for the address in lamports + * @throws IOException if the balance could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching the balance + */ + ΩlamportsΩ getBalanceInLamport(ΩSolanaAddressΩ address) throws IOException, InterruptedException; + + /** + * Fetches SPL token holdings owned by a Solana address for a specific token program. + * + *

The supplied token program decides which token accounts are inspected. For example, + * callers may query the original SPL Token Program or the Token-2022 Program depending + * on which token accounts they need to discover.

+ * + * @param ownerAddress the Solana owner address whose token holdings should be inspected + * @param splProgramId the SPL token program to query + * @return a map of SPL mint addresses to token holding information + * @throws IOException if the token holdings could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching token holdings + */ + Map<ΩSPLMintAddressΩ, SPLTokenHolding> getSPLTokenHoldings( + ΩSolanaAddressΩ ownerAddress, + SolanaSPLTokenProgram splProgramId + ) throws IOException, InterruptedException; + + /** + * Fetches NFT-like token mint address candidates owned by a Solana address for a specific token program. + * + *

This method identifies token holdings that look like NFTs within the supplied token + * program. A returned address is only a candidate. Higher-level integrations are responsible + * for deciding whether the returned address has domain-specific meaning.

+ * + * // TODO This method currently identifies candidates from the owner's token holdings only. + * // A token with zero decimals and an owner balance of one is not guaranteed to be a real NFT, + * // because the mint's total supply may still be greater than one. A future implementation + * // should verify the mint supply, for example by using Solana getTokenSupply, before treating + * // the result as a confirmed NFT. + * + * @param ownerAddress the Solana owner address whose NFT-like holdings should be inspected + * @param splProgram the SPL token program to query + * @return the NFT-like Solana mint address candidates owned by the address + * @throws IOException if the NFT candidate addresses could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching NFT candidate addresses + */ + Set<ΩSolanaNFTAddressΩ> getSolanaNFTCandidateAddresses( + ΩSolanaAddressΩ ownerAddress, + SolanaSPLTokenProgram splProgram + ) throws IOException, InterruptedException; + + /** + * Finds a Solana program derived address for a program id and a set of seeds. + * + *

The seeds describe the logical inputs used to derive the address. The implementation + * is responsible for converting each seed into the byte representation required by Solana.

+ * + * @param programId the Solana program id used to derive the address + * @param seeds the seeds used when deriving the program address + * @return the derived Solana address together with its bump value + */ + SolanaProgramDerivedAddress findProgramAddress( + ΩSolanaProgramIdΩ programId, + List seeds + ); + + /** + * Fetches account information for a Solana account address. + * + *

If the account does not exist, this method returns {@code null}. If the account exists, + * the returned value contains the account address, the owning Solana program id and the + * account data encoded as Base64.

+ * + * @param accountAddress the Solana account address to inspect + * @return account information, or {@code null} if the account does not exist + * @throws IOException if the account information could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching account information + */ + SolanaAccountInfo getAccountInfo(ΩSolanaAddressΩ accountAddress) + throws IOException, InterruptedException; + + /** + * Encodes a raw 32-byte Solana address into its textual Solana address representation. + * + *

This method is intended for callers that have obtained raw Solana address bytes from + * account data and need the normal string representation used elsewhere in the API.

+ * + * @param addressBytes the raw 32-byte Solana address + * @return the encoded Solana address + * @throws IllegalArgumentException if the supplied byte array is not a valid Solana address length + */ + ΩSolanaAddressΩ encodeSolanaAddress(byte[] addressBytes); + + /** + * Fetches the total supply of an SPL token mint for a specific token program. + * + *

The supplied token program identifies which SPL token program owns the mint, + * for example the original SPL Token Program or the Token-2022 Program.

+ * + * @param mintAddress the SPL mint address whose supply should be fetched + * @param splProgram the SPL token program to query + * @return the SPL token supply for the mint + * @throws IOException if the token supply could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching token supply + */ + SPLTokenSupply getSPLTokenSupply( + ΩSPLMintAddressΩ mintAddress, + SolanaSPLTokenProgram splProgram + ) throws IOException, InterruptedException; + + /** + * Fetches accounts owned by a Solana program using server-side account data filters. + * + *

This method uses Solana's {@code getProgramAccounts} RPC call. The supplied filters + * are sent to the RPC node, so matching is performed server-side instead of fetching all + * accounts owned by the program and filtering them locally.

+ * + *

The initial supported filter type is {@link SolanaProgramAccountMemcmpFilter}, which + * matches bytes at a specific offset in the account data.

+ * + * @param programId the Solana program id that owns the accounts to search + * @param filters the memcmp filters to apply when searching program accounts + * @return the matching program accounts + * @throws IOException if the program accounts could not be fetched or parsed + * @throws InterruptedException if the calling thread is interrupted while fetching program accounts + */ + Set getProgramAccounts( + ΩSolanaProgramIdΩ programId, + Set filters + ) throws IOException, InterruptedException; +} \ No newline at end of file diff --git a/src/main/tjava/com/r35157/libs/solana/SolanaProgramAccountMemcmpFilter.tjava b/src/main/tjava/com/r35157/libs/solana/SolanaProgramAccountMemcmpFilter.tjava new file mode 100644 index 0000000..eb523be --- /dev/null +++ b/src/main/tjava/com/r35157/libs/solana/SolanaProgramAccountMemcmpFilter.tjava @@ -0,0 +1,17 @@ +package com.r35157.libs.solana; + +/** + * Filter used when fetching accounts owned by a Solana program. + * + *

The initial supported filter type is {@code memcmp}, which asks the + * Solana RPC node to only return accounts where the account data at a specific + * byte offset matches a base58 encoded value.

+ * + * @param offset the byte offset in the account data where comparison starts + * @param bytes the base58 encoded bytes to match + */ +public record SolanaProgramAccountMemcmpFilter( + int offset, + String bytes +) { +} \ No newline at end of file diff --git a/src/main/tjava/com/r35157/libs/solana/valuetypes/WellKnownCurrencyTypes.tjava b/src/main/tjava/com/r35157/libs/solana/valuetypes/WellKnownCurrencyTypes.tjava new file mode 100644 index 0000000..7c88278 --- /dev/null +++ b/src/main/tjava/com/r35157/libs/solana/valuetypes/WellKnownCurrencyTypes.tjava @@ -0,0 +1,52 @@ +package com.r35157.libs.solana.valuetypes; + +import com.r35157.libs.valuetypes.basic.CurrencyType; + +import java.util.UUID; + +/** + * Defines well-known currency types used by the Solana integration. + * + *

Each enum value wraps a {@link CurrencyType} with a stable identifier and a + * human-readable currency name. These predefined values are intended for common + * currencies that the Solana-related modules need to reference consistently.

+ */ +public enum WellKnownCurrencyTypes { + /** + * Native Solana currency. + */ + SOLANA(new CurrencyType( + UUID.fromString("019e0116-fce5-792f-a647-fa6da4dffec5"), + "Solana", + "SOL") + ), + + /** + * Syrup USDC token currency. + */ + SYRUPUSDC(new CurrencyType( + UUID.fromString("019e1d51-0600-7956-8231-f3b7058a91c2"), + "SyrupUSDC", + "SyrupUSDC") + ); + + /** + * Creates a well-known currency type entry. + * + * @param currencyType the currency type represented by this enum value + */ + WellKnownCurrencyTypes(CurrencyType currencyType) { + this.currencyType = currencyType; + } + + /** + * Returns the currency type represented by this enum value. + * + * @return the represented currency type + */ + public CurrencyType getCurrencyType() { + return currencyType; + } + + private final CurrencyType currencyType; +} \ No newline at end of file diff --git a/src/main/tjava/com/r35157/libs/valuetypes/basic/MoneyPrice.tjava b/src/main/tjava/com/r35157/libs/valuetypes/basic/MoneyPrice.tjava new file mode 100644 index 0000000..4480d0d --- /dev/null +++ b/src/main/tjava/com/r35157/libs/valuetypes/basic/MoneyPrice.tjava @@ -0,0 +1,8 @@ +package com.r35157.libs.valuetypes.basic; + +import java.math.BigDecimal; + +public record MoneyPrice( + ΩPriceΩ price, + CurrencyType currencyType +) { }