-
Notifications
You must be signed in to change notification settings - Fork 976
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
1 parent
90e1b79
commit 3ad999a
Showing
4 changed files
with
151 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {IHooks} from "../interfaces/IHooks.sol"; | ||
import {PoolKey} from "../types/PoolKey.sol"; | ||
import {BalanceDelta} from "../types/BalanceDelta.sol"; | ||
import {IPoolManager} from "../interfaces/IPoolManager.sol"; | ||
|
||
contract BaseTestHooks is IHooks { | ||
error HookNotImplemented(); | ||
|
||
function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, bytes calldata hookData) | ||
external | ||
virtual | ||
returns (bytes4) | ||
{ | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function afterInitialize( | ||
address sender, | ||
PoolKey calldata key, | ||
uint160 sqrtPriceX96, | ||
int24 tick, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function beforeModifyPosition( | ||
address sender, | ||
PoolKey calldata key, | ||
IPoolManager.ModifyPositionParams calldata params, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function afterModifyPosition( | ||
address sender, | ||
PoolKey calldata key, | ||
IPoolManager.ModifyPositionParams calldata params, | ||
BalanceDelta delta, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function beforeSwap( | ||
address sender, | ||
PoolKey calldata key, | ||
IPoolManager.SwapParams calldata params, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function afterSwap( | ||
address sender, | ||
PoolKey calldata key, | ||
IPoolManager.SwapParams calldata params, | ||
BalanceDelta delta, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function beforeDonate( | ||
address sender, | ||
PoolKey calldata key, | ||
uint256 amount0, | ||
uint256 amount1, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
|
||
function afterDonate( | ||
address sender, | ||
PoolKey calldata key, | ||
uint256 amount0, | ||
uint256 amount1, | ||
bytes calldata hookData | ||
) external virtual returns (bytes4) { | ||
revert HookNotImplemented(); | ||
} | ||
} |
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,47 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {BaseTestHooks} from "./BaseTestHooks.sol"; | ||
import {IDynamicFeeManager} from "../interfaces/IDynamicFeeManager.sol"; | ||
import {PoolKey} from "../types/PoolKey.sol"; | ||
import {IPoolManager} from "../interfaces/IPoolManager.sol"; | ||
import {IHooks} from "../interfaces/IHooks.sol"; | ||
|
||
contract DynamicFeesTest is BaseTestHooks, IDynamicFeeManager { | ||
uint24 internal fee; | ||
IPoolManager manager; | ||
|
||
constructor() {} | ||
|
||
function setManager(IPoolManager _manager) external { | ||
manager = _manager; | ||
} | ||
|
||
function setFee(uint24 _fee) external { | ||
fee = _fee; | ||
} | ||
|
||
function getFee(address, PoolKey calldata) public view returns (uint24) { | ||
return fee; | ||
} | ||
|
||
function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata hookData) | ||
external | ||
override | ||
returns (bytes4) | ||
{ | ||
// updates the dynamic fee in the pool if update is true | ||
bool _update; | ||
uint24 _fee; | ||
|
||
if (hookData.length > 0) { | ||
(_update, _fee) = abi.decode(hookData, (bool, uint24)); | ||
} | ||
if (_update == true) { | ||
fee = _fee; | ||
|
||
manager.setDynamicFee(key); | ||
} | ||
return IHooks.beforeSwap.selector; | ||
} | ||
} |
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