Skip to content

Commit

Permalink
[ANCHOR-603] Add fee_details to SEP-6/24/31 Transaction object and ap…
Browse files Browse the repository at this point in the history
…propriate RPC endpoints (#1283)

### Description

Add protocol changes introduced in
stellar/stellar-protocol#1441 and
stellar/stellar-protocol#1429

### Context

Previously, protocol was lacking ability to break down fees being
charged by the anchor. This PR adds this functionality

### Testing

- `./gradlew test`

### Documentation

stellar/stellar-docs#349

### Known limitations

N/A
  • Loading branch information
Ifropc authored Mar 15, 2024
1 parent f04e137 commit 8e2e1c6
Show file tree
Hide file tree
Showing 69 changed files with 634 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.stellar.anchor.api.sep.sep38.RateFee;
import org.stellar.anchor.api.shared.FeeDetails;
import reactor.util.annotation.Nullable;

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ public GetRateResponse(Rate rate) {
* @return a GET /rate response with price, total_price, sell_amount, buy_amount and fee.
*/
public static GetRateResponse indicativePrice(
String price, String sellAmount, String buyAmount, RateFee fee) {
String price, String sellAmount, String buyAmount, FeeDetails fee) {
Rate rate =
Rate.builder().price(price).sellAmount(sellAmount).buyAmount(buyAmount).fee(fee).build();
return new GetRateResponse(rate);
Expand All @@ -60,6 +60,6 @@ public static class Rate {
@Nullable
Instant expiresAt;

@Nullable RateFee fee;
@Nullable FeeDetails fee;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.sep.sep38.RateFee;
import org.stellar.anchor.api.shared.FeeDetails;
import org.stellar.anchor.api.shared.StellarId;

@Data
Expand Down Expand Up @@ -51,5 +51,5 @@ public class GetQuoteResponse {
@SerializedName("created_at")
Instant createdAt;

RateFee fee;
FeeDetails fee;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public class PlatformTransactionData {
Amount amountOut;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
Amount amountFee;

@SerializedName("fee_details")
FeeDetails feeDetails;

@SerializedName("quote_id")
String quoteId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.FeeDetails;

@Data
@SuperBuilder
Expand All @@ -18,6 +19,9 @@ public class NotifyAmountsUpdatedRequest extends RpcMethodParamsRequest {
private AmountRequest amountOut;

@SerializedName("amount_fee")
@NotNull
@Deprecated // ANCHOR-636
private AmountRequest amountFee;

@SerializedName("fee_details")
private FeeDetails feeDetails;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.FeeDetails;

@Data
@SuperBuilder
Expand All @@ -21,10 +22,13 @@ public class NotifyInteractiveFlowCompletedRequest extends RpcMethodParamsReques
@SerializedName("amount_out")
private AmountAssetRequest amountOut;

@NotNull
@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
private AmountAssetRequest amountFee;

@SerializedName("fee_details")
private FeeDetails feeDetails;

@SerializedName("amount_expected")
private AmountRequest amountExpected;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.FeeDetails;

@Data
@SuperBuilder
Expand All @@ -26,5 +27,9 @@ public class NotifyOffchainFundsReceivedRequest extends RpcMethodParamsRequest {
private AmountRequest amountOut;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
private AmountRequest amountFee;

@SerializedName("fee_details")
private FeeDetails feeDetails;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.FeeDetails;

@Data
@SuperBuilder
Expand All @@ -24,5 +25,9 @@ public class NotifyOnchainFundsReceivedRequest extends RpcMethodParamsRequest {
private AmountRequest amountOut;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
private AmountRequest amountFee;

@SerializedName("fee_details")
private FeeDetails feeDetails;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.FeeDetails;
import org.stellar.anchor.api.shared.InstructionField;

@Data
Expand All @@ -21,8 +22,12 @@ public class RequestOffchainFundsRequest extends RpcMethodParamsRequest {
private AmountAssetRequest amountOut;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
private AmountAssetRequest amountFee;

@SerializedName("fee_details")
private FeeDetails feeDetails;

@SerializedName("amount_expected")
private AmountRequest amountExpected;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;
import org.stellar.anchor.api.shared.FeeDetails;

@Data
@SuperBuilder
Expand All @@ -19,8 +20,12 @@ public class RequestOnchainFundsRequest extends RpcMethodParamsRequest {
private AmountAssetRequest amountOut;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
private AmountAssetRequest amountFee;

@SerializedName("fee_details")
private FeeDetails feeDetails;

@SerializedName("amount_expected")
private AmountRequest amountExpected;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.annotations.SerializedName;
import java.time.Instant;
import lombok.Data;
import org.stellar.anchor.api.shared.FeeDetails;

/** Base class of transaction responses for withdraw and deposit. */
@Data
Expand Down Expand Up @@ -32,11 +33,16 @@ public class TransactionResponse {
String amountOutAsset;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
String amountFee;

@SerializedName("amount_fee_asset")
@Deprecated // ANCHOR-636
String amountFeeAsset;

@SerializedName("fee_details")
FeeDetails feeDetails;

@SerializedName("started_at")
Instant startedAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Data;
import org.stellar.anchor.api.shared.FeeDetails;

/**
* The response body of the GET /price endpoint of SEP-38.
Expand All @@ -25,5 +26,5 @@ public class GetPriceResponse {
@SerializedName("buy_amount")
String buyAmount;

RateFee fee;
FeeDetails fee;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.Instant;
import lombok.Builder;
import lombok.Data;
import org.stellar.anchor.api.shared.FeeDetails;

/**
* The response body of the POST /quote endpoint of SEP-38.
Expand Down Expand Up @@ -37,5 +38,5 @@ public class Sep38QuoteResponse {
@SerializedName("buy_amount")
String buyAmount;

RateFee fee;
FeeDetails fee;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;
import lombok.Builder;
import lombok.Data;
import org.stellar.anchor.api.shared.FeeDetails;
import org.stellar.anchor.api.shared.InstructionField;
import org.stellar.anchor.api.shared.Refunds;

Expand Down Expand Up @@ -36,11 +37,16 @@ public class Sep6TransactionResponse {
String amountOutAsset;

@SerializedName("amount_fee")
@Deprecated // ANCHOR-636
String amountFee;

@SerializedName("amount_fee_asset")
@Deprecated // ANCHOR-636
String amountFeeAsset;

@SerializedName("fee_details")
FeeDetails feeDetails;

@SerializedName("quote_id")
String quoteId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.stellar.anchor.api.sep.sep38;
package org.stellar.anchor.api.shared;

import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -7,12 +7,12 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RateFeeDetail {
public class FeeDescription {
String name;
String description;
String amount;

public RateFeeDetail(String name, String amount) {
public FeeDescription(String name, String amount) {
this.name = name;
this.amount = amount;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.stellar.anchor.api.sep.sep38;
package org.stellar.anchor.api.shared;

import java.math.BigDecimal;
import java.math.RoundingMode;
Expand All @@ -12,17 +12,17 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RateFee {
public class FeeDetails {
String total;
String asset;
List<RateFeeDetail> details;
List<FeeDescription> details;

public RateFee(String total, String asset) {
public FeeDetails(String total, String asset) {
this.total = total;
this.asset = asset;
}

public void addFeeDetail(RateFeeDetail feeDetail) {
public void addFeeDetail(FeeDescription feeDetail) {
if (feeDetail == null || feeDetail.amount == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,7 @@ public void validatedAndPopulateQuote(
builder.amountInAsset(quote.getSellAsset());
builder.amountOut(quote.getBuyAmount());
builder.amountOutAsset(quote.getBuyAsset());
builder.amountFee(quote.getFee().getTotal());
builder.amountFeeAsset(quote.getFee().getAsset());
builder.feeDetails(quote.getFee());

if (kind.equals(DEPOSIT.toString())) {
builder.sourceAsset(quote.getSellAsset());
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/org/stellar/anchor/sep24/Sep24Transaction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.stellar.anchor.sep24;

import org.stellar.anchor.SepTransaction;
import org.stellar.anchor.api.shared.FeeDetails;

@SuppressWarnings("unused")
public interface Sep24Transaction extends SepTransaction {
Expand Down Expand Up @@ -205,8 +206,10 @@ public interface Sep24Transaction extends SepTransaction {
*
* @return <code>amount_fee</code> field of the SEP-24 transaction history.
*/
@Deprecated // ANCHOR-636
String getAmountFee();

@Deprecated // ANCHOR-636
void setAmountFee(String amountFee);

/**
Expand All @@ -216,10 +219,23 @@ public interface Sep24Transaction extends SepTransaction {
*
* @return <code>amount_fee_asset</code> field of the SEP-24 transaction history.
*/
@Deprecated // ANCHOR-636
String getAmountFeeAsset();

@Deprecated // ANCHOR-636
void setAmountFeeAsset(String amountFeeAsset);

/**
* Description of fee charged by the anchor. The schema for this object is defined in the Fee
* Details Object Schema and matches the one of SEP-38 quote's fee.
*
* @return Unified fields of SEP-24 transaction history complied from <code>amount_fee</code>,
* <code>amount_fee_asset</code> and <code>fee_details</code>
*/
FeeDetails getFeeDetails();

void setFeeDetails(FeeDetails feeDetails);

Boolean getRefunded();

void setRefunded(Boolean refunded);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.stellar.anchor.sep24;

import java.time.Instant;
import org.stellar.anchor.api.shared.FeeDetails;

@SuppressWarnings("unused")
public class Sep24TransactionBuilder {
Expand Down Expand Up @@ -105,11 +106,6 @@ public Sep24TransactionBuilder amountOut(String amountOut) {
return this;
}

public Sep24TransactionBuilder amountFee(String amountFee) {
txn.setAmountFee(amountFee);
return this;
}

public Sep24TransactionBuilder amountInAsset(String amountInAsset) {
txn.setAmountInAsset(amountInAsset);
return this;
Expand All @@ -120,8 +116,8 @@ public Sep24TransactionBuilder amountOutAsset(String amountOutAsset) {
return this;
}

public Sep24TransactionBuilder amountFeeAsset(String amountFeeAsset) {
txn.setAmountFeeAsset(amountFeeAsset);
public Sep24TransactionBuilder feeDetails(FeeDetails feeDetails) {
txn.setFeeDetails(feeDetails);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/stellar/anchor/sep31/Sep31Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class Sep31Helper {
public static boolean allAmountAvailable(Sep31Transaction txn) {
return txn.getAmountIn() != null
&& txn.getAmountInAsset() != null
&& txn.getAmountFee() != null
&& txn.getAmountFeeAsset() != null
&& txn.getFeeDetails() != null
&& txn.getFeeDetails().getAsset() != null
&& txn.getAmountOut() != null
&& txn.getAmountOutAsset() != null;
}
Expand Down
Loading

0 comments on commit 8e2e1c6

Please sign in to comment.