13: Decode Jupiter Perps position - entry price only

This commit is contained in:
2026-06-25 10:50:43 +02:00
parent c130d6c7d4
commit 9376208591
@@ -3,14 +3,55 @@ package com.r35157.libs.jupiter.perps.impl.anchoridl;
import com.r35157.libs.jupiter.perps.JupiterPerpsPosition; import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
import com.r35157.libs.solana.SolanaAccountInfo; import com.r35157.libs.solana.SolanaAccountInfo;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Base64;
class AnchorIdlJupiterPerpsPositionDecoder { class AnchorIdlJupiterPerpsPositionDecoder {
JupiterPerpsPosition decode( JupiterPerpsPosition decode(
ΩJupiterPerpsPositionAccountΩ positionAccount, ΩJupiterPerpsPositionAccountΩ positionAccount,
SolanaAccountInfo accountInfo SolanaAccountInfo accountInfo
) { ) {
throw new UnsupportedOperationException( byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
"Jupiter Perps position decoding is not implemented yet."
if (data.length < PRICE_OFFSET + U64_LENGTH) {
throw new IllegalArgumentException(
"Jupiter Perps position account data is too short: " + data.length
); );
} }
long rawEntryPrice = ByteBuffer
.wrap(data, PRICE_OFFSET, U64_LENGTH)
.order(ByteOrder.LITTLE_ENDIAN)
.getLong();
ΩUSDCPriceΩ entryPrice = BigDecimal
.valueOf(rawEntryPrice)
.movePointLeft(6);
JupiterPerpsPosition pos = new JupiterPerpsPosition(
positionAccount,
entryPrice
);
return pos;
}
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 U64_LENGTH = 8;
private static final int SIDE_ENUM_LENGTH = 1;
private static final int PRICE_OFFSET =
ANCHOR_DISCRIMINATOR_LENGTH
+ PUBLIC_KEY_LENGTH // owner
+ PUBLIC_KEY_LENGTH // pool
+ PUBLIC_KEY_LENGTH // custody
+ PUBLIC_KEY_LENGTH // collateralCustody
+ I64_LENGTH // openTime
+ I64_LENGTH // updateTime
+ SIDE_ENUM_LENGTH; // side
} }