22: Implement AnchorIdlJupiterPerpsCustodyDecoder.decodeCurrentCumulativeInterestRate() method
This commit is contained in:
+32
-2
@@ -23,8 +23,21 @@ class AnchorIdlJupiterPerpsCustodyDecoder {
|
||||
return readPublicKey(data, MINT_OFFSET);
|
||||
}
|
||||
|
||||
BigInteger decodeCurrentCumulativeInterestRate(SolanaAccountInfo custodyAccountInfo) {
|
||||
return null;
|
||||
BigInteger decodeCurrentCumulativeInterestRate(
|
||||
SolanaAccountInfo custodyAccountInfo
|
||||
) {
|
||||
byte[] data = Base64.getDecoder().decode(custodyAccountInfo.dataBase64());
|
||||
|
||||
if (data.length < CUMULATIVE_INTEREST_RATE_OFFSET + U128_LENGTH) {
|
||||
throw new IllegalArgumentException(
|
||||
"Jupiter Perps custody account data is too short: " + data.length
|
||||
);
|
||||
}
|
||||
|
||||
return readU128(
|
||||
data,
|
||||
CUMULATIVE_INTEREST_RATE_OFFSET
|
||||
);
|
||||
}
|
||||
|
||||
private ΩSPLMintAddressΩ readPublicKey(
|
||||
@@ -44,6 +57,23 @@ class AnchorIdlJupiterPerpsCustodyDecoder {
|
||||
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 U128_LENGTH = 16;
|
||||
private static final int ANCHOR_DISCRIMINATOR_LENGTH = 8;
|
||||
private static final int PUBLIC_KEY_LENGTH = 32;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user