From b2363fb62d89433adcbf2366149b7716fe195899 Mon Sep 17 00:00:00 2001 From: jpe7s Date: Sat, 12 Oct 2024 18:15:45 -0500 Subject: [PATCH] stream perp/spot markets configs. --- .../sava/anchor/programs/drift/PerpMarkets.java | 6 ++++++ .../anchor/programs/drift/PerpMarketsRecord.java | 13 +++++++++++++ .../sava/anchor/programs/drift/SpotMarkets.java | 6 ++++++ .../anchor/programs/drift/SpotMarketsRecord.java | 13 +++++++++++++ 4 files changed, 38 insertions(+) diff --git a/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarkets.java b/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarkets.java index 783959a..210ca86 100644 --- a/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarkets.java +++ b/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarkets.java @@ -1,7 +1,9 @@ package software.sava.anchor.programs.drift; import java.util.Arrays; +import java.util.Collection; import java.util.EnumMap; +import java.util.stream.Stream; public interface PerpMarkets { @@ -22,4 +24,8 @@ static PerpMarkets createRecord(final PerpMarketConfig[] marketConfigs) { PerpMarketConfig forProduct(final DriftProduct product); int numMarkets(); + + Stream streamMarkets(); + + Collection markets(); } diff --git a/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarketsRecord.java b/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarketsRecord.java index f1f1f1b..8c62d89 100644 --- a/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarketsRecord.java +++ b/programs/src/main/java/software/sava/anchor/programs/drift/PerpMarketsRecord.java @@ -1,6 +1,9 @@ package software.sava.anchor.programs.drift; +import java.util.Arrays; +import java.util.Collection; import java.util.Map; +import java.util.stream.Stream; public record PerpMarketsRecord(PerpMarketConfig[] marketConfigs, Map byProduct) implements PerpMarkets { @@ -19,4 +22,14 @@ public PerpMarketConfig forProduct(final DriftProduct product) { public int numMarkets() { return marketConfigs.length; } + + @Override + public Stream streamMarkets() { + return Arrays.stream(marketConfigs); + } + + @Override + public Collection markets() { + return byProduct.values(); + } } diff --git a/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarkets.java b/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarkets.java index e786be0..ea194d1 100644 --- a/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarkets.java +++ b/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarkets.java @@ -1,7 +1,9 @@ package software.sava.anchor.programs.drift; import java.util.Arrays; +import java.util.Collection; import java.util.EnumMap; +import java.util.stream.Stream; public interface SpotMarkets { @@ -16,4 +18,8 @@ static SpotMarkets createRecord(final SpotMarketConfig[] marketConfigs) { SpotMarketConfig forAsset(final DriftAsset asset); int numMarkets(); + + Stream streamMarkets(); + + Collection markets(); } diff --git a/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarketsRecord.java b/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarketsRecord.java index 04837c8..ca36ef0 100644 --- a/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarketsRecord.java +++ b/programs/src/main/java/software/sava/anchor/programs/drift/SpotMarketsRecord.java @@ -1,6 +1,9 @@ package software.sava.anchor.programs.drift; +import java.util.Arrays; +import java.util.Collection; import java.util.Map; +import java.util.stream.Stream; record SpotMarketsRecord(SpotMarketConfig[] marketConfigs, Map byAsset) implements SpotMarkets { @@ -19,4 +22,14 @@ public SpotMarketConfig forAsset(final DriftAsset asset) { public int numMarkets() { return marketConfigs.length; } + + @Override + public Stream streamMarkets() { + return Arrays.stream(marketConfigs); + } + + @Override + public Collection markets() { + return byAsset.values(); + } }