solidquant/whack-a-mole

Can't get the code to work

cryptic-bmd opened this issue · 7 comments

I'm trying to run main.py, but it keeps giving me this error

PS C:\Users\bmd\bmd\OneDrive\Documents\GitHub\whackamole> & c:/Users/bmd/OneDrive/Documents/GitHub/whackamole/venv/Scripts/Activate.ps1
(venv) PS C:\Users\bmd\OneDrive\Documents\GitHub\whackamole> & c:/Users/bmd/OneDrive/Documents/GitHub/whackamole/venv/Scripts/python.exe c:/Users/bmd/OneDrive/Documents/GitHub/whackamole/main.py
Process Process-1:
Traceback (most recent call last):
File "C:\Users\bmd\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Users\bmd\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "c:\Usersbmd\OneDrive\Documents\GitHub\whackamole\main.py", line 18, in dex_stream_process
dex = DEX({chain: RPC_ENDPOINTS[chain]},
File "c:\Users\bmd\OneDrive\Documents\GitHub\whackamole\data\dex.py", line 450, in init
self.load()
File "c:\Users\bmd\OneDrive\Documents\GitHub\whackamole\data\dex.py", line 132, in load
self._load_pool_data()
File "c:\Users\bmd\OneDrive\Documents\GitHub\whackamole\data\dex.py", line 210, in _load_pool_data
sqrt_price = storage_data[0]
TypeError: 'NoneType' object is not subscriptable

Not sure what went wrong, please kindly look into it. Thanks

This problem can occur when the multicall request failed to return values from the DEX pools that you specified within the addresses/ethereum.py file:

EXCHANGE = 'ethereum'

TOKENS = {
    'ETH': ['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18],
    'USDT': ['0xdAC17F958D2ee523a2206206994597C13D831ec7', 6],
    'USDC': ['0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6],
    'BTC': ['0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 8],
    'DAI': ['0x6B175474E89094C44Da98b954EedeAC495271d0F', 18],
    'PEPE': ['0x6982508145454Ce325dDbE47a25d4ec3d2311933', 18],
}

columns = ['chain', 'exchange', 'version', 'name', 'address', 'fee', 'token0', 'token1']

POOLS = [
    ['uniswap', 3, 'ETH/USDT', '0x11b815efB8f581194ae79006d24E0d814B7697F6', 500, 'ETH', 'USDT'],
    ['uniswap', 3, 'USDC/USDT', '0x3416cF6C708Da44DB2624D63ea0AAef7113527C6', 100, 'USDC', 'USDT'],
    ['uniswap', 3, 'BTC/ETH', '0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0', 500, 'BTC', 'ETH'],
    ['uniswap', 3, 'DAI/USDC', '0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168', 100, 'DAI', 'USDC'],
    ['uniswap', 3, 'PEPE/ETH', '0x11950d141EcB863F01007AdD7D1A342041227b58', 3000, 'PEPE', 'ETH'],

    ['uniswap', 2, 'ETH/USDT', '0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852', 3000, 'ETH', 'USDT'],
    ['uniswap', 2, 'USDC/ETH', '0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc', 3000, 'USDC', 'ETH'],
    ['uniswap', 2, 'DAI/USDC', '0xAE461cA67B15dc8dc81CE7615e0320dA1A9aB8D5', 3000, 'DAI', 'USDC'],
    ['uniswap', 2, 'PEPE/ETH', '0xA43fe16908251ee70EF74718545e4FE6C5cCEc9f', 3000, 'PEPE', 'ETH'],

    ['sushiswap', 3, 'ETH/USDT', '0x72c2178E082feDB13246877B5aA42ebcE1b72218', 500, 'ETH', 'USDT'],
    ['sushiswap', 3, 'USDC/ETH', '0x35644Fb61aFBc458bf92B15AdD6ABc1996Be5014', 500, 'USDC', 'ETH'],
    ['sushiswap', 3, 'BTC/ETH', '0x801CCFae9d2C77893B545E8D0E4637C055CD26cB', 500, 'BTC', 'ETH'],
    ['sushiswap', 3, 'USDC/USDT', '0xfA6e8E97ecECDC36302eCA534f63439b1E79487B', 100, 'USDC', 'USDT'],
    ['sushiswap', 3, 'DAI/USDC', '0x31ac258B911Af9a0d2669ebDFC4e39D92e96b772', 100, 'DAI', 'USDC'],

    ['sushiswap', 2, 'BTC/ETH', '0xCEfF51756c56CeFFCA006cD410B03FFC46dd3a58', 3000, 'BTC', 'ETH'],
    ['sushiswap', 2, 'ETH/USDT', '0x06da0fd433C1A5d7a4faa01111c044910A184553', 3000, 'ETH', 'USDT'],
    ['sushiswap', 2, 'USDC/ETH', '0x397FF1542f962076d0BFE58eA045FfA2d347ACa0', 3000, 'USDC', 'ETH'],
    ['sushiswap', 2, 'DAI/ETH', '0xC3D03e4F041Fd4cD388c549Ee2A29a9E5075882f', 3000, 'DAI', 'ETH'],
]

POOLS = [dict(zip(columns, [EXCHANGE] + pool)) for pool in POOLS]

The above is a sample code snippet from my addresses/ethereum.py on examples/strategy/dex_arb_base branch. All the addresses specified here should be in its checksummed format.

Your error output tells us that there's an error with (the red breakpointed line):

스크린샷 2023-08-01 오전 9 14 29

This is a problem with an Uniswap V3 variant pool, which should be checked by debugging the pool value by doing:

스크린샷 2023-08-01 오전 9 23 49

If you already know what particular pool the system is causing errors at, try doing this with multicall.py (https://github.com/banteg/multicall.py):

from web3 import Web3
from multicall import Call, Multicall

rpc_url = '<YOUR RPC URL HERE>'
web3 = Web3(Web3.HTTPProvider(rpc_url))

pool_address = '<POOL ADDRESS HERE>'
signature = 'slot0()((uint160,int24,uint16,uint16,uint16,uint8,bool))'
call = Call(pool_address, signature, [(0, lambda x: x)])
multicall = Multicall([call], _w3=web3)
result = multicall()
print(result[0])

This is exactly how multicall requests are made in the data/dex.py file. Running an example with 0x11b815efB8f581194ae79006d24E0d814B7697F6, which is WETH-USDC Uniswap V3 pool worked and returned a value of:

(3415028606754314648668691, -201049, 45, 180, 180, 0, True)

If it returns a similar tuple data from slot0 of that pool, then it should work.

So I ran a few tests and I discovered that the error was because I used testnets RPC, so it appears the pools are not on testnets.

Which should mean I'll have to find all the addresses for testnets.

But firstly, is the codebase designed to work with testnets?

Yes, the code should work with testnets as well. The only changes you need to make to make it work on testnet are:

  1. change the token/pool addresses to testnet addresses,
  2. use testnet HTTPS/WSS RPC endpoints (check .env and configs.py),
  3. edit PRIVATE_RELAY in execution/dex_order.py to testnet url, for example as https://relay-goerli.flashbots.net

Thanks for the help, but I've decided to stick to the mainnet for now, I can't seem to find my way around getting those addresses and LPs. It's not easy as it looks 😅, so I'll get to it later, just trying to understand the code for now!

But I've encountered another error. It's trivial, but I wonder why...

Here is the error I'm getting:

{'chain': 'ethereum', 'exchange': 'uniswap', 'version': 3, 'name': 'ETH/USDT', 'address': '0x11b815efB8f581194ae79006d24E0d814B7697F6', 'fee': 500, 'token0': 'ETH', 'token1': 'USDT'}
{'chain': 'ethereum', 'exchange': 'uniswap', 'version': 3, 'name': 'USDC/USDT', 'address': '0x3416cF6C708Da44DB2624D63ea0AAef7113527C6', 'fee': 100, 'token0': 'USDC', 'token1': 'USDT'}
{'chain': 'ethereum', 'exchange': 'uniswap', 'version': 3, 'name': 'BTC/ETH', 'address': '0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0', 'fee': 500, 'token0': 'BTC', 'token1': 'ETH'}
{'chain': 'ethereum', 'exchange': 'uniswap', 'version': 3, 'name': 'DAI/USDC', 'address': '0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168', 'fee': 100, 'token0': 'DAI', 'token1': 'USDC'}
{'chain': 'ethereum', 'exchange': 'uniswap', 'version': 3, 'name': 'PEPE/ETH', 'address': '0x11950d141EcB863F01007AdD7D1A342041227b58', 'fee': 3000, 'token0': 'PEPE', 'token1': 'ETH'}
{'chain': 'ethereum', 'exchange': 'sushiswap', 'version': 3, 'name': 'ETH/USDT', 'address': '0x72c2178E082feDB13246877B5aA42ebcE1b72218', 'fee': 500, 'token0': 'ETH', 'token1': 'USDT'}
{'chain': 'ethereum', 'exchange': 'sushiswap', 'version': 3, 'name': 'USDC/ETH', 'address': '0x35644Fb61aFBc458bf92B15AdD6ABc1996Be5014', 'fee': 500, 'token0': 'USDC', 'token1': 'ETH'}
{'chain': 'ethereum', 'exchange': 'sushiswap', 'version': 3, 'name': 'BTC/ETH', 'address': '0x801CCFae9d2C77893B545E8D0E4637C055CD26cB', 'fee': 500, 'token0': 'BTC', 'token1': 'ETH'}
{'chain': 'ethereum', 'exchange': 'sushiswap', 'version': 3, 'name': 'USDC/USDT', 'address': '0xfA6e8E97ecECDC36302eCA534f63439b1E79487B', 'fee': 100, 'token0': 'USDC', 'token1': 'USDT'}
{'chain': 'ethereum', 'exchange': 'sushiswap', 'version': 3, 'name': 'DAI/USDC', 'address': '0x31ac258B911Af9a0d2669ebDFC4e39D92e96b772', 'fee': 100, 'token0': 'DAI', 'token1': 'USDC'}
here {'source': 'dex', 'type': 'block', 'chain': 'ethereum', 'block': 17825760, 'base_fee': 14214850899, 'max_priority_fee_per_gas': 350000000, 'max_fee_per_gas': 17570000000}
Traceback (most recent call last):
File "c:\Users\bmd\OneDrive\Documents\GitHub\whackamole\main.py", line 47, in
asyncio.run(data_collector(queue))
File "C:\Users\bmd\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\bmd\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "c:\Users\bmd\OneDrive\Documents\GitHub\whackamole\main.py", line 33, in data_collector
for i in range(len(data['tag'])):
KeyError: 'tag'

Here is the output when I printed out data:

{'source': 'dex', 'type': 'block', 'chain': 'ethereum', 'block': 17825760, 'base_fee': 14214850899, 'max_priority_fee_per_gas': 350000000, 'max_fee_per_gas': 17570000000}

The function stream_new_blocks in dex_streams.py publishes a dict with no key bearing 'tag', which should be the cause of the error.
Screenshot 2023-08-02 084520

Not sure if it's supposed to be happening, kindly look into it! Thanks!

Hey, I just realized that you're using the wrong branch. The main branch you're on is currently going under quite a lot of changes, so the example might not work there as intended. But switching to the examples/strategy/dex_arb_base branch will work for you.

I've updated the requirements for examples/strategy/dex_arb_base branch, so you should pull the changes before you can start running main.py again.

So running the below should work:

git checkout examples/strategy/dex_arb_base
git pull

I just pushed some changes to the main branch to make it work just like the examples/strategy/dex_arb_base branch.

You should be able to pull from main branch and run the script now.

Sorry about the confusion 😢. I've also added this to README.md so that people can know beforehand that running the code should happen from within another branch to test the code out.