Compare commits
5 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| ba9a167a57 | |||
| 0c2f00f791 | |||
| 8f0f4061ee | |||
| 3f47f9a895 | |||
| a52dbec41a |
@@ -1,6 +1,7 @@
|
||||
package com.r35157.libs.jupiter.perps;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service for reading Jupiter Perps positions.
|
||||
@@ -27,4 +28,18 @@ public interface JupiterPerpsPositionService {
|
||||
*/
|
||||
JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount)
|
||||
throws IOException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Finds open Jupiter Perps positions owned by a wallet.
|
||||
*
|
||||
* <p>This method returns decoded Jupiter Perps position objects. It does not return
|
||||
* raw Solana accounts or account ids.</p>
|
||||
*
|
||||
* @param owner the wallet address that owns the Jupiter Perps positions
|
||||
* @return the open Jupiter Perps positions owned by the wallet
|
||||
* @throws IOException if the position accounts could not be fetched or decoded
|
||||
* @throws InterruptedException if the calling thread is interrupted while fetching positions
|
||||
*/
|
||||
Set<JupiterPerpsPosition> getOpenPositions(ΩSolanaWalletIdΩ owner)
|
||||
throws IOException, InterruptedException;
|
||||
}
|
||||
+37
@@ -4,8 +4,11 @@ import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
|
||||
import com.r35157.libs.jupiter.perps.JupiterPerpsPositionService;
|
||||
import com.r35157.libs.solana.SolanaAccountInfo;
|
||||
import com.r35157.libs.solana.SolanaBlockChain;
|
||||
import com.r35157.libs.solana.SolanaProgramAccountMemcmpFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPositionService {
|
||||
|
||||
@@ -35,8 +38,42 @@ public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPos
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<JupiterPerpsPosition> getOpenPositions(ΩSolanaWalletIdΩ owner)
|
||||
throws IOException, InterruptedException {
|
||||
Set<SolanaAccountInfo> accountInfos = solanaBlockChain.getProgramAccounts(
|
||||
JUPITER_PERPS_PROGRAM_ID,
|
||||
Set.of(new SolanaProgramAccountMemcmpFilter(
|
||||
POSITION_OWNER_OFFSET,
|
||||
owner
|
||||
))
|
||||
);
|
||||
|
||||
Set<JupiterPerpsPosition> positions = new HashSet<>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID =
|
||||
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
|
||||
private static final int POSITION_OWNER_OFFSET = 8;
|
||||
|
||||
private final SolanaBlockChain solanaBlockChain;
|
||||
private final AnchorIdlJupiterPerpsPositionDecoder positionDecoder;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.r35157.nenjim.hubd.impl.ref;
|
||||
|
||||
import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
|
||||
import com.r35157.libs.jupiter.perps.JupiterPerpsPositionService;
|
||||
import com.r35157.libs.jupiter.perps.impl.anchoridl.AnchorIdlJupiterPerpsPositionServiceImpl;
|
||||
import com.r35157.libs.solana.SolanaBlockChain;
|
||||
import com.r35157.libs.solana.impl.ref.SolanaBlockChainImpl;
|
||||
import com.r35157.nenjim.hubd.ctx.Context;
|
||||
import com.r35157.nenjim.hubd.NenjimHub;
|
||||
import org.slf4j.Logger;
|
||||
@@ -12,12 +17,20 @@ import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
|
||||
// TODO: Consider if we really need a Main class or we just need to move the main method to NenjimHubImpl?
|
||||
static void main(String[] args) throws Exception {
|
||||
NenjimHubImpl nenjimHub = new NenjimHubImpl();
|
||||
/*
|
||||
SolanaBlockChain sbc = new SolanaBlockChainImpl();
|
||||
JupiterPerpsPositionService jupiter = new AnchorIdlJupiterPerpsPositionServiceImpl(sbc);
|
||||
ΩSolanaWalletIdΩ walletId = "vj98roDZ7744EBfxyuDFkKpEGCsKQLr7K8UFRumJNHf";
|
||||
Set<JupiterPerpsPosition> positions = jupiter.getOpenPositions(walletId);
|
||||
int a=0;
|
||||
*/
|
||||
nenjimHub.awaitShutdown();
|
||||
|
||||
/* try {
|
||||
|
||||
Reference in New Issue
Block a user