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

#576: Add support for AMMClawback #601

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.xrpl.xrpl4j.model.transactions.AccountSet;
import org.xrpl.xrpl4j.model.transactions.Address;
import org.xrpl.xrpl4j.model.transactions.AmmBid;
import org.xrpl.xrpl4j.model.transactions.AmmClawback;
import org.xrpl.xrpl4j.model.transactions.AmmCreate;
import org.xrpl.xrpl4j.model.transactions.AmmDelete;
import org.xrpl.xrpl4j.model.transactions.AmmDeposit;
Expand Down Expand Up @@ -391,6 +392,10 @@ public <T extends Transaction> SingleSignedTransaction<T> addSignatureToTransact
transactionWithSignature = OracleDelete.builder().from((OracleDelete) transaction)
.transactionSignature(signature)
.build();
} else if (AmmClawback.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignature = AmmClawback.builder().from((AmmClawback) transaction)
.transactionSignature(signature)
.build();
} else {
// Should never happen, but will in a unit test if we miss one.
throw new IllegalArgumentException("Signing fields could not be added to the transaction.");
Expand Down Expand Up @@ -602,6 +607,10 @@ public <T extends Transaction> T addMultiSignaturesToTransaction(T transaction,
transactionWithSignatures = OracleDelete.builder().from((OracleDelete) transaction)
.signers(signers)
.build();
} else if (AmmClawback.class.isAssignableFrom(transaction.getClass())) {
transactionWithSignatures = AmmClawback.builder().from((AmmClawback) transaction)
.signers(signers)
.build();
} else {
// Should never happen, but will in a unit test if we miss one.
throw new IllegalArgumentException("Signing fields could not be added to the transaction.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.xrpl.xrpl4j.model.flags;

/*-
* ========================LICENSE_START=================================
* xrpl4j :: core
* %%
* Copyright (C) 2020 - 2023 XRPL Foundation and its contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/

import org.xrpl.xrpl4j.model.transactions.AmmClawback;

/**
* {@link TransactionFlags} for {@link AmmClawback} transactions.
*/
public class AmmClawbackFlags extends TransactionFlags {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at other TransactionFlags implementations, we always have a static empty() method which calls a private no-arg constructor. Check out OfferCreateFlags for reference

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this class needs a test. Check out OfferCreateFlagsTests as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have added this static empty() method and also added AmmClawbackFlagTest. thanks for the references 👍🏽 let me know what you think

/**
* Constant {@link AmmDepositFlags} for the {@code tfClawTwoAssets} flag.
*/
public static final AmmClawbackFlags CLAW_TWO_ASSETS = new AmmClawbackFlags(0x00000001);

/**
* Constant {@link AmmDepositFlags} for an unset value for "flags".
*/
public static final AmmClawbackFlags UNSET = new AmmClawbackFlags(0L);

private AmmClawbackFlags(long value) {
super(value);
}

private AmmClawbackFlags() {
}

/**
* Construct an empty instance of {@link AmmClawbackFlags}. Transactions with empty flags will
* not be serialized with a {@code Flags} field.
*
* @return An empty {@link AmmClawbackFlags}.
*/
public static AmmClawbackFlags empty() {
return new AmmClawbackFlags();
}

/**
* Whether the {@code tfClawTwoAssets} flag is set.
*
* @return {@code true} if {@code tfLPToken} is set, otherwise {@code false}.
*/
public boolean tfClawTwoAssets() {
return this.isSet(CLAW_TWO_ASSETS);
}
Comment on lines +61 to +63
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unused, i added it to follow the practice I saw with other TransactionFlag classes I saw (e.g. AmmWithdrawFlags). Let me know if I should remove.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.xrpl.xrpl4j.model.transactions;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.annotations.Beta;
import org.immutables.value.Value;
import org.xrpl.xrpl4j.model.flags.AmmClawbackFlags;
import org.xrpl.xrpl4j.model.ledger.Issue;
import org.xrpl.xrpl4j.model.transactions.Address;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import org.xrpl.xrpl4j.model.transactions.Address;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have added this extra import, but on my IDE it shows as unused.

when i define the type for holder, i do see the Address references this path, but doesn't add the import. is there any reason why this happens?

import java.util.Optional;

/**
* An {@link AmmClawback} transaction claws back tokens from a holder that has funds in an AMM pool.
*/
@Value.Immutable
@JsonSerialize(as = ImmutableAmmClawback.class)
@JsonDeserialize(as = ImmutableAmmClawback.class)
@Beta
public interface AmmClawback extends Transaction {

/**
* Construct a builder for this class.
*
* @return An {@link ImmutableAmmClawback.Builder}.
*/
static ImmutableAmmClawback.Builder builder() {
return ImmutableAmmClawback.builder();
}

/**
* The address of the holder that has funds deposited in the AMM pool.
*
* @return An {@link Address}.
*/
@JsonProperty("Holder")
Address holder();

/**
* The asset in the AMM pool that the issuer is looking to claw back.
*
* @return An {@link Issue}.
*/
@JsonProperty("Asset")
Issue asset();

/**
* Other asset in the AMM pool that the issuer is looking to claw back.
*
* @return An {@link Issue}.
*/
@JsonProperty("Asset2")
Issue asset2();

/**
* Optional field that specifies the maximum amount to clawback from the AMM pool.
*
* @return An {@link CurrencyAmount}.
*/
@JsonProperty("Amount")
Optional<CurrencyAmount> amount();

/**
* Transaction Flags for {@link AmmClawback}, with the only option being tfClawTwoAssets.
*
* @return {@link AmmClawbackFlags#UNSET} if field was not set, otherwise returns with the set flag.
*/
@JsonProperty("Flags")
@Value.Default
default AmmClawbackFlags flags() {
return AmmClawbackFlags.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public interface Transaction {
.put(ImmutableOracleSet.class, TransactionType.ORACLE_SET)
.put(ImmutableOracleDelete.class, TransactionType.ORACLE_DELETE)
.put(ImmutableUnknownTransaction.class, TransactionType.UNKNOWN)
.put(ImmutableAmmClawback.class, TransactionType.AMM_CLAWBACK)
.build();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public enum TransactionType {
@Beta
ORACLE_DELETE("OracleDelete"),

AMM_CLAWBACK("AMMClawback"),
/**
* The {@link TransactionType} for any transaction that is unrecognized/unsupported by xrpl4j.
*/
Expand Down
Loading