Skip to content

treat WETH->ETH as sametoken trade#4531

Merged
extrawurst merged 12 commits into
mainfrom
sametoken-no-volume-fee-wrapped-to-native-token
Jun 18, 2026
Merged

treat WETH->ETH as sametoken trade#4531
extrawurst merged 12 commits into
mainfrom
sametoken-no-volume-fee-wrapped-to-native-token

Conversation

@extrawurst

Copy link
Copy Markdown
Contributor

Skip volume fee on wrapped↔native (WETH→ETH) same-token trades

Same-token trades (sell_token == buy_token) already skip the volume fee unless enable_sell_equals_buy_volume_fee (off by default) is set. This extends "same-token" to native ETH buys: WETH → ETH (buy_token == BUY_ETH_ADDRESS) and the fee is dropped on both the quote and the settlement.

Changes

  • shared/fee.rs: get_applicable_volume_fee_factor takes native_token and skips the fee for the native same-token case.
  • model/order.rs: extracted is_same_buy_and_sell_token(sell, buy, native), reused by both the fee policy and order validation.
  • orderbook (QuoteHandler) and autopilot (ProtocolFees) thread native_token through so quote and settlement agree.

Tests

  • Unit: shared::fee::tests::test_same_token_volume_fee_skipped
  • E2E: local_node_volume_fee_{dropped_on_same_token, charged_on_same_token_when_enabled, dropped_on_wrapped_to_native_token}

where we drop the volume fee
@extrawurst extrawurst requested a review from a team as a code owner June 17, 2026 18:30
@claude

claude Bot commented Jun 17, 2026

Copy link
Copy Markdown

Claude encountered an error after 2m 31s —— View job


PR Review in progress

  • Read changed files & gather context
  • Analyze fee logic changes
  • Analyze order validation refactor
  • Analyze quoter & autopilot integration
  • Review tests
  • Post final review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@AryanGodara AryanGodara left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👌🏼

[nit]native_token could move onto VolumeFeePolicy itself, since both callers (ProtocolFees and QuoteHandler) already construct the policy with the chain's native token immediately after receiving it.

I tried this locally and it works, but is like a 2/10 refactor. So not pushing for it 😅

Tradeoff I think is binding the policy to a specific chain 🤔

@jmg-duarte jmg-duarte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

did you test this in staging? and shouldnt the unwraps not even be considered this kind of trade?

Comment thread crates/model/src/order.rs Outdated
Comment thread crates/model/src/order.rs
Comment thread crates/e2e/tests/e2e/protocol_fee.rs
Comment thread crates/shared/src/fee.rs Outdated
Comment thread crates/shared/src/fee.rs Outdated
Comment thread crates/e2e/tests/e2e/protocol_fee.rs Outdated
Comment thread crates/e2e/tests/e2e/protocol_fee.rs

@MartinquaXD MartinquaXD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Logic makes sense to me and test coverage is good.

Comment thread crates/autopilot/src/domain/fee/mod.rs Outdated
Comment thread crates/e2e/tests/e2e/protocol_fee.rs Outdated
@extrawurst

extrawurst commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

tested on base staging now:

{
  "quote": {
    "sellToken": "0x4200000000000000000000000000000000000006",
    "buyToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
    "receiver": null,
    "sellAmount": "999999359157841156",
    "buyAmount": "999999359157841156",
    "validTo": 1781791616,
    "appData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "feeAmount": "640842158844",
    "gasAmount": "115614",
    "gasPrice": "5542946",
    "sellTokenPrice": "1",
    "kind": "sell",
    "partiallyFillable": false,
    "sellTokenBalance": "erc20",
    "buyTokenBalance": "erc20",
    "signingScheme": "eip712"
  },
  "from": "...",
  "expiration": "2026-06-18T13:38:56.649238120Z",
  "id": 1114090,
  "verified": true
}

note: no protocolFeeBps as its null.

without my PR:

{
  "quote": {
    "sellToken": "0x4200000000000000000000000000000000000006",
    "buyToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
    "receiver": null,
    "sellAmount": "999999353643515812",
    "buyAmount": "999969353662906507",
    "validTo": 1781791860,
    "appData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "feeAmount": "646356484188",
    "gasAmount": "115614",
    "gasPrice": "5590642",
    "sellTokenPrice": "1",
    "kind": "sell",
    "partiallyFillable": false,
    "sellTokenBalance": "erc20",
    "buyTokenBalance": "erc20",
    "signingScheme": "eip712"
  },
  "from": "...",
  "expiration": "2026-06-18T13:43:00.668009912Z",
  "id": 1114153,
  "verified": true,
  "protocolFeeBps": "0.3"
}

@extrawurst extrawurst added this pull request to the merge queue Jun 18, 2026
Merged via the queue into main with commit b0cccb1 Jun 18, 2026
21 checks passed
@extrawurst extrawurst deleted the sametoken-no-volume-fee-wrapped-to-native-token branch June 18, 2026 13:53
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 18, 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.

4 participants