Skip to content

feat(swap-widget): broadcast api-supplied approval txs - #12518

Merged
kaladinlight merged 3 commits into
developfrom
feat/swap-widget-approval-txs
Aug 5, 2026
Merged

feat(swap-widget): broadcast api-supplied approval txs#12518
kaladinlight merged 3 commits into
developfrom
feat/swap-widget-approval-txs

Conversation

@kaladinlight

Copy link
Copy Markdown
Member

Description

Follow-up to #12517 (stacked on it) — the widget now consumes the API's approval.approvalTxs instead of hand-encoding a single approve.

useSwapApproval broadcasts the supplied transactions sequentially, waiting for each receipt, and reports the final hash to the machine. This inherits the API's USDT-style reset handling and fixes a latent on-chain revert: the previous single approve(spender, amount) fails for reset-requiring tokens whenever a prior exact approval was left unspent (e.g. the widget's own approve-then-abandon flow leaves a dangling non-zero USDT allowance, breaking the next larger sell through the same spender).

Local exact-approve encoding remains as a fallback for API deployments predating approvalTxs, so widget and API can release in either order.

Issue (if applicable)

closes #

Risk

Low. Approval flow only; the common case (no reset needed) broadcasts the same single exact-amount approve as before, now server-encoded. Swap execution untouched.

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

Widget ERC-20 approval transactions on EVM sells. Same spender, same exact amount; USDT-style tokens gain the required approve(spender, 0) reset first.

Testing

Engineering

Operations

  • Swap an unapproved ERC-20 via the widget — approval broadcasts and swap proceeds as before.
  • USDT with a leftover partial allowance to the spender now prompts two sequential approval transactions instead of failing.

Screenshots (if applicable)

🤖 Generated with Claude Code

@kaladinlight
kaladinlight requested a review from a team as a code owner August 3, 2026 21:57
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@kaladinlight, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe2a2861-0f3d-4d07-b5d5-15574b19a23f

📥 Commits

Reviewing files that changed from the base of the PR and between 43dc0f9 and 252aec0.

📒 Files selected for processing (2)
  • packages/swap-widget/package.json
  • packages/swap-widget/src/hooks/useSwapApproval.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kaladinlight
kaladinlight force-pushed the feat/swap-widget-approval-txs branch 2 times, most recently from c91b5d5 to 3196dbb Compare August 3, 2026 22:13
@kaladinlight
kaladinlight force-pushed the feat/public-api-approval-txs branch from c7fa6f9 to 8f9d84f Compare August 3, 2026 22:25
@kaladinlight
kaladinlight force-pushed the feat/swap-widget-approval-txs branch from 3196dbb to 86b1f6a Compare August 3, 2026 22:25
Base automatically changed from feat/public-api-approval-txs to develop August 3, 2026 22:37
Use quote.approval.approvalTxs (sequential broadcast, wait for each
receipt) instead of hand-encoding a single approve. Inherits the API's
USDT-style reset handling - the previous single approve reverted
on-chain for tokens requiring a zero-allowance reset whenever a prior
exact approval was left unspent. Local encoding remains as fallback for
API versions predating approvalTxs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kaladinlight
kaladinlight force-pushed the feat/swap-widget-approval-txs branch from 86b1f6a to 53eb27d Compare August 5, 2026 17:19
kaladinlight and others added 2 commits August 5, 2026 11:25
….7.0

The machine only enters approving when the api set isRequired, which
contractually implies non-empty approvalTxs - the local encode fallback
was unreachable on current api versions and silently reproduced the
legacy exact-approve behavior (no USDT reset) against stale ones.
Replace it with an explicit error.

Throw when an approval receipt reverts: in the reset-then-approve flow
an unchecked reverted reset would cascade into a second guaranteed
revert and a false APPROVAL_SUCCESS.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…heck

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kaladinlight
kaladinlight enabled auto-merge (squash) August 5, 2026 17:31
@kaladinlight
kaladinlight merged commit 43ce069 into develop Aug 5, 2026
4 checks passed
@kaladinlight
kaladinlight deleted the feat/swap-widget-approval-txs branch August 5, 2026 17:40
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