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: create route to withdraw rewards #146

Merged
merged 3 commits into from
Jul 2, 2024

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Apr 4, 2024

Summary by CodeRabbit

  • New Features

    • Introduced functionality to claim rewards within the broker-staking module.
  • Tests

    • Added new test cases to ensure proper handling of reward withdrawals.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

This update introduces the ability to claim rewards within the broker-staking smart contract. Key changes include the addition of a claim_rewards function, updates to messages in the contract, new tests for reward withdrawals, and corresponding checksum updates to the WebAssembly binary files.

Changes

File Summary
artifacts/checksums.txt Changes to the checksum values for broker_bank.wasm and broker_staking.wasm.
contracts/broker-staking/src/contract.rs Added claim_rewards function, ClaimRewards variant in ExecuteMsg, and modified imports.
contracts/broker-staking/src/msg.rs Added ClaimRewards variant to the ExecuteMsg enum.
contracts/broker-staking/src/testing.rs Added DistributionMsg import and test_withdraw_rewards function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BrokerStakingContract
    participant RewardsDistribution

    User ->> BrokerStakingContract: Execute ClaimRewards
    BrokerStakingContract ->> RewardsDistribution: Request Rewards Distribution
    RewardsDistribution -->> BrokerStakingContract: Distribute Rewards
    BrokerStakingContract -->> User: Acknowledge Claim
Loading

Poem

In the fields where staking grows,
A rabbit hops and claims rewards,
New functions spark, in code’s embrace,
Bringing wealth at a swift pace.
Tests will run, and checks will pass,
Rewarding those in staking’s class.
🌟


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

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 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 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.

deps.querier.query_all_delegations(&env.contract.address)?;

let mut messages: Vec<CosmosMsg> = vec![];
for delegation in delegations.iter() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a CLI command to do withdraw all but it's internally just doing this logic. There's no actual message to withdraw from all delegations in the comsos sdk

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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f143dc9 and 325b1c1.
Files ignored due to path filters (2)
  • artifacts/broker_bank.wasm is excluded by !**/*.wasm, !**/*.wasm
  • artifacts/broker_staking.wasm is excluded by !**/*.wasm, !**/*.wasm
Files selected for processing (4)
  • artifacts/checksums.txt (1 hunks)
  • contracts/broker-staking/src/contract.rs (2 hunks)
  • contracts/broker-staking/src/msg.rs (1 hunks)
  • contracts/broker-staking/src/testing.rs (2 hunks)
Additional comments not posted (6)
artifacts/checksums.txt (1)

1-2: Checksum updates for broker_bank.wasm and broker_staking.wasm are aligned with the PR objectives.

contracts/broker-staking/src/msg.rs (1)

34-34: The addition of the ClaimRewards variant to the ExecuteMsg enum correctly implements the new feature for withdrawing rewards.

contracts/broker-staking/src/contract.rs (2)

62-62: Correctly integrated handling for ClaimRewards in the execute function.


66-92: The claim_rewards function is correctly implemented to allow operators to claim delegator rewards.

contracts/broker-staking/src/testing.rs (2)

7-8: Correctly replaced DistributionMsg with StakingMsg to align with the changes in the contract logic.


756-831: The test_withdraw_rewards function correctly tests the new ClaimRewards functionality under various scenarios.

Copy link

codecov bot commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 13 lines in your changes missing coverage. Please review.

Project coverage is 88.12%. Comparing base (902b788) to head (325b1c1).
Report is 25 commits behind head on main.

Current head 325b1c1 differs from pull request most recent head 0ee189c

Please upload reports for the commit 0ee189c to get more accurate results.

Additional details and impacted files
Files Coverage Δ
contracts/broker-staking/src/msg.rs 0.00% <ø> (ø)
contracts/broker-staking/src/contract.rs 84.00% <73.91%> (ø)
contracts/broker-staking/src/testing.rs 95.41% <89.70%> (ø)

... and 41 files with indirect coverage changes

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 325b1c1 and 97bea89.

Files selected for processing (1)
  • contracts/broker-staking/src/testing.rs (2 hunks)
Additional comments not posted (1)
contracts/broker-staking/src/testing.rs (1)

757-831: Comprehensive test coverage for ClaimRewards.

The new test function test_withdraw_rewards is well-structured and covers various scenarios for claiming rewards, including success and failure cases for different senders. This ensures that the ClaimRewards functionality is thoroughly tested.

However, consider adding the following improvements:

  1. Edge Cases: Include tests for edge cases such as when there are no rewards to claim or when the contract is halted.
  2. Assertions: Ensure that the state changes (e.g., rewards balance) are asserted after the operation to verify the correctness of the functionality.

Example:

// Edge case: No rewards to claim
TestCaseExec {
    to_addrs: to_addrs.to_vec(),
    opers: opers.to_vec(),
    sender: "owner",
    exec_msg: ExecuteMsg::ClaimRewards {},
    err: Some("no rewards to claim"),
    contract_funds_start: None,
    resp_msgs: vec![],
},
// Edge case: Contract is halted
IS_HALTED.save(deps.as_mut().storage, &true)?;
let res = execute(deps.as_mut(), env.clone(), info, ExecuteMsg::ClaimRewards {});
assert!(res.is_err(), "contract is halted");

@matthiasmatt matthiasmatt merged commit e6a3a65 into main Jul 2, 2024
3 checks passed
@matthiasmatt matthiasmatt deleted the mat/withdraw-reward-broker-staking branch July 2, 2024 12:39
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