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

feat: Enable XP NFT to be transferable #199

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

andresaiello
Copy link
Collaborator

@andresaiello andresaiello commented Dec 30, 2024

Summary

  • Enable NFT to be transferable
  • Add test

Summary by CodeRabbit

  • New Features

    • Introduced a new version (V3) of the XP NFT contract with enhanced tag management functionality.
    • Added ability to move and update tags associated with NFT tokens.
    • Implemented a new event to log tag updates.
  • Improvements

    • Enhanced contract flexibility by allowing method overriding in base contracts.
    • Updated version tracking mechanism for the NFT contract.
  • Tests

    • Added comprehensive test suite for XP NFT V3 contract.
    • Implemented test cases for NFT minting, transfer, and tag management.

Copy link

coderabbitai bot commented Dec 30, 2024

Caution

Review failed

The pull request is closed.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

TypeError: prettier.resolveConfig.sync is not a function
Occurred while linting /packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts:1
Rule: "prettier/prettier"
at Program (/node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:138:40)
at ruleErrorHandler (/node_modules/eslint/lib/linter/linter.js:1076:28)
at /node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach ()
at Object.emit (/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
at /node_modules/eslint/lib/linter/linter.js:1111:32

📝 Walkthrough

Walkthrough

This pull request introduces modifications to the XP NFT contract series, focusing on enhancing the flexibility and functionality of token transfers and versioning. The changes span three contract files (xpNFT.sol, xpNFT_V2.sol, and xpNFT_V3.sol). Key updates include making certain methods virtual to allow overriding, introducing tag management for NFTs in the new ZetaXP_V3 contract, and implementing a robust transfer mechanism that incorporates tag updates.

Changes

File Change Summary
packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol Updated _transfer method signature from internal override to internal virtual override
packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V2.sol Updated version method signature from public pure override to public pure virtual override
packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V3.sol New contract with added TagUpdated event, overridden version method, modified _transfer, and new moveTagToToken function
packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts Added comprehensive test suite for XP NFT V3 contract, including NFT minting and tag management tests

Sequence Diagram

sequenceDiagram
    participant Owner as NFT Owner
    participant Contract as ZetaXP_V3
    participant NewOwner as New Owner

    Owner->>Contract: moveTagToToken(tokenId, tag)
    Contract-->>Owner: Validate ownership
    Owner->>Contract: Transfer NFT
    Contract->>Contract: Update tag mappings
    Contract->>Contract: Emit TagUpdated event
    NewOwner->>Contract: Receive NFT with associated tag
Loading

Possibly Related PRs


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68f440b and 1ac3b3e.

📒 Files selected for processing (1)
  • packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts (1 hunks)

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

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 (2)
packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V3.sol (1)

13-22: Solid tag-handling in the _transfer override.
Your logic correctly clears the tag from the sender's map and assigns it to the recipient only if no existing token is mapped to that tag. The assumption that the tag doesn't collide for the new owner is sensible, but consider how you'd handle accidental collisions in the future.

packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts (1)

18-46: Setup and initialization are clear.
You effectively deploy the proxy, upgrade it, and prepare sampleNFT. Provide more nuance in naming constants and variables if the code grows.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 27d7c2f and 68f440b.

📒 Files selected for processing (4)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol (1 hunks)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V2.sol (1 hunks)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V3.sol (1 hunks)
  • packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts (1 hunks)
🔇 Additional comments (8)
packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V3.sol (3)

7-7: Event usage looks appropriate.
Defining TagUpdated with indexed parameters is helpful for efficient event filtering.


9-11: Versioning strategy seems correct.
Overriding the version to "3.0.0" aligns with the new contract's functionality.


24-40: Robust moveTagToToken function.
The ownership check on line 27 is crucial. The function logically clears the old token tag and updates the new token's mapping. The early return on line 31 is lean and prevents redundant work.

packages/zevm-app-contracts/contracts/xp-nft/xpNFT_V2.sol (1)

23-23: Allowing further overrides of version().
Marking version() as virtual extends flexibility for new implementations.

packages/zevm-app-contracts/test/xp-nft/xp-nft-v3.ts (3)

1-16: Imports and constants are well-structured.
No apparent issues. All references to Hardhat, Chai, and ethers are standard best practices for a test suite.


48-74: Helper function design.
The mintNFT utility streamlines repeated mint logic. Ensuring you handle block timing, signature expiration, and robust validations is well done.


75-113: End-to-end tag updating test.
This test thoroughly verifies the minted token ownership, transfer, and subsequent tag reassociations. Great coverage for critical logic.

packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol (1)

156-156: Deferring transfer to subclasses is well-intentioned.
By overriding _transfer to revert, you ensure that only derived contracts can customize the transfer logic. This is critical given your new _transfer in V3.

GMaiolo
GMaiolo previously approved these changes Dec 30, 2024
Copy link
Collaborator

@GMaiolo GMaiolo left a comment

Choose a reason for hiding this comment

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

LGTM, left a small comment in the tests

Co-authored-by: Guillermo Maiolo <guille.maiolo@gmail.com>
@andresaiello andresaiello merged commit 66ad597 into main Jan 3, 2025
8 of 10 checks passed
@andresaiello andresaiello deleted the andy/pd-7062-enable-xp-nft-to-be-transferable branch January 3, 2025 18:14
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