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 core compounder contract #126

Merged
merged 11 commits into from
Mar 22, 2024
Merged

feat: add core compounder contract #126

merged 11 commits into from
Mar 22, 2024

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Feb 29, 2024

This contracts allows to let anyone handle our staking re-delegation to avoid risk of having the seeds of a big account leaked.

Summary by CodeRabbit

  • New Features

    • Introduced an auto-compounder contract for vesting native tokens with functionalities for staking, unstaking, withdrawing, and querying status.
    • Added a Compounder contract for managing funds within a multisig setup, including permissions for admins and managers.
    • Enhanced the broker-bank contract with new functions for withdrawals, operator edits, and checking halt status.
  • Documentation

    • Updated documentation for the core-compounder contract and its functionalities.
  • Refactor

    • Refactored broker-bank contract logic for improved clarity and maintainability.
  • Tests

    • Added comprehensive test cases for the core-compounder contract functionalities.
  • Chores

    • Introduced new build and testing configurations for the core-compounder contract.
    • Updated .gitignore to ignore unnecessary files and directories.

Copy link
Contributor

coderabbitai bot commented Feb 29, 2024

Walkthrough

The recent updates bring forth an auto compounder contract for vesting native tokens, enhancing security and efficiency in fund management within a multisig setup. These changes introduce new functionalities for instantiating, executing, and querying contract states. Additionally, improvements have been made in the broker-bank contract, focusing on permission management, staking operations, and ensuring contract integrity through various modes of operation and error handling.

Changes

Files Summary
Cookbook.md, .../core-compounder/README.md Reorganized structure with updated section headings, added new contracts like "Airdrop token vesting" and "Auto compounder."
.../core-compounder/.cargo/config, .../core-compounder/.gitignore, artifacts/checksums.txt Introduced aliases for building, testing, and running WebAssembly code, updated ignore list, and added checksum entries.
.../core-compounder/examples/schema.rs, .../core-compounder/src/msg.rs Generated JSON schemas for messages, introduced message types for contract execution.
.../core-compounder/src/contract.rs, .../core-compounder/src/errors.rs, .../core-compounder/src/lib.rs, .../core-compounder/src/state.rs, .../core-compounder/src/testing.rs Managed stake operations, ownership, permissions, introduced error handling, state management, and testing functionalities.
.../broker-bank/src/contract.rs, .../broker-bank/src/lib.rs, .../broker-bank/src/msgs.rs Enhanced broker-bank contract with new functions, refactored logic, and added a query message for halted status.

🐰✨
In the realm of code, where smart contracts thrive,
A rabbit hopped in, making blockchains come alive.
With a flick and a hop, it spun up a scheme,
To compound and vest, a financier's dream.
"To the moon!" it exclaimed, with a twinkle in its eye,
For in the world of DeFi, even rabbits can fly.
🚀🌕

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.

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5436b53 and 6af55fb.
Files ignored due to path filters (7)
  • Cargo.lock is excluded by: !**/*.lock
  • contracts/core-compounder/Cargo.lock is excluded by: !**/*.lock
  • contracts/core-compounder/Cargo.toml is excluded by: !**/*.toml
  • contracts/core-compounder/schema/execute_msg.json is excluded by: !**/*.json
  • contracts/core-compounder/schema/instantiate_msg.json is excluded by: !**/*.json
  • contracts/core-compounder/schema/query_msg.json is excluded by: !**/*.json
  • contracts/core-compounder/schema/vesting_account_response.json is excluded by: !**/*.json
Files selected for processing (11)
  • Cookbook.md (1 hunks)
  • contracts/core-compounder/.cargo/config (1 hunks)
  • contracts/core-compounder/.gitignore (1 hunks)
  • contracts/core-compounder/README.md (1 hunks)
  • contracts/core-compounder/examples/schema.rs (1 hunks)
  • contracts/core-compounder/src/contract.rs (1 hunks)
  • contracts/core-compounder/src/errors.rs (1 hunks)
  • contracts/core-compounder/src/lib.rs (1 hunks)
  • contracts/core-compounder/src/msg.rs (1 hunks)
  • contracts/core-compounder/src/state.rs (1 hunks)
  • contracts/core-compounder/src/testing.rs (1 hunks)
Files skipped from review due to trivial changes (3)
  • contracts/core-compounder/.cargo/config
  • contracts/core-compounder/.gitignore
  • contracts/core-compounder/src/testing.rs
Additional comments: 14
contracts/core-compounder/src/lib.rs (1)
  • 1-7: The module structure and conditional compilation directive for the testing module are correctly implemented, adhering to Rust's best practices.
contracts/core-compounder/src/errors.rs (1)
  • 1-13: The error definitions in errors.rs are correctly implemented, using the thiserror crate for clear and concise error handling, which adheres to Rust's best practices.
contracts/core-compounder/examples/schema.rs (1)
  • 1-16: The schema generation script in schema.rs is correctly implemented, using the cosmwasm_schema crate to generate JSON schemas for the contract's message structures, adhering to best practices for CosmWasm contract development.
contracts/core-compounder/src/state.rs (1)
  • 1-24: The state management in state.rs is correctly implemented, using cw_storage_plus for state items and HashSet for managing unique manager addresses, adhering to best practices for CosmWasm contract development.
contracts/core-compounder/README.md (1)
  • 1-39: The documentation in README.md is well-written and provides a clear and accurate overview of the Compounder contract's functionality, modes, and role-based operations.
contracts/core-compounder/src/msg.rs (1)
  • 1-61: The message structures in msg.rs are correctly implemented, covering a comprehensive range of contract operations and adhering to best practices for CosmWasm contract message design.
contracts/core-compounder/src/contract.rs (8)
  • 12-18: The instantiation function correctly validates the input parameters, ensuring that the list of managers is not empty and that all addresses are valid. This is crucial for preventing misconfiguration of the contract at deployment.
  • 40-46: The execute function correctly dispatches the incoming message to the appropriate handler based on the message type. This pattern is standard and effective for handling different contract actions.
  • 66-90: The update_managers function correctly implements authorization checks to ensure that only the admin can update the list of managers. This is a critical security measure to prevent unauthorized changes to the contract's state.
  • 92-105: The set_autocompounder_mode function correctly implements authorization checks and updates the auto compounder mode state. This function is essential for controlling the contract's behavior based on the admin's decisions.
  • 108-133: The withdraw function correctly implements authorization checks and constructs a message for withdrawing funds. It's important to ensure that only the admin can perform withdrawals, maintaining control over the contract's funds.
  • 136-157: The unstake function correctly implements authorization checks and constructs messages for unstaking tokens. This function is crucial for managing the contract's staked tokens in a secure manner.
  • 162-197: The stake function correctly implements authorization checks, allowing both managers and the admin to stake tokens. It also validates the total shares to prevent invalid stake distributions. This function is key to the contract's functionality, enabling the staking of tokens in a controlled and secure manner.
  • 261-279: The query functions correctly implement the logic for returning the auto compounder mode and the admin and managers' information. These functions are essential for external parties to understand the contract's current state and configuration.

Cookbook.md Outdated
Comment on lines 658 to 766
```javascript
{
"admin": "cosmos1...",
"managers": ["cosmos1...", "cosmos1..."]
}
```

### 8.2 Execute

#### Admin functions

- **SetAutoCompounderMode** sets the auto compounder mode

```javascript
{
"set_auto_compounder_mode": {
"mode": "true" // true or false
}
}
```

- **Withdraw** allows to withdraw the funds from the contract

```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
}
}
```

- **unstakes** allows to unstake the funds from the contract

```javascript
{
"unstake": {
"unstake_msgs": [
{
"validator": "cosmosvaloper1...",
"amount": "1000000"
},
{
"validator": "cosmosvaloper1...",
"amount": "1000000"
}
]
}
}
```

- **update managers** allows to update the managers of the contract

```javascript
{
"update_managers": {
"managers": ["cosmos1...", "cosmos1..."]
}
}
```

#### Manager functions

- **stake** allows to stake the funds from the contract. The shares are normalized

```javascript
{
"stake": {
"stake_msgs": [
{
"validator": "cosmosvaloper1...",
"share": "1000000"
},
{
"validator": "cosmosvaloper1...",
"share": "1000000"
}
]
},
"amount": "1000000"
}
```

### 8.3 Query

- **auto compounder mode** returns wether the auto compounder mode is enabled or not

```javascript
{
"auto_compounder_mode": {}
}
```

- **AdminAndManagers** returns the admin and managers of the contract

```javascript
{
"admin_and_managers": {}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation for the "Auto compounder" contract is well-structured and aligns with the PR objectives of enhancing security and efficiency in staking re-delegation processes. However, there are a few areas that could be improved for clarity and consistency:

  1. Instantiate Section (Lines 665-671): The description "This contract implements vesting accounts for the native tokens." seems to be a copy-paste error from the previous section. It would be more appropriate to describe the specific purpose of the auto compounder contract here, focusing on its role in managing staking re-delegation securely.

  2. Execute Section - Withdraw Function (Lines 688-697): There's a missing comma at the end of line 693. This could lead to confusion or errors if someone tries to use this JSON snippet as is. It should be corrected to ensure syntactical accuracy.

  3. General Consistency: Ensure that the documentation style, such as the use of backticks for code snippets and the indentation of JSON objects, is consistent throughout this section and matches the style used in the rest of the Cookbook.md file. This includes consistent use of comments within the JSON snippets to explain parameters or expected values.

  4. Clarity on Manager Functions (Lines 728-747): It would be beneficial to add a brief explanation about what it means for shares to be "normalized" in the context of staking. This could help users understand how the stake function operates and what they should expect when using it.

Improving these areas will enhance the readability and usability of the documentation for developers and users interacting with the auto compounder contract.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 93.90642% with 56 lines in your changes are missing coverage. Please review.

Project coverage is 88.14%. Comparing base (902b788) to head (e5c1af5).
Report is 21 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
contracts/broker-bank/src/msgs.rs 25.00% <ø> (ø)
contracts/core-token-vesting-v2/src/contract.rs 98.46% <100.00%> (ø)
contracts/broker-bank/src/tutil.rs 88.63% <0.00%> (ø)
contracts/broker-staking/src/msg.rs 0.00% <0.00%> (ø)
contracts/core-token-vesting-v2/src/state.rs 75.67% <0.00%> (ø)
contracts/broker-bank/src/contract.rs 96.17% <97.33%> (ø)
contracts/broker-staking/src/contract.rs 84.49% <84.49%> (ø)
contracts/broker-staking/src/testing.rs 96.03% <96.03%> (ø)

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6af55fb and 36ca1fd.
Files ignored due to path filters (3)
  • artifacts/core_compounder.wasm is excluded by: !**/*.wasm
  • contracts/core-compounder/schema/execute_msg.json is excluded by: !**/*.json
  • contracts/core-compounder/schema/query_msg.json is excluded by: !**/*.json
Files selected for processing (3)
  • artifacts/checksums.txt (1 hunks)
  • contracts/core-compounder/src/contract.rs (1 hunks)
  • contracts/core-compounder/src/testing.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contracts/core-compounder/src/contract.rs
Additional comments: 6
artifacts/checksums.txt (1)
  • 4-4: The addition of the core_compounder.wasm checksum follows the project's standards for tracking WebAssembly binaries. This update is crucial for ensuring the integrity of the newly introduced contract.
contracts/core-compounder/src/testing.rs (5)
  • 14-90: This test function invalid_manangers_initialization correctly checks for various invalid initialization scenarios, ensuring that the contract initialization logic is robust against incorrect inputs. It's well-structured and covers essential failure cases, including empty managers and invalid admin addresses.
  • 92-301: The test_execute_permission function thoroughly tests permissions for various contract actions, such as staking, unstaking, withdrawing, and updating managers. It ensures that only authorized roles can perform specific actions, which is crucial for the contract's security. The tests are comprehensive and cover a wide range of scenarios.
  • 304-436: The test_share_calc function tests the share calculation logic during staking to multiple validators with different shares. It's a critical test that ensures the staking logic divides tokens correctly among validators based on the specified shares. The test is well-designed and covers several scenarios, including equal and unequal shares.
  • 439-463: The test_withdraw function checks the withdrawal functionality, ensuring that only authorized roles can perform withdrawals. This test is straightforward and validates an essential aspect of the contract's security regarding fund management.
  • 467-517: The test_unstake function validates the unstaking functionality, ensuring that the contract correctly handles unstaking requests to multiple validators. It's an important test that verifies the contract's ability to handle unstaking actions correctly, including handling different amounts and validators.

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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 36ca1fd and 50a1130.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by: !**/*.lock
  • artifacts/core_compounder.wasm is excluded by: !**/*.wasm
Files selected for processing (2)
  • Cookbook.md (5 hunks)
  • artifacts/checksums.txt (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • artifacts/checksums.txt
Additional comments: 5
Cookbook.md (5)
  • 517-523: The instantiation message correctly specifies the admin and managers, aligning with the contract's design for role separation. This is essential for managing permissions within a multisig setup.
  • 551-567: The unstake function documentation uses the term "unstakes" which might be a typo or inconsistency in naming. Consider using "unstake" for consistency with the function name.
  • 570-577: The update managers function documentation should use camelCase for consistency with other function names in the documentation, e.g., updateManagers. Consistency in naming conventions improves readability and maintainability.
-  "update managers": {
+  "updateManagers": {
  • 604-610: The query for the auto compounder mode is correctly documented, providing a clear example of how to check if the auto compounder mode is enabled or not.
  • 612-618: The query for retrieving the admin and managers of the contract is well-documented, offering a straightforward way to obtain this information. This is crucial for understanding the contract's permission structure.

Comment on lines +582 to +598

```javascript
{
"stake": {
"stake_msgs": [
{
"validator": "cosmosvaloper1...",
"share": "1000000"
},
{
"validator": "cosmosvaloper1...",
"share": "1000000"
}
]
},
"amount": "1000000"
Copy link
Contributor

Choose a reason for hiding this comment

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

The stake function documentation mentions that "The shares are normalized," but it lacks clarity on what "normalized" means in this context. Adding a brief explanation would help users understand how the function operates and what to expect when using it.

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 50a1130 and 3209e9c.
Files ignored due to path filters (1)
  • artifacts/core_compounder.wasm is excluded by: !**/*.wasm
Files selected for processing (2)
  • artifacts/checksums.txt (1 hunks)
  • contracts/core-compounder/src/contract.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • artifacts/checksums.txt
  • contracts/core-compounder/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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3209e9c and 73f96b5.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by: !**/*.lock
Files selected for processing (1)
  • artifacts/checksums.txt (1 hunks)
Additional comments: 1
artifacts/checksums.txt (1)
  • 2-2: The addition of the checksum for core_compounder.wasm is consistent with the file's purpose of tracking checksums for wasm files. Ensure the checksum is correctly generated and matches the actual wasm file to prevent any integrity issues.

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 73f96b5 and abf8865.
Files ignored due to path filters (2)
  • Cargo.lock is excluded by: !**/*.lock
  • contracts/core-compounder/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (8)
  • contracts/broker-bank/src/contract.rs (2 hunks)
  • contracts/broker-bank/src/lib.rs (1 hunks)
  • contracts/broker-bank/src/msgs.rs (1 hunks)
  • contracts/core-compounder/examples/schema.rs (1 hunks)
  • contracts/core-compounder/src/contract.rs (1 hunks)
  • contracts/core-compounder/src/lib.rs (1 hunks)
  • contracts/core-compounder/src/msg.rs (1 hunks)
  • contracts/core-compounder/src/testing.rs (1 hunks)
Additional comments: 16
contracts/core-compounder/src/lib.rs (3)
  • 1-1: LGTM!
  • 2-2: LGTM!
  • 4-5: Correct use of conditional compilation for the testing module.
contracts/broker-bank/src/lib.rs (1)
  • 1-5: > 📝 NOTE

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

The removal of the #[cfg(test)] attribute from the tutil module means it will now be included in the production build. Please verify if this was intentional. If tutil is meant only for testing, consider restoring the #[cfg(test)] attribute.

contracts/core-compounder/examples/schema.rs (1)
  • 1-17: The schema generation script is correctly implemented. Consider adding error handling instead of using unwrap() for a more robust solution, especially in larger or more complex scripts.
contracts/broker-bank/src/msgs.rs (1)
  • 43-45: The addition of the IsHalted query message is correctly implemented and enhances the contract's functionality.
contracts/core-compounder/src/testing.rs (10)
  • 23-31: The TestCaseExec struct is well-defined for encapsulating test case parameters. However, consider adding documentation comments to explain the purpose of each field, especially for complex or non-obvious ones like resp_msgs and contract_funds_start. This will improve code readability and maintainability.
  • 236-252: The CosmosMsgExt struct and its implementations (PartialEq, Display) are cleverly designed for comparing CosmosMsg instances in a human-readable format. This is a good practice for test assertions that involve complex structures. Well done!
  • 33-121: The test test_assert_owner effectively checks that owner-gated execute calls fail when the sender is not the contract owner. It's comprehensive and covers multiple scenarios. However, ensure that the error messages checked in the assertions are aligned with the actual contract implementation to avoid false negatives in the tests.
  • 123-234: The exec_withdraw test case is well-structured and covers both success and failure scenarios for withdrawal operations. It's good to see the use of mock queriers for setting up contract balances. To further improve, consider adding more detailed comments explaining the rationale behind each test case, especially for complex scenarios involving contract funds and expected response messages.
  • 254-303: The exec_toggle_halt test case thoroughly checks the functionality of toggling the halt status of the contract. It includes both success and error cases, which is commendable. One suggestion is to add assertions for the state change after the toggle operation to ensure that the contract's state is correctly updated.
  • 309-352: The exec_edit_opers_add test case effectively tests the addition of operators. It's good to see checks for both the response and the updated state. To enhance this test, consider adding negative test cases, such as attempting to add an operator that already exists, to ensure robust error handling.
  • 354-407: The exec_edit_opers_remove test case is well-implemented, covering the removal of operators from the permissions set. Similar to the previous comment, consider adding negative test cases, such as attempting to remove an operator that does not exist, to ensure the contract handles these scenarios gracefully.
  • 409-454: The exec_stake_halted test case checks staking operations under normal and halted conditions. This is crucial for ensuring the contract behaves correctly under different states. It's well-implemented, but adding comments to explain the rationale behind each test scenario would improve readability.
  • 456-624: The exec_stake test case thoroughly tests various staking scenarios, including success cases with different shares and failure cases with invalid senders or empty stake messages. This comprehensive approach is commendable. To further improve, consider adding tests for edge cases, such as staking with minimal amounts or to non-existent validators, to ensure robustness.
  • 626-764: The exec_unstake test case covers unstaking operations, including success scenarios and failure cases where the sender lacks the necessary permissions. It's well-structured and provides a good coverage of the unstake functionality. Similar to previous comments, adding tests for edge cases, such as unstaking more than the available balance, would enhance the test suite.

Comment on lines 305 to 307
// TODO: test ExecuteMsg::EditOpers
// TODO: ownership query
// pub fn get_ownership(storage: &dyn Storage) -> StdResult<Ownership<Addr>>
Copy link
Contributor

Choose a reason for hiding this comment

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

These TODO comments indicate unfinished work related to testing ExecuteMsg::EditOpers and querying ownership. It's important to address these to ensure comprehensive test coverage of the contract's functionalities.

Would you like me to help implement these tests or open a GitHub issue to track this task?

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: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between abf8865 and 4b87403.
Files selected for processing (3)
  • Cookbook.md (5 hunks)
  • contracts/README.md (2 hunks)
  • contracts/core-compounder/README.md (1 hunks)
Additional comments: 3
contracts/README.md (1)
  • 17-18: The addition of the core-compounder contract to the README is clear and aligns with the PR objectives. However, consider adding a more detailed description or a link to further documentation for users who might be interested in learning more about its functionalities and use cases.
contracts/core-compounder/README.md (1)
  • 49-49: The description for the Withdraw function could be improved for clarity. Consider specifying that it allows the admin to withdraw funds, to make it clear who has the permission to perform this action.
Cookbook.md (1)
  • 582-598: The documentation mentions that "The shares are normalized" in the context of staking, but it lacks clarity on what "normalized" means. Adding a brief explanation would help users understand how the function operates and what to expect when using it.

contracts/core-compounder/README.md Outdated Show resolved Hide resolved
contracts/core-compounder/README.md Outdated Show resolved Hide resolved
Cookbook.md Outdated Show resolved Hide resolved
Comment on lines +540 to +546
- **Withdraw** allows to withdraw the funds from the contract

```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
Copy link
Contributor

Choose a reason for hiding this comment

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

The JSON snippet for the Withdraw function is missing a comma at the end of line 545. This syntax error could lead to confusion or errors if someone tries to use this snippet as is. It should be corrected to ensure syntactical accuracy.

     "withdraw": {
       "amount": "1000000",
       "recipient": "cosmos1..."

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000",
"recipient": "cosmos1..."

Copy link
Member

Choose a reason for hiding this comment

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

There's some duplicate code here

artifacts/core_compounder.wasm Outdated Show resolved Hide resolved
@@ -40,7 +40,9 @@ pub enum QueryMsg {
/// operator set is "halted".
#[returns(PermsStatus)]
Perms {},
// TODO: feat(broker-bank): Logs query
Copy link
Member

Choose a reason for hiding this comment

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

TODO not yet implemented, so we should keep the comment and open an issue

contracts/core-compounder/.gitignore Outdated Show resolved Hide resolved
contracts/core-compounder/Cargo.toml Outdated Show resolved Hide resolved
contracts/core-compounder/schema/execute_msg.json Outdated Show resolved Hide resolved
Unique-Divine and others added 2 commits March 22, 2024 04:37
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b87403 and fca8548.
Files ignored due to path filters (9)
  • Cargo.lock is excluded by: !**/*.lock
  • Cargo.toml is excluded by: !**/*.toml
  • artifacts/broker_bank.wasm is excluded by: !**/*.wasm
  • artifacts/broker_staking.wasm is excluded by: !**/*.wasm
  • artifacts/core_token_vesting_v2.wasm is excluded by: !**/*.wasm
  • artifacts/shifter.wasm is excluded by: !**/*.wasm
  • contracts/broker-bank/Cargo.toml is excluded by: !**/*.toml
  • contracts/broker-staking/Cargo.lock is excluded by: !**/*.lock
  • contracts/broker-staking/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (16)
  • artifacts/checksums.txt (1 hunks)
  • contracts/README.md (3 hunks)
  • contracts/broker-bank/README.md (1 hunks)
  • contracts/broker-bank/src/contract.rs (3 hunks)
  • contracts/broker-bank/src/lib.rs (1 hunks)
  • contracts/broker-bank/src/tutil.rs (2 hunks)
  • contracts/broker-staking/.cargo/config (1 hunks)
  • contracts/broker-staking/.gitignore (1 hunks)
  • contracts/broker-staking/README.md (1 hunks)
  • contracts/broker-staking/examples/schema.rs (1 hunks)
  • contracts/broker-staking/src/contract.rs (1 hunks)
  • contracts/broker-staking/src/lib.rs (1 hunks)
  • contracts/broker-staking/src/msg.rs (1 hunks)
  • contracts/broker-staking/src/testing.rs (1 hunks)
  • contracts/core-token-vesting-v2/src/contract.rs (2 hunks)
  • contracts/core-token-vesting-v2/src/state.rs (1 hunks)
Files skipped from review due to trivial changes (3)
  • contracts/broker-staking/.cargo/config
  • contracts/broker-staking/.gitignore
  • contracts/core-token-vesting-v2/src/contract.rs
Files skipped from review as they are similar to previous changes (2)
  • contracts/broker-bank/src/contract.rs
  • contracts/broker-bank/src/lib.rs
Additional comments: 26
contracts/broker-staking/src/lib.rs (1)
  • 1-5: LGTM! The module declarations are correctly defined.
contracts/broker-bank/README.md (1)
  • 1-5: The description of the broker-bank contract is clear and concise.
contracts/broker-staking/examples/schema.rs (1)
  • 1-17: The schema generation script is correctly implemented and uses appropriate imports for message types.
artifacts/checksums.txt (1)
  • 1-14: The checksum entries are correctly added and updated. The formatting is consistent with expected standards.
contracts/broker-bank/src/tutil.rs (1)
  • 1-11: > 📝 NOTE

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

The testing utilities are well-organized with appropriate conditional compilation for non-WASM targets. The setup functions for contracts are correctly implemented.

contracts/broker-staking/src/msg.rs (1)
  • 1-61: The message types for the broker-staking contract are well-defined, with clear documentation comments explaining each operation. The use of BTreeSet for denoms in the Withdraw message is a good practice to ensure uniqueness.
contracts/core-token-vesting-v2/src/state.rs (1)
  • 62-70: > 📝 NOTE

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

The vested_amount method in the VestingAccount implementation is correctly calculated and clearly written. The explicit subtraction syntax enhances readability and maintainability.

contracts/README.md (1)
  • 9-37: > 📝 NOTE

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

The updates to the README file correctly include new broker contracts and improve formatting for better readability. The content is well-organized and clear.

contracts/broker-staking/README.md (1)
  • 66-66: The phrase "allows to withdraw" might be improved for clarity. Consider rephrasing to explicitly state the subject performing the action.

Consider rephrasing to "allows the admin to withdraw" for clarity.

contracts/broker-staking/src/contract.rs (6)
  • 1-6: Ensure that all imported modules and functions are used within the file. Unused imports can lead to confusion and clutter the codebase.
Verification successful

All imported modules and functions (assert_not_halted, edit_opers, execute_update_ownership, query_perms_status, toggle_halt, withdraw, withdraw_all) are utilized within contracts/broker-staking/src/contract.rs. No unused imports were found.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if all imported modules and functions are utilized.
rg 'assert_not_halted|edit_opers|execute_update_ownership|query_perms_status|toggle_halt|withdraw|withdraw_all' contracts/broker-staking/src/contract.rs

Length of output: 715

* 20-34: The `instantiate` function correctly initializes the contract state. Ensure that all necessary validations are performed on the input parameters to prevent any potential issues.

Consider adding validation for the msg.to_addrs and msg.opers fields to ensure they meet specific criteria (e.g., non-empty, valid addresses).

  • 36-63: The execute function dispatches various contract actions based on the message type. It's crucial to ensure that permissions are correctly enforced for each action to prevent unauthorized access.

Verify that permission checks (e.g., ownership or operator status) are correctly implemented for sensitive actions such as Withdraw, ToggleHalt, and UpdateOwnership.

  • 65-87: The unstake function allows the contract owner to unstake funds. Ensure that the amount to unstake is validated against the contract's staked balance to prevent underflow or other issues.

Consider adding a check to ensure that the total unstake amount does not exceed the contract's current staked balance.

  • 89-132: The stake function allows operators to stake funds. It's important to validate the amount and stake_msgs to ensure they are within acceptable ranges and conditions.

Verify that the amount to stake is validated against the contract's available balance to prevent over-staking. Additionally, ensure that the stake_msgs are validated for correctness.

  • 160-179: The query function handles various query messages. Ensure that the responses are correctly formatted and contain all necessary information for each query type.

Verify that the query responses for Perms, Ownership, and IsHalted contain accurate and complete information.

contracts/broker-staking/src/testing.rs (11)
  • 3-11: Consider organizing imports to improve readability. Grouping standard library imports, third-party crates, and local module imports separately can make the code cleaner.
  • 23-31: The TestCaseExec struct is well-defined for encapsulating test case parameters. However, consider adding documentation comments to explain the purpose of each field, especially for complex or non-obvious ones. This will enhance maintainability and readability for other developers.
  • 36-120: The test test_assert_owner effectively checks owner-gated execute calls. However, it's recommended to separate the test cases into individual test functions or use a parameterized testing framework like rstest for clarity and easier debugging.
  • 124-233: In exec_withdraw, consider verifying the correctness of the BankMsg::Send amounts in the success cases. Currently, the test checks for the presence of expected messages but does not validate the amounts being sent, which is crucial for withdrawal functionality.
  • 236-252: The CosmosMsgExt struct and its implementations are a clever way to compare CosmosMsg instances. However, adding a brief comment explaining its purpose and usage would be beneficial for maintainability.
  • 254-303: In exec_toggle_halt, the test effectively toggles the halt status and verifies the operation. However, it's recommended to split the error and success cases into separate test functions for clarity. Additionally, consider verifying the state change directly from the contract's storage instead of relying solely on query responses to ensure the state is correctly updated.
  • 309-352: For exec_edit_opers_add, it's good practice to also verify the absence of the new member in the permissions set before the operation. This ensures the test covers the state change more comprehensively.
  • 355-407: In exec_edit_opers_remove, consider adding a check to ensure the member to be removed exists in the permissions set before the operation. This addition would make the test more robust by covering the initial state more thoroughly.
  • 410-454: The test exec_stake_halted correctly checks the behavior when staking operations are halted. However, it would be beneficial to add a test case that verifies the successful staking operation when IS_HALTED is set to false, to ensure both states are covered.
  • 457-619: In exec_stake, the test cases cover various scenarios effectively. However, for the fail cases, consider verifying that no state changes occurred in the contract as a result of the failed operation. This can be done by checking the contract's storage or balances before and after the operation.
  • 621-754: For exec_unstake, similar to the exec_stake test, it's recommended to verify that no state changes occurred in the contract for the fail cases. Additionally, consider adding a test case to verify the behavior when attempting to unstake more than the available balance, to ensure robust error handling.

This smart contract handles account abstraction to enable certain staking transaction messages
to be called by a subset of "operators", while the funds can only be withdrawn by the contract owner.

This is useful if you want a mutlisig to manage a large allocation of funds while
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a typo in "mutlisig" which should be corrected to "multisig".

- This is useful if you want a mutlisig to manage a large allocation of funds while
+ This is useful if you want a multisig to manage a large allocation of funds while

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
This is useful if you want a mutlisig to manage a large allocation of funds while
This is useful if you want a multisig to manage a large allocation of funds while


- stake funds to validators in the proportion given

This way, only the multisig can maange the funds, and the seed keys of the
Copy link
Contributor

Choose a reason for hiding this comment

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

The word "maange" is misspelled. It should be corrected to "manage".

- This way, only the multisig can maange the funds, and the seed keys of the
+ This way, only the multisig can manage the funds, and the seed keys of the

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
This way, only the multisig can maange the funds, and the seed keys of the
This way, only the multisig can manage the funds, and the seed keys of the

}
```

- **unstakes** allows to unstake the funds from the contract
Copy link
Contributor

Choose a reason for hiding this comment

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

The function name "unstakes" seems to be inconsistent with the naming convention used for other functions. Function names should be verbs and correctly spelled.

- - **unstakes** allows to unstake the funds from the contract
+ - **Unstake** allows to unstake the funds from the contract

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **unstakes** allows to unstake the funds from the contract
- **Unstake** allows to unstake the funds from the contract


##### Manager functions

- **stake** allows to stake the funds from the contract. The shares are normalized
Copy link
Contributor

Choose a reason for hiding this comment

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

The function name "stake" should start with an uppercase letter to maintain consistency with other function names in the document.

- - **stake** allows to stake the funds from the contract. The shares are normalized
+ - **Stake** allows to stake the funds from the contract. The shares are normalized

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **stake** allows to stake the funds from the contract. The shares are normalized
- **Stake** allows to stake the funds from the contract. The shares are normalized


#### Query

- **auto compounder mode** returns wether the auto compounder mode is enabled or not
Copy link
Contributor

Choose a reason for hiding this comment

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

The word "wether" is misspelled. It should be corrected to "whether".

- - **auto compounder mode** returns wether the auto compounder mode is enabled or not
+ - **auto compounder mode** returns whether the auto compounder mode is enabled or not

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **auto compounder mode** returns wether the auto compounder mode is enabled or not
- **auto compounder mode** returns whether the auto compounder mode is enabled or not


### Deployed Contract Info

TODO for mainnet/testnet
Copy link
Contributor

Choose a reason for hiding this comment

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

The "TODO for mainnet/testnet" placeholder suggests that information is missing. It's important to complete this section before the final release.

Would you like assistance in completing this section?

@@ -0,0 +1,5 @@
# contracts/broker-bank

Account abstration to enable funds to be held and sent to a whitelisted set of
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a typo in "abstration"; it should be "abstraction".

- Account abstration to enable funds to be held and sent to a whitelisted set of
+ Account abstraction to enable funds to be held and sent to a whitelisted set of

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Account abstration to enable funds to be held and sent to a whitelisted set of
Account abstraction to enable funds to be held and sent to a whitelisted set of

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fca8548 and e5c1af5.
Files selected for processing (1)
  • Cookbook.md (5 hunks)
Additional comments: 4
Cookbook.md (4)
  • 6-34: The reorganization of section headings and subheadings improves the document's structure and readability. The addition of "Airdrop token vesting" and "Auto compounder" contracts is clearly marked and follows the established documentation format.
  • 437-509: The "Airdrop token vesting" contract documentation is well-structured, providing clear instructions for instantiation, execution, and querying. However, ensure that the example JSON snippets are correctly formatted and that any specific details about the contract's functionality are accurately described.
  • 511-618: The "Auto compounder" contract documentation aligns with the PR objectives of enhancing security and efficiency in staking re-delegation processes. It's well-structured, covering instantiation, execution (including admin and manager functions), and querying. Ensure that the JSON snippets are syntactically correct and that the descriptions accurately reflect the contract's capabilities.
  • 582-598: The documentation for the stake function mentions that "The shares are normalized," but it lacks clarity on what "normalized" means in this context. Adding a brief explanation would help users understand how the function operates and what to expect when using it.

Consider adding a sentence or two explaining the normalization process for shares in the context of staking to enhance clarity for the readers.

Comment on lines +540 to +549

```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
}
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a missing comma at the end of line 546 in the JSON snippet for the Withdraw function. This syntax error could lead to confusion or errors if someone tries to use this snippet as is. It should be corrected to ensure syntactical accuracy.

  {
    "withdraw": {
      "amount": "1000000",
+     "recipient": "cosmos1..."
    }
  }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
}
}
```
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000",
"recipient": "cosmos1..."
}
}

</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

@Unique-Divine Unique-Divine merged commit f546e89 into main Mar 22, 2024
5 checks passed
@Unique-Divine Unique-Divine deleted the mat/autocompounder branch March 22, 2024 17:00
@Unique-Divine Unique-Divine mentioned this pull request Mar 27, 2024
2 tasks
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