16: Add 'side' to AnchorIdlJupiterPerpsPositionDecoder
This commit is contained in:
+26
-3
@@ -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)
|
||||
@@ -33,25 +37,44 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
||||
|
||||
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
||||
positionAccount,
|
||||
entryPrice
|
||||
entryPrice,
|
||||
direction
|
||||
);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
private JupiterPerpsPositionDirection decodeDirection(
|
||||
byte rawSide
|
||||
) {
|
||||
// Jupiter Perps position side values are encoded as 1 = LONG, 2 = SHORT.
|
||||
JupiterPerpsPositionDirection direction = switch (rawSide) {
|
||||
case 1 -> JupiterPerpsPositionDirection.LONG;
|
||||
case 2 -> JupiterPerpsPositionDirection.SHORT;
|
||||
default -> throw new IllegalArgumentException(
|
||||
"Unknown Jupiter Perps position side: " + rawSide
|
||||
);
|
||||
};
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user