-
Notifications
You must be signed in to change notification settings - Fork 4
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
4 changed files
with
79 additions
and
1 deletion.
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
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,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {Deployers} from "v4-core/test/utils/Deployers.sol"; | ||
import {DynamicAfterFeeMock} from "test/mocks/DynamicAfterFeeMock.sol"; | ||
import {IHooks} from "v4-core/src/interfaces/IHooks.sol"; | ||
import {Hooks} from "v4-core/src/libraries/Hooks.sol"; | ||
import {PoolSwapTest} from "v4-core/src/test/PoolSwapTest.sol"; | ||
import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol"; | ||
import {Currency} from "v4-core/src/types/Currency.sol"; | ||
import {BalanceDelta} from "v4-core/src/types/BalanceDelta.sol"; | ||
import {PoolKey} from "v4-core/src/types/PoolKey.sol"; | ||
import {LPFeeLibrary} from "v4-core/src/libraries/LPFeeLibrary.sol"; | ||
|
||
contract DynamicAfterFeeTest is Test, Deployers { | ||
DynamicAfterFeeMock hook; | ||
PoolKey noHookKey; | ||
|
||
function setUp() public { | ||
deployFreshManagerAndRouters(); | ||
deployMintAndApprove2Currencies(); | ||
|
||
hook = DynamicAfterFeeMock( | ||
address(uint160(Hooks.BEFORE_SWAP_FLAG | Hooks.AFTER_SWAP_FLAG | Hooks.AFTER_SWAP_RETURNS_DELTA_FLAG)) | ||
); | ||
deployCodeTo("test/mocks/DynamicAfterFeeMock.sol:DynamicAfterFeeMock", abi.encode(manager), address(hook)); | ||
|
||
(key,) = initPoolAndAddLiquidity( | ||
currency0, currency1, IHooks(address(hook)), LPFeeLibrary.DYNAMIC_FEE_FLAG, SQRT_PRICE_1_1 | ||
); | ||
(noHookKey,) = initPoolAndAddLiquidity(currency0, currency1, IHooks(address(0)), 100, SQRT_PRICE_1_1); | ||
|
||
vm.label(Currency.unwrap(currency0), "currency0"); | ||
vm.label(Currency.unwrap(currency1), "currency1"); | ||
} | ||
} |
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,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "src/base/DynamicAfterFee.sol"; | ||
import {BeforeSwapDeltaLibrary} from "v4-core/src/types/BeforeSwapDelta.sol"; | ||
import {BalanceDelta} from "v4-core/src/types/BalanceDelta.sol"; | ||
|
||
contract DynamicAfterFeeMock is DynamicAfterFee { | ||
constructor(IPoolManager _poolManager) DynamicAfterFee(_poolManager) {} | ||
|
||
function _beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) | ||
internal | ||
override | ||
returns (bytes4, BeforeSwapDelta, uint24) | ||
{ | ||
PoolId poolId = key.toId(); | ||
_targetDeltas[poolId] = BalanceDelta.wrap(0); | ||
|
||
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0); | ||
} | ||
|
||
function getHookPermissions() public pure virtual override returns (Hooks.Permissions memory) { | ||
return Hooks.Permissions({ | ||
beforeInitialize: false, | ||
afterInitialize: false, | ||
beforeAddLiquidity: false, | ||
afterAddLiquidity: false, | ||
beforeRemoveLiquidity: false, | ||
afterRemoveLiquidity: false, | ||
beforeSwap: true, | ||
afterSwap: true, | ||
beforeDonate: false, | ||
afterDonate: false, | ||
beforeSwapReturnDelta: false, | ||
afterSwapReturnDelta: true, | ||
afterAddLiquidityReturnDelta: false, | ||
afterRemoveLiquidityReturnDelta: false | ||
}); | ||
} | ||
} |