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

build: artifacts + just tidy + docs + fix nibiru-std proto import #117

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Jan 11, 2024

  • fix(bash-rs): type corrections for e2e tests
  • build: artifacts + just tidy + docs + merge main
  • feat: export new prost types

Summary by CodeRabbit

  • New Features

    • Introduced the EventInflationDistribution struct to represent NIBI token emissions.
    • Added message types for editing oracle parameters and new operations in the perpetual markets.
    • Enhanced bash scripting capabilities with additional functions and error handling.
  • Improvements

    • Improved readability and clarity in contract functions with added comments and error handling refactor.
    • Streamlined import orders and formatting across various files for consistency.
    • Updated naming conventions for message types to align with functionality.
  • Bug Fixes

    • Adjusted logic in the DecimalExt implementation to ensure correct behavior.
  • Documentation

    • Provided detailed comments for new message types and structures.
    • Updated comments for better understanding of the contract's genesis state and sudoers events.
  • Refactor

    • Modified the execute function to reflect the renaming of fund withdrawal operations.
    • Cleaned up test files by reordering imports and simplifying assertions.
  • Style

    • Standardized code formatting in enums, structs, and test vectors.

commit 2296e6f1e91db857318632089aa2cf888a4ce8ae
Merge: c14558d dd90c9a
Author: Unique-Divine <[email protected]>
Date:   Wed Jan 10 21:25:41 2024 -0600

    Merge branch 'main' into realu/std

commit c14558de1b80b739701ff3b146355ea815327192
Author: Unique-Divine <[email protected]>
Date:   Wed Jan 10 15:43:00 2024 -0600

    quick save wip!

commit dd90c9a
Merge: bd792e4 902b788
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 19:00:52 2024 +0100

    Merge pull request #111 from NibiruChain/feat/some-refactors-airdrop

    add some refactors to airdrop contract

commit 902b788
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:41:16 2024 +0100

    remove unused imports

commit 0f337d1
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:39:21 2024 +0100

    it fails when there are not enough funds

commit 1d42220
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:31:57 2024 +0100

    add some refactors, part 1

commit bd792e4
Author: Kevin Yang <[email protected]>
Date:   Wed Jan 3 14:22:23 2024 -0800

    feat: initial airdrop contract (#110)

    * feat: initial airdrop contract

    * create cargo config

    * test: instantiate message

    * remove owner from instantiate msg

    * test: query functions

    * test: execute functions

    * feat: add manager list

    * feat: implement manager list

    * Create README.md

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * fix error messages

    ---------

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

commit 88ae9fd
Author: Matthias <[email protected]>
Date:   Wed Jan 3 15:32:33 2024 +0100

    doc: Add cookbook for live smart contracts (#109)
Copy link
Contributor

coderabbitai bot commented Jan 11, 2024

Walkthrough

The changes across the codebase focus on refactoring for readability and maintainability. They include the removal of redundant return keywords, the addition of comments for clarity, reordering of imports, formatting adjustments for consistency, and an update to error handling approaches. New features and message types are introduced in the nibiru-std module, while the bash-rs package sees improvements to function parameters and the addition of new functionalities.

Changes

File Path Change Summary
contracts/airdrop/src/contract.rs Removed return keyword, added comments, refactored error handling
contracts/airdrop/src/msg.rs, contracts/airdrop/src/state.rs, .../tests/execute/*.rs, .../tests/query/*.rs, .../tests/instantiate.rs, .../tests/mod.rs Reordered imports, formatted enums and vectors, simplified assertions
nibiru-std/src/proto/buf/*.rs, nibiru-std/src/proto/type_url_nibiru.rs Added new message types and structs, renamed fields, updated comments, added Name trait implementations
packages/bash-rs/src/bash.rs, packages/bash-rs/src/errors.rs Changed function parameters, added new functions, introduced new error variant
packages/core-controller/src/*.rs Renamed message variant and updated variable names
scripts/wasm_out.rs Modified function call to pass reference

"In the code's burrow, beneath the moon's glow,
Refactoring hops, as new features grow.
🐇 With each commit push, the garden's more lush,
Bugs scatter away, in the twilight's hush."

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

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit Configration File (.coderabbit.yaml)

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

CodeRabbit Discord Community

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

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (902b788) 85.16% compared to head (42af5d3) 85.00%.
Report is 1 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
contracts/airdrop/src/msg.rs 40.00% <ø> (ø)
contracts/airdrop/src/state.rs 100.00% <ø> (ø)
nibiru-std/src/proto/type_url_nibiru.rs 95.00% <ø> (ø)
packages/bash-rs/src/errors.rs 0.00% <ø> (ø)
packages/core-controller/src/msgs.rs 33.33% <ø> (ø)
contracts/airdrop/src/contract.rs 71.82% <93.33%> (+0.23%) ⬆️
nibiru-std/src/math.rs 80.45% <0.00%> (-0.40%) ⬇️
packages/core-controller/src/contract.rs 88.18% <0.00%> (ø)
scripts/wasm_out.rs 62.01% <0.00%> (ø)
packages/bash-rs/src/bash.rs 59.45% <33.33%> (-7.72%) ⬇️

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dd90c9a and 42af5d3.
Files ignored due to filter (13)
  • Cargo.lock
  • Cargo.toml
  • artifacts/airdrop.wasm
  • artifacts/cw3_flex_multisig.wasm
  • artifacts/incentives.wasm
  • artifacts/lockup.wasm
  • artifacts/nibi_stargate.wasm
  • artifacts/nibi_stargate_perp.wasm
  • artifacts/nusd_valuator.wasm
  • artifacts/pricefeed.wasm
  • artifacts/shifter.wasm
  • artifacts/token_vesting.wasm
  • contracts/airdrop/Cargo.toml
Files selected for processing (24)
  • artifacts/checksums.txt (1 hunks)
  • contracts/airdrop/src/contract.rs (10 hunks)
  • contracts/airdrop/src/msg.rs (2 hunks)
  • contracts/airdrop/src/state.rs (1 hunks)
  • contracts/airdrop/src/tests/execute/claim.rs (4 hunks)
  • contracts/airdrop/src/tests/execute/mod.rs (1 hunks)
  • contracts/airdrop/src/tests/execute/reward_users.rs (8 hunks)
  • contracts/airdrop/src/tests/execute/withdraw.rs (4 hunks)
  • contracts/airdrop/src/tests/instantiate.rs (4 hunks)
  • contracts/airdrop/src/tests/mod.rs (1 hunks)
  • contracts/airdrop/src/tests/query/campaign.rs (3 hunks)
  • contracts/airdrop/src/tests/query/mod.rs (1 hunks)
  • contracts/airdrop/src/tests/query/user_pool.rs (2 hunks)
  • nibiru-std/src/math.rs (2 hunks)
  • nibiru-std/src/proto/buf/nibiru.inflation.v1.rs (1 hunks)
  • nibiru-std/src/proto/buf/nibiru.oracle.v1.rs (14 hunks)
  • nibiru-std/src/proto/buf/nibiru.perp.v2.rs (5 hunks)
  • nibiru-std/src/proto/buf/nibiru.sudo.v1.rs (1 hunks)
  • nibiru-std/src/proto/type_url_nibiru.rs (2 hunks)
  • packages/bash-rs/src/bash.rs (6 hunks)
  • packages/bash-rs/src/errors.rs (1 hunks)
  • packages/core-controller/src/contract.rs (1 hunks)
  • packages/core-controller/src/msgs.rs (1 hunks)
  • scripts/wasm_out.rs (1 hunks)
Files skipped from review due to trivial changes (10)
  • contracts/airdrop/src/msg.rs
  • contracts/airdrop/src/state.rs
  • contracts/airdrop/src/tests/execute/mod.rs
  • contracts/airdrop/src/tests/execute/reward_users.rs
  • contracts/airdrop/src/tests/execute/withdraw.rs
  • contracts/airdrop/src/tests/instantiate.rs
  • contracts/airdrop/src/tests/mod.rs
  • contracts/airdrop/src/tests/query/campaign.rs
  • contracts/airdrop/src/tests/query/mod.rs
  • nibiru-std/src/proto/buf/nibiru.sudo.v1.rs
Additional comments: 37
packages/bash-rs/src/errors.rs (1)
  • 16-17: The addition of the WhichBinNotPresent error variant is a good practice for providing more descriptive error messages related to binary presence checks. This should help with debugging and user error messages.
artifacts/checksums.txt (1)
  • 1-11: Checksums for compiled wasm files are typically used to verify the integrity of the files. It's important to ensure that these checksums are updated whenever the corresponding wasm files are changed to maintain integrity checks.
contracts/airdrop/src/tests/query/user_pool.rs (2)
  • 20-23: The formatting changes to the managers vector improve readability by placing each address on a separate line.

  • 69-72: The assertion has been updated to directly compare the result of query_user_reward with the expected error. This is a more direct and clear way to write the test.

contracts/airdrop/src/tests/execute/claim.rs (3)
  • 3-3: The import statement for USER_REWARDS has been simplified by removing unnecessary braces. This is a minor but positive change for code cleanliness.

  • 21-24: The managers vector declaration has been formatted for better readability, similar to the changes in user_pool.rs.

  • 57-57: The assertion related to USER_REWARDS has been simplified to check the absence of a user's rewards after a claim. This makes the test more concise and clear.

packages/core-controller/src/msgs.rs (1)
  • 22-22: The renaming of the InsuranceFundWithdraw variant to WithdrawPerpFund in the ExecuteMsg enum aligns with the changes in contract execution logic mentioned in the PR overview. This change should be verified across the codebase to ensure that all references to this enum variant have been updated accordingly.
Verification successful

The verification process has confirmed that the InsuranceFundWithdraw variant has been successfully renamed to WithdrawPerpFund in the ExecuteMsg enum and that the new variant name is being used correctly in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old enum variant name to ensure it's no longer used.
rg --type rust "InsuranceFundWithdraw"
# Search for the new enum variant name to ensure it's used correctly.
rg --type rust "WithdrawPerpFund"

Length of output: 342

packages/bash-rs/src/bash.rs (6)
  • 12-13: Changing the parameter type from String to &str for the bash_code parameter in the run_bash function is a good practice as it avoids unnecessary cloning and can improve performance.

  • 35-35: The build_bash_cmd function has also been updated to take a string slice, which is consistent with the changes made to run_bash.

  • 45-45: The run_bash_and_print function now correctly takes a string slice, aligning with the other function signatures and avoiding unnecessary cloning.

  • 100-102: The BashOutput struct's cmd field has been changed to take a String instead of a string slice. This change is appropriate since the struct needs to own the data it contains.

  • 159-166: The addition of the which_ok_assert function is a useful utility for ensuring that a binary is present in the PATH, and it properly uses the new WhichBinNotPresent error variant.

  • 169-176: The run_bash_multi function is a new addition that allows running multiple bash commands and collecting their outputs. This can be useful for scripting multiple steps in a single function call.

nibiru-std/src/proto/buf/nibiru.inflation.v1.rs (1)
  • 2-12: The addition of the EventInflationDistribution struct with fields staking_rewards, strategic_reserve, and community_pool is a clear way to represent the distribution of inflation. This should make it easier to work with inflation events in the codebase.
contracts/airdrop/src/contract.rs (6)
  • 49-51: The removal of the explicit return keyword in the instantiate function is a Rust idiom that favors implicit returns for the last expression in a block, making the code more idiomatic and concise.

  • 98-103: The addition of comments explaining the requirements and actions in the reward_users function is a good practice for maintainability, making the code easier to understand for future developers.

  • 160-163: The comments added to the claim function provide a clear explanation of its behavior, which is beneficial for code readability and maintainability.

  • 189-192: The comments in the withdraw function are descriptive and helpful for understanding the purpose and constraints of the function.

  • 242-243: The refactoring of error handling in the query_campaign function to provide a more specific error message is a good improvement for debugging and error tracing.

  • 253-255: Similarly, the refactoring in the query_user_reward function to provide a specific error message when a user reward does not exist is a good practice for error clarity.

scripts/wasm_out.rs (1)
  • 97-97: Passing a reference to the cmd variable in the run_bash_and_print function call is consistent with the changes made in the bash-rs package and avoids unnecessary cloning.
packages/core-controller/src/contract.rs (2)
  • 60-63: The match arms for AddMember, RemoveMember, and ChangeAdmin in the execute function appear to be correctly implemented with proper error handling and state changes. These changes align with the PR's objectives to improve maintainability and readability.

  • 60-63: The can_execute function is well-implemented, providing a clear and concise way to determine if the sender has the necessary permissions to perform certain actions. This function is a good example of encapsulating permission logic in a single place, which aids in maintainability and readability.

nibiru-std/src/math.rs (3)
  • 54-54: The addition of the return statement return *self; within the else if block of the add method in the DecimalExt implementation is correct. This ensures that if the other DecimalExt is zero, the method returns the current instance without modification, which is the expected behavior for adding zero to a number.

  • 54-54: The removal of the blank_test function from the test_sign_dec module is not visible in the provided code. If this function was not serving any purpose or was a placeholder without any assertions, its removal is justified to keep the test suite clean and focused on actual test cases.

  • 54-54: The implementations for mathematical operations and conversions in the DecimalExt and SdkDec structs are well-structured and include comprehensive error handling. This contributes to the robustness and maintainability of the mathematical utilities provided by the nibiru-std crate.

nibiru-std/src/proto/type_url_nibiru.rs (2)
  • 72-75: The implementation of the Name trait for nibiru::oracle::MsgEditOracleParams looks correct and follows the established pattern in the file.

  • 269-276: The implementation of the Name trait for nibiru::perp::MsgWithdrawFromPerpFund and nibiru::perp::MsgCloseMarket is consistent with the rest of the file and follows the established pattern.

nibiru-std/src/proto/buf/nibiru.oracle.v1.rs (2)
  • 7-11: The prost attributes for the Params struct fields have been updated to remove spaces around the equal sign. This change is consistent and improves the readability of the code.

  • 483-515: New message types MsgEditOracleParams and MsgEditOracleParamsResponse have been added. Ensure that these new message types are integrated correctly with the rest of the system and that any necessary handlers or logic for these messages have been implemented.

nibiru-std/src/proto/buf/nibiru.perp.v2.rs (6)
  • 58-61: The addition of the oracle_pair field to the Market struct is consistent with the summary provided. This field is important for associating a market with its corresponding oracle pair, which is likely used for price referencing.

  • 906-906: The comment for MsgChangeCollateralDenom indicates that it is only callable by sudoers, which is a security measure to ensure that only authorized users can change the collateral denomination. This is a good practice for administrative operations that could have a significant impact on the system.

  • 952-953: The MsgShiftPegMultiplier message is marked as [SUDO], indicating that it should only be callable by sudoers. This is another administrative operation that can impact the trading system significantly, and it is good to see that it is restricted to authorized users.

  • 970-971: Similarly, MsgShiftSwapInvariant is also marked as [SUDO], which is appropriate for an operation that can alter the trading dynamics of the platform.

  • 988-1006: The MsgWithdrawFromPerpFund message allows for withdrawal from the perpetual fund. It includes an optional denom field for cases where assets other than the default (presumably NUSD) are to be withdrawn. This flexibility is good, but it's important to ensure that the implementation checks for valid denominations and permissions, especially since it's marked as [SUDO].

  • 1009-1022: The MsgCloseMarket message is intended for administrative use to close a market. It's crucial that the implementation of this message includes proper authorization checks to prevent unauthorized closures.

const NAME: &'static str = "MsgEditOracleParams";
const PACKAGE: &'static str = PACKAGE_ORACLE;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a TODO comment about a type that exists but was not exported by the protos. It's important to address this TODO to ensure that all necessary types are properly exported and available for use.

Comment on lines 68 to 79
}

// ORACLE tx msg

impl Name for nibiru::oracle::MsgEditOracleParams {
const NAME: &'static str = "MsgEditOracleParams";
const PACKAGE: &'static str = PACKAGE_ORACLE;
}

// ORACLE query

impl Name for nibiru::oracle::QueryExchangeRateRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [413-415]

The test cases in the module seem to cover the Name trait implementations for the tokenfactory messages. Ensure that similar tests are implemented for the newly added Name trait implementations to maintain thorough test coverage.

Comment on lines +60 to +63
ExecuteMsg::WithdrawPerpFund { amount, to } => {
check_member(check)?;
todo!();
let _cw_msg = ExecuteMsg::InsuranceFundWithdraw { amount, to };
let _cw_msg = ExecuteMsg::WithdrawPerpFund { amount, to };
Copy link
Contributor

Choose a reason for hiding this comment

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

The execute function has been updated to change the match arm from InsuranceFundWithdraw to WithdrawPerpFund. The variable _cw_msg is also updated accordingly. However, the actual logic for handling the WithdrawPerpFund message is marked as todo!(), indicating that the implementation is incomplete. It's important to ensure that the logic for this match arm is implemented before merging the PR.

Additionally, the commented-out code should either be removed or implemented if it's meant to be part of the final version. Leaving commented-out code can lead to confusion and clutter in the codebase.

ExecuteMsg::WithdrawPerpFund { amount, to } => {
    check_member(check)?;
    todo!();
    let _cw_msg = ExecuteMsg::WithdrawPerpFund { amount, to };
    // let res = Response::new()
    //     .add_message(cw_msg)
    //     .add_attributes(vec![attr("action", "insurance_fund_withdraw")]);
    // Ok(res)
}

The match arms for SetMarketEnabled, CreateMarket, and EditOracleParams in the execute function are placeholders with todo!() and commented-out code. This suggests that the functionality for these cases is not yet implemented. It's crucial to complete the implementation for these cases or remove them if they are not intended for the current scope of work.

Leaving todo!() in the code that is merged into the main branch can lead to runtime panics if these code paths are executed. Ensure that the implementation is completed or feature-flagged if it's work in progress.


The tests in the tests module cover various functionalities such as contract instantiation, admin checks, and member management. However, there are no tests for the new WithdrawPerpFund functionality or other new features introduced in this PR. It's important to add comprehensive tests for all new functionalities to ensure they work as expected and to prevent regressions in the future.

@Unique-Divine Unique-Divine merged commit 349daec into main Jan 11, 2024
4 of 5 checks passed
@Unique-Divine Unique-Divine deleted the realu/std-2 branch January 11, 2024 05:51
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.

1 participant