1010 uniswap_v4_sv_contract ,
1111)
1212from utils .web3_utils import (
13- MULTICALL_ADDRESS_BY_CHAIN ,
1413 call_with_retry ,
1514 fetch_events_logs_with_retry ,
1615 multicall_by_address ,
2322
2423PAGINATION_SIZE = 1000
2524
25+ extract_signed_24bit = lambda val : val - (1 << 24 ) if val >= (1 << 23 ) else val
26+
2627
2728def get_all_users (
2829 start = 21688329 ,
@@ -69,7 +70,7 @@ def get_all_users(
6970 if ownerOf_calls :
7071 multicall_results = multicall_by_address (
7172 wb3 = w3 ,
72- multical_address = MULTICALL_ADDRESS_BY_CHAIN [ Chain . ETHEREUM ] ,
73+ multical_address = "0xcA11bde05977b3631167028862bE2a173976CA11" ,
7374 calls = ownerOf_calls ,
7475 block_identifier = end ,
7576 allow_failure = True ,
@@ -95,27 +96,32 @@ def get_all_users(
9596
9697def get_position_balance (token_id , block , tick , sqrt_price ):
9798 try :
98- [ packedInfo ] = call_with_retry (
99+ packedInfo = call_with_retry (
99100 uniswap_v4_nfpm_contract .functions .positionInfo (token_id ),
100101 block ,
101102 )
102- [ liquidity ] = call_with_retry (
103+ liquidity = call_with_retry (
103104 uniswap_v4_nfpm_contract .functions .getPositionLiquidity (token_id ),
104105 block ,
105106 )
106107 except Exception :
107- print (f"token { token_id } not yet created at block { block } " )
108+ print (f"token { token_id } empty at block { block } " )
108109 return [0 , 0 ]
109110
110111 if liquidity == 0 :
111112 return [0 , 0 ]
113+
112114 t0 = 0
113115 t1 = 0
114116
115117 # tickUpper: bits 32-55 (from the right, 0-indexed)
116118 # tickLower: bits 8-31
117- tick_upper = (packedInfo >> 32 ) & ((1 << 24 ) - 1 )
118- tick_lower = (packedInfo >> 8 ) & ((1 << 24 ) - 1 )
119+ tick_upper = extract_signed_24bit ((packedInfo >> 32 ) & ((1 << 24 ) - 1 ))
120+ tick_lower = extract_signed_24bit ((packedInfo >> 8 ) & ((1 << 24 ) - 1 ))
121+
122+ # print(
123+ # f"tick: {tick}, tick_lower: {tick_lower}, tick_upper: {tick_upper}, token_id: {token_id}, liquidity: {liquidity}"
124+ # )
119125
120126 sqrt_ratio_l = math .sqrt (1.0001 ** tick_lower )
121127 sqrt_ratio_u = math .sqrt (1.0001 ** tick_upper )
@@ -126,6 +132,7 @@ def get_position_balance(token_id, block, tick, sqrt_price):
126132 t1 = liquidity * (sqrt_ratio_u - sqrt_ratio_l )
127133 else :
128134 t0 = liquidity * (sqrt_ratio_u - sqrt_ratio_l ) / (sqrt_ratio_u * sqrt_ratio_l )
135+
129136 return [abs (t0 / 10 ** 18 ), abs (t1 / 10 ** 6 )]
130137
131138
@@ -150,8 +157,8 @@ def get_deposit_ids_balances(
150157 user_t0_balances = 0
151158 user_t1_balances = 0
152159
153- [sqrtPriceX96 , tick ] = call_with_retry (
154- uniswap_v4_sv_contract .functions .getSlot0 (token_id ),
160+ [sqrtPriceX96 , tick , _ , _ ] = call_with_retry (
161+ uniswap_v4_sv_contract .functions .getSlot0 (UNISWAP_V4_USDE_POOL ),
155162 block ,
156163 )
157164
@@ -197,9 +204,9 @@ def get_participants_with_deposit_ids(
197204 print ("=" * 60 )
198205
199206 # The specific USDe pool was created at this block.
200- v4_integration = UniswapV4Integration (IntID .UNISWAP_V4_POOL , 23067966 )
207+ v4_integration = UniswapV4Integration (IntID .UNISWAP_V4_POOL , 23468000 )
201208
202- BLOCK = 23067966 + 2000
209+ BLOCK = 23468700
203210 # BLOCK = 23393544
204211
205212 print (f"Block: { BLOCK :,} " )
0 commit comments