-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
105 additions
and
15 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 openzeppelin-contracts
updated
619 files
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
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,88 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {BaseHook} from "./../../contracts/BaseHook.sol"; | ||
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; | ||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; | ||
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; | ||
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol"; | ||
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol"; | ||
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; | ||
|
||
contract Counter is BaseHook { | ||
using PoolIdLibrary for PoolKey; | ||
|
||
// NOTE: --------------------------------------------------------- | ||
// state variables should typically be unique to a pool | ||
// a single hook contract should be able to service multiple pools | ||
// --------------------------------------------------------------- | ||
|
||
mapping(PoolId => uint256 count) public beforeSwapCount; | ||
mapping(PoolId => uint256 count) public afterSwapCount; | ||
|
||
mapping(PoolId => uint256 count) public beforeAddLiquidityCount; | ||
mapping(PoolId => uint256 count) public beforeRemoveLiquidityCount; | ||
|
||
constructor(IPoolManager _poolManager) BaseHook(_poolManager) {} | ||
|
||
function getHookPermissions() public pure override returns (Hooks.Permissions memory) { | ||
return Hooks.Permissions({ | ||
beforeInitialize: false, | ||
afterInitialize: false, | ||
beforeAddLiquidity: true, | ||
afterAddLiquidity: false, | ||
beforeRemoveLiquidity: true, | ||
afterRemoveLiquidity: false, | ||
beforeSwap: true, | ||
afterSwap: true, | ||
beforeDonate: false, | ||
afterDonate: false, | ||
beforeSwapReturnDelta: false, | ||
afterSwapReturnDelta: false, | ||
afterAddLiquidityReturnDelta: false, | ||
afterRemoveLiquidityReturnDelta: false | ||
}); | ||
} | ||
|
||
// ----------------------------------------------- | ||
// NOTE: see IHooks.sol for function documentation | ||
// ----------------------------------------------- | ||
|
||
function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata) | ||
external | ||
override | ||
returns (bytes4, BeforeSwapDelta, uint24) | ||
{ | ||
beforeSwapCount[key.toId()]++; | ||
return (BaseHook.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); | ||
} | ||
|
||
function afterSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) | ||
external | ||
override | ||
returns (bytes4, int128) | ||
{ | ||
afterSwapCount[key.toId()]++; | ||
return (BaseHook.afterSwap.selector, 0); | ||
} | ||
|
||
function beforeAddLiquidity( | ||
address, | ||
PoolKey calldata key, | ||
IPoolManager.ModifyLiquidityParams calldata, | ||
bytes calldata | ||
) external override returns (bytes4) { | ||
beforeAddLiquidityCount[key.toId()]++; | ||
return BaseHook.beforeAddLiquidity.selector; | ||
} | ||
|
||
function beforeRemoveLiquidity( | ||
address, | ||
PoolKey calldata key, | ||
IPoolManager.ModifyLiquidityParams calldata, | ||
bytes calldata | ||
) external override returns (bytes4) { | ||
beforeRemoveLiquidityCount[key.toId()]++; | ||
return BaseHook.beforeRemoveLiquidity.selector; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
contracts/middleware/test/FeeTakingLite.sol → test/middleware/FeeTakingLite.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
2 changes: 1 addition & 1 deletion
2
contracts/middleware/test/HooksOutOfGas.sol → test/middleware/HooksOutOfGas.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
2 changes: 1 addition & 1 deletion
2
contracts/middleware/test/HooksRevert.sol → test/middleware/HooksRevert.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
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