Skip to content

HUBS-124 adds more relevant ipnft metadata fields to the subgraph #172

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

Conversation

elmariachi111
Copy link
Contributor

@elmariachi111 elmariachi111 commented Jan 16, 2025

extends the Subgraph with more IPNFT metadata. Please look at the matchstick test and notice the elegance how the graph allows you to test this case https://github.com/moleculeprotocol/IPNFT/pull/172/files#diff-e695976b80e70791b2ad0d0c0facbf1cbad3db6164e6f4c6f1b78e39a48012fc. Please be careful when just adopting this on the frontend: if you just trust this approach, the latency between minting & data appears on the subgraph will need to be handled. It's pretty nice to just query and display historic dat

Summary by CodeRabbit

Release Notes v1.3.1

  • New Features

    • Enhanced IP-NFT metadata with additional fields including organization, topic, research lead details, and funding information
    • Improved token tracking with single IP token association
  • Bug Fixes

    • Improved logging for metadata processing to aid debugging
  • Chores

    • Updated IPFS service image to latest version
    • Bumped subgraph deployment version to 1.3.1
  • Tests

    • Added comprehensive metadata handling test suite

Signed-off-by: Stefan Adolf <stefan@molecule.to>
uses a later ipfs node for local envs

Signed-off-by: Stefan Adolf <stefan@molecule.to>
uses strings for the funding amount

Signed-off-by: Stefan Adolf <stefan@molecule.to>
Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces comprehensive updates to the subgraph implementation for IP-NFT metadata handling. The changes span multiple files, including the GraphQL schema, mapping files, and test fixtures. The primary focus is on enhancing metadata extraction, adding new fields for project and funding details, and improving logging mechanisms. The IPFS service in the docker-compose file is also updated to a newer image version, and the deployment scripts are incrementally versioned to 1.3.1.

Changes

File Change Summary
docker-compose.yml Updated IPFS image from v0.30.0 to master-2025-01-15-1768204
subgraph/.gitignore Added new ignore entries: tests/.bin and .latest.json
subgraph/package.json Updated deployment script version labels from 1.3.0 to 1.3.1 for Sepolia and Mainnet
subgraph/schema.graphql Added multiple new fields to Ipnft and IpnftMetadata types, including ipToken, initialSymbol, organization, etc.
subgraph/src/ipnftMapping.ts Enhanced logging messages with function context prefixes
subgraph/src/metadataMapping.ts Improved metadata handling with more comprehensive field extraction
subgraph/src/tokenizerMapping.ts Added import for Ipnft and implemented ipToken assignment
subgraph/tests/fixtures/ipnft_1.json New test fixture with detailed IP-NFT metadata
subgraph/tests/metadata.test.ts Added new test case for metadata handling

Sequence Diagram

sequenceDiagram
    participant Tokenizer
    participant Subgraph
    participant IPFS
    participant Metadata

    Tokenizer->>Subgraph: Create IPT
    Subgraph->>Metadata: Fetch Metadata
    IPFS-->>Metadata: Retrieve JSON
    Metadata->>Subgraph: Parse Metadata
    Subgraph->>Subgraph: Save Enriched Metadata
Loading

Possibly related PRs

Suggested reviewers

  • nour-karoui

Poem

🐰 Metadata dancing, fields so bright
Subgraph evolves with pure delight
IPFS whispers secrets anew
Version bumped, our code rings true
Rabbit hops through GraphQL's embrace! 🌟

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@elmariachi111 elmariachi111 requested a review from endro42 January 16, 2025 14:25
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (8)
subgraph/src/tokenizerMapping.ts (1)

27-31: Consider adding error logging for missing Ipnft.

While the null check is correct, consider adding error logging when the Ipnft is not found to help with debugging.

  let ipnft = Ipnft.load(event.params.ipnftId.toString());
  if (ipnft) {
    ipnft.ipToken = event.params.tokenContract
    ipnft.save()
+ } else {
+   log.warning('Ipnft not found for id: {}', [event.params.ipnftId.toString()])
  }
subgraph/tests/metadata.test.ts (2)

10-24: Enhance test coverage with additional test cases.

While the current test verifies successful metadata parsing, consider adding:

  1. Negative test cases for missing or malformed metadata
  2. Tests for all metadata fields, not just a subset
  3. Tests for error conditions in IPFS data fetching

25-25: Remove commented debug code.

The commented logStore() line appears to be debugging code that should be removed.

subgraph/src/metadataMapping.ts (1)

73-80: Improve type conversion documentation and error handling.

The comment about type conversion could be more explicit, and error handling for the conversion should be added.

-           // on json metadata this can be a decimal value. I'm using a string to store as there's imo no f64 compatible decimal type on the schema scalar types
-           // https://thegraph.com/docs/en/subgraphs/developing/creating/ql-schema/#built-in-scalar-types
+           // Store decimal values as strings since The Graph's schema doesn't support floating-point types
+           // See: https://thegraph.com/docs/en/subgraphs/developing/creating/ql-schema/#built-in-scalar-types
+           try {
              ipnftMetadata.fundingAmount_value = _fundingAmount_value.toF64().toString()
              ipnftMetadata.fundingAmount_decimals = i8(_fundingAmount_decimals.toI64())
              ipnftMetadata.fundingAmount_currency = _fundingAmount_currency.toString()
              ipnftMetadata.fundingAmount_currencyType = _fundingAmount_currencyType.toString()
+           } catch (e) {
+             log.error('Failed to convert funding amount values: {}', [e.toString()])
+           }
deploy/inittest.sh (1)

20-23: Consider improving the network configuration handling.

The current approach using sed commands is marked as a "bad local config hack". Consider:

  1. Using environment variables or configuration files instead
  2. Adding platform-specific sed syntax for Linux compatibility
subgraph/tests/fixtures/ipnft_1.json (1)

22-24: Avoid hardcoding network-specific values in test fixtures.

The contract address is hardcoded to the Sepolia network. Consider making this configurable or using a placeholder address for tests.

       {
         "conditionType": "evmContract",
-        "contractAddress": "0x152B444e60C526fe4434C721561a077269FcF61a",
-        "chain": "sepolia",
+        "contractAddress": "{{CONTRACT_ADDRESS}}",
+        "chain": "{{NETWORK}}",
         "functionName": "canRead",
subgraph/schema.graphql (2)

24-26: Consider making essential metadata fields non-nullable.

Fields like organization and topic appear to be essential metadata. Consider making them non-nullable if they are required fields in the business logic.

-  initialSymbol: String
-  organization: String
-  topic: String
+  initialSymbol: String!
+  organization: String!
+  topic: String!

31-34: Ensure consistent naming convention for nested fields.

The funding amount fields use underscores, while GraphQL typically uses camelCase. Consider updating the field names for consistency.

-  fundingAmount_value: String
-  fundingAmount_decimals: Int8
-  fundingAmount_currency: String
-  fundingAmount_currencyType: String
+  fundingAmountValue: String
+  fundingAmountDecimals: Int8
+  fundingAmountCurrency: String
+  fundingAmountCurrencyType: String
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4589881 and 05a2fbb.

📒 Files selected for processing (10)
  • deploy/inittest.sh (1 hunks)
  • docker-compose.yml (1 hunks)
  • subgraph/.gitignore (1 hunks)
  • subgraph/package.json (1 hunks)
  • subgraph/schema.graphql (2 hunks)
  • subgraph/src/ipnftMapping.ts (1 hunks)
  • subgraph/src/metadataMapping.ts (2 hunks)
  • subgraph/src/tokenizerMapping.ts (2 hunks)
  • subgraph/tests/fixtures/ipnft_1.json (1 hunks)
  • subgraph/tests/metadata.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • subgraph/.gitignore
  • subgraph/src/ipnftMapping.ts
🔇 Additional comments (2)
subgraph/src/tokenizerMapping.ts (1)

6-6: LGTM! Import statement updated correctly.

The import statement now includes the Ipnft entity alongside IPT.

subgraph/package.json (1)

11-12: Verify version label consistency across deployment environments.

The version label has been updated to 1.3.1-dev.9 for both Sepolia and Mainnet deployments, which is good for consistency. However, using a development version (dev.9) in the Mainnet deployment script might not be ideal for production.

✅ Verification successful

Version labels are consistent, but consider production versioning strategy

The version label 1.3.1-dev.9 is consistently used across all deployment configurations. While using a development version in mainnet deployment scripts is unusual, it appears to be intentional for testing purposes. Consider establishing a clear versioning strategy for production releases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other version references that need to be updated
rg "1\.3\.0|1\.3\.1" --type yaml --type json

Length of output: 546

Copy link

@endro42 endro42 left a comment

Choose a reason for hiding this comment

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

LGTM!

@elmariachi111 elmariachi111 force-pushed the feature/hubs-124-add-more-relevant-ipnft-metadata-fields-to-the-subgraph branch from 05a2fbb to c9c83f1 Compare January 16, 2025 22:40
adds ipfs reading / conversion tests
rolls back pnpm to yarn
deescalates sample key
releases 1.3.1

Signed-off-by: Stefan Adolf <stefan@molecule.to>
@elmariachi111 elmariachi111 force-pushed the feature/hubs-124-add-more-relevant-ipnft-metadata-fields-to-the-subgraph branch from c9c83f1 to d221d3b Compare January 16, 2025 22:47
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
subgraph/src/metadataMapping.ts (3)

36-49: Consider adding logging for missing project details fields.

For consistency with the initial_symbol handling, consider adding logging when organization or topic fields are missing. This would help with debugging.

        if (_organization) {
          ipnftMetadata.organization = _organization.toString()
+       } else {
+         log.info("[handlemetadata] organization not found", [])
        }

        let _topic = projectDetails.get('topic')
        if (_topic) {
          ipnftMetadata.topic = _topic.toString()
+       } else {
+         log.info("[handlemetadata] topic not found", [])
        }

51-62: Consider handling partial research lead data.

The current implementation only saves research lead data if both email and name are present. Consider:

  1. Adding logging when fields are missing
  2. Allowing partial data to be saved
        if (_research_lead) {
          let researchLead = _research_lead.toObject()
          let researchLead_email = researchLead.get('email')
          let researchLead_name = researchLead.get('name')
          
-         if (researchLead_email && researchLead_name) {
+         if (researchLead_email) {
            ipnftMetadata.researchLead_email = researchLead_email.toString()
+         } else {
+           log.info("[handlemetadata] research_lead email not found", [])
+         }
+         if (researchLead_name) {
            ipnftMetadata.researchLead_name = researchLead_name.toString()
+         } else {
+           log.info("[handlemetadata] research_lead name not found", [])
          }
        }

64-82: Consider handling partial funding amount data.

The current implementation only saves funding amount data if all fields are present. Consider:

  1. Adding logging for missing fields
  2. Allowing partial data to be saved when available
        if (_funding_amount) {
          let funding_amount = _funding_amount.toObject()
          let _fundingAmount_value = funding_amount.get('value')
          let _fundingAmount_decimals = funding_amount.get('decimals')
          let _fundingAmount_currency = funding_amount.get('currency')
          let _fundingAmount_currencyType = funding_amount.get('currency_type')

-         if (_fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType) {
+         if (_fundingAmount_value) {
            ipnftMetadata.fundingAmount_value = _fundingAmount_value.toF64().toString()
+         } else {
+           log.info("[handlemetadata] funding_amount value not found", [])
+         }
+         if (_fundingAmount_decimals) {
            ipnftMetadata.fundingAmount_decimals = i8(_fundingAmount_decimals.toI64())
+         } else {
+           log.info("[handlemetadata] funding_amount decimals not found", [])
+         }
+         if (_fundingAmount_currency) {
            ipnftMetadata.fundingAmount_currency = _fundingAmount_currency.toString()
+         } else {
+           log.info("[handlemetadata] funding_amount currency not found", [])
+         }
+         if (_fundingAmount_currencyType) {
            ipnftMetadata.fundingAmount_currencyType = _fundingAmount_currencyType.toString()
+         } else {
+           log.info("[handlemetadata] funding_amount currency_type not found", [])
          }
        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9c83f1 and d221d3b.

📒 Files selected for processing (5)
  • subgraph/.gitignore (1 hunks)
  • subgraph/package.json (1 hunks)
  • subgraph/src/metadataMapping.ts (2 hunks)
  • subgraph/tests/fixtures/ipnft_1.json (1 hunks)
  • subgraph/tests/metadata.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • subgraph/.gitignore
  • subgraph/package.json
  • subgraph/tests/metadata.test.ts
  • subgraph/tests/fixtures/ipnft_1.json
🔇 Additional comments (4)
subgraph/src/metadataMapping.ts (4)

19-21: Remove duplicate save() call.

The entity is saved twice: once after basic metadata and again at the end of the function. Remove the first save() call as it's redundant.

      ipnftMetadata.description = description.toString()
-     ipnftMetadata.save()
    } else {

22-23: LGTM! Good addition of logging.

The logging statement will help with debugging when essential metadata fields are missing.


25-34: LGTM! Well-structured properties handling.

Good practices observed:

  • Proper null checks
  • Explicit default value
  • Helpful logging for debugging

74-75: LGTM! Helpful type conversion documentation.

Good practice: The comment clearly explains the rationale behind using string type for decimal values and includes a reference to the documentation.

@@ -9,6 +9,9 @@ type Ipnft @entity {
ipts: [IPT!] @derivedFrom(field: "ipnft")
metadata: IpnftMetadata
updatedAtTimestamp: BigInt

# as of 1.3 the Tokenizer only will create 1 ipt instance, in contrast to the ipts field above.
ipToken: Bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the reason to add this field when we have the ipts field? for the Tokenizer 1.3 we would have an array with only one element

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly. That's what the comment says. This is here as we since 1.3 only need 1 IPT instance but never updated the subgraph accordingly. Mainly as we need to also upgrade the frontend. If we'd agree that the only IPT is just one field, we can easily adopt the frontend and switch off the ipts array. The more pragmatic reason for this field being a plain address is that Tom can simply use it for ordering IPNFTs.

@elmariachi111 elmariachi111 merged commit 0cc9189 into main Jan 17, 2025
2 checks passed
@elmariachi111 elmariachi111 deleted the feature/hubs-124-add-more-relevant-ipnft-metadata-fields-to-the-subgraph branch January 17, 2025 15:10
@Annyrich2
Copy link

Hello

I’m currently testing a large-scale smart contract deployment on the Sepolia testnet and need a higher amount of Sepolia ETH than most faucets provide. My project involves deploying + smart contracts, each managing multiple wallets, so I’m looking for [X amount] of Sepolia ETH to continue testing.

I’ve already used available faucets, but they have daily limits that slow down my progress. If anyone has extra Sepolia ETH or knows a source for larger distributions, I’d really appreciate the help.

1000 or 500 sepolia is all I need
My Sepolia address:

0x96070538C13533Cb838B2fb1799A3e5f621155eD

I’m happy to return any unused ETH after testing or contribute back to the community in other ways. Thanks in advance!

Best wishes
Shepherd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants