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(treasury): add swap functionalities through osmosis #126

Merged
merged 22 commits into from
Jun 11, 2024

Conversation

manu0466
Copy link
Contributor

@manu0466 manu0466 commented May 29, 2024

Overview

This PR updates the treasury and staking contracts, allowing the staking contract to send protocol fees to the treasury and enabling a trader account to perform swap operations, helping the treasury hedge against asset price fluctuations.

To prevent the trader from converting the treasury's assets into unwanted ones, a list of swap routes can be defined. This forces the trader to use only a predefined set of pools and only in a predefined direction. For example, if the Osmosis pool 1 has the OSMO/USDC pair, we can enforce that the trader can only swap OSMO for USDC, but not the other way around.

closes: MILKTIA-35

What changes have been made in this PR?

  • Add swap functionalities to the treasury contract
  • Allow the staking contract to send the protocol fees to the treasury
  • Fix lint errors reported by cargo clippy

Checklist


  • Appropriate labels applied
  • Targeted PR against correct branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit and integration
  • Updated relevant documentation

@manu0466 manu0466 requested a review from jaybxyz as a code owner May 29, 2024 10:37
Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

The recent updates involve adding new dependencies, updating existing ones, and incorporating new functionalities across various files. Key changes include transitioning to to_json_binary for data serialization, introducing a send_fees_to_treasury configuration option, and updating the bech32 library usage. These changes enhance the project's compatibility, functionality, and performance.

Changes

Files/Paths Change Summaries
Cargo.toml, contracts/staking/Cargo.toml Added new dependencies (bech32, cw-controllers, cw-storage-plus, semver) and updated existing ones (cosmwasm-schema, cosmwasm-std, osmosis-std).
README.md Updated treasury contract description.
contracts/staking/src/ack.rs, contracts/staking/src/contract.rs Replaced to_binary with to_json_binary for serialization.
contracts/staking/src/contract.rs, contracts/staking/src/state.rs, contracts/staking/src/msg.rs Added send_fees_to_treasury configuration option.
contracts/staking/src/execute.rs Modified transfer_stake_msg, update_config, and receive_rewards to handle send_fees_to_treasury configuration.
contracts/staking/src/helpers.rs Updated bech32 library usage and adjusted related functions.
contracts/staking/src/migrations/mod.rs Updated module version from v0_4_19 to v0_4_20.
contracts/staking/src/tests/circuit_breaker_tests.rs, contracts/staking/src/tests/ibc_transfer_tests.rs, contracts/staking/src/tests/reward_tests.rs, contracts/staking/src/tests/stake_tests.rs, contracts/staking/src/tests/submit_batch_tests.rs, contracts/staking/src/tests/test_helper.rs, contracts/staking/src/tests/instantiate_tests.rs Restructured and updated tests to accommodate new configurations and updated dependencies.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant StakingContract
    participant Treasury

    User->>StakingContract: Instantiate with `send_fees_to_treasury`
    StakingContract->>StakingContract: Initialize configuration
    StakingContract->>Treasury: Send fees (if `send_fees_to_treasury` is true)
    User->>StakingContract: Execute transaction
    StakingContract->>StakingContract: Process transaction
    StakingContract->>Treasury: Send fees (if `send_fees_to_treasury` is true)
    User->>StakingContract: Query data
    StakingContract->>User: Return data
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@manu0466 manu0466 marked this pull request as draft May 29, 2024 10:40
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: 6

Outside diff range and nitpick comments (2)
README.md (2)

Line range hint 34-34: Specify the language for fenced code blocks to enhance readability.

- ```rust
+ ```bash

Line range hint 38-38: Specify the language for fenced code blocks to enhance readability.

- ```
+ ```bash
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between c3b00e4 and 16bd23e.
Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (19)
  • Cargo.toml (2 hunks)
  • README.md (1 hunks)
  • contracts/staking/Cargo.toml (1 hunks)
  • contracts/treasury/Cargo.toml (3 hunks)
  • contracts/treasury/README.md (1 hunks)
  • contracts/treasury/src/contract.rs (4 hunks)
  • contracts/treasury/src/error.rs (2 hunks)
  • contracts/treasury/src/execute.rs (4 hunks)
  • contracts/treasury/src/helpers.rs (1 hunks)
  • contracts/treasury/src/lib.rs (1 hunks)
  • contracts/treasury/src/msg.rs (2 hunks)
  • contracts/treasury/src/query.rs (1 hunks)
  • contracts/treasury/src/state.rs (2 hunks)
  • contracts/treasury/src/tests/mod.rs (1 hunks)
  • contracts/treasury/src/tests/ownership_tests.rs (1 hunks)
  • contracts/treasury/src/tests/send_tests.rs (1 hunks)
  • contracts/treasury/src/tests/swap_tests.rs (1 hunks)
  • contracts/treasury/src/tests/test_helper.rs (1 hunks)
  • contracts/treasury/src/tests/update_config_test.rs (1 hunks)
Files skipped from review due to trivial changes (5)
  • contracts/treasury/Cargo.toml
  • contracts/treasury/src/lib.rs
  • contracts/treasury/src/tests/mod.rs
  • contracts/treasury/src/tests/ownership_tests.rs
  • contracts/treasury/src/tests/send_tests.rs
Additional Context Used
Markdownlint (9)
README.md (2)

34: null
Fenced code blocks should have a language specified


38: null
Fenced code blocks should have a language specified

contracts/treasury/README.md (7)

40: null
Lists should be surrounded by blank lines


60: null
Lists should be surrounded by blank lines


69: null
Lists should be surrounded by blank lines


84: null
Lists should be surrounded by blank lines


100: null
Lists should be surrounded by blank lines


116: null
Lists should be surrounded by blank lines


133: null
Lists should be surrounded by blank lines

Additional comments not posted (22)
Cargo.toml (1)

17-26: Ensure all new dependencies are compatible with the project's existing ecosystem.

contracts/staking/Cargo.toml (1)

25-41: All dependencies have been updated to use workspace versions. This is a good practice to ensure consistency across the project.

contracts/treasury/src/tests/update_config_test.rs (2)

10-28: The test update_config_not_admin_fail correctly checks that only the admin can update the configuration. This is crucial for maintaining secure control over contract settings.


30-50: The test update_config effectively verifies the functionality of updating the trader and allowed swap routes. It's good to see comprehensive checks on the state after the operation.

contracts/treasury/src/tests/test_helper.rs (1)

10-45: The initialization function is well-structured and sets up the contract with a comprehensive set of parameters. This setup is crucial for ensuring that subsequent tests run under realistic conditions.

contracts/treasury/src/state.rs (2)

19-27: The SwapRoute and Config structs are well-defined with appropriate documentation. The use of vectors for allowed_swap_routes in Config provides flexibility in defining complex swap paths.

Also applies to: 29-35


39-63: The methods assert_trader and assert_allowed_swap_route are essential for enforcing contract rules and preventing unauthorized actions. The error handling is robust, ensuring that only valid operations proceed.

contracts/treasury/src/contract.rs (3)

Line range hint 27-63: The instantiate function is well-implemented, setting up the contract state and configuration correctly. The use of optional fields with defaults ensures flexibility in contract deployment.


86-99: The execution functions for swapping and updating configurations are correctly implemented. It's good to see detailed handling of different scenarios and input validations.


104-137: The query and migrate functions are correctly implemented. The migration logic includes version checks to prevent incorrect upgrades, which is a critical safety feature.

contracts/treasury/README.md (1)

3-172: The README is comprehensive and provides clear instructions for all operations related to the treasury contract. It's important that the documentation stays up-to-date with the contract's capabilities.

contracts/treasury/src/execute.rs (5)

107-113: Consider validating the address format before constructing the message.

This ensures that the address format is correct before proceeding with the transaction, potentially preventing failed transactions due to address format errors.


Line range hint 117-128: Ensure proper error handling for the IBC transfer scenario.

The comment mentions not using the IBC queue here and just reexecuting if this fails. It's crucial to handle potential failures in IBC transfers robustly, possibly by implementing a retry mechanism or logging the failure for manual intervention.


150-194: Ensure that the swap functionality adheres to the specified swap routes and token denominations.

This function performs a swap with a specified minimum output amount. It's important to verify that the swap routes and token denominations are correctly validated against the allowed configurations to prevent unauthorized swaps.


196-240: Review the logic for executing swaps with an exact amount out.

Similar to the previous function, this one needs thorough validation of swap routes and token denominations. Additionally, ensure that the logic for handling the maximum input amount is correctly implemented to prevent overspending.


242-266: Check the update configuration functionality for proper authorization and validation.

This function updates the trading configuration. It's crucial to ensure that only authorized users can update the configuration and that the input data is properly validated.

contracts/treasury/src/tests/swap_tests.rs (6)

20-48: Add more detailed assertions to the test for unauthorized swaps.

While the test checks for unauthorized access, it could be enhanced by adding more detailed assertions to verify that no state changes occur and no messages are sent when the swap is unauthorized.


50-61: Ensure comprehensive coverage for scenarios with empty swap routes.

This test checks the behavior when the swap routes are empty. Consider adding assertions to verify that no state changes or unintended actions occur in this scenario.


63-101: Validate the handling of unauthorized pools in swap operations.

This test covers scenarios where swaps are attempted with unauthorized pools. Ensure that the test adequately checks for all possible unauthorized access points and correctly handles them.


103-156: Check the validation logic for token denominations in swap operations.

This series of tests checks for mismatches in token denominations. Ensure that the tests comprehensively cover all edge cases and correctly assert the expected errors.


158-194: Review the tests for unauthorized token output denominations.

These tests should verify that the swap operation does not proceed with unauthorized output denominations. Ensure that the tests are comprehensive and correctly handle all scenarios.


196-543: Confirm that successful swap operations are correctly tested.

These tests verify successful swap operations. Ensure that they correctly simulate the swap process, check for the correct state changes, and validate that the expected messages are sent.

contracts/treasury/src/helpers.rs Outdated Show resolved Hide resolved
contracts/treasury/src/helpers.rs Outdated Show resolved Hide resolved
contracts/treasury/src/query.rs Outdated Show resolved Hide resolved
contracts/treasury/src/error.rs Outdated Show resolved Hide resolved
contracts/treasury/src/msg.rs Outdated Show resolved Hide resolved
contracts/staking/Cargo.toml Show resolved Hide resolved
@manu0466 manu0466 marked this pull request as ready for review May 31, 2024 11:58
@manu0466 manu0466 self-assigned this May 31, 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.

Actionable comments posted: 11

Outside diff range and nitpick comments (4)
contracts/staking/src/migrations/v0_4_19.rs (1)

Line range hint 41-61: Proper integration of send_fees_to_treasury in the migration logic.

Would you like me to help create a unit test to verify the migration logic?

contracts/staking/src/helpers.rs (1)

107-107: Clarify the purpose of allowing type complexity in paginate_map.

Consider adding a comment explaining why #[allow(clippy::type_complexity)] is necessary here, for future maintainers.

contracts/staking/src/contract.rs (1)

[!TIP]
Codebase Verification

The constants CELESTIA_ACCOUNT_PREFIX and OSMOSIS_ACCOUNT_PREFIX are defined but not used anywhere in the codebase. Please review if these constants are intended to be used or if they can be removed.

  • CELESTIA_ACCOUNT_PREFIX defined at contracts/staking/src/contract.rs:39
  • OSMOSIS_ACCOUNT_PREFIX defined at contracts/staking/src/contract.rs:40
Analysis chain

Line range hint 27-44: Ensure the constants are correctly defined and used throughout the contract.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct definition and usage of constants in the contract.

# Test: Search for the constants usage in the contract. Expect: Correct definitions and consistent usage.
rg --type rust $'CELESTIA_ACCOUNT_PREFIX|OSMOSIS_ACCOUNT_PREFIX|CELESTIA_VALIDATOR_PREFIX' contracts/staking/src/contract.rs

Length of output: 377



Script:

#!/bin/bash
# Description: Verify the usage of CELESTIA_ACCOUNT_PREFIX and OSMOSIS_ACCOUNT_PREFIX in the codebase.

# Test: Search for the constants usage in the entire codebase. Expect: Correct definitions and consistent usage.
rg --type rust $'CELESTIA_ACCOUNT_PREFIX|OSMOSIS_ACCOUNT_PREFIX'

Length of output: 236

contracts/staking/src/execute.rs (1)

57-57: Update the memo format to include more context if needed.

Consider including additional context or identifiers in the memo field to enhance traceability and debugging.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16bd23e and 22fef35.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (25)
  • contracts/staking/Cargo.toml (1 hunks)
  • contracts/staking/src/ack.rs (2 hunks)
  • contracts/staking/src/contract.rs (9 hunks)
  • contracts/staking/src/execute.rs (7 hunks)
  • contracts/staking/src/helpers.rs (7 hunks)
  • contracts/staking/src/migrations/v0_4_19.rs (2 hunks)
  • contracts/staking/src/msg.rs (4 hunks)
  • contracts/staking/src/query.rs (3 hunks)
  • contracts/staking/src/state.rs (1 hunks)
  • contracts/staking/src/tests/circuit_breaker_tests.rs (1 hunks)
  • contracts/staking/src/tests/ibc_transfer_tests.rs (1 hunks)
  • contracts/staking/src/tests/instantiate_tests.rs (6 hunks)
  • contracts/staking/src/tests/ownership_tests.rs (1 hunks)
  • contracts/staking/src/tests/query_tests.rs (1 hunks)
  • contracts/staking/src/tests/reward_tests.rs (1 hunks)
  • contracts/staking/src/tests/stake_tests.rs (4 hunks)
  • contracts/staking/src/tests/submit_batch_tests.rs (1 hunks)
  • contracts/staking/src/tests/test_helper.rs (1 hunks)
  • contracts/staking/src/tests/unstake_tests.rs (1 hunks)
  • contracts/staking/src/tests/validator_tests.rs (1 hunks)
  • contracts/staking/src/tests/withdraw_tests.rs (1 hunks)
  • contracts/treasury/src/error.rs (2 hunks)
  • contracts/treasury/src/helpers.rs (1 hunks)
  • contracts/treasury/src/msg.rs (2 hunks)
  • contracts/treasury/src/query.rs (1 hunks)
Files skipped from review due to trivial changes (5)
  • contracts/staking/src/tests/circuit_breaker_tests.rs
  • contracts/staking/src/tests/ownership_tests.rs
  • contracts/staking/src/tests/submit_batch_tests.rs
  • contracts/staking/src/tests/test_helper.rs
  • contracts/staking/src/tests/validator_tests.rs
Files skipped from review as they are similar to previous changes (5)
  • contracts/staking/Cargo.toml
  • contracts/treasury/src/error.rs
  • contracts/treasury/src/helpers.rs
  • contracts/treasury/src/msg.rs
  • contracts/treasury/src/query.rs
Additional comments not posted (30)
contracts/staking/src/ack.rs (1)

14-14: Change from to_binary to to_json_binary aligns with modern web standards.

contracts/staking/src/state.rs (1)

22-24: Clear documentation and appropriate integration of send_fees_to_treasury in the Config struct.

Verification successful

The send_fees_to_treasury field is consistently integrated and used across the codebase, including in query.rs, msg.rs, execute.rs, contract.rs, and various test files. This indicates proper handling and integration of the new field.

  • contracts/staking/src/query.rs: Properly includes send_fees_to_treasury.
  • contracts/staking/src/msg.rs: Defines and uses send_fees_to_treasury.
  • contracts/staking/src/execute.rs: Handles send_fees_to_treasury in execution logic.
  • contracts/staking/src/contract.rs: Integrates send_fees_to_treasury in contract logic.
  • Test files: Include tests for send_fees_to_treasury.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify usage of `send_fees_to_treasury` across the system.

# Test: Search for usage of `send_fees_to_treasury`. Expect: Proper handling in business logic.
rg --type rust $'send_fees_to_treasury'

Length of output: 2410

contracts/staking/src/tests/reward_tests.rs (1)

101-169: Effective testing of the receive_rewards_and_send_fees_to_treasury function, ensuring correct interaction with the treasury.

Verification successful

The extracted code from execute.rs confirms that the treasury_address and send_fees_to_treasury configurations are correctly handled. The logic ensures that if send_fees_to_treasury is set to true, the fees are transferred to the treasury address.

Key points:

  • The treasury_address is validated and set in the configuration.
  • The send_fees_to_treasury flag is checked, and if true, a BankMsg::Send message is created to transfer the fees to the treasury address.

This confirms that the integration with the treasury contract is correctly implemented.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of `receive_rewards_and_send_fees_to_treasury` with the treasury contract.

# Test: Search for usage of `receive_rewards_and_send_fees_to_treasury`. Expect: Proper handling of fees transfer.
rg --type rust $'receive_rewards_and_send_fees_to_treasury'

Length of output: 151



Script:

#!/bin/bash
# Description: Verify integration with the treasury contract by searching for references to the treasury address and related configurations.

# Search for references to the treasury address in the codebase.
rg --type rust 'treasury_address'

# Search for references to the `send_fees_to_treasury` configuration in the codebase.
rg --type rust 'send_fees_to_treasury'

Length of output: 4851



Script:

#!/bin/bash
# Description: Extract relevant code from `execute.rs` to verify handling of `treasury_address` and `send_fees_to_treasury`.

# Extract functions from `execute.rs` that handle `treasury_address` and `send_fees_to_treasury`.
rg --type rust --context 10 'treasury_address|send_fees_to_treasury' contracts/staking/src/execute.rs

Length of output: 4130

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

36-37: Proper addition of send_fees_to_treasury to InstantiateMsg for initial configuration.

Verification successful

The integration of send_fees_to_treasury in the instantiation logic and tests appears to be properly handled. Here are the relevant locations:

  • Instantiation Logic:

    • contracts/staking/src/contract.rs:
      • Line: send_fees_to_treasury: msg.send_fees_to_treasury
      • Line: Some(msg.send_fees_to_treasury)
      • Line: send_fees_to_treasury
      • Line: send_fees_to_treasury
      • Line: send_fees_to_treasury
      • Line: migrations::v0_4_19::migrate(deps.branch(), env, send_fees_to_treasury)?
  • Tests:

    • contracts/staking/src/tests/test_helper.rs:
      • Line: send_fees_to_treasury: true
    • contracts/staking/src/tests/reward_tests.rs:
      • Line: config.send_fees_to_treasury = false
      • Line: receive_rewards_and_send_fees_to_treasury
      • Line: config.send_fees_to_treasury = true
    • contracts/staking/src/tests/instantiate_tests.rs:
      • Line: send_fees_to_treasury: false
      • Line: send_fees_to_treasury: None
      • Line: send_fees_to_treasury: None
      • Line: send_fees_to_treasury: None
      • Line: send_fees_to_treasury: None

The changes ensure that the send_fees_to_treasury field is correctly integrated into the contract's instantiation logic and adequately tested.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify integration of `send_fees_to_treasury` in contract instantiation logic.

# Test: Search for instantiation calls. Expect: Proper handling of the new field.
rg --type rust $'InstantiateMsg'

Length of output: 1384



Script:

#!/bin/bash
# Description: Verify handling of `send_fees_to_treasury` in instantiation logic and tests.

# Test: Search for `send_fees_to_treasury` in contract instantiation logic.
rg --type rust 'send_fees_to_treasury' contracts/staking/src/contract.rs

# Test: Search for `send_fees_to_treasury` in instantiation tests.
rg --type rust 'send_fees_to_treasury' contracts/staking/src/tests

Length of output: 1229

contracts/staking/src/helpers.rs (1)

163-166: Ensure accuracy in financial calculations in get_rates.

Verify that the ratio calculations in get_rates function handle edge cases correctly, such as division by zero or extremely large values.

contracts/staking/src/tests/instantiate_tests.rs (2)

49-49: Validate the addition of send_fees_to_treasury in InstantiateMsg.

The addition of send_fees_to_treasury to InstantiateMsg aligns with the PR's objective to allow the staking contract to send fees to the treasury.


160-160: Ensure consistency in handling send_fees_to_treasury across different configurations.

Verify that the handling of send_fees_to_treasury is consistent and correctly implemented across various configurations in the update_config tests.

Also applies to: 200-200, 226-226

Verification successful

The gathered context shows that send_fees_to_treasury is used in various configurations across different test files. The values assigned to send_fees_to_treasury include true, false, and None, indicating different scenarios being tested.

Observations:

  • test_helper.rs: send_fees_to_treasury is set to true.
  • instantiate_tests.rs: send_fees_to_treasury is set to false and None in different instances.
  • reward_tests.rs: send_fees_to_treasury is toggled between true and false to test different behaviors.

Analysis:

The usage of send_fees_to_treasury appears to be consistent with the intention of testing various configurations. Each test case sets this parameter to different values to verify the behavior of the system under those conditions.

Conclusion:

The handling of send_fees_to_treasury is consistent and correctly implemented across the different configurations in the update_config tests.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistent handling of `send_fees_to_treasury`.

# Test: Search for all occurrences of `send_fees_to_treasury` in test cases.
# Expect: Consistent and correct implementation.
rg --type rust "send_fees_to_treasury" contracts/staking/src/tests/

Length of output: 866



Script:

#!/bin/bash
# Extract and display the relevant lines and surrounding context for `send_fees_to_treasury` in the identified files.

# Display lines around occurrences in test_helper.rs
rg --type rust --context 5 "send_fees_to_treasury" contracts/staking/src/tests/test_helper.rs

# Display lines around occurrences in instantiate_tests.rs
rg --type rust --context 5 "send_fees_to_treasury" contracts/staking/src/tests/instantiate_tests.rs

# Display lines around occurrences in reward_tests.rs
rg --type rust --context 5 "send_fees_to_treasury" contracts/staking/src/tests/reward_tests.rs

Length of output: 3778

contracts/staking/src/tests/withdraw_tests.rs (1)

1-10: Ensure correct imports and setup for withdrawal tests.

The setup and imports for the withdrawal tests are correctly configured, providing the necessary context and functionality for the tests.

contracts/staking/src/tests/query_tests.rs (1)

1-12: Check for necessary imports and setup in query tests.

The setup and imports for the query tests are correctly configured, ensuring that all dependencies are properly declared.

contracts/staking/src/tests/stake_tests.rs (3)

Line range hint 56-67: Ensure the MsgTransfer message construction is correct and aligns with the intended functionality.

Verification successful

The MsgTransfer construction in the proper_liquid_stake function appears to be correctly structured with the appropriate parameters. The MsgTransfer message includes the source_channel, source_port, sender, receiver, token, timeout_height, timeout_timestamp, and memo fields, which align with the expected structure.

  • source_channel: CHANNEL_ID.to_string()
  • source_port: "transfer".to_string()
  • sender: env.contract.address.to_string()
  • receiver: Addr::unchecked(CELESTIA1).to_string()
  • token: Some(ibc_coin)
  • timeout_height: None
  • timeout_timestamp: timeout.timestamp().unwrap().nanos()
  • memo: format!("{{\"ibc_callback\":\"{}\"}}", env.contract.address)

These parameters are consistent with the intended functionality of the MsgTransfer message.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct construction of `MsgTransfer` in the `proper_liquid_stake` test function.

# Test: Search for the `MsgTransfer` usage in the `proper_liquid_stake` function. Expect: Correct parameters and structure.
rg --type rust $'MsgTransfer' contracts/staking/src/tests/stake_tests.rs

Length of output: 227



Script:

#!/bin/bash
# Extract the full context of `MsgTransfer` usage in the `proper_liquid_stake` function.
# This will help verify the parameters and structure.

# Search for the `proper_liquid_stake` function definition and extract its body.
ast-grep --lang rust --pattern $'fn proper_liquid_stake($_) {
  $$$
}' contracts/staking/src/tests/stake_tests.rs

Length of output: 114



Script:

#!/bin/bash
# Extract the full context of `MsgTransfer` usage in the `proper_liquid_stake` function.
# This will help verify the parameters and structure.

# Search for the `proper_liquid_stake` function definition and extract its body.
rg 'fn proper_liquid_stake' -A 50 contracts/staking/src/tests/stake_tests.rs

Length of output: 2283


206-206: Verify the correct usage of derive_intermediate_sender function.

Verification successful

The derive_intermediate_sender function is defined as follows:

pub fn derive_intermediate_sender(
    channel_id: &str,
    original_sender: &str,
    bech32_prefix: &str,
) -> Result<String, bech32::Error> {
    use bech32::ToBase32;
    let sender_str = format!("{channel_id}/{original_sender}");
    let sender_hash_32 = addess_hash(SENDER_PREFIX, sender_str.as_bytes());
    let sender = sender_hash_32.to_base32();
    bech32::encode(bech32_prefix, sender, bech32::Variant::Bech32)
}

The usage of derive_intermediate_sender in the proper_ibc_liquid_stake test function:

derive_intermediate_sender(CHANNEL_ID, CELESTIA1, "osmo").unwrap();

is correct as it matches the function's parameters: channel_id, original_sender, and bech32_prefix.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage of `derive_intermediate_sender` function in the `proper_ibc_liquid_stake` test function.

# Test: Search for the `derive_intermediate_sender` usage in the `proper_ibc_liquid_stake` function. Expect: Correct parameters and structure.
rg --type rust $'derive_intermediate_sender' contracts/staking/src/tests/stake_tests.rs

Length of output: 280



Script:

#!/bin/bash
# Description: Locate the definition of the `derive_intermediate_sender` function to verify its correct usage.

# Search for the definition of `derive_intermediate_sender` in the codebase.
ast-grep --lang rust --pattern 'fn derive_intermediate_sender($_, $_, $_) { $$$ }'

Length of output: 84



Script:

#!/bin/bash
# Description: Locate the definition of the `derive_intermediate_sender` function to verify its correct usage.

# Search for the definition of `derive_intermediate_sender` in the codebase.
rg --type rust 'fn derive_intermediate_sender' 

Length of output: 116



Script:

#!/bin/bash
# Description: Display the definition of the `derive_intermediate_sender` function to verify its correct usage.

# Display the definition of `derive_intermediate_sender` in `contracts/staking/src/helpers.rs`.
rg --type rust -A 10 'fn derive_intermediate_sender' contracts/staking/src/helpers.rs

Length of output: 513


231-233: Ensure the derive_intermediate_sender function is correctly handling the reward_collector_address in the receive_rewards_before_minting test function.

Verification successful

The receive_rewards_before_minting function is present in the stake_tests.rs file and includes the handling of reward_collector_address. The function uses reward_collector_address as part of the derive_intermediate_sender function call.

  • Location: contracts/staking/src/tests/stake_tests.rs, lines 231-233

The handling of reward_collector_address appears to be correctly integrated within the receive_rewards_before_minting function.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of `reward_collector_address` in the `receive_rewards_before_minting` test function.

# Test: Search for the `reward_collector_address` usage in the `receive_rewards_before_minting` function. Expect: Correct handling and structure.
rg --type rust $'reward_collector_address' contracts/staking/src/tests/stake_tests.rs

Length of output: 136



Script:

#!/bin/bash
# Locate the `receive_rewards_before_minting` function and inspect its implementation.

# Search for the definition of the `receive_rewards_before_minting` function in the `stake_tests.rs` file.
ast-grep --lang rust --pattern 'fn receive_rewards_before_minting($_) { $$$ }' contracts/staking/src/tests/stake_tests.rs

Length of output: 123



Script:

#!/bin/bash
# List all function definitions in the `stake_tests.rs` file to identify the correct function.

# Search for all function definitions in the `stake_tests.rs` file.
ast-grep --lang rust --pattern 'fn $_($_) { $$$ }' contracts/staking/src/tests/stake_tests.rs

Length of output: 95



Script:

#!/bin/bash
# Verify the existence of the `stake_tests.rs` file and list its content.

# Check if the `stake_tests.rs` file exists and list its content.
if [ -f contracts/staking/src/tests/stake_tests.rs ]; then
  cat contracts/staking/src/tests/stake_tests.rs
else
  echo "File not found: contracts/staking/src/tests/stake_tests.rs"
fi

Length of output: 11846

contracts/staking/src/contract.rs (4)

324-326: Ensure the migration logic in MigrateMsg::V0_4_18ToV0_4_19 correctly handles the send_fees_to_treasury parameter.

Verification successful

The send_fees_to_treasury parameter is correctly handled in the migration logic. It is passed to the migrate function and used to set the send_fees_to_treasury field in the new configuration, which is then saved.

  • contracts/staking/src/migrations/v0_4_19.rs:61: The send_fees_to_treasury parameter is assigned to the corresponding field in the new configuration.
  • contracts/staking/src/migrations/v0_4_19.rs:64: The new configuration, including the send_fees_to_treasury field, is saved.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of `send_fees_to_treasury` in the migration logic.

# Test: Search for the `send_fees_to_treasury` usage in the migration logic. Expect: Correct handling and structure.
rg --type rust $'send_fees_to_treasury' contracts/staking/src/contract.rs

Length of output: 363



Script:

#!/bin/bash
# Description: Verify the correct handling of `send_fees_to_treasury` in the migration logic.

# Test: Search for the `send_fees_to_treasury` usage in the migration logic file.
rg --type rust 'send_fees_to_treasury' $(fd migrate | grep 'migrations/v0_4_19')

Length of output: 2451



Script:

#!/bin/bash
# Description: Extract the `migrate` function implementation to verify the handling of `send_fees_to_treasury`.

# Test: Extract the `migrate` function from the migration logic file.
ast-grep --lang rust --pattern 'pub fn migrate($_, $_, $_) -> $_ { $$$ }' contracts/staking/src/migrations/v0_4_19.rs

Length of output: 2917


Line range hint 98-117: Verify the correct handling of send_fees_to_treasury in the instantiate function.

Verification successful

The instantiate and migrate functions have been identified, but the extracted code does not provide enough context to verify the handling of send_fees_to_treasury. We need to extract more lines from these functions to ensure we capture the relevant logic.


The extracted code from the instantiate and migrate functions shows that send_fees_to_treasury is correctly handled in both functions. In the instantiate function, it is assigned to the config struct, and in the migrate function, it is passed to the migration logic.

  • In the instantiate function, send_fees_to_treasury is set as part of the Config struct.
  • In the migrate function, send_fees_to_treasury is passed to the migrations::v0_4_19::migrate function.

This confirms that send_fees_to_treasury is correctly handled in the instantiate function and related migration logic.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of `send_fees_to_treasury` in the `instantiate` function.

# Test: Search for the `send_fees_to_treasury` usage in the `instantiate` function. Expect: Correct handling and structure.
rg --type rust $'send_fees_to_treasury' contracts/staking/src/contract.rs

Length of output: 363



Script:

#!/bin/bash
# Extract the `instantiate` function and related context to verify the handling of `send_fees_to_treasury`.

# Extract the `instantiate` function
ast-grep --lang rust --pattern 'fn instantiate($_, $_, $_) -> $_ {
  $$$
}' contracts/staking/src/contract.rs

# Extract the migration function related to `send_fees_to_treasury`
ast-grep --lang rust --pattern 'fn migrate($_, $_, $_) -> $_ {
  $$$
}' contracts/staking/src/contract.rs

Length of output: 219



Script:

#!/bin/bash
# Adjusted patterns to extract the `instantiate` function and related context to verify the handling of `send_fees_to_treasury`.

# Extract the `instantiate` function with a more flexible pattern
ast-grep --lang rust --pattern 'fn instantiate($_) -> $_ {
  $$$
}' contracts/staking/src/contract.rs

# Extract the migration function related to `send_fees_to_treasury` with a more flexible pattern
ast-grep --lang rust --pattern 'fn migrate($_) -> $_ {
  $$$
}' contracts/staking/src/contract.rs

Length of output: 203



Script:

#!/bin/bash
# Use `rg` to search for the `instantiate` and migration function definitions and extract the relevant code.

# Search for the `instantiate` function definition
rg --type rust 'fn instantiate' contracts/staking/src/contract.rs -A 20

# Search for the migration function definition related to `send_fees_to_treasury`
rg --type rust 'fn migrate' contracts/staking/src/contract.rs -A 20

Length of output: 1787



Script:

#!/bin/bash
# Extract more lines from the `instantiate` and `migrate` functions to verify the handling of `send_fees_to_treasury`.

# Extract more lines from the `instantiate` function
rg --type rust 'fn instantiate' contracts/staking/src/contract.rs -A 50

# Extract more lines from the migration function related to `send_fees_to_treasury`
rg --type rust 'fn migrate' contracts/staking/src/contract.rs -A 50

Length of output: 3728


264-290: Verify the correct implementation of query functions and their alignment with the contract's functionality.

Verification successful

The implementations of the query functions have been successfully extracted and reviewed. They appear to be correctly implemented and aligned with the contract's functionality.

  • query_config: Retrieves and formats the contract's configuration.
  • query_state: Retrieves and formats the contract's state.
  • query_batch: Retrieves a specific batch by ID.
  • query_batches: Retrieves batches with optional filtering by status.
  • query_batches_by_ids: Retrieves batches by a list of IDs.
  • query_pending_batch: Retrieves the pending batch.
  • query_unstake_requests: Retrieves unstake requests for a specific user.
  • query_all_unstake_requests: Retrieves all unstake requests.
  • query_all_unstake_requests_v2: Retrieves all unstake requests in a different format.
  • query_ibc_queue: Retrieves the IBC queue.
  • query_reply_queue: Retrieves the IBC reply queue.

These functions are implemented in contracts/staking/src/query.rs and appear to be functioning as intended.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation of query functions in the contract.

# Test: Search for the query functions usage in the contract. Expect: Correct implementation and alignment with contract functionality.
rg --type rust $'query_config|query_state|query_batch|query_batches|query_batches_by_ids|query_pending_batch|query_unstake_requests|query_all_unstake_requests|query_all_unstake_requests_v2|query_ibc_queue|query_reply_queue' contracts/staking/src/contract.rs

Length of output: 1347



Script:

#!/bin/bash
# Description: Locate the definitions of query functions in the codebase.

# Search for the definitions of each query function.
ast-grep --lang rust --pattern 'fn query_config($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_state($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_batch($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_batches($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_batches_by_ids($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_pending_batch($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_unstake_requests($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_all_unstake_requests($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_all_unstake_requests_v2($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_ibc_queue($_) { $$$ }'
ast-grep --lang rust --pattern 'fn query_reply_queue($_) { $$$ }'

Length of output: 755



Script:

#!/bin/bash
# Description: Locate the definitions of query functions in the codebase by searching for function names directly.

# Search for the definitions of each query function.
rg --type rust 'fn query_config'
rg --type rust 'fn query_state'
rg --type rust 'fn query_batch'
rg --type rust 'fn query_batches'
rg --type rust 'fn query_batches_by_ids'
rg --type rust 'fn query_pending_batch'
rg --type rust 'fn query_unstake_requests'
rg --type rust 'fn query_all_unstake_requests'
rg --type rust 'fn query_all_unstake_requests_v2'
rg --type rust 'fn query_ibc_queue'
rg --type rust 'fn query_reply_queue'

Length of output: 1833



Script:

#!/bin/bash
# Description: Extract the implementations of query functions from the identified files.

# Extract the implementations of each query function.
rg --type rust -A 20 'pub fn query_config' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_state' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_batch' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_batches' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_batches_by_ids' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_pending_batch' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_unstake_requests' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_all_unstake_requests' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_all_unstake_requests_v2' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_ibc_queue' contracts/staking/src/query.rs
rg --type rust -A 20 'pub fn query_reply_queue' contracts/staking/src/query.rs

Length of output: 9803


Line range hint 209-224: Ensure the update_config function correctly handles the send_fees_to_treasury parameter.

Verification successful

The update_config function in contracts/staking/src/execute.rs correctly handles the send_fees_to_treasury parameter by updating the config.send_fees_to_treasury field if the parameter is provided.

  • contracts/staking/src/execute.rs, lines 206-212: The send_fees_to_treasury parameter is correctly handled within the update_config function.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of `send_fees_to_treasury` in the `update_config` function.

# Test: Search for the `send_fees_to_treasury` usage in the `update_config` function. Expect: Correct handling and structure.
rg --type rust $'send_fees_to_treasury' contracts/staking/src/contract.rs

Length of output: 363



Script:

#!/bin/bash
# Extract the `update_config` function to inspect the handling of `send_fees_to_treasury`.
ast-grep --lang rust --pattern 'fn update_config($_) {
  $$$
}' contracts/staking/src/contract.rs

Length of output: 99



Script:

#!/bin/bash
# Refine the pattern to match the `update_config` function more accurately.
ast-grep --lang rust --pattern 'fn update_config($$$) {
  $$$
}' contracts/staking/src/contract.rs

Length of output: 100



Script:

#!/bin/bash
# Locate the `update_config` function definition and inspect the handling of `send_fees_to_treasury`.
rg 'fn update_config' contracts/staking/src/contract.rs -A 20

Length of output: 63



Script:

#!/bin/bash
# Search for the `update_config` function definition across the entire repository.
rg 'fn update_config' -t rust

Length of output: 319



Script:

#!/bin/bash
# Extract the `update_config` function from `contracts/staking/src/execute.rs` to inspect the handling of `send_fees_to_treasury`.
ast-grep --lang rust --pattern 'pub fn update_config($$$) {
  $$$
}' contracts/staking/src/execute.rs

Length of output: 103



Script:

#!/bin/bash
# Locate the `update_config` function definition in `contracts/staking/src/execute.rs` and inspect the handling of `send_fees_to_treasury`.
rg 'fn update_config' contracts/staking/src/execute.rs -A 50

Length of output: 2128

contracts/staking/src/tests/unstake_tests.rs (6)

59-130: The test double_liquid_unstake effectively checks the scenario where a user unstakes multiple times before a batch is submitted. It's crucial to verify that the state updates correctly after each unstake operation and that the batch totals reflect all unstake requests accurately.


171-187: The test invalid_denom_liquid_unstake is designed to verify that the contract correctly handles attempts to unstake with an invalid denomination. This is a good practice as it ensures robust error handling in the contract.


242-298: The test invalid_amount_liquid_unstake should verify that the contract handles cases where the unstake amount is greater than the total liquid stake tokens. This test is crucial for ensuring that the contract does not allow unauthorized token creation or manipulation.


300-356: The test total_liquid_stake_token_with_zero checks the behavior when the total liquid stake token is zero. This is an important edge case to test, ensuring that the contract behaves correctly under such conditions.


358-440: The test claimable_batches verifies the functionality related to querying and receiving tokens for claimable batches. It's essential to ensure that the test covers scenarios where multiple batches are claimable and that the contract handles each correctly.


18-57: The test proper_liquid_unstake appears to be well-structured and covers the basic functionality of liquid unstaking. However, it's important to ensure that the test checks for the correct handling of edge cases, such as when the unstake amount exceeds the available tokens.

Verification successful

The proper_liquid_unstake test is complemented by other tests such as invalid_denom_liquid_unstake and invalid_amount_liquid_unstake, which handle important edge cases. Therefore, the edge cases are adequately covered in the test suite.

  • invalid_denom_liquid_unstake: Tests the scenario where the unstake denomination is invalid.
  • invalid_amount_liquid_unstake: Tests the scenario where the unstake amount is invalid.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `proper_liquid_unstake` test handles edge cases properly.

# Test: Search for additional tests handling edge cases.
rg --type rust $'fn proper_liquid_unstake' contracts/staking/src/tests/

Length of output: 146



Script:

#!/bin/bash
# Description: List all test functions in the `unstake_tests.rs` file to check for edge cases.

# List all test functions in the file.
rg --type rust --pcre2 --only-matching --no-line-number --no-filename '^fn \w+' contracts/staking/src/tests/unstake_tests.rs

Length of output: 327



Script:

#!/bin/bash
# Description: Extract the implementations of `invalid_denom_liquid_unstake` and `invalid_amount_liquid_unstake` functions to review edge case handling.

# Extract the `invalid_denom_liquid_unstake` function implementation.
rg --type rust --context 10 'fn invalid_denom_liquid_unstake' contracts/staking/src/tests/unstake_tests.rs

# Extract the `invalid_amount_liquid_unstake` function implementation.
rg --type rust --context 10 'fn invalid_amount_liquid_unstake' contracts/staking/src/tests/unstake_tests.rs

Length of output: 1490

contracts/staking/src/tests/ibc_transfer_tests.rs (7)

160-238: The test fail_ibc_queue checks the behavior of the IBC transfer mechanism when the acknowledgment fails. This is crucial for ensuring that the contract can handle failures gracefully and correctly revert or adjust the state as necessary.


240-316: The test timeout_ibc_queue is designed to verify the contract's behavior when an IBC transfer times out. Testing timeout scenarios is essential for ensuring that the contract can handle network delays or disruptions correctly.


318-345: The test recover_non_paginated checks the recovery mechanism for non-paginated IBC transfers. It's important to verify that the recovery process correctly handles all packets, regardless of their status.


347-374: The test recover_paginated verifies the recovery process for paginated IBC transfers. Ensuring that pagination is handled correctly is crucial for the scalability and performance of the contract.


376-407: The test recover_forced explores the forced recovery of selected IBC packets. This test is important for verifying that the contract can selectively recover packets based on specific criteria or conditions.


409-529: The test recover_multiple and recover_recursive are designed to test the recovery mechanisms for multiple and recursive IBC transfers. These tests are crucial for ensuring that the contract can handle complex scenarios where multiple transfers need recovery.


16-158: The test success_ibc_queue effectively simulates a successful IBC queue operation, including the creation of an IBC transfer message and handling the reply. It's important to ensure that the test covers all aspects of the IBC lifecycle, including timeouts and error handling.

Verification successful

The ibc_transfer_tests.rs file contains tests that cover various aspects of the IBC lifecycle, including error handling and timeouts. Specifically:

  • fail_ibc_queue covers scenarios where the IBC transfer fails.
  • timeout_ibc_queue covers scenarios where the IBC transfer times out.

These tests, along with success_ibc_queue, ensure comprehensive coverage of the IBC lifecycle, including success, failure, and timeout scenarios.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all aspects of the IBC lifecycle are covered in `success_ibc_queue`.

# Test: Search for tests covering timeouts and error handling in IBC lifecycle.
rg --type rust $'IBC_TIMEOUT' contracts/staking/src/tests/ibc_transfer_tests.rs

Length of output: 267



Script:

#!/bin/bash
# Description: Search for other tests in the file that might cover error handling and timeouts.

# Test: Search for test functions in the file.
rg --type rust '#\[test\]' contracts/staking/src/tests/ibc_transfer_tests.rs

# Test: Search for error handling in the file.
rg --type rust 'Err\(' contracts/staking/src/tests/ibc_transfer_tests.rs

Length of output: 277



Script:

#!/bin/bash
# Description: Extract the names of the test functions and the context around the error handling instances.

# Extract the names of the test functions.
rg --type rust --context 1 '#\[test\]' contracts/staking/src/tests/ibc_transfer_tests.rs

# Extract the context around the error handling instances.
rg --type rust --context 5 'Err\(' contracts/staking/src/tests/ibc_transfer_tests.rs

Length of output: 1202



Script:

#!/bin/bash
# Description: Extract the implementations of `fail_ibc_queue` and `timeout_ibc_queue` tests.

# Extract the implementation of `fail_ibc_queue`.
rg --type rust --context 50 'fn fail_ibc_queue' contracts/staking/src/tests/ibc_transfer_tests.rs

# Extract the implementation of `timeout_ibc_queue`.
rg --type rust --context 50 'fn timeout_ibc_queue' contracts/staking/src/tests/ibc_transfer_tests.rs

Length of output: 6230

contracts/staking/src/execute.rs (1)

Line range hint 687-702: Ensure consistent handling of optional parameters in update_config.

Also applies to: 731-733

Verification successful

The calls to update_config in contracts/staking/src/contract.rs handle optional parameters by passing Some values explicitly. This ensures that the optional parameters are consistently handled.

  • contracts/staking/src/contract.rs, line 20: update_config is called with Some values for all optional parameters.
  • contracts/staking/src/contract.rs, line 40: update_config is called with variables that are likely to be Option types, ensuring proper handling of optional parameters.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all calls to `update_config` correctly handle optional parameters.

# Test: Search for the function usage. Expect: Proper handling of None values for optional parameters.
rg --type rust $'update_config'

Length of output: 1369



Script:

#!/bin/bash
# Extract and inspect calls to `update_config` in the relevant files.

# Search for calls to `update_config` in `contracts/staking/src/contract.rs` and `contracts/staking/src/execute.rs`
rg --type rust 'update_config' contracts/staking/src/contract.rs contracts/staking/src/execute.rs

Length of output: 469



Script:

#!/bin/bash
# Extract relevant lines around the calls to `update_config` in `contracts/staking/src/contract.rs`.

# Extract 10 lines before and after each call to `update_config` for context.
rg --type rust 'update_config' -A 10 -B 10 contracts/staking/src/contract.rs

Length of output: 1916

contracts/staking/src/execute.rs Outdated Show resolved Hide resolved
contracts/staking/src/execute.rs Show resolved Hide resolved
contracts/staking/src/execute.rs Show resolved Hide resolved
contracts/staking/src/helpers.rs Outdated Show resolved Hide resolved
contracts/staking/src/helpers.rs Show resolved Hide resolved
contracts/staking/src/ack.rs Outdated Show resolved Hide resolved
contracts/staking/src/tests/reward_tests.rs Show resolved Hide resolved
contracts/staking/src/msg.rs Show resolved Hide resolved
contracts/staking/src/msg.rs Show resolved Hide resolved
contracts/staking/src/query.rs Show resolved Hide resolved
@manu0466 manu0466 force-pushed the manuel/update-treasury-contract branch from e134a60 to 9e3b2cd Compare June 3, 2024 08:00
@manu0466 manu0466 force-pushed the manuel/update-treasury-contract branch from 9e3b2cd to aeae749 Compare June 3, 2024 08:03
@manu0466 manu0466 requested a review from rustcandy June 3, 2024 23:41
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 and nitpick comments (1)
contracts/staking/src/migrations/v0_4_20.rs (1)

[!TIP]
Codebase Verification

The send_fees_to_treasury field is missing from the Config struct definition in state.rs. The migration function in v0_4_20.rs attempts to set this field, but it is not present in the struct definition. To resolve this, you need to update the Config struct to include the send_fees_to_treasury field and ensure the migration function correctly sets this field.

  • Update the Config struct in contracts/staking/src/state.rs to include the send_fees_to_treasury field.
  • Ensure the migration function in contracts/staking/src/migrations/v0_4_20.rs correctly sets this field during migration.
Analysis chain

Line range hint 41-61: Ensure proper testing of the migration logic.


The output indicates that the send_fees_to_treasury field is not present in the Config struct after the migration. This suggests that the migration logic might not be correctly updating the struct. To verify this, we need to check the definition of the Config struct and ensure that the send_fees_to_treasury field is included and correctly set during migration.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the migration logic by checking the state before and after migration.

# Test: Check the state before and after migration. Expect: The new field should be present and correctly set after migration.
# Fetch the contract state before migration
echo "State before migration:"
cat contracts/staking/src/state.rs | grep -A 10 "pub struct Config"

# Perform the migration
echo "Performing migration..."
# Simulate migration command here (pseudo-command)
echo "migrate --send_fees_to_treasury true"

# Fetch the contract state after migration
echo "State after migration:"
cat contracts/staking/src/state.rs | grep -A 10 "pub struct Config"

Length of output: 1203



Script:

#!/bin/bash
# Verify the presence of the `send_fees_to_treasury` field in the `Config` struct definition.

# Check the definition of the `Config` struct in the state file.
echo "Checking Config struct definition:"
cat contracts/staking/src/state.rs | grep -A 15 "pub struct Config"

# Check the migration function to ensure it updates the `send_fees_to_treasury` field.
echo "Checking migration function:"
cat contracts/staking/src/migrations/v0_4_20.rs | grep -A 20 "pub fn migrate"

Length of output: 2019

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 22fef35 and 1d56854.

Files selected for processing (8)
  • contracts/staking/src/ack.rs (2 hunks)
  • contracts/staking/src/contract.rs (9 hunks)
  • contracts/staking/src/execute.rs (7 hunks)
  • contracts/staking/src/helpers.rs (7 hunks)
  • contracts/staking/src/migrations/mod.rs (1 hunks)
  • contracts/staking/src/migrations/v0_4_20.rs (2 hunks)
  • contracts/staking/src/msg.rs (4 hunks)
  • contracts/staking/src/tests/instantiate_tests.rs (8 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/staking/src/migrations/mod.rs
Files skipped from review as they are similar to previous changes (6)
  • contracts/staking/src/ack.rs
  • contracts/staking/src/contract.rs
  • contracts/staking/src/execute.rs
  • contracts/staking/src/helpers.rs
  • contracts/staking/src/msg.rs
  • contracts/staking/src/tests/instantiate_tests.rs

Copy link
Contributor

@hallazzang hallazzang left a comment

Choose a reason for hiding this comment

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

Overall looks good to me.

contracts/staking/src/msg.rs Show resolved Hide resolved
Copy link
Contributor

@rustcandy rustcandy left a comment

Choose a reason for hiding this comment

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

LGTM

@manu0466 manu0466 requested a review from hallazzang June 5, 2024 07:34
Copy link
Contributor

@hallazzang hallazzang left a comment

Choose a reason for hiding this comment

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

LGTM!

@RiccardoM RiccardoM merged commit 7a61644 into main Jun 11, 2024
1 check passed
@RiccardoM RiccardoM deleted the manuel/update-treasury-contract branch June 11, 2024 14:13
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.

4 participants