feat(wallet): typed swap refusals from the desk instead of a 500 - #217
Merged
Merged
Conversation
A swap adapter had no way to refuse a quote or a fill that the router understood, so a replayed quote or an over-limit swap reached the player as a 500. The port now carries SwapRefusedError (CONFLICT) and SwapLimitExceededError (BAD_REQUEST), each with a machine-readable data.reason, mapped on both swap.quote and swap.execute. SwapFillAmountMissingError stays unmapped. Claude-Session: https://claude.ai/code/session_0178TH3L8uHsQUGnf8bsfmFF
zaxovaiko
requested review from
damianrzepka,
jakubfilinger-b,
klaudia-blazyczek-blurify,
marek-chmielowski-blurify,
mp-blurify and
okapitula
as code owners
September 24, 2026 12:32
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.
Summary
A swap adapter can now refuse a quote or a fill with a typed error that the wallet router maps to a 4xx carrying
data.reason. Until now every such refusal reached the player as a 500. BF-0.Why
SwapAdapter.getQuoteandexecutehad no port-level error of their own. Anything an adapter threw fell through themapErrorsmap on theswap.quoteandswap.executehandlers, so a replayed quote, an expired quote or an over-limit swap all returned 500. The client could not tell them apart and could not offer a requote.The port now exports two classes:
SwapRefusedErrormaps to CONFLICT. Reasons:quote_missing,quote_invalid,quote_expired,quote_spent,insufficient_inventory,no_rate.quote_invalidalso covers a quote issued to another player, so the caller cannot learn which case it hit.SwapLimitExceededErrormaps to BAD_REQUEST. Reasons:over_swap_limit,over_daily_limit.SwapFillAmountMissingErrorstays unmapped: the desk filled but did not say how much, which is a fault on our side of the seam. Ifexecutethrows, the held funds are returned as before.Alternatives considered
mapErrorskeys a code off the class, and one class per code keeps it that way, the same asRgLimitExceededError.ORPCErrordirectly. Rejected: that puts transport concerns inside an adapter and breaks the typed-errors-at-the-edge rule.Risks