Fix SEP-38 buy_amount description: total_price, not price - #2003
Open
yigitcangokmen wants to merge 1 commit into
Open
Fix SEP-38 buy_amount description: total_price, not price#2003yigitcangokmen wants to merge 1 commit into
yigitcangokmen wants to merge 1 commit into
Conversation
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.
yigitcangokmen
force-pushed
the
fix/sep-38-buy-amount-total-price
branch
from
August 29, 2026 11:20
9448770 to
49805b2
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Corrects SEP-38’s fee-aware buy_amount identity to match its normative formulas and examples.
Changes:
- Replaces
pricewithtotal_pricein 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
buy_amountfield description in thePOST /quoteandGET /quoteresponse tables states:This contradicts the spec's own Price Formulas section, which states
sell_amount = total_price * buy_amount. Because this SEP definespriceas the price without fees andtotal_priceas the price including fees,price * buy_amount = sell_amountonly 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:sell_amount = total_price * buy_amount.POST /quoteexample hastotal_price: "5.42",price: "5.00",sell_amount: "542",buy_amount: "100":total_price * buy_amount = 542 = sell_amount, whileprice * buy_amount = 500 != 542. The other four examples behave the same.stellar/anchor-platform,Sep38Service.getTotalPrice):total_price = sell_amount / buy_amount.The stale wording predates fees. It was correct before
total_price/feewere introduced (#1204, v2.0.0), whenpricewas itself the all-in ratio, but it was not updated whenpricewas redefined as fee-exclusive.Change
Corrects the
buy_amountdescription in both response tables tototal_price * buy_amount = sell_amount. The fee-aware formulas (sell_amount - fee = price * buy_amount,sell_amount = price * (buy_amount + fee)) correctly usepriceand are left unchanged. Bumps the version to2.5.1and adds a changelog entry.Note: the
GET /quoteresponse table does not separately list atotal_pricefield (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.