-
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
base: main
Are you sure you want to change the base?
Changes from all commits
89371f2
3a1380e
537c938
96150fb
f2fffff
83514a7
7e9c82c
6fe22d1
265cc6b
d3b0e27
0752dc9
0139733
e7333ce
a6fbd5b
778e283
6a4e24c
9cd9996
56b8971
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 |
|---|---|---|
|
|
@@ -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.
Contributor
Author
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. That's a good idea, I will ask them. |
||
| 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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.