Skip to content

Conversation

@nour-karoui
Copy link
Contributor

@nour-karoui nour-karoui commented Oct 30, 2025

  • Update Subgraph aabis
  • Add error handling if the metadata is null and deploy a new version on Sepolia

Summary by CodeRabbit

  • New Features

    • Added token wrapping support: new wrap flows, events, and governance controls for wrapped IP tokens.
  • Bug Fixes

    • Improved metadata handling with early validation, safer JSON parsing, and clearer warnings for malformed or missing content.
  • Chores

    • Bumped subgraph deploy version to 1.3.2.
    • Standardized ABI/type annotations and updated related function signatures for consistency.

@nour-karoui nour-karoui changed the title chore(subgraph): update subgraph abis / fix(subgraph): add error hand… chore(subgraph): update subgraph abis / fix(subgraph): add error handgit commit -m "chore(subgraph): update subgraph abis / fix(subgraph): add error handling if the metadata is null and deploy a new version on Sepolia" Oct 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 30, 2025

Walkthrough

Updated multiple subgraph ABIs (IPToken, TermsAcceptedPermissioner, Tokenizer), bumped subgraph deploy version label, added guarded JSON parsing/validation to metadataMapping.ts, and removed an anchor reference in subgraph.yaml (formatting/inline mapping).

Changes

Cohort / File(s) Summary
IPToken ABI
subgraph/abis/IPToken.json
Renamed initialize input parameter names: namename_ and symbolsymbol_ (no type/order changes).
TermsAcceptedPermissioner ABI
subgraph/abis/TermsAcceptedPermissioner.json
Replaced internalType occurrences of contract IPToken with contract IIPToken for accept, isValidSignature, and an overload of specificTermsV1.
Tokenizer ABI
subgraph/abis/Tokenizer.json
Added attachIpt, setWrappedIPTokenImplementation, wrappedTokenImplementation; added events TokenWrapped, WrappedIPTokenImplementationUpdated; added errors InvalidTokenContract, InvalidTokenDecimals; updated reinit signature and changed internalType/output references from IPTokenIIPToken.
Deployment config
subgraph/package.json
Bumped --version-label in deploy:sepolia and deploy:mainnet from 1.3.11.3.2.
Mapping logic
subgraph/src/metadataMapping.ts
Added early validation for empty/non-JSON content; switched to json.try_fromBytes(content) with error handling and logging; use parsed JSONValue (parsedValue) for extracting image, name, description, external_url, and properties.
Subgraph manifest
subgraph/subgraph.yaml
Removed an anchor reference and inlined the StakedLockingCrowdSale mapping (anchor → inline mapping); minor formatting cleanup and removal of an example commented block.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Tokenizer
  participant IIPToken as IIPToken (tokenContract)
  participant Wrapped as WrappedIPToken

  Note over Client,Tokenizer #E8F1FF: New attach/wrap flow (ABI additions)
  Client->>Tokenizer: attachIpt(ipnftId, agreementCid, signedAgreement, tokenContract)
  Tokenizer->>IIPToken: validate tokenContract / synthesized(...)
  alt tokenContract valid
    IIPToken-->>Tokenizer: synthesized(address)
    Tokenizer->>Wrapped: setWrappedIPTokenImplementation(addr) / wrappedTokenImplementation()
    Tokenizer-->>Client: return wrappedIpt address
    Tokenizer-->>Tokenizer: emit TokenWrapped / WrappedIPTokenImplementationUpdated
  else invalid tokenContract
    Tokenizer-->>Client: revert InvalidTokenContract or InvalidTokenDecimals
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • subgraph/src/metadataMapping.ts — guarded JSON parse, error paths, and logging details.
    • subgraph/abis/Tokenizer.json — new functions/events/errors and internalType changes; ensure ABI matches on-chain contracts.
    • Cross-check IPTokenIIPToken / renamed initialize params across consumers of these ABIs.
    • subgraph/subgraph.yaml — ensure inlined mapping semantics match previous anchor behavior.

Possibly related PRs

Suggested reviewers

  • elmariachi111
  • endro42

Poem

🐇 I nibble bytes beneath the moonlight,

IIPToken hopped into the night,
JSON guarded, parsed with care,
Wrapped tokens tumble through the air,
The subgraph hums — a rabbit's delight.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "IP-1188: fix failing subgraph" directly corresponds to the linked issue and clearly summarizes the primary objective. The title accurately reflects the main change—implementing error handling to fix the failing subgraph on Sepolia—and includes the issue number for reference. The title is concise, specific to the core problem, and a developer scanning the history would understand this addresses a bug fix for subgraph reliability.
Linked Issues Check ✅ Passed The code changes directly address the objectives stated in linked issue IP-1188. The primary fix—robust error handling for null metadata in metadataMapping.ts—implements content validation, checks for empty content, warns when content is not JSON, and uses guarded JSON parsing with error handling. This directly targets the requirement to fix the failing subgraph and ensure staging works reliably. Supporting changes include ABI updates to reflect contract interface changes and a version bump from 1.3.1 to 1.3.2 for deployment on Sepolia and mainnet.
Out of Scope Changes Check ✅ Passed The changes align with the stated PR objectives which explicitly include "Update Subgraph ABIs" alongside the error handling fix and deployment. All modifications directly support fixing the failing subgraph: the metadataMapping.ts changes address null metadata handling, the ABI updates in IPToken.json, TermsAcceptedPermissioner.json, and Tokenizer.json reflect necessary contract interface updates, and the package.json version bump enables deployment of the fix. The subgraph.yaml formatting changes are minor cleanup with no functional impact.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ip-1188-add-error-handling-for-null-metadata

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d86bf3e and 281c9df.

📒 Files selected for processing (6)
  • subgraph/abis/IPToken.json (1 hunks)
  • subgraph/abis/TermsAcceptedPermissioner.json (3 hunks)
  • subgraph/abis/Tokenizer.json (9 hunks)
  • subgraph/package.json (1 hunks)
  • subgraph/src/metadataMapping.ts (2 hunks)
  • subgraph/subgraph.yaml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • subgraph/subgraph.yaml
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: elmariachi111
PR: moleculeprotocol/IPNFT#166
File: subgraph/src/metadataMapping.ts:8-18
Timestamp: 2024-10-08T19:40:07.111Z
Learning: In `subgraph/src/metadataMapping.ts`, the code is written in AssemblyScript, which cannot use advanced JavaScript features.
📚 Learning: 2024-10-08T19:40:07.111Z
Learnt from: elmariachi111
PR: moleculeprotocol/IPNFT#166
File: subgraph/src/metadataMapping.ts:8-18
Timestamp: 2024-10-08T19:40:07.111Z
Learning: In `subgraph/src/metadataMapping.ts`, the code is written in AssemblyScript, which cannot use advanced JavaScript features.

Applied to files:

  • subgraph/src/metadataMapping.ts
📚 Learning: 2024-10-08T19:40:07.111Z
Learnt from: elmariachi111
PR: moleculeprotocol/IPNFT#166
File: subgraph/src/metadataMapping.ts:8-18
Timestamp: 2024-10-08T19:40:07.111Z
Learning: The NFT metadata standard requires all fields (`image`, `name`, `description`, `external_url`) to be present, and this is validated by a different service before the entity goes onto the chain.

Applied to files:

  • subgraph/src/metadataMapping.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Smart contract tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@nour-karoui nour-karoui changed the title chore(subgraph): update subgraph abis / fix(subgraph): add error handgit commit -m "chore(subgraph): update subgraph abis / fix(subgraph): add error handling if the metadata is null and deploy a new version on Sepolia" IP-1188: fix failing subgraph Oct 30, 2025
@nour-karoui nour-karoui requested a review from 0xmme October 30, 2025 14:51
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
subgraph/src/metadataMapping.ts (1)

109-109: Remove redundant save() call to avoid double-write.

Line 109 unconditionally calls ipnftMetadata.save(), but Line 45 already saves the entity when all required fields are present. This results in:

  • Double-save when all fields exist (performance/efficiency issue)
  • Save with partial data when required fields are missing (data integrity concern)

Apply this diff to remove the redundant save:

       }
     }
-    ipnftMetadata.save()
   }
 }

The entity is already saved at Line 45 when the required fields (name, image, description, externalURL) are present. The properties extraction (lines 50-108) happens after that save, updating optional fields. If you intend to save the optional properties updates, the save should be conditional on whether any properties were actually updated.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1b3abcd and d4915b0.

📒 Files selected for processing (5)
  • subgraph/abis/IPToken.json (1 hunks)
  • subgraph/abis/TermsAcceptedPermissioner.json (3 hunks)
  • subgraph/abis/Tokenizer.json (9 hunks)
  • subgraph/package.json (1 hunks)
  • subgraph/src/metadataMapping.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-10-08T19:40:07.111Z
Learnt from: elmariachi111
PR: moleculeprotocol/IPNFT#166
File: subgraph/src/metadataMapping.ts:8-18
Timestamp: 2024-10-08T19:40:07.111Z
Learning: In `subgraph/src/metadataMapping.ts`, the code is written in AssemblyScript, which cannot use advanced JavaScript features.

Applied to files:

  • subgraph/src/metadataMapping.ts
📚 Learning: 2024-10-08T19:40:07.111Z
Learnt from: elmariachi111
PR: moleculeprotocol/IPNFT#166
File: subgraph/src/metadataMapping.ts:8-18
Timestamp: 2024-10-08T19:40:07.111Z
Learning: The NFT metadata standard requires all fields (`image`, `name`, `description`, `external_url`) to be present, and this is validated by a different service before the entity goes onto the chain.

Applied to files:

  • subgraph/src/metadataMapping.ts
🔇 Additional comments (6)
subgraph/abis/TermsAcceptedPermissioner.json (1)

9-9: LGTM! Type references updated consistently.

The internalType updates from IPToken to IIPToken are consistent across all three occurrences and align with the broader ABI type updates in this PR.

Also applies to: 32-32, 97-97

subgraph/abis/IPToken.json (1)

196-196: LGTM! Parameter naming follows convention.

The underscore suffix (name_, symbol_) is a standard convention to avoid shadowing state variables in the contract implementation.

Also applies to: 201-201

subgraph/src/metadataMapping.ts (1)

1-30: Excellent defensive JSON parsing!

The added validation layers effectively handle edge cases:

  • Empty content check prevents processing invalid data
  • JSON format validation (checking for { or [) provides early detection
  • try_fromBytes with proper error handling prevents parsing failures

This aligns well with the PR objective to add error handling for null metadata.

subgraph/abis/Tokenizer.json (3)

7-40: LGTM! Comprehensive token wrapping functionality added.

The new functions for token wrapping are well-structured:

  • attachIpt: Creates wrapped token from existing ERC20
  • setWrappedIPTokenImplementation: Updates the wrapped token implementation
  • wrappedTokenImplementation: Queries current implementation
  • Updated reinit to support wrapped token configuration

Also applies to: 183-187, 217-229, 332-344


244-244: LGTM! Type updates and new events are consistent.

The ABI updates properly reflect:

  • Type migration from IPToken to IIPToken in existing declarations
  • New TokenWrapped and WrappedIPTokenImplementationUpdated events for observability
  • Consistent use of IIPToken and WrappedIPToken contract types throughout

Also applies to: 385-385, 391-391, 447-465, 534-552


563-572: LGTM! Error types for validation added.

The new error types InvalidTokenContract and InvalidTokenDecimals provide clear failure modes for token wrapping validation.

@nour-karoui nour-karoui force-pushed the fix/ip-1188-add-error-handling-for-null-metadata branch 2 times, most recently from 8b46419 to d86bf3e Compare October 30, 2025 15:27
…ling if the metadata is null and deploy a new version for sepolia and mainnet
@nour-karoui nour-karoui force-pushed the fix/ip-1188-add-error-handling-for-null-metadata branch from d86bf3e to 281c9df Compare October 30, 2025 15:41
Copy link
Contributor

@0xmme 0xmme left a comment

Choose a reason for hiding this comment

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

🔥

@nour-karoui nour-karoui merged commit 7346358 into main Oct 30, 2025
2 checks passed
@nour-karoui nour-karoui deleted the fix/ip-1188-add-error-handling-for-null-metadata branch October 30, 2025 16:10
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.

3 participants