-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement v4Migrator for cl-pool
- Loading branch information
1 parent
bd5b369
commit c759b71
Showing
10 changed files
with
413 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule v2-core
deleted from
4dd590
Submodule v3-periphery
deleted from
80f26c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// Copyright (C) 2024 PancakeSwap | ||
pragma solidity ^0.8.19; | ||
|
||
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol"; | ||
|
||
interface IBaseMigrator { | ||
event MoreFundsAdded(address currency0, address currency1, uint256 extraAmount0, uint256 extraAmount1); | ||
|
||
struct V2PoolParams { | ||
// the PancakeSwap v2-compatible pair | ||
address pair; | ||
// the amount of v2 lp token to be withdrawn | ||
uint256 migrateAmount; | ||
} | ||
|
||
struct V3PoolParams { | ||
// the PancakeSwap v3-compatible NFP | ||
address nfp; | ||
uint256 tokenId; | ||
uint128 liquidity; | ||
uint256 amount0Min; | ||
uint256 amount1Min; | ||
// decide whether to collect fee | ||
bool collectFee; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity >=0.5.0; | ||
|
||
/// @notice Copying from PancakeSwap V2 Pair | ||
/// https://github.com/pancakeswap/pancake-swap-core-v2/blob/master/contracts/interfaces/IPancakePair.sol | ||
interface IPancakePair { | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
|
||
function name() external pure returns (string memory); | ||
function symbol() external pure returns (string memory); | ||
function decimals() external pure returns (uint8); | ||
function totalSupply() external view returns (uint256); | ||
function balanceOf(address owner) external view returns (uint256); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
|
||
function approve(address spender, uint256 value) external returns (bool); | ||
function transfer(address to, uint256 value) external returns (bool); | ||
function transferFrom(address from, address to, uint256 value) external returns (bool); | ||
|
||
function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
function PERMIT_TYPEHASH() external pure returns (bytes32); | ||
function nonces(address owner) external view returns (uint256); | ||
|
||
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) | ||
external; | ||
|
||
event Mint(address indexed sender, uint256 amount0, uint256 amount1); | ||
event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to); | ||
event Swap( | ||
address indexed sender, | ||
uint256 amount0In, | ||
uint256 amount1In, | ||
uint256 amount0Out, | ||
uint256 amount1Out, | ||
address indexed to | ||
); | ||
event Sync(uint112 reserve0, uint112 reserve1); | ||
|
||
function MINIMUM_LIQUIDITY() external pure returns (uint256); | ||
function factory() external view returns (address); | ||
function token0() external view returns (address); | ||
function token1() external view returns (address); | ||
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); | ||
function price0CumulativeLast() external view returns (uint256); | ||
function price1CumulativeLast() external view returns (uint256); | ||
function kLast() external view returns (uint256); | ||
|
||
function mint(address to) external returns (uint256 liquidity); | ||
function burn(address to) external returns (uint256 amount0, uint256 amount1); | ||
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external; | ||
function skim(address to) external; | ||
function sync() external; | ||
|
||
function initialize(address, address) external; | ||
} |
156 changes: 156 additions & 0 deletions
156
src/interfaces/external/IV3NonfungiblePositionManager.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity >=0.7.5; | ||
pragma abicoder v2; | ||
|
||
/// @title Non-fungible token for positions | ||
/// @notice Wraps PancakeSwap V3 positions in a non-fungible token interface which allows for them to be transferred | ||
/// and authorized. Copying from PancakeSwap-V3 | ||
/// https://github.com/pancakeswap/pancake-v3-contracts/blob/main/projects/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol | ||
interface IV3NonfungiblePositionManager { | ||
/// @notice Emitted when liquidity is increased for a position NFT | ||
/// @dev Also emitted when a token is minted | ||
/// @param tokenId The ID of the token for which liquidity was increased | ||
/// @param liquidity The amount by which liquidity for the NFT position was increased | ||
/// @param amount0 The amount of token0 that was paid for the increase in liquidity | ||
/// @param amount1 The amount of token1 that was paid for the increase in liquidity | ||
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); | ||
/// @notice Emitted when liquidity is decreased for a position NFT | ||
/// @param tokenId The ID of the token for which liquidity was decreased | ||
/// @param liquidity The amount by which liquidity for the NFT position was decreased | ||
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity | ||
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity | ||
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); | ||
/// @notice Emitted when tokens are collected for a position NFT | ||
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior | ||
/// @param tokenId The ID of the token for which underlying tokens were collected | ||
/// @param recipient The address of the account that received the collected tokens | ||
/// @param amount0 The amount of token0 owed to the position that was collected | ||
/// @param amount1 The amount of token1 owed to the position that was collected | ||
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1); | ||
|
||
/// @notice Returns the position information associated with a given token ID. | ||
/// @dev Throws if the token ID is not valid. | ||
/// @param tokenId The ID of the token that represents the position | ||
/// @return nonce The nonce for permits | ||
/// @return operator The address that is approved for spending | ||
/// @return token0 The address of the token0 for a specific pool | ||
/// @return token1 The address of the token1 for a specific pool | ||
/// @return fee The fee associated with the pool | ||
/// @return tickLower The lower end of the tick range for the position | ||
/// @return tickUpper The higher end of the tick range for the position | ||
/// @return liquidity The liquidity of the position | ||
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position | ||
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position | ||
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation | ||
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation | ||
function positions(uint256 tokenId) | ||
external | ||
view | ||
returns ( | ||
uint96 nonce, | ||
address operator, | ||
address token0, | ||
address token1, | ||
uint24 fee, | ||
int24 tickLower, | ||
int24 tickUpper, | ||
uint128 liquidity, | ||
uint256 feeGrowthInside0LastX128, | ||
uint256 feeGrowthInside1LastX128, | ||
uint128 tokensOwed0, | ||
uint128 tokensOwed1 | ||
); | ||
|
||
struct MintParams { | ||
address token0; | ||
address token1; | ||
uint24 fee; | ||
int24 tickLower; | ||
int24 tickUpper; | ||
uint256 amount0Desired; | ||
uint256 amount1Desired; | ||
uint256 amount0Min; | ||
uint256 amount1Min; | ||
address recipient; | ||
uint256 deadline; | ||
} | ||
|
||
/// @notice Creates a new position wrapped in a NFT | ||
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized | ||
/// a method does not exist, i.e. the pool is assumed to be initialized. | ||
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata | ||
/// @return tokenId The ID of the token that represents the minted position | ||
/// @return liquidity The amount of liquidity for this position | ||
/// @return amount0 The amount of token0 | ||
/// @return amount1 The amount of token1 | ||
function mint(MintParams calldata params) | ||
external | ||
payable | ||
returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
struct IncreaseLiquidityParams { | ||
uint256 tokenId; | ||
uint256 amount0Desired; | ||
uint256 amount1Desired; | ||
uint256 amount0Min; | ||
uint256 amount1Min; | ||
uint256 deadline; | ||
} | ||
|
||
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` | ||
/// @param params tokenId The ID of the token for which liquidity is being increased, | ||
/// amount0Desired The desired amount of token0 to be spent, | ||
/// amount1Desired The desired amount of token1 to be spent, | ||
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check, | ||
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check, | ||
/// deadline The time by which the transaction must be included to effect the change | ||
/// @return liquidity The new liquidity amount as a result of the increase | ||
/// @return amount0 The amount of token0 to acheive resulting liquidity | ||
/// @return amount1 The amount of token1 to acheive resulting liquidity | ||
function increaseLiquidity(IncreaseLiquidityParams calldata params) | ||
external | ||
payable | ||
returns (uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
struct DecreaseLiquidityParams { | ||
uint256 tokenId; | ||
uint128 liquidity; | ||
uint256 amount0Min; | ||
uint256 amount1Min; | ||
uint256 deadline; | ||
} | ||
|
||
/// @notice Decreases the amount of liquidity in a position and accounts it to the position | ||
/// @param params tokenId The ID of the token for which liquidity is being decreased, | ||
/// amount The amount by which liquidity will be decreased, | ||
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, | ||
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, | ||
/// deadline The time by which the transaction must be included to effect the change | ||
/// @return amount0 The amount of token0 accounted to the position's tokens owed | ||
/// @return amount1 The amount of token1 accounted to the position's tokens owed | ||
function decreaseLiquidity(DecreaseLiquidityParams calldata params) | ||
external | ||
payable | ||
returns (uint256 amount0, uint256 amount1); | ||
|
||
struct CollectParams { | ||
uint256 tokenId; | ||
address recipient; | ||
uint128 amount0Max; | ||
uint128 amount1Max; | ||
} | ||
|
||
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient | ||
/// @param params tokenId The ID of the NFT for which tokens are being collected, | ||
/// recipient The account that should receive the tokens, | ||
/// amount0Max The maximum amount of token0 to collect, | ||
/// amount1Max The maximum amount of token1 to collect | ||
/// @return amount0 The amount of fees collected in token0 | ||
/// @return amount1 The amount of fees collected in token1 | ||
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1); | ||
|
||
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens | ||
/// must be collected first. | ||
/// @param tokenId The ID of the token that is being burned | ||
function burn(uint256 tokenId) external payable; | ||
} |
Oops, something went wrong.