Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeSwap returns dynamic fee #648

Merged
merged 26 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
36e7653
allow beforeSwap to return and set the lpFee
saucepoint May 13, 2024
07a9d30
fix tests; default to a sentinel for Hooks.beforeSwap
saucepoint May 13, 2024
28311ce
merge in main; regenerate snapshots
saucepoint May 14, 2024
7406eb9
define constant
saucepoint May 14, 2024
761ccb9
very smol optimization
saucepoint May 14, 2024
f424c1b
Optimise before swap return fee (#650)
hensha256 May 14, 2024
ad6dcf6
Try shared parse lib (#652)
snreynolds May 14, 2024
cd95832
Update src/interfaces/IHooks.sol
saucepoint May 14, 2024
52ef386
misc
saucepoint May 14, 2024
132a877
merge in main; regenerate snapshots
saucepoint May 14, 2024
616bc84
merge in main; regenerate snapshots; fix test
saucepoint May 15, 2024
f508681
review comments; abstract fee checks; add new test
saucepoint May 15, 2024
b5929ae
make ProtocolFeeLibrary similar to LPFeeLibrary
saucepoint May 15, 2024
3a9747c
fix test
saucepoint May 15, 2024
160e4c6
rename how protocol fee is validated
saucepoint May 16, 2024
196af36
fee masking
saucepoint May 16, 2024
525108e
trial new override mechanism
hensha256 May 16, 2024
fdfa579
remove assembly block
hensha256 May 16, 2024
afcda81
cleanup; some natspec
saucepoint May 16, 2024
2ffaa92
revert if override fee exceeds the maximum
saucepoint May 16, 2024
60e1060
review comments; consolidate fee flag
saucepoint May 16, 2024
9499de9
use 2nd bit of uint24 to signal override
saucepoint May 16, 2024
bac221f
naming
saucepoint May 16, 2024
ef84cb0
Update src/libraries/LPFeeLibrary.sol
saucepoint May 17, 2024
35a1402
Update src/libraries/LPFeeLibrary.sol
saucepoint May 17, 2024
abb6988
additional code comment
saucepoint May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/interfaces/IHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ interface IHooks {
/// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
/// @return uint24 An optional swap fee, only used if the Pool has a dynamic fee and the value is less than or equal to LPFeeLibrary.MAX_LP_FEE
/// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1) the Pool has a dynamic fee, 2) the value's leading bit is set to 1 (24th bit, 0x800000), 3) the value is less than or equal to the maximum fee (1 million)
saucepoint marked this conversation as resolved.
Show resolved Hide resolved
function beforeSwap(
address sender,
PoolKey calldata key,
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/LPFeeLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ library LPFeeLibrary {
lpFee.validate();
}

/// @dev converts a fee (returned from beforeSwap) to an override fee by setting the top bit of the uint24
/// @notice converts a fee to an override fee (to be returned by beforeSwap) by setting the top bit of the uint24
function asOverrideFee(uint24 self) internal pure returns (uint24) {
saucepoint marked this conversation as resolved.
Show resolved Hide resolved
return self | BEFORE_SWAP_FEE_OVERRIDE_FLAG;
}

/// @notice returns true if the fee has the override flag set (top bit of the uint24)
function isOverride(uint24 self) internal pure returns (bool) {
return self & BEFORE_SWAP_FEE_OVERRIDE_FLAG != 0;
}

/// @notice returns a fee with the override flag removed
function removeOverrideFlag(uint24 self) internal pure returns (uint24) {
return self & FEE_MASK;
}
Expand Down
1 change: 0 additions & 1 deletion src/libraries/ParseBytes.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {LPFeeLibrary} from "./LPFeeLibrary.sol";
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity ^0.8.20;
Expand Down
Loading