Skip to content

Commit

Permalink
Started implementing StablecoinsClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jansoren committed Oct 12, 2023
1 parent a11672d commit a5206ee
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/no/jansoren/defillama/StablecoinsClient.java
Original file line number Diff line number Diff line change
@@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Map<String, Object>> chainCirculating,

@JsonProperty("gecko_id")
String geckoId,

@JsonProperty("chains")
List<String> chains,

@JsonProperty("circulatingPrevWeek")
Map<String, BigDecimal> circulatingPrevWeek,

@JsonProperty("pegType")
String pegType,

@JsonProperty("circulatingPrevMonth")
Object circulatingPrevMonth,

@JsonProperty("pegMechanism")
String pegMechanism,

@JsonProperty("circulating")
Map<String, BigDecimal> circulating,

@JsonProperty("circulatingPrevDay")
Map<String, BigDecimal> circulatingPrevDay,

@JsonProperty("price")
int price,

@JsonProperty("priceSource")
String priceSource,

@JsonProperty("name")
String name,

@JsonProperty("id")
String id
) {
}
Original file line number Diff line number Diff line change
@@ -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<PeggedAssetsItem> peggedAssets
) {
}
28 changes: 28 additions & 0 deletions src/test/java/no/jansoren/defillama/StablecoinsClientTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit a5206ee

Please sign in to comment.