0xProject/0x-monorepo

Python contract wrapper methods return raw tuples

feuGeneA opened this issue · 0 comments

Expected Behavior

Contract method wrappers should return TypedDicts that match the Python method definitions.

Current Behavior

Contract method wrappers are returning raw tuples instead of typed dictionaries. For example, the Python definition for Exchange.fillOrder() is:

    def call(
        self,
        order: Tuple0x6ca34a6f,
        taker_asset_fill_amount: int,
        signature: Union[bytes, str],
        tx_params: Optional[TxParams] = None,
    ) -> Union[Tuple0x735c43e3, Union[HexBytes, bytes]]:
    ...

And Tuple0x735c43e3 is defined as:

class Tuple0x735c43e3(TypedDict):
...
    makerAssetFilledAmount: int
    takerAssetFilledAmount: int
    makerFeePaid: int
    takerFeePaid: int
    protocolFeePaid: int

Currently, executing a fillOrder eth_call returns a raw tuple:

>>> exchange.fill_order.call(
...     order=order,
...     taker_asset_fill_amount=order["takerAssetAmount"],
...     signature=maker_signature,
...     tx_params=TxParams(from_=taker_address)
... )
(100000000000000000, 100000000000000000, 0, 0, 0)

Whereas one would expect that return value to look more like:

>>> exchange.fill_order.call(...)
{'makerAssetFilledAmount': 100000000000000000,
 'takerAssetFilledAmount': 100000000000000000,
 'makerFeePaid': 0,
 'takerFeePaid': 0,
 'protocolFeePaid': 0}

Possible Solution

Modify @0x/abi-gen to have generated Python methods populate the TypedDict structure with the data return data tuple given by the method invocation. This will require changes to both the templates and the TypeScript helper code.

Steps to Reproduce (for bugs)

Just run a contract method that returns a struct and look at the return value.

Context

We're generating method wrappers to return structured, typed data, but we're not living up to those expectations we're setting.