File tree Expand file tree Collapse file tree 7 files changed +39
-8
lines changed Expand file tree Collapse file tree 7 files changed +39
-8
lines changed Original file line number Diff line number Diff line change @@ -299,7 +299,7 @@ def main(
299
299
node_url = "https://rpc-core.icecreamswap.com" ,
300
300
usdt_address = "0x900101d06A7426441Ae63e9AB3B9b0F63Be145F1" ,
301
301
):
302
- from eth_utils import to_checksum_address
302
+ from IceCreamSwapWeb3 import to_checksum_address
303
303
304
304
usdt_address = to_checksum_address (usdt_address )
305
305
Original file line number Diff line number Diff line change
1
+ import os
2
+ from typing import cast
3
+ from eth_hash .auto import keccak
4
+ from eth_typing import ChecksumAddress
5
+
6
+ CACHE_SIZE = int (os .getenv ("CHECKSUM_CACHE_SIZE" , 1000 ))
7
+ CHECKSUM_CACHE = {}
8
+
9
+ def to_checksum_address (address : str ) -> ChecksumAddress :
10
+ """Fast checksum address with caching."""
11
+ normalized_address = address .lower ().replace ("0x" , "" )
12
+ assert len (normalized_address ) == 40 , "Address has incorrect length"
13
+
14
+ if normalized_address in CHECKSUM_CACHE :
15
+ return CHECKSUM_CACHE [normalized_address ]
16
+
17
+ hashed_address = keccak (normalized_address .encode ()).hex ()
18
+ checksum_address = "0x" + "" .join (
19
+ char .upper () if int (hashed_address [i ], 16 ) >= 8 else char
20
+ for i , char in enumerate (normalized_address )
21
+ )
22
+
23
+ if len (CHECKSUM_CACHE ) >= CACHE_SIZE :
24
+ CHECKSUM_CACHE .pop (next (iter (CHECKSUM_CACHE )))
25
+
26
+ CHECKSUM_CACHE [normalized_address ] = checksum_address
27
+ return cast (ChecksumAddress , checksum_address )
Original file line number Diff line number Diff line change 5
5
import eth_abi
6
6
import eth_utils
7
7
import rlp
8
- from eth_utils import to_checksum_address , to_bytes
8
+ from eth_utils import to_bytes
9
9
from eth_utils .abi import get_abi_output_types , get_abi_input_types
10
10
from web3 .contract .contract import ContractFunction , ContractConstructor
11
11
from web3 .exceptions import ContractLogicError
12
12
13
- from IceCreamSwapWeb3 import Web3Advanced
13
+ from IceCreamSwapWeb3 import Web3Advanced , to_checksum_address
14
14
15
15
# load multicall abi
16
16
with files ("IceCreamSwapWeb3" ).joinpath ("./abi/Multicall.abi" ).open ('r' ) as f :
Original file line number Diff line number Diff line change
1
+ from typing import cast
2
+
1
3
import requests
4
+ from IceCreamSwapWeb3 import to_checksum_address
2
5
from eth_utils import to_checksum_address
3
6
from hexbytes import HexBytes
4
7
from tqdm import tqdm
@@ -103,10 +106,10 @@ def get_filter(
103
106
address = to_checksum_address (log ['address' ]),
104
107
blockHash = block ["header" ]["hash" ],
105
108
blockNumber = block ["header" ]["number" ],
106
- data = HexBytes (log ["data" ]),
109
+ data = cast ( HexBytes , bytes . fromhex (log ["data" ][ 2 :]) ),
107
110
logIndex = log ["logIndex" ],
108
- topics = [HexBytes (topic ) for topic in log ["topics" ]],
109
- transactionHash = HexBytes (log ["transactionHash" ]),
111
+ topics = [cast ( HexBytes , bytes . fromhex (topic [ 2 :]) ) for topic in log ["topics" ]],
112
+ transactionHash = cast ( HexBytes , bytes . fromhex (log ["transactionHash" ][ 2 :]) ),
110
113
transactionIndex = log ["transactionIndex" ],
111
114
removed = False ,
112
115
))
Original file line number Diff line number Diff line change 2
2
from importlib .resources import files
3
3
from time import sleep
4
4
5
- from eth_utils import to_checksum_address
5
+ from IceCreamSwapWeb3 import to_checksum_address
6
6
from web3 import Web3
7
7
from web3 .exceptions import ContractLogicError
8
8
from web3 .main import get_default_modules
Original file line number Diff line number Diff line change 1
1
from .Web3Advanced import Web3Advanced
2
+ from .FastChecksumAddress import to_checksum_address
Original file line number Diff line number Diff line change 1
1
from setuptools import setup , find_packages
2
2
3
- VERSION = '0.1.28 '
3
+ VERSION = '0.1.29 '
4
4
DESCRIPTION = 'IceCreamSwap Web3.py wrapper'
5
5
LONG_DESCRIPTION = 'IceCreamSwap Web3.py wrapper with automatic retries, multicall and other advanced functionality'
6
6
You can’t perform that action at this time.
0 commit comments