Compare commits
2 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| a7858ff3fd | |||
| d2cce123b9 |
+3
-21
@@ -1,28 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "$#" -ne 1 ]; then
|
|
||||||
echo "Usage: $0 <github-snapshot-branch>" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
BRANCH="$1"
|
|
||||||
|
|
||||||
SOURCE="$HOME/projects/com_r35157_nenjim-hubd-impl_ref"
|
SOURCE="$HOME/projects/com_r35157_nenjim-hubd-impl_ref"
|
||||||
TARGET="$HOME/projects/com_r35157_nenjim-hubd-impl_ref_github_snapshot"
|
TARGET="$HOME/projects/com_r35157_nenjim-hubd-impl_ref_github_snapshot"
|
||||||
|
|
||||||
cd "$TARGET"
|
|
||||||
|
|
||||||
git fetch origin
|
|
||||||
|
|
||||||
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
|
|
||||||
git switch "$BRANCH"
|
|
||||||
elif git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then
|
|
||||||
git switch --track "origin/$BRANCH"
|
|
||||||
else
|
|
||||||
git switch --create "$BRANCH"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rsync -a --delete \
|
rsync -a --delete \
|
||||||
--exclude '.git' \
|
--exclude '.git' \
|
||||||
--exclude 'conf/*.conf' \
|
--exclude 'conf/*.conf' \
|
||||||
@@ -30,12 +11,13 @@ rsync -a --delete \
|
|||||||
"$SOURCE/" \
|
"$SOURCE/" \
|
||||||
"$TARGET/"
|
"$TARGET/"
|
||||||
|
|
||||||
|
cd "$TARGET"
|
||||||
git add -A
|
git add -A
|
||||||
|
|
||||||
if git diff --cached --quiet; then
|
if git diff --cached --quiet; then
|
||||||
echo "No snapshot changes to publish on branch '$BRANCH'."
|
echo "No snapshot changes to publish."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git commit -m "Mirror snapshot"
|
git commit -m "Mirror snapshot"
|
||||||
git push -u origin "$BRANCH"
|
git push
|
||||||
|
|||||||
+39
-1
@@ -7,6 +7,7 @@ import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection;
|
|||||||
import com.r35157.libs.solana.SolanaAccountInfo;
|
import com.r35157.libs.solana.SolanaAccountInfo;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@@ -56,6 +57,11 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
.valueOf(rawSizeUsd)
|
.valueOf(rawSizeUsd)
|
||||||
.movePointLeft(6);
|
.movePointLeft(6);
|
||||||
|
|
||||||
|
BigInteger cumulativeInterestSnapshot = readU128(
|
||||||
|
data,
|
||||||
|
CUMULATIVE_INTEREST_SNAPSHOT_OFFSET
|
||||||
|
);
|
||||||
|
|
||||||
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
||||||
positionAccount,
|
positionAccount,
|
||||||
entryPrice,
|
entryPrice,
|
||||||
@@ -68,6 +74,22 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BigInteger decodeCumulativeInterestSnapshot(SolanaAccountInfo accountInfo) {
|
||||||
|
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||||
|
|
||||||
|
if (data.length < CUMULATIVE_INTEREST_SNAPSHOT_OFFSET + U128_LENGTH) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Jupiter Perps position account data is too short: " + data.length
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger value = readU128(
|
||||||
|
data,
|
||||||
|
CUMULATIVE_INTEREST_SNAPSHOT_OFFSET
|
||||||
|
);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
ΩSolanaAddressΩ decodeCustodyAccount(SolanaAccountInfo accountInfo) {
|
ΩSolanaAddressΩ decodeCustodyAccount(SolanaAccountInfo accountInfo) {
|
||||||
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||||
|
|
||||||
@@ -115,11 +137,25 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
return base58.encode(publicKeyBytes);
|
return base58.encode(publicKeyBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static BigInteger readU128(
|
||||||
|
byte[] data,
|
||||||
|
int offset
|
||||||
|
) {
|
||||||
|
byte[] bytes = new byte[U128_LENGTH];
|
||||||
|
|
||||||
|
for (int i = 0; i < U128_LENGTH; i++) {
|
||||||
|
bytes[i] = data[offset + U128_LENGTH - 1 - i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BigInteger(1, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
private static final int ANCHOR_DISCRIMINATOR_LENGTH = 8;
|
private static final int ANCHOR_DISCRIMINATOR_LENGTH = 8;
|
||||||
private static final int PUBLIC_KEY_LENGTH = 32;
|
private static final int PUBLIC_KEY_LENGTH = 32;
|
||||||
private static final int I64_LENGTH = 8;
|
|
||||||
private static final int SIDE_ENUM_LENGTH = 1;
|
private static final int SIDE_ENUM_LENGTH = 1;
|
||||||
|
private static final int I64_LENGTH = 8;
|
||||||
private static final int U64_LENGTH = 8;
|
private static final int U64_LENGTH = 8;
|
||||||
|
private static final int U128_LENGTH = 16;
|
||||||
|
|
||||||
private static final int OWNER_OFFSET = ANCHOR_DISCRIMINATOR_LENGTH;
|
private static final int OWNER_OFFSET = ANCHOR_DISCRIMINATOR_LENGTH;
|
||||||
private static final int POOL_OFFSET = OWNER_OFFSET + PUBLIC_KEY_LENGTH;
|
private static final int POOL_OFFSET = OWNER_OFFSET + PUBLIC_KEY_LENGTH;
|
||||||
@@ -131,6 +167,8 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
|||||||
private static final int PRICE_OFFSET = SIDE_OFFSET + SIDE_ENUM_LENGTH;
|
private static final int PRICE_OFFSET = SIDE_OFFSET + SIDE_ENUM_LENGTH;
|
||||||
private static final int SIZE_USD_OFFSET = PRICE_OFFSET + U64_LENGTH;
|
private static final int SIZE_USD_OFFSET = PRICE_OFFSET + U64_LENGTH;
|
||||||
private static final int COLLATERAL_USD_OFFSET = SIZE_USD_OFFSET + U64_LENGTH;
|
private static final int COLLATERAL_USD_OFFSET = SIZE_USD_OFFSET + U64_LENGTH;
|
||||||
|
private static final int REALISED_PNL_USD_OFFSET = COLLATERAL_USD_OFFSET + U64_LENGTH;
|
||||||
|
private static final int CUMULATIVE_INTEREST_SNAPSHOT_OFFSET = REALISED_PNL_USD_OFFSET + I64_LENGTH;
|
||||||
|
|
||||||
private static final Base58Codec base58 = new Base58CodecImpl();
|
private static final Base58Codec base58 = new Base58CodecImpl();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user