16: Add 'side' to AnchorIdlJupiterPerpsPositionDecoder

This commit is contained in:
2026-06-26 18:25:29 +02:00
parent ee969dc831
commit 332095ad92
@@ -1,6 +1,7 @@
package com.r35157.libs.jupiter.perps.impl.anchoridl;
import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection;
import com.r35157.libs.solana.SolanaAccountInfo;
import java.math.BigDecimal;
@@ -22,6 +23,9 @@ class AnchorIdlJupiterPerpsPositionDecoder {
);
}
JupiterPerpsPositionDirection direction =
decodeDirection(data[SIDE_OFFSET]);
long rawEntryPrice = ByteBuffer
.wrap(data, PRICE_OFFSET, U64_LENGTH)
.order(ByteOrder.LITTLE_ENDIAN)
@@ -40,19 +44,34 @@ class AnchorIdlJupiterPerpsPositionDecoder {
return pos;
}
private JupiterPerpsPositionDirection decodeDirection(
byte rawSide
) {
return switch (rawSide) {
case 0 -> JupiterPerpsPositionDirection.LONG;
case 1 -> JupiterPerpsPositionDirection.SHORT;
default -> throw new IllegalArgumentException(
"Unknown Jupiter Perps position side: " + rawSide
);
};
}
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 =
private static final int SIDE_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
+ I64_LENGTH; // updateTime
private static final int PRICE_OFFSET =
SIDE_OFFSET
+ SIDE_ENUM_LENGTH; // side
}