From d2cce123b953da3040e3a4e27f0ad6545a1b3e361d71c095f398a880bcfc1caa Mon Sep 17 00:00:00 2001 From: Minimons Date: Tue, 30 Jun 2026 11:45:55 +0200 Subject: [PATCH] 22: Decode cumulativeInterestSnapshot from Position account --- ...AnchorIdlJupiterPerpsPositionDecoder.tjava | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionDecoder.tjava b/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionDecoder.tjava index b4a52b5..89313c5 100644 --- a/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionDecoder.tjava +++ b/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionDecoder.tjava @@ -7,6 +7,7 @@ import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection; import com.r35157.libs.solana.SolanaAccountInfo; import java.math.BigDecimal; +import java.math.BigInteger; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Base64; @@ -56,6 +57,13 @@ class AnchorIdlJupiterPerpsPositionDecoder { .valueOf(rawSizeUsd) .movePointLeft(6); + BigInteger cumulativeInterestSnapshot = readU128( + data, + CUMULATIVE_INTEREST_SNAPSHOT_OFFSET + ); + + System.out.println("cumulativeInterestSnapshot = " + cumulativeInterestSnapshot); + JupiterPerpsPosition pos = new JupiterPerpsPosition( positionAccount, entryPrice, @@ -115,11 +123,25 @@ class AnchorIdlJupiterPerpsPositionDecoder { return base58.encode(publicKeyBytes); } + private static BigInteger readU128( + byte[] data, + int offset + ) { + byte[] bytes = new byte[U128_LENGTH]; + + for (int i = 0; i < U128_LENGTH; i++) { + bytes[i] = data[offset + U128_LENGTH - 1 - i]; + } + + return new BigInteger(1, bytes); + } + private static final int ANCHOR_DISCRIMINATOR_LENGTH = 8; private static final int PUBLIC_KEY_LENGTH = 32; - private static final int I64_LENGTH = 8; private static final int SIDE_ENUM_LENGTH = 1; + private static final int I64_LENGTH = 8; private static final int U64_LENGTH = 8; + private static final int U128_LENGTH = 16; private static final int OWNER_OFFSET = ANCHOR_DISCRIMINATOR_LENGTH; private static final int POOL_OFFSET = OWNER_OFFSET + PUBLIC_KEY_LENGTH; @@ -131,6 +153,8 @@ class AnchorIdlJupiterPerpsPositionDecoder { private static final int PRICE_OFFSET = SIDE_OFFSET + SIDE_ENUM_LENGTH; private static final int SIZE_USD_OFFSET = PRICE_OFFSET + U64_LENGTH; private static final int COLLATERAL_USD_OFFSET = SIZE_USD_OFFSET + U64_LENGTH; + private static final int REALISED_PNL_USD_OFFSET = COLLATERAL_USD_OFFSET + U64_LENGTH; + private static final int CUMULATIVE_INTEREST_SNAPSHOT_OFFSET = REALISED_PNL_USD_OFFSET + I64_LENGTH; private static final Base58Codec base58 = new Base58CodecImpl(); } \ No newline at end of file