From d5d4957b35750e8cf1f3db5584e77eef4861c21e Mon Sep 17 00:00:00 2001 From: Daniel Gretzke Date: Tue, 28 May 2024 19:08:31 +0200 Subject: [PATCH] annotate memory safe assembly for further gas optimizations (#723) --- .forge-snapshots/donate gas with 1 token.snap | 2 +- .../donate gas with 2 tokens.snap | 2 +- .forge-snapshots/getReserves.snap | 2 +- .../swap CA custom curve + swap noop.snap | 2 +- .../swap CA fee on unspecified.snap | 2 +- ...p against liquidity with native token.snap | 2 +- .forge-snapshots/swap against liquidity.snap | 2 +- .../swap burn 6909 for input.snap | 2 +- .../swap burn native 6909 for input.snap | 2 +- .../swap mint native output as 6909.snap | 2 +- .../swap mint output as 6909.snap | 2 +- ...wap skips hook call if hook is caller.snap | 2 +- .forge-snapshots/swap with dynamic fee.snap | 2 +- .forge-snapshots/swap with hooks.snap | 2 +- .../swap with lp fee and protocol fee.snap | 2 +- .../swap with return dynamic fee.snap | 2 +- .../update dynamic fee in before swap.snap | 2 +- src/Extsload.sol | 9 +++---- src/Exttload.sol | 6 ++--- src/libraries/CustomRevert.sol | 18 +++++--------- src/libraries/Hooks.sol | 3 +-- src/libraries/Position.sol | 3 +-- src/libraries/SafeCast.sol | 3 +-- src/libraries/SqrtPriceMath.sol | 15 ++++-------- src/libraries/StateLibrary.sol | 3 +-- src/libraries/TickBitmap.sol | 3 +-- src/libraries/TickMath.sol | 6 ++--- src/libraries/TransientStateLibrary.sol | 4 ++-- src/types/BeforeSwapDelta.sol | 6 ++--- src/types/Currency.sol | 6 ++--- src/types/PoolId.sol | 3 +-- src/types/Slot0.sol | 24 +++++++------------ 32 files changed, 55 insertions(+), 91 deletions(-) diff --git a/.forge-snapshots/donate gas with 1 token.snap b/.forge-snapshots/donate gas with 1 token.snap index 65ab0d319..3ac69e91a 100644 --- a/.forge-snapshots/donate gas with 1 token.snap +++ b/.forge-snapshots/donate gas with 1 token.snap @@ -1 +1 @@ -106027 \ No newline at end of file +104674 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 2 tokens.snap b/.forge-snapshots/donate gas with 2 tokens.snap index 1e0fe8e89..0eb094c9c 100644 --- a/.forge-snapshots/donate gas with 2 tokens.snap +++ b/.forge-snapshots/donate gas with 2 tokens.snap @@ -1 +1 @@ -146035 \ No newline at end of file +144554 \ No newline at end of file diff --git a/.forge-snapshots/getReserves.snap b/.forge-snapshots/getReserves.snap index 4e010ec2c..daa7729f3 100644 --- a/.forge-snapshots/getReserves.snap +++ b/.forge-snapshots/getReserves.snap @@ -1 +1 @@ -1630 \ No newline at end of file +1552 \ No newline at end of file diff --git a/.forge-snapshots/swap CA custom curve + swap noop.snap b/.forge-snapshots/swap CA custom curve + swap noop.snap index ad5a6f017..a79fb9dc2 100644 --- a/.forge-snapshots/swap CA custom curve + swap noop.snap +++ b/.forge-snapshots/swap CA custom curve + swap noop.snap @@ -1 +1 @@ -128990 \ No newline at end of file +127257 \ No newline at end of file diff --git a/.forge-snapshots/swap CA fee on unspecified.snap b/.forge-snapshots/swap CA fee on unspecified.snap index 62fa8c493..72036d09f 100644 --- a/.forge-snapshots/swap CA fee on unspecified.snap +++ b/.forge-snapshots/swap CA fee on unspecified.snap @@ -1 +1 @@ -174512 \ No newline at end of file +172779 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity with native token.snap b/.forge-snapshots/swap against liquidity with native token.snap index 92ea94409..a090cfd2b 100644 --- a/.forge-snapshots/swap against liquidity with native token.snap +++ b/.forge-snapshots/swap against liquidity with native token.snap @@ -1 +1 @@ -108127 \ No newline at end of file +106660 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity.snap b/.forge-snapshots/swap against liquidity.snap index 46710db50..8795aa2dd 100644 --- a/.forge-snapshots/swap against liquidity.snap +++ b/.forge-snapshots/swap against liquidity.snap @@ -1 +1 @@ -119479 \ No newline at end of file +117746 \ No newline at end of file diff --git a/.forge-snapshots/swap burn 6909 for input.snap b/.forge-snapshots/swap burn 6909 for input.snap index d285794c3..7b637dae0 100644 --- a/.forge-snapshots/swap burn 6909 for input.snap +++ b/.forge-snapshots/swap burn 6909 for input.snap @@ -1 +1 @@ -131285 \ No newline at end of file +129595 \ No newline at end of file diff --git a/.forge-snapshots/swap burn native 6909 for input.snap b/.forge-snapshots/swap burn native 6909 for input.snap index 51f4664e9..9682aa9ce 100644 --- a/.forge-snapshots/swap burn native 6909 for input.snap +++ b/.forge-snapshots/swap burn native 6909 for input.snap @@ -1 +1 @@ -120369 \ No newline at end of file +118816 \ No newline at end of file diff --git a/.forge-snapshots/swap mint native output as 6909.snap b/.forge-snapshots/swap mint native output as 6909.snap index 864e42be4..c1657a67d 100644 --- a/.forge-snapshots/swap mint native output as 6909.snap +++ b/.forge-snapshots/swap mint native output as 6909.snap @@ -1 +1 @@ -142229 \ No newline at end of file +140629 \ No newline at end of file diff --git a/.forge-snapshots/swap mint output as 6909.snap b/.forge-snapshots/swap mint output as 6909.snap index c471997eb..84a80bb08 100644 --- a/.forge-snapshots/swap mint output as 6909.snap +++ b/.forge-snapshots/swap mint output as 6909.snap @@ -1 +1 @@ -158199 \ No newline at end of file +156433 \ No newline at end of file diff --git a/.forge-snapshots/swap skips hook call if hook is caller.snap b/.forge-snapshots/swap skips hook call if hook is caller.snap index 48ffdca94..3394318c1 100644 --- a/.forge-snapshots/swap skips hook call if hook is caller.snap +++ b/.forge-snapshots/swap skips hook call if hook is caller.snap @@ -1 +1 @@ -211054 \ No newline at end of file +208496 \ No newline at end of file diff --git a/.forge-snapshots/swap with dynamic fee.snap b/.forge-snapshots/swap with dynamic fee.snap index 5e7a69da6..aa1cc9e71 100644 --- a/.forge-snapshots/swap with dynamic fee.snap +++ b/.forge-snapshots/swap with dynamic fee.snap @@ -1 +1 @@ -142260 \ No newline at end of file +140527 \ No newline at end of file diff --git a/.forge-snapshots/swap with hooks.snap b/.forge-snapshots/swap with hooks.snap index 26d1b296d..ae921c39e 100644 --- a/.forge-snapshots/swap with hooks.snap +++ b/.forge-snapshots/swap with hooks.snap @@ -1 +1 @@ -134930 \ No newline at end of file +133197 \ No newline at end of file diff --git a/.forge-snapshots/swap with lp fee and protocol fee.snap b/.forge-snapshots/swap with lp fee and protocol fee.snap index f8a54567b..f55fd26bc 100644 --- a/.forge-snapshots/swap with lp fee and protocol fee.snap +++ b/.forge-snapshots/swap with lp fee and protocol fee.snap @@ -1 +1 @@ -172061 \ No newline at end of file +170330 \ No newline at end of file diff --git a/.forge-snapshots/swap with return dynamic fee.snap b/.forge-snapshots/swap with return dynamic fee.snap index 8dae67f26..8ede4c390 100644 --- a/.forge-snapshots/swap with return dynamic fee.snap +++ b/.forge-snapshots/swap with return dynamic fee.snap @@ -1 +1 @@ -148491 \ No newline at end of file +146758 \ No newline at end of file diff --git a/.forge-snapshots/update dynamic fee in before swap.snap b/.forge-snapshots/update dynamic fee in before swap.snap index b2df693e3..ff2a78a6d 100644 --- a/.forge-snapshots/update dynamic fee in before swap.snap +++ b/.forge-snapshots/update dynamic fee in before swap.snap @@ -1 +1 @@ -150749 \ No newline at end of file +149016 \ No newline at end of file diff --git a/src/Extsload.sol b/src/Extsload.sol index d2724b871..6f1c4a0b3 100644 --- a/src/Extsload.sol +++ b/src/Extsload.sol @@ -8,8 +8,7 @@ import {IExtsload} from "./interfaces/IExtsload.sol"; abstract contract Extsload is IExtsload { /// @inheritdoc IExtsload function extsload(bytes32 slot) external view returns (bytes32) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, sload(slot)) return(0, 0x20) } @@ -17,8 +16,7 @@ abstract contract Extsload is IExtsload { /// @inheritdoc IExtsload function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes memory) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // The abi offset of dynamic array in the returndata is 32. mstore(0, 0x20) // A left bit-shift of 5 is equivalent to multiplying by 32 but costs less gas. @@ -40,8 +38,7 @@ abstract contract Extsload is IExtsload { // since the function is external and enters a new call context and exits right // after execution, Solidity's memory management convention can be disregarded // and a direct slice of memory can be returned - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // Copy the abi offset of dynamic array and the length of the array to memory. calldatacopy(0, 0x04, 0x40) // A left bit-shift of 5 is equivalent to multiplying by 32 but costs less gas. diff --git a/src/Exttload.sol b/src/Exttload.sol index 251db04a2..e666791f4 100644 --- a/src/Exttload.sol +++ b/src/Exttload.sol @@ -8,8 +8,7 @@ import {IExttload} from "./interfaces/IExttload.sol"; abstract contract Exttload is IExttload { /// @inheritdoc IExttload function exttload(bytes32 slot) external view returns (bytes32) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, tload(slot)) return(0, 0x20) } @@ -20,8 +19,7 @@ abstract contract Exttload is IExttload { // since the function is external and enters a new call context and exits right // after execution, Solidity's memory management convention can be disregarded // and a direct slice of memory can be returned - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // Copy the abi offset of dynamic array and the length of the array to memory. calldatacopy(0, 0x04, 0x40) // A left bit-shift of 5 is equivalent to multiplying by 32 but costs less gas. diff --git a/src/libraries/CustomRevert.sol b/src/libraries/CustomRevert.sol index 7f72c64d1..f17a61a88 100644 --- a/src/libraries/CustomRevert.sol +++ b/src/libraries/CustomRevert.sol @@ -9,8 +9,7 @@ pragma solidity >=0.8.4; library CustomRevert { /// @dev Reverts with the selector of a custom error in the scratch space function revertWith(bytes4 selector) internal pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, selector) revert(0, 0x04) } @@ -18,8 +17,7 @@ library CustomRevert { /// @dev Reverts with a custom error with an address argument in the scratch space function revertWith(bytes4 selector, address addr) internal pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, selector) mstore(0x04, addr) revert(0, 0x24) @@ -28,8 +26,7 @@ library CustomRevert { /// @dev Reverts with a custom error with an int24 argument in the scratch space function revertWith(bytes4 selector, int24 value) internal pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, selector) mstore(0x04, value) revert(0, 0x24) @@ -38,8 +35,7 @@ library CustomRevert { /// @dev Reverts with a custom error with a uint160 argument in the scratch space function revertWith(bytes4 selector, uint160 value) internal pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, selector) mstore(0x04, value) revert(0, 0x24) @@ -48,8 +44,7 @@ library CustomRevert { /// @dev Reverts with a custom error with two int24 arguments function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, selector) mstore(0x04, value1) mstore(0x24, value2) @@ -59,8 +54,7 @@ library CustomRevert { /// @dev Reverts with a custom error with two uint160 arguments function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0, selector) mstore(0x04, value1) mstore(0x24, value2) diff --git a/src/libraries/Hooks.sol b/src/libraries/Hooks.sol index 5ade806e5..dac5317e4 100644 --- a/src/libraries/Hooks.sol +++ b/src/libraries/Hooks.sol @@ -127,8 +127,7 @@ library Hooks { /// @notice performs a hook call using the given calldata on the given hook that doesnt return a delta /// @return result The complete data returned by the hook function callHook(IHooks self, bytes memory data) internal returns (bytes memory result) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if iszero(call(gas(), self, 0, add(data, 0x20), mload(data), 0, 0)) { if iszero(returndatasize()) { // if the call failed without a revert reason, revert with `FailedHookCall()` diff --git a/src/libraries/Position.sol b/src/libraries/Position.sol index 0fe5dfa92..d9de27290 100644 --- a/src/libraries/Position.sol +++ b/src/libraries/Position.sol @@ -39,8 +39,7 @@ library Position { // positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt)) bytes32 positionKey; - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0x26, salt) // [0x26, 0x46) mstore(0x06, tickUpper) // [0x23, 0x26) mstore(0x03, tickLower) // [0x20, 0x23) diff --git a/src/libraries/SafeCast.sol b/src/libraries/SafeCast.sol index 8f22bed45..a94d613e1 100644 --- a/src/libraries/SafeCast.sol +++ b/src/libraries/SafeCast.sol @@ -7,8 +7,7 @@ library SafeCast { error SafeCastOverflow(); function _revertOverflow() private pure { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // Store the function selector of `SafeCastOverflow()`. mstore(0x00, 0x93dafdf1) // Revert with (offset, size). diff --git a/src/libraries/SqrtPriceMath.sol b/src/libraries/SqrtPriceMath.sol index 49ae93fa5..8613c9c96 100644 --- a/src/libraries/SqrtPriceMath.sol +++ b/src/libraries/SqrtPriceMath.sol @@ -56,8 +56,7 @@ library SqrtPriceMath { // if the product overflows, we know the denominator underflows // in addition, we must check that the denominator does not underflow // equivalent: if (product / amount != sqrtPX96 || numerator1 <= product) revert PriceOverflow(); - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if iszero(and(eq(div(product, amount), sqrtPX96), gt(numerator1, product))) { mstore(0, 0xf5c787f1) // selector for PriceOverflow() revert(0x1c, 0x04) @@ -102,8 +101,7 @@ library SqrtPriceMath { ); // equivalent: if (sqrtPX96 <= quotient) revert NotEnoughLiquidity(); - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if iszero(gt(sqrtPX96, quotient)) { mstore(0, 0x4323a555) // selector for NotEnoughLiquidity() revert(0x1c, 0x04) @@ -129,8 +127,7 @@ library SqrtPriceMath { returns (uint160 sqrtQX96) { // equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity(); - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if or(iszero(sqrtPX96), iszero(liquidity)) { mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity() revert(0x1c, 0x04) @@ -156,8 +153,7 @@ library SqrtPriceMath { returns (uint160 sqrtQX96) { // equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity(); - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if or(iszero(sqrtPX96), iszero(liquidity)) { mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity() revert(0x1c, 0x04) @@ -187,8 +183,7 @@ library SqrtPriceMath { if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96); // equivalent: if (sqrtPriceAX96 == 0) revert InvalidPrice(); - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if iszero(sqrtPriceAX96) { mstore(0, 0x00bfc921) // selector for InvalidPrice() revert(0x1c, 0x04) diff --git a/src/libraries/StateLibrary.sol b/src/libraries/StateLibrary.sol index 45c596f75..8e91f3f29 100644 --- a/src/libraries/StateLibrary.sol +++ b/src/libraries/StateLibrary.sol @@ -253,8 +253,7 @@ library StateLibrary { // positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt)) bytes32 positionKey; - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0x26, salt) // [0x26, 0x46) mstore(0x06, tickUpper) // [0x23, 0x26) mstore(0x03, tickLower) // [0x20, 0x23) diff --git a/src/libraries/TickBitmap.sol b/src/libraries/TickBitmap.sol index d98cdfff3..67c68525e 100644 --- a/src/libraries/TickBitmap.sol +++ b/src/libraries/TickBitmap.sol @@ -50,8 +50,7 @@ library TickBitmap { * uint256 mask = 1 << bitPos; * self[wordPos] ^= mask; */ - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // ensure that the tick is spaced if smod(tick, tickSpacing) { mstore(0, 0xd4d8f3e6) // selector for TickMisaligned(int24,int24) diff --git a/src/libraries/TickMath.sol b/src/libraries/TickMath.sol index 5a43775ed..06efacbea 100644 --- a/src/libraries/TickMath.sol +++ b/src/libraries/TickMath.sol @@ -59,8 +59,7 @@ library TickMath { absTick := xor(mask, add(mask, tick)) } // Equivalent: if (absTick > MAX_TICK) revert InvalidTick(); - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { if gt(absTick, MAX_TICK) { // store 4-byte selector of "InvalidTick()" at memory [0x1c, 0x20) mstore(0, 0xce8ef7fc) @@ -118,8 +117,7 @@ library TickMath { unchecked { // Equivalent: if (sqrtPriceX96 < MIN_SQRT_PRICE || sqrtPriceX96 >= MAX_SQRT_PRICE) revert InvalidSqrtPrice(); // second inequality must be < because the price can never reach the price at the max tick - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // if sqrtPriceX96 < MIN_SQRT_PRICE, the `sub` underflows and `gt` is true // if sqrtPriceX96 >= MAX_SQRT_PRICE, sqrtPriceX96 - MIN_SQRT_PRICE > MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1 if gt(sub(sqrtPriceX96, MIN_SQRT_PRICE), MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE) { diff --git a/src/libraries/TransientStateLibrary.sol b/src/libraries/TransientStateLibrary.sol index 81bfb6212..d635be258 100644 --- a/src/libraries/TransientStateLibrary.sol +++ b/src/libraries/TransientStateLibrary.sol @@ -25,7 +25,7 @@ library TransientStateLibrary { /// @dev returns type(uint256).max if the reserves are synced but the value is 0 function getReserves(IPoolManager manager, Currency currency) internal view returns (uint256) { bytes32 key; - assembly { + assembly ("memory-safe") { mstore(0, RESERVES_OF_SLOT) mstore(32, currency) key := keccak256(0, 64) @@ -43,7 +43,7 @@ library TransientStateLibrary { /// @param currency The currency for which to lookup the delta function currencyDelta(IPoolManager manager, address caller_, Currency currency) internal view returns (int256) { bytes32 key; - assembly { + assembly ("memory-safe") { mstore(0, caller_) mstore(32, currency) key := keccak256(0, 64) diff --git a/src/types/BeforeSwapDelta.sol b/src/types/BeforeSwapDelta.sol index d7b7bdd6c..e0c5f96ab 100644 --- a/src/types/BeforeSwapDelta.sol +++ b/src/types/BeforeSwapDelta.sol @@ -12,8 +12,7 @@ function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified) pure returns (BeforeSwapDelta beforeSwapDelta) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified)) } } @@ -32,8 +31,7 @@ library BeforeSwapDeltaLibrary { /// extracts int128 from the lower 128 bits of the BeforeSwapDelta /// returned by beforeSwap and afterSwap function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { deltaUnspecified := signextend(15, delta) } } diff --git a/src/types/Currency.sol b/src/types/Currency.sol index 5d3d52e0a..96e804005 100644 --- a/src/types/Currency.sol +++ b/src/types/Currency.sol @@ -40,8 +40,7 @@ library CurrencyLibrary { // modified custom error selectors if (currency.isNative()) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { // Transfer the ETH and revert if it fails. if iszero(call(gas(), to, amount, 0x00, 0x00, 0x00, 0x00)) { mstore(0x00, 0xf4b3b1bc) // `NativeTransferFailed()`. @@ -49,8 +48,7 @@ library CurrencyLibrary { } } } else { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { mstore(0x14, to) // Store the `to` address in [0x20, 0x34). mstore(0x34, amount) // Store the `amount` argument in [0x34, 0x54). // Store the selector of `transfer(address,uint256)` in [0x10, 0x14). diff --git a/src/types/PoolId.sol b/src/types/PoolId.sol index 88387a8d9..6a7eb00ea 100644 --- a/src/types/PoolId.sol +++ b/src/types/PoolId.sol @@ -9,8 +9,7 @@ type PoolId is bytes32; library PoolIdLibrary { /// @notice Returns value equal to keccak256(abi.encode(poolKey)) function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { poolId := keccak256(poolKey, mul(32, 5)) } } diff --git a/src/types/Slot0.sol b/src/types/Slot0.sol index 9a7eee665..df319562b 100644 --- a/src/types/Slot0.sol +++ b/src/types/Slot0.sol @@ -38,51 +38,44 @@ library Slot0Library { // #### GETTERS #### function sqrtPriceX96(Slot0 _packed) internal pure returns (uint160 _sqrtPriceX96) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _sqrtPriceX96 := and(MASK_160_BITS, _packed) } } function tick(Slot0 _packed) internal pure returns (int24 _tick) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _tick := signextend(2, shr(TICK_OFFSET, _packed)) } } function protocolFee(Slot0 _packed) internal pure returns (uint24 _protocolFee) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _protocolFee := and(MASK_24_BITS, shr(PROTOCOL_FEE_OFFSET, _packed)) } } function lpFee(Slot0 _packed) internal pure returns (uint24 _lpFee) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _lpFee := and(MASK_24_BITS, shr(LP_FEE_OFFSET, _packed)) } } // #### SETTERS #### function setSqrtPriceX96(Slot0 _packed, uint160 _sqrtPriceX96) internal pure returns (Slot0 _result) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _result := or(and(not(MASK_160_BITS), _packed), and(MASK_160_BITS, _sqrtPriceX96)) } } function setTick(Slot0 _packed, int24 _tick) internal pure returns (Slot0 _result) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _result := or(and(not(shl(TICK_OFFSET, MASK_24_BITS)), _packed), shl(TICK_OFFSET, and(MASK_24_BITS, _tick))) } } function setProtocolFee(Slot0 _packed, uint24 _protocolFee) internal pure returns (Slot0 _result) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _result := or( and(not(shl(PROTOCOL_FEE_OFFSET, MASK_24_BITS)), _packed), @@ -92,8 +85,7 @@ library Slot0Library { } function setLpFee(Slot0 _packed, uint24 _lpFee) internal pure returns (Slot0 _result) { - /// @solidity memory-safe-assembly - assembly { + assembly ("memory-safe") { _result := or(and(not(shl(LP_FEE_OFFSET, MASK_24_BITS)), _packed), shl(LP_FEE_OFFSET, and(MASK_24_BITS, _lpFee))) }