Skip to content

fix(simulation): charge forward overhead on signed exclusive Ekubo pools - #1257

Merged
tamaralipows merged 4 commits into
mainfrom
tnl/ekubo-signed-swap-gas
Aug 3, 2026
Merged

tamaralipows merged 4 commits into
mainfrom
tnl/ekubo-signed-swap-gas

Conversation

@tamaralipows

@tamaralipows tamaralipows commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

A SignedExclusiveSwap pool reverts in beforeSwap, so every swap goes through Core.forward with a signature to recover and a nonce to write. The curve math is identical either way, so the simulated gas missed all of it and an exclusive route was costed as a direct swap.

The number

Measured in Ekubo's harness (SignedExclusiveSwap.t.sol, --isolate), adding a plain-swap baseline so the lock, settle, fee, tick spacing, position and amount match on both sides:

case gas
plain swap 81,139
signed, zero fee 118,991
signed, non-zero fee 143,512

forward + signature = 37,852; fee accounting = 24,521. The constant is the non-zero-fee delta, 62,373 — Fynd normally signs a fee above zero, and erring high is the safe direction.

Why here, not the estimator

estimate_gas_usage documents the split: pool gas comes from get_amount_out; the estimator adds only what get_amount_out cannot see (transfers, approvals, router). This overhead is inside the pool call, and the estimator adds group.estimated_gas to its own total, so it flows through either way. Execution's per-protocol lists classify token movement, not pool execution cost.

Happy to move it if you'd rather all gas accounting live in the estimator — that needs an address in protocol_specific_addresses.json and a chain param on a public function.

Impact

Fynd uses output net of gas both to select exclusive routes and to set the taker's committed amount, so understating it biases against the taker twice. ~19 bps on a $1,000 trade at 10 gwei.

Dormant until SIGNED_EXCLUSIVE_SWAP_ADDRESS is the deployed address. Found via fynd#365; tracks ENG-6283.

🤖 Generated with Claude Code

@louise-poole louise-poole left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes sense. Looks good to me 👍

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Tycho Jul 31, 2026
Comment thread crates/tycho-simulation/src/evm/protocol/ekubo_v3/state.rs Outdated

@Troshchk Troshchk 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.

Thank youuu ✨

tamaralipows and others added 4 commits August 3, 2026 12:19
A SignedExclusiveSwap pool reverts in beforeSwap, so every swap on it goes
through Core.forward with a signature the extension recovers and a nonce it
writes. The concentrated math is identical either way, so the simulated gas
missed the whole overhead and an exclusive route was costed as a direct swap.

Measured at 62373 in Ekubo's own harness against a plain-swap baseline added
alongside the existing signed cases, so lock, settle, fee, tick spacing,
position and amount match on both sides.
cargo fmt ran on stable, but this repo formats with nightly, so the whole crate
was reformatted. Restores every file except the one this branch changes.
The constant is the non-zero-fee delta: `forward` plus the signature
check is 37,852 and charging the signed fee is another 24,521.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tamaralipows
tamaralipows force-pushed the tnl/ekubo-signed-swap-gas branch from d911145 to 9347bfb Compare August 3, 2026 16:19
@tamaralipows
tamaralipows enabled auto-merge August 3, 2026 16:20
@tamaralipows
tamaralipows merged commit 38343c3 into main Aug 3, 2026
28 checks passed
@tamaralipows
tamaralipows deleted the tnl/ekubo-signed-swap-gas branch August 3, 2026 16:23
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Tycho Aug 3, 2026
propellerci Bot pushed a commit that referenced this pull request Aug 3, 2026
## [0.348.2](0.348.1...0.348.2) (2026-08-03)

### Bug Fixes

* **simulation:** charge forward overhead on signed exclusive Ekubo pools ([4d586c6](4d586c6))
* **simulation:** charge forward overhead on signed exclusive Ekubo pools ([#1257](#1257)) ([38343c3](38343c3))
@propellerci

propellerci Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This PR is included in version 0.348.2 🎉

@propellerci propellerci Bot added the true label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants