Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/orderbook/src/order_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl OrderSimulator {
self.chain_id.clone(),
&result.tx,
result.overrides,
Some(BlockNo(block_number)),
BlockNo(block_number),
)
.map_err(|err| Error::Other(anyhow!(err)))?
};
Expand Down
9 changes: 7 additions & 2 deletions crates/price-estimation/src/trade_verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ impl TradeVerifier {
&self.simulator.domain_separator,
)?);
}
let output = self.simulator.simulate_swap_with_solver(swap).await?;
let block = *self.simulator.current_block.borrow();
let output = self
.simulator
.simulate_swap_with_solver(swap, block)
.await?;

if let Some(tenderly) = &self.tenderly
&& let Err(err) = tenderly.log_simulation_command(output.tx, output.overrides, None)
&& let Err(err) =
tenderly.log_simulation_command(output.tx, output.overrides, block.number.into())
{
tracing::debug!(?err, "could not log tenderly simulation command");
}
Expand Down
14 changes: 11 additions & 3 deletions crates/simulator/src/swap_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use {
support::Solver::{self, Solver::swapReturn},
},
eth_domain_types::NonZeroU256,
ethrpc::{Web3, block_stream::CurrentBlockWatcher},
ethrpc::{
Web3,
block_stream::{BlockInfo, CurrentBlockWatcher},
},
model::{
DomainSeparator,
order::{BUY_ETH_ADDRESS, BuyTokenDestination, OrderData, OrderKind, SellTokenSource},
Expand Down Expand Up @@ -192,12 +195,16 @@ impl SwapSimulator {
/// Simulates a solver call to settlement contract with the provided swap
/// data. The swap call result is contained in the returned
/// SwapSimulation struct, along with the original TransactionRequest
/// and State overrides (if needed to be logged, or processed elsewhere)
/// and State overrides (if needed to be logged, or processed elsewhere).
///
/// The caller supplies the `block` so the gas-price computation, the
/// pinned `.call()` block, and any downstream logging all reference the
/// same snapshot of chain state.
pub async fn simulate_swap_with_solver(
&self,
swap: EncodedSwap,
block: BlockInfo,
) -> Result<SwapSimulation<swapReturn>> {
let block = *self.current_block.borrow();
let (settlement_target, calldata) = self.get_target_and_calldata(&swap);
let solver = Solver::Instance::new(swap.solver, self.web3.provider.clone());
let overrides = swap.overrides;
Expand All @@ -224,6 +231,7 @@ impl SwapSimulator {
let result = swap
.call()
.overrides(overrides.clone())
.block(block.number.into())
.await
.map_err(|err| anyhow!(err))
.context("failed to simulate swap");
Expand Down
12 changes: 6 additions & 6 deletions crates/simulator/src/tenderly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait Api: Send + Sync + 'static {
&self,
tx: TransactionRequest,
overrides: StateOverride,
block: Option<BlockNo>,
block: BlockNo,
) -> Result<()>;

async fn simulate(&self, request: dto::Request) -> Result<dto::Response>;
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Tenderly {
self.eth.chain().id().to_string(),
&tx,
Default::default(),
Some(block),
block,
)?
};

Expand Down Expand Up @@ -162,7 +162,7 @@ impl Api for TenderlyApi {
&self,
tx: TransactionRequest,
overrides: StateOverride,
block: Option<BlockNo>,
block: BlockNo,
) -> Result<()> {
let request = dto::Request {
save: Some(true),
Expand Down Expand Up @@ -215,10 +215,10 @@ pub fn prepare_request(
chain_id: String,
tx: &TransactionRequest,
overrides: StateOverride,
block: Option<BlockNo>,
block: BlockNo,
) -> Result<dto::Request, Error> {
Ok(dto::Request {
block_number: block.map(|block| block.0),
block_number: Some(block.0),
// By default, tenderly simulates on the top of the specified block, whereas regular
// nodes simulate at the end of the specified block. This is to make
// simulation results match in case critical state changed within the block.
Expand Down Expand Up @@ -319,7 +319,7 @@ impl Api for Instrumented {
&self,
tx: TransactionRequest,
overrides: StateOverride,
block: Option<BlockNo>,
block: BlockNo,
) -> Result<()> {
self.inner.log_simulation_command(tx, overrides, block)
}
Expand Down
Loading