@@ -11,6 +11,7 @@ pub mod time;
1111pub mod trade;
1212
1313use {
14+ alloy:: primitives:: Address ,
1415 const_hex:: { FromHex , FromHexError } ,
1516 primitive_types:: H160 ,
1617 std:: { fmt, sync:: LazyLock } ,
@@ -24,12 +25,12 @@ pub type AuctionId = i64;
2425
2526/// Erc20 token pair specified by two contract addresses.
2627#[ derive( Copy , Clone , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
27- pub struct TokenPair ( H160 , H160 ) ;
28+ pub struct TokenPair ( Address , Address ) ;
2829
2930impl TokenPair {
3031 /// Create a new token pair from two addresses.
3132 /// The addresses must not be the equal.
32- pub fn new ( token_a : H160 , token_b : H160 ) -> Option < Self > {
33+ pub fn new ( token_a : Address , token_b : Address ) -> Option < Self > {
3334 match token_a. cmp ( & token_b) {
3435 std:: cmp:: Ordering :: Less => Some ( Self ( token_a, token_b) ) ,
3536 std:: cmp:: Ordering :: Equal => None ,
@@ -38,13 +39,13 @@ impl TokenPair {
3839 }
3940
4041 /// Used to determine if `token` is among the pair.
41- pub fn contains ( & self , token : & H160 ) -> bool {
42+ pub fn contains ( & self , token : & Address ) -> bool {
4243 self . 0 == * token || self . 1 == * token
4344 }
4445
4546 /// Returns the token in the pair which is not the one passed in, or None if
4647 /// token passed in is not part of the pair
47- pub fn other ( & self , token : & H160 ) -> Option < H160 > {
48+ pub fn other ( & self , token : & Address ) -> Option < Address > {
4849 if & self . 0 == token {
4950 Some ( self . 1 )
5051 } else if & self . 1 == token {
@@ -56,37 +57,37 @@ impl TokenPair {
5657
5758 /// The first address is always the lower one.
5859 /// The addresses are never equal.
59- pub fn get ( & self ) -> ( H160 , H160 ) {
60+ pub fn get ( & self ) -> ( Address , Address ) {
6061 ( self . 0 , self . 1 )
6162 }
6263
6364 /// Lowest element according to Ord trait.
6465 pub fn first_ord ( ) -> Self {
6566 Self (
66- H160 ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ,
67- H160 ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) ,
67+ Address :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ,
68+ Address :: from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) ,
6869 )
6970 }
7071}
7172
7273impl Default for TokenPair {
7374 fn default ( ) -> Self {
74- Self :: new ( H160 :: from_low_u64_be ( 0 ) , H160 :: from_low_u64_be ( 1 ) ) . unwrap ( )
75+ Self :: new ( Address :: with_last_byte ( 0 ) , Address :: with_last_byte ( 1 ) ) . unwrap ( )
7576 }
7677}
7778
7879impl IntoIterator for TokenPair {
79- type IntoIter = std:: iter:: Chain < std:: iter:: Once < H160 > , std:: iter:: Once < H160 > > ;
80- type Item = H160 ;
80+ type IntoIter = std:: iter:: Chain < std:: iter:: Once < Address > , std:: iter:: Once < Address > > ;
81+ type Item = Address ;
8182
8283 fn into_iter ( self ) -> Self :: IntoIter {
8384 std:: iter:: once ( self . 0 ) . chain ( std:: iter:: once ( self . 1 ) )
8485 }
8586}
8687
8788impl < ' a > IntoIterator for & ' a TokenPair {
88- type IntoIter = std:: iter:: Chain < std:: iter:: Once < & ' a H160 > , std:: iter:: Once < & ' a H160 > > ;
89- type Item = & ' a H160 ;
89+ type IntoIter = std:: iter:: Chain < std:: iter:: Once < & ' a Address > , std:: iter:: Once < & ' a Address > > ;
90+ type Item = & ' a Address ;
9091
9192 fn into_iter ( self ) -> Self :: IntoIter {
9293 std:: iter:: once ( & self . 0 ) . chain ( std:: iter:: once ( & self . 1 ) )
@@ -175,9 +176,9 @@ mod tests {
175176
176177 #[ test]
177178 fn token_pair_contains ( ) {
178- let token_a = H160 :: from_low_u64_be ( 0 ) ;
179- let token_b = H160 :: from_low_u64_be ( 1 ) ;
180- let token_c = H160 :: from_low_u64_be ( 2 ) ;
179+ let token_a = Address :: with_last_byte ( 0 ) ;
180+ let token_b = Address :: with_last_byte ( 1 ) ;
181+ let token_c = Address :: with_last_byte ( 2 ) ;
181182 let pair = TokenPair :: new ( token_a, token_b) . unwrap ( ) ;
182183
183184 assert ! ( pair. contains( & token_a) ) ;
@@ -187,9 +188,9 @@ mod tests {
187188
188189 #[ test]
189190 fn token_pair_other ( ) {
190- let token_a = H160 :: from_low_u64_be ( 0 ) ;
191- let token_b = H160 :: from_low_u64_be ( 1 ) ;
192- let token_c = H160 :: from_low_u64_be ( 2 ) ;
191+ let token_a = Address :: with_last_byte ( 0 ) ;
192+ let token_b = Address :: with_last_byte ( 1 ) ;
193+ let token_c = Address :: with_last_byte ( 2 ) ;
193194 let pair = TokenPair :: new ( token_a, token_b) . unwrap ( ) ;
194195
195196 assert_eq ! ( pair. other( & token_a) , Some ( token_b) ) ;
@@ -199,8 +200,8 @@ mod tests {
199200
200201 #[ test]
201202 fn token_pair_is_sorted ( ) {
202- let token_a = H160 :: from_low_u64_be ( 0 ) ;
203- let token_b = H160 :: from_low_u64_be ( 1 ) ;
203+ let token_a = Address :: with_last_byte ( 0 ) ;
204+ let token_b = Address :: with_last_byte ( 1 ) ;
204205 let pair_0 = TokenPair :: new ( token_a, token_b) . unwrap ( ) ;
205206 let pair_1 = TokenPair :: new ( token_b, token_a) . unwrap ( ) ;
206207 assert_eq ! ( pair_0, pair_1) ;
@@ -210,14 +211,14 @@ mod tests {
210211
211212 #[ test]
212213 fn token_pair_cannot_be_equal ( ) {
213- let token = H160 :: from_low_u64_be ( 1 ) ;
214+ let token = Address :: with_last_byte ( 1 ) ;
214215 assert_eq ! ( TokenPair :: new( token, token) , None ) ;
215216 }
216217
217218 #[ test]
218219 fn token_pair_iterator ( ) {
219- let token_a = H160 :: from_low_u64_be ( 0 ) ;
220- let token_b = H160 :: from_low_u64_be ( 1 ) ;
220+ let token_a = Address :: with_last_byte ( 0 ) ;
221+ let token_b = Address :: with_last_byte ( 1 ) ;
221222 let pair = TokenPair :: new ( token_a, token_b) . unwrap ( ) ;
222223
223224 let mut iter = ( & pair) . into_iter ( ) ;
@@ -233,9 +234,9 @@ mod tests {
233234
234235 #[ test]
235236 fn token_pair_ordering ( ) {
236- let token_a = H160 :: from_low_u64_be ( 0 ) ;
237- let token_b = H160 :: from_low_u64_be ( 1 ) ;
238- let token_c = H160 :: from_low_u64_be ( 2 ) ;
237+ let token_a = Address :: with_last_byte ( 0 ) ;
238+ let token_b = Address :: with_last_byte ( 1 ) ;
239+ let token_c = Address :: with_last_byte ( 2 ) ;
239240 let pair_ab = TokenPair :: new ( token_a, token_b) . unwrap ( ) ;
240241 let pair_bc = TokenPair :: new ( token_b, token_c) . unwrap ( ) ;
241242 let pair_ca = TokenPair :: new ( token_c, token_a) . unwrap ( ) ;
0 commit comments