Sep38Fee

@Serializable
data class Sep38Fee(val total: String, val asset: String, val details: List<Sep38FeeDetail>? = null)

Fee structure for an exchange operation.

Provides total fee amount and optional breakdown of individual fee components. The total represents the complete fee charged by the anchor, while details provides transparency about how the fee is calculated.

Fees can be denominated in either the sell asset or buy asset, as indicated by the asset property. This affects how the fee is applied in price calculations:

  • If fee is in sell asset: sell_amount - fee = price * buy_amount

  • If fee is in buy asset: sell_amount = price * (buy_amount + fee)

Example - Simple fee (no breakdown):

val fee = Sep38Fee(
total = "10.00",
asset = "stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"
)

Example - Detailed fee breakdown:

val fee = Sep38Fee(
total = "42.00",
asset = "iso4217:BRL",
details = listOf(
Sep38FeeDetail("PIX fee", "12.00", "Fee charged in order to process the outgoing PIX transaction."),
Sep38FeeDetail("Brazilian conciliation fee", "15.00", "Fee charged in order to process conciliation costs with intermediary banks."),
Sep38FeeDetail("Service fee", "15.00")
)
)
// sum(details.amount) = 12.00 + 15.00 + 15.00 = 42.00 = total

Example - Displaying fees to users:

val price = sep38Service.price(
context = "sep6",
sellAsset = "iso4217:BRL",
buyAsset = "stellar:USDC:G...",
sellAmount = "542"
)

println("Fee: ${price.fee.total} ${price.fee.asset}")
price.fee.details?.forEach { detail ->
println(" ${detail.name}: ${detail.amount}")
}

Example - Fee validation:

val quote = sep38Service.postQuote(request, jwtToken)

// Verify fee breakdown sums to total
val detailSum = quote.fee.details?.sumOf { it.amount.toDouble() } ?: 0.0
val total = quote.fee.total.toDouble()
require((detailSum - total).absoluteValue < 0.01) { "Fee details don't sum to total" }

See also:

Constructors

Link copied to clipboard
constructor(total: String, asset: String, details: List<Sep38FeeDetail>? = null)

Properties

Link copied to clipboard
@SerialName(value = "asset")
val asset: String

Asset in which fee is denominated, using Asset Identification Format

Link copied to clipboard
@SerialName(value = "details")
val details: List<Sep38FeeDetail>?

Optional breakdown of individual fee components (sum of amounts should equal total)

Link copied to clipboard
@SerialName(value = "total")
val total: String

Total fee amount as a string decimal