22: Testing
This commit is contained in:
+3
-3
@@ -7,9 +7,9 @@ import com.r35157.libs.solana.SolanaAccountInfo;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
class AnchorIdlJupiterPerpsCustodyDecoder {
|
public class AnchorIdlJupiterPerpsCustodyDecoder {
|
||||||
|
|
||||||
ΩSPLMintAddressΩ decodeMint(
|
public ΩSPLMintAddressΩ decodeMint(
|
||||||
SolanaAccountInfo custodyAccountInfo
|
SolanaAccountInfo custodyAccountInfo
|
||||||
) {
|
) {
|
||||||
byte[] data = Base64.getDecoder().decode(custodyAccountInfo.dataBase64());
|
byte[] data = Base64.getDecoder().decode(custodyAccountInfo.dataBase64());
|
||||||
@@ -23,7 +23,7 @@ class AnchorIdlJupiterPerpsCustodyDecoder {
|
|||||||
return readPublicKey(data, MINT_OFFSET);
|
return readPublicKey(data, MINT_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger decodeCurrentCumulativeInterestRate(
|
public BigInteger decodeCurrentCumulativeInterestRate(
|
||||||
SolanaAccountInfo custodyAccountInfo
|
SolanaAccountInfo custodyAccountInfo
|
||||||
) {
|
) {
|
||||||
byte[] data = Base64.getDecoder().decode(custodyAccountInfo.dataBase64());
|
byte[] data = Base64.getDecoder().decode(custodyAccountInfo.dataBase64());
|
||||||
|
|||||||
+21
-13
@@ -12,7 +12,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
class AnchorIdlJupiterPerpsPositionDecoder {
|
public class AnchorIdlJupiterPerpsPositionDecoder {
|
||||||
|
|
||||||
JupiterPerpsPosition decode(
|
JupiterPerpsPosition decode(
|
||||||
ΩJupiterPerpsPositionAccountΩ positionAccount,
|
ΩJupiterPerpsPositionAccountΩ positionAccount,
|
||||||
@@ -57,10 +57,7 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
.valueOf(rawSizeUsd)
|
.valueOf(rawSizeUsd)
|
||||||
.movePointLeft(6);
|
.movePointLeft(6);
|
||||||
|
|
||||||
BigInteger cumulativeInterestSnapshot = readU128(
|
BigInteger cumulativeInterestSnapshot = decodeCumulativeInterestSnapshot(accountInfo);
|
||||||
data,
|
|
||||||
CUMULATIVE_INTEREST_SNAPSHOT_OFFSET
|
|
||||||
);
|
|
||||||
|
|
||||||
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
||||||
positionAccount,
|
positionAccount,
|
||||||
@@ -74,7 +71,7 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger decodeCumulativeInterestSnapshot(SolanaAccountInfo accountInfo) {
|
public BigInteger decodeCumulativeInterestSnapshot(SolanaAccountInfo accountInfo) {
|
||||||
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||||
|
|
||||||
if (data.length < CUMULATIVE_INTEREST_SNAPSHOT_OFFSET + U128_LENGTH) {
|
if (data.length < CUMULATIVE_INTEREST_SNAPSHOT_OFFSET + U128_LENGTH) {
|
||||||
@@ -90,13 +87,7 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger decodeCurrentCumulativeInterestRate(
|
public ΩSolanaAddressΩ decodeCustodyAccount(SolanaAccountInfo accountInfo) {
|
||||||
SolanaAccountInfo collateralCustodyAccountInfo
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ΩSolanaAddressΩ decodeCustodyAccount(SolanaAccountInfo accountInfo) {
|
|
||||||
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||||
|
|
||||||
if (data.length < CUSTODY_OFFSET + PUBLIC_KEY_LENGTH) {
|
if (data.length < CUSTODY_OFFSET + PUBLIC_KEY_LENGTH) {
|
||||||
@@ -111,6 +102,23 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ΩSolanaAddressΩ decodeCollateralCustodyAccount(
|
||||||
|
SolanaAccountInfo accountInfo
|
||||||
|
) {
|
||||||
|
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||||
|
|
||||||
|
if (data.length < COLLATERAL_CUSTODY_OFFSET + PUBLIC_KEY_LENGTH) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Jupiter Perps position account data is too short: " + data.length
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return readPublicKey(
|
||||||
|
data,
|
||||||
|
COLLATERAL_CUSTODY_OFFSET
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private JupiterPerpsPositionDirection decodeDirection(
|
private JupiterPerpsPositionDirection decodeDirection(
|
||||||
byte rawSide
|
byte rawSide
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.r35157.nenjim.hubd.impl.ref;
|
|||||||
|
|
||||||
import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
|
import com.r35157.libs.jupiter.perps.JupiterPerpsPosition;
|
||||||
import com.r35157.libs.jupiter.perps.JupiterPerpsService;
|
import com.r35157.libs.jupiter.perps.JupiterPerpsService;
|
||||||
|
import com.r35157.libs.jupiter.perps.impl.anchoridl.AnchorIdlJupiterPerpsPositionDecoder;
|
||||||
import com.r35157.libs.jupiter.perps.impl.anchoridl.AnchorIdlJupiterPerpsServiceImpl;
|
import com.r35157.libs.jupiter.perps.impl.anchoridl.AnchorIdlJupiterPerpsServiceImpl;
|
||||||
import com.r35157.libs.solana.SolanaBlockChain;
|
import com.r35157.libs.solana.SolanaBlockChain;
|
||||||
import com.r35157.libs.solana.impl.ref.SolanaBlockChainImpl;
|
import com.r35157.libs.solana.impl.ref.SolanaBlockChainImpl;
|
||||||
@@ -11,7 +12,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import java.lang.management.ClassLoadingMXBean;
|
import java.lang.management.ClassLoadingMXBean;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import com.r35157.libs.jupiter.perps.impl.anchoridl.AnchorIdlJupiterPerpsCustodyDecoder;
|
||||||
|
import com.r35157.libs.solana.SolanaAccountInfo;
|
||||||
|
import java.math.BigInteger;
|
||||||
import com.r35157.nenjim.hubd.ctx.ContextManager;
|
import com.r35157.nenjim.hubd.ctx.ContextManager;
|
||||||
import com.r35157.nenjim.hubd.journal.JournalManager;
|
import com.r35157.nenjim.hubd.journal.JournalManager;
|
||||||
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
import com.r35157.nenjim.hubd.impl.ref.JournalManagerImpl;
|
||||||
@@ -23,16 +26,34 @@ 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();
|
SolanaBlockChain sbc = new SolanaBlockChainImpl();
|
||||||
JupiterPerpsService jupiter = new AnchorIdlJupiterPerpsServiceImpl(sbc);
|
JupiterPerpsService jupiter = new AnchorIdlJupiterPerpsServiceImpl(sbc);
|
||||||
ΩSolanaWalletIdΩ walletId = "vj98roDZ7744EBfxyuDFkKpEGCsKQLr7K8UFRumJNHf";
|
ΩSolanaWalletIdΩ walletId = "vj98roDZ7744EBfxyuDFkKpEGCsKQLr7K8UFRumJNHf";
|
||||||
|
|
||||||
Set<JupiterPerpsPosition> positions = jupiter.getOpenPositions(walletId);
|
Set<JupiterPerpsPosition> positions = jupiter.getOpenPositions(walletId);
|
||||||
|
|
||||||
|
AnchorIdlJupiterPerpsPositionDecoder positionDecoder = new AnchorIdlJupiterPerpsPositionDecoder();
|
||||||
|
AnchorIdlJupiterPerpsCustodyDecoder custodyDecoder = new AnchorIdlJupiterPerpsCustodyDecoder();
|
||||||
|
|
||||||
|
for (JupiterPerpsPosition position : positions) {
|
||||||
|
SolanaAccountInfo positionAccountInfo = sbc.getAccountInfo(position.positionAccount());
|
||||||
|
ΩSolanaAddressΩ collateralCustodyAccount = positionDecoder.decodeCollateralCustodyAccount(positionAccountInfo);
|
||||||
|
SolanaAccountInfo collateralCustodyAccountInfo = sbc.getAccountInfo(collateralCustodyAccount);
|
||||||
|
BigInteger currentCumulativeInterestRate =custodyDecoder.decodeCurrentCumulativeInterestRate(collateralCustodyAccountInfo);
|
||||||
|
BigInteger cumulativeInterestSnapshot = positionDecoder.decodeCumulativeInterestSnapshot(positionAccountInfo);
|
||||||
|
BigInteger difference = currentCumulativeInterestRate.subtract(cumulativeInterestSnapshot);
|
||||||
|
|
||||||
|
System.out.println("positionAccount: " + position.positionAccount());
|
||||||
|
System.out.println("currentCumulativeInterestRate: " + currentCumulativeInterestRate);
|
||||||
|
System.out.println("cumulativeInterestSnapshot: " + cumulativeInterestSnapshot);
|
||||||
|
System.out.println("difference: " + difference);
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
int a=0;
|
int a=0;
|
||||||
*/
|
//nenjimHub.awaitShutdown();
|
||||||
nenjimHub.awaitShutdown();
|
|
||||||
|
|
||||||
/* try {
|
/* try {
|
||||||
log.info("Auto-starting 2 Nenjim application(s)...");
|
log.info("Auto-starting 2 Nenjim application(s)...");
|
||||||
|
|||||||
Reference in New Issue
Block a user