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

Deploy: SwapQuoterV2 on Arbitrum/Avalanche #266

Merged
merged 41 commits into from
Dec 12, 2023
Merged

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Aug 11, 2023

Description

  • Added a script for extracting SwapQuoterV2 configuration from Ethereum's BridgeConfigV3 contract.
  • Added a script for SwapQuoterV2 deployment.
  • Added a script for switching active quoter in SynapseRouter contract.
  • Deployed on Arbitrum.

TODO:

  • Automatically fetch the whitelisted pools from SynapseCCTP contract and save them to the config.
  • Deploy on Avalanche.

Checklist

  • New Contracts have been tested
  • Lint has been run
  • I have checked my code and corrected any misspellings

Summary by CodeRabbit

  • New Features
    • Introduced IBridgeConfigV3 and IMulticall3 interfaces to enhance token and pool configurations and streamline multicall processes.
    • Added transferOwnership function to IOwnable interface, enabling ownership transfers.
    • Implemented ISynapseRouter interface with functions to manage swap quoters.
    • Developed new contracts ActivateRouterV1sQuoter, BasicRouterScript, TransferOwnership, ConfigureQuoterV2, DeployQuoterV2, and SaveConfigQuoterV2 to improve router and quoter management.
    • Created BridgeConfigLens contract to provide easy access to token and pool configurations.

@coveralls
Copy link

coveralls commented Aug 11, 2023

Pull Request Test Coverage Report for Build 6865200911

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 13.096%

Totals Coverage Status
Change from base Build 6770399108: 0.0%
Covered Lines: 664
Relevant Lines: 4627

💛 - Coveralls

@ChiTimesChi ChiTimesChi marked this pull request as ready for review October 20, 2023 13:46
@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2023

The existing sections are already well-structured and provide a clear overview of the changes. I will proceed with crafting a whimsical poem to celebrate the changes:

🍂 As the leaves fall and the air grows colder, 🍁
Our code evolves, becoming bolder. 📜
New interfaces and contracts take the stage, 🎭
Guiding our project to a new age. 🌅

The poem captures the spirit of change and progression, aligning with the evolving nature of the codebase.


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

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

Commits Files that changed from the base of the PR and between 947505f and 2827638.
Files ignored due to filter (13)
  • deployments/arbitrum/SwapQuoterV2.json
  • deployments/avalanche/DefaultPoolCalc.json
  • deployments/avalanche/SwapQuoterV2.json
  • deployments/mainnet/DefaultPoolCalc.json
  • deployments/mainnet/SwapQuoterV2.json
  • deployments/optimism/DefaultPoolCalc.json
  • deployments/optimism/SwapQuoterV2.json
  • script/configs/SwapQuoterV2.ignored.json
  • script/configs/arbitrum/SwapQuoterV2.dc.json
  • script/configs/avalanche/SwapQuoterV2.dc.json
  • script/configs/mainnet/SwapQuoterV2.dc.json
  • script/configs/optimism/SwapQuoterV2.dc.json
  • script/networks.json
Files selected for processing (11)
  • script/interfaces/IBridgeConfigV3.sol (1 hunks)
  • script/interfaces/IMulticall3.sol (1 hunks)
  • script/interfaces/IOwnable.sol (1 hunks)
  • script/interfaces/ISynapseRouter.sol (1 hunks)
  • script/router/ActivateRouterV1sQuoter.s.sol (1 hunks)
  • script/router/BasicRouter.s.sol (1 hunks)
  • script/router/TransferOwnership.s.sol (1 hunks)
  • script/router/quoter/ConfigureQuoterV2.s.sol (1 hunks)
  • script/router/quoter/DeployQuoterV2.s.sol (1 hunks)
  • script/router/quoter/SaveConfigQuoterV2.s.sol (1 hunks)
  • script/router/quoter/helpers/BridgeConfigLens.sol (1 hunks)
Files skipped from review due to trivial changes (2)
  • script/interfaces/IOwnable.sol
  • script/router/quoter/helpers/BridgeConfigLens.sol
Additional comments (Suppressed): 18
script/interfaces/ISynapseRouter.sol (1)
  • 1-8: The ISynapseRouter interface is well defined with functions to set and get the swapQuoter address. Ensure that the setSwapQuoter function is properly secured to prevent unauthorized access. This could be done by adding a modifier in the implementation to allow only the contract owner or authorized addresses to call this function.
script/interfaces/IMulticall3.sol (1)
  • 1-17: The IMulticall3 interface is well defined with clear function signatures and data structures. The aggregate3 function takes an array of Call3 structs and returns an array of Result structs. This function is marked as payable, which means it can receive Ether. Ensure that this is the intended behavior and that the function properly handles any Ether sent to it. Also, verify that the allowFailure field in the Call3 struct is used correctly in the implementation to allow or disallow failures as intended.
script/interfaces/IBridgeConfigV3.sol (2)
  • 1-35: The new interface IBridgeConfigV3 introduces two new structs Token and Pool to represent token and pool configurations respectively. It also introduces three new functions getAllTokenIDs, getTokenByID, and getPoolConfig to retrieve these configurations. Ensure that these new data structures and functions are correctly used in the rest of the codebase.

  • 25-35: The functions getAllTokenIDs, getTokenByID, and getPoolConfig are declared to return memory arrays or structs. Ensure that these are handled correctly in the calling code to avoid potential memory-related issues.

script/router/TransferOwnership.s.sol (1)
  • 1-4: The IOwnable interface is imported but the new transferOwnership function is not reflected in the interface. Ensure that the IOwnable interface has been updated to include this function.
script/router/ActivateRouterV1sQuoter.s.sol (1)
  • 9-26: The function run does not have any access control. This means that any address can call this function and potentially change the swapQuoter of the SynapseRouter. This could be a serious security issue if not intended. Please verify if this is the desired behavior. If not, consider adding appropriate access control, such as onlyOwner or onlyAdmin.
script/router/quoter/DeployQuoterV2.s.sol (3)
  • 1-35: The contract DeployQuoterV2 is well-structured and follows the best practices of Solidity. It deploys the SwapQuoterV2 contract and saves its address for future use. The contract uses environment variables to get the owner's address, which is a good practice for security reasons. However, ensure that the environment variables are properly set and secured. Also, make sure that the OWNER_ADDR is a trusted address, as it will have ownership of the deployed contract.

  • 14-20: The run function sets up the script, starts broadcasting, deploys the SwapQuoterV2 contract, and then stops broadcasting. This is a good practice as it encapsulates the entire process in a single function. However, ensure that the setUp function and the vm.startBroadcast and vm.stopBroadcast functions are working as expected and handle any potential errors.

  • 26-33: The deployQuoterV2 function deploys the SwapQuoterV2 contract with the necessary parameters. It retrieves the latest router deployment, the default pool calculator, the wrapped Ether (or equivalent on other chains), and the owner's address. It then deploys the SwapQuoterV2 contract and returns its address and the constructor arguments. This function is well-structured and follows best practices. However, ensure that the getLatestRouterDeployment, getDeploymentAddress, and vm.envAddress functions are working as expected and handle any potential errors.

script/router/quoter/ConfigureQuoterV2.s.sol (9)
  • 34-44: The run function is the main entry point for this contract. It sets up the BasicSynapseScript, checks if the sender is the owner, reads the configuration, starts broadcasting, sets the SynapseRouter, sets the pools, and then stops broadcasting. This function is well-structured and follows a logical sequence of operations. However, it's important to ensure that the setUp, readConfig, setSynapseRouter, and setPools functions are implemented correctly and handle errors appropriately.

  • 46-71: The readConfig function reads the configuration for the SwapQuoterV2 contract from the deployment configuration. It then parses this configuration and stores it in the configBridgePools, bridgeTokenToSymbol, and symbolToBridgeToken data structures. This function also checks for duplicate symbols and bridge tokens, which is a good practice to prevent configuration errors. However, it's important to ensure that the configuration is formatted correctly and contains all the necessary information.

  • 73-79: The setSynapseRouter function sets the synapseRouter of the SwapQuoterV2 contract to the latest router deployment. This function checks if the current synapseRouter is different from the latest router deployment before setting it, which is a good practice to prevent unnecessary operations. However, it's important to ensure that the getLatestRouterDeployment function returns the correct address.

  • 81-87: The setPools function updates the pools of the SwapQuoterV2 contract based on the configuration. It first removes all bridge pools that are not in the configuration, and then adds all pools from the configuration that are not in the bridge pools. This function is well-structured and follows a logical sequence of operations. However, it's important to ensure that the removeMissingPools and addMissingPools functions are implemented correctly and handle errors appropriately.

  • 89-115: The getAllPools function retrieves all pools from the SwapQuoterV2 contract and combines them into a single array. This function is well-structured and follows a logical sequence of operations. However, it's important to ensure that the getOriginDefaultPools, getOriginLinkedPools, and getBridgePools functions return the correct addresses.

  • 117-134: The removeMissingPools function removes all pools from the SwapQuoterV2 contract that are not in the configuration. This function uses the getMissingPools function to find the pools to remove, and then calls the removePools function of the SwapQuoterV2 contract to remove them. This function is well-structured and follows a logical sequence of operations. However, it's important to ensure that the getMissingPools and removePools functions are implemented correctly and handle errors appropriately.

  • 136-159: The addMissingPools function adds all pools from the configuration to the SwapQuoterV2 contract that are not already in the bridge pools. This function uses the getMissingPools function to find the pools to add, and then calls the addPools function of the SwapQuoterV2 contract to add them. This function is well-structured and follows a logical sequence of operations. However, it's important to ensure that the getMissingPools and addPools functions are implemented correctly and handle errors appropriately.

  • 163-178: The equalBridgeToken and equalFully functions are used to compare two pools. The equalBridgeToken function checks if the bridgeToken field in the two pools is equal, and the equalFully function checks if all fields in the two pools are equal. These functions are well-implemented and follow good practices for comparing data structures.

  • 182-213: The getMissingPools function returns a list of pools that are in poolsToFilter but not in existingPools. This function uses a comparePools function to compare the pools, which allows for flexible comparison logic. This function is well-structured and follows a logical sequence of operations. However, it's important to ensure that the comparePools function is implemented correctly and handles errors appropriately.

script/router/BasicRouter.s.sol Show resolved Hide resolved
script/interfaces/IBridgeConfigV3.sol Show resolved Hide resolved
script/interfaces/IBridgeConfigV3.sol Show resolved Hide resolved
script/router/TransferOwnership.s.sol Show resolved Hide resolved
script/router/TransferOwnership.s.sol Show resolved Hide resolved
script/router/ActivateRouterV1sQuoter.s.sol Show resolved Hide resolved
script/router/ActivateRouterV1sQuoter.s.sol Show resolved Hide resolved
script/router/quoter/SaveConfigQuoterV2.s.sol Outdated Show resolved Hide resolved
script/router/quoter/SaveConfigQuoterV2.s.sol Outdated Show resolved Hide resolved
script/router/quoter/SaveConfigQuoterV2.s.sol Outdated Show resolved Hide resolved
@ChiTimesChi ChiTimesChi marked this pull request as draft October 20, 2023 14:05
@ChiTimesChi ChiTimesChi marked this pull request as ready for review November 6, 2023 13:33
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: 11

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2827638 and b40959d.
Files ignored due to filter (9)
  • deployments/base/DefaultPoolCalc.json
  • deployments/base/SwapQuoterV2.json
  • script/configs/SwapQuoterV2.originOnly.json
  • script/configs/arbitrum/SwapQuoterV2.dc.json
  • script/configs/avalanche/SwapQuoterV2.dc.json
  • script/configs/base/SwapQuoterV2.dc.json
  • script/configs/mainnet/SwapQuoterV2.dc.json
  • script/configs/optimism/SwapQuoterV2.dc.json
  • script/networks.json
Files selected for processing (3)
  • script/router/quoter/ConfigureQuoterV2.s.sol (1 hunks)
  • script/router/quoter/SaveConfigQuoterV2.s.sol (1 hunks)
  • script/templates/BasicSynapse.s.sol (1 hunks)
Additional comments: 5
script/templates/BasicSynapse.s.sol (1)
  • 189-199: The loadDeploymentSalt function has been updated to check if a key exists in the allSalts JSON string using the keyExists function. If the key exists, it decodes the corresponding salt entry and verifies the initCodeHash. If the key doesn't exist, it returns 0. This change seems to be logically correct and should improve the function's robustness by handling the case where the key doesn't exist in the allSalts JSON string.
script/router/quoter/SaveConfigQuoterV2.s.sol (2)
  • 31-49: The run function is the main entry point for this contract. It checks if a configuration file already exists for the SwapQuoterV2 contract. If it does, it loads the configuration from the file and returns. If not, it loads the ignored pools, saves the origin-only pools, saves the SynapseCCTP pools, saves the BridgeConfigV3 pools, and then serializes and writes the configuration to a file. This function is well-structured and follows a clear sequence of steps.

  • 164-166: The getPoolType function uses the isLinkedPool function to determine the type of a pool. It returns SwapQuoterV2.PoolType.Linked if the pool is a LinkedPool and SwapQuoterV2.PoolType.Default otherwise. This function is straightforward and correctly uses the isLinkedPool function.

script/router/quoter/ConfigureQuoterV2.s.sol (2)
  • 1-4: Ensure that the correct version of Solidity is being used and that the imported contracts are compatible with this version.

  • 34-45: The run function is the main entry point for this contract. It sets up the contract, checks if the sender is the owner, reads the configuration, and then sets the Synapse router and pools. It's important to ensure that the owner check is robust and secure.

script/router/quoter/SaveConfigQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/SaveConfigQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
script/router/quoter/ConfigureQuoterV2.s.sol Show resolved Hide resolved
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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b40959d and a0d2de1.
Files ignored due to filter (1)
  • script/configs/mainnet/SwapQuoterV2.dc.json
Files selected for processing (1)
  • script/router/quoter/SaveConfigQuoterV2.s.sol (1 hunks)

script/router/quoter/SaveConfigQuoterV2.s.sol Show resolved Hide resolved
@Defi-Moses
Copy link
Collaborator

LGTM

Copy link
Collaborator

@Defi-Moses Defi-Moses left a comment

Choose a reason for hiding this comment

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

LGTM

@ChiTimesChi ChiTimesChi merged commit e4eb8b3 into master Dec 12, 2023
10 checks passed
@ChiTimesChi ChiTimesChi deleted the deploy/quoter-v2 branch December 12, 2023 11:19
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