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

[Bug]: Sync reverts when locked #883

Open
wjmelements opened this issue Sep 28, 2024 · 8 comments
Open

[Bug]: Sync reverts when locked #883

wjmelements opened this issue Sep 28, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@wjmelements
Copy link
Contributor

Describe the bug

Sync reverts when locked

Expected Behavior

Sync should work when locked

To Reproduce

call sync outside unlock

Additional context

broken by #856

@wjmelements wjmelements added the bug Something isn't working label Sep 28, 2024
Copy link

linear bot commented Sep 28, 2024

PROTO-621 [Bug]: Sync reverts when locked

@wjmelements
Copy link
Contributor Author

I should be able to

  1. sync
  2. transfer
  3. unlock
  4. settle; swap; take
  5. finish unlock

This pattern was broken by #856; now sync and transfer must happen within unlock.

  • There is no reason for this restriction.
  • It impacts many use cases by requiring more activities happen inside the callback.
  • In some cases the restriction requires additional transfers, wasting thousands of gas.

@wjmelements
Copy link
Contributor Author

My recommendation is to revert #856.

@wjmelements
Copy link
Contributor Author

Full writeup is in the PR description: #885

@wjmelements
Copy link
Contributor Author

I have a second solution in case ToB-UNI4-3 is still considered important after reconsideration: #886.

@wjmelements
Copy link
Contributor Author

wjmelements commented Sep 30, 2024

I calculate that the gas impact of the newly necessary approve/transferFrom or extra transfer described in #885 for my project is between 8371 and 25292 for tokens DAI and WETH.

@wjmelements
Copy link
Contributor Author

I calculate that the gas impact of the newly necessary approve/transferFrom or extra transfer described in #885 for my project is between 8371 and 25292 for tokens DAI and WETH.

Full writeup is in the PR description: #885

I reproduce the impact statement here, which discusses who all is impacted and how.

Impact: Additional transfers

This section describes example of the aforementioned scenario, where being able to sync before unlock saves thousands of gas. For my project the gas impact is between 8371 and 25292 gas when the settled token is DAI or WETH.

Custodian Contract (CC)

This contract custodies funds and is the ultimate counterparty performing the swap. Perhaps it is an ERC-4337 smart account. Perhaps it is a multisig. But for whatever reason it doesn't have support for the UniswapV4 callback.

Swap Callback (SC)

This contract has support for the UniswapV4 callback. Its logic might be shared between many CC or it may be specific to one CC.

The swap with versatile sync: transfer

CC: PoolManager.sync(TokenA)
CC: TokenA.transfer(PoolManager, AmountIn)
CC: SC.performSwap()
SC: PoolManager.unlock()
PoolManager: SC.unlockCallback()
SC: PoolManager.settle(TokenA)
SC: PoolManager.swap()
SC: PoolManager.take(TokenB, CC)

The swap without versatile sync: approve/transferFrom

CC: TokenA.approve(SC, AmountIn)
CC: SC.performSwap()
SC: PoolManager.unlock()
PoolManager: SC.unlockCallback()
SC: PoolManager.sync(TokenA)
SC: TokenA.transferFrom(CC, PoolManager, AmountIn)
SC: PoolManager.settle(TokenA)
SC: PoolManager.swap()
SC: PoolManager.take(TokenB, CC)

The swap without versatile sync: transfer/transfer

CC: TokenA.transfer(SC, AmountIn)
CC: SC.performSwap()
SC: PoolManager.unlock()
PoolManager: SC.unlockCallback()
SC: PoolManager.sync(TokenA)
SC: TokenA.transfer(PoolManager, AmountIn)
SC: PoolManager.settle(TokenA)
SC: PoolManager.swap()
SC: PoolManager.take(TokenB, CC)

Analysis

The additional approval/transferFrom or transfer/transfer in comparison to a single transfer amounts to thousands to tens of thousands of gas.
Any account that wants to swap but doesn't have uniswap v4 callbacks benefits from sync outside of unlock.

@wjmelements
Copy link
Contributor Author

I have a second solution in case ToB-UNI4-3 is still considered important after reconsideration: #886.

#885 was closed, possibly in favor of #886.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant