Skip to content

Correctly encode approval interactions for USDT-like tokens#4354

Merged
MartinquaXD merged 5 commits intomainfrom
handle-usdt-approvals
Apr 21, 2026
Merged

Correctly encode approval interactions for USDT-like tokens#4354
MartinquaXD merged 5 commits intomainfrom
handle-usdt-approvals

Conversation

@MartinquaXD
Copy link
Copy Markdown
Contributor

Description

Alternative to #4340

USDT is a bit special because it is one of very few tokens where the approve() function requires you to set the allowance back to 0 before you can alter it again to avoid a vulnerability (see here).

Changes

This PR adjusts the driver's approval encoding logic such that it checks whether the regular approve() call would revert. In case that happens it encodes an approve(0) and approve(desired_value) to be compatible with this security measure / quirk.
That way we support all those tokens on all chains without needing any extra configuration parameters or hardcoded values. The downside is 1 extra RPC call every time we have to increase an approval which is extremely rare so it's fine.

How to test

Converted an existing USDC -> USDT order fork test to be a USDT -> USDC test. This test fails without the PR's change.

@MartinquaXD MartinquaXD requested a review from a team as a code owner April 21, 2026 11:22
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the approvals logic to support tokens like USDT, which require resetting allowances to zero before they can be increased. It also updates the end-to-end tests to use USDT to validate this new behavior. Feedback was provided regarding the approvals implementation, specifically pointing out that the use of a HashMap for aggregation is redundant and introduces non-determinism. Furthermore, the logic should be corrected to avoid emitting an unnecessary approval interaction when the current on-chain allowance is already sufficient.

Comment thread crates/driver/src/domain/competition/solution/mod.rs Outdated
Comment thread crates/driver/src/domain/competition/solution/mod.rs Outdated
Comment thread crates/driver/src/domain/competition/solution/mod.rs Outdated
Comment thread crates/driver/src/domain/competition/solution/mod.rs Outdated
@MartinquaXD MartinquaXD enabled auto-merge April 21, 2026 11:57
@MartinquaXD MartinquaXD added this pull request to the merge queue Apr 21, 2026
Merged via the queue into main with commit 2c34db9 Apr 21, 2026
20 checks passed
@MartinquaXD MartinquaXD deleted the handle-usdt-approvals branch April 21, 2026 12:17
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants