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

<WIP> feat: set reserveOf transient #33

Closed
wants to merge 4 commits into from
Closed

Conversation

ChefMist
Copy link
Collaborator

@ChefMist ChefMist commented May 3, 2024

This PR is a POC on setting reserveOf as transient.

Context

  1. user flow to v4-core would change from erc20.transfer(vault, amt) -> vault.settle() to vault.sync() -> erc20.transfer(vault, amt) -> vault.settle()

  2. as reservesOf are already tracked in reserveOfPoolManager, reserveOf is now transient. This should still be secured in the sense that CLPoolManager cannot take BinPoolManager asset

  3. This also remove the need for settleAndMintRefund() due to a sync(currency) which set the current erc20 balance

  4. this should save gas however the snapshot might not show this case (see below)

Why gas snapshot doesn't show this case ?

  1. we are using forge test where we should use forge test --isolate to run each statement as a new transaction. In this case we can see the clear benefit of transient storage

Discussion:

  1. potentially have seperate PR to use forge test --isolate and snapLastCall() and merge then update this branch and we can see clear gas benefit
  2. [discuss] update test cases to remove reserveOf check or move to erc20.balanceOf(vault)
  3. [discuss] instead of a sync call, do we want to explore another method eg. lockWithSync(bytes calldata data, Currency[] currency) which gets a lock() and sync() those currency

@ChefSnoopy
Copy link
Collaborator

So now we use sync, the excess tokens be burned ?

@ChefMist
Copy link
Collaborator Author

ChefMist commented May 6, 2024

So now we use sync, the excess tokens be burned ?

do you mean the case when someone else randomly send erc20 token to the vault? If so, then yes, those tokens are burned now if this PR is merged.

ChefSnoopy
ChefSnoopy previously approved these changes May 6, 2024
chef-omelette
chef-omelette previously approved these changes May 6, 2024
Copy link
Contributor

@chef-omelette chef-omelette left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +44 to +48
assembly {
mstore(0x0, slot)
mstore(0x20, currency)
key := keccak256(0x0, 0x40)
}
Copy link
Contributor

@chef-omelette chef-omelette May 6, 2024

Choose a reason for hiding this comment

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

just curious, why not keccak256(abi.encodePacked(slot, currency.unwrap())) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mostly around gas savings, can see CLPosition and BinPosition using similar technique.

@ChefMist ChefMist mentioned this pull request May 7, 2024
@ChefMist ChefMist dismissed stale reviews from chef-omelette and ChefSnoopy via 6b6f7ed May 7, 2024 06:43
@ChefMist
Copy link
Collaborator Author

ChefMist commented May 7, 2024

now the latest test snapshot would be more accurate. though some test are failing and have comment out for now. likely this PR can serve as reference for now

@chefburger
Copy link
Collaborator

#42

@chefburger chefburger closed this May 17, 2024
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

4 participants