Skip to content

fix(cli-sdk): add pre-flight balance check and on-chain tx confirmation#42

Merged
arein merged 2 commits intomainfrom
fix/swidge-balance-check-and-receipt
Mar 9, 2026
Merged

fix(cli-sdk): add pre-flight balance check and on-chain tx confirmation#42
arein merged 2 commits intomainfrom
fix/swidge-balance-check-and-receipt

Conversation

@arein
Copy link
Member

@arein arein commented Mar 9, 2026

Summary

  • Pre-flight balance check: After LI.FI quote resolves the token address, checks balanceOf (ERC-20) or eth_getBalance (native) and errors early with "Insufficient balance: have X, need Y" instead of sending a doomed tx to the wallet
  • On-chain tx confirmation: Polls eth_getTransactionReceipt after both approval and bridge transactions — only reports "confirmed" after status === 0x1, throws on revert
  • Process-level unhandledRejection handler: Catches any relay/WC errors that escape per-request handlers, prints clean error message instead of minified source dump

Context

The swidge sent 0.81 USDC when only 0.807 was available — reverted twice. Both reverted txs were reported as "confirmed" because the CLI only had the tx hash (submission), not the receipt (confirmation).

Test plan

  • npm run build — all packages build
  • npm run test — all 107 tests pass
  • Manual: attempt swidge with insufficient balance, verify early error
  • Manual: successful swidge, verify receipt polling and "confirmed" after on-chain confirmation
  • Manual: reject in wallet, verify clean error message (no minified dump)

🤖 Generated with Claude Code

arein and others added 2 commits March 9, 2026 22:42
…on to swidge

1. Pre-flight balance check: after the LI.FI quote resolves the token
   address, check balanceOf (ERC-20) or eth_getBalance (native) and
   error early with "Insufficient balance: have X, need Y" instead of
   sending a doomed tx to the wallet.

2. On-chain tx confirmation: poll eth_getTransactionReceipt after both
   approval and bridge transactions. Only report "confirmed" after
   receipt.status === 0x1. Throw on revert instead of silently
   reporting success.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…error output

Catches any relay/WC errors that escape the per-request handler and
prints a clean error message instead of dumping minified source.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arein arein merged commit d3f928d into main Mar 9, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 9, 2026
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.

1 participant