pub struct TradeSimulator { /* private fields */ }Expand description
Simulates settlement execution to estimate gas costs and detect reverts.
Wraps a reqwest::Client targeting a JSON-RPC endpoint and the canonical
GPv2Settlement contract on a specific chain.
§Example
use cow_chains::SupportedChainId;
use cow_settlement::simulator::TradeSimulator;
let sim = TradeSimulator::new("https://rpc.sepolia.org", SupportedChainId::Sepolia);Implementations§
Source§impl TradeSimulator
impl TradeSimulator
Sourcepub fn new(
rpc_url: impl Into<String>,
chain: SupportedChainId,
) -> TradeSimulator
pub fn new( rpc_url: impl Into<String>, chain: SupportedChainId, ) -> TradeSimulator
Create a new trade simulator for the given chain.
Uses the canonical GPv2Settlement contract address for chain.
§Arguments
rpc_url- The JSON-RPC endpoint URL.chain- The targetSupportedChainId.
§Returns
A new TradeSimulator configured for the specified chain.
Sourcepub const fn settlement_address(&self) -> Address
pub const fn settlement_address(&self) -> Address
Sourcepub async fn estimate_gas(&self, calldata: &[u8]) -> Result<u64, CowError>
pub async fn estimate_gas(&self, calldata: &[u8]) -> Result<u64, CowError>
Estimate the gas cost of executing calldata against the settlement contract.
Sends an eth_estimateGas JSON-RPC request with the provided calldata
targeting the settlement contract.
§Arguments
calldata- The ABI-encoded calldata to estimate gas for.
§Returns
The estimated gas as u64.
§Errors
Returns CowError::Rpc if the RPC request fails or the node returns
an error (e.g., the transaction would revert).
Sourcepub async fn simulate(
&self,
calldata: &[u8],
) -> Result<SimulationResult, CowError>
pub async fn simulate( &self, calldata: &[u8], ) -> Result<SimulationResult, CowError>
Simulate executing calldata against the settlement contract via eth_call.
Unlike estimate_gas, this method does not fail on
reverts — instead it returns a SimulationResult indicating whether the
call succeeded or reverted.
§Arguments
calldata- The ABI-encoded calldata to simulate.
§Returns
A SimulationResult with success status, gas estimate, and return data.
§Errors
Returns CowError::Rpc only on transport-level failures (HTTP errors).
Execution reverts are captured in the returned SimulationResult.
Sourcepub async fn estimate_settlement(
&self,
encoder: &SettlementEncoder,
) -> Result<u64, CowError>
pub async fn estimate_settlement( &self, encoder: &SettlementEncoder, ) -> Result<u64, CowError>
Convenience method: encode a settlement and estimate its gas cost.
Combines SettlementEncoder::encode_settlement with
estimate_gas.
§Arguments
encoder- TheSettlementEncodercontaining the settlement to estimate.
§Returns
The estimated gas as u64.
§Errors
Returns CowError::Rpc if the RPC request fails or the settlement
would revert.
Trait Implementations§
Source§impl Clone for TradeSimulator
impl Clone for TradeSimulator
Source§fn clone(&self) -> TradeSimulator
fn clone(&self) -> TradeSimulator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TradeSimulator
impl !RefUnwindSafe for TradeSimulator
impl Send for TradeSimulator
impl Sync for TradeSimulator
impl Unpin for TradeSimulator
impl UnsafeUnpin for TradeSimulator
impl !UnwindSafe for TradeSimulator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more