From a5206eed71b884df155fb632b9e758b8152375d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Terje=20S=C3=B8rensen?= Date: Thu, 12 Oct 2023 18:08:50 +0200 Subject: [PATCH] Started implementing StablecoinsClient --- .../jansoren/defillama/StablecoinsClient.java | 21 ++++++++ .../model/protocols/BaseDefiLlamaClient.java | 1 + .../model/stablecoins/PeggedAssetsItem.java | 53 +++++++++++++++++++ .../model/stablecoins/Stablecoins.java | 11 ++++ .../defillama/StablecoinsClientTest.java | 28 ++++++++++ 5 files changed, 114 insertions(+) create mode 100644 src/main/java/no/jansoren/defillama/StablecoinsClient.java create mode 100644 src/main/java/no/jansoren/defillama/model/stablecoins/PeggedAssetsItem.java create mode 100644 src/main/java/no/jansoren/defillama/model/stablecoins/Stablecoins.java create mode 100644 src/test/java/no/jansoren/defillama/StablecoinsClientTest.java diff --git a/src/main/java/no/jansoren/defillama/StablecoinsClient.java b/src/main/java/no/jansoren/defillama/StablecoinsClient.java new file mode 100644 index 0000000..cf4434f --- /dev/null +++ b/src/main/java/no/jansoren/defillama/StablecoinsClient.java @@ -0,0 +1,21 @@ +package no.jansoren.defillama; + +import com.fasterxml.jackson.databind.ObjectMapper; +import no.jansoren.defillama.model.protocols.BaseDefiLlamaClient; +import no.jansoren.defillama.model.stablecoins.Stablecoins; + +import java.net.http.HttpClient; + +public class StablecoinsClient extends BaseDefiLlamaClient { + + public StablecoinsClient(HttpClient httpClient, ObjectMapper objectMapper) { + super(httpClient, objectMapper); + } + + public Stablecoins getStablecoins(boolean includePrices) { + return get(HOSTNAME_STABLECOINS+"/stablecoins?includePrices="+includePrices, Stablecoins.class); + } + + // TODO - Work in progress + +} diff --git a/src/main/java/no/jansoren/defillama/model/protocols/BaseDefiLlamaClient.java b/src/main/java/no/jansoren/defillama/model/protocols/BaseDefiLlamaClient.java index d13d763..6ccf7c5 100644 --- a/src/main/java/no/jansoren/defillama/model/protocols/BaseDefiLlamaClient.java +++ b/src/main/java/no/jansoren/defillama/model/protocols/BaseDefiLlamaClient.java @@ -16,6 +16,7 @@ public class BaseDefiLlamaClient { protected static final String HOSTNAME_API = "https://api.llama.fi"; protected static final String HOSTNAME_COINS = "https://coins.llama.fi"; + protected static final String HOSTNAME_STABLECOINS = "https://stablecoins.llama.fi"; protected final HttpClient httpClient; protected final ObjectMapper objectMapper; diff --git a/src/main/java/no/jansoren/defillama/model/stablecoins/PeggedAssetsItem.java b/src/main/java/no/jansoren/defillama/model/stablecoins/PeggedAssetsItem.java new file mode 100644 index 0000000..f58758b --- /dev/null +++ b/src/main/java/no/jansoren/defillama/model/stablecoins/PeggedAssetsItem.java @@ -0,0 +1,53 @@ +package no.jansoren.defillama.model.stablecoins; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public record PeggedAssetsItem( + + @JsonProperty("symbol") + String symbol, + + @JsonProperty("chainCirculating") + Map> chainCirculating, + + @JsonProperty("gecko_id") + String geckoId, + + @JsonProperty("chains") + List chains, + + @JsonProperty("circulatingPrevWeek") + Map circulatingPrevWeek, + + @JsonProperty("pegType") + String pegType, + + @JsonProperty("circulatingPrevMonth") + Object circulatingPrevMonth, + + @JsonProperty("pegMechanism") + String pegMechanism, + + @JsonProperty("circulating") + Map circulating, + + @JsonProperty("circulatingPrevDay") + Map circulatingPrevDay, + + @JsonProperty("price") + int price, + + @JsonProperty("priceSource") + String priceSource, + + @JsonProperty("name") + String name, + + @JsonProperty("id") + String id +) { +} \ No newline at end of file diff --git a/src/main/java/no/jansoren/defillama/model/stablecoins/Stablecoins.java b/src/main/java/no/jansoren/defillama/model/stablecoins/Stablecoins.java new file mode 100644 index 0000000..6a8a8c8 --- /dev/null +++ b/src/main/java/no/jansoren/defillama/model/stablecoins/Stablecoins.java @@ -0,0 +1,11 @@ +package no.jansoren.defillama.model.stablecoins; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +public record Stablecoins( + + @JsonProperty("peggedAssets") + List peggedAssets +) { +} \ No newline at end of file diff --git a/src/test/java/no/jansoren/defillama/StablecoinsClientTest.java b/src/test/java/no/jansoren/defillama/StablecoinsClientTest.java new file mode 100644 index 0000000..ec3abbf --- /dev/null +++ b/src/test/java/no/jansoren/defillama/StablecoinsClientTest.java @@ -0,0 +1,28 @@ +package no.jansoren.defillama; + +import com.fasterxml.jackson.databind.ObjectMapper; +import no.jansoren.defillama.model.stablecoins.Stablecoins; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.http.HttpClient; + +class StablecoinsClientTest { + + private StablecoinsClient client; + + @BeforeEach + void before() { + var httpClient = HttpClient.newBuilder().build(); + var objectMapper = new ObjectMapper(); + client = new StablecoinsClient(httpClient, objectMapper); + } + + @Test + void testGetStablecoins() { + Stablecoins stablecoins = client.getStablecoins(true); + Assertions.assertNotNull(stablecoins); + } + +}