forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwapFeeLibrary.sol
32 lines (24 loc) · 1023 Bytes
/
SwapFeeLibrary.sol
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
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;
import {PoolKey} from "../types/PoolKey.sol";
library SwapFeeLibrary {
using SwapFeeLibrary for uint24;
/// @notice Thrown when the static or dynamic fee on a pool exceeds 100%.
error FeeTooLarge();
uint24 public constant STATIC_FEE_MASK = 0x7FFFFF;
uint24 public constant DYNAMIC_FEE_FLAG = 0x800000;
// the swap fee is represented in hundredths of a bip, so the max is 100%
uint24 public constant MAX_SWAP_FEE = 1000000;
function isDynamicFee(uint24 self) internal pure returns (bool) {
return self & DYNAMIC_FEE_FLAG != 0;
}
function validate(uint24 self) internal pure {
if (self > MAX_SWAP_FEE) revert FeeTooLarge();
}
function getInitialSwapFee(uint24 self) internal pure returns (uint24 swapFee) {
// the initial fee for a dynamic fee pool is 0
if (self.isDynamicFee()) return 0;
swapFee = self & STATIC_FEE_MASK;
swapFee.validate();
}
}