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

Temporarily add v2 contracts to the toolkit #183

Merged
merged 4 commits into from
Sep 19, 2024
Merged

Temporarily add v2 contracts to the toolkit #183

merged 4 commits into from
Sep 19, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Sep 12, 2024

  • added v1 contracts like system contract to the toolkit, because it's not published as part of v2 version yet
  • updated Solidity version to 0.8.26
  • fixed introduced a fix to encode values passed on the CLI correctly (so "true" becomes an actual true value)

Summary by CodeRabbit

  • New Features

    • Introduced a framework for handling revertable calls in smart contracts.
    • Added interfaces for ZRC20 token management, enhancing compatibility and usability.
    • Implemented a central SystemContract for cross-chain interactions and liquidity management.
    • Enhanced input parameter handling in client functions for improved type safety and error handling.
  • Bug Fixes

    • Updated Solidity version across multiple contracts for improved performance and security.
  • Documentation

    • Added deprecation notice for the zContract interface, encouraging transition to UniversalContract.
  • Chores

    • Updated import paths to improve modularity and accommodate project structure changes.
    • Upgraded project dependencies for enhanced functionality and support for upgradeable contracts.

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

Walkthrough

The pull request introduces multiple changes across various Solidity files, primarily updating the Solidity version from 0.8.7 to 0.8.26. It also adds new components such as the Revert.sol file for managing revertable calls, the SystemContract for blockchain interactions, and the IZRC20 interface for ZRC20 token management. Additionally, it includes restructuring of imports and the addition of new functionalities, while preserving existing logic.

Changes

File(s) Change Summary
contracts/BytesHelperLib.sol, contracts/EthZetaMock.sol, contracts/SwapHelperLib.sol, contracts/TestZRC20.sol, contracts/shared/MockZRC20.sol, contracts/shared/TestUniswapRouter.sol, contracts/shared/libraries/SafeMath.sol Updated Solidity version from 0.8.7 to 0.8.26.
contracts/Revert.sol Introduced RevertOptions and RevertContext structs, and Revertable interface with onRevert function for handling revertable operations.
contracts/SystemContract.sol Introduced SystemContract with mappings for gas prices, ZRC20 addresses, and Uniswap pools, along with access control and functions for deposits and updates.
contracts/UniversalContract.sol Introduced zContract and UniversalContract interfaces for cross-chain calls, along with zContext struct and deprecation notice for zContract.
contracts/shared/interfaces/IZRC20.sol Introduced IZRC20 interface for ZRC20 token management, including standard functions and events, as well as IZRC20Metadata and ZRC20Events interfaces.

Possibly related PRs


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a12b88b and a62513c.

Files ignored due to path filters (10)
  • typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts is excluded by !typechain-types/**
  • typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts is excluded by !typechain-types/**
  • typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts is excluded by !typechain-types/**
  • typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/@openzeppelin/contracts/interfaces/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts is excluded by !typechain-types/**
Files selected for processing (4)
  • packages/client/src/evmCall.ts (1 hunks)
  • packages/client/src/evmDepositAndCall.ts (1 hunks)
  • packages/client/src/zetachainCall.ts (1 hunks)
  • packages/client/src/zetachainWithdrawAndCall.ts (1 hunks)
Additional comments not posted (5)
packages/client/src/evmCall.ts (2)

25-40: LGTM!

The changes in this code segment improve the robustness of the evmCall function by:

  1. Parsing the args.types JSON string into an array for type validation.
  2. Converting boolean values and handling invalid boolean inputs.
  3. Converting numeric values to ethers.BigNumber instances, which is a best practice.
  4. Retaining the original value for other types, ensuring compatibility with string literals and other valid types.

These changes reduce the likelihood of runtime errors during contract calls by ensuring that the values passed to the contract are correctly formatted and validated.


43-44: LGTM!

Updating the encoding of parameters to use the valuesArray is necessary to maintain consistency with the parsing and conversion logic implemented in the previous code segment. This change ensures that the contract call uses the validated and properly formatted values, reducing the chances of unexpected behavior during the contract execution.

packages/client/src/zetachainCall.ts (1)

49-65: Excellent work on introducing type-based parsing for args.values!

The new implementation significantly improves the function's robustness by:

  • Enforcing type safety for boolean, uint, int, and other types.
  • Providing clear error handling for invalid boolean inputs.
  • Using ethers.BigNumber for numeric types to ensure proper handling of large integers.

This structured approach to parameter encoding is crucial for ensuring that the function behaves correctly with various input types.

packages/client/src/evmDepositAndCall.ts (1)

42-57: LGTM! The changes enhance type safety and error handling.

The introduced logic for processing args.values based on the corresponding types in args.types is a significant improvement. It ensures that the values are correctly formatted before being passed to the ABI encoder, enhancing type safety and error handling in the function.

Specifically, the changes handle boolean values by attempting to parse them as JSON after converting to lowercase, throwing an error for invalid inputs. For numeric types (uint and int), the values are converted into ethers.BigNumber instances.

These transformations make the input handling more robust while preserving the overall functionality of the evmDepositAndCall function.

packages/client/src/zetachainWithdrawAndCall.ts (1)

48-68: LGTM! The changes introduce a robust parsing mechanism for input values.

The new parsing logic for args.values based on the corresponding types specified in args.types is a significant improvement. It enhances the handling of input parameters and ensures that the values are correctly typed before being encoded.

Key benefits:

  • Type validation and conversion for boolean and numeric types.
  • Improved type safety and prevention of potential runtime errors.
  • Enhanced integrity of the data being processed.

The changes make the function more robust and resilient to improperly formatted input values.


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 generate interesting stats about this repository and render them as a table.
    -- @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 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.

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.

@fadeev fadeev marked this pull request as ready for review September 12, 2024 10:29
@fadeev fadeev requested review from andresaiello and a team as code owners September 12, 2024 10:29
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

Outside diff range and nitpick comments (1)
contracts/SystemContract.sol (1)

1-200: Overall, the contract design and implementation look good!

The contract is well-structured, follows best practices, and correctly implements the intended behavior. The access control and event emission are properly handled.

Just one minor note:

The zContract interface import on line 5 is commented out. Is this intentional or should it be uncommented?

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73b823d and 696aba9.

Files ignored due to path filters (39)
  • typechain-types/contracts/Revert.sol/Revertable.ts is excluded by !typechain-types/**
  • typechain-types/contracts/Revert.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/contracts/SystemContract.sol/SystemContract.ts is excluded by !typechain-types/**
  • typechain-types/contracts/SystemContract.sol/SystemContractErrors.ts is excluded by !typechain-types/**
  • typechain-types/contracts/SystemContract.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/contracts/UniversalContract.sol/UniversalContract.ts is excluded by !typechain-types/**
  • typechain-types/contracts/UniversalContract.sol/ZContract.ts is excluded by !typechain-types/**
  • typechain-types/contracts/UniversalContract.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/contracts/index.ts is excluded by !typechain-types/**
  • typechain-types/contracts/shared/interfaces/IZRC20.sol/IZRC20.ts is excluded by !typechain-types/**
  • typechain-types/contracts/shared/interfaces/IZRC20.sol/IZRC20Metadata.ts is excluded by !typechain-types/**
  • typechain-types/contracts/shared/interfaces/IZRC20.sol/ZRC20Events.ts is excluded by !typechain-types/**
  • typechain-types/contracts/shared/interfaces/IZRC20.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/contracts/shared/interfaces/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/@openzeppelin/contracts/token/ERC20/ERC20__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/BytesHelperLib__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/Revert.sol/Revertable__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/Revert.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/SwapHelperLib__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/SystemContract.sol/SystemContractErrors__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/SystemContract.sol/SystemContract__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/SystemContract.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/TestZRC20__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/UniversalContract.sol/UniversalContract__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/UniversalContract.sol/ZContract__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/UniversalContract.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/MockZRC20__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/TestUniswapRouter__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/interfaces/IZRC20.sol/IZRC20Metadata__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/interfaces/IZRC20.sol/IZRC20__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/interfaces/IZRC20.sol/ZRC20Events__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/interfaces/IZRC20.sol/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/interfaces/index.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/libraries/SafeMath.sol/Math__factory.ts is excluded by !typechain-types/**
  • typechain-types/factories/contracts/shared/libraries/UniswapV2Library__factory.ts is excluded by !typechain-types/**
  • typechain-types/hardhat.d.ts is excluded by !typechain-types/**
  • typechain-types/index.ts is excluded by !typechain-types/**
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (11)
  • contracts/BytesHelperLib.sol (1 hunks)
  • contracts/Revert.sol (1 hunks)
  • contracts/SwapHelperLib.sol (1 hunks)
  • contracts/SystemContract.sol (1 hunks)
  • contracts/TestZRC20.sol (1 hunks)
  • contracts/UniversalContract.sol (1 hunks)
  • contracts/shared/MockZRC20.sol (1 hunks)
  • contracts/shared/TestUniswapRouter.sol (1 hunks)
  • contracts/shared/interfaces/IZRC20.sol (1 hunks)
  • contracts/shared/libraries/SafeMath.sol (1 hunks)
  • hardhat.config.ts (1 hunks)
Files skipped from review due to trivial changes (5)
  • contracts/BytesHelperLib.sol
  • contracts/TestZRC20.sol
  • contracts/shared/MockZRC20.sol
  • contracts/shared/TestUniswapRouter.sol
  • contracts/shared/libraries/SafeMath.sol
Additional comments not posted (21)
hardhat.config.ts (1)

17-17: LGTM!

Adding Solidity compiler version 0.8.26 to the compilers array is a good change. It allows leveraging the latest features, optimizations, and bug fixes in Solidity 0.8.26 for compiling smart contracts.

The change is straightforward and does not introduce any issues to the existing Hardhat configuration.

contracts/UniversalContract.sol (3)

6-10: LGTM!

The zContext struct is well-defined with appropriate field types.


23-32: Verify if UniversalContract is intended to replace zContract.

The UniversalContract interface is well-defined with appropriate function signatures. The onCrossChainCall function is identical to the one in the deprecated zContract interface, which might indicate that UniversalContract is intended to replace zContract. Please confirm if this is the case.

Also, the onRevert function is new and takes a RevertContext parameter. It would be helpful to have documentation explaining the purpose and usage of this function.

Run the following script to verify if UniversalContract is intended to replace zContract:

Do you want me to generate documentation for the UniversalContract interface and its functions?


12-21: Address the deprecation comment.

The zContract interface is well-defined with an appropriate function signature. However, please ensure to remove this interface once v2 SystemContract is not used anymore, as indicated by the deprecation comment.

Run the following script to verify the usage of zContract interface:

contracts/Revert.sol (3)

10-16: LGTM!

The RevertOptions struct is well-defined and follows the Solidity naming conventions. The comments provide clear and helpful information about each field, including the note about the onRevertGasLimit field being unused on GatewayZEVM methods.


22-26: LGTM!

The RevertContext struct is well-defined and follows the Solidity naming conventions. The comments provide clear and helpful information about each field, including the note about the asset field being empty if it's a gas token.


30-34: LGTM!

The Revertable interface is well-defined and follows the Solidity naming conventions. The comment provides clear and helpful information about the onRevert function. The function takes a RevertContext struct as a parameter, which is a good design choice as it encapsulates all the necessary information for handling reverts.

contracts/shared/interfaces/IZRC20.sol (3)

6-50: LGTM!

The IZRC20 interface correctly defines the standard functions for a ZRC20 token contract, including totalSupply, balanceOf, transfer, allowance, approve, and transferFrom. The function signatures match the expected inputs and outputs for a ZRC20 token.

In addition to the standard ZRC20 functions, the interface also includes Zeta-specific functions such as:

  • deposit: Allows depositing tokens to a specified address.
  • burn: Allows burning tokens.
  • withdraw: Allows withdrawing tokens to a specified address.
  • withdrawGasFee: Returns the address and amount of the gas fee for withdrawals.
  • withdrawGasFeeWithGasLimit: Returns the address and amount of the gas fee for withdrawals with a specified gas limit.
  • PROTOCOL_FLAT_FEE: Returns the protocol flat fee.
  • GAS_LIMIT: Returns the gas limit.
  • setName: Allows setting the token name.
  • setSymbol: Allows setting the token symbol.

These additional functions provide functionality specific to the Zeta blockchain and enhance the capabilities of the ZRC20 token contract.


54-60: LGTM!

The IZRC20Metadata interface correctly extends IZRC20 and defines the metadata functions for a ZRC20 token contract, including name, symbol, and decimals. The function signatures match the expected outputs for token metadata.


64-83: LGTM!

The ZRC20Events interface correctly defines the events for a ZRC20 token contract, including:

  • Transfer: Emitted when tokens are transferred from one address to another.
  • Approval: Emitted when an owner approves a spender to transfer tokens on their behalf.
  • Deposit: Emitted when tokens are deposited to an address.
  • Withdrawal: Emitted when tokens are withdrawn from an address.
  • UpdatedSystemContract: Emitted when the system contract address is updated.
  • UpdatedGateway: Emitted when the gateway address is updated.
  • UpdatedGasLimit: Emitted when the gas limit is updated.
  • UpdatedProtocolFlatFee: Emitted when the protocol flat fee is updated.

The event signatures match the expected inputs for each event, providing a comprehensive set of notifications for various actions related to the ZRC20 token contract.

contracts/SystemContract.sol (9)

53-64: LGTM!

The constructor is correctly setting the initial state and has the necessary access control check.


74-88: LGTM!

The depositAndCall function has the necessary access control and target address checks, and correctly interacts with the ZRC20 and target contracts.


96-105: LGTM!

The sortTokens function is correctly sorting the token addresses and handling the edge cases. The function visibility and state mutability are appropriate.


114-134: LGTM!

The uniswapv2PairFor function is correctly calculating the pair address using the expected formula. The function visibility and state mutability are appropriate.


141-146: LGTM!

The setGasPrice function has the necessary access control check and is correctly updating the state variable and emitting the event.


153-158: LGTM!

The setGasCoinZRC20 function has the necessary access control check and is correctly updating the state variable and emitting the event.


165-175: LGTM!

The setGasZetaPool function has the necessary access control check, correctly calculates the pool address, and updates the state variable and emits the event.


181-187: LGTM!

The setWZETAContractAddress function has the necessary access control and zero address checks, and correctly updates the state variable and emits the event.


193-199: LGTM!

The setConnectorZEVMAddress function has the necessary access control and zero address checks, and correctly updates the state variable and emits the event.

contracts/SwapHelperLib.sol (2)

2-2: Thoroughly test the contract and ensure project-wide compatibility with Solidity 0.8.26.

Updating the Solidity version from 0.8.7 to 0.8.26 is a significant change. Solidity 0.8.26 introduces new features, enhancements, and bug fixes that could affect the contract's behavior and compatibility.

Please ensure the following:

  1. Thoroughly test the SwapHelperLib contract to verify its functionality and correctness with Solidity 0.8.26.
  2. Check the compatibility of the entire project, including all contracts and libraries, with Solidity 0.8.26. Update them if necessary.
  3. Verify that the project's dependencies are compatible with Solidity 0.8.26. Update the dependencies to their compatible versions if required.

6-7: Verify the functionality of the imported contracts and review their changes if modified.

The import statements for IZRC20.sol and SystemContract.sol have been updated to use local paths, suggesting a project restructure.

Please ensure the following:

  1. Verify that the locally imported IZRC20.sol and SystemContract.sol contracts provide the same functionality as the previously imported ones from the ZetaChain protocol contracts. Test the SwapHelperLib contract thoroughly to ensure it still works as expected with these local imports.
  2. If the imported contracts have been modified, carefully review their changes to understand any impact on the SwapHelperLib contract.

@fadeev
Copy link
Member Author

fadeev commented Sep 16, 2024

@zeta-chain/fullstack @andresaiello please, review.

@fadeev fadeev merged commit e8bb021 into main Sep 19, 2024
5 checks passed
@fadeev fadeev deleted the v2-contracts branch September 19, 2024 02: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.

2 participants