graphprotocol / graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
https://thegraph.com
Apache License 2.0
2.9k stars 968 forks source link

Support multiple contracts per address and improve namespacing #301

Closed yanivtal closed 4 years ago

yanivtal commented 6 years ago

This is how we currently specify a contract to subscribe to in the subgraph manifest. image

Is abi in this context the best name for this attribute? contract may be better. Solidity files can include multiple contracts that get deployed to a single address. Do we currently support accessing multiple contracts at a single address? If not we should update the manifest format to accept a list of contracts. We should then update graph-cli to create contract classes for each contract.

Finally, we may not want to inject globals in the mapping files. Rather, it could be desirable to have developers manually import classes at the top of their files.

Jannis commented 6 years ago

Perhaps we should replace the source field with a contract field and either replace or extend the abi field with a file field, like we use for all other files that are referenced from the manifest. It's strange right now how a name is used here that is then required to be defined in the mapping section. Instead, we could point directly to the ABI file.

This is what it could look like:

dataSources:
- kind: ethereum/contract
  name: AdNetworks
  contract:
    address: "5E2Eb..."
    file: ./abis/AdNetworks.json
  mapping: ...

or

dataSources:
- kind: ethereum/contract
  name: AdNetworks
  contract:
    address: "5E2Eb..."
    abi:
      file: ./abis/AdNetworks.json
  mapping: ...

I suggest we split out the manual imports of generated types into a separate issue because the two really are independent.