-
Notifications
You must be signed in to change notification settings - Fork 93
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
Use blocks to determine other environment settlements #3053
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8fdccbe
Use blocks to determine other environments
sunce86 4c8de8c
missing block
sunce86 092eb7b
Use chain to determine max settlement age
sunce86 121d463
fix values
sunce86 9ae0295
Merge branch 'main' into detect-settlements-from-other-environments
sunce86 bfc633a
update chain id accessibility
sunce86 6259fb8
pretty format
sunce86 cf94132
refactor settlement age
sunce86 85e916c
move chain to infra
sunce86 1f863f9
small rename
sunce86 30d9648
Merge branch 'main' into detect-settlements-from-other-environments
sunce86 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 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 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 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use primitive_types::U256; | ||
|
||
/// A supported Ethereum Chain ID. | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum ChainId { | ||
Mainnet = 1, | ||
Gnosis = 100, | ||
Sepolia = 11155111, | ||
ArbitrumOne = 42161, | ||
} | ||
|
||
impl ChainId { | ||
pub fn new(value: U256) -> Result<Self, UnsupportedChain> { | ||
// Check to avoid panics for large `U256` values, as there is no checked | ||
// conversion API available and we don't support chains with IDs greater | ||
// than `u64::MAX` anyway. | ||
if value > U256::from(u64::MAX) { | ||
return Err(UnsupportedChain); | ||
} | ||
|
||
match value.as_u64() { | ||
1 => Ok(Self::Mainnet), | ||
100 => Ok(Self::Gnosis), | ||
11155111 => Ok(Self::Sepolia), | ||
42161 => Ok(Self::ArbitrumOne), | ||
_ => Err(UnsupportedChain), | ||
} | ||
} | ||
|
||
/// Returns the network ID for the chain. | ||
pub fn network_id(self) -> &'static str { | ||
match self { | ||
ChainId::Mainnet => "1", | ||
ChainId::Gnosis => "100", | ||
ChainId::Sepolia => "11155111", | ||
ChainId::ArbitrumOne => "42161", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
#[error("unsupported chain")] | ||
pub struct UnsupportedChain; |
This file contains 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 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 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 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 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 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 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.
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.
Maybe not to do in this PR, but we have logic depending on the chain id scattered all over the place. Maybe it could be unified in one place, and implement all functions related to the chain (e.i.
default_amount_to_estimate_native_prices_with()
)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 am not against it. Although I think we agreed somewhere that we are fine with some level of code duplication to avoid sharing too much code between autopilot, driver, solvers etc, and to support DDD way of organizing code.
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.
Yes, but for this particular case I think it comes handy. So, in the future, if we were to support more networks, it is all in one place.
But no need for action in this PR, I just wanted to open the debate. This is something I want to do in the upcoming weeks.
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.
In that case, I'd suggest opening an issue for this (if we don't have it already). Some people might want to discuss it further. 👍