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: connector native minting cap #248

Merged
merged 15 commits into from
Jul 25, 2024
Merged

feat: connector native minting cap #248

merged 15 commits into from
Jul 25, 2024

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Jul 23, 2024

closes #236

Summary by CodeRabbit

  • New Features

    • Implemented a maximum supply control for token minting, including a mechanism to update this limit.
    • Added notifications for maximum supply updates and error handling for exceeding the supply limit.
  • Bug Fixes

    • Enhanced withdrawal functions to prevent minting beyond the established maximum supply.
  • Tests

    • Introduced tests to validate maximum supply constraints during withdrawal operations and ensure proper error handling.

Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent changes to the ZetaConnectorNonNative contract primarily focus on implementing a maximum supply mechanism for token minting. This enhancement includes the introduction of a maxSupply variable, an event for tracking updates, and error handling for oversupply scenarios. The modifications strengthen the contract's operational integrity, ensuring that any minting attempts exceeding the specified limit are effectively prevented and logged.

Changes

Files Change Summaries
contracts/prototypes/evm/ZetaConnectorNonNative.sol Introduced maxSupply variable; added MaxSupplyUpdated event and ExceedsMaxSupply error; implemented setMaxSupply function; modified withdrawal functions to check against maxSupply.
testFoundry/ZetaConnectorNonNative.t.sol Added tests for new maximum supply constraints, including scenarios for withdrawal failures when max supply is reached and asserting expected events/errors during these operations.
testFoundry/GatewayEVM.t.sol Allocated 1 ether to tssAddress in test setup to ensure sufficient balance for operations.
testFoundry/ZetaConnectorNative.t.sol Similar allocation of 1 ether to tssAddress in testMint function to prepare for minting operations.

Sequence Diagram(s)

sequenceDiagram
    participant TSS as Trusted Service Supplier
    participant Contract as ZetaConnectorNonNative
    participant User as User

    User->>TSS: Request minting
    TSS->>Contract: Check maxSupply
    alt Sufficient supply available
        Contract-->>TSS: Proceed with minting
        TSS-->>User: Tokens minted successfully
    else Max supply reached
        Contract-->>TSS: Revert with ExceedsMaxSupply
        TSS-->>User: Minting failed
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement safety mechanism for ZetaConnector v2 (#236)
Minting cap

🐇 In the meadow where bunnies play,
New limits on tokens brighten the day!
With max supply set, we hop with glee,
No more excess, just harmony!
Events will ring, and errors will cheer,
A safer contract, for all to revere! 🌼


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.

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.40%. Comparing base (9b5ff23) to head (9c33fdb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
+ Coverage   60.91%   61.40%   +0.48%     
==========================================
  Files          16       16              
  Lines         394      399       +5     
  Branches      103      106       +3     
==========================================
+ Hits          240      245       +5     
  Misses        154      154              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from access-control to main July 25, 2024 14:43
@skosito skosito marked this pull request as ready for review July 25, 2024 16:57
Copy link
Contributor

@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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9b5ff23 and 9c33fdb.

Files ignored due to path filters (3)
  • pkg/contracts/prototypes/evm/zetaconnectornonnative.sol/zetaconnectornonnative.go is excluded by !pkg/**
  • typechain-types/contracts/prototypes/evm/ZetaConnectorNonNative.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/prototypes/evm/ZetaConnectorNonNative__factory.ts is excluded by !typechain-types/**
Files selected for processing (4)
  • contracts/prototypes/evm/ZetaConnectorNonNative.sol (3 hunks)
  • testFoundry/GatewayEVM.t.sol (1 hunks)
  • testFoundry/ZetaConnectorNative.t.sol (1 hunks)
  • testFoundry/ZetaConnectorNonNative.t.sol (6 hunks)
Additional context used
Path-based instructions (1)
contracts/prototypes/evm/ZetaConnectorNonNative.sol (1)

Pattern contracts/**: Review the Solidity contracts for security vulnerabilities and best practices.

Additional comments not posted (13)
contracts/prototypes/evm/ZetaConnectorNonNative.sol (7)

10-10: Addition of maxSupply variable approved.

The maxSupply variable is appropriately initialized to the maximum value for uint256, ensuring the cap is effectively unlimited until explicitly set.


14-14: Addition of MaxSupplyUpdated event approved.

The MaxSupplyUpdated event provides necessary transparency and traceability for changes to the minting limit.


15-15: Addition of ExceedsMaxSupply error approved.

The ExceedsMaxSupply error is crucial for enforcing constraints on the token supply.


24-27: setMaxSupply function approved.

The function correctly sets the new maximum supply and emits the MaxSupplyUpdated event. However, the parameter _maxSupply should be renamed to maxSupply to conform to Solidity naming conventions.

-  function setMaxSupply(uint256 _maxSupply) external onlyTSS() {
-      maxSupply = _maxSupply;
-      emit MaxSupplyUpdated(_maxSupply);
+  function setMaxSupply(uint256 maxSupply) external onlyTSS() {
+      maxSupply = maxSupply;
+      emit MaxSupplyUpdated(maxSupply);

31-31: Modification to withdraw function approved.

The addition of the check against maxSupply ensures that the function adheres to the maximum supply constraint.


39-39: Modification to withdrawAndCall function approved.

The addition of the check against maxSupply ensures that the function adheres to the maximum supply constraint.


52-52: Modification to withdrawAndRevert function approved.

The addition of the check against maxSupply ensures that the function adheres to the maximum supply constraint.

testFoundry/ZetaConnectorNative.t.sol (1)

60-60: Addition of vm.deal(tssAddress, 1 ether); approved.

This change ensures that the tssAddress has a sufficient balance to interact with the contract, enhancing the test setup.

testFoundry/ZetaConnectorNonNative.t.sol (4)

35-36: Addition of ExceedsMaxSupply error and MaxSupplyUpdated event approved.

These additions are crucial for enforcing supply limits and providing transparency for changes to the minting limit.


84-99: Addition of testWithdrawFailsIfMaxSupplyReached function approved.

This test ensures that the withdraw function adheres to the maximum supply constraint, enhancing the contract's robustness.


155-169: Addition of testWithdrawAndCallReceiveERC20FailsIfMaxSupplyReached function approved.

This test ensures that the withdrawAndCall function adheres to the maximum supply constraint, enhancing the contract's robustness.


288-302: Addition of testWithdrawAndRevertFailsIfMaxSupplyReached function approved.

This test ensures that the withdrawAndRevert function adheres to the maximum supply constraint, enhancing the contract's robustness.

testFoundry/GatewayEVM.t.sol (1)

61-62: LGTM! The change enhances the test setup.

The addition of vm.deal(tssAddress, 1 ether); ensures that the tssAddress has sufficient ether for subsequent operations, improving the robustness of the test setup.

@skosito skosito merged commit 0ba9959 into main Jul 25, 2024
16 of 18 checks passed
@skosito skosito deleted the connector-minting-cap branch July 25, 2024 17:01
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.

Implement safety mechanism for ZetaConnector v2
4 participants