Skip to content

Commit

Permalink
Merge branch 'master' into soroban (#527)
Browse files Browse the repository at this point in the history
* fix the issue of unable to parse liquidity_pool_revoked effect properly. (#521)

* add jitpack config.

* bump project version to upcoming 0.4.1

* update change log, include #522

* define `cursor`, `order` and `limit` in AssetsRequestBuilder object. (#522)
  • Loading branch information
overcat authored Sep 12, 2023
1 parent 9d21b19 commit 00da8ab
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.
| TransactionPreconditions.minSeqAge | Long | BigInteger |
| TransactionPreconditions.minSeqLedgerGap | int | long |

## 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
18 changes: 18 additions & 0 deletions src/main/java/org/stellar/sdk/requests/AssetsRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,22 @@ public static Page<AssetResponse> execute(OkHttpClient httpClient, HttpUrl uri)
public Page<AssetResponse> execute() throws IOException, TooManyRequestsException {
return this.execute(this.httpClient, this.buildUri());
}

@Override
public AssetsRequestBuilder cursor(String token) {
super.cursor(token);
return this;
}

@Override
public AssetsRequestBuilder limit(int number) {
super.limit(number);
return this;
}

@Override
public AssetsRequestBuilder order(Order direction) {
super.order(direction);
return this;
}
}
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
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.math.BigInteger;
Expand All @@ -23,6 +24,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 @@ -1322,4 +1325,96 @@ public void testDeserializeLiquidityPoolTradeEffect() {
new AssetAmount(
create("ARST:GB7TAYRUZGE6TVT7NHP5SMIZRNQA6PLM423EYISAOAP3MKYIQMVYP2JO"), "1.0000000"));
}

@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");
}
}

0 comments on commit 00da8ab

Please sign in to comment.