Skip to content

Conversation

@pranay123-stack
Copy link

Summary

  • Adds an early return in POSITIVE_SLIPPAGE action when maxBps == 0 to explicitly skip surplus capture
  • Updates both SettlerBase.sol and Mainnet/Common.sol (which has a duplicate implementation)
  • Adds NatSpec documentation to ISettlerActions.sol explaining the behavior

Problem

Fee-on-transfer tokens like ECOIN have internal mechanics (e.g., automatic fee redistribution or internal swaps) that can deposit extra tokens into the Settler contract during a swap. The POSITIVE_SLIPPAGE action was incorrectly capturing these internally-generated tokens as "surplus", redirecting funds that were meant for the token's administrative wallet.

Solution

When maxBps is set to 0, the POSITIVE_SLIPPAGE action now returns early without attempting to capture any surplus. This allows the 0x API to explicitly disable surplus capture for fee-on-transfer tokens.

Note: The existing logic would result in no transfer when maxBps = 0 (since cap = 0), but this explicit early return:

  1. Makes the behavior clearer and more intentional
  2. Saves gas by avoiding unnecessary balance checks
  3. Provides clear documentation for API integrators

Test plan

  • Build passes: forge build --skip MultiCall.sol --skip CrossChainReceiverFactory.sol --skip 'test/*'
  • Run unit tests to verify no regression
  • Verify that setting maxBps = 0 skips surplus capture entirely
  • Test with fee-on-transfer tokens to confirm internal token mechanics are no longer captured

API Integration Note

After this fix is deployed, the 0x API should set maxBps = 0 when generating POSITIVE_SLIPPAGE actions for known fee-on-transfer tokens to prevent incorrect surplus capture.

Fixes #346

🤖 Generated with Claude Code

@immunefi-magnus
Copy link

🛡️ Immunefi PR Reviews

We noticed that your project isn't set up for automatic code reviews. If you'd like this PR reviewed by the Immunefi team, you can request it manually using the link below:

🔗 Send this PR in for review

Once submitted, we'll take care of assigning a reviewer and follow up here.

This fixes an issue where fee-on-transfer tokens with internal mechanics
(e.g., automatic fee redistribution or internal swaps) could have their
internal token movements incorrectly captured as surplus by the
POSITIVE_SLIPPAGE action.

When maxBps is set to 0, the POSITIVE_SLIPPAGE action now returns early
without attempting to capture any surplus. This allows the 0x API to
explicitly disable surplus capture for fee-on-transfer tokens that may
deposit extra tokens into the Settler contract during a swap.

Fixes 0xProject#346
@pranay123-stack pranay123-stack force-pushed the fix/skip-surplus-for-fot-tokens branch from 1381ea3 to b177a29 Compare January 3, 2026 15:51
@duncancmt
Copy link
Collaborator

Hello!

Unfortunately, I can't merge this PR for a couple reasons:

  • We don't accept AI-generated PRs without review on the part of the human who opened the PR.
  • Issue Surplus Logic Intercepts Internal Token Swaps Meant for Administrative Wallet #346 is incorrect and should have been closed. The analysis presented there is incorrect and Settler needs no patching to address it.
  • This feature needlessly introduces complexity. The POSITIVE_SLIPPAGE action could simply be omitted to obtain the same functionality.

For these reasons, I am closing this PR. Please feel free to submit a new PR if you find any additional issues. We appreciate your contributions!

@duncancmt duncancmt closed this Jan 4, 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.

Surplus Logic Intercepts Internal Token Swaps Meant for Administrative Wallet

2 participants