forked from marktoda/uniswapx-artemis
-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: skip reprocessing event if already seen; also bunch of small optimizations #20
Open
ConjunctiveNormalForm
wants to merge
7
commits into
main
Choose a base branch
from
skip-reprocessing-event
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.
+124
−143
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e39a769
prefer impl From than Into
ConjunctiveNormalForm dbea1ae
favor impl'ing Display than ToString
ConjunctiveNormalForm 57f78de
use built-in strip_prefix
ConjunctiveNormalForm 9faa179
is_some()
ConjunctiveNormalForm 1911a37
unsless referencing, &String copying, etc
ConjunctiveNormalForm b926203
typo
ConjunctiveNormalForm 65ae346
cargo fmt
ConjunctiveNormalForm 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,115 @@ | ||
pub mod cloudwatch_utils { | ||
|
||
/// Constants for dimension names and values | ||
pub const EXECUTOR_DIMENSION: &str = "Executor"; | ||
pub const PRIORITY_EXECUTOR: &str = "PriorityExecutor"; | ||
pub const V2_EXECUTOR: &str = "V2Executor"; | ||
|
||
/// Constants for metric names | ||
pub const TX_SUCCEEDED_METRIC: &str = "TransactionSucceeded"; | ||
pub const TX_REVERTED_METRIC: &str = "TransactionReverted"; | ||
pub const TX_SUBMITTED_METRIC: &str = "TransactionSubmitted"; | ||
pub const TX_STATUS_UNKNOWN_METRIC: &str = "TransactionStatusUnknown"; | ||
|
||
pub enum DimensionName { | ||
Executor, | ||
} | ||
impl AsRef<str> for DimensionName { | ||
fn as_ref(&self) -> &str { | ||
match self { | ||
DimensionName::Executor => PRIORITY_EXECUTOR, | ||
} | ||
/// Constants for dimension names and values | ||
pub const EXECUTOR_DIMENSION: &str = "Executor"; | ||
pub const PRIORITY_EXECUTOR: &str = "PriorityExecutor"; | ||
pub const V2_EXECUTOR: &str = "V2Executor"; | ||
|
||
/// Constants for metric names | ||
pub const TX_SUCCEEDED_METRIC: &str = "TransactionSucceeded"; | ||
pub const TX_REVERTED_METRIC: &str = "TransactionReverted"; | ||
pub const TX_SUBMITTED_METRIC: &str = "TransactionSubmitted"; | ||
pub const TX_STATUS_UNKNOWN_METRIC: &str = "TransactionStatusUnknown"; | ||
|
||
pub enum DimensionName { | ||
Executor, | ||
} | ||
impl AsRef<str> for DimensionName { | ||
fn as_ref(&self) -> &str { | ||
match self { | ||
DimensionName::Executor => PRIORITY_EXECUTOR, | ||
} | ||
} | ||
} | ||
|
||
impl Into<String> for DimensionName { | ||
fn into(self) -> String { | ||
match self { | ||
DimensionName::Executor => EXECUTOR_DIMENSION.to_string(), | ||
} | ||
impl From<DimensionName> for String { | ||
fn from(dimension: DimensionName) -> Self { | ||
match dimension { | ||
DimensionName::Executor => EXECUTOR_DIMENSION.to_string(), | ||
} | ||
} | ||
} | ||
|
||
pub enum DimensionValue { | ||
PriorityExecutor, | ||
V2Executor, | ||
} | ||
|
||
impl Into<String> for DimensionValue { | ||
fn into(self) -> String { | ||
match self { | ||
DimensionValue::PriorityExecutor => PRIORITY_EXECUTOR.to_string(), | ||
DimensionValue::V2Executor => V2_EXECUTOR.to_string(), | ||
} | ||
pub enum DimensionValue { | ||
PriorityExecutor, | ||
V2Executor, | ||
} | ||
impl From<DimensionValue> for String { | ||
fn from(value: DimensionValue) -> Self { | ||
match value { | ||
DimensionValue::PriorityExecutor => PRIORITY_EXECUTOR.to_string(), | ||
DimensionValue::V2Executor => V2_EXECUTOR.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl AsRef<str> for DimensionValue { | ||
fn as_ref(&self) -> &str { | ||
match self { | ||
DimensionValue::PriorityExecutor => PRIORITY_EXECUTOR, | ||
DimensionValue::V2Executor => V2_EXECUTOR, | ||
} | ||
impl AsRef<str> for DimensionValue { | ||
fn as_ref(&self) -> &str { | ||
match self { | ||
DimensionValue::PriorityExecutor => PRIORITY_EXECUTOR, | ||
DimensionValue::V2Executor => V2_EXECUTOR, | ||
} | ||
} | ||
} | ||
|
||
pub enum CwMetrics { | ||
TxSucceeded, | ||
TxReverted, | ||
TxSubmitted, | ||
TxStatusUnknown, | ||
} | ||
|
||
impl Into<String> for CwMetrics { | ||
fn into(self) -> String { | ||
match self { | ||
CwMetrics::TxSucceeded => TX_SUCCEEDED_METRIC.to_string(), | ||
CwMetrics::TxReverted => TX_REVERTED_METRIC.to_string(), | ||
CwMetrics::TxSubmitted => TX_SUBMITTED_METRIC.to_string(), | ||
CwMetrics::TxStatusUnknown => TX_STATUS_UNKNOWN_METRIC.to_string(), | ||
} | ||
pub enum CwMetrics { | ||
TxSucceeded, | ||
TxReverted, | ||
TxSubmitted, | ||
TxStatusUnknown, | ||
} | ||
impl From<CwMetrics> for String { | ||
fn from(metric: CwMetrics) -> Self { | ||
match metric { | ||
CwMetrics::TxSucceeded => TX_SUCCEEDED_METRIC.to_string(), | ||
CwMetrics::TxReverted => TX_REVERTED_METRIC.to_string(), | ||
CwMetrics::TxSubmitted => TX_SUBMITTED_METRIC.to_string(), | ||
CwMetrics::TxStatusUnknown => TX_STATUS_UNKNOWN_METRIC.to_string(), | ||
} | ||
} | ||
} | ||
|
||
use aws_sdk_cloudwatch::types::Dimension; | ||
use aws_sdk_cloudwatch::types::Dimension; | ||
|
||
pub const ARTEMIS_NAMESPACE: &str = "Artemis"; | ||
pub const ARTEMIS_NAMESPACE: &str = "Artemis"; | ||
|
||
pub struct MetricBuilder { | ||
metric_name: String, | ||
dimensions: Vec<Dimension>, | ||
value: f64, | ||
} | ||
pub struct MetricBuilder { | ||
metric_name: String, | ||
dimensions: Vec<Dimension>, | ||
value: f64, | ||
} | ||
|
||
impl MetricBuilder { | ||
pub fn new(metric: CwMetrics) -> Self { | ||
Self { | ||
metric_name: metric.into(), | ||
dimensions: Vec::new(), | ||
value: 1.0, | ||
} | ||
impl MetricBuilder { | ||
pub fn new(metric: CwMetrics) -> Self { | ||
Self { | ||
metric_name: metric.into(), | ||
dimensions: Vec::new(), | ||
value: 1.0, | ||
} | ||
} | ||
|
||
pub fn add_dimension(mut self, name: &str, value: &str) -> Self { | ||
self.dimensions | ||
.push(Dimension::builder().name(name).value(value).build()); | ||
self | ||
} | ||
pub fn add_dimension(mut self, name: &str, value: &str) -> Self { | ||
self.dimensions | ||
.push(Dimension::builder().name(name).value(value).build()); | ||
self | ||
} | ||
|
||
pub fn with_value(mut self, value: f64) -> Self { | ||
self.value = value; | ||
self | ||
} | ||
pub fn with_value(mut self, value: f64) -> Self { | ||
self.value = value; | ||
self | ||
} | ||
|
||
pub fn build(self) -> aws_sdk_cloudwatch::types::MetricDatum { | ||
aws_sdk_cloudwatch::types::MetricDatum::builder() | ||
.metric_name(self.metric_name) | ||
.value(self.value) | ||
.set_dimensions(Some(self.dimensions)) | ||
.build() | ||
} | ||
pub fn build(self) -> aws_sdk_cloudwatch::types::MetricDatum { | ||
aws_sdk_cloudwatch::types::MetricDatum::builder() | ||
.metric_name(self.metric_name) | ||
.value(self.value) | ||
.set_dimensions(Some(self.dimensions)) | ||
.build() | ||
} | ||
} | ||
|
||
pub fn receipt_status_to_metric(status: u64) -> CwMetrics { | ||
match status { | ||
1 => CwMetrics::TxSucceeded, | ||
0 => CwMetrics::TxReverted, | ||
_ => CwMetrics::TxStatusUnknown, | ||
} | ||
pub fn receipt_status_to_metric(status: u64) -> CwMetrics { | ||
match status { | ||
1 => CwMetrics::TxSucceeded, | ||
0 => CwMetrics::TxReverted, | ||
_ => CwMetrics::TxStatusUnknown, | ||
} | ||
} |
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 |
---|---|---|
|
@@ -26,9 +26,10 @@ impl fmt::Display for OrderTypeError { | |
|
||
impl std::error::Error for OrderTypeError {} | ||
|
||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
#[derive(Debug, Default, PartialEq, Eq, Clone)] | ||
pub enum OrderType { | ||
DutchV2, | ||
#[default] | ||
Priority, | ||
} | ||
|
||
|
@@ -44,21 +45,15 @@ impl FromStr for OrderType { | |
} | ||
} | ||
|
||
impl ToString for OrderType { | ||
fn to_string(&self) -> String { | ||
impl fmt::Display for OrderType { | ||
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. impl Display gives you ToString for free |
||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
OrderType::DutchV2 => "Dutch_V2".to_string(), | ||
OrderType::Priority => "Priority".to_string(), | ||
OrderType::DutchV2 => write!(f, "Dutch_V2"), | ||
OrderType::Priority => write!(f, "Priority"), | ||
} | ||
} | ||
} | ||
|
||
impl Default for OrderType { | ||
fn default() -> Self { | ||
OrderType::DutchV2 | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
pub struct UniswapXOrder { | ||
#[serde(rename = "encodedOrder")] | ||
|
@@ -109,9 +104,7 @@ impl Collector<UniswapXOrder> for UniswapXOrderCollector { | |
async fn get_event_stream(&self) -> Result<CollectorStream<'_, UniswapXOrder>> { | ||
let url = format!( | ||
"{}/orders?orderStatus=open&chainId={}&orderType={}", | ||
self.base_url, | ||
self.chain_id, | ||
self.order_type.to_string() | ||
self.base_url, self.chain_id, self.order_type, | ||
); | ||
|
||
// stream that polls the UniswapX API every 5 seconds | ||
|
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 |
---|---|---|
|
@@ -95,6 +95,10 @@ impl KeyStore { | |
pub fn len(&self) -> usize { | ||
self.keys.len() | ||
} | ||
|
||
pub fn is_empty(&self) -> bool { | ||
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.
|
||
self.keys.is_empty() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
|
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.
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.
impl From gives you Into for free, the reverse not true