Repository navigation
fix(onchain): pay a sat-denominated on-chain request from the Cash wallet - #554
Merged
Merged
Conversation
…llet An on-chain payment request that names its amount in sats could not be paid from the Cash wallet. The app asks for the fee and the send "as BTC denominated", and both were dead in this fork: the send was a stub that answered "Currently do not support Bitcoin denomination." and the fee query still called the pre-IBEX path, so the app showed "Failed to calculate fee". IBEX sends from a dollar wallet in dollars only, so both now price the sats at the mid rate, round UP with a margin, and use the same IBEX calls as the dollar-denominated pair. The recipient gets at least the sats asked for, never less. The margin is onChainWallet.btcDenominatedSendMarginBps, default 50 (0.5%). The send runs the send guard first, on the sat amount. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01Gn2VCc25BAQjEu33uLycvP
- usdCentsPerSatMidPrice gets its own spec. Every caller's spec mocks it, so nothing pinned its unit. It now checks cents per sat from a wallet price ratio ($60,000 a bitcoin is 0.06), that a price error comes back as the same instance, and, through the real getCurrentPriceAsWalletPriceRatio, that the price service's dollars per sat are scaled to cents. Dropping that scaling now fails the spec (0.0006 against 0.06). - docs/send-guard.md: the span section names the three guarded on-chain rails, onChainUsdPaymentSendAsBtcDenominated among them, instead of "either on-chain rail". - send-guard-wiring.spec.ts: the comment counts nine guarded rails and names onchain-usd-payment-send-as-sats.ts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Gn2VCc25BAQjEu33uLycvP
This was referenced Nov 27, 2026
Merged
Closed
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.
The problem
A user who scans or pastes an on-chain payment request that names its amount in bitcoin cannot pay it from the Cash wallet. The app shows "Failed to calculate fee" and "Currently do not support Bitcoin denomination.", and the confirm button stays disabled. Every merchant invoice and every POS on-chain checkout is this kind of request.
The app is doing the right thing. For a sat-denominated amount it calls
onChainUsdTxFeeAsBtcDenominatedandonChainUsdPaymentSendAsBtcDenominated. In this fork both were dead:return new UnsupportedCurrencyError("Currently do not support Bitcoin denomination."), with the old body commented out;Wallets.getOnChainFeeForUsdWalletAndBtcAmount, the pre-IBEX path.The dollar-denominated pair (
onChainUsdTxFee,onChainUsdPaymentSend) has always worked.The constraint
IBEX sends from a dollar wallet in dollars only:
sendToAddressV2takes "amount in the wallet's currency". Nothing in its API delivers an exact number of sats from a USD or USDT account. So the sats have to be priced in dollars before the send.What changes
usdCentsToDeliverSats(src/app/payments/usd-cents-for-sats.ts):cents = ceil(sats x centsPerSat x (1 + margin)), at the mid rate. It rounds up, never down, so the recipient gets at least what was asked.onChainWallet.btcDenominatedSendMarginBps, default50(0.5%), accepted range 0 to 1000. It covers the price moving between the quote and IBEX executing, and any gap between the mid rate and the rate IBEX converts at.Ibex.estimateOnchainFeeexactly asonChainUsdTxFeedoes. The estimate is for the amount the send will use.onChainUsdPaymentSendstep for step (cash-wallet routing, send guard, wallet amount,payOnChainByWalletId). The send guard runs first, on the sat amount the caller asked for, before the price is read.Decisions worth a reviewer's eye
{ currency: "BTC", sats }, so its limit check prices the sats without the margin. The difference is at most the margin.getOnChainFeeForUsdWalletAndBtcAmountstays insrc/app/wallets/get-on-chain-fee.ts, now unused by this query.onchain-payment-send.ts(BTC wallet on-chain send) is still a stub.Tests
usd-cents-for-sats.spec.ts: the arithmetic; never rounds down; a property check over margins, prices and amounts that the result is at least the marked-up value and less than a cent above it; the configured margin is used; invalid sat amounts refused without reading the price; a price failure passed back; unusable prices refused; span attributes.onchain-btc-denominated-margin.spec.ts: default 50; filled in when a deployment sets the block without the key; not required; bounds enforced at boot.onchain-usd-payment-send-as-sats.spec.ts: the marked-up amount is sent from the routed wallet; the stub's message is gone; guard first, on the sat amount, with call order pinned; guard rejection stops before the price and the payout; zero sats left to the guard; no price, no payout; routing, wallet-amount and payout failures; pending passed through; each bad input; authentication required.on-chain-usd-tx-fee-query-as-sats.spec.ts: IBEX fee for the converted amount; no price, wallet failure, IBEX failure and missing fee all fail; a zero fee is zero; bad inputs; authentication required.tscerrors insrc/servers/graphql-server.tsandgraphql-admin-server.ts, untouched here, from older local dependencies. CI is the reference.🤖 Generated with Claude Code
https://claude.ai/code/session_01Gn2VCc25BAQjEu33uLycvP