Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the issue of unable to parse liquidity_pool_revoked effect properly. #521

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

## Pending

## 0.40.1
* Fix the issue of unable to parse liquidity_pool_revoked effect properly. ([#521](https://github.com/stellar/java-stellar-sdk/pull/521))
* Define cursor, order and limit in AssetsRequestBuilder object. ([#522](https://github.com/stellar/java-stellar-sdk/pull/522))
* Add basic implementation of liquidity_pools?account ([#426](https://github.com/stellar/java-stellar-sdk/pull/426))
* Add source account comparison to `ClawbackClaimableBalanceOperation`, `LiquidityPoolWithdrawOperation`, and `LiquidityPoolDepositOperation` for equality check. ([#484](https://github.com/stellar/java-stellar-sdk/pull/484))

## 0.40.0
* Add strkey support for contract ids ([#471](https://github.com/stellar/java-stellar-sdk/pull/471))
* Fix NPE in `KeyPair.equals()` method ([#474](https://github.com/stellar/java-stellar-sdk/pull/474))
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spotless {


sourceCompatibility = JavaVersion.VERSION_1_8.toString()
version = '0.40.0'
version = '0.40.1'
group = 'stellar'
jar.enabled = false

Expand Down
7 changes: 7 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
jdk:
- openjdk11

before_install:
- sdk install java 11.0.23-open
- sdk use java 11.0.23-open

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is irrelevant to this PR, please ignore it.

Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ public LiquidityPoolsRequestBuilder forReserves(String... reserves) {
uriBuilder.setQueryParameter(RESERVES_PARAMETER_NAME, String.join(",", reserves));
return this;
}

/**
* Returns all liquidity pools the specified account is participating in.
*
* @param account Account ID to filter liquidity pools
* @return current {@link LiquidityPoolsRequestBuilder} instance
* @see <a href="https://developers.stellar.org/api/resources/liquiditypools/list/">LiquidityPools</a>
* @see <a
* href="https://developers.stellar.org/api/resources/liquiditypools/list/">LiquidityPools</a>
*/
public LiquidityPoolsRequestBuilder forAccount(String account) {
uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account);
return this;
uriBuilder.setQueryParameter(ACCOUNT_PARAMETER_NAME, account);
return this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.sdk.responses;

import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
Expand All @@ -25,6 +26,7 @@ public EffectResponse deserialize(
.registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer())
.registerTypeAdapter(LiquidityPoolType.class, new LiquidityPoolTypeDeserializer())
.registerTypeAdapter(Predicate.class, new PredicateDeserializer())
.registerTypeAdapter(ImmutableList.class, new ImmutableListDeserializer())
.create();

int type = json.getAsJsonObject().get("type_i").getAsInt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.stellar.sdk.responses.effects;

import com.google.gson.annotations.SerializedName;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.stellar.sdk.Asset;

/**
Expand All @@ -11,6 +13,8 @@
* @see org.stellar.sdk.requests.EffectsRequestBuilder
* @see org.stellar.sdk.Server#effects()
*/
@EqualsAndHashCode
@ToString
public class LiquidityPoolClaimableAssetAmount {
@SerializedName("asset")
protected final Asset asset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.sdk.responses.effects;

import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -15,14 +16,14 @@ public class LiquidityPoolRevokedEffectResponse extends EffectResponse {
protected final LiquidityPool liquidityPool;

@SerializedName("reserves_revoked")
protected final LiquidityPoolClaimableAssetAmount reservesRevoked;
protected final ImmutableList<LiquidityPoolClaimableAssetAmount> reservesRevoked;

@SerializedName("shares_revoked")
protected final String sharesRevoked;

public LiquidityPoolRevokedEffectResponse(
LiquidityPool liquidityPool,
LiquidityPoolClaimableAssetAmount reservesRevoked,
ImmutableList<LiquidityPoolClaimableAssetAmount> reservesRevoked,
String sharesRevoked) {
this.liquidityPool = liquidityPool;
this.reservesRevoked = reservesRevoked;
Expand All @@ -33,7 +34,7 @@ public LiquidityPool getLiquidityPool() {
return liquidityPool;
}

public LiquidityPoolClaimableAssetAmount getReservesRevoked() {
public ImmutableList<LiquidityPoolClaimableAssetAmount> getReservesRevoked() {
return reservesRevoked;
}

Expand Down
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is irrelevant to this PR, please ignore it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what issue or pr is it related to, this will land on master, is there a way to rebase the source branch to get cleaner change set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because when we merged #426, #426 was not formatted (it is a very "old" PR.). If necessary, I can create another PR to format it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see it mentioned in the changelog notes, which is great, thanks!

Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,29 @@ public void testForReserves() {
"https://horizon-testnet.stellar.org/liquidity_pools?reserves=EURT%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S%2CPHP%3AGAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S",
uri.toString());
}

@Test
public void testForAccount() {
Server server = new Server("https://horizon-testnet.stellar.org");
HttpUrl uri = server.liquidityPools()
.forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account=GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S", uri.toString());
HttpUrl uri =
server
.liquidityPools()
.forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
.buildUri();
assertEquals(
"https://horizon-testnet.stellar.org/liquidity_pools?account=GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S",
uri.toString());
}

@Test
public void testForAccountClear() {
Server server = new Server("https://horizon-testnet.stellar.org");
HttpUrl uri = server.liquidityPools()
.forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
.forAccount(null)
.buildUri();
HttpUrl uri =
server
.liquidityPools()
.forAccount("GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S")
.forAccount(null)
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools?account", uri.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.stellar.sdk.responses;

import static org.junit.Assert.assertArrayEquals;
import static org.stellar.sdk.Asset.create;

import java.util.Arrays;
Expand All @@ -22,6 +23,8 @@
import org.stellar.sdk.responses.effects.DataRemovedEffectResponse;
import org.stellar.sdk.responses.effects.DataUpdatedEffectResponse;
import org.stellar.sdk.responses.effects.EffectResponse;
import org.stellar.sdk.responses.effects.LiquidityPoolClaimableAssetAmount;
import org.stellar.sdk.responses.effects.LiquidityPoolRevokedEffectResponse;
import org.stellar.sdk.responses.effects.LiquidityPoolTradeEffectResponse;
import org.stellar.sdk.responses.effects.SequenceBumpedEffectResponse;
import org.stellar.sdk.responses.effects.SignerCreatedEffectResponse;
Expand Down Expand Up @@ -1318,4 +1321,96 @@ public void testDeserializeLiquidityPoolTradeEffect() {
new AssetAmount(
create("ARST:GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO"), "1.0000000"));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great test coverage!

@Test
public void testDeserializeLiquidityPoolRevokedEffect() {
String json =
"{\n"
+ " \"_links\": {\n"
+ " \"operation\": {\n"
+ " \"href\": \"https://horizon.stellar.org/operations/166807682144149505\"\n"
+ " },\n"
+ " \"succeeds\": {\n"
+ " \"href\": \"https://horizon.stellar.org/effects?order=desc&cursor=166807682144149505-7\"\n"
+ " },\n"
+ " \"precedes\": {\n"
+ " \"href\": \"https://horizon.stellar.org/effects?order=asc&cursor=166807682144149505-7\"\n"
+ " }\n"
+ " },\n"
+ " \"id\": \"0166807682144149505-0000000007\",\n"
+ " \"paging_token\": \"166807682144149505-7\",\n"
+ " \"account\": \"GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y\",\n"
+ " \"type\": \"liquidity_pool_revoked\",\n"
+ " \"type_i\": 95,\n"
+ " \"created_at\": \"2021-12-22T13:50:44Z\",\n"
+ " \"liquidity_pool\": {\n"
+ " \"id\": \"d0e6dfe3cb35848c528ba283f8a274b61c0acae73486981e2e49c815ef0fa275\",\n"
+ " \"fee_bp\": 30,\n"
+ " \"type\": \"constant_product\",\n"
+ " \"total_trustlines\": \"2\",\n"
+ " \"total_shares\": \"12695.9043474\",\n"
+ " \"reserves\": [\n"
+ " {\n"
+ " \"asset\": \"native\",\n"
+ " \"amount\": \"166.0927633\"\n"
+ " },\n"
+ " {\n"
+ " \"asset\": \"TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y\",\n"
+ " \"amount\": \"979387.4348690\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"reserves_revoked\": [\n"
+ " {\n"
+ " \"asset\": \"native\",\n"
+ " \"amount\": \"319.8948139\",\n"
+ " \"claimable_balance_id\": \"0000000021e897197b8fe396772891ba3ece3244c37ba039fd73bd0ef0ce68a90d5bb688\"\n"
+ " },\n"
+ " {\n"
+ " \"asset\": \"TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y\",\n"
+ " \"amount\": \"1886301.0948913\",\n"
+ " \"claimable_balance_id\": \"000000001843f844860fd96541993c96c72157c1a5eb9d522e6f5b99e2ab300ccee8e38d\"\n"
+ " }\n"
+ " ],\n"
+ " \"shares_revoked\": \"24452.3233794\"\n"
+ "}\n";

LiquidityPoolRevokedEffectResponse effect =
(LiquidityPoolRevokedEffectResponse)
GsonSingleton.getInstance().fromJson(json, EffectResponse.class);

assertEquals(effect.getType(), "liquidity_pool_revoked");

assertEquals(effect.getAccount(), "GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y");
assertEquals(effect.getCreatedAt(), "2021-12-22T13:50:44Z");
assertEquals(
effect.getLiquidityPool().getID().toString(),
"d0e6dfe3cb35848c528ba283f8a274b61c0acae73486981e2e49c815ef0fa275");
assertEquals(effect.getLiquidityPool().getFeeBP(), Integer.valueOf(30));
assertEquals(
effect.getLiquidityPool().getType(), LiquidityPoolType.LIQUIDITY_POOL_CONSTANT_PRODUCT);
assertEquals(effect.getLiquidityPool().getTotalTrustlines(), Long.valueOf(2));
assertEquals(effect.getLiquidityPool().getTotalShares(), "12695.9043474");
assertArrayEquals(
effect.getLiquidityPool().getReserves(),
new AssetAmount[] {
new AssetAmount(create("native"), "166.0927633"),
new AssetAmount(
create("TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y"),
"979387.4348690")
});
assertArrayEquals(
effect.getReservesRevoked().toArray(),
new LiquidityPoolClaimableAssetAmount[] {
new LiquidityPoolClaimableAssetAmount(
create("native"),
"319.8948139",
"0000000021e897197b8fe396772891ba3ece3244c37ba039fd73bd0ef0ce68a90d5bb688"),
new LiquidityPoolClaimableAssetAmount(
create("TESLABIOHEAL:GDGO6TGQLDCUYLQU3JOCSIU7CVCVUC2VHSTUUDPOUEDSZ2L5K3SWO76Y"),
"1886301.0948913",
"000000001843f844860fd96541993c96c72157c1a5eb9d522e6f5b99e2ab300ccee8e38d")
});
assertEquals(effect.getSharesRevoked(), "24452.3233794");
}
}
Loading