Repository navigation
fix(x402): exclude stacked STX from balance checks; check inbox and news payments - #436
Merged
Merged
Conversation
…ews payments - spendableStx(): Hiro's stx.balance includes STX locked in stacking, which a transfer cannot move; direct and sponsored balance checks now subtract it - inbox send and aibtc-news file-signal sign their own sponsored sBTC payments; run checkSponsoredPaymentBalance before signing there too - aibtc-news imported getAccount from wallet-manager, which does not export it, so the paid file-signal path threw at runtime; import it from x402.service - requestWasNeverSent: Bun reports a refused connection and a failed name lookup as "ConnectionRefused", so direct mode called them ambiguous and kept the duplicate guard and spend entry, refusing an immediate retry - test fake: destroy sockets on close so a held response cannot hang server.close() (the x402 test file never finished under Bun) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
biwasxyz
force-pushed
the
fix/x402-balance-followups
branch
from
October 8, 2026 11:39
0426f48 to
77d7734
Compare
Contributor
Author
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.
Why
Follow-ups from #435, plus two bugs found while getting the full test suite to finish.
What
stx.balanceincludes STX locked in stacking, which a transfer cannot move. NewspendableStx()subtractslocked; the sponsored check (fix(x402): refuse sponsored payments the wallet cannot cover before signing #435) and the direct-mode gas/price check both use it. Before this, a wallet with mostly stacked STX passed the check and failed at settlement.inbox sendandaibtc-news file-signalbuild their own sponsored sBTC transfers outside the engine. Both now callcheckSponsoredPaymentBalancebefore signing.aibtc-news file-signalcould not pay. It importedgetAccountfromwallet-manager, which does not export it, so the paid path threwgetAccount is not a function. It went unnoticed becausetsconly coverssrc/. Now imported fromx402.service, likeinboxdoes.ConnectionRefused, notECONNREFUSED/ENOTFOUND.requestWasNeverSentdid not recognise it, so in direct mode a paid request that never left the machine was reported as "Settlement is ambiguous", and the duplicate guard and spend entry were kept, refusing an immediate retry for up to 15 minutes. AddedConnectionRefusedto the not-sent set; verified the codes Bun 1.1.43 actually produces (TLS errors already use Node's codes).paid: hangtest,server.close()waited forever on the held connection (closeAllConnections()does not drop it under Bun). The fake now tracks sockets and destroys them on close. This is whybun test src/libappeared to hang; CI does not run the tests, so nobody saw it.Verification
bun run typecheck,bun run validate(204/204) pass;inbox/inbox.tsandaibtc-news/aibtc-news.tsalso typecheck clean on their own (the news file had one error before: thegetAccountimport).bun test src/lib: 167 pass, 0 fail, 16 s (previously hung). New tests:spendableStx, sponsored STX price with locked STX (refused), direct gas with locked STX (refused). The existing "never reaches the server" test was failing under Bun and now passes.hodlmm-flow,inscription-queue-watcher,launkr,signing,stacks-alpha-engine): 49 pass, 1 fail. The failure is pre-existing:stacks-alpha-engineimportstiny-secp256k1, which is not inpackage.json.Follow-up worth considering
CI runs typecheck/validate but not
bun test, andtsconly coverssrc/, which is how both bugs above shipped. Addingbun test src/libto CI and widening the typecheck would catch them.🤖 Generated with Claude Code