16: Add 'side' to AnchorIdlJupiterPerpsPositionDecoder
This commit is contained in:
+23
-3
@@ -1,6 +1,7 @@
|
|||||||
package com.r35157.libs.jupiter.perps.impl.anchoridl;
|
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.jupiter.perps.JupiterPerpsPositionDirection;
|
||||||
import com.r35157.libs.solana.SolanaAccountInfo;
|
import com.r35157.libs.solana.SolanaAccountInfo;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -22,6 +23,9 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JupiterPerpsPositionDirection direction =
|
||||||
|
decodeDirection(data[SIDE_OFFSET]);
|
||||||
|
|
||||||
long rawEntryPrice = ByteBuffer
|
long rawEntryPrice = ByteBuffer
|
||||||
.wrap(data, PRICE_OFFSET, U64_LENGTH)
|
.wrap(data, PRICE_OFFSET, U64_LENGTH)
|
||||||
.order(ByteOrder.LITTLE_ENDIAN)
|
.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
@@ -33,25 +37,41 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
|
|
||||||
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
||||||
positionAccount,
|
positionAccount,
|
||||||
entryPrice
|
entryPrice,
|
||||||
|
direction
|
||||||
);
|
);
|
||||||
|
|
||||||
return pos;
|
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 ANCHOR_DISCRIMINATOR_LENGTH = 8;
|
||||||
private static final int PUBLIC_KEY_LENGTH = 32;
|
private static final int PUBLIC_KEY_LENGTH = 32;
|
||||||
private static final int I64_LENGTH = 8;
|
private static final int I64_LENGTH = 8;
|
||||||
private static final int U64_LENGTH = 8;
|
private static final int U64_LENGTH = 8;
|
||||||
private static final int SIDE_ENUM_LENGTH = 1;
|
private static final int SIDE_ENUM_LENGTH = 1;
|
||||||
|
|
||||||
private static final int PRICE_OFFSET =
|
private static final int SIDE_OFFSET =
|
||||||
ANCHOR_DISCRIMINATOR_LENGTH
|
ANCHOR_DISCRIMINATOR_LENGTH
|
||||||
+ PUBLIC_KEY_LENGTH // owner
|
+ PUBLIC_KEY_LENGTH // owner
|
||||||
+ PUBLIC_KEY_LENGTH // pool
|
+ PUBLIC_KEY_LENGTH // pool
|
||||||
+ PUBLIC_KEY_LENGTH // custody
|
+ PUBLIC_KEY_LENGTH // custody
|
||||||
+ PUBLIC_KEY_LENGTH // collateralCustody
|
+ PUBLIC_KEY_LENGTH // collateralCustody
|
||||||
+ I64_LENGTH // openTime
|
+ I64_LENGTH // openTime
|
||||||
+ I64_LENGTH // updateTime
|
+ I64_LENGTH; // updateTime
|
||||||
|
|
||||||
|
private static final int PRICE_OFFSET =
|
||||||
|
SIDE_OFFSET
|
||||||
+ SIDE_ENUM_LENGTH; // side
|
+ SIDE_ENUM_LENGTH; // side
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user