-
Notifications
You must be signed in to change notification settings - Fork 162
Simulate EIP-1271 orders at creation #4355
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
base: main
Are you sure you want to change the base?
Changes from 37 commits
6897fec
4d63688
7eb008b
3d074e4
d68cb90
f0af347
bd51ed8
5c6e8d2
557ae35
6e7ee7a
1733fb2
af31a39
65a0290
a37c7a0
9c93de6
f5ddba5
cebd99b
67a4d32
2fbf9f0
a781c44
d11442e
eca5c61
5407c8b
eed5990
2785108
7281ded
3525684
191d7ff
e62217c
4c25c46
250f5da
c51a522
7bd2592
ea11e37
ebfd4a9
06c478a
490bcdc
fbe765c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| use { | ||
| crate::order_simulator::{self, OrderSimulator}, | ||
| async_trait::async_trait, | ||
| model::order::Order, | ||
| shared::order_validation::{Eip1271Simulating, Eip1271SimulationError}, | ||
| std::sync::Arc, | ||
| }; | ||
|
|
||
| /// Adapter exposing `OrderSimulator` via the | ||
| /// `shared::order_validation::Eip1271Simulating` trait. | ||
| /// | ||
| /// This is a temporary shim. Once the `simulator` crate is refactored to own | ||
| /// `OrderSimulator`, `OrderValidator` can depend on it directly and this | ||
| /// adapter can be deleted. | ||
| pub struct OrderSimulatorAdapter { | ||
| inner: Arc<OrderSimulator>, | ||
| } | ||
|
|
||
| impl OrderSimulatorAdapter { | ||
| pub fn new(inner: Arc<OrderSimulator>) -> Self { | ||
| Self { inner } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl Eip1271Simulating for OrderSimulatorAdapter { | ||
| async fn simulate(&self, order: &Order) -> Result<(), Eip1271SimulationError> { | ||
| let swap = self.inner.encode_order(order, Vec::new(), None).await?; | ||
|
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. How does this logic work for Aave orders that require a flashloan and are routed via the FlashloanWrapper contract instead of directly via GPv2Settlement? If we don't pass in any wrappers here, how will it encode the transaction in a way that simulation can pass? Is there a way we can test this case in our existing Aave integration test?
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. Other simulations side stepped the flashloan aspect by using state overrides to make the sell_tokens appear. But I also can't find this logic in the current PR. |
||
| let result = self.inner.simulate_swap(swap, None).await?; | ||
| match result.error { | ||
| Some(reason) => Err(Eip1271SimulationError::Reverted { | ||
| reason, | ||
| tenderly_url: result.tenderly_url, | ||
| }), | ||
| None => Ok(()), | ||
| } | ||
|
squadgazzz marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| impl From<order_simulator::Error> for Eip1271SimulationError { | ||
| fn from(err: order_simulator::Error) -> Self { | ||
| match err { | ||
| order_simulator::Error::Other(e) | order_simulator::Error::MalformedInput(e) => { | ||
| Self::Infra(e) | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Shouldn't this be part of either the configs crate or the order simulator?
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.
It is in configs, this is the enum you're commenting on. The copy in shared::order_validation is only there because OrderValidator lives in shared and shared can't depend on configs, so we mirror plus convert at the call site in run.rs. Once Martin's simulator refactor lands and OrderSimulator moves out of orderbook, we can probably collapse both into one enum.