23: Investigate and expose closeFeeUsd in JupiterPerpsPosition

This commit is contained in:
2026-08-05 10:12:38 +02:00
parent eda12a12fd
commit db20e68e93
@@ -117,10 +117,9 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
ΩJupiterPostionInterestΩ positionInterest = custodyAccountInfo.currentCumulativeInterestRate()
.subtract(perpsPositionInfo.cumulativeInterestSnapshot());
ΩUSDCAmountΩ borrowFeesDue = calculateBorrowFeesDue(
positionInterest,
perpsPositionInfo.positionSize()
);
ΩUSDCAmountΩ positionSize = perpsPositionInfo.positionSize();
ΩUSDCAmountΩ borrowFeesDue = calculateBorrowFeesDue(positionInterest, positionSize);
ΩUSDCAmountΩ closeFeePending = calculateCloseFeePending(positionSize);
ΩUSDCAmountΩ value = ZERO; // TODO - Dummy
ΩUSDCAmountΩ pnl = ZERO; // TODO - Dummy
@@ -128,7 +127,6 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
BigDecimal leverage = ZERO; // TODO - Dummy
ΩUSDCPriceΩ marketPrice = ZERO; // TODO - Dummy
ΩUSDCAmountΩ totalFees = ZERO; // TODO - Dummy
ΩUSDCAmountΩ closeFeePending = ZERO; // TODO - Dummy
ΩSolanaAmountΩ accountRent = new MoneyAmount( // TODO - Dummy
ZERO,
WellKnownCurrencyTypes.SOLANA.getCurrencyType()
@@ -139,7 +137,7 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
mintAddress,
perpsPositionInfo.direction(),
value,
perpsPositionInfo.positionSize(),
positionSize,
pnl,
pnlPercent,
leverage,
@@ -169,7 +167,21 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
return fees;
}
private static ΩUSDCAmountΩ calculateCloseFeePending(ΩUSDCAmountΩ size) {
ΩUSDCAmountΩ fee = size
.multiply(BigDecimal.valueOf(CLOSE_FEE_BPS))
.divide(
BigDecimal.valueOf(BASIS_POINTS_DIVISOR),
6,
RoundingMode.CEILING
);
return fee;
}
private static final long RATE_POWER = 1_000_000_000L;
private static final int CLOSE_FEE_BPS = 6;
private static final int BASIS_POINTS_DIVISOR = 10_000;
private static final ΩJupiterPerpsProgramIdΩ JUPITER_PERPS_PROGRAM_ID =
"PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu";
private static final int POSITION_OWNER_OFFSET = 8;