Skip to content

Commit

Permalink
fix: a
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedm1 committed Sep 7, 2023
1 parent 340e14c commit 6249235
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions contracts/SemiFungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
/// @notice Modifier that prohibits reentrant calls for a specific pool
/// @dev We piggyback the reentrancy lock on the (pool id => pool) mapping to save gas
/// @dev (there's an extra 96 bits of storage available in the mapping slot and it's almost always warm)
/// @param poolId The poolId of the pool to activate the reentrancy lock on
modifier ReentrancyLock(uint64 poolId) {
// check if the pool is already locked
// init lock if not
Expand All @@ -335,6 +336,8 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
/// @dev If the pool IDs are different, behavior is equivalent to calling `ReentrancyLock` on both pools
/// @dev We piggyback the reentrancy lock on the (pool id => pool) mapping to save gas
/// @dev (there's an extra 96 bits of storage available in the mapping slot and it's almost always warm)
/// @param poolIdOld the poolId of the pool on the tokenId being rolled from
/// @param poolIdNew the poolId of the pool on the tokenId being rolled to
modifier ReentrancyLockRoll(uint64 poolIdOld, uint64 poolIdNew) {
if (poolIdOld != poolIdNew) {
// check if the pools are already locked
Expand Down Expand Up @@ -384,7 +387,7 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
//////////////////////////////////////////////////////////////*/

/// @notice Construct the Semi-Fungible Position Manager (SFPM)
/// @param _factory the Uniswap v3 Factory used to retrieve registered Uniswap pools.
/// @param _factory the Uniswap v3 Factory used to retrieve registered Uniswap pools
constructor(IUniswapV3Factory _factory) {
FACTORY = _factory;
}
Expand Down Expand Up @@ -860,7 +863,7 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
/// It that position is burnt, then we remove a mix of the two tokens and swap one of them so that the user receives only one.
/// @param univ3pool the uniswap pool in which to swap.
/// @param itmAmounts how much to swap - how much is ITM
/// @return totalSwapped the amount swapped in the AMM.
/// @return totalSwapped the amount swapped in the AMM
function swapInAMM(
IUniswapV3Pool univ3pool,
int256 itmAmounts
Expand Down Expand Up @@ -1064,7 +1067,7 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
/// @param _univ3pool the Uniswap pool.
/// @param _tokenId the option position
/// @param _leg the leg index that needs to be modified
/// @param _liquidityChunk has lower tick, upper tick, and liquidity amount to mint.
/// @param _liquidityChunk has lower tick, upper tick, and liquidity amount to mint
/// @param _isBurn is true if the position is burnt
/// @return _moved the total amount of liquidity moved from the msg.sender to Uniswap
/// @return _itmAmounts the amount of tokens swapped due to legs being in-the-money
Expand Down Expand Up @@ -1203,9 +1206,9 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
}

/// @notice caches/stores the accumulated premia values for the specified postion.
/// @param positionKey the hashed data which represents the underlying position in the Uniswap pool.
/// @param currentLiquidity the total amount of liquidity in the AMM for the specific position.
/// @param collectedAmounts amount of tokens (token0 and token1) collected from Uniswap.
/// @param positionKey the hashed data which represents the underlying position in the Uniswap pool
/// @param currentLiquidity the total amount of liquidity in the AMM for the specific position
/// @param collectedAmounts amount of tokens (token0 and token1) collected from Uniswap
function _updateStoredPremia(
bytes32 positionKey,
uint256 currentLiquidity,
Expand All @@ -1224,8 +1227,8 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {

/// @notice Compute the feesGrowth * liquidity / 2**128 by reading feeGrowthInside0LastX128 and feeGrowthInside1LastX128 from univ3pool.positions.
/// @param univ3pool the Uniswap pool.
/// @param liquidity the total amount of liquidity in the AMM for the specific position.
/// @param liquidityChunk has lower tick, upper tick, and liquidity amount to mint.
/// @param liquidity the total amount of liquidity in the AMM for the specific position
/// @param liquidityChunk has lower tick, upper tick, and liquidity amount to mint
function _getFeesBase(
IUniswapV3Pool univ3pool,
uint128 liquidity,
Expand Down Expand Up @@ -1261,6 +1264,11 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
);
}

/// @notice Mint a chunk of liquidity (`liquidityChunk`) in the Uniswap v3 pool; return the amount moved.
/// @dev note that "moved" means: mint in Uniswap and move tokens from msg.sender.
/// @param liquidityChunk the chunk of liquidity to mint given by tick upper, tick lower, and its size
/// @param univ3pool the Uniswap v3 pool to mint liquidity in/to
/// @return movedAmounts how many tokens were moved from msg.sender to Uniswap
function _mintLiquidity(
uint256 liquidityChunk,
IUniswapV3Pool univ3pool
Expand Down Expand Up @@ -1296,11 +1304,11 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
);
}

/// @notice Burn a chunk of liquidity (`liquidityChunk`) in the Uniswap v3 pool and send to the Panoptic Pool; return the amount moved.
/// @dev note that "moved" means: burn in Uniswap and send to msg.sender.
/// @notice Burn a chunk of liquidity (`liquidityChunk`) in the Uniswap v3 pool and send to msg.sender; return the amount moved.
/// @dev note that "moved" means: burn position in Uniswap and send tokens to msg.sender.
/// @param liquidityChunk the chunk of liquidity to burn given by tick upper, tick lower, and its size
/// @param univ3pool the Uniswap v3 pool to burn liquidity in/from
/// @return movedAmounts how much liquidity was moved from Uniswap to msg.sender.
/// @return movedAmounts how many tokens were moved from Uniswap to msg.sender
function _burnLiquidity(
uint256 liquidityChunk,
IUniswapV3Pool univ3pool
Expand Down Expand Up @@ -1329,9 +1337,9 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
/// @param univ3pool the Uniswap pool where the position is deployed
/// @param currentLiquidity the existing liquidity msg.sender owns in the AMM for this chunk before the SFPM was called
/// @param positionKey the unique key to identify the liquidity chunk/tokenType pairing in this uniswap pool
/// @param movedInLeg how much liquidity has been moved between msg.sender and Uniswap before this function call.
/// @param movedInLeg how much liquidity has been moved between msg.sender and Uniswap before this function call
/// @param isLong whether the leg in question is long (=1) or short (=0)
/// @return collectedOut the incoming totalCollected with potentially whatever is collected in this function added to it.
/// @return collectedOut the incoming totalCollected with potentially whatever is collected in this function added to it
function _collectAndWritePositionData(
uint256 liquidityChunk,
IUniswapV3Pool univ3pool,
Expand Down Expand Up @@ -1471,10 +1479,10 @@ contract SemiFungiblePositionManager is ERC1155, Multicall {
/// @param positionSize the amount of the position to roll
/// @param tickLimitLow lower tick for slippage check
/// @param tickLimitHigh upper tick for slippage check
/// @return totalCollectedBurn total amount of fees collected from the burnt chunk.
/// @return totalSwappedBurn total amount of tokens swapped during the burn.
/// @return totalCollectedMint total amount of fees collected from the mint chunk.
/// @return totalSwappedMint total amount of tokens swapped during the mint.
/// @return totalCollectedBurn total amount of fees collected from the burnt chunk
/// @return totalSwappedBurn total amount of tokens swapped during the burn
/// @return totalCollectedMint total amount of fees collected from the mint chunk
/// @return totalSwappedMint total amount of tokens swapped during the mint
function _exerciseRolls(
uint256 burnTokenId,
uint256 mintTokenId,
Expand Down

0 comments on commit 6249235

Please sign in to comment.