Compare commits
3 Commits
0.1-dev
...
41fdf09b7b
| Author | SHA256 | Date | |
|---|---|---|---|
| 41fdf09b7b | |||
| ae5172802e | |||
| 646fbe7947 |
+39
-1
@@ -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,11 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
||||
.valueOf(rawSizeUsd)
|
||||
.movePointLeft(6);
|
||||
|
||||
BigInteger cumulativeInterestSnapshot = readU128(
|
||||
data,
|
||||
CUMULATIVE_INTEREST_SNAPSHOT_OFFSET
|
||||
);
|
||||
|
||||
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
||||
positionAccount,
|
||||
entryPrice,
|
||||
@@ -68,6 +74,22 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
||||
return pos;
|
||||
}
|
||||
|
||||
BigInteger decodeCumulativeInterestSnapshot(SolanaAccountInfo accountInfo) {
|
||||
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||
|
||||
if (data.length < CUMULATIVE_INTEREST_SNAPSHOT_OFFSET + U128_LENGTH) {
|
||||
throw new IllegalArgumentException(
|
||||
"Jupiter Perps position account data is too short: " + data.length
|
||||
);
|
||||
}
|
||||
|
||||
BigInteger value = readU128(
|
||||
data,
|
||||
CUMULATIVE_INTEREST_SNAPSHOT_OFFSET
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
ΩSolanaAddressΩ decodeCustodyAccount(SolanaAccountInfo accountInfo) {
|
||||
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||
|
||||
@@ -115,11 +137,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 +167,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();
|
||||
}
|
||||
Reference in New Issue
Block a user