From 9bb9bc6d03310cdcd4e260a46bd2483ec51878f5fb707f09b28a5eaae9831f59 Mon Sep 17 00:00:00 2001 From: Minimons Date: Tue, 30 Jun 2026 17:08:03 +0200 Subject: [PATCH] 22: Implement AnchorIdlJupiterPerpsCustodyDecoder.decodeCurrentCumulativeInterestRate() method --- .../AnchorIdlJupiterPerpsCustodyDecoder.tjava | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsCustodyDecoder.tjava b/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsCustodyDecoder.tjava index 6fb6240..7829bf3 100644 --- a/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsCustodyDecoder.tjava +++ b/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsCustodyDecoder.tjava @@ -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;