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

Support arbitrary bytes on test routers #343

Closed
wants to merge 22 commits into from

Conversation

saucepoint
Copy link
Collaborator

@saucepoint saucepoint commented Aug 25, 2023

Related Issue

Which issue does this pull request resolve?

The test routers (i.e. PoolSwapTest) did not support arbitrary data arguments (new in #332). This PR updates the test routers to support the flow of arbitrary bytes from the router to the hooks.

Description of changes

  1. Updated the main function(s) in PoolSwapTest, PoolModifyPositionTest, and PoolDonateTest to support arbitrary data args

  2. Updated MockHooks to write arbitrary data to storage. Used to verify that test routers are providing arbitrary bytes correctly (Hooks.t.sol)

@saucepoint
Copy link
Collaborator Author

@ewilz any chance i can get reviewers on this?

snreynolds
snreynolds previously approved these changes Sep 11, 2023
Copy link
Member

@snreynolds snreynolds left a comment

Choose a reason for hiding this comment

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

lgtm!

@@ -35,21 +36,29 @@ contract PoolSwapTest is ILockCallback {
payable
returns (BalanceDelta delta)
{
delta =
abi.decode(manager.lock(abi.encode(CallbackData(msg.sender, testSettings, key, params))), (BalanceDelta));
return swap(key, params, testSettings, new bytes(0));
Copy link
Member

@ewilz ewilz Sep 11, 2023

Choose a reason for hiding this comment

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

looks like gas snapshots went up by >1k for all swaps...wonder if consolidating the swap functions here makes more sense than having 2 external calls (or just keeping them separate altogether)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer removing the old function signature and moving everything over to the new function signature w/ bytes memory hookData (instead of duplicating the logic). I wanted to keep the original for backwards compatibility with v4-periphery and community repos, but I suppose theres been breaking changes already so might as well keep it up 😝

Will try it for both swap + modifyPosition

}

function modifyPosition(PoolKey memory key, IPoolManager.ModifyPositionParams memory params)
external
payable
returns (BalanceDelta delta)
{
delta = abi.decode(manager.lock(abi.encode(CallbackData(msg.sender, key, params))), (BalanceDelta));
return modifyPosition(key, params, new bytes(0));
Copy link
Member

@ewilz ewilz Sep 11, 2023

Choose a reason for hiding this comment

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

same as swap, but only 977 gas increase for modify position. I wonder if we can minimize the impact on gas
per test contracts by either consolidating the functions..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed the old modifyPosition() and the gas is practically the same, or worse in some cases 🤔

Here's the diff
https://github.com/saucepoint/v4-core/pull/1/files

@snreynolds
Copy link
Member

Also looks like the hardhat tests are failing. Since we still have some coverage with hardhat unfortunately we should get those updated even though we are in the process of deprecating. Can reproduce with yarn test.

@saucepoint

This comment was marked as outdated.

@saucepoint
Copy link
Collaborator Author

saucepoint commented Sep 12, 2023

To recap the outstanding changes, there's two paths we could take:

  1. Remove overloaded functions by consolidating to the function(s) with bytes memory parameters

    • Gas improvements are negligible or worse
    • Update hardhat tests to the new function signatures
    • Update v4-periphery to the new function signatures
    • Requires users to provide ZERO_BYTES when using the test routers
    • More work, but cleaner codebase
  2. Keep overloaded functions

    • Hardhat tests are ugly because they need to reference the full function signature. But these are getting deprecated anyway 🙏
    • backwards compatible with v4-periphery and existing repos
    • cleaner interface for users that dont need arbitrary bytes

Consolidate overloaded `modifyPosition` and `swap`
@snreynolds
Copy link
Member

To recap the outstanding changes, there's two paths we could take:

  1. Remove overloaded functions by consolidating to the function(s) with bytes memory parameters

    • Gas improvements are negligible or worse
    • Update hardhat tests to the new function signatures
    • Update v4-periphery to the new function signatures
    • Requires users to provide ZERO_BYTES when using the test routers
    • More work, but cleaner codebase
  2. Keep overloaded functions

    • Hardhat tests are ugly because they need to reference the full function signature. But these are getting deprecated anyway 🙏
    • backwards compatible with v4-periphery and existing repos
    • cleaner interface for users that dont need arbitrary bytes

I'm in favor of option #1. Don't think we need to maintain backwards compatibility in tests - we should just update them to match the new functionality. Gas seems to just be overhead of the new ZERO_BYTES param so I'm not that worried about it but curious to hear your thoughts @ewilz.

contracts/test/PoolSwapTest.sol Outdated Show resolved Hide resolved
contracts/test/PoolDonateTest.sol Outdated Show resolved Hide resolved
contracts/test/PoolDonateTest.sol Outdated Show resolved Hide resolved
contracts/test/PoolModifyPositionTest.sol Outdated Show resolved Hide resolved
snreynolds
snreynolds previously approved these changes Sep 22, 2023
@snreynolds
Copy link
Member

snreynolds commented Sep 26, 2023

@saucepoint Hm looks like hardhat tests are still failing, and I think you need to run yarn prettier but other than that happy to merge! I think for the hardhat tests you just need to update the snapshots

@snreynolds snreynolds self-requested a review September 26, 2023 19:30
@snreynolds
Copy link
Member

Closing in favor of #361

@snreynolds snreynolds closed this Sep 26, 2023
@saucepoint saucepoint deleted the router-bytes branch November 8, 2023 16:21
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