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

refactor: Validator Staking Adjustments #458

Merged
merged 8 commits into from
May 22, 2024

Conversation

joemonem
Copy link
Contributor

@joemonem joemonem commented May 15, 2024

Motivation

Resolves: #453

Implementation

Users now can specify the amount of funds they'd like to unstake.

Testing

An integration test was created for unstaking a specific amount.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added the option to specify an amount when unstaking in Validator Staking.
  • Bug Fixes

    • Updated the claim recipient type for better compatibility and clarity.
  • Tests

    • Introduced new test cases for staking and unstaking operations with specified amounts.

@joemonem joemonem linked an issue May 15, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented May 15, 2024

Walkthrough

The changes enhance the Validator Staking functionality by introducing the ability to specify the amount for unstaking tokens and enabling rewards to be sent to other ADOs using the Recipient type. These updates involve modifications across various files to accommodate these new features.

Changes

File Path Change Summary
contracts/finance/andromeda-validator-staking/src/contract.rs Added amount parameter to Unstake, updated Claim to use Recipient, and adjusted related logic.
contracts/finance/andromeda-validator-staking/src/mock.rs Updated imports and function signatures to include amount and Recipient.
contracts/finance/andromeda-validator-staking/src/testing/tests.rs Modified tests to handle amount in Unstake and Recipient in Claim.
packages/andromeda-finance/src/validator_staking.rs Updated imports and adjusted ExecuteMsg enum to incorporate amount and Recipient.
tests-integration/tests/validator_staking.rs Added Recipient and Uint128 types, adjusted function calls, and included new test cases for specific unstaking amounts.
CHANGELOG.md Documented the addition of the amount parameter for unstaking and the update to Claim message to use Recipient.

Assessment against linked issues

Objective Addressed Explanation
Unstaking takes an optional amount field to specify the number of tokens to unstake (#453)
Claim now has the option to send the rewards to another ADO (by using the Recipient struct) (#453)
Unit test to confirm functionality (#453)

In fields of code where logic blooms,
We unstake tokens, new amounts consume.
With Recipient we claim, rewards to share,
Our tests ensure, the code is fair.
In bytes and lines, our work does sing,
A rabbit's joy in every string. 🐇


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@joemonem joemonem requested a review from cowboy0015 May 15, 2024 22:30
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 11e545d and 211e0c6.
Files selected for processing (5)
  • contracts/finance/andromeda-validator-staking/src/contract.rs (9 hunks)
  • contracts/finance/andromeda-validator-staking/src/mock.rs (5 hunks)
  • contracts/finance/andromeda-validator-staking/src/testing/tests.rs (3 hunks)
  • packages/andromeda-finance/src/validator_staking.rs (2 hunks)
  • tests-integration/tests/validator_staking.rs (8 hunks)
Additional comments not posted (12)
packages/andromeda-finance/src/validator_staking.rs (2)

23-23: The addition of the amount parameter to the Unstake variant is consistent with the PR objectives and allows users to specify the amount to unstake.


27-27: The change of the recipient type in the Claim variant from AndrAddr to Recipient is consistent with the PR objectives and allows rewards to be sent to another ADO.

contracts/finance/andromeda-validator-staking/src/mock.rs (2)

98-99: The addition of the amount parameter to the mock_execute_unstake function is consistent with the changes in the ExecuteMsg enum and ensures that the mock function reflects the new functionality.


104-104: The change of the recipient type in the mock_execute_claim_reward function from AndrAddr to Recipient is consistent with the changes in the ExecuteMsg enum and ensures that the mock function reflects the new functionality.

contracts/finance/andromeda-validator-staking/src/testing/tests.rs (2)

148-148: The addition of the amount parameter to the ExecuteMsg::Unstake message in the test_unauthorized_unstake test case is consistent with the changes in the ExecuteMsg enum and ensures that the test case reflects the new functionality.


173-173: The change of the recipient type in the ExecuteMsg::Claim message from AndrAddr to Recipient in the test_unauthorized_claim test case is consistent with the changes in the ExecuteMsg enum and ensures that the test case reflects the new functionality.

contracts/finance/andromeda-validator-staking/src/contract.rs (4)

82-82: The addition of the amount parameter to the ExecuteMsg::Unstake variant is consistent with the PR objectives and allows users to specify the amount to unstake.


202-202: The change of the recipient type in the ExecuteMsg::Claim variant from AndrAddr to Recipient is consistent with the PR objectives and allows rewards to be sent to another ADO.


Line range hint 142-192: The update to the execute_unstake function to handle the amount parameter ensures that the function properly handles the new parameter, allowing users to specify the amount to unstake. The logic includes validation to ensure the amount is not zero and does not exceed the staked amount.


Line range hint 202-260: The update to the execute_claim function to handle the Recipient type ensures that the function properly handles the new type, allowing rewards to be sent to another ADO. The logic includes validation to ensure the recipient is the contract owner.

tests-integration/tests/validator_staking.rs (2)

316-326: The addition of the amount parameter to the execute_unstake function calls in the integration tests is consistent with the changes in the ExecuteMsg enum and ensures that the integration tests reflect the new functionality.


99-99: The change of the recipient type in the execute_claim_reward function calls from AndrAddr to Recipient is consistent with the changes in the ExecuteMsg enum and ensures that the integration tests reflect the new functionality.

if let Some(recipient) = recipient {
if recipient.msg.is_some() {
res.clone()
.add_submessage(recipient.generate_direct_msg(&deps.as_ref(), info.funds)?);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the amount being sent here not be the amount that is being claimed?

Copy link
Contributor

Choose a reason for hiding this comment

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

The more I think about this the more difficult I think this implementation might be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we have a discussion about that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go ahead and undo it, we can come back to this in a future release. Keep it as AndrAddr for now.

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 211e0c6 and eb5e521.
Files selected for processing (1)
  • contracts/finance/andromeda-validator-staking/src/contract.rs (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contracts/finance/andromeda-validator-staking/src/contract.rs

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 eb5e521 and d2352e1.
Files selected for processing (5)
  • contracts/finance/andromeda-validator-staking/src/contract.rs (7 hunks)
  • contracts/finance/andromeda-validator-staking/src/mock.rs (3 hunks)
  • contracts/finance/andromeda-validator-staking/src/testing/tests.rs (1 hunks)
  • packages/andromeda-finance/src/validator_staking.rs (2 hunks)
  • tests-integration/tests/validator_staking.rs (5 hunks)
Files skipped from review as they are similar to previous changes (5)
  • contracts/finance/andromeda-validator-staking/src/contract.rs
  • contracts/finance/andromeda-validator-staking/src/mock.rs
  • contracts/finance/andromeda-validator-staking/src/testing/tests.rs
  • packages/andromeda-finance/src/validator_staking.rs
  • tests-integration/tests/validator_staking.rs

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 d2352e1 and 0587379.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments not posted (1)
CHANGELOG.md (1)

17-17: The changelog entry accurately reflects the new feature added by the PR and is correctly linked to the PR. Good job on maintaining clear and precise documentation.

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 0587379 and 8614d9d.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@joemonem joemonem merged commit 9b80c47 into development May 22, 2024
9 checks passed
@joemonem joemonem deleted the joe/validator-staking-adjustments branch May 22, 2024 14:10
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2024
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.

[Staking] Add Amount for Unstaking Funds
3 participants