-
Notifications
You must be signed in to change notification settings - Fork 148
Reimplement sell=buy PoC PR #3894
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
Open
m-sz
wants to merge
18
commits into
main
Choose a base branch
from
sell=buy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+727
−135
Open
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
89371f2
Reimplement sell=buy PoC PR
m-sz 3a1380e
Fix failing sell=buy test
m-sz 537c938
cleanup
m-sz 96150fb
cleanup comments
m-sz f2fffff
Feature flag for sell=buy
m-sz 83514a7
Rename liquidity_pairs to token_liquidity
m-sz 7e9c82c
Refactor Route and sell=buy validation control
m-sz 6fe22d1
Fix quote verification for sell=buy
m-sz 265cc6b
fmt
m-sz d3b0e27
Addressed comments
m-sz 0752dc9
Remove sell=buy test case already covered by onchain verification
m-sz 0139733
Remove the builder method for allowing same sell and buy token
m-sz e7333ce
Update crates/orderbook/src/arguments.rs
m-sz a6fbd5b
Update crates/shared/src/price_estimation/sanitized.rs
m-sz 778e283
Update crates/e2e/tests/e2e/place_order_with_quote.rs
m-sz 6a4e24c
Apply suggestion from @MartinquaXD
m-sz 9cd9996
Rename allow_same_sell_and_buy_token to disallow_...
m-sz 56b8971
Address comments
m-sz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,7 @@ use { | |
| }, | ||
| chrono::Utc, | ||
| ethrpc::alloy::conversions::IntoLegacy, | ||
| std::{ | ||
| collections::{HashMap, HashSet}, | ||
| iter, | ||
| }, | ||
| std::collections::{HashMap, HashSet}, | ||
| }; | ||
|
|
||
| /// A quote describing the expected outcome of an order. | ||
|
|
@@ -91,13 +88,13 @@ impl Order { | |
| liquidity: &infra::liquidity::Fetcher, | ||
| tokens: &infra::tokens::Fetcher, | ||
| ) -> Result<Quote, Error> { | ||
| let liquidity = match solver.liquidity() { | ||
| solver::Liquidity::Fetch => { | ||
| let liquidity = match (solver.liquidity(), self.token_liquidity()) { | ||
| (solver::Liquidity::Fetch, pairs) if !pairs.is_empty() => { | ||
| liquidity | ||
| .fetch(&self.liquidity_pairs(), infra::liquidity::AtBlock::Recent) | ||
| .fetch(&pairs, infra::liquidity::AtBlock::Recent) | ||
| .await | ||
| } | ||
| solver::Liquidity::Skip => Default::default(), | ||
| _ => Default::default(), | ||
| }; | ||
|
|
||
| let auction = self | ||
|
|
@@ -226,29 +223,23 @@ impl Order { | |
| } | ||
|
|
||
| /// Returns the token pairs to fetch liquidity for. | ||
| fn liquidity_pairs(&self) -> HashSet<liquidity::TokenPair> { | ||
| let pair = liquidity::TokenPair::try_new(self.tokens.sell(), self.tokens.buy()) | ||
| .expect("sell != buy by construction"); | ||
| iter::once(pair).collect() | ||
| fn token_liquidity(&self) -> HashSet<liquidity::TokenPair> { | ||
| liquidity::TokenPair::try_new(self.tokens.sell(), self.tokens.buy()) | ||
| .ok() | ||
| .into_iter() | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
| /// The sell and buy tokens to quote for. This type maintains the invariant that | ||
| /// the sell and buy tokens are distinct. | ||
| #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
| pub struct Tokens { | ||
| sell: eth::TokenAddress, | ||
| buy: eth::TokenAddress, | ||
| } | ||
|
|
||
| impl Tokens { | ||
| /// Creates a new instance of [`Tokens`], verifying that the input buy and | ||
| /// sell tokens are distinct. | ||
|
Comment on lines
-245
to
-246
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. I would like to get some feedback from solvers how they would expect this to work. Specifically to ask them about using the regular quoting logic vs. building something into the orderbook which only needs the native price of the tokens and a simulation to get the gas amount. |
||
| pub fn try_new(sell: eth::TokenAddress, buy: eth::TokenAddress) -> Result<Self, SameTokens> { | ||
| if sell == buy { | ||
| return Err(SameTokens); | ||
| } | ||
| Ok(Self { sell, buy }) | ||
| pub fn new(sell: eth::TokenAddress, buy: eth::TokenAddress) -> Self { | ||
| Self { sell, buy } | ||
| } | ||
|
|
||
| pub fn sell(&self) -> eth::TokenAddress { | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.