Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Sourcify contract information lookup #1899

Merged
merged 9 commits into from
Jan 21, 2025

Conversation

0237h
Copy link
Collaborator

@0237h 0237h commented Jan 10, 2025

Etherscan requires an API key for ABI lookup and other operations.
Sourcify (https://sourcify.dev/) is an open-source decentralized alternative.

Features

  • Contract name, ABI and creation transaction hash (start block) from Sourcify API.
  • Runs before the registry lookup and replaces default values (not interactive) if not provided by the user.
    This means priority for CLI parameters looks like:
    user submitted (env/CLI args) > Sourcify API > Default values > Registry fetch

Closes #1001.

Details

The getFromSourcify method returns all the information related to contracts that are normally fetch from registry URLs:

{ abi: ABI; startBlock: string; name: string }

It internally makes the RPC call for the startBlock using the creation transaction hash.

@0237h 0237h self-assigned this Jan 10, 2025
Copy link

changeset-bot bot commented Jan 10, 2025

🦋 Changeset detected

Latest commit: dfd7bde

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphprotocol/graph-cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@0237h 0237h force-pushed the feat/support-sourcify-lookups branch from 6464dbd to e9206b6 Compare January 10, 2025 20:04
- Contract name, ABI and creation transaction hash (start block)
  from [Sourcify API](https://docs.sourcify.dev/docs/api/).
- Runs before the registry lookup and replaces default values
  (not interactive) if not provided by the user.
  This means priority for CLI parameters looks like:
  user submitted (env/CLI args) > Sourcify API > Default values > Registry fetch
@0237h 0237h force-pushed the feat/support-sourcify-lookups branch from e9206b6 to c5c9010 Compare January 13, 2025 21:08
@0237h 0237h marked this pull request as ready for review January 13, 2025 21:10
@0237h 0237h force-pushed the feat/support-sourcify-lookups branch from 5d4312f to 19cbd8a Compare January 13, 2025 21:19
@0237h 0237h requested a review from YaroShkvorets January 13, 2025 21:20
Copy link
Collaborator

@YaroShkvorets YaroShkvorets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Can we add a couple of test cases to https://github.com/graphprotocol/graph-tooling/blob/main/packages/cli/src/command-helpers/contracts.test.ts

Also, any idea why it can't find source code on Sourcify for this contract on mainnet: 0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB. It exists on Etherscan. I thought it's supposed to import it from etherscan?

@0237h 0237h force-pushed the feat/support-sourcify-lookups branch from 25fd23e to 7aa683f Compare January 16, 2025 16:07
@0237h 0237h requested a review from YaroShkvorets January 16, 2025 16:08
0237h and others added 3 commits January 16, 2025 11:22

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Collaborator

@YaroShkvorets YaroShkvorets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
added some retry logic to etherscan tests to handle rate-limited endpoints

@YaroShkvorets YaroShkvorets merged commit 8cdaf31 into graphprotocol:main Jan 21, 2025
8 checks passed
incrypto32 pushed a commit that referenced this pull request Jan 30, 2025
* Add support for Sourcify contract information lookup

- Contract name, ABI and creation transaction hash (start block)
  from [Sourcify API](https://docs.sourcify.dev/docs/api/).
- Runs before the registry lookup and replaces default values
  (not interactive) if not provided by the user.
  This means priority for CLI parameters looks like:
  user submitted (env/CLI args) > Sourcify API > Default values > Registry fetch

* Fix incorrect ABI instantiation for `init` with parameters

* Add changeset

* Throw early for non-EVM chains

* Add tests for contract name and startBlock info

* Add test for non-evm contract lookup

* removed hardcoded wax check, added test

* add retries to tests

---------

Co-authored-by: YaroShkvorets <shkvorets@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Support for Sourcify
2 participants