Skip to content

Commit

Permalink
calculate config id in assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 committed Jul 31, 2024
1 parent e5e2db9 commit 5353f1f
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47690
46784
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_empty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
47508
46601
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_nonEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130555
129648
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_burn_nonEmpty_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123476
122570
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150859
149728
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142011
140880
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150859
149728
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decreaseLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116402
115271
Original file line number Diff line number Diff line change
@@ -1 +1 @@
109084
108179
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135328
133516
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128067
126256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129118
127987
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152337
151206
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134220
133089
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135050
133919
Original file line number Diff line number Diff line change
@@ -1 +1 @@
171206
170075
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372374
371250
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337157
336033
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_nativeWithSweep.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
344095
342971
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315056
313932
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315698
314574
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
241280
240156
Original file line number Diff line number Diff line change
@@ -1 +1 @@
321074
319950
Original file line number Diff line number Diff line change
@@ -1 +1 @@
416750
415626
29 changes: 16 additions & 13 deletions src/libraries/PositionConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ struct PositionConfig {
/// @notice Library for computing the configId given a PositionConfig
library PositionConfigLibrary {
function toId(PositionConfig calldata config) internal pure returns (bytes32 id) {
PoolKey calldata poolKey;
// id = keccak256(abi.encodePacked(currency0, currency1, fee, tickSpacing, hooks, tickLower, tickUpper)))
assembly ("memory-safe") {
poolKey := config
let fmp := mload(0x40)
mstore(add(fmp, 0x34), calldataload(add(config, 0xc0))) // tickUpper: [0x51, 0x54)
mstore(add(fmp, 0x31), calldataload(add(config, 0xa0))) // tickLower: [0x4E, 0x51)
mstore(add(fmp, 0x2E), calldataload(add(config, 0x80))) // hooks: [0x3A, 0x4E)
mstore(add(fmp, 0x1A), calldataload(add(config, 0x60))) // tickSpacing: [0x37, 0x3A)
mstore(add(fmp, 0x17), calldataload(add(config, 0x40))) // fee: [0x34, 0x37)
mstore(add(fmp, 0x14), calldataload(add(config, 0x20))) // currency1: [0x20, 0x34)
mstore(fmp, calldataload(config)) // currency0: [0x0c, 0x20)

id := keccak256(add(fmp, 0x0c), 0x48) // len is 72 bytes

// now clean the memory we used
mstore(add(fmp, 0x40), 0) // fmp+0x40 held hooks (14 bytes), tickLower, tickUpper
mstore(add(fmp, 0x20), 0) // fmp+0x20 held currency1, fee, tickSpacing, hooks (6 bytes)
mstore(fmp, 0) // fmp held currency0
}
return keccak256(
abi.encodePacked(
poolKey.currency0,
poolKey.currency1,
poolKey.fee,
poolKey.tickSpacing,
poolKey.hooks,
config.tickLower,
config.tickUpper
)
);
}
}

0 comments on commit 5353f1f

Please sign in to comment.