node icon indicating copy to clipboard operation
node copied to clipboard

feat: add fungible keeper ability to lock/unlock ZRC20 tokens

Open fbac opened this issue 1 year ago • 2 comments

Description

Add capabilities to fungible keeper:

  • Fungible Call ZRC20 method.
  • Lock ZRC20.
  • Unlock ZRC20.
  • Check ZRC20 allowance.
  • Check ZRC20 balance.
  • Check ZRC20 validity.
  • Bank contract uses fungible keeper to lock/unlock.

How Has This Been Tested?

  • [ ] Tested CCTX in localnet
  • [ ] Tested in development environment
  • [x] Go unit tests
  • [x] Go integration tests
  • [x] Tested via GitHub Actions

Summary by CodeRabbit

Release Notes

  • New Features

    • Support for stateful precompiled contracts and staking precompiled contract.
    • Enhanced Bitcoin chain support, including TSS address derivation by chain ID.
    • Introduction of a fungible keeper for locking/unlocking ZRC20 tokens.
    • Integration of authenticated calls into the protocol.
  • Bug Fixes

    • Resolved issues with operator voting on discarded keygen ballots and improved outbound tracking for EVM chains.
  • Tests

    • Expanded testing coverage for stateful precompiled contracts and staking functionalities.
  • Documentation

    • Updated changelog to reflect new features, fixes, and improvements.

These updates significantly enhance functionality, testing coverage, and overall user experience.

fbac avatar Oct 07 '24 15:10 fbac

📝 Walkthrough

Walkthrough

The pull request introduces significant updates to the Zeta Chain node, encompassing new features, refactoring, testing enhancements, and fixes. Key additions include support for stateful precompiled contracts, a common zetacored RPC package, and improvements to Bitcoin chain integration. The deposit and withdrawal mechanisms for ZRC20 tokens have been streamlined, while new methods for checking allowances and balances have been added. The changelog has been updated to reflect these changes, alongside improvements in the CI pipeline.

Changes

File Path Change Summary
changelog.md Updated to reflect new features, refactors, tests, fixes, and CI improvements, including support for stateful precompiled contracts and enhancements to Bitcoin chain support.
e2e/e2etests/test_precompiles_bank.go Updated bank contract address references from bank.ContractAddress to fungibletypes.ModuleAddressZEVM.
e2e/e2etests/test_precompiles_bank_through_contract.go Changed bank contract address references to fungibletypes.ModuleAddressZEVM for consistency.
precompiles/bank/method_deposit.go Removed validity and allowance checks for ZRC20 tokens in the deposit process, simplifying the logic.
precompiles/bank/method_test.go Updated caller address to fungibletypes.ModuleAddressZEVM and added a test case for zero token deposits.
precompiles/bank/method_withdraw.go Simplified withdrawal logic by consolidating checks for ZRC20 validity and balance.
x/fungible/keeper/zrc20_check_allowance.go Introduced CheckFungibleZRC20Allowance method to verify token allowance for a specified address.
x/fungible/keeper/zrc20_check_balance.go Introduced CheckFungibleZRC20Balance method to verify token balance for a specified address.
x/fungible/keeper/zrc20_check_token_validity.go Added IsValidZRC20 method to validate ZRC20 token addresses.
x/fungible/keeper/zrc20_lock_token.go Introduced LockZRC20 method for locking ZRC20 tokens in a bank contract.
x/fungible/keeper/zrc20_unlock_token.go Introduced UnlockZRC20 method for unlocking and transferring ZRC20 tokens.
x/fungible/types/keys.go Added ModuleAddressZEVM, updated formatting of ModuleAddress, clarified comments, and removed the init function.

Possibly related PRs

  • #2904: Integrates authenticated calls smart contract functionality into the protocol.
  • #2919: Adds an inbound sender to the revert context, enhancing context management.
  • #2870: Supports multiple Bitcoin chain configurations, connecting to Bitcoin integration updates.
  • #2890: Refactors MsgUpdateChainInfo functionality for single chain updates.
  • #2907: Derives Bitcoin TSS addresses by chain ID, enhancing Bitcoin integration.
  • #2861: Emits events from the staking precompile, relevant to staking functionality enhancements.

Suggested labels

breaking:cli, ADMIN_TESTS, UPGRADE_TESTS

Suggested reviewers

  • kingpinXD
  • swift1337
  • skosito
  • brewmaster012
  • lumtis
  • ws4charlie

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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

coderabbitai[bot] avatar Oct 07 '24 15:10 coderabbitai[bot]

Codecov Report

Attention: Patch coverage is 67.48971% with 79 lines in your changes missing coverage. Please review.

Project coverage is 66.38%. Comparing base (250b90e) to head (900da58). Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
x/fungible/keeper/zrc20_methods.go 70.00% 24 Missing and 24 partials :warning:
x/fungible/keeper/zrc20_cosmos_coins_mapping.go 71.01% 10 Missing and 10 partials :warning:
precompiles/bank/method_withdraw.go 0.00% 6 Missing and 5 partials :warning:
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2979      +/-   ##
===========================================
+ Coverage    66.25%   66.38%   +0.12%     
===========================================
  Files          406      408       +2     
  Lines        22772    22924     +152     
===========================================
+ Hits         15088    15217     +129     
- Misses        6907     6909       +2     
- Partials       777      798      +21     
Files with missing lines Coverage Δ
precompiles/bank/method_deposit.go 49.23% <100.00%> (+6.77%) :arrow_up:
precompiles/bank/method_withdraw.go 24.19% <0.00%> (-10.51%) :arrow_down:
x/fungible/keeper/zrc20_cosmos_coins_mapping.go 71.01% <71.01%> (ø)
x/fungible/keeper/zrc20_methods.go 70.00% <70.00%> (ø)

codecov[bot] avatar Oct 10 '24 21:10 codecov[bot]