ApeWorX / ape

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

Ape does not cache contract-type for when using `abi=` #2176

Closed kaleb-keny closed 4 months ago

kaleb-keny commented 4 months ago

Environment information

$ ape --version
0.8.8

$ ape plugins list
  alchemy      0.8.0
  etherscan    0.8.2
  foundry      0.8.0
  hardhat      0.8.0
  solidity     0.8.2
$ cat ape-config.yaml
default_ecosystem: ethereum

plugins:
  - name: hardhat
  - name: foundry
  - name: alchemy
  - name: etherscan
  - name: solidity

hardhat:
  host: auto
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
      sepolia:
        upstream_provider: alchemy

ethereum:
  default_network: sepolia-fork
  sepolia_fork:
    default_provider: foundry
    gas_limit: auto
    transaction_acceptance_timeout: 180
  sepolia:
    default_provider: alchemy
    transaction_acceptance_timeout: 180

foundry:
  host: auto
  request_timeout: 1000 # Defaults to 30
  fork_request_timeout: 6000  # Defaults to 300
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
      sepolia:
        upstream_provider: alchemy 

What went wrong?

Please include information like: For contracts behind proxies, ape fails to decode logs, poc below

import web3 as W3
from ape import networks, api, Contract, accounts
import json

provider_url = "https://eth-sepolia.g.alchemy.com/v2/XXXXXXXXXXXXXXXXXXXXXXXXX"
w3     = W3.Web3(W3.HTTPProvider(provider_url))
with open("deployments.json","r") as f:
    abi = json.load(f)
with networks.parse_network_choice("ethereum:sepolia-fork:foundry"):
    contract = Contract(address="0x8715b7eaDC55DF39F0D7bd8D5Ae44BaD4A7a0a8f",abi=abi)
    with accounts.use_sender("0x0000000000000000000000000000000000000001"):        
        tx = contract.createAccount(gas=int(10e6),max_fee="10 gwei",type=2)
    print(tx.logs)

which prints

print(tx.logs)
[{'address': '0xCb5D8fE2B4AfbedB1970CCDc2f2e2919a6114240', 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000'), HexBytes('0x0000000000000000000000000000000000000000000000000000000000000001'), HexBytes('0x0000000000000000000000000000000080000000000000000000000000000001')], 'data': HexBytes('0x'), 'blockHash': HexBytes('0x882d6b2140d83bd07c29518b15b13e1f25fc5e91115aced610d0fd63853bd4da'), 'blockNumber': 6297502, 'blockTimestamp': '0x66915fd3', 'transactionHash': HexBytes('0x8961e05a33e1def65fd534d112bb6ff99939618208adaaaf590013c52fa2f633'), 'transactionIndex': 0, 'logIndex': 0, 'removed': False}, {'address': '0x8715b7eaDC55DF39F0D7bd8D5Ae44BaD4A7a0a8f', 'topics': [HexBytes('0xa9e04d307e860938fa63307df8b8090e365276e59fcca12ed55656c25e538019'), HexBytes('0x0000000000000000000000000000000080000000000000000000000000000001'), HexBytes('0x0000000000000000000000000000000000000000000000000000000000000001')], 'data': HexBytes('0x'), 'blockHash': HexBytes('0x882d6b2140d83bd07c29518b15b13e1f25fc5e91115aced610d0fd63853bd4da'), 'blockNumber': 6297502, 'blockTimestamp': '0x66915fd3', 'transactionHash': HexBytes('0x8961e05a33e1def65fd534d112bb6ff99939618208adaaaf590013c52fa2f633'), 'transactionIndex': 0, 'logIndex': 1, 'removed': False}]

How can it be fixed?

Use the abi of the contract to decode events

linear[bot] commented 4 months ago

APE-1784 Ape Does Not Automatically Decode Events Loaded Into It's Contracts

kaleb-keny commented 4 months ago

Abi of the below snipped found here deployments.json

antazoey commented 4 months ago

Use tx.events

kaleb-keny commented 4 months ago

hey @antazoey

tx.events
WARNING: Failed to locate contract at '0xCb5D8fE2B4AfbedB1970CCDc2f2e2919a6114240'.
Out  [10]: [<<UnknownLogAtAddress_0xCb5D8fE2B4AfbedB1970CCDc2f2e2919a6114240_AndLogIndex_0> root=b''>, <<UnknownLogWithSelector_0xa9e04d307e860938fa63307df8b8090e365276e59fcca12ed55656c25e538019> root=b''>]
antazoey commented 4 months ago

Yep, those are the events decoded

kaleb-keny commented 4 months ago

It shows unknown selector thought 🤔 I dont see decoded logs

antazoey commented 4 months ago

It also looks like you are missing the contract type! Once you add that, the logs will decode even better.

kaleb-keny commented 4 months ago

hmm sorry what is a contract type referring to, a contract is an address and an abi, right?

antazoey commented 4 months ago

Are you on Discord or Telegram or something? We move this discussion there, we can help you out!

antazoey commented 4 months ago

Feel free to re-open if you find issues! Check out some of the documentation: https://docs.apeworx.io/ape/stable/methoddocs/contracts.html

kaleb-keny commented 4 months ago

dm'd you via intermediary on discord

antazoey commented 4 months ago

actually this one is best: https://docs.apeworx.io/ape/stable/userguides/contracts.html

antazoey commented 4 months ago

ok actually is a bug lol but is a little different than described originally

kaleb-keny commented 4 months ago

appreciate the fast response, thank you