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

fix(register-derivatives): collect and approve minting fees for commercial licenses #23

Conversation

sebsadface
Copy link
Member

@sebsadface sebsadface commented Aug 15, 2024

Description

This PR fixes an issue where calling registerIpAndMakeDerivative and mintAndRegisterIpAndMakeDerivative on parent IPs with commercial licenses throws an ERC20InsufficientAllowance error.

Key Changes

  • Implemented _collectMintFeesAndSetApproval and helper functions to:
    1. Fetch and calculate the total minting fees required to register the derivative.
    2. Transfer the minting fees from the caller to the SPG contract.
    3. Approve the royalty policy to collect the minting fees.
  • Added calls to _collectMintFeesAndSetApproval in registerIpAndMakeDerivative and mintAndRegisterIpAndMakeDerivative prior to registering the derivative.

Tests

  • Updated existing tests to reflect changes in SPG functions.
  • Added new tests to verify correct registration of derivatives under commercial licenses.

Related Issue

This PR closes #21.

Notes

Users must approve an additional transaction to transfer the minting fees to the SPG contract when calling registerIpAndMakeDerivative and mintAndRegisterIpAndMakeDerivative.

Summary by CodeRabbit

  • New Features

    • Enhanced licensing and royalty functionalities in the StoryProtocolGateway contract.
    • Added support for dynamic fee structures based on licensing terms.
    • Introduced new parameters for handling licensing and royalty modules during initialization.
  • Bug Fixes

    • Improved logic for minting fees and approvals to ensure secure financial transactions.
  • Tests

    • Updated test logic and modifiers to reflect new licensing types, enhancing clarity and accuracy in testing.
    • Introduced internal functions to improve the reusability and maintainability of the test suite.
  • Chores

    • Adjusted linter settings to accommodate longer lines in the codebase.

Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent updates enhance the functionality of the StoryProtocolGateway and related contracts by integrating new licensing and royalty mechanisms. Key changes include the addition of modules for managing licenses and royalties, updated constructors to handle new addresses, and improved testing frameworks. This evolution aims to facilitate the registration of derivative IPs under commercial licenses while ensuring robust fee collection and approval processes.

Changes

Files Change Summary
contracts/SPGNFT.sol Added comment to disable linting rule for long import line.
contracts/StoryProtocolGateway.sol Integrated licensing and royalty features with new imports, state variables, and internal functions.
script/Main.s.sol Updated constructor to accept new parameters for licensing and royalty modules.
script/utils/StoryProtocolCoreAddressManager.sol Introduced internal variables for license registry and royalty module, sourced from JSON config.
test/StoryProtocolGateway.t.sol Modified test logic and names for clarity, introduced new internal functions for better reusability.
test/utils/BaseTest.t.sol Expanded royalty management capabilities with new variables and deployment logic for royalty policies.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SPG
    participant LicensingModule
    participant RoyaltyModule

    User->>SPG: Register IP Asset
    SPG->>LicensingModule: Call registerDerivative
    LicensingModule-->>SPG: Return success
    SPG->>RoyaltyModule: Initiate royalty distribution
    RoyaltyModule-->>SPG: Confirm royalty setup
Loading

Assessment against linked issues

Objective Addressed Explanation
Register derivative IPs with commercial licenses (21) Changes introduce new licensing features but do not clarify if the issue is fully resolved.
Preserve msg.sender in licensing calls (21) The proposed solution using delegate calls is not implemented in the current changes.

🐰 "In the meadow where changes bloom,
A gateway opens, dispelling gloom.
With licenses and royalties in hand,
The contracts dance, a joyful band.
Derivatives await, with a hop and a cheer,
For every new feature, we’ll hold dear!" 🌼


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 0308d83 and 19f0041.

Files selected for processing (6)
  • contracts/SPGNFT.sol (1 hunks)
  • contracts/StoryProtocolGateway.sol (8 hunks)
  • script/Main.s.sol (1 hunks)
  • script/utils/StoryProtocolCoreAddressManager.sol (2 hunks)
  • test/StoryProtocolGateway.t.sol (5 hunks)
  • test/utils/BaseTest.t.sol (7 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/SPGNFT.sol
Additional comments not posted (25)
script/utils/StoryProtocolCoreAddressManager.sol (1)

13-14: LGTM! Verify JSON path usage.

The addition of licenseRegistryAddr and royaltyModuleAddr looks good. Ensure that the JSON paths .main.LicenseRegistry and .main.RoyaltyModule are correct and that the JSON file structure aligns with these paths.

script/Main.s.sol (1)

60-61: LGTM! Verify constructor usage.

The addition of licenseRegistryAddr and royaltyModuleAddr to the deployment process looks good. Ensure that these addresses are passed correctly to the Main contract's constructor and used appropriately in the deployment logic.

Verification successful

Addresses are used correctly in deployment logic.

The licenseRegistryAddr and royaltyModuleAddr are not passed to the Main contract's constructor directly. Instead, they are used as parameters in the instantiation of the StoryProtocolGateway contract within the _deployProtocolContracts function, which is part of the deployment logic executed by the run function. This usage aligns with the intended deployment process.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify constructor usage for licenseRegistryAddr and royaltyModuleAddr.

# Test: Search for the Main contract instantiation. Expect: Correct parameters passed to the constructor.
rg --type solidity -A 5 $'new Main'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify constructor usage for licenseRegistryAddr and royaltyModuleAddr.

# Test: Search for the Main contract instantiation in Solidity files. Expect: Correct parameters passed to the constructor.
rg 'new Main' --glob '*.sol' -A 5

Length of output: 35


Script:

#!/bin/bash
# Description: Search for the Main contract definition and its constructor to verify parameter usage.

# Test: Locate the Main contract definition and constructor in Solidity files.
rg 'contract Main' --glob '*.sol' -A 10

Length of output: 709


Script:

#!/bin/bash
# Description: Search for the usage of licenseRegistryAddr and royaltyModuleAddr in the Main contract.

# Test: Locate references to licenseRegistryAddr and royaltyModuleAddr in the Main contract.
rg 'licenseRegistryAddr|royaltyModuleAddr' --glob 'script/Main.s.sol' -A 5

Length of output: 403


Script:

#!/bin/bash
# Description: Identify the function or contract call using licenseRegistryAddr and royaltyModuleAddr.

# Test: Search for the function or contract call that includes these parameters in Main.s.sol.
rg 'function|contract' --glob 'script/Main.s.sol' -A 10

Length of output: 3745

test/utils/BaseTest.t.sol (8)

44-47: LGTM! Verify variable initialization.

The initialization of royaltyModule, royaltyPolicyLAP, ipRoyaltyVaultBeacon, and ipRoyaltyVaultImpl looks correct. Ensure these are initialized properly in the setUp_test_Core function.

Verification successful

Initialization Verified in setUp_test_Core Function

The variables royaltyModule, royaltyPolicyLAP, ipRoyaltyVaultBeacon, and ipRoyaltyVaultImpl are properly initialized within the codebase. Here are the relevant initializations:

  • royaltyModule is initialized with RoyaltyModule(...).
  • royaltyPolicyLAP is initialized with RoyaltyPolicyLAP(...).
  • ipRoyaltyVaultImpl is initialized with IpRoyaltyVault(...).
  • ipRoyaltyVaultBeacon is initialized with UpgradeableBeacon(...).

These initializations ensure that the variables are set up correctly in the setUp_test_Core function or its equivalent setup context.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify initialization of new variables.

# Test: Search for the initialization of royaltyModule, royaltyPolicyLAP, ipRoyaltyVaultBeacon, and ipRoyaltyVaultImpl.
rg --type solidity -A 5 $'royaltyModule|royaltyPolicyLAP|ipRoyaltyVaultBeacon|ipRoyaltyVaultImpl'

Length of output: 131


Script:

#!/bin/bash
# Description: Verify initialization of new variables.

# Find all Solidity files and search for the initialization of the specified variables.
fd --extension sol --exec rg 'royaltyModule|royaltyPolicyLAP|ipRoyaltyVaultBeacon|ipRoyaltyVaultImpl' {}

Length of output: 2019


243-267: LGTM! Verify RoyaltyPolicyLAP deployment.

The deployment and initialization of RoyaltyPolicyLAP appear correct. Ensure that the proxy setup and address checks are accurate.

Verification successful

RoyaltyPolicyLAP Deployment and Proxy Setup Verified

The deployment and proxy setup of RoyaltyPolicyLAP are correctly implemented. The address and proxy implementation checks are present and align with the expected setup.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify RoyaltyPolicyLAP deployment and proxy setup.

# Test: Search for the deployment and proxy setup of RoyaltyPolicyLAP. Expect: Correct setup and address checks.
rg --type solidity -A 5 $'new RoyaltyPolicyLAP'

Length of output: 81


Script:

#!/bin/bash
# Find all Solidity files and search for the deployment and proxy setup of RoyaltyPolicyLAP.
fd -e sol -x rg 'new RoyaltyPolicyLAP' {} -A 5

Length of output: 346


204-204: LGTM! Verify RoyaltyModule deployment.

The deployment of RoyaltyModule is consistent with the existing pattern. Ensure the deployment logic aligns with the expected module setup.

Verification successful

RoyaltyModule Deployment Verified

The deployment of RoyaltyModule follows the expected modular setup pattern, using addresses from other modules and registries. This aligns with the existing deployment logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify RoyaltyModule deployment logic.

# Test: Search for the deployment and initialization of RoyaltyModule. Expect: Logic should match the expected pattern.
rg --type solidity -A 5 $'new RoyaltyModule'

Length of output: 78


Script:

#!/bin/bash
# Description: Verify RoyaltyModule deployment logic.

# Test: Search for the deployment and initialization of RoyaltyModule. Expect: Logic should match the expected pattern.
rg 'new RoyaltyModule' -A 5

Length of output: 387


368-369: LGTM! Verify StoryProtocolGateway deployment.

The deployment of StoryProtocolGateway with the new parameters looks good. Ensure the parameters are passed correctly and the deployment logic is sound.


268-276: LGTM! Verify IpRoyaltyVault deployment.

The deployment of IpRoyaltyVault and the setup of ipRoyaltyVaultBeacon look correct. Ensure that these components are correctly integrated into the system.


357-359: LGTM! Verify RoyaltyPolicyLAP integration.

The integration of RoyaltyPolicyLAP with the IP royalty vault beacon is correctly implemented. Ensure this integration is tested and functions as expected.


19-20: LGTM! Verify new imports.

The imports for RoyaltyPolicyLAP and IpRoyaltyVault are correctly added. Ensure that these modules are available and correctly integrated into the project.


408-408: LGTM! Verify royalty token whitelisting.

The whitelisting of the royalty token is correctly implemented. Ensure this functionality is tested and operates as intended.

test/StoryProtocolGateway.t.sol (9)

208-210: LGTM!

The changes to the withEnoughTokens modifier correctly reflect the need for increased token balance and approval for the spg contract.


284-284: LGTM!

Renaming the modifier to withNonCommercialParentIp improves clarity and aligns with the test's focus on non-commercial licenses.


295-303: LGTM!

Renaming the function and using a base test function improves clarity and reusability in testing non-commercial licenses.


305-313: LGTM!

The renaming and use of a base test function enhance clarity and logic reuse for testing non-commercial licenses.


315-327: LGTM!

The withCommercialParentIp modifier is well-defined for setting up tests with commercial license terms.


330-338: LGTM!

The function effectively tests derivatives with commercial licenses using a base test function, enhancing clarity and reusability.


340-347: LGTM!

Renaming the function and using a base test function improve clarity and logic reuse for testing commercial licenses.


549-591: LGTM!

The _mintAndRegisterIpAndMakeDerivativeBaseTest function effectively centralizes common logic, enhancing maintainability and reusability.


593-657: LGTM!

The _registerIpAndMakeDerivativeBaseTest function centralizes logic for registering derivatives, improving maintainability and reusability.

contracts/StoryProtocolGateway.sol (6)

16-21: LGTM!

The new imports for licensing and royalty interfaces are necessary for the enhanced functionalities in the contract.


56-61: LGTM!

The addition of LICENSE_REGISTRY and ROYALTY_MODULE state variables is essential for the contract's new licensing and royalty functionalities.


Line range hint 83-103:
LGTM!

The constructor modifications correctly incorporate parameters for the license registry and royalty module, aligning with the new functionalities.


482-511: LGTM!

The _collectMintFeesAndSetApproval function effectively handles mint fees and sets approval, aligning with the new licensing processes.


513-536: LGTM!

The _aggregateMintFees function accurately calculates total mint fees, supporting the contract's enhanced fee management.


538-583: LGTM!

The _getMintFeeForSingleParent function dynamically calculates mint fees, enhancing flexibility in the contract's fee structures.

@kingster-will kingster-will merged commit 4a4f718 into storyprotocol:main Aug 15, 2024
3 checks passed
@sebsadface sebsadface deleted the issue-21-fails-to-register-derivative-with-commercial-license branch August 30, 2024 21:37
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.

SPG - Derivative Function / Commercial License Issue
2 participants