Skip to content

Commit

Permalink
Merge pull request #187 from 0xDmtri/feature/hashable-amm
Browse files Browse the repository at this point in the history
Implement Hash, Eq and PartialEq for `AMM` and `Factory`
  • Loading branch information
0xKitsune authored Aug 18, 2024
2 parents 643b049 + c52e7c9 commit c3187de
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/amm/factory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::Arc;
use std::{
hash::{Hash, Hasher},
sync::Arc,
};

use alloy::{
network::Network,
Expand Down Expand Up @@ -154,6 +157,20 @@ macro_rules! factory {
}
}
}

impl Hash for Factory {
fn hash<H: Hasher>(&self, state: &mut H) {
self.address().hash(state);
}
}

impl PartialEq for Factory {
fn eq(&self, other: &Self) -> bool {
self.address() == other.address()
}
}

impl Eq for Factory {}
};
}

Expand Down
19 changes: 18 additions & 1 deletion src/amm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ pub mod factory;
pub mod uniswap_v2;
pub mod uniswap_v3;

use std::sync::Arc;
use std::{
hash::{Hash, Hasher},
sync::Arc,
};

use alloy::{
network::Network,
Expand Down Expand Up @@ -167,6 +170,20 @@ macro_rules! amm {
}
}
}

impl Hash for AMM {
fn hash<H: Hasher>(&self, state: &mut H) {
self.address().hash(state);
}
}

impl PartialEq for AMM {
fn eq(&self, other: &Self) -> bool {
self.address() == other.address()
}
}

impl Eq for AMM {}
};
}

Expand Down

0 comments on commit c3187de

Please sign in to comment.