-
Notifications
You must be signed in to change notification settings - Fork 6
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
V4 BinMigrator #59
Conversation
4bb0e82
to
7971c3b
Compare
f1fb45e
to
c48480b
Compare
c48480b
to
3c0c42d
Compare
binFungiblePositionManager = IBinFungiblePositionManager(_binFungiblePositionManager); | ||
} | ||
|
||
function migrateFromV2( |
There was a problem hiding this comment.
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
e700e77
to
2208034
Compare
/// @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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
* 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
Same as pancakeswap/pancake-v4-periphery#51 but for bin-pool