ExocoreNetwork / exocore-contracts

5 stars 5 forks source link

refactor: `addWhitelistTokens` require more token info than just token address #39

Closed adu-web3 closed 4 months ago

adu-web3 commented 4 months ago

Description

according to the interface design and implementation of IAssets.sol on exocore chain side: https://github.com/ExocoreNetwork/exocore/pull/116, more token infos like decimals and tvl limit is required for assets module. So we need to add those fields to layerzero message payload and decode them on exocore side to feed into assets precompile

@coderabbitai pause review for this pr until it is ready for review

Summary by CodeRabbit

coderabbitai[bot] commented 4 months ago

Walkthrough

This update involves enhanced handling of Exocore contracts' setup, including expanded client chain metadata registration, token whitelisting with detailed parameters, and restaking functionality. Key modifications include additional validation in token and client chain management, reentrancy protection in mock contracts, and comprehensive test adaptations.

Changes

File Path Change Summary
script/3_Setup.s.sol Expanded setup for Exocore contracts: added client chain metadata registration, detailed token whitelisting, and restaking support; new function parameters for decimals, TVL limits, names, and metadata.
src/core/ExocoreGateway.sol Added client chain metadata functions; removed requestRegisterTokens; introduced token whitelisting; updated existing functions with additional parameters and error handling; modified internal functions for enhanced logic.
test/foundry (multiple files) Adjusted for new events and functionality: changed whitelistTokens from address[] to bytes32[]; added new test functions and error scenarios for token whitelisting and client chain registration.
test/mocks/ExocoreGatewayMock.sol Added new functions for client chain and token whitelisting; implemented reentrancy protection in markBootstrapOnAllChains; updated existing functions to incorporate new parameters and validation.
src/storage (multiple files) Updated constants and added new mappings and events for client chain and token whitelisting; refined error definitions for better error handling and validation in ExocoreGatewayStorage and GatewayStorage; removed old constants and events from ClientChainGatewayStorage.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant SetupScript as SetupScript
    participant ExocoreGateway as ExocoreGateway
    participant ClientChain as ClientChain

    User->>SetupScript: call setup()
    SetupScript->>ExocoreGateway: call registerOrUpdateClientChain()
    ExocoreGateway->>ClientChain: validate metadata
    ClientChain-->>ExocoreGateway: return validation results
    ExocoreGateway->>SetupScript: update chain metadata

    User->>SetupScript: call addWhitelistTokens()
    SetupScript->>ExocoreGateway: call addWhitelistTokens()
    ExocoreGateway->>ClientChain: validate and whitelist tokens
    ClientChain-->>ExocoreGateway: return validation and whitelist results
    ExocoreGateway->>SetupScript: update whitelist tokens

Poem

🐰 In fields of code where changes play,
New tokens join the whitelist today.
Client chains with metadata fair,
Enhanced and setup with tender care.
Restaking soars, validation's tight,
Exocore shines in blockchain light.✨


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
adu-web3 commented 4 months ago

checklist:

@coderabbitai please review these commits since this PR is ready for review

coderabbitai[bot] commented 4 months ago

@adu-web3, I've reviewed the changes listed in your checklist against the codebase. Here's the breakdown:

  1. Enable addWhitelistTokens in ExocoreGateway and disable in ClientChainGateway:

    • ExocoreGateway: The addWhitelistTokens function is implemented and active.
    • ClientChainGateway: The function addWhitelistTokens still exists and does not appear to be disabled. It is marked as external onlyOwner whenNotPaused, which suggests it's still operational unless further context (like a dynamic feature toggle) is provided elsewhere in the code.
  2. Add ExocoreGateway.registerOrUpdateClientChain:

    • This function is correctly implemented to handle more metadata about client chains, as specified.
  3. Override ExocoreGateway.setPeer:

    • The setPeer function in ExocoreGateway has been overridden to include additional logic before calling the superclass method, aligning with your requirements to restrict updates until the client chain is registered.
  4. Add ExocoreGateway.updateWhitelistedTokens:

    • This function has been added to allow updating token information like TVL limits, as required.
  5. Unit Tests:

    • Tests for addWhitelistTokens and updateWhitelistedTokens are found in the test files, indicating that unit tests have been addressed as per your checklist.

You may need to check the operational status of the addWhitelistTokens function in the ClientChainGateway to ensure it's disabled as intended. If there's anything specific you would like me to look into further or any additional changes, please let me know!

Analysis chain ---
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Search for the implementation of specific functions in ExocoreGateway and ClientChainGateway ast-grep --lang solidity --pattern $'contract ExocoreGateway { $$$ addWhitelistTokens($_, $_, $_, $_, $_, $_) { $$$ } registerOrUpdateClientChain($_, $_, $_, $_, $_, $_) { $$$ } setPeer($_) { $$$ } updateWhitelistedTokens($_, $_, $_, $_, $_) { $$$ } $$$ }' ast-grep --lang solidity --pattern $'contract ClientChainGateway { $$$ addWhitelistTokens($_) { $$$ } $$$ }' # Search for unit tests related to the modified functionalities rg "function test.*WhitelistTokens|test.*registerOrUpdateClientChain|test.*setPeer|test.*updateWhitelistedTokens" --glob '*t.sol' ``` Length of output: 962 --- --- Script: ```shell #!/bin/bash # Search for the implementation of specific functions in ExocoreGateway and ClientChainGateway using rg rg "addWhitelistTokens\(" --glob '*ExocoreGateway.sol' rg "registerOrUpdateClientChain\(" --glob '*ExocoreGateway.sol' rg "setPeer\(" --glob '*ExocoreGateway.sol' rg "updateWhitelistedTokens\(" --glob '*ExocoreGateway.sol' rg "addWhitelistTokens\(" --glob '*ClientChainGateway.sol' ``` Length of output: 1023
Actions performed Review triggered. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
cloud8little commented 4 months ago

Test https://github.com/ExocoreNetwork/exocore-contracts/pull/39/commits/3cd44bb19b08a64775ae67a6de74f80ab671e540 passed with https://github.com/ExocoreNetwork/exocore/pull/116/commits/8a9a9d8d0d483c38f7dcf81979abc58240a7c9b3 for deposit/withdraw/delegateTo/depositThenDelegate function.