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: curve ADO #515

Merged

Conversation

mdjakovic0920
Copy link
Contributor

@mdjakovic0920 mdjakovic0920 commented Jul 15, 2024

Motivation

The purpose of this ADO is to move a value along a specified curve like exponential curve.
So 0 to 1 on the X axis, and then Y axis will follow a growth or decay curve.
First, user have to configure the exponential.
Then, user can query the value of Y from value of X.

Implementation

Instantiate

#[andr_instantiate]
#[cw_serde]
pub struct InstantiateMsg {
    pub curve_config: CurveConfig,
    pub restriction: CurveRestriction,
}

impl CurveConfig {
    pub fn validate(&self) -> Result<(), ContractError> {
        match self {
            CurveConfig::ExpConfig {
                curve_id: _,
                base_value,
                multiple_variable_value: _,
                constant_value: _,
            } => {
                ensure!(
                    *base_value != 0,
                    ContractError::CustomError {
                        msg: "Base Value must be bigger than Zero".to_string()
                    }
                );
            }
        }
        Ok(())
    }
}

Execute

#[andr_exec]
#[cw_serde]
pub enum ExecuteMsg {
    UpdateCurveConfig { curve_config: CurveConfig },
    UpdateRestriction { restriction: CurveRestriction },
    Reset {},
}

Query

#[andr_query]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(GetCurveConfigResponse)]
    GetCurveConfig {},
    #[returns(GetRestrictionResponse)]
    GetRestriction {},
    #[returns(GetPlotYFromXResponse)]
    GetPlotYFromX { x_value: f64 },
}

Testing

Unit-test is added.

Version Changes

The version of ADO is set as 1.0.0

Notes

Just added exponential curve first.

Future work

Will add other curves like linear, power function and so on.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced the Validator Staking ADO and new enums for asset management.
    • Added multiple ADOs, including Curve ADO, String Storage ADO, and Date Time ADO.
    • Enhanced marketplace features with authorized CW721 addresses and a BuyNow option for auctions.
    • Implemented curve configuration management within the Andromeda ecosystem.
  • Bug Fixes

    • Resolved issues related to lock time calculations and precision in vesting claims.
  • Testing

    • Implemented a comprehensive suite of unit tests for the Curve module, ensuring functionality and validation.
  • Documentation

    • Updated CHANGELOG.md with details on new features and enhancements.

Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

The changes introduce several new features and components to the Andromeda system, as documented in the CHANGELOG.md. Key additions include the Validator Staking ADO, various new ADOs such as Curve ADO and String Storage ADO, and enhancements to the marketplace. The curve.rs file implements a framework for managing curve configurations, while the lib.rs file adds a public module for improved access. The Cargo.toml file has also been updated to include a new dependency.

Changes

File(s) Change Summary
CHANGELOG.md Updated to document new features like Validator Staking ADO, various ADOs, and marketplace enhancements.
packages/andromeda-modules/src/curve.rs Implemented a framework for managing curve configurations with enums and message structures.
packages/andromeda-modules/src/lib.rs Added a new public module named curve to enhance library functionality.
contracts/modules/andromeda-curve/src/contract.rs Introduced a smart contract for managing curve configurations, including instantiation, execution, and querying functionalities.
Cargo.toml Added new dependency test-case = { version = "3.3.1" } and commented out removed workspace members.

Possibly related PRs

Suggested labels

ci: skip-changelog

Suggested reviewers

  • joemonem
  • crnbarr93
  • cowboy0015

Poem

Burrows deep in code so fine,
Curves and lines in perfect line.
Modules crafted with such care,
Testing mocks and states to share.
Andromeda’s curves now dance and play,
In Rust’s embrace, they find their way.
🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73c76db and 7c5d2f2.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (12)
  • contracts/modules/andromeda-curve/.cargo/config (1 hunks)
  • contracts/modules/andromeda-curve/Cargo.toml (1 hunks)
  • contracts/modules/andromeda-curve/examples/schema.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/lib.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/mock.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/state.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/mock.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/mod.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/curve.rs (1 hunks)
  • packages/andromeda-modules/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (3)
  • contracts/modules/andromeda-curve/.cargo/config
  • contracts/modules/andromeda-curve/src/testing/mod.rs
  • packages/andromeda-modules/src/lib.rs
Additional comments not posted (14)
contracts/modules/andromeda-curve/src/lib.rs (1)

1-7: Modular structure and conditional compilation are well-implemented.

The organization into separate modules (contract, state, testing, mock) enhances maintainability and clarity. The use of conditional compilation (#[cfg] attributes) to include modules based on the build target and features is correctly applied, ensuring that test and mock functionalities are segregated from production code.

contracts/modules/andromeda-curve/examples/schema.rs (1)

1-10: Correct use of write_api! for schema generation.

The write_api! macro is appropriately used to generate schema files for the contract's messages (InstantiateMsg, QueryMsg, ExecuteMsg). This is crucial for interfacing with external clients and ensuring that the contract's API is well-documented and accessible.

contracts/modules/andromeda-curve/src/state.rs (1)

1-16: State management setup is appropriate, but verify default values.

The use of cw_storage_plus::Item for defining storage constants (CURVE_TYPE, CURVE_ID, etc.) is standard and well-implemented. The naming and organization of these constants are clear and maintainable.

However, the default values for MULTIPLE_VARIABLE_VALUE and CONSTANT_VALUE are set to 1. It's important to verify that these defaults are suitable for all intended use cases of the curve functionalities.

contracts/modules/andromeda-curve/Cargo.toml (1)

1-32: Package configuration and dependency management are well-handled.

The Cargo.toml file is well-configured with clear definitions for package metadata (name, version, edition), dependencies, and features. The use of workspace dependencies (cosmwasm-std, andromeda-modules, etc.) is particularly notable, as it helps manage multiple related packages efficiently and ensures consistency across the workspace.

The conditional dependencies (cw-multi-test, andromeda-testing) are appropriately set to be optional and only included when not targeting wasm32, which is a good practice for managing build-specific requirements.

packages/andromeda-modules/src/curve.rs (2)

4-60: Review of Enums and Structs for Curve Operations

The enums CurveType, CurveRestriction, and CurveId, along with the structs InstantiateMsg, ExecuteMsg, and QueryMsg, are well-defined and align with the PR's objectives to handle curve operations. The use of cw_serde for serialization and andr_* attributes for Andromeda-specific operations are correctly applied.

  • CurveType: Defines the type of curve, currently only Exponential.
  • CurveRestriction: Indicates whether a curve is Private or Public.
  • CurveId: Identifies the curve as either Growth or Decay.

The struct definitions for message passing (InstantiateMsg, ExecuteMsg, QueryMsg) are properly annotated and structured for clarity and functionality.


62-83: Review of Response Structs

The response structs GetCurveTypeResponse, GetConfigurationExpResponse, GetPlotYFromXResponse, and GetRestrictionResponse are well-defined. Each struct is equipped with appropriate fields that match the expected responses for curve-related queries.

  • GetCurveTypeResponse: Returns the curve_type.
  • GetConfigurationExpResponse: Includes all parameters relevant to the exponential configuration.
  • GetPlotYFromXResponse: Provides the calculated y_value from a given x_value.
  • GetRestrictionResponse: Returns the current restriction setting.

These structs are crucial for the functionality of querying the curve system and are implemented correctly according to the PR’s description.

contracts/modules/andromeda-curve/src/testing/tests.rs (1)

11-102: Review of Unit Tests for Curve Functionalities

The unit tests provided cover various functionalities such as instantiation, updating curve types and restrictions, configuring exponential values, and querying. Each test is properly isolated and uses mock dependencies for controlled testing environments.

  • Test Instantiation: Checks proper initialization with given curve type and restriction.
  • Test Update Restriction: Validates the update functionality for restrictions and handles unauthorized attempts correctly.
  • Test Configure Exponential: Ensures that exponential curve parameters can be set and queried accurately.
  • Test Reset: Verifies that the reset functionality clears configurations as expected.
  • Test Query Functions: Each query-related test checks the correctness of the response based on the curve configurations.

These tests appear to be comprehensive and effectively validate the critical functionalities of the curve management system.

contracts/modules/andromeda-curve/src/testing/mock.rs (1)

16-115: Review of Mock Functions for Curve Functionalities

The mock functions provided facilitate the testing of curve functionalities by simulating various operations such as instantiation, execution, and querying. These functions use mock dependencies and environments to ensure isolated and controlled testing conditions.

  • Mock Initialization: Correctly sets up a curve instance with specified parameters.
  • Mock Execution Functions: Each function (update_curve_type, update_restriction, configure_exponential, reset) correctly simulates the corresponding execution message.
  • Mock Query Functions: Each function provides a simulated response for the associated query, ensuring that the mock responses are consistent with expected results.

These mock implementations are crucial for unit testing and are implemented correctly to support comprehensive testing of the curve functionalities.

contracts/modules/andromeda-curve/src/mock.rs (1)

17-165: Review of Additional Mock Implementations for Curve Functionalities

This file extends the mock functionalities for curve operations, providing a comprehensive set of tools for testing various aspects of the curve system. The implementations are well-structured and align with the testing objectives.

  • MockCurve Structure: Facilitates the instantiation and execution of curve-related operations in a controlled testing environment.
  • Mock Functions: Each function is designed to simulate specific operations such as updating curve types, updating restrictions, configuring exponential parameters, and resetting configurations.
  • Query Functions: Simulate the querying of curve configurations and ensure that the responses are consistent with the expected outputs.

These additional mock implementations are well-crafted and provide the necessary infrastructure for thorough testing of the curve functionalities.

contracts/modules/andromeda-curve/src/contract.rs (5)

26-52: Review of the instantiate function

The function correctly initializes the contract with default values and saves the initial configuration provided in the InstantiateMsg. The use of ADOContract::default().instantiate ensures that the contract instantiation adheres to the standard contract lifecycle.

Considerations:

  • Ensure that msg.kernel_address and msg.owner are validated or handled appropriately elsewhere to avoid unauthorized access.
  • It's good practice to log the instantiation parameters for audit purposes.

54-68: Review of the execute function

This function routes different ExecuteMsg variants to their respective handlers. The use of pattern matching in Rust is appropriate and ensures that each message type is handled correctly.

Considerations:

  • Ensure that handle_execute function is robust and handles all possible ExecuteMsg variants as expected.
  • The use of ADOContract::default().execute_amp_receive for AMPReceive messages should be verified to ensure it integrates well with the Andromeda messaging system.

129-164: Review of execute_configure_exponential function

This function configures exponential curve parameters. It handles optional parameters well by providing default values if they are not specified.

Considerations:

  • The function does a good job of ensuring that the sender has the necessary permissions before proceeding with the configuration.
  • It might be beneficial to separate the logic for saving default values into a helper function for clarity and potential reuse.

204-269: Review of the query function and related helpers

The query function and its helpers effectively retrieve stored data and ensure that conditions are met before allowing access to certain information.

Considerations:

  • The use of ensure! to check conditions before proceeding is a good practice.
  • It would be beneficial to add more detailed error messages to help users understand why a query might fail.

271-274: Review of the migrate function

This function handles contract migrations by delegating to the ADOContract::default().migrate. It ensures that the contract name and version are properly managed.

Considerations:

  • Ensure that migration paths are tested thoroughly to prevent data loss.
  • Consider logging migration steps and results for better traceability.

contracts/modules/andromeda-curve/src/contract.rs Outdated Show resolved Hide resolved
contracts/modules/andromeda-curve/src/contract.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7c5d2f2 and 29b58b8.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • contracts/modules/andromeda-curve/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/mock.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/state.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/mock.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/mod.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/curve.rs (1 hunks)
  • packages/andromeda-modules/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • CHANGELOG.md
  • contracts/modules/andromeda-curve/src/testing/mod.rs
Additional comments not posted (56)
packages/andromeda-modules/src/lib.rs (1)

2-2: New module curve added.

The addition of the curve module looks good. Ensure that the module is properly implemented and tested.

contracts/modules/andromeda-curve/src/state.rs (3)

1-2: Ensure proper usage of imported modules.

The necessary modules are imported correctly.


4-10: Constants defined for curve configuration.

The constants for storing curve-related data are defined correctly. Ensure they are used appropriately in the implementation.


12-13: Default values for multiple variable and constant defined.

The default values for multiple_variable_value and constant_value are defined correctly. Ensure they are used appropriately in the implementation.

packages/andromeda-modules/src/curve.rs (11)

1-2: Ensure proper usage of imported modules.

The necessary modules are imported correctly.


4-9: Structure InstantiateMsg defined for instantiation.

The InstantiateMsg structure is defined correctly for instantiation. Ensure it is used appropriately in the implementation.


11-27: Enum ExecuteMsg defined for execution.

The ExecuteMsg enum is defined correctly for execution. Ensure it is used appropriately in the implementation.


29-41: Enum QueryMsg defined for querying.

The QueryMsg enum is defined correctly for querying. Ensure it is used appropriately in the implementation.


43-46: Enum CurveType defined for curve types.

The CurveType enum is defined correctly. Ensure it is used appropriately in the implementation.


48-52: Enum CurveRestriction defined for curve restrictions.

The CurveRestriction enum is defined correctly. Ensure it is used appropriately in the implementation.


54-58: Enum CurveId defined for curve IDs.

The CurveId enum is defined correctly. Ensure it is used appropriately in the implementation.


60-63: Structure GetCurveTypeResponse defined for curve type response.

The GetCurveTypeResponse structure is defined correctly. Ensure it is used appropriately in the implementation.


65-71: Structure GetConfigurationExpResponse defined for configuration response.

The GetConfigurationExpResponse structure is defined correctly. Ensure it is used appropriately in the implementation.


73-76: Structure GetPlotYFromXResponse defined for plot response.

The GetPlotYFromXResponse structure is defined correctly. Ensure it is used appropriately in the implementation.


78-81: Structure GetRestrictionResponse defined for restriction response.

The GetRestrictionResponse structure is defined correctly. Ensure it is used appropriately in the implementation.

contracts/modules/andromeda-curve/src/testing/mock.rs (10)

19-35: LGTM!

The proper_initialization function correctly initializes mock dependencies and performs contract instantiation.


37-45: LGTM!

The update_curve_type function correctly constructs and executes the UpdateCurveType message.


47-51: LGTM!

The reset function correctly constructs and executes the Reset message.


53-61: LGTM!

The update_restriction function correctly constructs and executes the UpdateRestriction message.


63-79: LGTM!

The configure_exponential function correctly constructs and executes the ConfigureExponential message.


81-87: LGTM!

The query_restriction function correctly queries the GetRestriction message and processes the response.


89-95: LGTM!

The query_curve_type function correctly queries the GetCurveType message and processes the response.


97-103: LGTM!

The query_configuration_exp function correctly queries the GetConfigurationExp message and processes the response.


105-113: LGTM!

The query_plot_y_from_x function correctly queries the GetPlotYFromX message and processes the response.


1-114: LGTM!

The file is correctly formatted.

contracts/modules/andromeda-curve/src/testing/tests.rs (8)

8-11: LGTM!

The test_instantiation function correctly tests the instantiation of the contract.


13-29: LGTM!

The test_update_restriction function correctly tests the update restriction functionality, including unauthorized access.


31-55: LGTM!

The test_configure_exponential function correctly tests the configuration of the exponential curve.


57-72: LGTM!

The test_reset function correctly tests the reset functionality.


74-118: LGTM!

The test_query_plot_y_from_x function correctly tests querying the Y value from a given X value.


120-125: LGTM!

The test_query_curve_type function correctly tests querying the curve type.


127-131: LGTM!

The test_update_curve_type function correctly tests updating the curve type.


1-131: LGTM!

The file is correctly formatted.

contracts/modules/andromeda-curve/src/mock.rs (7)

16-133: LGTM!

The MockCurve struct and its methods are correctly implemented, covering instantiation, execution of different messages, and querying.


135-138: LGTM!

The mock_andromeda_curve function correctly creates a mock contract wrapper.


140-152: LGTM!

The mock_curve_instantiate_msg function correctly creates an InstantiateMsg for the curve contract.


154-156: LGTM!

The mock_execute_update_curve_type_msg function correctly creates an ExecuteMsg::UpdateCurveType message.


158-160: LGTM!

The mock_execute_update_restriction_msg function correctly creates an ExecuteMsg::UpdateRestriction message.


162-174: LGTM!

The mock_execute_configure_exponential_msg function correctly creates an ExecuteMsg::ConfigureExponential message.


1-174: LGTM!

The file is correctly formatted.

contracts/modules/andromeda-curve/src/contract.rs (16)

1-19: Imports look good!

All necessary modules and crates are imported, and there are no unused imports.


21-23: Constants are correctly defined.

The contract name and version are correctly defined and used.


25-51: Instantiation function looks good!

The function correctly initializes the contract with the provided curve type and restriction, and sets default values for exponential configuration. Error handling is appropriately managed.


53-67: Execute function looks good!

The function correctly delegates to the appropriate handler based on the execution message and manages errors appropriately.


69-108: Handle execute function looks good!

The function correctly performs the corresponding actions for each execution message and manages errors appropriately.


110-131: Execute update curve type function looks good!

The function correctly performs the authorization check, updates the curve type, clears related state, and manages errors appropriately.


133-148: Execute update restriction function looks good!

The function correctly performs the authorization check, updates the restriction, and manages errors appropriately.


150-184: Execute configure exponential function looks good!

The function correctly performs the authorization check, saves the configuration values, and manages errors appropriately.


186-203: Execute reset function looks good!

The function correctly performs the authorization check, verifies the curve is configured, resets the configuration, and manages errors appropriately.


205-212: Has permission function looks good!

The function correctly checks the permissions based on the curve restriction and manages errors appropriately.


214-225: Query function looks good!

The function correctly delegates to the appropriate handler based on the query message and manages errors appropriately.


227-230: Query curve type function looks good!

The function correctly retrieves the curve type from storage and manages errors appropriately.


232-248: Query configuration exponential function looks good!

The function correctly retrieves the exponential configuration from storage and manages errors appropriately.


250-253: Query restriction function looks good!

The function correctly retrieves the curve restriction from storage and manages errors appropriately.


255-275: Query plot Y from X function looks good!

The function correctly calculates the Y value based on the X value and the exponential configuration, retrieves the necessary data from storage, and manages errors appropriately.


277-280: Migration function looks good!

The function correctly updates the contract to the new version and manages errors appropriately.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29b58b8 and 81fde51.

Files selected for processing (1)
  • contracts/modules/andromeda-curve/src/contract.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contracts/modules/andromeda-curve/src/contract.rs

@mdjakovic0920
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mdjakovic0920 mdjakovic0920 requested a review from joemonem August 6, 2024 15:31
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81fde51 and 6db3b1f.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (1)
  • contracts/modules/andromeda-curve/src/testing/tests.rs (1 hunks)
Additional comments not posted (7)
contracts/modules/andromeda-curve/src/testing/tests.rs (7)

8-11: LGTM!

The test_instantiation function correctly verifies the initialization logic for the curve.


13-29: LGTM!

The test_update_restriction function correctly tests unauthorized access and updates to curve restrictions.


31-55: LGTM!

The test_configure_exponential function correctly configures the exponential curve and verifies the configuration.


57-72: LGTM!

The test_rest function correctly tests the reset functionality by verifying that querying after reset results in an error.


74-116: LGTM!

The test_query_plot_y_from_x function correctly tests the plotting of Y values from given X values for both growth and decay configurations.


118-123: LGTM!

The test_query_curve_type function correctly verifies the retrieval of the curve type.


125-129: LGTM!

The test_update_curve_type function correctly tests the update of the curve type.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6db3b1f and 10666f9.

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

19-19: LGTM!

The added entry for "Curve ADO" follows the format of the changelog and aligns with the broader set of updates to the Andromeda protocol.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
contracts/modules/andromeda-curve/src/contract.rs (1)

24-212: LGTM with minor suggestions!

The contract entry points and their implementations are correctly structured and follow the expected behavior. The code is well-organized and modular, making it easy to understand and maintain.

A few minor suggestions for further improvement:

  1. Consider adding more detailed error messages to the ensure! macros to provide more context when an error occurs.

  2. In the execute_update_curve_config and execute_update_restriction functions, consider adding an event to emit the updated values for better transparency and easier tracking of changes.

  3. In the query_plot_y_from_x function, consider adding validation for the input x_value to ensure it falls within the expected range (e.g., between 0 and 1).

Overall, the code looks good and is ready to be merged.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 10666f9 and 73e999a.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (7)
  • Cargo.toml (1 hunks)
  • contracts/modules/andromeda-curve/Cargo.toml (1 hunks)
  • contracts/modules/andromeda-curve/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/state.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/mock.rs (1 hunks)
  • contracts/modules/andromeda-curve/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/curve.rs (1 hunks)
Additional comments not posted (35)
contracts/modules/andromeda-curve/src/state.rs (4)

1-2: LGTM!

The imports are necessary for defining the state variables.


4-5: LGTM!

  • Using cw_storage_plus::Item is a good choice for storing singleton data.
  • The constant names are descriptive and follow the naming convention.

7-7: LGTM!

The constant is defined correctly and has a sensible default value.


8-8: LGTM!

The constant is defined correctly and has a sensible default value.

contracts/modules/andromeda-curve/Cargo.toml (1)

1-33: LGTM!

The Cargo configuration file for the andromeda-curve module looks good:

  • The package configuration is correct, with the package name matching the module name and the version set to 1.0.0.
  • The library configuration is properly defined, with both cdylib and rlib crate types specified.
  • The features are well-defined, including backtraces, library, and testing.
  • The dependencies are appropriately specified, including cosmwasm-std, cosmwasm-schema, cw-storage-plus, cw-utils, test-case, andromeda-std, and andromeda-modules.
  • The dev-dependencies include cw-multi-test, andromeda-testing, and andromeda-app, which are suitable for testing and development purposes.
Cargo.toml (1)

58-58: LGTM!

The addition of the test-case dependency can improve the testing process by providing additional tools and utilities. Using a specific version ensures consistent builds across different environments.

packages/andromeda-modules/src/curve.rs (12)

7-10: LGTM!

The InstantiateMsg struct is well-defined and annotated with appropriate attributes.


13-16: LGTM!

The CurveRestriction enum provides a clear way to define the access restriction for curves.


19-22: LGTM!

The CurveId enum provides a clear way to define the types of curves.


25-32: LGTM!

The CurveConfig enum provides a clear way to define the configuration for exponential curves.


34-53: LGTM!

The validate function correctly ensures that the base value is not zero for exponential curves.


57-61: LGTM!

The ExecuteMsg enum provides a clear way to define the execute messages for the contract.


66-73: LGTM!

The QueryMsg enum provides a clear way to define the query messages for the contract.


76-78: LGTM!

The GetCurveConfigResponse struct is well-defined and serves as the response for the GetCurveConfig query.


81-83: LGTM!

The GetPlotYFromXResponse struct is well-defined and serves as the response for the GetPlotYFromX query.


86-88: LGTM!

The GetRestrictionResponse struct is well-defined and serves as the response for the GetRestriction query.


95-103: LGTM!

The test_validate_valid function correctly tests the validate function with a valid curve configuration.


106-114: LGTM!

The test_validate_invalid function correctly tests the validate function with an invalid curve configuration.

contracts/modules/andromeda-curve/src/testing/mock.rs (4)

19-35: LGTM!

The proper_initialization function is a useful utility for setting up the contract with proper initialization for testing. It takes curve_config and restriction as arguments, initializes the contract using the instantiate function, and asserts that no messages are returned. The code changes are approved.


37-52: LGTM!

The error_initialization function is a useful utility for testing error scenarios during contract initialization. It takes curve_config and restriction as arguments, initializes the contract using the instantiate function, and returns the ContractError. The code changes are approved.


54-78: LGTM!

The update_curve_config, reset, and update_restriction functions are useful utilities for testing the execute functionality of the contract. They update the curve configuration, reset the contract state, and update the restriction respectively. The code changes are approved.


80-105: LGTM!

The query_restriction, query_curve_config, and query_plot_y_from_x functions are useful utilities for testing the query functionality of the contract. They query the restriction, curve configuration, and y value for a given x value respectively. The code changes are approved.

contracts/modules/andromeda-curve/src/testing/tests.rs (10)

143-145: Skipping the existing comment as it is no longer applicable.

The code is already using the test_case macro for case-based testing, which serves a similar purpose as rstest. Therefore, the existing comment suggesting the use of rstest is no longer applicable.

Also applies to: 161-163, 179-181


11-21: LGTM!

The code changes are approved.


24-47: LGTM!

The code changes are approved.


50-64: LGTM!

The code changes are approved.


67-99: LGTM!

The code changes are approved.


102-122: LGTM!

The code changes are approved.


125-141: LGTM!

The code changes are approved.


146-159: LGTM!

The code changes are approved.


164-177: LGTM!

The code changes are approved.


182-195: LGTM!

The code changes are approved.

contracts/modules/andromeda-curve/src/contract.rs (3)

1-14: LGTM!

The imports are correctly used and necessary for the contract implementation.


16-18: LGTM!

The imports are correctly used and necessary for the contract implementation.


20-22: LGTM!

The constants are correctly defined.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73e999a and bbb2db7.

Files selected for processing (1)
  • packages/andromeda-modules/src/curve.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/andromeda-modules/src/curve.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bbb2db7 and b52dbf3.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • packages/andromeda-modules/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
Additional comments not posted (1)
packages/andromeda-modules/src/lib.rs (1)

2-2: LGTM!

The public declaration of the curve module is consistent with the other module declarations in the file. The addition of the curve module is a valid change that enhances the library's capabilities.

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)
CHANGELOG.md (1)

19-19: LGTM! Consider adding a brief description.

The addition of the Curve ADO is well-documented and consistent with the changelog format. It aligns with the PR objectives and provides traceability through the pull request reference.

To enhance clarity for users, consider adding a brief description of the Curve ADO's purpose. For example:

- Added Curve ADO [(#515)](https://github.com/andromedaprotocol/andromeda-core/pull/515)
+ Added Curve ADO for managing exponential curves [(#515)](https://github.com/andromedaprotocol/andromeda-core/pull/515)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b52dbf3 and 3345f19.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • Cargo.toml (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
Cargo.toml (2)

Line range hint 1-59: Verify the status of contracts/automation/* in workspace members.

The AI-generated summary mentions that contracts/automation/* has been removed from the workspace members. However, this change is not reflected in the provided code. The line # "contracts/automation/*", is still present (commented out) in the workspace members list.

Please clarify:

  1. Was the removal of contracts/automation/* intended but not implemented?
  2. If it was removed, why is it still present (albeit commented out) in the file?
  3. If it wasn't removed, why does the AI summary mention its removal?

To verify the current status of the contracts/automation/* directory, run the following script:

#!/bin/bash
# Description: Check the status of contracts/automation directory

# Test: Check if the directory exists
if [ -d "contracts/automation" ]; then
    echo "contracts/automation directory exists"
    # List contents of the directory
    ls -l contracts/automation
else
    echo "contracts/automation directory does not exist"
fi

# Test: Check for any Rust files in the directory
fd -e rs -t f -g 'contracts/automation/**'

This script will help determine if the contracts/automation directory still exists and contains any Rust files, which can provide insight into whether it should be included in the workspace or not.


59-59: Approve the addition of test-case dependency with suggestions.

The addition of the test-case dependency (version 3.3.1) is approved. This library can enhance the project's testing capabilities by enabling parameterized tests.

However, please consider the following recommendations:

  1. Verify that this dependency is necessary for the project and aligns with the current testing strategy.
  2. Ensure that it's being used effectively in the test files.
  3. Update the project documentation to reflect this addition and provide guidelines on how to use it in tests.

To verify the usage of the test-case crate, run the following script:

This script will help identify if and how the test-case crate is being used in the project's test files.

✅ Verification successful

test-case Dependency Usage Verified

The test-case dependency (version 3.3.1) is actively utilized within contracts/modules/andromeda-curve/src/testing/tests.rs for parameterized testing through multiple #[test_case] attributes and corresponding use statements.

No further actions are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the usage of the test-case crate in test files

# Test: Search for #[test_case] attribute in test files
rg --type rust '#\[test_case' $(fd -e rs -t f -g '**/tests/**')

# Test: Search for use statements importing test_case
rg --type rust 'use .*test_case' $(fd -e rs -t f -g '**/tests/**')

Length of output: 179


Script:

#!/bin/bash
# Description: Comprehensive search for the usage of the test-case crate in the entire codebase

# Test: Search for #[test_case] attribute in all Rust files
rg --type rust '#\[test_case' .

# Test: Search for use statements importing test_case in all Rust files
rg --type rust 'use .*test_case' .

Length of output: 1146

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

🧹 Outside diff range and nitpick comments (1)
contracts/modules/andromeda-curve/src/contract.rs (1)

143-145: Add Logging for State Reset Operation

In execute_reset, the curve configuration is removed from storage. To improve transparency and auditability, consider adding logging or attributes that record the reset action and potentially the previous configuration state.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3345f19 and b33862b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • contracts/modules/andromeda-curve/src/contract.rs (1 hunks)
🧰 Additional context used

@crnbarr93 crnbarr93 merged commit c6c98d0 into andromedaprotocol:development Oct 14, 2024
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2024
@mdjakovic0920 mdjakovic0920 deleted the mdjakovic/curve-ado branch November 28, 2024 15:05
This was referenced Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants