fix: Skip surplus capture when maxBps is 0 for fee-on-transfer tokens #461
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
POSITIVE_SLIPPAGEaction whenmaxBps == 0to explicitly skip surplus captureSettlerBase.solandMainnet/Common.sol(which has a duplicate implementation)ISettlerActions.solexplaining the behaviorProblem
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_SLIPPAGEaction was incorrectly capturing these internally-generated tokens as "surplus", redirecting funds that were meant for the token's administrative wallet.Solution
When
maxBpsis set to0, thePOSITIVE_SLIPPAGEaction 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(sincecap = 0), but this explicit early return:Test plan
forge build --skip MultiCall.sol --skip CrossChainReceiverFactory.sol --skip 'test/*'maxBps = 0skips surplus capture entirelyAPI Integration Note
After this fix is deployed, the 0x API should set
maxBps = 0when generatingPOSITIVE_SLIPPAGEactions for known fee-on-transfer tokens to prevent incorrect surplus capture.Fixes #346
🤖 Generated with Claude Code