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

fix: converted seconds to milliseconds #578

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

cowboy0015
Copy link
Member

@cowboy0015 cowboy0015 commented Oct 14, 2024

Motivation

Resolves following issues

Implementation

  • Updated vesting ado to use Milliseconds for up_to_time, lockup_duration and release_unit instead of u64
  • Removed unnecessary batch flag and unbonding duration.

Testing

Unit tests for vesting updated to use Milliseconds
Removed test case with disabled multi batching option

Summary by CodeRabbit

  • New Features

    • Introduced multiple new ADOs including Validator Staking, Asset, String Storage, Boolean Storage, Counter, Date Time, and IBC Registry ADO.
    • Added functionality for removing/replacing reward tokens in staking and a BuyNow option for auctions.
    • Implemented Denom Validation for Rates and in the IBC Registry ADO.
  • Bug Fixes

    • Resolved issues with Splitter and Conditional Splitter lock time calculations and precision in vesting claim batch method.
  • Changes

    • Updated time-related fields to use a new Milliseconds type for improved clarity and type safety in contracts and tests.
    • Simplified instantiation logic by removing the is_multi_batch_enabled parameter.
    • Removed the IncompleteUnbondingPeriod variant from error handling for streamlined error management.

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request updates the CHANGELOG.md to document new features, changes, fixes, and removals in the project. Key additions include various ADOs and enhancements related to staking and auctions. Significant modifications in the contract files involve replacing u64 with a new Milliseconds type for time-related parameters, enhancing type safety. Test cases are also updated to align with these changes.

Changes

File Change Summary
CHANGELOG.md Updated to document new features, changes, fixes, and removals, including multiple new ADOs and enhancements.
contracts/finance/andromeda-vesting/src/contract.rs Updated function signatures to use Milliseconds instead of u64 for time-related parameters and modified time calculations.
contracts/finance/andromeda-vesting/src/mock.rs Removed is_multi_batch_enabled parameter from instantiation methods, simplifying the contract creation process.
contracts/finance/andromeda-vesting/src/state.rs Changed Batch struct fields from u64 to Milliseconds and updated related functions.
contracts/finance/andromeda-vesting/src/testing/tests.rs Updated test cases to use Milliseconds for time-related parameters instead of u64.
packages/andromeda-finance/src/vesting.rs Updated several fields from u64 to Milliseconds in structures and enums related to time management.
packages/std/src/error.rs Removed IncompleteUnbondingPeriod variant from ContractError enum.

Assessment against linked issues

Objective Addressed Explanation
Use milliseconds instead of seconds in contracts (SUPP-116)
Maintain consistency with other ADOs using milliseconds (SUPP-116)
Remove the option to enable/disable multi-batching (SUPP-115)

Possibly related PRs

Suggested labels

ci: skip-changelog

Suggested reviewers

  • joemonem
  • crnbarr93

Poem

In the land of code where rabbits hop,
We’ve changed the time, no need to stop.
From seconds to millis, we’ve made it clear,
With every new feature, we cheer and cheer!
So let’s code away, with joy in our hearts,
For every small change is where the magic starts! 🐇✨


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.

@cowboy0015 cowboy0015 requested review from crnbarr93 and joemonem and removed request for crnbarr93 October 14, 2024 18:25
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: 4

🧹 Outside diff range and nitpick comments (3)
packages/andromeda-finance/src/vesting.rs (3)

36-44: LGTM: Time units converted to Milliseconds, minor comment update needed

The changes from u64 to Milliseconds in the ExecuteMsg enum are consistent with the PR objective of converting time units to milliseconds. This includes:

  • up_to_time in ClaimAll
  • lockup_duration and release_unit in CreateBatch

These changes improve type safety and align with the standard practice in other ADOs.

Consider updating the comment on line 43 from "seconds" to "milliseconds" for consistency:

-        /// How often releases occur in seconds.
+        /// How often releases occur in milliseconds.

92-99: LGTM: Time units converted to Milliseconds in BatchResponse, minor comment update needed

The changes from u64 to Milliseconds in the BatchResponse struct are consistent with the PR objective:

  • lockup_end
  • release_unit
  • last_claimed_release_time

These changes improve type safety and align with the standard practice in other ADOs.

Consider updating the comment on line 98 from "seconds" to "milliseconds" for consistency:

-    /// The time at which the last claim took place in seconds.
+    /// The time at which the last claim took place in milliseconds.

Incomplete Replacement of Time-related u64 Instances

The verification script identified instances where u64 is still used in time-related contexts alongside Milliseconds. Specifically:

  • contracts/fungible-tokens/andromeda-lockdrop/src/contract.rs: 50u64 * time_left.milliseconds()

These remaining u64 usages should be converted to Milliseconds to ensure consistency and prevent potential bugs.

🔗 Analysis chain

Line range hint 1-99: Summary: Successful conversion of time units to milliseconds

The changes in this file successfully implement the conversion from seconds to milliseconds as per the PR objectives:

  1. All time-related fields previously using u64 have been updated to use the Milliseconds type.
  2. The changes are consistent across the ExecuteMsg enum and BatchResponse struct.
  3. The import statement has been updated to include Milliseconds from the common module.

These modifications enhance type safety and align the contract's time measurement with the standard practice observed in other ADOs. The changes address the issue raised in SUPP-116 and contribute to maintaining consistency across the codebase.

To ensure that all instances of u64 related to time measurements have been replaced, run the following verification script:

This script will help identify any remaining u64 instances that might be time-related and confirm the usage of Milliseconds for time-related fields.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all time-related u64 instances have been replaced with Milliseconds

# Test: Search for any remaining u64 usages that might be time-related
rg --type rust 'u64.*(?i)(time|duration|period|interval|frequency)'

# Test: Confirm Milliseconds is used for time-related fields
rg --type rust 'Milliseconds.*(?i)(time|duration|period|interval|frequency)'

Length of output: 25163

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c6c98d0 and 68ca0b9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • contracts/finance/andromeda-vesting/Cargo.toml (1 hunks)
  • contracts/finance/andromeda-vesting/src/contract.rs (11 hunks)
  • contracts/finance/andromeda-vesting/src/state.rs (5 hunks)
  • contracts/finance/andromeda-vesting/src/testing/tests.rs (53 hunks)
  • packages/andromeda-finance/src/vesting.rs (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • contracts/finance/andromeda-vesting/Cargo.toml
🧰 Additional context used
🔇 Additional comments (45)
packages/andromeda-finance/src/vesting.rs (1)

4-4: LGTM: Import statement updated correctly

The addition of Milliseconds to the import statement from the common module is consistent with its usage throughout the file and aligns with the PR objective of converting time units to milliseconds.

CHANGELOG.md (2)

53-53: LGTM! The change aligns with the PR objectives.

The changelog entry correctly reflects the change from seconds to milliseconds in the Vesting ADO, which aligns with the PR objectives and the linked issue SUPP-116. This change promotes consistency across ADOs in time measurement.


Line range hint 1-53: Verify consistency and completeness of the changelog.

While the change to milliseconds in the Vesting ADO is correctly documented, it's important to ensure that all related changes are captured in the changelog.

Please run the following script to check for any mentions of time units in the changed files:

This will help ensure that all relevant changes related to the time unit modification are properly documented in the changelog.

✅ Verification successful

The changelog is consistent and complete with respect to the time unit changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for mentions of time units in changed files

# Test: Search for mentions of seconds, milliseconds, or time units in changed files
git diff --name-only HEAD~1 | xargs rg -i '(second|millisecond|time unit)'

# Test: Check if there are any other changes in the vesting-related files that might need to be mentioned in the changelog
git diff --name-only HEAD~1 | grep -i 'vesting' | xargs rg -i '(change|update|modify)'

Length of output: 755

contracts/finance/andromeda-vesting/src/state.rs (6)

2-3: Import Milliseconds Type Correctly

The Milliseconds type is imported properly from andromeda_std::common, aligning with the updated time representation in the contract.


23-23: Update Batch Struct Fields to Milliseconds

The fields lockup_end, release_unit, and last_claimed_release_time in the Batch struct are updated to use the Milliseconds type. This enhances time precision and maintains consistency across the contract.

Also applies to: 25-25, 30-30


55-55: Verify Index Ordering with Milliseconds

Ensure that using b.lockup_end.milliseconds() in the index correctly orders the batches as intended. Since Milliseconds is now used, it's important to confirm that the sorting behavior remains consistent.

If you'd like assistance in verifying this, please let me know.


88-88: Update Function Parameter to Milliseconds

The current_time parameter in get_claimable_batches_with_ids is updated to Milliseconds, ensuring consistency in time handling throughout the contract.


94-94: Review Addition of 1 Millisecond to current_time

Adding 1 millisecond to current_time.milliseconds() when calculating max_key may affect batch retrieval logic. Please confirm that this adjustment correctly aligns with the intended time boundary conditions for batch eligibility.


144-170: Tests Updated to Use Milliseconds

The test cases have been appropriately updated to utilize the Milliseconds type and associated methods like plus_seconds and minus_seconds. This ensures that testing accurately reflects the new time unit implementations.

contracts/finance/andromeda-vesting/src/contract.rs (11)

3-5: Import Milliseconds for time-related computations.

The addition of Milliseconds to the imports aligns with the changes to time units in the contract and enhances type safety.


119-119: Convert current time to Milliseconds.

The current time is appropriately converted from seconds to Milliseconds using Milliseconds::from_seconds, ensuring consistency in time calculations.


138-138: Ensure non-zero release_unit and release_amount.

Using is_zero() with the Milliseconds type accurately checks for zero values, preventing invalid batch creations.


171-171: Calculate lockup_end with Milliseconds.

The lockup_end is correctly computed by adding the lockup_duration to current_time using plus_milliseconds, which maintains consistency in time units.


259-264: Compute current_time and up_to_time using Milliseconds.

The calculation of current_time and the determination of up_to_time using Milliseconds ensures that time comparisons are accurate and consistent throughout the function.


275-276: Calculate elapsed time and available claims accurately.

The use of minus_milliseconds and division by milliseconds() correctly computes elapsed_time and num_available_claims, adhering to the updated time unit.


314-314: Convert current time to Milliseconds in claim_batch.

Consistently converting current_time to Milliseconds maintains uniformity in time calculations within the claim_batch function.


322-323: Calculate elapsed_time and num_available_claims with Milliseconds.

The calculations are appropriately adjusted to use Milliseconds, ensuring accurate claim processing.


344-354: Update last_claimed_release_time with proper overflow checks.

The method of calculating claims_release_unit includes necessary overflow checks, and wrapping the result with Milliseconds ensures type safety when updating last_claimed_release_time.


243-243: Update function parameter to Milliseconds.

The execute_claim_all function now takes up_to_time as Option<Milliseconds>. Ensure all invocations of this function are updated to reflect the new parameter type.

Run the following script to find and review function calls:

#!/bin/bash
# Description: Verify all calls to `execute_claim_all` use the updated `Milliseconds` parameter.

rg --type rust 'execute_claim_all' -A 5

106-107: Update function parameters to use Milliseconds.

The function execute_create_batch now accepts lockup_duration as Option<Milliseconds> and release_unit as Milliseconds, which improves clarity and consistency in time representations. Ensure all calls to this function are updated to match the new signature.

Run the following script to verify all function calls:

contracts/finance/andromeda-vesting/src/testing/tests.rs (25)

2-3: Imports updated appropriately

The imports of amp::Recipient, withdraw::WithdrawalType, and Milliseconds are correctly added to support the updated time units and recipient handling.


40-41: Function signature updated to use Milliseconds

The create_batch function now accepts lockup_duration: Option<Milliseconds> and release_unit: Milliseconds, enhancing type safety for time-related parameters in alignment with the PR objectives.


89-89: Test case updated with Milliseconds::from_seconds(1)

In the test_create_batch_unauthorized test, release_unit is correctly updated to use Milliseconds::from_seconds(1), ensuring consistency with the new time unit representation.


108-108: Test case updated with Milliseconds::from_seconds(1)

The test_create_batch_no_funds test accurately updates release_unit to Milliseconds::from_seconds(1), maintaining consistency across test cases.


131-131: Test case updated with Milliseconds::from_seconds(1)

In the test_create_batch_invalid_denom test, the release_unit parameter is correctly updated, reflecting the change to Milliseconds.


154-154: Validation for zero amount handled appropriately

The test_create_batch_valid_denom_zero_amount test correctly uses Milliseconds::from_seconds(1) for release_unit, and appropriately checks for zero amount, ensuring robustness in input validation.


172-172: Validation for zero release_unit

The test_create_batch_release_unit_zero test correctly sets release_unit to Milliseconds::zero(), testing the contract's handling of an invalid zero release unit.


190-190: Validation for zero release_amount

In the test_create_batch_release_amount_zero test, release_unit is properly set to Milliseconds::from_seconds(10), and the test accurately checks for a zero release_amount.


208-208: Test batch creation with valid parameters

The test_create_batch test correctly initializes release_unit with Milliseconds::from_seconds(10) and release_amount, ensuring the batch is created with valid parameters.


213-213: Current time captured using Milliseconds

Capturing the current time with Milliseconds::from_seconds(mock_env().block.time.seconds()) enhances the precision of time tracking in tests.


220-220: Attributes updated to reflect Milliseconds

The add_attribute call correctly converts release_unit to a string using Milliseconds::from_seconds(10).to_string(), ensuring accurate logging.


232-232: Batch struct updated with Milliseconds types

The Batch struct initialization now uses Milliseconds::from_seconds(10) for release_unit, ensuring consistency in time representation.


243-243: Optional lockup_duration using Milliseconds

The lockup_duration parameter is correctly set using Some(Milliseconds::from_seconds(100)), allowing for optional lockup durations with precise time units.


254-255: Attributes reflect adjusted lockup_end and release_unit

The lockup_end and release_unit attributes are accurately represented using Milliseconds, aligning with the updated time unit usage.


266-267: Batch struct correctly handles lockup_end and release_unit

The batch's lockup_end, release_unit, and last_claimed_release_time are properly initialized with Milliseconds, ensuring accurate time tracking.

Also applies to: 269-269


295-296: Batch creation with Milliseconds in multi-batch unsupported test

In test_create_batch_multi_batch_not_supported, lockup_duration and release_unit are correctly set using Milliseconds, complying with the new time unit standards.


301-301: Current time captured using Milliseconds

Consistently capturing the current time enhances test reliability and accuracy.


307-308: Attributes updated with Milliseconds values

The add_attribute calls include lockup_end and release_unit formatted as strings, reflecting the updated time units.


319-320: Batch initialization with updated time units

The batch in test_create_batch_multi_batch_not_supported is initialized with Milliseconds for lockup_end, release_unit, and last_claimed_release_time.

Also applies to: 322-322


360-361: Batch creation with lockup_duration using Milliseconds

The test test_claim_batch_still_locked correctly sets lockup_duration to Some(Milliseconds::from_seconds(100)), verifying lockup behavior with the new time units.


387-387: Test case update with Milliseconds for release_unit

In test_claim_batch_no_funds_available, release_unit is properly updated to Milliseconds::from_seconds(10).


603-605: Batch struct correctly reflects updated release_unit and last_claimed_release_time

The Batch struct in the test accurately uses Milliseconds for release_unit and updates last_claimed_release_time, ensuring consistent time tracking.


729-729: Test correctly advances time using release_unit

In test_claim_batch_multiple_claims, time is advanced using env.block.time.plus_seconds(4 * release_unit.seconds()), which aligns with the Milliseconds usage.


783-783: Batch struct updated after multiple claims

The Batch struct correctly updates amount_claimed and last_claimed_release_time after multiple claims, ensuring correct state management.


993-993: Batch responses accurately reflect Milliseconds usage

In test_claim_all, the BatchResponse structures correctly represent time-related fields using Milliseconds, enhancing consistency.

@@ -411,7 +414,7 @@ fn get_batch_response(
) -> Result<BatchResponse, ContractError> {
let previous_amount = batch.amount_claimed;
let previous_last_claimed_release_time = batch.last_claimed_release_time;
let amount_available_to_claim = if env.block.time.seconds() >= batch.lockup_end {
let amount_available_to_claim = if env.block.time.seconds() >= batch.lockup_end.seconds() {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistent time units in conditional checks.

Comparing env.block.time.seconds() with batch.lockup_end.seconds() might introduce precision issues due to truncation. Consider converting env.block.time to Milliseconds for an accurate comparison.

Apply this change to improve precision:

-let amount_available_to_claim = if env.block.time.seconds() >= batch.lockup_end.seconds() {
+let current_time = Milliseconds::from_seconds(env.block.time.seconds());
+let amount_available_to_claim = if current_time >= batch.lockup_end {

Committable suggestion was skipped due to low confidence.

@@ -406,7 +408,7 @@ fn test_claim_batch_single_claim() {
init(deps.as_mut());
let info = mock_info("owner", &coins(100, "uusd"));

let release_unit = 10;
let release_unit = Milliseconds::from_seconds(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider defining release_unit as a constant

The release_unit is repeatedly defined as Milliseconds::from_seconds(10) across multiple test functions. To improve maintainability and reduce duplication, consider defining release_unit as a constant at the module level.

Apply this diff to define RELEASE_UNIT as a constant:

+const RELEASE_UNIT: Milliseconds = Milliseconds::from_seconds(10);

 // In test functions, replace:
-let release_unit = Milliseconds::from_seconds(10);
+// Use the constant:
+let release_unit = RELEASE_UNIT;

This change promotes consistency and simplifies updates to the release_unit value in the future.

Also applies to: 492-492, 645-645, 711-711, 804-804, 870-870, 947-947

@@ -569,7 +571,7 @@
// Skip time.
let mut env = mock_env();
// Two releases are out.
env.block.time = env.block.time.plus_seconds(2 * release_unit);
env.block.time = env.block.time.plus_seconds(2 * release_unit.seconds());
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Adjust time advancement using Milliseconds

In test_claim_batch_not_nice_numbers_multiple_releases, consider using release_unit directly for time advancement to maintain type consistency.

Apply this diff to update the time advancement:

-env.block.time = env.block.time.plus_seconds(2 * release_unit.seconds());
+env.block.time = env.block.time.plus_milliseconds(2 * release_unit.milliseconds());

This ensures that time calculations remain consistent with the Milliseconds type throughout the test.

📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
env.block.time = env.block.time.plus_seconds(2 * release_unit.seconds());
env.block.time = env.block.time.plus_milliseconds(2 * release_unit.milliseconds());

Comment on lines +554 to 555
let release_unit = Milliseconds::from_seconds(1); // 1 second
let duration: u64 = 60 * 60 * 24 * 365 * 5; // 5 years
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using Milliseconds for duration

Currently, duration is defined as a u64. To maintain type consistency and enhance readability, consider defining duration as a Milliseconds.

Apply this diff to update duration:

-let duration: u64 = 60 * 60 * 24 * 365 * 5; // 5 years
+let duration = Milliseconds::from_seconds(60 * 60 * 24 * 365 * 5); // 5 years

Adjust subsequent code to use duration.seconds() or duration.milliseconds() as needed.

📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let release_unit = Milliseconds::from_seconds(1); // 1 second
let duration: u64 = 60 * 60 * 24 * 365 * 5; // 5 years
let release_unit = Milliseconds::from_seconds(1); // 1 second
let duration = Milliseconds::from_seconds(60 * 60 * 24 * 365 * 5); // 5 years

@cowboy0015 cowboy0015 requested a review from crnbarr93 October 14, 2024 18:48
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 68ca0b9 and 5642e9a.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • contracts/finance/andromeda-vesting/src/contract.rs (12 hunks)
  • contracts/finance/andromeda-vesting/src/mock.rs (0 hunks)
  • contracts/finance/andromeda-vesting/src/state.rs (6 hunks)
  • contracts/finance/andromeda-vesting/src/testing/tests.rs (51 hunks)
  • packages/andromeda-finance/src/vesting.rs (3 hunks)
💤 Files with no reviewable changes (1)
  • contracts/finance/andromeda-vesting/src/mock.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
🧰 Additional context used
🔇 Additional comments (25)
contracts/finance/andromeda-vesting/src/contract.rs (10)

3-5: LGTM: Import of Milliseconds type

The addition of the Milliseconds import from andromeda_std::common is consistent with the PR objective of converting seconds to milliseconds. This change lays the foundation for using the new time unit throughout the contract.


105-106: LGTM: Updated function signature to use Milliseconds

The changes to the execute_create_batch function signature, specifically updating lockup_duration to Option<Milliseconds> and release_unit to Milliseconds, are in line with the PR objective. This ensures consistency in time unit usage throughout the contract.


118-118: LGTM: Conversion of block time to milliseconds

The calculation of current_time using Milliseconds::from_seconds(env.block.time.seconds()) correctly converts the block time from seconds to milliseconds. This change ensures consistency with the new time unit used throughout the contract.


137-137: LGTM: Updated zero check for Milliseconds type

The zero amount check has been correctly updated to use the is_zero() method on the Milliseconds type. This change maintains the existing logic while adapting to the new time unit representation.


170-170: LGTM: Updated time addition using plus_milliseconds

The use of plus_milliseconds for adding the lockup duration to the current time is correct and consistent with the new Milliseconds type. This ensures accurate calculation of the lockup end time.


242-242: LGTM: Updated execute_claim_all to use Milliseconds

The changes in the execute_claim_all function, including the parameter type update and the up_to_time calculation, correctly implement the conversion to milliseconds. The logic remains consistent while adapting to the new time unit representation.

Also applies to: 258-263


274-275: LGTM: Updated time calculations to use Milliseconds methods

The use of minus_milliseconds for time subtraction and the adaptation of the num_available_claims calculation to use milliseconds() are correct and consistent with the new Milliseconds type. These changes ensure accurate time-based calculations in the contract.


313-313: LGTM: Updated claim_batch function to use Milliseconds

The changes in the claim_batch function correctly implement the conversion to milliseconds. The use of Milliseconds methods for time calculations and the added overflow check enhance the accuracy and safety of the time-based operations in the contract.

Also applies to: 321-322, 343-353


Line range hint 1-441: Summary: Successful implementation of milliseconds conversion

The changes in this file successfully implement the conversion from seconds to milliseconds as per the PR objective. The use of the Milliseconds type is consistent throughout the contract, ensuring improved precision in time-based calculations and comparisons. All modified segments have been reviewed and approved.

One existing precision issue was noted and a suggestion for improvement has been provided. Overall, the changes enhance the contract's handling of time-related operations and align with the stated goals of the pull request.


416-416: ⚠️ Potential issue

Consider addressing the precision issue in time comparison

There's an existing potential precision issue in the comparison between env.block.time.seconds() and batch.lockup_end.seconds(). This comparison might introduce inaccuracies due to the loss of millisecond precision when converting to seconds.

Consider updating this comparison to use milliseconds for improved precision:

-let amount_available_to_claim = if env.block.time.seconds() >= batch.lockup_end.seconds() {
+let current_time = Milliseconds::from_seconds(env.block.time.seconds());
+let amount_available_to_claim = if current_time >= batch.lockup_end {

This change would ensure consistent precision in time comparisons throughout the contract.

packages/andromeda-finance/src/vesting.rs (5)

2-4: Import Milliseconds for time precision

Adding Milliseconds to the imports ensures that time-related parameters throughout the contract use a consistent and precise type, enhancing readability and reducing potential errors.


34-34: Update up_to_time to use Milliseconds

Updating up_to_time to Option<Milliseconds> in the ClaimAll message enhances type safety and aligns with the contract's use of milliseconds for time measurements.


40-42: Consistent time units in CreateBatch

Changing lockup_duration and release_unit to Milliseconds in the CreateBatch message improves consistency across the contract and ensures precise time calculations.


88-95: Use Milliseconds in BatchResponse fields

Updating lockup_end, release_unit, and last_claimed_release_time to Milliseconds in the BatchResponse struct ensures that all time-related fields use the same unit, improving consistency and reducing potential confusion.


Line range hint 34-95: Verify all time-related types are updated to Milliseconds

While the update to Milliseconds enhances precision, please ensure that all references to these fields throughout the codebase have been updated accordingly to prevent type mismatches or serialization issues.

Run the following script to identify any remaining usages of u64 for time-related parameters:

contracts/finance/andromeda-vesting/src/state.rs (7)

2-5: Imports updated to include necessary modules

The imports have been correctly updated to include WithdrawalType and Milliseconds from andromeda_std::common, which are required for the updated time handling and withdrawal logic.


7-7: Usage of cosmwasm_std imports is appropriate

The import statement for cosmwasm_std::{Order, Storage, Uint128} has been updated appropriately to support the changes in the code.


23-23: Time fields in Batch struct updated to Milliseconds

The fields lockup_end, release_unit, and last_claimed_release_time in the Batch struct have been updated to use the Milliseconds type. This enhances time precision and consistency across the contract.

Also applies to: 25-25, 30-30


55-55: Indexing adjusted for Milliseconds type

In the claim_time index, the code now uses b.lockup_end.milliseconds(). This ensures that the index operates correctly with the new Milliseconds type by accessing the underlying millisecond value.


137-163: Tests updated to reflect Milliseconds changes

In the test_get_claimable_batches_with_ids function, current_time is correctly initialized using Milliseconds::from_seconds. Time fields in the test batches have been updated to use Milliseconds, and methods like plus_seconds and minus_seconds are used appropriately.


81-87: get_claimable_batches_with_ids now uses Milliseconds

The get_claimable_batches_with_ids function has been updated to accept current_time as Milliseconds. The calculation of max_key has been adjusted to use current_time.milliseconds() + 1, ensuring correct comparison logic.

Run the following script to check all calls to get_claimable_batches_with_ids:

✅ Verification successful

All calls to get_claimable_batches_with_ids correctly pass Milliseconds as the current_time parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that all calls to get_claimable_batches_with_ids pass Milliseconds
rg --type rust 'get_claimable_batches_with_ids\(' -A 3 -B 3

Length of output: 2668


64-64: ⚠️ Potential issue

Function save_new_batch signature modified

The save_new_batch function no longer accepts the config parameter. Since config was previously used to check if multi-batch functionality was enabled, please ensure that this change aligns with the intended functionality and that any related logic has been appropriately refactored.

Run the following script to find and review all calls to save_new_batch:

✅ Verification successful

Function save_new_batch signature modification verified

All usages of save_new_batch have been updated to match the new function signature without the config parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of save_new_batch to verify function calls
rg --type rust 'save_new_batch\(' -A 3 -B 3

Length of output: 1174

contracts/finance/andromeda-vesting/src/testing/tests.rs (3)

2-3: Imports updated appropriately to include necessary modules

The addition of amp::Recipient and common::{withdraw::WithdrawalType, Milliseconds} ensures that the necessary types are available for the updated code.


39-40: Function signature updated to enhance type safety

The create_batch function now accepts lockup_duration: Option<Milliseconds> and release_unit: Milliseconds, which improves type safety and consistency in time-related parameters.


87-87: Consistent use of Milliseconds::from_seconds in test cases

Using Milliseconds::from_seconds(...) for release_unit in test cases enhances readability and maintains consistency across the codebase.

Also applies to: 106-106, 129-129, 152-152, 170-170, 188-188, 206-206

@@ -663,14 +605,14 @@ fn test_claim_batch_middle_of_interval() {

let mut env = mock_env();
// Only halfway to first release.
env.block.time = env.block.time.plus_seconds(release_unit / 2);
env.block.time = env.block.time.plus_seconds(release_unit.seconds() / 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential integer division leading to zero time advancement

Dividing release_unit.seconds() by 2 may cause integer truncation, resulting in zero when release_unit.seconds() is an odd number (e.g., 1 second). This could lead to the block time not advancing as intended.

Apply this diff to use milliseconds for precise time advancement:

-env.block.time = env.block.time.plus_seconds(release_unit.seconds() / 2);
+env.block.time = env.block.time.plus_milliseconds(release_unit.milliseconds() / 2);
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
env.block.time = env.block.time.plus_seconds(release_unit.seconds() / 2);
env.block.time = env.block.time.plus_milliseconds(release_unit.milliseconds() / 2);

@@ -952,17 +894,22 @@
create_batch(
deps.as_mut(),
None,
release_unit / 2,
Milliseconds::from_seconds(release_unit.seconds() / 2),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid loss of precision when creating half release_unit

Using integer division in Milliseconds::from_seconds(release_unit.seconds() / 2) may lead to unintended zero or incorrect duration due to truncation. To maintain accuracy, calculate using milliseconds.

Apply this diff to correctly compute half of release_unit:

-create_batch(
    deps.as_mut(),
    None,
-   Milliseconds::from_seconds(release_unit.seconds() / 2),
+   Milliseconds::from_milliseconds(release_unit.milliseconds() / 2),
    release_amount.clone(),
);

Committable suggestion was skipped due to low confidence.

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 (4)
contracts/finance/andromeda-vesting/src/testing/tests.rs (4)

Line range hint 202-263: LGTM: Time-related parameters updated to use Milliseconds

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations. The addition of current_time using Milliseconds is a good practice for consistency.

Consider extracting the Milliseconds::from_seconds(10) into a constant at the beginning of the test function to improve readability and maintainability. For example:

let release_unit = Milliseconds::from_seconds(10);

Then use release_unit throughout the test instead of repeating Milliseconds::from_seconds(10).


Line range hint 490-569: LGTM with suggestion: Consistent use of Milliseconds, but duration can be improved

The changes in this test function correctly implement the use of Milliseconds for most time-related parameters and calculations. However, there's an opportunity for improvement:

Consider updating the duration variable to use Milliseconds for consistency:

-let duration: u64 = 60 * 60 * 24 * 365 * 5; // 5 years
+let duration = Milliseconds::from_seconds(60 * 60 * 24 * 365 * 5); // 5 years

Then, update subsequent uses of duration to call .seconds() or .milliseconds() as needed.


Line range hint 581-635: LGTM with suggestion: Use of Milliseconds is consistent, but division might lose precision

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations. However, there's a potential issue:

On line 604, the division release_unit.seconds() / 2 might lead to precision loss if release_unit.seconds() is an odd number. Consider using milliseconds for more precise calculations:

-env.block.time = env.block.time.plus_seconds(release_unit.seconds() / 2);
+env.block.time = env.block.time.plus_milliseconds(release_unit.milliseconds() / 2);

This ensures that you're always advancing time by exactly half of the release unit, even if it's an odd number of seconds.


Line range hint 883-974: LGTM with suggestion: Consistent use of Milliseconds, but potential precision loss

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations, maintaining consistency with the updated type system. However, there's a potential issue:

On line 893, creating a batch with half of the release_unit using Milliseconds::from_seconds(release_unit.seconds() / 2) might lead to precision loss if release_unit.seconds() is an odd number. Consider using milliseconds for more precise calculations:

-Milliseconds::from_seconds(release_unit.seconds() / 2),
+Milliseconds::from_milliseconds(release_unit.milliseconds() / 2),

This ensures that you're always using exactly half of the release unit, even if it's an odd number of seconds.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5642e9a and d9f6ef5.

📒 Files selected for processing (4)
  • contracts/finance/andromeda-vesting/src/mock.rs (1 hunks)
  • contracts/finance/andromeda-vesting/src/testing/tests.rs (51 hunks)
  • packages/andromeda-finance/src/vesting.rs (3 hunks)
  • packages/std/src/error.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/std/src/error.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/andromeda-finance/src/vesting.rs
🧰 Additional context used
🔇 Additional comments (12)
contracts/finance/andromeda-vesting/src/mock.rs (2)

27-27: LGTM: Changes align with PR objectives

The removal of is_multi_batch_enabled and unbonding_duration parameters from the instantiate method and the corresponding update to the mock_vesting_instantiate_msg call align well with the PR objectives. This change simplifies the contract instantiation process and removes the unnecessary batch flag as intended.


Line range hint 45-55: LGTM: Consistent changes, verify test coverage

The updates to mock_vesting_instantiate_msg function are consistent with the changes made to the instantiate method. Removing is_multi_batch_enabled and unbonding_duration parameters aligns with the PR objectives to simplify the contract and remove the unnecessary batch flag.

To ensure these changes don't negatively impact existing functionality:

Please review the test results to ensure all tests are passing and that there are no unexpected references to the removed parameters.

contracts/finance/andromeda-vesting/src/testing/tests.rs (10)

3-3: LGTM: Import of Milliseconds added

The addition of Milliseconds import is consistent with the PR objectives to use milliseconds instead of seconds for time-related parameters.


35-36: LGTM: Function signature updated to use Milliseconds

The changes to the create_batch function signature, replacing u64 with Milliseconds for lockup_duration and release_unit, are in line with the PR objectives to use milliseconds for time-related parameters.


166-166: LGTM: release_unit updated to use Milliseconds::zero()

The change from release_unit: 0 to release_unit: Milliseconds::zero() correctly implements the new Milliseconds type for the release_unit parameter, maintaining consistency with the updated type system.


Line range hint 347-416: LGTM: Consistent use of Milliseconds for time-related operations

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations. The addition of release_unit as a variable improves readability and consistency throughout the test.


Line range hint 428-477: LGTM: Consistent implementation of Milliseconds for time calculations

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations, maintaining consistency with the updated type system throughout the test.


Line range hint 647-728: LGTM: Consistent implementation of Milliseconds for time calculations

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations. The use of release_unit improves readability and maintains consistency with the updated type system throughout the test.


Line range hint 740-789: LGTM: Consistent use of Milliseconds for time-related operations

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations. The addition of release_unit as a variable improves readability and maintains consistency with the updated type system throughout the test.


Line range hint 806-855: LGTM: Consistent implementation of Milliseconds for time calculations

The changes in this test function correctly implement the use of Milliseconds for time-related parameters and calculations. The use of release_unit improves readability and maintains consistency with the updated type system throughout the test.


Line range hint 1001-1033: LGTM: Consistent implementation of Milliseconds for time calculations

The changes in this latter part of the test_claim_all function correctly implement the use of Milliseconds for time-related parameters and calculations. This maintains consistency with the updated type system throughout the test.


Line range hint 1-1033: Overall assessment: Successfully implemented Milliseconds with minor suggestions for improvement

The changes in this file successfully implement the use of Milliseconds for time-related parameters and calculations throughout the test suite. This aligns well with the PR objectives to use milliseconds instead of seconds for better precision and consistency with other ADOs.

Key points:

  1. All time-related parameters now use the Milliseconds type.
  2. Time calculations and comparisons have been updated to work with Milliseconds.
  3. The changes maintain consistency across all test functions.

Minor suggestions for improvement:

  1. Consider using a constant for repeated Milliseconds::from_seconds(10) in some test functions.
  2. Update the duration variable in test_claim_batch_not_nice_numbers_multiple_releases to use Milliseconds.
  3. Be cautious of potential precision loss when dividing seconds, especially when creating half intervals. Consider using milliseconds for these calculations.

These changes significantly enhance the handling of time units in the vesting contract's testing framework, improving type safety and precision.

Copy link
Contributor

@crnbarr93 crnbarr93 left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants