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: add function to withdraw and check delegator rewards #3088

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

fbac
Copy link
Contributor

@fbac fbac commented Nov 4, 2024

Description

Add distribute functions to the staking precompile:

  • getDelegatorValidators: returns all the validators where a delegator has delegated to.
  • getRewards: returns all the outstanding rewards in a validator for an specific delegator.
  • claimRewards: claims all the delegation rewards. The caller has to be the delegator, or a contract called by the delegator.

How Has This Been Tested?

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

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced reward claiming and validator retrieval functionalities in the staking contract.
    • Added the ability to check and withdraw delegator rewards.
    • Integrated distribution functionalities within the Ethereum virtual machine context.
    • Enhanced testing framework with new tests for Solana and TON.
  • Bug Fixes

    • Resolved issues with emissions module registration and out-of-gas errors during omnichain calls.
  • Documentation

    • Updated changelog to reflect new features and improvements in testing.
  • Refactor

    • Streamlined the initialization and configuration of the App structure.
    • Improved organization of constants and logging methods in the staking module.

@fbac fbac added the stateful-precompile A new stateful precompile contract that is user facing label Nov 4, 2024
Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant changes to the ZetaChain application, particularly enhancing the App structure's initialization by integrating a new DistrKeeper into the EvmKeeper. This integration allows for improved management of distribution functionalities within the Ethereum virtual machine context. Additionally, the changelog has been updated to reflect various new features, tests, and refactoring efforts. Modifications to several test files enhance the testing framework, particularly for staking and distribution functionalities, while new methods and constants have been added to support these enhancements.

Changes

File Path Change Summary
app/app.go - Updated New(...) *App method to include DistrKeeper in EvmKeeper initialization.
- Added DistrKeeper to App struct.
changelog.md - Updated to reflect new features, tests, refactoring, and fixes, including SPL token whitelisting and improvements.
cmd/zetae2e/local/local.go - Updated localE2ETest function for minting amounts and added precompiled contract tests.
cmd/zetae2e/local/precompiles.go - Modified statefulPrecompilesTestRoutine to include ZetaTxServer initialization and updated transaction amounts.
e2e/contracts/testdistribute/TestDistribute.abi - Replaced constructor with a fallback function, updated parameters for claimRewardsThroughContract, and added new functions.
e2e/contracts/testdistribute/TestDistribute.go - Added DecCoin struct and new methods for interacting with the updated ABI.
e2e/contracts/testdistribute/TestDistribute.json - Similar updates as in .abi, including new functions and removal of the Distributed event.
e2e/contracts/testdistribute/TestDistribute.sol - Removed Distributed event, added new functions for reward claims and validator retrieval.
e2e/e2etests/e2etests.go - Renamed test functions to reflect new functionalities related to distribution and claiming.
e2e/e2etests/test_precompiles_bank_through_contract.go - Improved variable declarations and balance checks.
e2e/e2etests/test_precompiles_distribute.go - Expanded functionality to include reward claiming and validator interactions.
e2e/e2etests/test_precompiles_distribute_through_contract.go - Updated to include staking and claiming processes in the test logic.
precompiles/precompiles.go - Added distributionKeeper parameter to StatefulContracts function.
precompiles/precompiles_test.go - Updated tests to include the new DistributionKeeper parameter.
precompiles/staking/IStaking.abi - Added new events and functions for claiming rewards and querying validators.
precompiles/staking/IStaking.gen.go - Introduced new methods for rewards and validators, along with event handling improvements.
precompiles/staking/IStaking.json - Similar updates as in .abi, enhancing functionality for reward claims and validator queries.
precompiles/staking/staking.go - Enhanced Run method to handle new reward and validator methods.
precompiles/types/coin.go - Added CoinIsZRC20 function for checking ZRC20 coins.
testutil/keeper/keeper.go - Added DistributionKeeper and EmissionsKeeper to SDKKeepers and ZetaKeepers structures.

Possibly related PRs

Suggested labels

no-changelog

Suggested reviewers

  • kingpinXD
  • swift1337
  • skosito
  • brewmaster012
  • lumtis
  • gartnera

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.

@fbac fbac changed the title feat: add function to withdraw delegator rewards feat: add function to withdraw and check delegator rewards Nov 4, 2024
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 42.75862% with 166 lines in your changes missing coverage. Please review.

Project coverage is 61.86%. Comparing base (cc3bc86) to head (d3a97fb).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
precompiles/staking/method_claim_rewards.go 23.59% 64 Missing and 4 partials ⚠️
precompiles/staking/method_get_rewards.go 39.68% 31 Missing and 7 partials ⚠️
precompiles/staking/logs.go 0.00% 21 Missing ⚠️
precompiles/staking/method_get_validators.go 42.85% 16 Missing and 4 partials ⚠️
precompiles/staking/staking.go 85.41% 5 Missing and 2 partials ⚠️
precompiles/types/address.go 0.00% 6 Missing ⚠️
precompiles/types/coin.go 62.50% 5 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3088      +/-   ##
===========================================
- Coverage    62.06%   61.86%   -0.20%     
===========================================
  Files          428      431       +3     
  Lines        30438    30717     +279     
===========================================
+ Hits         18890    19003     +113     
- Misses       10708    10856     +148     
- Partials       840      858      +18     
Files with missing lines Coverage Δ
precompiles/bank/method_deposit.go 42.85% <100.00%> (ø)
precompiles/bank/method_withdraw.go 20.45% <100.00%> (ø)
precompiles/precompiles.go 100.00% <100.00%> (ø)
precompiles/staking/method_distribute.go 46.15% <100.00%> (ø)
precompiles/types/address.go 30.00% <0.00%> (-7.50%) ⬇️
precompiles/types/coin.go 42.85% <62.50%> (+9.52%) ⬆️
precompiles/staking/staking.go 72.13% <85.41%> (+2.95%) ⬆️
precompiles/staking/method_get_validators.go 42.85% <42.85%> (ø)
precompiles/staking/logs.go 12.96% <0.00%> (-3.13%) ⬇️
precompiles/staking/method_get_rewards.go 39.68% <39.68%> (ø)
... and 1 more

@fbac fbac force-pushed the feat/claim-zrc20-rewards branch 3 times, most recently from 654e153 to f2e421b Compare November 8, 2024 14:53
@fbac fbac marked this pull request as ready for review November 18, 2024 17:24
precompiles/staking/const.go Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Outdated Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Outdated Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Show resolved Hide resolved
precompiles/types/coin_test.go Show resolved Hide resolved
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good to me outside the fact we should remove the Origin usage

precompiles/staking/const.go Show resolved Hide resolved
changelog.md Outdated Show resolved Hide resolved
@fbac fbac requested a review from lumtis November 25, 2024 11:55
Copy link

gitguardian bot commented Nov 25, 2024

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
14567965 Triggered Generic Password c49327f cmd/zetaclientd/start.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

precompiles/staking/method_claim_rewards.go Outdated Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Outdated Show resolved Hide resolved
e2e/e2etests/test_precompiles_distribute.go Outdated Show resolved Hide resolved
precompiles/staking/method_claim_rewards.go Show resolved Hide resolved
cmd/zetae2e/local/local.go Show resolved Hide resolved
cmd/zetae2e/local/precompiles.go Show resolved Hide resolved
precompiles/staking/methiod_claim_rewards_test.go Outdated Show resolved Hide resolved
precompiles/staking/methiod_claim_rewards_test.go Outdated Show resolved Hide resolved
precompiles/staking/method_get_rewards.go Show resolved Hide resolved
precompiles/staking/staking.go Show resolved Hide resolved
Copy link
Contributor

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall ,
Would be great if this unit test could be added

precompiles/staking/staking.go Show resolved Hide resolved
@fbac fbac enabled auto-merge November 26, 2024 15:23
@fbac fbac added this pull request to the merge queue Nov 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 26, 2024
@fbac fbac added this pull request to the merge queue Nov 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli stateful-precompile A new stateful precompile contract that is user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants