33use {
44 super :: TokenOwnerProposing ,
55 crate :: sources:: { uniswap_v2:: pair_provider:: PairProvider , uniswap_v3_pair_provider} ,
6+ alloy:: eips:: BlockNumberOrTag ,
67 anyhow:: Result ,
7- contracts:: { IUniswapV3Factory , alloy:: BalancerV2Vault } ,
8- ethcontract:: { BlockNumber , H160 } ,
8+ contracts:: alloy:: { BalancerV2Vault , IUniswapV3Factory } ,
9+ ethcontract:: H160 ,
910 ethrpc:: alloy:: conversions:: IntoLegacy ,
1011 model:: TokenPair ,
1112} ;
@@ -38,7 +39,7 @@ impl TokenOwnerProposing for BalancerVaultFinder {
3839}
3940
4041pub struct UniswapV3Finder {
41- pub factory : IUniswapV3Factory ,
42+ pub factory : IUniswapV3Factory :: Instance ,
4243 pub base_tokens : Vec < H160 > ,
4344 fee_values : Vec < u32 > ,
4445}
@@ -55,7 +56,7 @@ pub enum FeeValues {
5556
5657impl UniswapV3Finder {
5758 pub async fn new (
58- factory : IUniswapV3Factory ,
59+ factory : IUniswapV3Factory :: Instance ,
5960 base_tokens : Vec < H160 > ,
6061 fee_values : FeeValues ,
6162 ) -> Result < Self > {
@@ -75,18 +76,25 @@ impl UniswapV3Finder {
7576
7677 // Possible fee values as given by
7778 // https://github.com/Uniswap/v3-core/blob/9161f9ae4aaa109f7efdff84f1df8d4bc8bfd042/contracts/UniswapV3Factory.sol#L26
78- async fn fee_values ( factory : & IUniswapV3Factory ) -> Result < Vec < u32 > > {
79+ async fn fee_values ( factory : & IUniswapV3Factory :: Instance ) -> Result < Vec < u32 > > {
7980 // We expect there to be few of these kind of events (currently there are 4) so
8081 // fetching all of them is fine. Alternatively we could index these
8182 // events in the database.
8283 let events = factory
83- . events ( )
84- . fee_amount_enabled ( )
85- . from_block ( BlockNumber :: Earliest )
86- . to_block ( BlockNumber :: Latest )
84+ . FeeAmountEnabled_filter ( )
85+ . from_block ( BlockNumberOrTag :: Earliest )
86+ . to_block ( BlockNumberOrTag :: Latest )
8787 . query ( )
8888 . await ?;
89- let fee_values = events. into_iter ( ) . map ( |event| event. data . fee ) . collect ( ) ;
89+ let fee_values = events
90+ . into_iter ( )
91+ . map ( |( enabled, _) | {
92+ enabled
93+ . fee
94+ . try_into ( )
95+ . expect ( "uint24 always fits inside u32" )
96+ } )
97+ . collect ( ) ;
9098 Ok ( fee_values)
9199 }
92100}
@@ -100,7 +108,11 @@ impl TokenOwnerProposing for UniswapV3Finder {
100108 . filter_map ( |base_token| TokenPair :: new ( * base_token, token) )
101109 . flat_map ( |pair| self . fee_values . iter ( ) . map ( move |fee| ( pair, * fee) ) )
102110 . map ( |( pair, fee) | {
103- uniswap_v3_pair_provider:: pair_address ( & self . factory . address ( ) , & pair, fee)
111+ uniswap_v3_pair_provider:: pair_address (
112+ & self . factory . address ( ) . into_legacy ( ) ,
113+ & pair,
114+ fee,
115+ )
104116 } )
105117 . collect ( ) )
106118 }
0 commit comments