Skip to content

Conversation

@m-sz
Copy link
Contributor

@m-sz m-sz commented Feb 10, 2026

Description

driver contains simulation logic that would benefit other initiatives if it were reusable:

  • Order simulation endpoint could be implemented in orderbook
  • Proper gas estimation for txs could be implemented by exposing a simulation endpoint in the driver

The logic in the driver is heavily intertwined with foundational domain and infra types, so I have made several attempts at cleanly refactoring the simulation logic to a separate crate. This is the smallest in the scope that provides with clear-cut separation of the simulator for it to be reviewable.

This can be further improved in follow-up PRs by:

  • Unifying the RPC and Ethereum related types across driver, simulator and potentially other crates
  • Unifying contracts, GasPriceEstimator, Erc20, infra::blockchain, token types across driver and simulator
  • Organising driver Config so there is no need to convert it's subset to simulator's Config

The above have been intentionally out of scope of this PR to keep it maneagable.

Changes

  • Factored out simulators to simulator crate
  • Factored out domain::eth, util::{Bytes, serialize}, into shared crate for reuse
  • Performed rudimentary conversion in the driver to adapt for simulator's types

How to test

This is purely a refactor, it is expected to be consistent with previous behavior.

  • Passes local e2e tests
  • [] Works well on staging

@m-sz m-sz requested a review from a team as a code owner February 10, 2026 18:23
Copy link
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 refactors the simulation logic from the driver crate into a new, reusable simulator crate, and moves shared domain and utility types into the shared crate. The changes are extensive but mostly consist of moving code and updating imports. I've identified a logic error in the error handling within the new simulator library, where non-revertible blockchain errors were incorrectly classified as transaction reverts. The provided review comment addresses this issue.

SimulatorError::Tenderly(tenderly::Error::Revert(_)) => Some(tx),
SimulatorError::Tenderly(provider::tenderly::Error::Http(_)) => None,
SimulatorError::Tenderly(provider::tenderly::Error::Revert(_)) => Some(tx),
SimulatorError::Blockchain(_) => Some(tx),
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current implementation incorrectly classifies all SimulatorError::Blockchain errors as revertible transaction errors. This includes errors like gas price estimation failures, which are not transaction reverts. This can lead to valid solutions being incorrectly discarded. The is_revert() method on blockchain::Error should be used to correctly classify the error.

Suggested change
SimulatorError::Blockchain(_) => Some(tx),
SimulatorError::Blockchain(err) => if err.is_revert() { Some(tx) } else { None },

Copy link
Contributor

@jmg-duarte jmg-duarte left a comment

Choose a reason for hiding this comment

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

IMO some of the extractions here should be one in a separate PR to reduce tech debt and reduce the size of this PR too

m-sz added 5 commits February 11, 2026 14:36
The module exports and provides only Web3 types wrapping ethrpc crate,
thus the new name is more fitting and avoids the need to rename imports
if importing ethrpc and shared::ethrpc together.
@m-sz
Copy link
Contributor Author

m-sz commented Feb 11, 2026

Moved refactoring of common types to #4142. This PR will be rebased and thus easier to review.

@m-sz m-sz force-pushed the simulator-refactor branch from d67034c to f5cb342 Compare February 11, 2026 15:27
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.

2 participants