-
Notifications
You must be signed in to change notification settings - Fork 2
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
98f9b5a
commit abca37f
Showing
11 changed files
with
329 additions
and
12 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
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,16 @@ | ||
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol"; | ||
|
||
function getHookPermissions() public pure override returns (Hooks.Permissions memory) { | ||
return Hooks.Permissions({ | ||
beforeInitialize: false, | ||
afterInitialize: false, | ||
beforeModifyPosition: false, | ||
afterModifyPosition: false, | ||
beforeSwap: true, | ||
afterSwap: false, | ||
beforeDonate: false, | ||
afterDonate: false, | ||
noOp: false, | ||
accessLock: true // -- ENABLE ACCESS LOCK -- // | ||
}); | ||
} |
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,64 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
// TODO: update to v4-periphery/BaseHook.sol when its compatible | ||
import {BaseHook} from "../forks/BaseHook.sol"; | ||
|
||
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol"; | ||
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol"; | ||
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; | ||
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol"; | ||
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol"; | ||
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/contracts/types/Currency.sol"; | ||
|
||
contract FixedHookFee is BaseHook { | ||
using PoolIdLibrary for PoolKey; | ||
using CurrencyLibrary for Currency; | ||
|
||
uint256 public constant FIXED_HOOK_FEE = 0.0001e18; | ||
|
||
constructor(IPoolManager _poolManager) BaseHook(_poolManager) {} | ||
|
||
function getHookPermissions() public pure override returns (Hooks.Permissions memory) { | ||
return Hooks.Permissions({ | ||
beforeInitialize: false, | ||
afterInitialize: false, | ||
beforeModifyPosition: false, | ||
afterModifyPosition: false, | ||
beforeSwap: true, | ||
afterSwap: false, | ||
beforeDonate: false, | ||
afterDonate: false, | ||
noOp: false, | ||
accessLock: true // -- Required to take a fee -- // | ||
}); | ||
} | ||
|
||
function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) | ||
external | ||
override | ||
returns (bytes4) | ||
{ | ||
// take a fixed fee of 0.0001 of the input token | ||
params.zeroForOne | ||
? poolManager.mint(key.currency0, address(this), FIXED_HOOK_FEE) | ||
: poolManager.mint(key.currency1, address(this), FIXED_HOOK_FEE); | ||
|
||
return BaseHook.beforeSwap.selector; | ||
} | ||
|
||
/// @dev Hook fees are kept as PoolManager claims, so collecting ERC20s will require locking | ||
function collectFee(address recipient, Currency currency) external returns (uint256 amount) { | ||
amount = abi.decode(poolManager.lock(abi.encodeCall(this.handleCollectFee, (recipient, currency))), (uint256)); | ||
} | ||
|
||
/// @dev requires the lock pattern in order to call poolManager.burn | ||
function handleCollectFee(address recipient, Currency currency) external returns (uint256 amount) { | ||
// convert the fee (Claims) into ERC20 tokens | ||
amount = poolManager.balanceOf(address(this), currency); | ||
poolManager.burn(currency, amount); | ||
|
||
// direct claims (the tokens) to the recipient | ||
poolManager.take(currency, recipient, amount); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/pages/fees/fixed-hook-fee/SetAccessLockPermission.solsnippet
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,7 @@ | ||
// Hook can take a fee via ACCESS_LOCK | ||
uint160 flags = uint160(Hooks.BEFORE_SWAP_FLAG | Hooks.ACCESS_LOCK_FLAG); | ||
|
||
(address hookAddress, bytes32 salt) = | ||
HookMiner.find(address(this), flags, type(FixedHookFee).creationCode, abi.encode(address(manager))); | ||
|
||
hook = new FixedHookFee{salt: salt}(IPoolManager(address(manager))); |
Oops, something went wrong.