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: remove vesting contract staking feature #554

Merged
merged 7 commits into from
Sep 16, 2024

Conversation

crnbarr93
Copy link
Contributor

@crnbarr93 crnbarr93 commented Sep 3, 2024

Motivation

Given the recent addition of the validator-staking ADO and feedback from the audit for both this contract and the vesting contract we decided to remove the ability to stake vested tokens using our vesting contract temporarily. In a future iteration it is likely we will add this functionality back but using the validator-staking ADO instead.

This should resolve the following findings:

Implementation

Removed all references to delegate/undelegate/vote in the vesting contract.

Testing

Removed related tests

Version Changes

andromeda-vesting: 2.0.0 -> 3.0.0

Future work

Readd this functionality using the validator-staking ADO

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Updated the vesting contract to remove staking functionalities, simplifying user interactions.
    • Major version increment for the andromeda-vesting package, indicating significant changes.
  • Bug Fixes

    • Fixed precision issues in the vestings claim batch method, improving accuracy in withdrawal calculations.
  • Refactor

    • Streamlined the smart contract by removing delegation-related functions and parameters, focusing on core functionalities.
  • Tests

    • Removed tests related to delegation and voting, reflecting changes in contract capabilities and simplifying the testing process.

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Walkthrough

The recent changes involve significant modifications to the Andromeda vesting contract, including the removal of delegation, voting, and staking functionalities. The version of the andromeda-vesting package has been updated from 2.0.1 to 3.0.1, reflecting a major shift in functionality. Additionally, several related test functions have been eliminated, streamlining both the contract and its testing suite.

Changes

File Path Change Summary
CHANGELOG.md Added entry for removal of staking from the vesting contract; fixed precision issue with claims.
contracts/finance/andromeda-vesting/Cargo.toml Updated version from "2.0.1" to "3.0.1".
contracts/finance/andromeda-vesting/src/contract.rs Removed delegation, redelegation, undelegation, reward withdrawal, and voting functions; streamlined execute_create_batch.
contracts/finance/andromeda-vesting/src/testing/tests.rs Removed tests related to delegation, redelegation, and undelegation; constants and helper functions eliminated.
packages/std/src/common/withdraw.rs Changed return type of get_amount methods from Uint128 to Decimal for more precise calculations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    User->>Contract: Create Batch
    Contract-->>User: Batch Created
    User->>Contract: Claim Batch
    Contract-->>User: Batch Claimed
Loading

🐰 "In a world of code, so bright and new,
I hop with joy, for changes true!
No more delegating, just a simple flow,
With batches created, watch them grow!
Hooray for clarity, let’s all cheer,
For a vesting contract that’s now more clear!" 🐇

Possibly related PRs

  • Feat: crowdfund-restructure/end campaign #456: The changes in the main PR involve significant modifications to the vesting contract, particularly the removal of staking features, which may relate to the overall management of funds and permissions in the crowdfund contract.
  • refactor: Splitter Adjustments #457: The changes in the main PR regarding the vesting contract's functionality could be related to the adjustments made in the Splitter contract, particularly in how funds are managed and distributed.
  • refactor: Validator Staking Adjustments #458: The removal of staking features in the vesting contract may connect with the validator staking adjustments, as both involve changes in how funds are handled and distributed.
  • feat: enabled migration for validator staking ADO #511: The addition of migration functionality in the validator staking ADO could relate to the changes in the vesting contract, as both involve managing state and functionality in smart contracts.
  • fix: Splitter & Conditional Splitter LockTime #547: The changes in the main PR regarding the vesting contract's functionality may connect with the updates made to the Splitter and Conditional Splitter contracts, particularly in how lock times and fund distributions are managed.
  • ref: replace MillisecondsExpiration with Expiry in TimeLock ADO #550: The changes in the main PR regarding the vesting contract's functionality may relate to the updates made in the Timelock ADO, particularly in how expiration times are handled.
  • fix: unintended permissioning underflow #553: The changes in the main PR regarding the vesting contract's functionality may connect with the updates made to the permissioning system, particularly in how permissions are managed and enforced across different contracts.

Tip

New features

Walkthrough comment now includes:

  • Possibly related PRs: A list of potentially related PRs to help you recall past context.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs. You can also provide custom labeling instructions in the UI or configuration file.

Notes:

  • Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled 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 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.

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

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 f999257 and d9db78a.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • contracts/finance/andromeda-vesting/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-vesting/src/contract.rs (7 hunks)
  • contracts/finance/andromeda-vesting/src/testing/tests.rs (26 hunks)
  • packages/andromeda-finance/src/vesting.rs (3 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
Additional context used
Learnings (1)
contracts/finance/andromeda-vesting/src/contract.rs (1)
Learnt from: cowboy0015
PR: andromedaprotocol/andromeda-core#466
File: contracts/non-fungible-tokens/andromeda-crowdfund/src/contract.rs:0-0
Timestamp: 2024-05-20T19:05:20.474Z
Learning: The `execute_claim` function in the Andromeda Crowdfund project has been refactored into `handle_successful_claim` and `handle_failed_claim` sub-functions to improve clarity and maintainability.
Additional comments not posted (25)
contracts/finance/andromeda-vesting/Cargo.toml (1)

3-3: Verify the impact of the version change on the dependent packages.

The version change from 2.0.0 to 3.0.0 indicates a major version update, which typically signifies breaking changes or significant enhancements in functionality. This aligns with the PR objective of removing the staking feature from the vesting contract.

Ensure that the version change does not break any dependent packages.

Run the following script to verify the impact of the version change:

Verification successful

Version change impact on integration tests appears minimal.

The andromeda-vesting package is referenced as a path dependency in tests-integration/Cargo.toml, but no specific usage of the package was found in the integration tests. This suggests that the version change to 3.0.0 does not directly impact the integration tests. However, ensure that any indirect dependencies or behaviors are verified manually.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the version change on the dependent packages.

# Test: Search for the usage of the `andromeda-vesting` package in the workspace. Expect: No breaking changes.
rg --type toml $'andromeda-vesting'

Length of output: 292


Script:

#!/bin/bash
# Description: Search for the usage of the `andromeda-vesting` package in the integration tests to identify potential breaking changes.

# Test: Search for references to `andromeda-vesting` in the `tests-integration` directory.
rg 'andromeda-vesting' tests-integration/

Length of output: 154

packages/andromeda-finance/src/vesting.rs (2)

Line range hint 23-46: LGTM!

The changes to the ExecuteMsg enum are approved. The removal of the variants and fields related to delegation and voting functionalities aligns with the PR objective of removing the staking feature from the vesting contract.


Line range hint 73-79: LGTM, but verify the impact on the codebase.

The removal of the unbonding_duration field from the Config struct is approved, as it aligns with the PR objective of removing the staking feature from the vesting contract.

However, ensure that the removal of this field does not break any existing functionality in the codebase.

Run the following script to verify the usage of the unbonding_duration field:

contracts/finance/andromeda-vesting/src/contract.rs (2)

90-90: LGTM!

The removal of the validator_to_delegate_to parameter is consistent with the overall changes in the file, which involve the removal of delegation-related functionalities. This change simplifies the execute_create_batch function by removing the delegation logic.


182-187: LGTM!

The changes in the execute_create_batch function are consistent with the removal of delegation-related functionalities. The function now focuses solely on creating a new batch and returning a response with relevant attributes. The changes simplify the function and improve its readability.

contracts/finance/andromeda-vesting/src/testing/tests.rs (20)

6-8: Removal of sample_validator is approved.

The function is not used in the remaining test functions, so its removal is safe.


6-8: Removal of sample_delegation is approved.

The function is not used in the remaining test functions, so its removal is safe.


6-8: Removal of set_delegation is approved.

The function is not used in the remaining test functions, so its removal is safe.


6-8: Removal of test_create_batch_and_delegate is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_claim_batch_all_funds_delegated is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_delegate_unauthorized is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_delegate_no_funds is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_delegate is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_delegate_more_than_balance is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_redelegate_unauthorized is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_redelegate_no_funds is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_redelegate is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_redelegate_more_than_max is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_undelegate_unauthorized is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_undelegate_no_funds is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_undelegate is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_undelegate_more_than_max is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_withdraw_rewards_unauthorized is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_vote_unauthorized is approved.

The function tests the voting functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.


6-8: Removal of test_withdraw_rewards is approved.

The function tests the delegation functionality, which has been removed from the contract. Therefore, its removal is consistent with the changes made to the contract.

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 d9db78a and 816e436.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments not posted (1)
CHANGELOG.md (1)

42-42: LGTM!

The new changelog entry is clear, concise, and consistent with the format of the other entries. It accurately reflects the removal of staking from the vesting contract.

* fix: vesting claim precision issues

* chore: version bump

* chore: changelog
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

Outside diff range, codebase verification and nitpick comments (4)
contracts/finance/andromeda-vesting/src/testing/tests.rs (4)

Line range hint 549-634: Review of New Test Case for Large Vesting Amounts

This test case introduces a scenario with a very large vesting amount and a complex release schedule. It's crucial to ensure that the logic handles large numbers and long durations correctly, especially with the use of Decimal for percentage calculations.

  • Correctness: The use of Decimal::from_ratio is appropriate for percentage calculations, ensuring precision.
  • Performance: Consider the impact of these calculations on performance, especially with large numbers and frequent claims.
  • Maintainability: The test is somewhat complex; ensure it is well-documented to explain its purpose and the expected outcomes.

Consider adding more detailed comments within the test to explain the rationale behind specific values and expected outcomes, enhancing maintainability and readability.


Line range hint 549-634: Potential Issue with Time Manipulation in Tests

The tests manipulate time to simulate the passing of vesting periods. This is a common practice in contract testing, but it must be done carefully to avoid misleading results.

  • Accuracy: Ensure that the time manipulation accurately reflects the intended testing scenarios.
  • Robustness: Consider edge cases where time manipulation might not reflect realistic scenarios, such as leap years or daylight saving changes.

Add checks or comments to ensure that time manipulations are clear and justified, helping future maintainers understand the test setup.


Line range hint 549-634: Complexity in Handling Large Numbers

The handling of large numbers, especially with financial calculations, must be precise to avoid rounding errors or integer overflows.

  • Safety: Use types and methods that are safe for handling large numbers, such as Uint128 from the cosmwasm_std library.
  • Testing: Include tests that specifically check for overflow conditions or rounding errors.

Refactor the test to include explicit checks for overflows and rounding errors, ensuring the robustness of financial calculations.


Line range hint 549-634: Enhance Test Coverage for New Functionality

Given the significant changes in functionality with the removal of staking features, it's important to ensure that the remaining functionalities are thoroughly tested.

  • Coverage: Review the test coverage to ensure that all critical paths and error conditions are tested.
  • Integration: Consider adding integration tests that cover interactions between different parts of the contract, especially with new configurations.

Would you like assistance in setting up additional tests or reviewing existing test coverage? I can help create a detailed test plan or review the current tests in more detail.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 816e436 and 09dee55.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • contracts/finance/andromeda-vesting/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-vesting/src/contract.rs (11 hunks)
  • contracts/finance/andromeda-vesting/src/testing/tests.rs (27 hunks)
  • packages/std/src/common/withdraw.rs (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contracts/finance/andromeda-vesting/Cargo.toml
Additional context used
Learnings (1)
contracts/finance/andromeda-vesting/src/contract.rs (1)
Learnt from: cowboy0015
PR: andromedaprotocol/andromeda-core#466
File: contracts/non-fungible-tokens/andromeda-crowdfund/src/contract.rs:0-0
Timestamp: 2024-05-20T19:05:20.474Z
Learning: The `execute_claim` function in the Andromeda Crowdfund project has been refactored into `handle_successful_claim` and `handle_failed_claim` sub-functions to improve clarity and maintainability.
Additional comments not posted (8)
packages/std/src/common/withdraw.rs (2)

20-22: Approved: Enhanced precision in withdrawal calculations.

The modification to return a decimal representation of the balance when no specific withdrawal type is provided enhances the precision of financial calculations, aligning with best practices in financial applications.


30-39: Approved: Accurate and safe arithmetic operations in withdrawal calculations.

The updates to handle different withdrawal types using decimal calculations, including the safe use of checked_mul, enhance the accuracy and safety of the financial computations.

contracts/finance/andromeda-vesting/src/testing/tests.rs (1)

6-8: Review of Import Changes

The imports have been adjusted to reflect the removal of staking features. Ensure that all necessary dependencies are still correctly imported for the remaining functionalities.

Verification successful

Imports are Correctly Adjusted

The imports in contracts/finance/andromeda-vesting/src/testing/tests.rs are correctly adjusted to reflect the removal of staking features. There are no unused imports, and all necessary dependencies for the vesting functionalities are present.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that no unused imports remain and all necessary imports are present.
rg --type rust "use" contracts/finance/andromeda-vesting/src/testing/tests.rs

Length of output: 328

CHANGELOG.md (2)

42-42: Clear and concise update on staking removal.

The entry accurately reflects the significant change in functionality by removing staking from the vesting contract and appropriately links to the pull request for more details.


50-50: Important update on precision fix.

The entry effectively communicates the resolution of precision issues with the vestings claim batch method, enhancing the reliability of the contract. It also appropriately links to the pull request for more details.

contracts/finance/andromeda-vesting/src/contract.rs (3)

Line range hint 91-142: Simplified batch creation logic.

The removal of the validator_to_delegate_to parameter simplifies the execute_create_batch function, aligning with the PR's objectives to reduce complexity and potential error sources in the contract. Ensure that all calls to this function have been updated to reflect the removal of this parameter.

Run the following script to verify the function usage:

Verification successful

Function signature update verified.

The execute_create_batch function is only used within contracts/finance/andromeda-vesting/src/contract.rs, and its signature change does not affect other parts of the codebase. The removal of the validator_to_delegate_to parameter aligns with the PR's objective to simplify the contract. No further updates are necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `execute_create_batch` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'execute_create_batch'

Length of output: 1176


325-329: Refined claim calculation logic.

The modifications in the claim_batch function improve the accuracy of the claim calculations, which is crucial for the integrity of financial transactions. Verify that the new calculations are correct and do not introduce rounding errors or other issues.

Run the following script to verify the correctness of the calculations:

Verification successful

Verified: Comprehensive test coverage for claim_batch function.

The modifications in the claim_batch function are thoroughly tested across various scenarios, ensuring the correctness of the calculations and handling of edge cases. The test cases cover unauthorized access, locked funds, no available funds, single and multiple claims, and edge cases with non-standard numbers, confirming the integrity of the new logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the claim calculations.

# Test: Search for the function usage and test cases. Expect: Correct calculations and no rounding errors.
rg --type rust -A 5 $'claim_batch'

Length of output: 7543


Script:

#!/bin/bash
# Extract the contents of the test functions related to claim_batch to verify their coverage.

# Search for the test functions related to claim_batch and extract their contents.
rg --type rust -A 20 'fn test_claim_batch_' contracts/finance/andromeda-vesting/src/testing/tests.rs

Length of output: 6057


420-423: Consistent update in claim calculations.

The modifications in the get_batch_response function ensure consistency with the changes in the claim_batch function, maintaining the accuracy of the claim calculations. Verify that the new calculations are correct and do not introduce rounding errors or other issues.

Run the following script to verify the correctness of the calculations:

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 09dee55 and af8b543.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (1)
  • CHANGELOG.md (2 hunks)
Additional comments not posted (2)
CHANGELOG.md (2)

42-42: Clear and relevant changelog entry.

The entry about the removal of staking from the vesting contract is clear and includes a reference to the relevant pull request, which is good practice for traceability.


52-52: Well-documented fix in the changelog.

The entry documenting the fix for the precision issue with the vestings claim batch method is concise and includes a reference to the pull request. It might be beneficial to add a brief description of the impact of this fix in future updates for better clarity.

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.

3 participants