Skip to content

Commit

Permalink
compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Jul 31, 2024
1 parent 43aa81f commit e51e16b
Show file tree
Hide file tree
Showing 58 changed files with 223 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/BaseActionsRouter_mock10commands.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62960
34844
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46864
14995
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46681
14995
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_nonEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132224
48191
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_nonEmpty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125145
51899
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152889
72860
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144041
76568
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152889
72860
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decreaseLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118432
40307
Original file line number Diff line number Diff line change
@@ -1 +1 @@
110708
44015
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136102
50159
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128841
53867
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131148
38623
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154374
48545
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136174
46901
Original file line number Diff line number Diff line change
@@ -1 +1 @@
137095
65984
Original file line number Diff line number Diff line change
@@ -1 +1 @@
173251
77916
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
374409
344624
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
339109
309780
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_nativeWithSweep.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
347739
317494
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
317091
255406
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
317733
260048
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
243315
160730
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372583
325892
Original file line number Diff line number Diff line change
@@ -1 +1 @@
323109
260624
Original file line number Diff line number Diff line change
@@ -1 +1 @@
418855
386334
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121090
94942
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120257
94109
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129129
102501
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135959
109331
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
187311
159499
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179274
151942
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238692
209672
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
230679
202115
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134717
108241
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119848
93852
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118993
93009
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126893
100553
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121098
94758
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129970
103150
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134771
107951
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186732
158728
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183655
156131
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238737
209525
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235684
206928
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229889
201133
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133251
106775
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125373
99377
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119636
93652
66 changes: 46 additions & 20 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {DeltaResolver} from "./base/DeltaResolver.sol";
import {PositionConfig, PositionConfigLibrary} from "./libraries/PositionConfig.sol";
import {BaseActionsRouter} from "./base/BaseActionsRouter.sol";
import {Actions} from "./libraries/Actions.sol";
import {StakingNotifier, StakingConfig} from "./base/StakingNotifier.sol";
import {Notifier} from "./base/Notifier.sol";
import {CalldataDecoder} from "./libraries/CalldataDecoder.sol";

contract PositionManager is
Expand All @@ -35,12 +35,12 @@ contract PositionManager is
DeltaResolver,
ReentrancyLock,
BaseActionsRouter,
StakingNotifier
Notifier
{
using SafeTransferLib for *;
using CurrencyLibrary for Currency;
using PoolIdLibrary for PoolKey;
using PositionConfigLibrary for PositionConfig;
using PositionConfigLibrary for *;
using StateLibrary for IPoolManager;
using TransientStateLibrary for IPoolManager;
using SafeCast for uint256;
Expand All @@ -50,13 +50,13 @@ contract PositionManager is
uint256 public nextTokenId = 1;

/// @inheritdoc IPositionManager
mapping(uint256 tokenId => bytes32 configId) public positionConfigs;
mapping(uint256 tokenId => bytes32 config) public positionConfigs;

IAllowanceTransfer public immutable permit2;

constructor(IPoolManager _poolManager, IAllowanceTransfer _permit2, uint256 _stakingGasLimit)
constructor(IPoolManager _poolManager, IAllowanceTransfer _permit2, uint256 _subscriberGasLimit)
BaseActionsRouter(_poolManager)
StakingNotifier(_stakingGasLimit)
Notifier(_subscriberGasLimit)
ERC721Permit("Uniswap V4 Positions NFT", "UNI-V4-POSM", "1")
{
permit2 = _permit2;
Expand All @@ -67,6 +67,16 @@ contract PositionManager is
_;
}

modifier onlyIfApproved(address sender, uint256 tokenId) {
if (!_isApprovedOrOwner(sender, tokenId)) revert NotApproved(sender);
_;
}

modifier onlyValidConfig(uint256 tokenId, PositionConfig calldata config) {
if (positionConfigs.getConfigId(tokenId) != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);
_;
}

/// @param unlockData is an encoding of actions, params, and currencies
/// @param deadline is the timestamp at which the unlockData will no longer be valid
function modifyLiquidities(bytes calldata unlockData, uint256 deadline)
Expand All @@ -78,6 +88,25 @@ contract PositionManager is
_executeActions(unlockData);
}

function subscribe(uint256 tokenId, PositionConfig calldata config, address subscriber)
external
onlyIfApproved(msg.sender, tokenId)
onlyValidConfig(tokenId, config)
{
if (positionConfigs.getConfigId(tokenId) != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);
_subscribe(tokenId, config, subscriber);
positionConfigs.setSubscribe(tokenId);
}

function unsubscribe(uint256 tokenId, PositionConfig calldata config)
external
onlyIfApproved(msg.sender, tokenId)
{
if (positionConfigs.getConfigId(tokenId) != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);
_unsubscribe(tokenId, config);
positionConfigs.setUnsubscribe(tokenId);
}

function _handleAction(uint256 action, bytes calldata params) internal override {
if (action == Actions.INCREASE_LIQUIDITY) {
(uint256 tokenId, PositionConfig calldata config, uint256 liquidity, bytes calldata hookData) =
Expand Down Expand Up @@ -116,19 +145,18 @@ contract PositionManager is
/// @dev Calling increase with 0 liquidity will credit the caller with any underlying fees of the position
function _increase(uint256 tokenId, PositionConfig calldata config, uint256 liquidity, bytes calldata hookData)
internal
onlyValidConfig(tokenId, config)
{
if (positionConfigs[tokenId] != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);
// Note: The tokenId is used as the salt for this position, so every minted position has unique storage in the pool manager.
BalanceDelta liquidityDelta = _modifyLiquidity(config, liquidity.toInt256(), bytes32(tokenId), hookData);
}

/// @dev Calling decrease with 0 liquidity will credit the caller with any underlying fees of the position
function _decrease(uint256 tokenId, PositionConfig calldata config, uint256 liquidity, bytes calldata hookData)
internal
onlyIfApproved(_msgSender(), tokenId)
onlyValidConfig(tokenId, config)
{
if (!_isApprovedOrOwner(_msgSender(), tokenId)) revert NotApproved(_msgSender());
if (positionConfigs[tokenId] != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);

// Note: the tokenId is used as the salt.
BalanceDelta liquidityDelta = _modifyLiquidity(config, -(liquidity.toInt256()), bytes32(tokenId), hookData);
}
Expand Down Expand Up @@ -171,9 +199,11 @@ contract PositionManager is
}

/// @dev this is overloaded with ERC721Permit._burn
function _burn(uint256 tokenId, PositionConfig calldata config, bytes calldata hookData) internal {
if (!_isApprovedOrOwner(_msgSender(), tokenId)) revert NotApproved(_msgSender());
if (positionConfigs[tokenId] != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);
function _burn(uint256 tokenId, PositionConfig calldata config, bytes calldata hookData)
internal
onlyIfApproved(_msgSender(), tokenId)
onlyValidConfig(tokenId, config)
{
uint256 liquidity = uint256(_getPositionLiquidity(config, tokenId));

BalanceDelta liquidityDelta;
Expand Down Expand Up @@ -204,13 +234,9 @@ contract PositionManager is
hookData
);

_notifyModifyLiquidity(uint256(salt), liquidityChange, config);
}

function stake(uint256 tokenId, StakingConfig calldata stakingConfig, PositionConfig calldata config) external {
if (!_isApprovedOrOwner(_msgSender(), tokenId)) revert NotApproved(_msgSender());
if (positionConfigs[tokenId] != config.toId()) revert IncorrectPositionConfigForTokenId(tokenId);
_notifyStake(tokenId, stakingConfig, config);
if (positionConfigs.getSubscribed(uint256(salt))) {
_notifyModifyLiquidity(uint256(salt), config, liquidityChange);
}
}

function _getPositionLiquidity(PositionConfig calldata config, uint256 tokenId)
Expand Down
Loading

0 comments on commit e51e16b

Please sign in to comment.