Skip to content

Commit

Permalink
Adding Neutron and Celestia providers
Browse files Browse the repository at this point in the history
  • Loading branch information
RedRaton committed Dec 9, 2023
1 parent e365c04 commit 8b0192c
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ AllMyCoins is a simple crypto portfolio manager.
- <img src="https://assets.coingecko.com/coins/images/13722/small/logo-200x200.jpg?1626095888" alt="E-Money" width="15"/> E-Money
- <img src="https://assets.coingecko.com/coins/images/22009/small/lum.png?1640590072" alt="Lum" width="15"/> Lum
- <img src="https://assets.coingecko.com/coins/images/22610/small/dsm.png?1643192656" alt="Desmos" width="15"/> Desmos
- <img src="https://assets.coingecko.com/coins/images/30813/standard/ntrn.png?1696529669" alt="Neutron" width="15"/> Neutron
- <img src="https://assets.coingecko.com/coins/images/31967/standard/tia.jpg?1696530772" alt="Celestia" width="15"/> Celestia

##### MultiversX ecosystem
* <img src="https://assets.coingecko.com/coins/images/12335/thumb_2x/Elrond.png" alt="Elrond" width="15"/> MultiversX
Expand Down
6 changes: 6 additions & 0 deletions privateConfig.template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,11 @@
# Desmos public address
#DESMOS_ADDRESS = ...

# Neutron public address
#NEUTRON_ADDRESS = ...

# Celestia public address
#CELESTIA_ADDRESS = ...

# Avalanche C public address
#AVALANCHE_C_ADDRESS = ...
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ public final class CosmosJsProvider implements PublicAddressSingleBalanceProvide
private final String baseUrl;
private final String denom;
private final String token;
private final boolean requestDelegation;

private CosmosJsBalanceJson[] cosmosJsBalances;

public CosmosJsProvider(String pPrivateConfigKey, String pNetwork, String pDenom, String pToken) {
this(pPrivateConfigKey, pNetwork, pDenom, pToken, true);
}

CosmosJsProvider(String pPrivateConfigKey, String pNetwork, String pDenom, String pToken,
boolean aRequestDelegation) {
privateConfigKey = pPrivateConfigKey;
network = pNetwork;
denom = pDenom;
token = pToken;
cosmosJsBalances = null;
baseUrl = COSMOS_DIRECTORY_BASE_URL + pNetwork.toLowerCase();
requestDelegation = aRequestDelegation;
}

private String denom() {
Expand All @@ -51,8 +58,8 @@ public String privateConfigKey() {
@Override
public BalanceJson singleBalance(String publicAddress) {
float qty = requestBalance(publicAddress);
float delegationQty = requestDelegation(publicAddress);
float rewardQty = requestReward(publicAddress);
float delegationQty = requestDelegation ? requestDelegation(publicAddress) : 0;
float rewardQty = requestDelegation ? requestReward(publicAddress) : 0;

return new BalanceJson(token, qty + delegationQty + rewardQty, network + " wallet");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ public final class CosmosJsProviders {
public static final CosmosJsProvider DESMOS_PROVIDER = new CosmosJsProvider("DESMOS_ADDRESS", "Desmos", "udsm",
"DSM");

public static final CosmosJsProvider NEUTRON_PROVIDER = new CosmosJsProvider("NEUTRON_ADDRESS", "Neutron", "untrn",
"NTRN", false);

public static final CosmosJsProvider CELESTIA_PROVIDER = new CosmosJsProvider("CELESTIA_ADDRESS", "Celestia",
"utia", "TIA");

private static final List<CosmosJsProvider> PROVIDERS = List.of(COSMOS_PROVIDER, AKASH_PROVIDER, IRISNET_PROVIDER,
JUNO_PROVIDER, COMDEX_PROVIDER, CHIHUAHA_PROVIDER, STARGAZE_PROVIDER, REGEN_PROVIDER, EMONEY_PROVIDER,
LUM_PROVIDER, DESMOS_PROVIDER);
LUM_PROVIDER, DESMOS_PROVIDER, NEUTRON_PROVIDER, CELESTIA_PROVIDER);

public static final List<CosmosJsProvider> providers() {
return PROVIDERS;
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/allmycoins/balance/CelestiaProviderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.allmycoins.balance;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;

import com.allmycoins.PrivateConfig;
import com.allmycoins.balance.cosmosjs.CosmosJsProvider;
import com.allmycoins.balance.cosmosjs.CosmosJsProviders;
import com.allmycoins.json.BalanceJson;

final class CelestiaProviderTest {

private static final Supplier<CosmosJsProvider> GET_PROVIDER = () -> CosmosJsProviders.CELESTIA_PROVIDER;

@Test
void testBalances() {
PrivateConfig.loadConfigurationFromClassLoader();

CosmosJsProvider provider = GET_PROVIDER.get();
List<BalanceJson> balances = provider.balances();
assertEquals(1, balances.size());

BalanceJson balance = balances.get(0);

assertEquals("TIA", balance.getAsset());
assertEquals("Celestia wallet", balance.getSrc());
assertTrue(balance.getQty() >= 0.0f);
}

@Test
void testNoBalances() {
PrivateConfig.clearConfiguration();

CosmosJsProvider provider = GET_PROVIDER.get();
List<BalanceJson> balances = provider.balances();
assertTrue(balances.isEmpty());
}
}
43 changes: 43 additions & 0 deletions src/test/java/com/allmycoins/balance/NeutronProviderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.allmycoins.balance;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;

import com.allmycoins.PrivateConfig;
import com.allmycoins.balance.cosmosjs.CosmosJsProvider;
import com.allmycoins.balance.cosmosjs.CosmosJsProviders;
import com.allmycoins.json.BalanceJson;

final class NeutronProviderTest {

private static final Supplier<CosmosJsProvider> GET_PROVIDER = () -> CosmosJsProviders.NEUTRON_PROVIDER;

@Test
void testBalances() {
PrivateConfig.loadConfigurationFromClassLoader();

CosmosJsProvider provider = GET_PROVIDER.get();
List<BalanceJson> balances = provider.balances();
assertEquals(1, balances.size());

BalanceJson balance = balances.get(0);

assertEquals("NTRN", balance.getAsset());
assertEquals("Neutron wallet", balance.getSrc());
assertTrue(balance.getQty() >= 0.0f);
}

@Test
void testNoBalances() {
PrivateConfig.clearConfiguration();

CosmosJsProvider provider = GET_PROVIDER.get();
List<BalanceJson> balances = provider.balances();
assertTrue(balances.isEmpty());
}
}
8 changes: 7 additions & 1 deletion src/test/resources/privateConfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ EMONEY_ADDRESS = emoney140g8fnnl46mlvfhygj3zvjqlku6x0fwuylucan
LUM_ADDRESS = lum1axqn30kead92gdsg7pusc6ezxx8ltq46t5cyh4

# Desmos public address for tests
DESMOS_ADDRESS = desmos1gwr9l765vfxv4l4zz8glsxwkkphj2084clxvs4
DESMOS_ADDRESS = desmos1gwr9l765vfxv4l4zz8glsxwkkphj2084clxvs4

# Neutron public address
NEUTRON_ADDRESS = neutron1yghndrffay859ma2ue4pa2cltw640vtaqx2096

# Celestia public address
CELESTIA_ADDRESS = celestia12s888zz8x2tdn4eq0y9uv0gdkmx79whypzu28m

0 comments on commit 8b0192c

Please sign in to comment.