Skip to content

Fix SEP-38 buy_amount description: total_price, not price - #2003

Open
yigitcangokmen wants to merge 1 commit into
stellar:masterfrom
yigitcangokmen:fix/sep-38-buy-amount-total-price
Open

Fix SEP-38 buy_amount description: total_price, not price#2003
yigitcangokmen wants to merge 1 commit into
stellar:masterfrom
yigitcangokmen:fix/sep-38-buy-amount-total-price

Conversation

@yigitcangokmen

Copy link
Copy Markdown

Problem

The buy_amount field description in the POST /quote and GET /quote response tables states:

price * buy_amount = sell_amount must be true up to the number of decimals required for buy_asset.

This contradicts the spec's own Price Formulas section, which states sell_amount = total_price * buy_amount. Because this SEP defines price as the price without fees and total_price as the price including fees, price * buy_amount = sell_amount only holds when the fee is zero. An implementer who validates quotes against this description literally would use the wrong identity and reject every fee-bearing quote.

The correct term, total_price, is over-determined by three independent sources:

  • The Price Formulas section: sell_amount = total_price * buy_amount.
  • Every worked example in this document. The first POST /quote example has total_price: "5.42", price: "5.00", sell_amount: "542", buy_amount: "100": total_price * buy_amount = 542 = sell_amount, while price * buy_amount = 500 != 542. The other four examples behave the same.
  • The reference implementation (stellar/anchor-platform, Sep38Service.getTotalPrice): total_price = sell_amount / buy_amount.

The stale wording predates fees. It was correct before total_price/fee were introduced (#1204, v2.0.0), when price was itself the all-in ratio, but it was not updated when price was redefined as fee-exclusive.

Change

Corrects the buy_amount description in both response tables to total_price * buy_amount = sell_amount. The fee-aware formulas (sell_amount - fee = price * buy_amount, sell_amount = price * (buy_amount + fee)) correctly use price and are left unchanged. Bumps the version to 2.5.1 and adds a changelog entry.

Note: the GET /quote response table does not separately list a total_price field (it relies on "This response body should match the response from POST /quote"); listing it there is a separate change and is intentionally out of scope here.

Copilot AI balanced review requested due to automatic review settings August 29, 2026 11:20
The buy_amount field description in both the POST /quote and GET /quote
response tables states "price * buy_amount = sell_amount" must be true.
This contradicts the spec's own Price Formulas section
(sell_amount = total_price * buy_amount), all five worked examples, and the
reference implementation (anchor-platform Sep38Service.getTotalPrice, where
total_price = sell_amount / buy_amount). Since price is defined without fees
and total_price with fees, price * buy_amount = sell_amount only holds when
the fee is zero.

Correct both descriptions to use total_price. The fee-aware formulas that
correctly use price are left unchanged. Bumps the version to 2.5.1 and adds a
changelog entry.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Corrects SEP-38’s fee-aware buy_amount identity to match its normative formulas and examples.

Changes:

  • Replaces price with total_price in both quote response tables.
  • Bumps SEP-38 to v2.5.1 and updates its changelog.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants