forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProtocolFeeLibrary.sol
More file actions
30 lines (25 loc) 路 959 Bytes
/
Copy pathProtocolFeeLibrary.sol
File metadata and controls
30 lines (25 loc) 路 959 Bytes
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
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;
library ProtocolFeeLibrary {
// Max protocol fee is 25% (2500 bips)
uint16 public constant MAX_PROTOCOL_FEE = 2500;
// Total bips
uint16 internal constant BIPS_DENOMINATOR = 10_000;
function getZeroForOneFee(uint24 self) internal pure returns (uint16) {
return uint16(self & (4096 - 1));
}
function getOneForZeroFee(uint24 self) internal pure returns (uint16) {
return uint16(self >> 12);
}
function validate(uint24 self) internal pure returns (bool) {
if (self != 0) {
uint16 fee0 = getZeroForOneFee(self);
uint16 fee1 = getOneForZeroFee(self);
// The fee is represented in bips so it cannot be GREATER than the MAX_PROTOCOL_FEE.
if ((fee0 > MAX_PROTOCOL_FEE) || (fee1 > MAX_PROTOCOL_FEE)) {
return false;
}
}
return true;
}
}