diff --git a/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionServiceImpl.tjava b/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionServiceImpl.tjava index 71da1a4..259d9e7 100644 --- a/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionServiceImpl.tjava +++ b/src/main/tjava/com/r35157/libs/jupiter/perps/impl/anchoridl/AnchorIdlJupiterPerpsPositionServiceImpl.tjava @@ -41,26 +41,36 @@ public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPos @Override public Set getOpenPositions(ΩSolanaWalletIdΩ owner) throws IOException, InterruptedException { - Set accountInfos = solanaBlockChain.getProgramAccounts( - JUPITER_PERPS_PROGRAM_ID, - Set.of(new SolanaProgramAccountMemcmpFilter( - POSITION_OWNER_OFFSET, - owner - )) + Set accountInfos = solanaBlockChain.getProgramAccounts( + JUPITER_PERPS_PROGRAM_ID, + Set.of(new SolanaProgramAccountMemcmpFilter( + POSITION_OWNER_OFFSET, + owner + )) ); - Set positions = new HashSet<>(); + Set positions = new HashSet<>(); - for (SolanaAccountInfo accountInfo : accountInfos) { - JupiterPerpsPosition position = positionDecoder.decode( - accountInfo.address(), - accountInfo - ); - positions.add(position); + for (SolanaAccountInfo accountInfo : accountInfos) { + ΩSolanaAddressΩ address = accountInfo.address(); + ΩSolanaProgramIdΩ programId = accountInfo.owner(); + + if (!JUPITER_PERPS_PROGRAM_ID.equals(programId)) { + String errorMsg = "Account '" + address + "' is not owned by Jupiter Perps program '" + + programId + "'"; + throw new IllegalArgumentException(errorMsg); + } + + JupiterPerpsPosition position = positionDecoder.decode( + address, + accountInfo + ); + positions.add(position); + } + + return Set.copyOf(positions); } - return Set.copyOf(positions); -} private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID = "PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu"; private static final int POSITION_OWNER_OFFSET = 8;