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

⚡️ [API-2293] Swap Directly On Astroport Pools, Deprecate Router Use #84

Merged
merged 6 commits into from
Jan 5, 2024

Conversation

NotJeremyLiu
Copy link
Member

@NotJeremyLiu NotJeremyLiu commented Jan 4, 2024

This PR

  • Deprecates the use of the Astroport router in the Astroport swap adapter contract, instead swapping directly on pools
  • Updates existing tests, and adds a new test_execute_astroport_pool_swap.rs file to unit test the new swapping dispatching.
  • Removes router contract logic in deploy configs/scripts

Summary by CodeRabbit

  • Refactor

    • Streamlined swap operations across various contracts.
    • Enhanced swap function to support multiple operations and pool swaps.
  • Bug Fixes

    • Fixed control flow in the query function of swap contracts.
  • New Features

    • Introduced a new swap type: Astroport Pool Swap.
  • Chores

    • Cleaned up code by removing unused imports and references.
    • Updated test cases to reflect new logic and swap operations.
  • Documentation

    • Updated comments for clarity in query functions.
  • Style

    • Organized imports and renamed comments for better readability.
  • Tests

    • Modified test scripts to accommodate new swap functionality.

Copy link

coderabbitai bot commented Jan 4, 2024

Walkthrough

The codebase underwent a significant shift away from using a router contract for swap operations in favor of direct swaps on pool contracts. This was achieved through refactoring functions, altering message structures, and removing redundant code. The changes streamlined swap-related contracts, enhancing their direct interaction with Astroport pools and eliminating the intermediate router layer.

Changes

File Path Change Summary
contracts/adapters/swap/astroport/README.md, contracts/adapters/swap/astroport/src/contract.rs The contract now converts the standardized entry point swap operations message format to Astroport pool swaps message format instead of the Astroport Router SwapOperation format. Swapping is now done by dispatching swaps to Astroport pool contracts instead of calling the Astroport router. Reorganization of imports, removal of unused imports, refactoring of functions, and introduction of AstroportPoolSwap execution message and related functions.
contracts/adapters/swap/astroport/src/bin/astroport-schema.rs Rearranged the order of imported items from the skip::swap module, swapping the positions of AstroportInstantiateMsg and InstantiateMsg.
contracts/adapters/swap/lido-satellite/tests/test_execute_swap.rs Modified a comment from "Store the router contract address" to "Store the lido satellite contract address" in the test_execute_swap function.
contracts/adapters/swap/osmosis-poolmanager/src/bin/osmosis-poolmanager-schema.rs, contracts/adapters/swap/osmosis-poolmanager/src/contract.rs Changed the import statement for the swap module, specifically in the osmosis-poolmanager-schema.rs file. Modified the query function to remove the default unimplemented!() branch, affecting the control flow and logic of the function.
packages/skip/src/swap.rs Renamed the OsmosisInstantiateMsg struct to InstantiateMsg, removed the AstroportInstantiateMsg struct, added a new variant AstroportPoolSwap to the ExecuteMsg enum, and removed the RouterContractAddress variant from the QueryMsg enum.
scripts/deploy.ipynb The logic for instantiating contracts has been simplified by removing conditional checks and always setting the swap_adapter_args with the entry_point_contract_address. This change streamlines the contract instantiation process.

Assessment against linked issues

Objective Addressed Explanation
API-2293: Stop using router in contracts The removal of router contract address storage and validation, along with refactoring to support direct pool swaps, aligns with the objective to cease using routers in swap adapter contracts.

Poem

As the stars align in the cosmic code,
🐇 CodeRabbit hopped down the new road.
No more routers to hop through the swap,
Direct to the pools, a quantum leap hop! 🌌

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's AI:

  • 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.
    • @coderabbitai read the files in the src/scheduler package and generate 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.

@NotJeremyLiu NotJeremyLiu changed the title Swap Directly On Astroport Pools, Deprecate Router Use ⚡️ [API-2293] Swap Directly On Astroport Pools, Deprecate Router Use Jan 4, 2024
@NotJeremyLiu NotJeremyLiu marked this pull request as ready for review January 4, 2024 20:31
Copy link

@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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 11a778e and b4a5115.
Files selected for processing (7)
  • contracts/adapters/swap/astroport/src/contract.rs (10 hunks)
  • contracts/adapters/swap/astroport/src/state.rs (1 hunks)
  • contracts/adapters/swap/astroport/tests/test_execute_receive.rs (5 hunks)
  • contracts/adapters/swap/astroport/tests/test_execute_swap.rs (7 hunks)
  • contracts/adapters/swap/lido-satellite/src/contract.rs (1 hunks)
  • contracts/adapters/swap/osmosis-poolmanager/src/contract.rs (1 hunks)
  • packages/skip/src/swap.rs (2 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/adapters/swap/astroport/tests/test_execute_receive.rs
Additional comments: 14
contracts/adapters/swap/astroport/src/state.rs (1)
  • 2-4: Removal of ROUTER_CONTRACT_ADDRESS is consistent with the PR's objective to deprecate router use.
contracts/adapters/swap/astroport/tests/test_execute_swap.rs (2)
  • 54-63: The addition of AstroportPoolSwap message in the test cases is consistent with the PR's objective to enable direct swaps on Astroport pools.

  • 154-160: Verify the implementation of the SwapOperationsEmpty error to ensure it is correctly handled in the contract logic.

Verification successful

The SwapOperationsEmpty error is implemented and used in various parts of the codebase, including the astroport adapter's contract logic and tests, as well as in the skip package. The test case in test_execute_swap.rs correctly expects this error when no swap operations are provided, which aligns with the error handling implemented in the contract logic.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the implementation of SwapOperationsEmpty error handling.
rg --type rust 'SwapOperationsEmpty'

Length of output: 2009

contracts/adapters/swap/astroport/src/contract.rs (9)
  • 3-7: The removal of the router contract address and the addition of ENTRY_POINT_CONTRACT_ADDRESS align with the PR objectives to deprecate router use and enable direct swaps on Astroport pools.

  • 56-64: The instantiate function now correctly stores the ENTRY_POINT_CONTRACT_ADDRESS instead of the router contract address, which is consistent with the PR objectives.

  • 87-91: The receive_cw20 function has been updated to handle the Swap operation directly, which is in line with the PR's goal to enable direct swaps on Astroport pools.

  • 108-109: The execute function now includes a check for a single coin in the message info, which is a good practice to prevent unexpected multiple coin transfers.

  • 176-207: The new function execute_astroport_pool_swap is added to handle direct pool swaps, which is a key part of the PR objectives. Ensure that this function is thoroughly tested, especially the authorization logic and the swap message creation.

  • 141-154: The execute_swap function now creates a response object for each swap operation, which is a change in the logic to support direct pool swaps. It's important to ensure that this change does not introduce any regressions.

  • 168-173: The assert_max_spread function remains unchanged, which is good as it's a critical part of ensuring that the swap does not exceed the maximum allowed slippage.

  • 214-219: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [214-255]

The query function has been updated to remove the RouterContractAddress variant, which is consistent with the PR's objective to deprecate router use.

  • 254-260: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [257-298]

The function query_simulate_swap_exact_asset_in has been updated to remove the router logic, which aligns with the PR's objective to enable direct swaps on Astroport pools.

packages/skip/src/swap.rs (2)
  • 58-58: The addition of the AstroportPoolSwap variant to the ExecuteMsg enum is necessary for the new direct swap functionality on Astroport pools.

  • 72-77: The removal of the RouterContractAddress variant from the QueryMsg enum is consistent with the PR's objective to deprecate router use.

Copy link

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b4a5115 and db40d13.
Files ignored due to filter (2)
  • scripts/configs/neutron.toml
  • scripts/configs/terra.toml
Files selected for processing (1)
  • scripts/deploy.py (1 hunks)
Additional comments: 2
scripts/deploy.py (2)
  • 151-156: The conditional block checking for the "lido_satellite_contract_address" in the venue dictionary has been retained. This is consistent with the PR objectives, as it does not relate to the router contract address, which is being deprecated. Ensure that the "lido_satellite_contract_address" is still relevant to the new architecture and that its usage here is intentional and correct.
Verification successful

The search for lido_satellite_contract_address in Python files only returned occurrences in the scripts/deploy.py file, which is the same file we are reviewing. There are no other references to this address in the Python codebase provided by the search results. This suggests that the lido_satellite_contract_address is not widely used or referenced in other parts of the Python codebase, at least not under this exact name.

Given this information, it seems that the lido_satellite_contract_address is still relevant to the deployment script and its usage in the deploy.py script is intentional. However, without further context on how this address is used within the broader application, we cannot fully confirm its relevance to the new architecture.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the "lido_satellite_contract_address" is still in use and relevant to the new architecture.
rg --type py 'lido_satellite_contract_address'

Length of output: 257

* 151-156: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-157]

The removal of the router contract address check in the main function is consistent with the PR objectives to deprecate router use. However, it's crucial to ensure that this change does not introduce any regressions or unintended side effects elsewhere in the deployment script. Verify that the router contract address is not referenced or required in any other part of the script or related modules.

Verification successful

The search for references to router_contract_address in the deployment script did not yield any results. This suggests that the removal of the router contract address check from the main function in deploy.py has not left any lingering references to the router contract address in the script.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to the router contract address in the deployment script.
rg --type py 'router_contract_address'

Length of output: 38

Copy link

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between db40d13 and 20f94b8.
Files selected for processing (3)
  • contracts/adapters/swap/astroport/src/contract.rs (10 hunks)
  • contracts/adapters/swap/astroport/src/error.rs (1 hunks)
  • contracts/adapters/swap/astroport/tests/test_execute_astroport_pool_swap.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/adapters/swap/astroport/src/error.rs
Files skipped from review as they are similar to previous changes (1)
  • contracts/adapters/swap/astroport/src/contract.rs
Additional comments: 8
contracts/adapters/swap/astroport/tests/test_execute_astroport_pool_swap.rs (8)
  • 1-17: The imports and module usage have been updated to reflect the new functionality for direct swaps on Astroport pools. Ensure that these changes are consistent with the rest of the codebase and that no unused imports remain.

  • 32-39: The Params struct is well-defined and includes all necessary fields for testing the execute_astroport_pool_swap function. It's important to ensure that the fields cover all scenarios that the function might encounter in production.

  • 42-74: The test case for "Native Swap Operation" appears to be correctly set up with the expected message and no error. It's important to ensure that the test case covers the scenario comprehensively and that the expected message matches the actual behavior of the contract.

  • 76-111: The test case for "Cw20 Swap Operation" is set up to test the CW20 token swap. Ensure that the contract address and the amount are correctly set up and that the expected behavior aligns with the contract's logic.

  • 113-124: The test case for "No Native Offer Asset In Contract Balance To Swap" correctly expects an error when there is no native offer asset in the contract balance. This is a good negative test case to ensure proper error handling in the contract.

  • 126-137: The test case for "No Cw20 Offer Asset In Contract Balance To Swap" also correctly expects an error under the condition that there is no CW20 offer asset in the contract balance. This negative test case is essential for ensuring the contract's robustness.

  • 139-152: The test case for "Unauthorized Caller" is designed to ensure that the contract correctly handles unauthorized access. The expected error is ContractError::Unauthorized, which should be verified against the contract's authorization logic.

  • 154-234: The test_execute_astroport_pool_swap function sets up the test environment and executes the execute function with various parameters. Ensure that the mock dependencies, environment, and assertions are correctly implemented to accurately test the contract's behavior.

Copy link

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 20f94b8 and f3ec78c.
Files selected for processing (8)
  • contracts/adapters/swap/astroport/README.md (3 hunks)
  • contracts/adapters/swap/astroport/src/bin/astroport-schema.rs (1 hunks)
  • contracts/adapters/swap/astroport/src/contract.rs (10 hunks)
  • contracts/adapters/swap/lido-satellite/tests/test_execute_swap.rs (1 hunks)
  • contracts/adapters/swap/osmosis-poolmanager/src/bin/osmosis-poolmanager-schema.rs (1 hunks)
  • contracts/adapters/swap/osmosis-poolmanager/src/contract.rs (2 hunks)
  • packages/skip/src/swap.rs (3 hunks)
  • scripts/deploy.ipynb (1 hunks)
Files skipped from review due to trivial changes (3)
  • contracts/adapters/swap/astroport/src/bin/astroport-schema.rs
  • contracts/adapters/swap/lido-satellite/tests/test_execute_swap.rs
  • scripts/deploy.ipynb
Additional comments: 13
contracts/adapters/swap/osmosis-poolmanager/src/bin/osmosis-poolmanager-schema.rs (1)
  • 2-2: The removal of OsmosisInstantiateMsg from the import statement aligns with the PR objectives and the summary provided. Ensure that this change does not affect any other parts of the codebase where OsmosisInstantiateMsg might be used.
contracts/adapters/swap/astroport/README.md (1)
  • 4-5: The updates to the README.md file correctly reflect the new functionality of the contract, which now handles direct swaps with Astroport pools. This is consistent with the PR objectives.
contracts/adapters/swap/osmosis-poolmanager/src/contract.rs (1)
  • 19-21: The changes to the import statements are in line with the PR objectives and the summary provided. The removal of OsmosisInstantiateMsg and the addition of InstantiateMsg and MigrateMsg reflect the updated functionality of the contract.
packages/skip/src/swap.rs (3)
  • 26-31: Renaming OsmosisInstantiateMsg to InstantiateMsg and removing AstroportInstantiateMsg are consistent with the PR objectives to streamline swap operations.

  • 50-50: Adding the AstroportPoolSwap variant to the ExecuteMsg enum aligns with the new functionality for direct pool swaps.

  • 65-68: The removal of RouterContractAddress from the QueryMsg enum is in line with the deprecation of router use, as described in the PR objectives.

contracts/adapters/swap/astroport/src/contract.rs (7)
  • 3-22: Reorganizing imports and removing unused ones, such as state::ENTRY_POINT_CONTRACT_ADDRESS, is a good practice for maintainability and clarity of the code.

  • 55-63: Refactoring the instantiate function to remove the storage of the router contract address is consistent with the PR's goal to deprecate router use.

  • 86-91: Modifying the receive_cw20 function to handle swap operations without the need for asset validation simplifies the contract logic in line with direct pool swaps.

  • 104-111: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [104-123]

Refactoring the execute function to handle different execution messages, including the new AstroportPoolSwap message, is necessary for the new functionality.

  • 137-156: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [126-153]

The implementation of execute_swap to create a response object and add an astroport pool swap message for each swap operation is a key part of the new direct swap functionality.

  • 175-212: Introducing the execute_astroport_pool_swap function to handle the new AstroportPoolSwap message is a crucial part of the contract's new responsibilities.

  • 218-223: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [218-259]

Removing the RouterContractAddress query and related functionality is in line with the PR's objective to remove router usage.

@NotJeremyLiu NotJeremyLiu merged commit 83a5033 into main Jan 5, 2024
5 checks passed
@NotJeremyLiu NotJeremyLiu deleted the jl/swap-directly-on-astroport-pools branch January 5, 2024 15:49
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.

None yet

2 participants