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: new oracle address #121

Merged
merged 3 commits into from
Apr 24, 2024
Merged

feat: new oracle address #121

merged 3 commits into from
Apr 24, 2024

Conversation

rustcandy
Copy link
Contributor

@rustcandy rustcandy commented Apr 22, 2024

Overview

closes: #XXXX

What changes have been made in this PR?

  • [ ]

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

Summary by CodeRabbit

  • New Features
    • Integrated new oracle address functionality in staking contracts for enhanced configuration and execution.
    • Added capability to post rates directly to the Milkyway Oracle.
  • Enhancements
    • Updated oracle address management to support the latest version.
  • Bug Fixes
    • Adjusted message index handling across various test scenarios to align with new message structures.
  • Refactor
    • Streamlined oracle-related fields in data structures for better clarity and maintenance.
  • Version Update
    • Updated application version to 0.4.11.

Copy link
Contributor

coderabbitai bot commented Apr 22, 2024

Walkthrough

The recent updates revolve around integrating an oracle_address field into various components of a staking contract. This addition enables communication with the Milkyway Oracle for rate postings. Changes encompass adding this field to configuration and message structures, refining logic for oracle interactions, and adjusting test cases to accommodate the new oracle address field and its associated functionality.

Changes

Files Summary
Cargo.toml Updated version from "0.4.10" to "0.4.11".
.../contract.rs, .../execute.rs, .../msg.rs, .../query.rs, .../state.rs, .../test_helper.rs Added oracle_address field and updated handling of oracle interactions. Renamed related attributes.
.../oracle.rs Introduced PostRates in Oracle enum; removed outdated comments and fields.
Various test files (.../ibc_transfer_tests.rs, .../instantiate_tests.rs, .../reward_tests.rs, .../stake_tests.rs, .../unstake_tests.rs, .../withdraw_tests.rs) Adjusted message index and count in assertions to align with new changes in message handling.

This table provides a concise overview of the modifications implemented across multiple files, emphasizing the systematic integration of the oracle address and its operational implications.


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4f2ed0c and 1f3d9fc.
Files selected for processing (1)
  • contracts/staking/src/oracle.rs (1 hunks)
Additional Context Used
GitHub Check Runs (1)
Test Suite success (9)

contracts/staking/src/oracle.rs: [warning] 3-3:
unused import: Decimal

Additional comments not posted (1)
contracts/staking/src/oracle.rs (1)

18-22: LGTM! The new PostRates variant aligns well with the PR objectives for enhanced interaction with the Milkyway Oracle.


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.

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

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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

Comment on lines +762 to +771
// update oracle contract address v3
if msg.oracle_address.is_some() {
let oracle_address = msg.oracle_address.unwrap();
let address = validate_address(&oracle_address, "osmo")?;
config.oracle_address = Some(address);
}

CONFIG.save(deps.storage, &config)?;

Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2"))
Ok(Response::new().add_attribute("action", "update_oracle_address"))
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 22, 2024

Choose a reason for hiding this comment

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

Update oracle address handling in migration.

-    if msg.oracle_address.is_some() {
-        let oracle_address = msg.oracle_address.unwrap();
-        let address = validate_address(&oracle_address, "osmo")?;
-        config.oracle_address = Some(address);
-    }
+    config.oracle_address = msg.oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap());

Refactor the handling of the new oracle address in the migration function to use more idiomatic Rust patterns, reducing redundancy and potential for errors.


Committable suggestion

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

Suggested change
// update oracle contract address v3
if msg.oracle_address.is_some() {
let oracle_address = msg.oracle_address.unwrap();
let address = validate_address(&oracle_address, "osmo")?;
config.oracle_address = Some(address);
}
CONFIG.save(deps.storage, &config)?;
Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2"))
Ok(Response::new().add_attribute("action", "update_oracle_address"))
// update oracle contract address v3
config.oracle_address = msg.oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap());
CONFIG.save(deps.storage, &config)?;
Ok(Response::new().add_attribute("action", "update_oracle_address"))

Copy link
Contributor

Choose a reason for hiding this comment

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

From my perspective, we can ignore this.
The suggested code will make the contract panic if we receive an invalid address, while with the original code, we return an error to the user.
If we want to make this more idiomatic Rust, I would prefer to remove the unwrap call from inside the map and use transpose on the returned Option<Result<Addr>> so that we can return the error to the user instead of panicking. However, this is more of a coding style decision that we should all agree on.

Copy link
Contributor

Choose a reason for hiding this comment

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

@manu0466, I completely agree with your perspective. Handling potential errors gracefully rather than causing the contract to panic is indeed a more robust approach. Using transpose on the returned Option<Result<Addr>> is a great suggestion as it aligns with idiomatic Rust practices and ensures that errors are handled appropriately.

Here's how the code could be refactored to incorporate your suggestion:

// update oracle contract address v3
config.oracle_address = msg.oracle_address.map(|addr| validate_address(&addr, "osmo")).transpose()?;

CONFIG.save(deps.storage, &config)?;

Ok(Response::new().add_attribute("action", "update_oracle_address"))

This modification uses map to apply validate_address to the oracle_address if it is Some, and then transpose is used to convert Option<Result<Addr>> into Result<Option<Addr>>, which can be propagated using ? if there is an error. This ensures that any address validation errors are returned as a contract error rather than causing a panic.

Thank you for pointing this out and for your insightful suggestion! If there's anything else you'd like to adjust or further discuss, feel free to let me know.

Comment on lines +857 to +862
if oracle_address.is_some() {
let oracle_address = oracle_address.unwrap();
let address = validate_address(&oracle_address, "osmo")?;
config.oracle_address = Some(address);
}

Copy link
Contributor

@coderabbitai coderabbitai bot Apr 22, 2024

Choose a reason for hiding this comment

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

Refactor handling of the new oracle address in configuration updates.

-    if oracle_address.is_some() {
-        let oracle_address = oracle_address.unwrap();
-        let address = validate_address(&oracle_address, "osmo")?;
-        config.oracle_address = Some(address);
-    }
+    config.oracle_address = oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap());

Simplify the handling of the new oracle address in the update_config function to use more idiomatic Rust patterns, reducing redundancy and potential for errors.


Committable suggestion

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

Suggested change
if oracle_address.is_some() {
let oracle_address = oracle_address.unwrap();
let address = validate_address(&oracle_address, "osmo")?;
config.oracle_address = Some(address);
}
config.oracle_address = oracle_address.map(|addr| validate_address(&addr, "osmo").unwrap());

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the other suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

@manu0466, thank you for confirming. If there's anything else you need help with or further adjustments to be made, feel free to let me know!

Copy link
Contributor

@manu0466 manu0466 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Let's decide if we want to ignore the suggestions from coderabbitai or refactor the code.

Comment on lines +762 to +771
// update oracle contract address v3
if msg.oracle_address.is_some() {
let oracle_address = msg.oracle_address.unwrap();
let address = validate_address(&oracle_address, "osmo")?;
config.oracle_address = Some(address);
}

CONFIG.save(deps.storage, &config)?;

Ok(Response::new().add_attribute("action", "update_oracle_contract_address_v2"))
Ok(Response::new().add_attribute("action", "update_oracle_address"))
Copy link
Contributor

Choose a reason for hiding this comment

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

From my perspective, we can ignore this.
The suggested code will make the contract panic if we receive an invalid address, while with the original code, we return an error to the user.
If we want to make this more idiomatic Rust, I would prefer to remove the unwrap call from inside the map and use transpose on the returned Option<Result<Addr>> so that we can return the error to the user instead of panicking. However, this is more of a coding style decision that we should all agree on.

Comment on lines +857 to +862
if oracle_address.is_some() {
let oracle_address = oracle_address.unwrap();
let address = validate_address(&oracle_address, "osmo")?;
config.oracle_address = Some(address);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the other suggestion.

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

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

Out of diff range and nitpick comments (1)
contracts/staking/src/oracle.rs (1)

Line range hint 3-3: Remove the unused import Decimal to clean up the code.

- use cosmwasm_std::{Binary, Decimal};
+ use cosmwasm_std::Binary;

@rustcandy rustcandy merged commit bbb14ff into main Apr 24, 2024
1 check passed
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