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: add callback in LiFiDEXAggregator (v1.1.0) #832

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

maxklenk
Copy link
Contributor

@maxklenk maxklenk commented Oct 10, 2024

Which Jira task belongs to this PR?

https://lifi.atlassian.net/browse/LF-10403

Why did I implement it this way?

Needed to support more liquidity sources

  • The update has to be deployed to Fraxtal only

Checklist before requesting a review

  • I have performed a self-review of my code
  • This pull request is as small as possible and only tackles one problem
  • I have added tests that cover the functionality / test the bug
  • I have updated any required documentation

Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)

  • I have checked that any arbitrary calls to external contracts are validated and or restricted
  • I have checked that any privileged calls (i.e. storage modifications) are validated and or restricted
  • I have ensured that any new contracts have had AT A MINIMUM 1 preliminary audit conducted on by <company/auditor>

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces updates to the LiFiDEXAggregator contract located in src/Periphery/LiFiDEXAggregator.sol. The contract version is incremented from 1.0.0 to 1.1.0, and a new public function, ramsesV2SwapCallback, is added to facilitate handling swap callbacks from the RaExchangeV3 pool. This function is designed to replicate the existing uniswapV3SwapCallback functionality, ensuring proper token payments for swaps. Other existing functions and modifiers in the contract remain unchanged. Additionally, the address of the LiFiDEXAggregator is updated in both deployments/fraxtal.diamond.json and deployments/fraxtal.json.

Changes

File Path Change Summary
src/Periphery/LiFiDEXAggregator.sol Version updated from 1.0.0 to 1.1.0; added ramsesV2SwapCallback(int256, int256, bytes) method.
deployments/fraxtal.diamond.json Updated LiFiDEXAggregator address from 0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc to 0xE38621607316cB43367c134C65dca3f41B61250f.
deployments/fraxtal.json Updated LiFiDEXAggregator address from 0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc to 0xE38621607316cB43367c134C65dca3f41B61250f.
config/dexs.json Removed address 0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc from network fraxtal; added address 0xE38621607316cB43367c134C65dca3f41B61250f to network fraxtal.

Possibly related PRs

  • Deploy lifi dex aggregator #812: The changes in this PR involve deploying the LiFiDEXAggregator, which is directly related to the modifications made in the main PR to the LiFiDEXAggregator contract, including the addition of the ramsesV2SwapCallback function.
  • config: addresses and signatures for sushiswap dex agg #818: This PR updates the config/dexs.json file, which includes the address of the LiFiDEXAggregator. The changes in this PR are relevant as they reflect the updated address associated with the aggregator in the configuration.

Suggested labels

AuditNotRequired

Suggested reviewers

  • ezynda3

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5b4b8b2 and a14bc77.

📒 Files selected for processing (1)
  • config/dexs.json (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
config/dexs.json (1)

407-408: Changes to Fraxtal network addresses look good.

The update to the Fraxtal network addresses, removing 0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc and adding 0xE38621607316cB43367c134C65dca3f41B61250f, appears to be in line with the PR objectives.

Could you please confirm that the new address 0xE38621607316cB43367c134C65dca3f41B61250f is correct and related to the new callback feature mentioned in the PR description? It would be helpful to run a quick check to ensure this address is properly configured for the Fraxtal network.

✅ Verification successful

Address update for LiFiDEXAggregator is correct, but no clear link to new callback feature.

The new address 0xE38621607316cB43367c134C65dca3f41B61250f is correctly updated in config/dexs.json and consistently used for LiFiDEXAggregator across multiple deployment files. This suggests the address change is intentional and correct.

However, there's no clear evidence linking this address update to a new callback feature:

  1. The LiFiDEXAggregator contract does include callback-related functions, but these appear to be existing functionality rather than new features.
  2. While there are references to callbacks in the codebase, none are directly associated with this specific address change.

It's possible that the callback feature mentioned in the PR description is implemented elsewhere or is part of a broader update not directly tied to this address change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the new address in the Fraxtal network configuration
grep -n "0xE38621607316cB43367c134C65dca3f41B61250f" config/dexs.json

Length of output: 122


Script:

#!/bin/bash
# Search for usages of the new address in the codebase
rg "0xE38621607316cB43367c134C65dca3f41B61250f" .

Length of output: 430


Script:

#!/bin/bash
# Search for the implementation and usage of LiFiDEXAggregator related to callbacks
rg "LiFiDEXAggregator" . -A 5
rg "callback" . -A 5
rg "0xE38621607316cB43367c134C65dca3f41B61250f" . | rg "callback"

Length of output: 378196


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.

@lifi-action-bot lifi-action-bot marked this pull request as draft October 10, 2024 09:39
@maxklenk maxklenk marked this pull request as ready for review October 10, 2024 09:39
@lifi-action-bot
Copy link
Collaborator

lifi-action-bot commented Oct 10, 2024

Test Coverage Report

Line Coverage: 78.41% (1700 / 2168 lines)
Function Coverage: 84.54% ( 361 / 427 functions)
Branch Coverage: 51.53% ( 269 / 522 branches)
Test coverage (78.41%) is above min threshold (74%). Check passed.

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 (1)
src/Periphery/LiFiDEXAggregator.sol (1)

578-591: LGTM: New callback function for RaExchangeV3

The new ramsesV2SwapCallback function is correctly implemented and follows the established pattern for swap callbacks in this contract. It properly delegates to the uniswapV3SwapCallback function, maintaining consistency with other DEX integrations.

For improved consistency with other callback functions in the contract, consider adding a comment explaining that this function is called by RaExchangeV3 after executing a swap.

You could add a comment similar to the ones used for other callback functions:

+    /// @notice Called to `msg.sender` after executing a swap via RaExchangeV3#swap.
     function ramsesV2SwapCallback(
         int256 amount0Delta,
         int256 amount1Delta,
         bytes calldata data
     ) external {
         uniswapV3SwapCallback(amount0Delta, amount1Delta, data);
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0dda420 and 705c680.

📒 Files selected for processing (1)
  • src/Periphery/LiFiDEXAggregator.sol (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
src/Periphery/LiFiDEXAggregator.sol (3)

25-25: Version update to 1.1.0

The contract version has been updated from 1.0.0 to 1.1.0, which is appropriate given the addition of a new feature (the ramsesV2SwapCallback function).


Line range hint 1-592: Summary: Addition of RaExchangeV3 support

The changes in this pull request are minimal and focused:

  1. The contract version has been updated from 1.0.0 to 1.1.0.
  2. A new ramsesV2SwapCallback function has been added to support RaExchangeV3 swaps.

These changes expand the contract's capabilities to handle swaps from RaExchangeV3 pools, following the existing patterns in the contract. The implementation appears to be consistent with the current codebase, minimizing the risk of introducing bugs.

No security issues or major concerns were identified during the review. However, it's important to ensure that the integration with RaExchangeV3 is properly tested and that the uniswapV3SwapCallback function can correctly handle data from RaExchangeV3 pools.

To ensure the changes don't introduce any unintended side effects, please run comprehensive tests focusing on:

  1. The new ramsesV2SwapCallback function
  2. Integration with RaExchangeV3 pools
  3. Existing functionality to confirm it remains unaffected

Additionally, consider updating the contract's documentation to reflect the added support for RaExchangeV3.


578-591: Verify RaExchangeV3 integration and compatibility

While the implementation of ramsesV2SwapCallback follows the established pattern in the contract, it's crucial to ensure that:

  1. The contract can properly handle calls from RaExchangeV3 pools.
  2. The uniswapV3SwapCallback function can correctly process the data from RaExchangeV3 pools.

To verify the integration, please run the following checks:

Please review the results to ensure that RaExchangeV3 is properly integrated and that the uniswapV3SwapCallback function can handle the data from RaExchangeV3 pools correctly.

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 (2)
src/Periphery/LiFiDEXAggregator.sol (2)

578-591: Approve new ramsesV2SwapCallback function with a minor suggestion

The implementation of ramsesV2SwapCallback looks correct and consistent with other similar callback functions in the contract. It properly delegates the logic to the existing uniswapV3SwapCallback function, which helps maintain code consistency and reduces duplication.

For improved consistency with other callback functions in this contract, consider adding a comment explaining the purpose of this callback, similar to the comments for uniswapV3SwapCallback and pancakeV3SwapCallback.


25-25: Summary of changes and considerations

The changes in this PR are minimal and focused:

  1. Updated contract version to 1.1.0
  2. Added ramsesV2SwapCallback function to support RaExchangeV3 swaps

The implementation follows established patterns in the contract and doesn't introduce significant new risks. However, please consider the following points:

  1. Ensure that the integration with RaExchangeV3 is thoroughly tested, especially the interaction between ramsesV2SwapCallback and uniswapV3SwapCallback.
  2. Verify that the lastCalledPool mechanism correctly handles RaExchangeV3 pool addresses to maintain security.
  3. Update the contract's documentation to reflect the added support for RaExchangeV3.
  4. Consider adding test cases specifically for the new RaExchangeV3 integration.

Also applies to: 578-591

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0dda420 and 705c680.

📒 Files selected for processing (1)
  • src/Periphery/LiFiDEXAggregator.sol (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
src/Periphery/LiFiDEXAggregator.sol (2)

25-25: Version update to 1.1.0

The contract version has been updated from 1.0.0 to 1.1.0, which is consistent with the addition of a new feature (the ramsesV2SwapCallback function).


578-591: Verify msg.sender check for new callback function

While the implementation looks correct, it's crucial to ensure that the msg.sender check in uniswapV3SwapCallback is sufficient for this new use case with RaExchangeV3. Please verify that the lastCalledPool mechanism correctly handles the RaExchangeV3 pool addresses to prevent unauthorized calls.

To assist with this verification, you can run the following script:

✅ Verification successful

msg.sender check in uniswapV3SwapCallback is sufficient

The uniswapV3SwapCallback function correctly verifies that msg.sender is equal to lastCalledPool, ensuring that only authorized pool addresses can invoke the callback. No security issues detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if RaExchangeV3 pools are properly handled in the contract

# Search for RaExchangeV3 pool address assignments
echo "Searching for RaExchangeV3 pool address assignments:"
rg --type solidity "RaExchangeV3|lastCalledPool" src/

# Check for any additional pool type checks
echo "Checking for pool type checks:"
rg --type solidity "poolType|lastCalledPool" src/

Length of output: 359


Script:

#!/bin/bash
# Description: Check if RaExchangeV3 pools are properly handled in the contract

# Search for RaExchangeV3 pool address assignments
echo "Searching for RaExchangeV3 pool address assignments in .sol files:"
rg --glob "*.sol" "RaExchangeV3|lastCalledPool" src/

# Check for any additional pool type checks
echo "Checking for pool type checks in .sol files:"
rg --glob "*.sol" "poolType|lastCalledPool" src/

Length of output: 2574


Script:

#!/bin/bash
# Description: Extract the implementation of uniswapV3SwapCallback from LiFiDEXAggregator.sol

# Define the file path
FILE_PATH="src/Periphery/LiFiDEXAggregator.sol"

# Extract the lines containing the uniswapV3SwapCallback function
echo "Extracting uniswapV3SwapCallback implementation:"
awk '/function uniswapV3SwapCallback/,/}/' "$FILE_PATH"

Length of output: 894

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 705c680 and 5b4b8b2.

📒 Files selected for processing (3)
  • deployments/_deployments_log_file.json (1 hunks)
  • deployments/fraxtal.diamond.json (1 hunks)
  • deployments/fraxtal.json (1 hunks)
🔥 Files not summarized due to errors (1)
  • deployments/_deployments_log_file.json: Error: Server error: no LLM provider could handle the message
✅ Files skipped from review due to trivial changes (1)
  • deployments/fraxtal.json
🧰 Additional context used
📓 Learnings (1)
deployments/fraxtal.diamond.json (2)
Learnt from: 0xDEnYO
PR: lifinance/contracts#819
File: deployments/scroll.diamond.json:82-82
Timestamp: 2024-10-09T03:47:21.269Z
Learning: In the `deployments/*.diamond.json` and `deployments/*.json` files, the `LiFiDEXAggregator` contract may intentionally have the same contract address across multiple networks. This is acceptable and should not be flagged as an issue in future code reviews.
Learnt from: 0xDEnYO
PR: lifinance/contracts#819
File: deployments/scroll.diamond.json:82-82
Timestamp: 2024-10-04T08:51:32.273Z
Learning: In the `deployments/*.diamond.json` and `deployments/*.json` files, the `LiFiDEXAggregator` contract may intentionally have the same contract address across multiple networks. This is acceptable and should not be flagged as an issue in future code reviews.
🔇 Additional comments (2)
deployments/fraxtal.diamond.json (1)

71-71: Verify the updated LiFiDEXAggregator address.

The address for the LiFiDEXAggregator has been updated to 0xE38621607316cB43367c134C65dca3f41B61250f. This change is consistent with the PR objectives to update the LiFiDEXAggregator contract.

Please confirm the following:

  1. This new address corresponds to the correct deployment of LiFiDEXAggregator v1.1.0.
  2. If applicable, ensure that this address is updated consistently across other network configuration files (e.g., other deployments/*.json and deployments/*.diamond.json files).

To verify the contract version at the new address, you can use the following script:

This script will help ensure that the deployed contract at the new address is indeed version 1.1.0.

✅ Verification successful

LiFiDEXAggregator address updated correctly to version 1.1.0.

The LiFiDEXAggregator address in deployments/fraxtal.diamond.json has been updated to 0xE38621607316cB43367c134C65dca3f41B61250f, corresponding to version 1.1.0. This change is consistent across the codebase as evidenced by multiple deployment files indicating "Version": "1.1.0".

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the version of the LiFiDEXAggregator contract

# Search for the version string in the contract
rg --type solidity -i 'version\s*=\s*"1\.1\.0"' $(fd -e sol)

# Optionally, if a version() function exists, you can use cast to call it
# Uncomment and modify the following line if needed:
# cast call 0xE38621607316cB43367c134C65dca3f41B61250f "version()(string)" --rpc-url <RPC_URL>

Length of output: 13012


Script:

#!/bin/bash
# Verify the version of the LiFiDEXAggregator contract

# Search for the version string in Solidity files
rg -i 'version\s*=\s*"1\.1\.0"' --glob '*.sol'

# Optionally, search for a version() function in the contract
rg -i 'function\s+version\s*\(\)\s+public\s+view\s+returns\s*\(string\)' --glob '*.sol'

Length of output: 138


Script:

#!/bin/bash
# Comprehensive search for the LiFiDEXAggregator version

# Search for the version string "1.1.0" in all files
rg -i '1\.1\.0' --follow

# Search for version definitions using different patterns in Solidity files
rg -i 'uint8\s+public\s+constant\s+VERSION\s*=\s*1\.1\.0' --glob '*.sol'
rg -i 'string\s+public\s+version\s*=\s*"1\.1\.0"' --glob '*.sol'

# Search for a version() function with different return types in Solidity files
rg -i 'function\s+version\s*\(\)\s+public\s+view\s+returns\s*\(uint8\)' --glob '*.sol'
rg -i 'function\s+getVersion\s*\(\)\s+public\s+view\s+returns\s*\(string\)' --glob '*.sol'

# Search within JSON and configuration files for the version string
rg -i '"version"\s*:\s*"1\.1\.0"' --glob '*.json' --glob '*.yaml' --glob '*.yml' --glob '*.md'

Length of output: 57669

deployments/_deployments_log_file.json (1)

23087-23096: Verify changes from the previous version.

The "SALT" and "VERIFIED" fields are consistent with the visible part of the previous version. However, please manually verify the following:

  1. The address has changed, as expected for a new deployment.
  2. The OPTIMIZER_RUNS value is appropriate and hasn't changed unexpectedly.
  3. The CONSTRUCTOR_ARGS are correct for the new version.

These checks will ensure that the deployment configuration is appropriate for version 1.1.0.

deployments/_deployments_log_file.json Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants