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: Multiple Rates #517

Closed
wants to merge 7 commits into from
Closed

feat: Multiple Rates #517

wants to merge 7 commits into from

Conversation

joemonem
Copy link
Contributor

@joemonem joemonem commented Jul 19, 2024

Motivation

Allow multiple rates to be set per action.

Implementation

Each action now has a corresponding Vec<Rate> instead of Rate
Changes have been made to query_deducted_funds to accommodate multiple rates:

                let mut all_msgs = vec![];
                let mut all_events = vec![];
                let mut all_leftover_funds = vec![];
                for rate in rates {
                    let (mut msgs, mut events, mut leftover_funds) = match rate {
                        Rate::Local(local_rate) => {
                            local_rate.generate_response(deps, coin.clone(), is_native)?
                        }
                        Rate::Contract(rates_address) => {
                            // Query rates contract
                            let addr = rates_address.get_raw_address(&deps)?;
                            let rate = AOSQuerier::get_rate(&deps.querier, &addr, &action)?;
                            rate.generate_response(deps, coin.clone(), is_native)?
                        }
                    };
                    all_msgs.append(&mut msgs);
                    all_events.append(&mut events);
                    all_leftover_funds.append(&mut leftover_funds);
                }
                let total_dedcuted_funds: Uint128 = all_leftover_funds
                    .iter()
                    .map(|x| coin.amount - x.amount)
                    .sum();
                let total_funds = coin.amount.checked_sub(total_dedcuted_funds)?;

Testing

The auction integration test was adjusted to have multiple rates:

vec![
                Rate::Local(LocalRate {
                    rate_type: LocalRateType::Deductive,
                    recipients: vec![
                        Recipient::new(recipient_one, None),
                        Recipient::new(recipient_two, None),
                    ],
                    value: LocalRateValue::Percent(PercentRate {
                        percent: Decimal::percent(25),
                    }),
                    description: None,
                }),
                Rate::Local(LocalRate {
                    rate_type: LocalRateType::Deductive,
                    recipients: vec![
                        Recipient::new(recipient_one, None),
                        Recipient::new(recipient_two, None),
                    ],
                    value: LocalRateValue::Percent(PercentRate {
                        percent: Decimal::percent(10),
                    }),
                    description: None,
                }),
            ]

In that test, the sent funds were 100. Adding the second rate resulted in an additional 10 coins being sent to recipient_one and recipient_two, alongside a decrease of 20 coins to the owner's balance.

Version Changes

No version changes have been made yet. Should the version bump be for all the contracts which use rates or just andromeda-std?

Notes

remove_rates removes the entire vector of rates.
If a user wants to modify the rates without removing them all, set_rate can be used since the new rates overwrite the old ones.
We should test scenarios like a mix of taxes and royalties, insufficient funds to cover all the taxes, and other possible edge cases.
The rates contract still only holds one LocalRate per action, but now multiple rates contracts can be referenced simultaneously.

Summary by CodeRabbit

  • New Features
    • Enhanced rate processing capability by allowing multiple rates to be handled in a single execution context across various components.
    • Updated RatesMessage and associated functions to support batch processing of rates.
    • Added documentation entry for the "Multiple Rates" update in the CHANGELOG.
  • Bug Fixes
    • Improved rate validation logic to ensure all rates are processed before execution.
  • Tests
    • Modified tests to reflect changes in rate structures, ensuring proper validation of the new multi-rate handling functionality.

@joemonem joemonem requested review from crnbarr93 and cowboy0015 July 19, 2024 08:05
Copy link
Contributor

coderabbitai bot commented Jul 19, 2024

Walkthrough

The recent changes enhance the handling of rates across multiple contracts by transitioning from single Rate instances to vectors (Vec<Rate>). This change allows for batch processing of rates, significantly improving flexibility and enabling the management of multiple rates simultaneously. Key updates include modifications to function signatures, message structures, and testing logic, ultimately enriching the contracts' functionality and adaptability in varied scenarios.

Changes

Files Change Summary
contracts/data-storage/.../execute.rs
contracts/data-storage/.../mock.rs
contracts/data-storage/.../testing/tests.rs
Updated to handle multiple rates (Vec<Rate>) instead of a single rate across execution and mocking functions.
contracts/fungible-tokens/.../mock.rs
contracts/fungible-tokens/.../testing/tests.rs
Similar updates for rate handling in execution and test functions, changing parameters to accept vectors.
contracts/non-fungible-tokens/.../mock.rs
contracts/non-fungible-tokens/.../testing/tests.rs
Modified to utilize vectors of rates in mock and test implementations, enhancing rate management.
contracts/non-fungible-tokens/.../marketplace/src/mock.rs
contracts/non-fungible-tokens/.../marketplace/src/testing/tests.rs
Adjusted to support vectors for rates in method signatures and test cases, improving flexibility.
packages/std/src/.../rates.rs
packages/std/src/.../rates.rs
Enum RatesMessage modified to include vectors; functions updated to accommodate multiple rates.
packages/std/src/.../ado_contract/rates.rs ADOContract methods updated to handle collections of rates, improving management and flexibility.
tests-integration/tests/.../auction_app.rs Test updates to include multiple rates, reflecting changes in expected distributions and balances.
tests-integration/tests/.../cw20_app.rs Modified to handle rate vectors in testing, allowing for more flexible rate configurations.
tests-integration/tests/.../marketplace_app.rs Adjustments made to utilize vectors for Rate::Contract in function calls, increasing function flexibility.
tests-integration/tests/.../primitive.rs Changes made to wrap Rate::Local instances in vectors for consistency with new handling logic.
CHANGELOG.md Added entry for "Multiple Rates" associated with pull request #517 to document the new feature.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    participant MessageHandler
    participant RateProcessor
    
    User->>Contract: Send RatesMessage(SetRate)
    Contract->>MessageHandler: Process RatesMessage
    MessageHandler->>RateProcessor: Execute with Vec<Rate>
    RateProcessor->>RateProcessor: Validate each Rate
    RateProcessor-->>MessageHandler: Return results
    MessageHandler-->>Contract: Response to User
Loading

🐰 Hopping through the fields so bright,
Rates gathered up, what a lovely sight!
From one to many, a grand new way,
Flexibility blooms in the light of day!
Let’s set the rates, let creativity soar,
In our contract garden, there’s always more! 🌼


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

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit 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: 0

Outside diff range, codebase verification and nitpick comments (2)
contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs (1)

Issues Found: Inconsistent Usage of New set_rates Signature

The following instances of set_rates do not use the new signature with Vec<Rate>:

  • contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs
    • Lines: 1-5, 8-12
  • contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs
    • Lines: 1-5, 8-12, 15-19
  • contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs
    • Lines: 1-5, 8-12, 15-19
  • contracts/data-storage/andromeda-primitive/src/testing/tests.rs
    • Lines: 1-5

Please update these instances to match the new signature with Vec<Rate>.

Analysis chain

Line range hint 790-801:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to set_rates match the new signature with a vector of rates.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `set_rates` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'set_rates'

Length of output: 9535


Script:

#!/bin/bash
# Description: Verify that all instances of `set_rates` use the new signature with `Vec<Rate>`.

# Check if all `set_rates` function calls use the new signature with `Vec<Rate>`.
rg --type rust --pcre2 'set_rates\(\s*deps\.as_mut\(\)\.storage,\s*"[A-Za-z]+",\s*vec!\['

Length of output: 91


Script:

#!/bin/bash
# Description: Verify that all instances of `set_rates` use the new signature with `Vec<Rate>`.

# Check if all `set_rates` function calls use the new signature with `Vec<Rate>`.
rg --type rust 'set_rates\(\s*deps\.as_mut\(\)\.storage,\s*".*",\s*\w+\s*\)' -A 3

Length of output: 4144

tests-integration/tests/marketplace_app.rs (1)

568-568: Inconsistent function signature for execute_set_rate

The function execute_set_rate has been updated to accept a vector of rates in some parts of the codebase, but not consistently.

  • contracts/modules/andromeda-rates/src/contract.rs still uses the old signature with a single rate.

Please update the function signature in contracts/modules/andromeda-rates/src/contract.rs to match the new signature that accepts a vector of rates.

Analysis chain

LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_set_rate match the new signature with a vector of rates.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `execute_set_rate` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'execute_set_rate'

Length of output: 3712

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73c76db and 6d63b30.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (16)
  • contracts/data-storage/andromeda-primitive/src/execute.rs (1 hunks)
  • contracts/data-storage/andromeda-primitive/src/mock.rs (2 hunks)
  • contracts/data-storage/andromeda-primitive/src/testing/tests.rs (3 hunks)
  • contracts/fungible-tokens/andromeda-cw20/src/mock.rs (2 hunks)
  • contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs (4 hunks)
  • contracts/non-fungible-tokens/andromeda-auction/src/mock.rs (2 hunks)
  • contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs (6 hunks)
  • contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs (2 hunks)
  • contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs (6 hunks)
  • packages/std/src/ado_base/rates.rs (1 hunks)
  • packages/std/src/ado_contract/rates.rs (8 hunks)
  • packages/std/src/ado_contract/state.rs (1 hunks)
  • tests-integration/tests/auction_app.rs (2 hunks)
  • tests-integration/tests/cw20_app.rs (2 hunks)
  • tests-integration/tests/marketplace_app.rs (4 hunks)
  • tests-integration/tests/primitive.rs (2 hunks)
Additional comments not posted (34)
packages/std/src/ado_contract/state.rs (1)

16-16: LGTM! But verify the usage of the rates field in the codebase.

The change to store multiple rates per action enhances flexibility.

However, ensure that all usages of the rates field are compatible with the new type.

contracts/data-storage/andromeda-primitive/src/mock.rs (2)

64-66: LGTM!

The change to accept a vector of Rate objects enhances flexibility.


112-113: LGTM!

The change to accept a vector of Rate objects enhances flexibility.

tests-integration/tests/cw20_app.rs (1)

Line range hint 102-112:
LGTM!

The change to wrap the Rate::Local instantiation in a vector enhances flexibility and is consistent with the updated functionality.

contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs (2)

66-68: LGTM!

The function execute_set_rate has been updated to accept a Vec<Rate>, which aligns with the new requirement to handle multiple rates.


153-156: LGTM!

The function mock_set_rates has been updated to accept a Vec<Rate>, which aligns with the new requirement to handle multiple rates.

contracts/data-storage/andromeda-primitive/src/execute.rs (1)

37-47: LGTM!

The function handle_execute has been updated to handle multiple rates. The logic iterates through each rate and validates it before executing the contract. This change is consistent with the new requirement to handle multiple rates.

contracts/fungible-tokens/andromeda-cw20/src/mock.rs (2)

126-128: LGTM!

The function execute_add_rate has been updated to accept a Vec<Rate>, which aligns with the new requirement to handle multiple rates.


223-224: LGTM!

The function mock_set_rate_msg has been updated to accept a Vec<Rate>, which aligns with the new requirement to handle multiple rates.

tests-integration/tests/primitive.rs (2)

87-94: LGTM! The change to wrap Rate::Local(LocalRate) in a vector is consistent with the new structure.

The test logic for adding a percentage rate remains valid.


107-112: LGTM! The change to wrap Rate::Local(LocalRate) in a vector is consistent with the new structure.

The test logic for adding a flat rate remains valid.

contracts/non-fungible-tokens/andromeda-auction/src/mock.rs (2)

110-112: LGTM! The change to update the function parameter to accept a vector of Rate objects is consistent with the new structure.

The function call and internal logic remain valid.


232-233: LGTM! The change to update the function parameter to accept a vector of Rate objects is consistent with the new structure.

The message construction logic remains valid.

packages/std/src/ado_base/rates.rs (1)

31-31: LGTM! The change to modify the SetRate variant to accept a vector of Rate objects is consistent with the new structure.

The enum variant and related logic remain valid.

packages/std/src/ado_contract/rates.rs (7)

15-17: LGTM!

The function rates has been updated to return Map<'a, &'a str, Vec<Rate>> to handle multiple rates. This change is correct and aligns with the new requirement.


23-28: LGTM!

The function set_rates has been updated to accept a Vec<Rate> instead of a single Rate. This change is correct and aligns with the new requirement.


35-37: LGTM!

The function execute_rates has been updated to handle RatesMessage::SetRate with a Vec<Rate>. This change is correct and aligns with the new requirement.


43-56: LGTM!

The function execute_set_rates has been updated to accept a Vec<Rate> instead of a single Rate. The function validates each rate and saves them to storage. This change is correct and aligns with the new requirement.


Line range hint 105-166: LGTM!

The function query_deducted_funds has been updated to handle multiple rates. The function iterates over each rate and generates corresponding messages, events, and leftover funds. This change is correct and aligns with the new requirement.


91-93: LGTM!

The function get_rates has been updated to return Option<Vec<Rate>> instead of Option<Rate>. This change is correct and aligns with the new requirement.


Line range hint 200-209: LGTM!

The test test_rates_crud has been updated to handle multiple rates. The test correctly sets, gets, and removes multiple rates. This change is correct and aligns with the new requirement.

contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs (2)

Line range hint 90-101: LGTM!

The function test_transfer has been updated to handle multiple rates by wrapping Rate::Local instances in a vec![]. This change is correct and aligns with the new requirement.


Line range hint 196-207: LGTM!

The function test_send has been updated to handle multiple rates by wrapping Rate::Local instances in a vec![]. This change is correct and aligns with the new requirement.

contracts/data-storage/andromeda-primitive/src/testing/tests.rs (2)

73-80: LGTM!

The function test_set_value_with_tax has been updated to handle multiple rates by wrapping Rate::Local instances in a vec![]. This change is correct and aligns with the new requirement.


Line range hint 93-102: LGTM!

The function test_set_value_with_tax has been updated to handle multiple rates by wrapping Rate::Local instances in a vec![]. This change is correct and aligns with the new requirement.

contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs (2)

Line range hint 713-724:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to set_rates match the new signature with a vector of rates.

Verification successful

Function usage verification successful.

All instances of the set_rates function call match the new signature with a vector of rates.

  • Verified locations:
    • packages/std/src/ado_contract/rates.rs
    • contracts/data-storage/andromeda-primitive/src/testing/tests.rs
    • contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs
    • contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs
    • contracts/non-fungible-tokens/andromeda-cw721/src/testing/mod.rs
    • contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs
    • contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `set_rates` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'set_rates'

Length of output: 9535


Line range hint 658-669:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to set_rates match the new signature with a vector of rates.

Verification successful

The new signature of set_rates is consistently used throughout the codebase.

The changes are correctly propagated and match the new functionality of handling multiple rates. No further action is required.

  • Verified in:
    • contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs
    • contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs
    • contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs
    • contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs
    • packages/std/src/ado_contract/rates.rs
    • contracts/data-storage/andromeda-primitive/src/testing/tests.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `set_rates` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'set_rates'

Length of output: 9535

tests-integration/tests/marketplace_app.rs (2)

140-140: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_set_rate match the new signature with a vector of rates.


866-866: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_set_rate match the new signature with a vector of rates.

Verification successful

Verify all instances of execute_set_rate and execute_set_rates conform to the new signature.

The code changes are approved.

However, ensure that all instances of execute_set_rate and execute_set_rates match the new signature with a vector of rates.


All instances of execute_set_rate and execute_set_rates conform to the new signature.

The code changes are approved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `execute_set_rate` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'execute_set_rate'

Length of output: 3712


Script:

#!/bin/bash
# Description: Verify all instances of `execute_set_rate` and `execute_set_rates` conform to the new signature.

# Test: Search for the function definitions and usages in the mentioned files.

# Verify function definitions
echo "Function definitions:"
rg --type rust -A 5 $'fn execute_set_rate' packages/std/src/ado_contract/rates.rs contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs contracts/modules/andromeda-rates/src/contract.rs
rg --type rust -A 5 $'fn execute_set_rates' packages/std/src/ado_contract/rates.rs

# Verify function usages
echo "Function usages:"
rg --type rust -A 5 $'execute_set_rate' packages/std/src/ado_contract/rates.rs contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs contracts/modules/andromeda-rates/src/contract.rs
rg --type rust -A 5 $'execute_set_rates' packages/std/src/ado_contract/rates.rs

Length of output: 4961

tests-integration/tests/auction_app.rs (2)

238-242: Update balance assertions to reflect new rate structure.

The balance assertions have been updated to reflect the new distribution of values among the involved parties.


120-143: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_add_rate match the new signature with a vector of rates.

Verification successful

All occurrences of execute_add_rate match the new signature.

The function calls to execute_add_rate across various files have been verified to match the new signature that includes a vector of rates.

  • tests-integration/tests/primitive.rs
  • tests-integration/tests/cw20_app.rs
  • tests-integration/tests/auction_app.rs
  • contracts/non-fungible-tokens/andromeda-auction/src/mock.rs
  • contracts/data-storage/andromeda-primitive/src/mock.rs
  • contracts/fungible-tokens/andromeda-cw20/src/mock.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `execute_add_rate` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type rust -A 5 $'execute_add_rate'

Length of output: 3197

contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs (3)

Line range hint 1490-1501:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_claim_cw20_with_tax match the new rate data structure.

Verification successful

No further verification needed.

The function execute_claim_cw20_with_tax is not called elsewhere in the codebase, confirming that the changes to the rate data structure are self-contained. Therefore, no additional verification is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `execute_claim_cw20_with_tax` match the new `rate` data structure.

# Test: Search for the function usage. Expect: Only occurrences of the new data structure.
rg --type rust -A 5 $'execute_claim_cw20_with_tax'

Length of output: 710


Script:

#!/bin/bash
# Description: Search for all instances where `execute_claim_cw20_with_tax` is called in the codebase.

# Test: Search for function calls. Expect: Only occurrences of the new data structure.
rg --type rust 'execute_claim_cw20_with_tax\('

Length of output: 152


Line range hint 1241-1250:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_claim_with_tax match the new rate data structure.

Verification successful

No issues found with the function usage.

The function execute_claim_with_tax is not called within the codebase, so there are no external usages to verify against the new rate data structure.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `execute_claim_with_tax` match the new `rate` data structure.

# Test: Search for the function usage. Expect: Only occurrences of the new data structure.
rg --type rust -A 5 $'execute_claim_with_tax'

Length of output: 646


Script:

#!/bin/bash
# Description: Find all call sites of `execute_claim_with_tax` and verify the `rate` data structure usage.

# Search for all call sites of `execute_claim_with_tax`
rg 'execute_claim_with_tax\(' --type rust -A 5

Length of output: 650


Script:

#!/bin/bash
# Description: Find all call sites of `execute_claim_with_tax` with extended context to ensure no call sites are missed.

# Search for all call sites of `execute_claim_with_tax` with extended context
rg 'execute_claim_with_tax\(' --type rust -A 10

Length of output: 1215


Line range hint 1328-1337:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to execute_claim_with_royalty match the new rate data structure.

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 6d63b30 and ef7c5dd.

Files selected for processing (13)
  • contracts/data-storage/andromeda-primitive/src/execute.rs (1 hunks)
  • contracts/data-storage/andromeda-primitive/src/testing/tests.rs (4 hunks)
  • contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs (4 hunks)
  • contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs (6 hunks)
  • contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs (2 hunks)
  • contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs (6 hunks)
  • packages/std/src/ado_base/rates.rs (2 hunks)
  • packages/std/src/ado_contract/execute.rs (2 hunks)
  • packages/std/src/ado_contract/rates.rs (7 hunks)
  • tests-integration/tests/auction_app.rs (2 hunks)
  • tests-integration/tests/cw20_app.rs (2 hunks)
  • tests-integration/tests/marketplace_app.rs (4 hunks)
  • tests-integration/tests/primitive.rs (2 hunks)
Additional comments not posted (28)
tests-integration/tests/cw20_app.rs (1)

Line range hint 102-112:
Ensure comprehensive test coverage for multiple rates.

The change from a single Rate::Local to a vector of rates is consistent with the PR's objective to handle multiple rates. Ensure that the test thoroughly checks scenarios with multiple rates, including edge cases such as zero rates and conflicting rates.

Verification successful

Comprehensive test coverage for multiple rates is present in the codebase. Although the cw20_app.rs file does not explicitly include tests for multiple Rate::Local instances, other test files such as those in the andromeda-marketplace, andromeda-auction, and andromeda-primitive directories do cover these scenarios. This indicates that the functionality for handling multiple rates is being tested elsewhere.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the test covers multiple rates scenarios.

# Test: Search for test functions that handle multiple rates. Expect: Comprehensive test cases.
rg --type rust 'test_cw20_with_rates' -A 10 | rg 'vec!\[Rate::Local'

Length of output: 68


Script:

#!/bin/bash
# Search for test functions in the tests-integration/tests/cw20_app.rs file that involve multiple Rate::Local instances.
fd 'cw20_app.rs' | xargs rg 'fn ' -A 10 | rg 'vec!\[Rate::Local'

Length of output: 64


Script:

#!/bin/bash
# Search for test functions across the tests-integration/tests directory that might involve multiple rates.
fd 'tests' | xargs rg 'fn ' -A 20 | rg 'Rate::Local'

Length of output: 848

contracts/non-fungible-tokens/andromeda-marketplace/src/mock.rs (2)

68-70: Adapt to handle multiple rates in execute_set_rate.

The execute_set_rate function now accepts a vector of rates, aligning with the PR's objective. Ensure that the logic within the function and any dependent components correctly processes each rate in the vector.


165-168: Update mock_set_rates to handle multiple rates.

The mock_set_rates function now accepts a Vec<Rate>, which enhances flexibility. Verify that all usages of this function are updated to pass vectors of rates, ensuring consistency across the codebase.

Verification successful

All usages of mock_set_rates are consistent with vector inputs.

The mock_set_rates function is used only once in the codebase, and it is correctly passed a vector of rates. No further updates are needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all usages of `mock_set_rates` are updated to pass vectors of rates.

# Test: Search for `mock_set_rates` function calls. Expect: Updated calls with vectors.
rg --type rust 'mock_set_rates' -A 5

Length of output: 1157


Script:

#!/bin/bash
# Search for all instances of `mock_set_rates` across the codebase to verify consistent usage.
rg 'mock_set_rates' --type rust -A 5

Length of output: 1157

contracts/data-storage/andromeda-primitive/src/execute.rs (1)

33-43: Verify rate processing logic in handle_execute.

The handle_execute function now processes multiple rates, maintaining validation for Rate::Local. Ensure that the logic correctly handles different rate types and that the validation for local rates is robust.

tests-integration/tests/primitive.rs (2)

87-94: Ensure handling of multiple rates in tests.

The change to wrap Rate::Local in a vector aligns with the new functionality of handling multiple rates. Ensure that the test logic correctly processes this vector and that assertions reflect the expected outcomes for multiple rates.


107-112: Confirm correct integration of multiple rates.

The wrapping of Rate::Local in a vector is consistent with the updated functionality. Ensure that the test scenarios adequately cover the implications of handling multiple rates.

packages/std/src/ado_base/rates.rs (2)

31-31: Verify handling of multiple rates in SetRate.

The SetRate variant now accepts a vector of rates, enhancing flexibility. Ensure that the logic processing this variant correctly handles multiple rates and that any related functions are updated accordingly.


251-251: Ensure correct handling of AllRatesResponse.

The all_rates field now holds a vector of tuples with vectors of rates, allowing for more complex rate management. Verify that the response handling logic is updated to accommodate this change and that all related functionality is tested.

contracts/fungible-tokens/andromeda-cw20/src/testing/tests.rs (2)

Line range hint 90-101: Validate handling of multiple rates in test_transfer.

The change to use a vector for Rate::Local aligns with the updated functionality. Ensure that the test logic correctly processes this vector and that assertions are updated to reflect the expected outcomes for multiple rates.


Line range hint 196-207: Confirm correct integration of multiple rates in test_send.

The wrapping of Rate::Local in a vector is consistent with the updated functionality. Ensure that the test scenarios adequately cover the implications of handling multiple rates and that assertions are updated accordingly.

packages/std/src/ado_contract/rates.rs (5)

13-15: LGTM!

The change to return a Map with Vec<Rate> aligns with the objective of supporting multiple rates.


29-60: LGTM!

The function correctly processes multiple rates, validating each and updating recipients as needed.


93-98: LGTM!

The function correctly retrieves a vector of rates for a given action.


Line range hint 103-115: LGTM!

The function correctly aggregates all rates into a vector of tuples, supporting the new multiple rates structure.


Line range hint 122-188: LGTM!

The function effectively processes multiple rates, calculating deducted funds and generating the appropriate response.

packages/std/src/ado_contract/execute.rs (1)

104-109: LGTM!

The pattern matching for RatesMessage enhances clarity and modularity in handling rate-related commands.

contracts/data-storage/andromeda-primitive/src/testing/tests.rs (1)

Line range hint 73-129: LGTM!

The test effectively verifies the handling of multiple rates, ensuring correct functionality.

contracts/non-fungible-tokens/andromeda-marketplace/src/testing/tests.rs (3)

Line range hint 658-669: LGTM! Transition to vector of rates is consistent.

The change to use a vector for the rate variable is correct and aligns with the goal of supporting multiple rates.


Line range hint 713-724: LGTM! Transition to vector of rates is consistent.

The change to use a vector for the rate variable is correct and aligns with the goal of supporting multiple rates.


Line range hint 790-801: LGTM! Transition to vector of rates is consistent.

The change to use a vector for the rate variable is correct and aligns with the goal of supporting multiple rates.

tests-integration/tests/marketplace_app.rs (3)

140-140: LGTM! Transition to vector of rates is consistent.

The change to use a vector for the Rate parameter is correct and aligns with the goal of supporting multiple rates.


586-586: LGTM! Transition to vector of rates is consistent.

The change to use a vector for the Rate parameter is correct and aligns with the goal of supporting multiple rates.


884-884: LGTM! Transition to vector of rates is consistent.

The change to use a vector for the Rate parameter is correct and aligns with the goal of supporting multiple rates.

tests-integration/tests/auction_app.rs (2)

120-142: LGTM! Enhanced rate configuration is consistent.

The introduction of multiple Rate::Local instances with different percentage values is correct and aligns with the goal of supporting more complex rate configurations.


238-242: LGTM! Balance assertions updated to match new rate configuration.

The changes to the balance assertions are correct and align with the new rate configuration, ensuring accurate test verification.

contracts/non-fungible-tokens/andromeda-auction/src/testing/tests.rs (3)

Line range hint 1241-1250: Transition to vector of rates is appropriate.

Wrapping the Rate::Local instance in a vector aligns with the PR's objective of supporting multiple rates. The logic remains intact.


Line range hint 1328-1337: Transition to vector of rates is appropriate.

Wrapping the Rate::Local instance in a vector aligns with the PR's objective of supporting multiple rates. The logic remains intact.


Line range hint 1490-1501: Transition to vector of rates is appropriate.

Wrapping the Rate::Local instance in a vector, using a percentage rate, aligns with the PR's objective of supporting multiple rates. The logic remains intact.

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 ef7c5dd and d07a9ed.

Files selected for processing (1)
  • packages/std/src/ado_contract/rates.rs (6 hunks)
Additional comments not posted (7)
packages/std/src/ado_contract/rates.rs (7)

13-15: LGTM!

The change to return a Map with a vector of Rate aligns with the requirement to handle multiple rates.


20-26: LGTM!

The function correctly delegates to execute_set_rates and execute_remove_rates, reflecting the updated logic for handling multiple rates.


28-38: LGTM!

The logic for storing a vector of rates for a given action is correctly implemented.


39-73: LGTM!

The function processes a vector of rates, ensuring validation and correct recipient updates, while enforcing contract ownership.


105-109: LGTM!

The function correctly returns an Option<Vec<Rate>>, aligning with the new structure for multiple rates.


Line range hint 111-123: LGTM!

The function correctly returns a vector of tuples with a string and a vector of rates, iterating over all stored rates.


Line range hint 125-199: LGTM!

The function accurately processes multiple rates, handling different fund types and calculating total deducted funds.

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 d07a9ed and 3730fe2.

Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

RatesMessage::SetRate { rates, .. } => {
for rate in rates {
match rate {
Rate::Local(local_rate) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Refactor this to a rate.is_flat() and rate.is_local()

}

// Save the updated rates
self.set_rates(ctx.deps.storage, action, rates)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is state breaking, we'd need a migration function for this for any current ADOs

@joemonem
Copy link
Contributor Author

We've decided to limit number of recipients per rate to one. A similar PR will be opened after this is merged.

@joemonem joemonem closed this Nov 25, 2024
@joemonem joemonem deleted the joe/multiple-rates branch December 11, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants