forked from alphixfi/alphix-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseDynamicFee.sol
More file actions
84 lines (76 loc) · 2.95 KB
/
Copy pathBaseDynamicFee.sol
File metadata and controls
84 lines (76 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: BUSL-1.1
// inspiration from: OpenZeppelin Uniswap Hooks (last updated v1.2.0) (src/fee/BaseDynamicFee.sol)
// Alphix version of the BaseDynamicFee
pragma solidity ^0.8.26;
import {BaseHook} from "@openzeppelin/uniswap-hooks/src/base/BaseHook.sol";
import {Hooks} from "v4-core/src/libraries/Hooks.sol";
import {PoolKey} from "v4-core/src/types/PoolKey.sol";
import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";
import {LPFeeLibrary} from "v4-core/src/libraries/LPFeeLibrary.sol";
/**
* @dev This contract takes inspiration from OpenZeppelin's Uniswap BaseDynamicFee Hook and slightly
* modifies it according to Alphix's Dynamic Fee Algorithm needs.
*
* WARNING: This is experimental software and is provided on an "as is" and "as available" basis. We do
* not give any warranties and will not be liable for any losses incurred through any use of this code
* base.
*
* _Available since v0.1.0_
*/
abstract contract BaseDynamicFee is BaseHook {
using LPFeeLibrary for uint24;
/**
* @dev The hook was attempted to be initialized with a non-dynamic fee.
*/
error NotDynamicFee();
/**
* @dev Set the `PoolManager` address.
*/
constructor(IPoolManager _poolManager) BaseHook(_poolManager) {}
/**
* @dev Set the fee after the pool is initialized.
*/
function _afterInitialize(address, PoolKey calldata key, uint160, int24)
internal
virtual
override
returns (bytes4)
{
if (!key.fee.isDynamicFee()) revert NotDynamicFee();
return this.afterInitialize.selector;
}
/**
* @dev Updates the dynamic LP fee for the pool this hook serves.
*
* WARNING: This base implementation is abstract. Inheriting contracts MUST override
* this function with proper access control (e.g., onlyOwner, role-based) and fee
* computation logic. Failure to do so allows any external caller to arbitrarily
* change pool fees.
*
* @param currentRatio The current ratio of the pool, used to update the dynamic LP fee.
*/
function poke(uint256 currentRatio) external virtual;
/**
* @dev Set the hook permissions, specifically `afterInitialize`.
*
* @return permissions The hook permissions.
*/
function getHookPermissions() public pure virtual override returns (Hooks.Permissions memory permissions) {
return Hooks.Permissions({
beforeInitialize: false,
afterInitialize: true,
beforeAddLiquidity: false,
afterAddLiquidity: false,
beforeRemoveLiquidity: false,
afterRemoveLiquidity: false,
beforeSwap: false,
afterSwap: false,
beforeDonate: false,
afterDonate: false,
beforeSwapReturnDelta: false,
afterSwapReturnDelta: false,
afterAddLiquidityReturnDelta: false,
afterRemoveLiquidityReturnDelta: false
});
}
}