Skip to content

Conversation

@elmariachi111
Copy link
Contributor

@elmariachi111 elmariachi111 commented Oct 4, 2024

this doesn't exactly work as expected but also doesn't really break sth :)

https://linear.app/molecule-to/issue/HUBS-90/read-ipnft-ipfs-metadata-during-subgraph-indexing

Summary by CodeRabbit

  • New Features

    • Introduced new fields in the IPNFT schema for enhanced metadata representation.
    • Added a new data source for IPNFT metadata to improve handling and storage.
    • Implemented new functions for processing IPNFT metadata and event handling.
  • Bug Fixes

    • Updated deployment scripts to ensure correct version labeling for Sepolia and Mainnet networks.
  • Documentation

    • Enhanced clarity in the GraphQL schema with new types and fields.

@elmariachi111 elmariachi111 force-pushed the feature/hubs-90-read-ipnft-ipfs-metadata-during-subgraph-indexing branch from c2968cb to 71be927 Compare October 4, 2024 16:11
Base automatically changed from feature/ipn-24-ipnft-contract-allows-metadata-cid-updates to main October 4, 2024 20:25
@elmariachi111 elmariachi111 force-pushed the feature/hubs-90-read-ipnft-ipfs-metadata-during-subgraph-indexing branch from 71be927 to 9130b99 Compare October 8, 2024 19:14
@coderabbitai
Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes in this pull request involve updates to the @molecule/ipfnt-subgraph project, specifically modifying the package.json, GraphQL schema, TypeScript mapping files, and the subgraph configuration. The package.json updates version labels for deployment scripts. The GraphQL schema introduces new fields and a new type for IPNFT metadata. TypeScript files enhance event handling and metadata management, including new functions for processing metadata. Additionally, a new data source for IPNFT metadata is defined in the subgraph configuration.

Changes

File Path Change Summary
subgraph/package.json Updated version labels in deploy:sepolia and deploy:mainnet scripts from 1.2.0 to 1.2.1.
subgraph/schema.graphql Added fields metadata (type IpnftMetadata) and updatedAtTimestamp (type BigInt) to Ipnft. Defined new type IpnftMetadata with required fields.
subgraph/src/ipnftMapping.ts Added functions for handling read access, reservations, and enhanced minting and metadata updates. Updated existing functions to manage IPNFT metadata.
subgraph/src/metadataMapping.ts Introduced handleMetadata function to process IPNFT metadata from bytes to JSON.
subgraph/subgraph.yaml Added new data source entry for IpnftMetadata with IPFS interaction and defined mapping details.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Subgraph
    participant IPNFT
    participant IPFS

    Client->>Subgraph: Request IPNFT Metadata
    Subgraph->>IPNFT: Fetch IPNFT Data
    IPNFT-->>Subgraph: Return IPNFT Data
    Subgraph->>IPFS: Retrieve Metadata
    IPFS-->>Subgraph: Return Metadata
    Subgraph-->>Client: Send IPNFT Metadata
Loading

🐰 In the garden where data blooms,
New fields sprout, dispelling glooms.
With metadata fresh and bright,
Our IPNFTs take flight!
Version bumps and scripts align,
In the world of code, all is fine! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

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: 7

🧹 Outside diff range and nitpick comments (8)
subgraph/src/metadataMapping.ts (1)

1-22: Summary: Good start, but needs some refinements for robustness.

Overall, the handleMetadata function provides a good foundation for processing IPNFT metadata. However, there are several areas where it could be improved:

  1. Error handling for JSON parsing
  2. Clarification of the metadata identifier
  3. Handling of partial metadata information
  4. Conditional saving of metadata objects

These improvements will make the function more robust and flexible in handling various metadata scenarios.

Would you like assistance in implementing these suggestions or clarifying any of the proposed changes?

subgraph/schema.graphql (3)

10-12: LGTM! Consider making updatedAtTimestamp non-nullable.

The addition of metadata and updatedAtTimestamp fields to the Ipnft type enhances the data model by allowing for structured metadata storage and tracking of update times. This is a good improvement that maintains backwards compatibility.

Consider making updatedAtTimestamp non-nullable (i.e., updatedAtTimestamp: BigInt!) if it's guaranteed to always have a value. This would ensure data integrity and simplify queries that rely on this field.


14-19: LGTM! Consider adding optional fields for extended metadata.

The introduction of the IpnftMetadata type with essential NFT metadata fields is a good addition to the schema. It provides a structured way to store and query IPNFT metadata.

Consider the following suggestions to enhance the metadata structure:

  1. Add optional fields for extended metadata that might be specific to your use case. For example:

    attributes: [Attribute!]

    Where Attribute could be a new type with trait_type and value fields.

  2. Consider adding a createdAt: BigInt! field to track when the metadata was first created.

  3. If versioning of metadata is important, consider adding a version: Int! field.

These suggestions can make the metadata structure more flexible and informative for future use cases.


Line range hint 1-19: Summary: Good additions for metadata handling.

The changes to the GraphQL schema enhance the IPNFT data model by introducing structured metadata storage and update tracking. These additions are backwards compatible and provide more detailed information about IPNFTs.

Consider the following architectural implications:

  1. Ensure that the subgraph indexing code is updated to populate the new metadata and updatedAtTimestamp fields for the Ipnft type.

  2. Update any API or client code that queries the subgraph to take advantage of the new metadata fields.

  3. If you plan to migrate existing IPNFTs to include metadata, consider creating a migration strategy to populate the new fields for existing entries.

  4. Review and update any documentation or API specifications to reflect these schema changes.

These changes lay a good foundation for more detailed IPNFT information and should improve the overall functionality of the system.

subgraph/subgraph.yaml (1)

231-243: LGTM with minor formatting suggestions.

The addition of the IpnftMetadata data source aligns well with the PR objective of adding metadata templates to the subgraph. However, there are a few minor formatting inconsistencies:

  1. The indentation of this new data source should be aligned with other data sources in the file.
  2. The "network" field is typically placed right after the "kind" field in other data sources.

Consider applying these formatting changes for consistency:

-  - name: IpnftMetadata
-    kind: file/ipfs
-    mapping:
-      apiVersion: 0.0.7
-      language: wasm/assemblyscript
-      file: ./src/metadataMapping.ts
-      handler: handleMetadata
-      entities:
-        - IpnftMetadata
-      abis:
-        - name: IPNFT
-          file: ./abis/IPNFT.json
-    network: foundry
+  - name: IpnftMetadata
+    kind: file/ipfs
+    network: foundry
+    mapping:
+      apiVersion: 0.0.7
+      language: wasm/assemblyscript
+      file: ./src/metadataMapping.ts
+      handler: handleMetadata
+      entities:
+        - IpnftMetadata
+      abis:
+        - name: IPNFT
+          file: ./abis/IPNFT.json
subgraph/src/ipnftMapping.ts (3)

104-107: Check for empty string in newUri

The check if (!newUri) might not catch cases where newUri is an empty string. In TypeScript, an empty string is a falsy value, but it might be safer to explicitly check for an empty string to ensure proper handling.

Modify the condition to:

 if (!newUri || newUri === '') {
   log.debug("No new URI found for token, likely just minted {}", [event.params._tokenId.toString()])
   return 
 }

15-15: Remove unused import TransferEvent

The TransferEvent import is added but not used in the code. Unused imports can clutter the code and may lead to confusion.

Consider removing the unused import:

-import {
-  Transfer as TransferEvent
-} from '../generated/IPNFT/IPNFT'

104-107: Ensure consistency in logging levels

In handleMetadataUpdated, the code uses log.debug to report missing newUri. Depending on the importance of this event, you might consider using log.warning or log.error to make it more noticeable in the logs.

Evaluate the logging level to ensure that important issues are appropriately flagged.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 94bd697 and 9130b99.

📒 Files selected for processing (5)
  • subgraph/package.json (1 hunks)
  • subgraph/schema.graphql (1 hunks)
  • subgraph/src/ipnftMapping.ts (3 hunks)
  • subgraph/src/metadataMapping.ts (1 hunks)
  • subgraph/subgraph.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • subgraph/package.json
🧰 Additional context used
🔇 Additional comments (2)
subgraph/src/metadataMapping.ts (1)

1-4: LGTM: Imports and function signature are appropriate.

The imports and function signature are well-defined and appropriate for handling metadata in a subgraph context. The use of Bytes as the input type is suitable for processing raw metadata content.

subgraph/subgraph.yaml (1)

231-243: Please clarify the implications of using "file/ipfs" kind.

The new IpnftMetadata data source uses kind: file/ipfs, which differs from the ethereum/contract kind used by other data sources. Additionally, it doesn't include a source section, which is present in other data sources.

  1. Could you explain the implications of using file/ipfs kind?
  2. Is the absence of a source section intentional and expected for this kind of data source?
  3. How does this data source interact with the IPFS system to fetch and process metadata?

Understanding these aspects will help ensure that the implementation aligns with the intended functionality for handling IPNFT metadata.

To help verify the usage of file/ipfs kind in The Graph's subgraph system, let's search for any documentation or examples:

only adds metadata relation if metadata is good

Signed-off-by: stadolf <[email protected]>
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: 1

🧹 Outside diff range and nitpick comments (1)
subgraph/src/ipnftMapping.ts (1)

78-91: Add unit tests for updateIpnftMetadata

The new updateIpnftMetadata function is crucial for handling IPNFT metadata updates. To ensure its correctness and robustness, consider adding unit tests that cover various scenarios, such as:

  • Valid IPFS URIs
  • Invalid URIs that do not start with ipfs://
  • Empty or null URI values
  • Edge cases with unusual but valid URIs

Would you like assistance in creating unit tests for this function or opening a GitHub issue to track this task?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9130b99 and bd86bfe.

📒 Files selected for processing (2)
  • subgraph/src/ipnftMapping.ts (3 hunks)
  • subgraph/src/metadataMapping.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • subgraph/src/metadataMapping.ts
🧰 Additional context used
🪛 Biome
subgraph/src/ipnftMapping.ts

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

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

🧹 Outside diff range and nitpick comments (3)
subgraph/src/ipnftMapping.ts (3)

Line range hint 33-68: LGTM: handleReadAccess function implemented correctly

The function correctly handles the ReadAccessGrantedEvent, creating a unique identifier for read access and saving it in the CanRead entity. The error handling and IPNFT existence check are properly implemented.

For improved code clarity, consider extracting the unique identifier generation logic into a separate helper function. This would make the main function more concise and easier to read.

🧰 Tools
🪛 Biome

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


78-88: LGTM with suggestion: updateIpnftMetadata function

The function correctly handles the metadata update process for IPNFTs. However, there's a minor issue that could be improved:

When an invalid URI format is detected, the function logs an error but continues execution. Consider adding a return statement after the error log to prevent updating the IPNFT with potentially invalid data.

Suggested improvement:

 function updateIpnftMetadata(ipnft: Ipnft, uri: string, timestamp: BigInt): void {
     let ipfsLocation = uri.replace('ipfs://', '');
     if (!ipfsLocation || ipfsLocation == uri) {
       log.error("Invalid URI format for tokenId {}: {}", [ipnft.id, uri]);
+      return;
     }

     ipnft.tokenURI = uri;
     ipnft.metadata = ipfsLocation;
     ipnft.updatedAtTimestamp = timestamp;
     IpnftMetadataTemplate.create(ipfsLocation);
 }

This change ensures that the IPNFT is not updated with invalid metadata.


112-116: LGTM with suggestion: handleMetadataUpdated function improvements

The function has been updated to include null and empty string checks for newUri, which improves error handling. The use of the new updateIpnftMetadata helper function aligns with the refactoring done in other parts of the code.

However, there's a minor inconsistency in the error logging:

  1. When newUri is null or an empty string, it logs a debug message saying "no new uri found for token, likely just minted". This message might be misleading since this function handles metadata updates, not minting.

Consider updating the log message to better reflect the metadata update context:

-    log.debug("no new uri found for token, likely just minted {}", [event.params._tokenId.toString()])
+    log.debug("No new URI found for token {} during metadata update", [event.params._tokenId.toString()])

This change makes the log message more accurate in the context of metadata updates.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bd86bfe and c952a3e.

📒 Files selected for processing (1)
  • subgraph/src/ipnftMapping.ts (3 hunks)
🧰 Additional context used
🪛 Biome
subgraph/src/ipnftMapping.ts

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (5)
subgraph/src/ipnftMapping.ts (5)

3-3: LGTM: Import statements updated correctly

The new import statements align with the added functionality in the file. The inclusion of BigInt, various event types, and IpnftMetadataTemplate suggests enhanced handling of IPNFT-related operations.

Also applies to: 11-11, 14-16, 18-19

🧰 Tools
🪛 Biome

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


Line range hint 70-75: LGTM: handleReservation function implemented correctly

The function properly handles the ReservedEvent by creating a new Reservation entity with the provided information. The implementation is concise and correct.


96-99: LGTM: handleMint function updated correctly

The handleMint function has been updated to use the new updateIpnftMetadata helper function, which simplifies the metadata update process during minting. The reservation removal logic remains intact, ensuring consistency with the previous implementation.


3-3: Static analysis hint: Ignore BigInt shadowing warning

The static analysis tool flagged the import of BigInt as potentially shadowing the global BigInt property. However, in the context of AssemblyScript and The Graph, importing BigInt from @graphprotocol/graph-ts is correct and necessary.

This warning can be safely ignored as it's likely a false positive due to the tool not being aware of the specific environment of The Graph's AssemblyScript.

🧰 Tools
🪛 Biome

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


Line range hint 1-118: Overall assessment: Significant improvements to IPNFT handling

This update introduces several enhancements to the IPNFT handling:

  1. New event handlers for read access and reservations.
  2. A helper function for updating IPNFT metadata, improving code reusability.
  3. Improved error handling and logging in existing functions.

These changes align well with the PR objectives of adding metadata templates to the subgraph. The code is generally well-structured and follows good practices. The minor suggestions provided in the review comments will further improve code clarity and robustness.

Great job on enhancing the IPNFT functionality!

@elmariachi111 elmariachi111 force-pushed the feature/hubs-90-read-ipnft-ipfs-metadata-during-subgraph-indexing branch from c952a3e to 2b386c9 Compare October 8, 2024 21:10
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

🧹 Outside diff range and nitpick comments (2)
subgraph/src/ipnftMapping.ts (2)

Line range hint 33-71: LGTM: handleReadAccess function implemented correctly

The function correctly processes read access events and creates a unique identifier for each access grant. However, consider adding error logging when the IPNFT doesn't exist or when encoding fails.

Consider adding error logging:

 if (!ipnft) {
+  log.error("IPNFT not found for tokenId: {}", [event.params.tokenId.toString()]);
   return;
 }
 // ... (existing code)
 if (!encoded) {
+  log.error("Failed to encode tuple for tokenId: {}", [event.params.tokenId.toString()]);
   return;
 }
🧰 Tools
🪛 Biome

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


113-117: LGTM: handleMetadataUpdated function improved

The function now includes better error handling for the newUri and uses the updateIpnftMetadata helper, reducing code duplication. These changes align with previous review suggestions.

Consider adding more detailed error logging:

 if (!newUri || newUri == "") {
-  log.debug("no new uri found for token, likely just minted {}", [event.params._tokenId.toString()])
+  log.warning("No new URI found for token {}, metadata update skipped", [event.params._tokenId.toString()])
   return 
 }

This change provides more context about why the function is returning early.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c952a3e and 2b386c9.

📒 Files selected for processing (1)
  • subgraph/src/ipnftMapping.ts (3 hunks)
🧰 Additional context used
🪛 Biome
subgraph/src/ipnftMapping.ts

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (5)
subgraph/src/ipnftMapping.ts (5)

3-3: LGTM: Import statements updated correctly

The new imports align with the added functionality, and renaming IPNFT to IPNFTContract improves code clarity.

Also applies to: 11-11, 14-16, 18-19

🧰 Tools
🪛 Biome

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


Line range hint 73-77: LGTM: handleReservation function implemented correctly

The function properly creates and saves a new Reservation entity with the relevant event parameters.


78-89: LGTM: updateIpnftMetadata function implemented correctly

The function effectively updates the IPNFT metadata, validating the URI format and updating all necessary fields. This implementation aligns with the previous refactoring suggestion, improving code maintainability.


97-100: LGTM: handleMint function updated correctly

The function now uses the updateIpnftMetadata helper, reducing code duplication. The removal of the Reservation after minting is a logical step in the process.


3-3: Ignore static analysis warning about BigInt import

The static analysis tool flagged the import of BigInt as potentially shadowing the global BigInt property. However, in the context of AssemblyScript and The Graph, importing BigInt from @graphprotocol/graph-ts is correct and necessary. This warning can be safely ignored as it's likely a false positive due to the tool's lack of context about The Graph's development environment.

🧰 Tools
🪛 Biome

[error] 3-3: Do not shadow the global "BigInt" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

@elmariachi111 elmariachi111 changed the title adds metadata templates to the subgraph HUBS-90 adds metadata templates to the subgraph Oct 8, 2024
@elmariachi111 elmariachi111 merged commit 67ad692 into main Oct 8, 2024
2 checks passed
@elmariachi111 elmariachi111 deleted the feature/hubs-90-read-ipnft-ipfs-metadata-during-subgraph-indexing branch October 8, 2024 21:26
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.

2 participants