-
Notifications
You must be signed in to change notification settings - Fork 162
[feature] implement unified order simulation logic #4127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
theghostmac
wants to merge
11
commits into
cowprotocol:main
from
theghostmac:feature/unified-order-simulation
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
136bf4a
[feature] unified order simulation logic
theghostmac 5663f34
[feature] implemented unified order simulation with state overrides
theghostmac c6db361
[feature] integrate order execution simulator into quoter factory
theghostmac 83939cc
[nit] remove unused import
theghostmac a4345bf
[fixes] fix order simulation edge cases
theghostmac fa36168
[feature] integrate order execution simulator into orderbook and auto…
theghostmac 8a71c59
[fix] accept gemini review suggestion
theghostmac 5e1d510
[refactor] move OrderExecutionSimulation to shared/src for high visib…
theghostmac a0d77b0
[refactor] implemented the interaction handling in order_quoting, plu…
theghostmac 2419ed0
[refactor] add post_interactions support in order simulation
theghostmac 1f0d30b
[feature] implemented flashload and wrapper support in OrderExecution…
theghostmac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,13 @@ | ||
| use { | ||
| super::price_estimation::{ | ||
| self, | ||
| PriceEstimating, | ||
| PriceEstimationError, | ||
| native::NativePriceEstimating, | ||
| self, PriceEstimating, PriceEstimationError, native::NativePriceEstimating, | ||
| }, | ||
| crate::{ | ||
| account_balances::{BalanceFetching, Query}, | ||
| db_order_conversions::order_kind_from, | ||
| fee::FeeParameters, | ||
| gas_price_estimation::GasPriceEstimating, | ||
| order_simulation::OrderExecutionSimulating, | ||
| order_validation::PreOrderData, | ||
| price_estimation::{Estimate, QuoteVerificationMode, Verification}, | ||
| trade_finding::external::dto, | ||
|
|
@@ -391,13 +389,13 @@ impl Now for DateTime<Utc> { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Eq, PartialEq)] | ||
| pub struct Validity { | ||
| pub eip1271_onchain_quote: Duration, | ||
| pub presign_onchain_quote: Duration, | ||
| pub standard_quote: Duration, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| impl Default for Validity { | ||
| fn default() -> Self { | ||
| Self { | ||
|
|
@@ -418,6 +416,8 @@ pub struct OrderQuoter { | |
| validity: Validity, | ||
| balance_fetcher: Arc<dyn BalanceFetching>, | ||
| quote_verification: QuoteVerificationMode, | ||
| #[allow(dead_code)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not used? |
||
| order_execution_simulator: Arc<dyn OrderExecutionSimulating>, | ||
| default_quote_timeout: std::time::Duration, | ||
| } | ||
|
|
||
|
|
@@ -431,6 +431,7 @@ impl OrderQuoter { | |
| validity: Validity, | ||
| balance_fetcher: Arc<dyn BalanceFetching>, | ||
| quote_verification: QuoteVerificationMode, | ||
| order_execution_simulator: Arc<dyn OrderExecutionSimulating>, | ||
| default_quote_timeout: std::time::Duration, | ||
| ) -> Self { | ||
| Self { | ||
|
|
@@ -442,6 +443,7 @@ impl OrderQuoter { | |
| validity, | ||
| balance_fetcher, | ||
| quote_verification, | ||
| order_execution_simulator, | ||
| default_quote_timeout, | ||
| } | ||
| } | ||
|
|
@@ -782,19 +784,19 @@ pub struct QuoteMetadataV1 { | |
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::order_simulation::SimulationOptions; | ||
|
|
||
| use { | ||
| super::*, | ||
| crate::{ | ||
| account_balances::MockBalanceFetching, | ||
| gas_price_estimation::FakeGasPriceEstimator, | ||
| price_estimation::{ | ||
| HEALTHY_PRICE_ESTIMATION_TIME, | ||
| MockPriceEstimating, | ||
| HEALTHY_PRICE_ESTIMATION_TIME, MockPriceEstimating, | ||
| native::MockNativePriceEstimating, | ||
| }, | ||
| }, | ||
| Address, | ||
| U256 as AlloyU256, | ||
| Address, U256 as AlloyU256, | ||
| alloy::eips::eip1559::Eip1559Estimation, | ||
| chrono::Utc, | ||
| futures::FutureExt, | ||
|
|
@@ -803,6 +805,19 @@ mod tests { | |
| number::nonzero::NonZeroU256, | ||
| }; | ||
|
|
||
| struct FakeOrderExecutionSimulator; | ||
| #[async_trait::async_trait] | ||
| impl OrderExecutionSimulating for FakeOrderExecutionSimulator { | ||
| async fn simulate_order_execution( | ||
| &self, | ||
| _: &model::order::Order, | ||
| _: &model::DomainSeparator, | ||
| _: SimulationOptions, | ||
| ) -> Result<()> { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| fn mock_balance_fetcher() -> Arc<dyn BalanceFetching> { | ||
| let mut mock = MockBalanceFetching::new(); | ||
| mock.expect_get_balances() | ||
|
|
@@ -938,6 +953,7 @@ mod tests { | |
| validity: super::Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1078,6 +1094,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1213,6 +1230,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1311,6 +1329,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1384,6 +1403,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1445,6 +1465,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1528,6 +1549,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1613,6 +1635,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1686,6 +1709,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
@@ -1717,6 +1741,7 @@ mod tests { | |
| validity: Validity::default(), | ||
| quote_verification: QuoteVerificationMode::Unverified, | ||
| balance_fetcher: mock_balance_fetcher(), | ||
| order_execution_simulator: Arc::new(FakeOrderExecutionSimulator), | ||
| default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME, | ||
| }; | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that
there is tenderly but its easier to read than thinking twice what thetis