Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
rileydcampbell committed Dec 14, 2023
1 parent 1260a27 commit 43d5aea
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 100 deletions.
3 changes: 2 additions & 1 deletion docs/latex/main-zh.tex
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ \subsection{操作Hooks}

\begin{itemize}
\item beforeInitialize/afterInitialize
\item beforeModifyPosition/afterModifyPosition
\item beforeAddLiquidity/afterAddLiquidity
\item beforeRemoveLiquidity/afterRemoveLiquidity
\item beforeSwap/afterSwap
\item beforeDonate/afterDonate
\end{itemize}
Expand Down
3 changes: 2 additions & 1 deletion docs/latex/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ \subsection{Action Hooks} \label{actionhooks}

\begin{itemize}
\item beforeInitialize/afterInitialize
\item beforeModifyPosition/afterModifyPosition
\item beforeAddLiquidity/afterAddLiquidity
\item beforeRemoveLiquidity/afterRemoveLiquidity
\item beforeSwap/afterSwap
\item beforeDonate/afterDonate
\end{itemize}
Expand Down
6 changes: 3 additions & 3 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {
/// @inheritdoc IPoolManager
function modifyLiquidity(
PoolKey memory key,
IPoolManager.ModifyPositionParams memory params,
IPoolManager.ModifyLiquidityParams memory params,
bytes calldata hookData
) external override noDelegateCall onlyByLocker returns (BalanceDelta delta) {
PoolId id = key.toId();
_checkPoolInitialized(id);

if (!key.hooks.beforeModifyPosition(key, params, hookData)) {
if (!key.hooks.beforeModifyLiquidity(key, params, hookData)) {
return BalanceDeltaLibrary.MAXIMUM_DELTA;
}

Expand All @@ -201,7 +201,7 @@ contract PoolManager is IPoolManager, Fees, NoDelegateCall, Claims {

_accountPoolBalanceDelta(key, delta);

key.hooks.afterModifyPosition(key, params, delta, hookData);
key.hooks.afterModifyLiquidity(key, params, delta, hookData);

emit ModifyPosition(id, msg.sender, params.tickLower, params.tickUpper, params.liquidityDelta);
}
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/IHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IHooks {
function beforeAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
IPoolManager.ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (bytes4);

Expand All @@ -57,7 +57,7 @@ interface IHooks {
function afterAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
IPoolManager.ModifyLiquidityParams calldata params,
BalanceDelta delta,
bytes calldata hookData
) external returns (bytes4);
Expand All @@ -71,7 +71,7 @@ interface IHooks {
function beforeRemoveLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
IPoolManager.ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (bytes4);

Expand All @@ -84,7 +84,7 @@ interface IHooks {
function afterRemoveLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
IPoolManager.ModifyLiquidityParams calldata params,
BalanceDelta delta,
bytes calldata hookData
) external returns (bytes4);
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/IPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ interface IPoolManager is IFees, IClaims {
/// @return The data returned by the call to `ILockCallback(msg.sender).lockAcquired(data)`
function lock(address lockTarget, bytes calldata data) external payable returns (bytes memory);

struct ModifyPositionParams {
struct ModifyLiquidityParams {
// the lower and upper tick of the position
int24 tickLower;
int24 tickUpper;
Expand All @@ -161,7 +161,7 @@ interface IPoolManager is IFees, IClaims {
/// @param params The parameters for modifying the liquidity
/// @param hookData Any data to pass to the callback, via `ILockCallback(msg.sender).lockAcquired(data)`
/// @return delta The balance delta of the liquidity
function modifyLiquidity(PoolKey memory key, ModifyPositionParams memory params, bytes calldata hookData)
function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
external
returns (BalanceDelta);

Expand Down
12 changes: 6 additions & 6 deletions src/libraries/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ library Hooks {
}
}

/// @notice calls beforeModifyPosition hook if permissioned and validates return value
function beforeModifyPosition(
/// @notice calls beforeModifyLiquidity hook if permissioned and validates return value
function beforeModifyLiquidity(
IHooks self,
PoolKey memory key,
IPoolManager.ModifyPositionParams memory params,
IPoolManager.ModifyLiquidityParams memory params,
bytes calldata hookData
) internal returns (bool shouldExecute) {
if (params.liquidityDelta > 0 && key.hooks.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)) {
Expand All @@ -181,11 +181,11 @@ library Hooks {
}
}

/// @notice calls afterModifyPosition hook if permissioned and validates return value
function afterModifyPosition(
/// @notice calls afterModifyLiquidity hook if permissioned and validates return value
function afterModifyLiquidity(
IHooks self,
PoolKey memory key,
IPoolManager.ModifyPositionParams memory params,
IPoolManager.ModifyLiquidityParams memory params,
BalanceDelta delta,
bytes calldata hookData
) internal {
Expand Down
14 changes: 7 additions & 7 deletions src/test/AccessLockHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract AccessLockHook is Test, BaseTestHooks {
function beforeAddLiquidity(
address, /* sender **/
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata hookData
) external override returns (bytes4) {
return _executeAction(key, hookData, IHooks.beforeAddLiquidity.selector);
Expand All @@ -79,7 +79,7 @@ contract AccessLockHook is Test, BaseTestHooks {
function beforeRemoveLiquidity(
address, /* sender **/
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata hookData
) external override returns (bytes4) {
return _executeAction(key, hookData, IHooks.beforeRemoveLiquidity.selector);
Expand Down Expand Up @@ -112,7 +112,7 @@ contract AccessLockHook is Test, BaseTestHooks {
} else if (action == LockAction.ModifyPosition) {
manager.modifyLiquidity(
key,
IPoolManager.ModifyPositionParams({tickLower: -60, tickUpper: 60, liquidityDelta: int256(amount)}),
IPoolManager.ModifyLiquidityParams({tickLower: -60, tickUpper: 60, liquidityDelta: int256(amount)}),
new bytes(0)
);
} else if (action == LockAction.NoOp) {
Expand Down Expand Up @@ -158,7 +158,7 @@ contract AccessLockHook2 is Test, BaseTestHooks {
function beforeAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
IPoolManager.ModifyLiquidityParams calldata params,
bytes calldata hookData
) external override returns (bytes4) {
if (address(manager.getCurrentHook()) != address(this)) {
Expand Down Expand Up @@ -205,7 +205,7 @@ contract AccessLockHook3 is Test, ILockCallback, BaseTestHooks {
function beforeAddLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata /* hookData **/
) external override returns (bytes4) {
assertEq(address(manager.getCurrentHook()), address(this));
Expand Down Expand Up @@ -246,7 +246,7 @@ contract AccessLockFeeHook is Test, BaseTestHooks {
function afterAddLiquidity(
address, /* sender **/
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
BalanceDelta delta,
bytes calldata /* hookData **/
) external override returns (bytes4) {
Expand All @@ -262,7 +262,7 @@ contract AccessLockFeeHook is Test, BaseTestHooks {
function afterRemoveLiquidity(
address, /* sender **/
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
BalanceDelta delta,
bytes calldata /* hookData **/
) external override returns (bytes4) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/BaseTestHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract BaseTestHooks is IHooks {
function beforeAddLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert HookNotImplemented();
Expand All @@ -40,7 +40,7 @@ contract BaseTestHooks is IHooks {
function afterAddLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
BalanceDelta, /* delta **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
Expand All @@ -50,7 +50,7 @@ contract BaseTestHooks is IHooks {
function beforeRemoveLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
revert HookNotImplemented();
Expand All @@ -59,7 +59,7 @@ contract BaseTestHooks is IHooks {
function afterRemoveLiquidity(
address, /* sender **/
PoolKey calldata, /* key **/
IPoolManager.ModifyPositionParams calldata, /* params **/
IPoolManager.ModifyLiquidityParams calldata, /* params **/
BalanceDelta, /* delta **/
bytes calldata /* hookData **/
) external virtual returns (bytes4) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/EmptyTestHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract EmptyTestHooks is IHooks {
return IHooks.afterInitialize.selector;
}

function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyPositionParams calldata, bytes calldata)
function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
external
pure
override
Expand All @@ -59,7 +59,7 @@ contract EmptyTestHooks is IHooks {
function afterAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
bytes calldata
) external pure override returns (bytes4) {
Expand All @@ -69,7 +69,7 @@ contract EmptyTestHooks is IHooks {
function beforeRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external pure override returns (bytes4) {
return IHooks.beforeRemoveLiquidity.selector;
Expand All @@ -78,7 +78,7 @@ contract EmptyTestHooks is IHooks {
function afterRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
bytes calldata
) external pure override returns (bytes4) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/MockHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract MockHooks is IHooks {
function beforeAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata hookData
) external override returns (bytes4) {
beforeAddLiquidityData = hookData;
Expand All @@ -61,7 +61,7 @@ contract MockHooks is IHooks {
function afterAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
bytes calldata hookData
) external override returns (bytes4) {
Expand All @@ -73,7 +73,7 @@ contract MockHooks is IHooks {
function beforeRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata hookData
) external override returns (bytes4) {
beforeRemoveLiquidityData = hookData;
Expand All @@ -84,7 +84,7 @@ contract MockHooks is IHooks {
function afterRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
bytes calldata hookData
) external override returns (bytes4) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/NoOpTestHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract NoOpTestHooks is BaseTestHooks {
);
}

function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyPositionParams calldata, bytes calldata)
function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
external
pure
override
Expand All @@ -40,7 +40,7 @@ contract NoOpTestHooks is BaseTestHooks {
function beforeRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external pure override returns (bytes4) {
return Hooks.NO_OP_SELECTOR;
Expand Down
12 changes: 6 additions & 6 deletions src/test/PoolModifyPositionTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ contract PoolModifyPositionTest is Test, PoolTestBase {
struct CallbackData {
address sender;
PoolKey key;
IPoolManager.ModifyPositionParams params;
IPoolManager.ModifyLiquidityParams params;
bytes hookData;
}

function modifyLiquidity(PoolKey memory key, IPoolManager.ModifyPositionParams memory params, bytes memory hookData)
external
payable
returns (BalanceDelta delta)
{
function modifyLiquidity(
PoolKey memory key,
IPoolManager.ModifyLiquidityParams memory params,
bytes memory hookData
) external payable returns (BalanceDelta delta) {
delta = abi.decode(
manager.lock(address(this), abi.encode(CallbackData(msg.sender, key, params, hookData))), (BalanceDelta)
);
Expand Down
Loading

0 comments on commit 43d5aea

Please sign in to comment.