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: Update nft contract to calculate tokenid #167

Conversation

andresaiello
Copy link
Collaborator

@andresaiello andresaiello commented Aug 15, 2024

Summary

  • Move tokenId logic to contract minting
  • Add tag

Summary by CodeRabbit

  • New Features

    • Upgraded the toolkit to version 10.0.0, introducing enhanced functionalities and improvements.
    • Added a new tag field to the NFT contract, allowing for enriched metadata.
    • New mappings for public access to last update timestamps and sign-up statuses per token.
    • Simplified NFT minting process by auto-incrementing token IDs.
    • Introduced a contract verification feature in the deployment process for transparency.
  • Bug Fixes

    • Improved clarity in the function calls related to updating NFTs by directly passing token IDs.
  • Documentation

    • Enhanced internal documentation to reflect changes in NFT structures and contract functionalities.
  • Tests

    • Updated test suite to align with new NFT handling and signature generation processes.

Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

Walkthrough

The recent changes implement substantial enhancements to the ZetaXP contract and its associated components. A critical upgrade to the @zetachain/toolkit to version 10.0.0 signals expanded capabilities and possible breaking changes. The WithdrawERC20 contract's swapTokensForExactTokens function has been refined for clarity. Additionally, the ZetaXP contract now incorporates metadata management through tag fields, improved public mappings for transparency, and optimized NFT minting and updating mechanisms.

Changes

Files Change Summary
package.json Updated @zetachain/toolkit version from ^5.0.0 to 10.0.0, indicating a major upgrade.
.../withdrawErc20/withdrawErc20.sol Simplified swapTokensForExactTokens function by passing systemContract object directly.
.../xp-nft/xpNFT.sol Introduced tag in UpdateData, made mappings public, added new mapping for tagByTokenId, and updated event signatures. Refined functions for explicit token ID handling.
.../test/xp-nft/test.helpers.ts Updated NFT interface to include tag, modified UpdateParam interface, and simplified getSignature function by removing tokenId.
.../test/xp-nft/xp-nft.ts Streamlined handling of tokenId, introduced tag in sampleNFT, and adjusted function calls to pass token ID explicitly.
.../scripts/xp-nft/deploy.ts Added verifyContract function for contract verification post-deployment and updated deployZetaXP to include verification for both main and implementation addresses.
.../data/addresses.json Updated ZetaXP addresses for unspecified network and added entry for zeta_mainnet, reflecting changes in contract deployment.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZetaXP
    participant NFT

    User->>ZetaXP: mintNFT(mintData)
    ZetaXP->>NFT: createNFT(mintData)
    NFT-->>ZetaXP: NFT created
    ZetaXP-->>User: return NFT details

    User->>ZetaXP: updateNFT(tokenId, updateData)
    ZetaXP->>NFT: updateNFT(tokenId, updateData)
    NFT-->>ZetaXP: NFT updated
    ZetaXP-->>User: return updated NFT details
Loading

This diagram illustrates the interactions involved in minting and updating NFTs within the ZetaXP contract, highlighting the user's role and the response from the contract.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b0132b4 and 3d1b6ec.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (5)
  • package.json (1 hunks)
  • packages/zevm-app-contracts/contracts/withdrawErc20/withdrawErc20.sol (1 hunks)
  • packages/zevm-app-contracts/contracts/xp-nft/xpNFT.sol (4 hunks)
  • packages/zevm-app-contracts/test/xp-nft/test.helpers.ts (1 hunks)
  • packages/zevm-app-contracts/test/xp-nft/xp-nft.ts (8 hunks)
Additional comments not posted (19)
packages/zevm-app-contracts/test/xp-nft/test.helpers.ts (3)

12-12: Addition of tag property to NFT interface is approved.

This change enhances the metadata associated with NFTs.

Ensure all instances of NFT are updated to include the tag property.

Verification successful

Let's correct the file type in the search command and try again to verify the presence of the tag property in all NFT instances.


Verification of tag Property in NFT Interface

The search results confirm that the tag property is included in the NFT interface and is being utilized appropriately in the codebase. Instances of NFT, such as sampleNFT, include the tag property, ensuring consistency with the updated interface definition.

  • The tag property is defined in the NFT interface in test.helpers.ts.
  • Instances of NFT in xp-nft.ts correctly include the tag property.

This change is consistent across the relevant files, ensuring proper integration of the new tag property into the NFT interface. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `NFT` include the `tag` property.

# Test: Search for `NFT` instances. Expect: All instances include `tag`.
rg --type typescript -A 2 $'NFT'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify all instances of `NFT` include the `tag` property.

# Test: Search for `NFT` instances. Expect: All instances include `tag`.
rg --type ts -A 2 $'NFT'

Length of output: 12280


22-25: Update to getSignature function is approved.

The function now uses tag instead of tokenId, aligning with the updated interfaces.

Verify that the function's logic is consistent with its intended use.

Verification successful

Verification Successful: Consistent Usage of getSignature Function

The getSignature function is used consistently with its updated parameters across the codebase. The transition from tokenId to tag has been correctly implemented. No issues were found.

  • Instances in xp-nft.ts confirm the correct usage of the updated logic.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `getSignature` aligns with its updated logic.

# Test: Search for `getSignature` usage. Expect: Consistent logic with updated parameters.
rg --type typescript -A 3 $'getSignature'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the usage of `getSignature` aligns with its updated logic.

# Test: Search for `getSignature` usage in TypeScript files. Expect: Consistent logic with updated parameters.
rg 'getSignature' --glob '*.ts' -A 3

Length of output: 4393


19-19: Inclusion of tokenId in UpdateParam is approved.

This change indicates that tokenId is relevant only for updates.

Ensure all relevant code reflects this change.

packages/zevm-app-contracts/contracts/withdrawErc20/withdrawErc20.sol (1)

22-22: Simplification of swapTokensForExactTokens call is approved.

Using the SystemContract object reduces the number of arguments and enhances maintainability.

Verify that the SystemContract object is correctly initialized and used.

Verification successful

Verify SystemContract Initialization and Usage

The SystemContract is correctly initialized and used in the codebase, as evidenced by the following:

  • The SystemContract is imported and instantiated in several Solidity files, including withdrawErc20.sol.
  • The initialization occurs in the constructor where systemContract = SystemContract(systemContractAddress); is used.
  • The SystemContract is consistently used across various test and script files, indicating proper integration.

These findings confirm that the SystemContract object is correctly initialized and utilized. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization and usage of `SystemContract`.

# Test: Search for `SystemContract` initialization and usage. Expect: Correct initialization and usage.
rg --type solidity -A 3 $'SystemContract'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the initialization and usage of `SystemContract` in the codebase.

# Test: Search for `SystemContract` initialization and usage across all files.
rg 'SystemContract' -A 3

Length of output: 32981

package.json (1)

42-42: Upgrade of @zetachain/toolkit to 10.0.0 is approved.

This significant version upgrade may introduce breaking changes.

Ensure compatibility with the new version.

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

20-20: Addition of tag field is appropriate.

The tag field in the UpdateData struct enhances metadata handling, improving contract flexibility.


23-25: Public mappings and new tagByTokenId mapping are well-implemented.

Making mappings public enhances transparency, and the addition of tagByTokenId supports the new tagging feature.


35-37: Inclusion of tag in events is beneficial.

Adding the tag parameter to events enhances the detail and utility of emitted events.


Line range hint 94-106: Direct tokenId parameter enhances clarity.

The _verify function now explicitly requires tokenId, which improves specificity and clarity in verification.


114-115: Inclusion of tag in hash calculation is secure.

Adding tag to the hash computation ensures the signature reflects all relevant update data.


121-124: Explicit tokenId parameter improves clarity.

The _updateNFT function now directly receives tokenId, ensuring accurate and clear state updates.


127-136: Automatic token ID assignment is efficient.

The mintNFT function now uses _currentTokenId for automatic ID assignment, simplifying the minting process and improving event detail.


139-145: Explicit token updates enhance clarity.

The updateNFT function now directly receives tokenId, ensuring precise and clear token updates.

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

23-27: Addition of tag to sampleNFT is appropriate.

The tag property aligns with contract changes, enabling comprehensive testing of the new metadata feature.


32-38: Direct tokenId parameter enhances test clarity.

The validateNFT function now requires tokenId, ensuring precise validation of specific NFTs.


40-42: Utility function for token ID extraction is effective.

The getTokenIdFromRecipient function supports streamlined test processes by facilitating token ID retrieval.


57-61: Transaction capture and token ID retrieval enhance test accuracy.

Capturing the transaction and retrieving tokenId ensures comprehensive test coverage for minting functionality.


Line range hint 96-131: Explicit tokenId handling ensures precise update testing.

The test accurately reflects contract changes by explicitly managing tokenId and validating updates.


227-240: Signature reuse test ensures robustness.

The test effectively validates protection against signature reuse, confirming contract security measures.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3d1b6ec and 82aafaf.

Files selected for processing (2)
  • packages/zevm-app-contracts/data/addresses.json (1 hunks)
  • packages/zevm-app-contracts/scripts/xp-nft/deploy.ts (3 hunks)
Additional comments not posted (3)
packages/zevm-app-contracts/data/addresses.json (1)

10-11: Verify the correctness of updated contract addresses.

Ensure that the updated ZetaXP contract addresses are correct and reflect the intended deployments for each network. Incorrect addresses can lead to application malfunctions.

Also applies to: 19-19

packages/zevm-app-contracts/scripts/xp-nft/deploy.ts (2)

12-24: LGTM! Consider enhancing error logging.

The verifyContract function is well-structured and effectively handles errors. Consider including more detailed error information to aid in debugging, such as the contract address and constructor arguments.


Line range hint 25-43:
LGTM! Verify deployment parameters and process.

The deployZetaXP function is well-implemented, ensuring both deployment and verification of the contract. Verify that the deployment parameters (e.g., "ZETA NFT", "ZNFT", ZETA_BASE_URL, signer) are correct and reflect the intended contract configuration.

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.

utACK
LGTM

@andresaiello andresaiello merged commit 9ef6dba into main Aug 15, 2024
12 checks passed
@andresaiello andresaiello deleted the andy/pd-6499-update-nft-contract-to-calculate-tokenid-and-add-tags branch August 15, 2024 18:25
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