ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
868 stars 133 forks source link

ABI includes full contract type data #959

Closed bout3fiddy closed 2 years ago

bout3fiddy commented 2 years ago

Environment information

macOS python 3.10.4

$ ape --version
# 0.4.1.dev7+g0b4d7bf

$ ape plugins list
# Installed Plugins:
  hardhat      0.4.0
  alchemy      0.4.0
  etherscan    0.4.0
$ cat ape-config.yaml
# 
plugins:
  - name: etherscan

geth:
  ethereum:
    mainnet:
      uri: http://localhost:9090

What went wrong?

Please include information like:

say i do the following:

pool = Contract("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7")
print(pool.AddLiquidity.abi)

this returns the following:

image

Now, it looks like it just dumps the entire contract abi instead of just the abi for AddLiquidity event. I assume that when one does contract.EventName.abi the returned output should only be for that event and not the whole contract.

Interestingly, it seems to return a shorter event abi if I do the following:

In [50]: print(pool.AddLiquidity.abi.json(indent=4))
{
    "anonymous":false,
    "inputs":[
        {
            "indexed":true,
            "name":"provider",
            "type":"address"
        },
        {
            "indexed":false,
            "name":"token_amounts",
            "type":"uint256[3]"
        },
        {
            "indexed":false,
            "name":"fees",
            "type":"uint256[3]"
        },
        {
            "indexed":false,
            "name":"invariant",
            "type":"uint256"
        },
        {
            "indexed":false,
            "name":"token_supply",
            "type":"uint256"
        }
    ],
    "name":"AddLiquidity",
    "type":"event"
}

Not sure if this is a bug, but I decided to report this any way.

How can it be fixed?

Fill this in if you have ideas on how the bug could be fixed.

antazoey commented 2 years ago

This is specific to ethpm-types. Every ABI object has a back reference to the contract type it came from but it is not actually part of the model during serialization.

You say it is returning the whole ABI but if you look closer at what you posted, you see the the whole ABI is under the key contract_type (along with other data related to the contract type).

It is not actually part of the model but just a property on the class.

Is this causing problems for you? Is this really a bug? I don't quite understand the problem.

antazoey commented 2 years ago

Let me know if this is actually causing problems if I can close this as working-as-intended.

antazoey commented 2 years ago

This PR "fixes" it: https://github.com/ApeWorX/ethpm-types/pull/42

Now, the contract_type will be hidden from the repr and hopefully causes less confusion.

Thank you.

fubuloubu commented 2 years ago

I think that PR will help, it should not be representing the back-refs like that

antazoey commented 2 years ago

Fixed in https://github.com/ApeWorX/ethpm-types/pull/42

bout3fiddy commented 2 years ago

Thanks! I think it was just a dev experience issue for me. I didn't want my terminal to clutter up. It causes issues when you're trying to use rich console for displaying exceptions with the state (state is huge because of that full dump that eth-pm gives).

Thanks for looking into it! I'll let you know if this helps! :)