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(core-token-vesting-v2)!: remove recipient #139

Merged
merged 3 commits into from
Mar 11, 2024

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Mar 11, 2024

  • remove recipient from Claim msg and default to sender
  • remove recipient from Withdraw msg and default to sender (who is also the admin)

BREAKING CHANGE: API breaking for Withdraw, but not for Claim because recipient was an Optional field. Doesn't matter for Withdraw because only the admin calls it on the backend.

Summary by CodeRabbit

  • Refactor
    • Simplified the handling of claim and withdrawal operations in the token vesting contract.
  • Bug Fixes
    • Adjusted recipient handling in withdrawal and claim functions for improved accuracy and security.
  • Tests
    • Updated withdrawal and claim logic in tests to reflect changes in the contract functionality.

@k-yang k-yang requested a review from matthiasmatt March 11, 2024 18:29
Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Walkthrough

The changes involve refining the functionality of the core-token-vesting-v2 contract, specifically focusing on simplifying the handling of Claim and Withdraw operations. By removing the recipient field from these operations, the contract now directly uses the info.sender for actions, streamlining the process and improving the contract's usability and security.

Changes

Files Summary of Changes
.../core-token-vesting-v2/src/contract.rs Refactored execute function; updated withdraw and claim.
.../core-token-vesting-v2/src/msg.rs Updated ExecuteMsg enum; removed recipient field.
.../core-token-vesting-v2/src/testing.rs Adjusted tests for withdrawal and claim logic changes.

Related issues

🐇🎉
To the code that we refine,
With each line, we align.
From Withdraw to Claim,
Simplicity's the aim.
Through the fields, we hop,
In our digital crop.
🚀🌟

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@k-yang k-yang requested a review from Unique-Divine March 11, 2024 18:29
@k-yang k-yang changed the title refactor(core-token-vesting-v2): remove recipient refactor(core-token-vesting-v2)!: remove recipient Mar 11, 2024
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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ddc4387 and 4cf78a9.
Files selected for processing (3)
  • contracts/core-token-vesting-v2/src/contract.rs (7 hunks)
  • contracts/core-token-vesting-v2/src/msg.rs (1 hunks)
  • contracts/core-token-vesting-v2/src/testing.rs (4 hunks)
Additional comments: 3
contracts/core-token-vesting-v2/src/msg.rs (1)
  • 35-45: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [80-81]

The removal of the recipient field from the Claim and Withdraw variants in the ExecuteMsg enum aligns with the PR's objectives to simplify the contract's logic. Ensure that this change has been thoroughly tested, especially in scenarios where the sender's defaulting as the recipient could affect the contract's intended functionality or security.

contracts/core-token-vesting-v2/src/contract.rs (2)
  • 90-104: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [80-114]

The changes in the withdraw function, including using info.sender as the recipient and the security checks, align with the PR's objectives to simplify the contract's logic. Ensure that these changes have been thoroughly tested, especially the admin check and the calculation of the maximum amount that can be withdrawn, to guarantee the function's robustness and correctness.

  • 353-366: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [357-400]

The updates to the claim function, including using info.sender as the recipient and simplifying the handling of vesting accounts, align with the PR's objectives. Ensure that these changes have been thoroughly tested, particularly in handling edge cases related to vesting accounts, to ensure the function's correctness and robustness.

Comment on lines 498 to 503

// unauthorized sender
let msg = ExecuteMsg::Withdraw {
recipient: "addr0000".to_string(),
amount: Uint128::new(1000),
};
require_error(
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [429-465]

The test test_withdraw correctly reflects the changes made to the ExecuteMsg::Withdraw message by removing the recipient parameter. However, it's important to ensure that the test cases cover scenarios where the sender is implicitly the recipient of the withdrawal. This is a key part of the PR's objectives, and the tests should explicitly verify that the funds are indeed sent to the info.sender address.

Additionally, the test includes a scenario where an unauthorized sender attempts to withdraw funds, which is good for verifying access control. However, it would be beneficial to add a test case that verifies the correct behavior when the sender attempts to withdraw an amount greater than their unallocated balance, ensuring that the contract logic correctly handles such cases.

Consider adding explicit assertions to verify that the withdrawn funds are sent to the info.sender address, as this is a critical aspect of the PR's objectives. Also, ensure that edge cases, such as attempting to withdraw more than the available unallocated balance, are adequately tested.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [467-567]

The claim_native test function has been updated to reflect the removal of the recipient parameter from the ExecuteMsg::Claim message. This test function is crucial for verifying that the claim functionality works as expected, particularly that the sender (who is also the claimant in this context) receives the claimed funds.

While the test does cover scenarios where the claim is made at different times to verify the amount claimable based on the vesting schedule, it would be beneficial to explicitly assert that the funds are sent to the info.sender address. Given the PR's objectives, ensuring that the claim functionality defaults the recipient to the sender is essential.

Enhance the claim_native test by adding explicit assertions to confirm that the claimed funds are sent to the info.sender address. This will ensure that the test suite fully covers the changes made to the claim functionality as per the PR's objectives.

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.58%. Comparing base (902b788) to head (cde2198).
Report is 18 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
contracts/core-token-vesting-v2/src/contract.rs 98.45% <100.00%> (ø)
contracts/core-token-vesting-v2/src/msg.rs 89.18% <ø> (ø)
contracts/core-token-vesting-v2/src/testing.rs 98.60% <100.00%> (ø)

... and 7 files with indirect coverage changes

ExecuteMsg::Withdraw { amount, recipient } => {
withdraw(deps, env, info, amount, recipient)
}
ExecuteMsg::Claim { denoms: _denoms } => claim(deps, env, info),
Copy link
Contributor

Choose a reason for hiding this comment

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

If we do breaking changes for the interface we can get rid of the denom parameter also

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing denoms is a breaking change for the UI because it's a mandatory field, but removing recipient is not because it's an Optional field, meaning the client doesn't have to send it.

Copy link
Contributor

Choose a reason for hiding this comment

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

we can leave it then

@k-yang k-yang requested a review from matthiasmatt March 11, 2024 18:53
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4cf78a9 and cde2198.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by: !**/*.lock
  • contracts/core-token-vesting-v2/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (3)
  • contracts/core-token-vesting-v2/src/contract.rs (8 hunks)
  • contracts/core-token-vesting-v2/src/msg.rs (2 hunks)
  • contracts/core-token-vesting-v2/src/testing.rs (4 hunks)
Files skipped from review as they are similar to previous changes (3)
  • contracts/core-token-vesting-v2/src/contract.rs
  • contracts/core-token-vesting-v2/src/msg.rs
  • contracts/core-token-vesting-v2/src/testing.rs

@matthiasmatt matthiasmatt merged commit 3ad5d5e into main Mar 11, 2024
5 checks passed
@matthiasmatt matthiasmatt deleted the refactor/core-token-vesting-v2/remove-recipient branch March 11, 2024 18:59
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