From 14be7351904495e25d388e82ca42e4dd7ba5e7fe Mon Sep 17 00:00:00 2001 From: skynetcap <100323448+skynetcap@users.noreply.github.com> Date: Sat, 18 Nov 2023 19:31:17 -0800 Subject: [PATCH] Phoenix Tests: Add FIFOOrderId, FIFORestingOrder --- .../mmorrell/phoenix/model/PhoenixMarket.java | 12 +++++++++++- phoenix/src/test/java/PhoenixTest.java | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/phoenix/src/main/java/com/mmorrell/phoenix/model/PhoenixMarket.java b/phoenix/src/main/java/com/mmorrell/phoenix/model/PhoenixMarket.java index c08a99b..d525a4f 100644 --- a/phoenix/src/main/java/com/mmorrell/phoenix/model/PhoenixMarket.java +++ b/phoenix/src/main/java/com/mmorrell/phoenix/model/PhoenixMarket.java @@ -1,9 +1,14 @@ package com.mmorrell.phoenix.model; +import com.google.common.io.Files; import lombok.Builder; import lombok.Data; import org.bitcoinj.core.Utils; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + @Data @Builder public class PhoenixMarket { @@ -17,7 +22,7 @@ public class PhoenixMarket { private long collectedQuoteLotFees; private long unclaimedQuoteLotFees; - public static PhoenixMarket readPhoenixMarket(byte[] data) { + public static PhoenixMarket readPhoenixMarket(byte[] data, PhoenixMarketHeader header) { PhoenixMarket phoenixMarket = PhoenixMarket.builder() .baseLotsPerBaseUnit(Utils.readInt64(data, START_OFFSET)) .tickSizeInQuoteLotsPerBaseUnit(Utils.readInt64(data, START_OFFSET + 8)) @@ -27,6 +32,11 @@ public static PhoenixMarket readPhoenixMarket(byte[] data) { .unclaimedQuoteLotFees(Utils.readInt64(data, START_OFFSET + 40)) .build(); + long bidsSize = + 16 + 16 + (16 + FIFOOrderId.FIFO_ORDER_ID_SIZE + FIFORestingOrder.FIFO_RESTING_ORDER_SIZE) * header.getBidsSize(); + + byte[] bidBuffer = Arrays.copyOfRange(data, 880, (int) bidsSize); + return phoenixMarket; } diff --git a/phoenix/src/test/java/PhoenixTest.java b/phoenix/src/test/java/PhoenixTest.java index 77df1c2..22457f9 100644 --- a/phoenix/src/test/java/PhoenixTest.java +++ b/phoenix/src/test/java/PhoenixTest.java @@ -1,5 +1,7 @@ import com.google.common.io.Files; import com.google.common.io.Resources; +import com.mmorrell.phoenix.model.FIFOOrderId; +import com.mmorrell.phoenix.model.FIFORestingOrder; import com.mmorrell.phoenix.model.PhoenixMarket; import com.mmorrell.phoenix.model.PhoenixMarketHeader; import com.mmorrell.phoenix.program.PhoenixProgram; @@ -95,13 +97,19 @@ public void phoenixGetMarketDetailTest() throws RpcException, IOException { log.info("Base lots per base unit: {}", baseLotsPerBaseUnit); log.info("Tick size in quote lots per base unit: {}", tickSizeInQuoteLotsPerBaseUnit); - PhoenixMarket phoenixMarket = PhoenixMarket.readPhoenixMarket(data); - log.info("Phoenix market: {}", phoenixMarket.toString()); - PhoenixMarketHeader header = PhoenixMarketHeader.readPhoenixMarketHeader(data); + + PhoenixMarket phoenixMarket = PhoenixMarket.readPhoenixMarket(data, header); + log.info("Phoenix market: {}", phoenixMarket.toString()); log.info("Header from market: {}", header.toString()); log.info("Bids size: {}, Asks Size: {}, Number of seats: {}", header.getBidsSize(), header.getAsksSize(), header.getNumSeats()); + + long bidsSize = + 16 + 16 + (16 + FIFOOrderId.FIFO_ORDER_ID_SIZE + FIFORestingOrder.FIFO_RESTING_ORDER_SIZE) * header.getBidsSize(); + + + } @Test @@ -140,7 +148,7 @@ public void phoenixClaimSeatTest() throws RpcException, IOException { ) ); - String claimSeatTxId = client.getApi().sendTransaction( + String claimSeatTxId = client.getApi().sendTransaction( claimSeatTransaction, List.of(tradingAccount), client.getApi().getRecentBlockhash(Commitment.PROCESSED)