banteg / multicall.py

aggregate results of multiple smart contract calls into one
MIT License
251 stars 108 forks source link

Updated the example calls to use `returns` tuples #55

Closed parkerburchett closed 1 year ago

parkerburchett commented 1 year ago

The example code in thereadme.md has the returns param passed a list instead of a tuple.

multi = Multicall([
    Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE], [['whale', from_wei]]),
    Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_FISH], [['fish', from_wei]]),
    Call(MKR_TOKEN, 'totalSupply()(uint256)', [['supply', from_wei]]),
])

multi()  # {'whale': 566437.0921992733, 'fish': 7005.0, 'supply': 1000003.1220798912}

# seth-style calls
Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE])()
Call(MKR_TOKEN, 'balanceOf(address)(uint256)')(MKR_WHALE)
# return values processing
Call(MKR_TOKEN, 'totalSupply()(uint256)', [['supply', from_wei]])()

The type hinting inside of Call returns: Optional[Iterable[Tuple[str,Callable]]] = None is for a tuple but the example code passes in a list.

class Call:
    def __init__(
        self, 
        target: AnyAddress, 
        function: Union[str,Iterable[Union[str,Any]]], # 'funcName(dtype)(dtype)' or ['funcName(dtype)(dtype)', input0, input1, ...]
        returns: Optional[Iterable[Tuple[str,Callable]]] = None, 
        block_id: Optional[int] = None, 
        gas_limit: Optional[int] = None,
        state_override_code: Optional[str] = None, 
        # This needs to be None in order to use process_pool_executor
        _w3: Web3 = None
    ) -> None:

https://github.com/banteg/multicall.py/blob/master/multicall/call.py

This is a simple change to the example in the readme.md so that it matches with the type hinting in Call

BobTheBuidler commented 1 year ago

Thank you