Skip to content

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

Open
kaladinlight wants to merge 3 commits into
developfrom
feat/swap-widget-approval-txs
Open

feat(swap-widget): broadcast api-supplied approval txs#12518
kaladinlight wants to merge 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

Populate approval.approvalTxs on the quote response: ready-to-sign
exact-amount approve transactions in broadcast order, with a preceding
approve(spender, 0) when the token requires resetting a non-zero
allowance before changing it (USDT-style, detected by simulating the
approve as the owner - no token list). Replaces the never-populated
singular approvalTx field.

Expose the first-hop allowanceContract on rates so clients can check or
set allowances manually before quoting.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@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

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 514943e2-c80b-4b1e-8e82-be269636bea8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 and others added 2 commits August 3, 2026 16:25
Probe via simulateContract so a token whose approve() fulfills but
returns false also lands on the reset side (return-less tokens reject
decoding and do too). Docs no longer claim every swap needs a fresh
approval - approvalTxs is empty when the current allowance covers the
amount.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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/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
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