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

V4 BinMigrator #59

Merged
merged 8 commits into from
Jul 18, 2024
Merged

V4 BinMigrator #59

merged 8 commits into from
Jul 18, 2024

Conversation

chefburger
Copy link
Collaborator

Same as pancakeswap/pancake-v4-periphery#51 but for bin-pool

@chefburger chefburger changed the base branch from main to feat/migrator July 9, 2024 07:25
@chefburger chefburger marked this pull request as draft July 9, 2024 07:26
@chefburger chefburger force-pushed the feat/binPool-migrator branch from 4bb0e82 to 7971c3b Compare July 9, 2024 08:14
@chefburger chefburger self-assigned this Jul 10, 2024
@chefburger chefburger marked this pull request as ready for review July 10, 2024 09:55
@chefburger chefburger force-pushed the feat/binPool-migrator branch from f1fb45e to c48480b Compare July 10, 2024 09:55
@chefburger chefburger force-pushed the feat/binPool-migrator branch from c48480b to 3c0c42d Compare July 10, 2024 09:59
@ChefMist ChefMist self-requested a review July 11, 2024 07:46
src/base/BaseMigrator.sol Outdated Show resolved Hide resolved
src/base/BaseMigrator.sol Outdated Show resolved Hide resolved
binFungiblePositionManager = IBinFungiblePositionManager(_binFungiblePositionManager);
}

function migrateFromV2(
Copy link
Collaborator

Choose a reason for hiding this comment

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

likewise can we add more natspec to all these function as well to make it easier for other devs

@chefburger chefburger force-pushed the feat/binPool-migrator branch from e700e77 to 2208034 Compare July 15, 2024 04:26
/// @notice compare if tokens from v3 pool are the same as token0/token1. Revert with
/// `TOKEN_NOT_MATCH` if tokens does not match
function checkTokenMatchFromV3(address nfp, uint256 tokenId, Currency token0, Currency token1) internal view {
(,, address token0V3, address token1V3,,,,,,,,) = IV3NonfungiblePositionManager(nfp).positions(tokenId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because the NFT position storage is too big , now we will query twice in checkTokenMatchFromV3 and withdrawLiquidityFromV3.
we should only query the NFT position once , can save almost 4k Gas.
Did a POC commit.
pancakeswap/pancake-v4-periphery@3f5afe6#diff-1a378b56bc0f605ffd85c5c0d02bae3dd8e2b735213e76b74f84719322dbd454

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yea, agree. Thx for reminding. let me draft an update for this

/// `TOKEN_NOT_MATCH` if tokens does not match
function checkTokenMatchFromV2(address v2Pair, Currency token0, Currency token1) internal view {
address token0V2 = IPancakePair(v2Pair).token0();
address token1V2 = IPancakePair(v2Pair).token1();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for the IPancakePair(v2Pair).token1(); did not test how muck gas will cost.
But it is better to query once.

* feat: support selfPermitForERC721

* docs: added comments suggesting users to use selfPermitERC721IfNecessary

* test: added tests to prevent ppl from removing payable keyword from external functions
@chefburger chefburger merged commit 3503133 into feat/migrator Jul 18, 2024
2 checks passed
@chefburger chefburger deleted the feat/binPool-migrator branch July 18, 2024 07:17
chefburger added a commit that referenced this pull request Jul 18, 2024
* feat: implement v4Migrator for cl-pool

* feat: added same price slippage check for migrateFromV2

* feat: using actual receive amount when adding liquidity to v4

* test: added test for clMigrator

* fix: take into consideration of extra funds when calc refund

* optimization: avoid unnecessary approve in old token cases

* optimization: avoid unnecessary refund call after adding liquidity

* optimization: avoid unnecessary WETH unwrap

* fix: extra check so that non-owner can not steal funds from lpV3 token

* typo

* refactor: restructure baseMigrator a bit so that more can be reused across pool type

* chore: typo and renaming

* V4 BinMigrator (#59)

* feat: impl binPool migrator

* refactor: restructure & renaming accordingly

* test: add tests cases for binPool migrator

* chore: renaming as well to align with clMigrator

* fix: add check to prevent token mismatch between source and target pool

* feat: added refundETH function and necessary comments

* optimization: avoid duplicate external call when query v2/v3 pool info

* feat: support selfPermitForERC721 (#62)

* feat: support selfPermitForERC721

* docs: added comments suggesting users to use selfPermitERC721IfNecessary

* test: added tests to prevent ppl from removing payable keyword from external functions

* docs: add explanation about the case where extra token0 is ETH
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