Compare commits
2 Commits
ba9a167a57
...
760ba0e823
| Author | SHA256 | Date | |
|---|---|---|---|
| 760ba0e823 | |||
| 1cb78fa3db |
@@ -1,6 +1,7 @@
|
|||||||
package com.r35157.libs.jupiter.perps;
|
package com.r35157.libs.jupiter.perps;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for reading Jupiter Perps positions.
|
* Service for reading Jupiter Perps positions.
|
||||||
@@ -27,4 +28,18 @@ public interface JupiterPerpsPositionService {
|
|||||||
*/
|
*/
|
||||||
JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount)
|
JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount)
|
||||||
throws IOException, InterruptedException;
|
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.jupiter.perps.JupiterPerpsPositionService;
|
||||||
import com.r35157.libs.solana.SolanaAccountInfo;
|
import com.r35157.libs.solana.SolanaAccountInfo;
|
||||||
import com.r35157.libs.solana.SolanaBlockChain;
|
import com.r35157.libs.solana.SolanaBlockChain;
|
||||||
|
import com.r35157.libs.solana.SolanaProgramAccountMemcmpFilter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPositionService {
|
public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPositionService {
|
||||||
|
|
||||||
@@ -35,8 +38,42 @@ public class AnchorIdlJupiterPerpsPositionServiceImpl implements JupiterPerpsPos
|
|||||||
return pos;
|
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 =
|
private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID =
|
||||||
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
|
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
|
||||||
|
private static final int POSITION_OWNER_OFFSET = 8;
|
||||||
|
|
||||||
private final SolanaBlockChain solanaBlockChain;
|
private final SolanaBlockChain solanaBlockChain;
|
||||||
private final AnchorIdlJupiterPerpsPositionDecoder positionDecoder;
|
private final AnchorIdlJupiterPerpsPositionDecoder positionDecoder;
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.r35157.nenjim.hubd.impl.ref;
|
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.ctx.Context;
|
||||||
import com.r35157.nenjim.hubd.NenjimHub;
|
import com.r35157.nenjim.hubd.NenjimHub;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -12,12 +17,20 @@ import com.r35157.nenjim.hubd.journal.JournalManager;
|
|||||||
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
// TODO: Consider if we really need a Main class or we just need to move the main method to NenjimHubImpl?
|
// 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 {
|
static void main(String[] args) throws Exception {
|
||||||
NenjimHubImpl nenjimHub = new NenjimHubImpl();
|
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();
|
nenjimHub.awaitShutdown();
|
||||||
|
|
||||||
/* try {
|
/* try {
|
||||||
|
|||||||
Reference in New Issue
Block a user