banteg / multicall.py

aggregate results of multiple smart contract calls into one
MIT License
246 stars 106 forks source link

ValueOutOfBounds when using default-no-parallelism branch #45

Closed LJlkdskdjflsa closed 1 year ago

LJlkdskdjflsa commented 2 years ago

I have read the Issue of #42 and #44 and clone the default-no-parallelism branch

my code is like this

def from_wei(value):
    return value / 1e18

def generate_multicall(call_list: list):
    multi = Multicall(call_list, _w3=w3)
    return multi

fund_vault_proxy_address = "0x9dd3b3471AF147DF6c7E93ff35a5f04eE9342e9C"

asset_data_list = list(Asset.objects.values_list("address", "name"))
test =[1,2,3]
multi = []
for asset_data in asset_data_list:
    # asset_address_list.append(asset_data[0])
    multi.append(
        Call(
            "0xd1Cc87496aF84105699E82D46B6c5Ab6775Afae4",
            ["balanceOf(address)(uint256)", fund_vault_proxy_address],
            [[asset_data[1], from_wei]],
        )
    )
    # asset_name_list.append(asset_data[1])
data = generate_multicall(multi)

run it and return Error

eth_abi.exceptions.ValueOutOfBounds: Value `[[['0xd1Cc87496aF84105699E82D46B6c5Ab6775Afae4', b'p\xa0\x821\x00\x00\x00\x0...` of type <class 'list'> cannot be encoded by TupleEncoder: value has 1 items when 2 were expected

Can anyone assist here? Thank you in advance.

full error message:

Traceback (most recent call last):
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/./manage.py", line 22, in <module>
    main()
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/django/core/management/commands/shell.py", line 127, in handle
    exec(sys.stdin.read(), globals())
  File "<string>", line 35, in <module>
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/multicall.py", line 76, in __call__
    response = await_awaitable(self.coroutine())
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/utils.py", line 65, in await_awaitable
    return get_event_loop().run_until_complete(awaitable)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/multicall.py", line 81, in coroutine
    batches = await gather(
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/utils.py", line 82, in gather
    raise_if_exception_in(results)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/utils.py", line 78, in raise_if_exception_in
    raise_if_exception(obj)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/utils.py", line 74, in raise_if_exception
    raise obj
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/multicall.py", line 121, in fetch_outputs
    _raise_or_proceed(e, len(calls), ConnErr_retries=ConnErr_retries)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/multicall.py", line 250, in _raise_or_proceed
    raise e
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/multicall.py", line 102, in fetch_outputs
    _, outputs = await self.aggregate.coroutine(args)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/eth_retry/eth_retry.py", line 63, in auto_retry_wrap_async
    return await func(*args,**kwargs)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/call.py", line 111, in coroutine
    args = await run_in_subprocess(
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/utils.py", line 69, in run_in_subprocess
    return callable(*args, **kwargs)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/call.py", line 134, in prep_args
    calldata = signature.encode_data(args)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/utils/multicall/signature.py", line 39, in encode_data
    return self.fourbyte + encode_single(self.input_types, args) if args else self.fourbyte
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/eth_abi/codec.py", line 72, in encode_single
    return encoder(arg)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/eth_abi/encoding.py", line 98, in __call__
    return self.encode(value)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/eth_abi/encoding.py", line 139, in encode
    self.validate_value(values)
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/eth_abi/encoding.py", line 123, in validate_value
    self.invalidate_value(
  File "/Users/lj/Documents/Work/NCHU/OnChainFund/Backend/.venv/lib/python3.10/site-packages/eth_abi/encoding.py", line 88, in invalidate_value
    raise exc(
eth_abi.exceptions.ValueOutOfBounds: Value `[[['0xd1Cc87496aF84105699E82D46B6c5Ab6775Afae4', b'p\xa0\x821\x00\x00\x00\x0...` of type <class 'list'> cannot be encoded by TupleEncoder: value has 1 items when 2 were expected
BobTheBuidler commented 1 year ago

@LJlkdskdjflsa after a quick look at your code, I don't see anything that appears problematic. Can you confirm you're still experiencing this on 0.6.2?

BobTheBuidler commented 1 year ago

Closing due to lack of activity