diff --git a/src/libraries/Lock.sol b/src/libraries/Lock.sol index df0f07099..1d89e9ac2 100644 --- a/src/libraries/Lock.sol +++ b/src/libraries/Lock.sol @@ -7,27 +7,24 @@ import {IHooks} from "../interfaces/IHooks.sol"; /// TODO: This library can be deleted when we have the transient keyword support in solidity. library Lock { // The slot holding the unlocked state, transiently. uint256(keccak256("Unlocked")) - 1; - uint256 constant IS_UNLOCKED_SLOT = uint256(0xc090fc4683624cfc3884e9d8de5eca132f2d0ec062aff75d43c0465d5ceeab23); + uint256 constant IS_UNLOCKED_SLOT = 0xc090fc4683624cfc3884e9d8de5eca132f2d0ec062aff75d43c0465d5ceeab23; function unlock() internal { - uint256 slot = IS_UNLOCKED_SLOT; assembly { // unlock - tstore(slot, true) + tstore(IS_UNLOCKED_SLOT, true) } } function lock() internal { - uint256 slot = IS_UNLOCKED_SLOT; assembly { - tstore(slot, false) + tstore(IS_UNLOCKED_SLOT, false) } } function isUnlocked() internal view returns (bool unlocked) { - uint256 slot = IS_UNLOCKED_SLOT; assembly { - unlocked := tload(slot) + unlocked := tload(IS_UNLOCKED_SLOT) } } } diff --git a/src/libraries/NonZeroDeltaCount.sol b/src/libraries/NonZeroDeltaCount.sol index e52df5300..853d32e19 100644 --- a/src/libraries/NonZeroDeltaCount.sol +++ b/src/libraries/NonZeroDeltaCount.sol @@ -8,33 +8,29 @@ import {IHooks} from "../interfaces/IHooks.sol"; /// TODO: This library can be deleted when we have the transient keyword support in solidity. library NonZeroDeltaCount { // The slot holding the number of nonzero deltas. uint256(keccak256("NonzeroDeltaCount")) - 1 - uint256 constant NONZERO_DELTA_COUNT_SLOT = - uint256(0x7d4b3164c6e45b97e7d87b7125a44c5828d005af88f9d751cfd78729c5d99a0b); + uint256 constant NONZERO_DELTA_COUNT_SLOT = 0x7d4b3164c6e45b97e7d87b7125a44c5828d005af88f9d751cfd78729c5d99a0b; function read() internal view returns (uint256 count) { - uint256 slot = NONZERO_DELTA_COUNT_SLOT; assembly { - count := tload(slot) + count := tload(NONZERO_DELTA_COUNT_SLOT) } } function increment() internal { - uint256 slot = NONZERO_DELTA_COUNT_SLOT; assembly { - let count := tload(slot) + let count := tload(NONZERO_DELTA_COUNT_SLOT) count := add(count, 1) - tstore(slot, count) + tstore(NONZERO_DELTA_COUNT_SLOT, count) } } /// @notice Potential to underflow. /// Current usage ensures this will not happen because we call decrement with known boundaries (only up to the number of times we call increment). function decrement() internal { - uint256 slot = NONZERO_DELTA_COUNT_SLOT; assembly { - let count := tload(slot) + let count := tload(NONZERO_DELTA_COUNT_SLOT) count := sub(count, 1) - tstore(slot, count) + tstore(NONZERO_DELTA_COUNT_SLOT, count) } } } diff --git a/src/libraries/Reserves.sol b/src/libraries/Reserves.sol index f6d4eab29..deda07d51 100644 --- a/src/libraries/Reserves.sol +++ b/src/libraries/Reserves.sol @@ -8,7 +8,7 @@ library Reserves { using CustomRevert for bytes4; /// uint256(keccak256("ReservesOf")) - 1 - uint256 constant RESERVES_OF_SLOT = uint256(0x1e0745a7db1623981f0b2a5d4232364c00787266eb75ad546f190e6cebe9bd95); + uint256 constant RESERVES_OF_SLOT = 0x1e0745a7db1623981f0b2a5d4232364c00787266eb75ad546f190e6cebe9bd95; /// @notice The transient reserves for pools with no balance is set to the max as a sentinel to track that it has been synced. uint256 public constant ZERO_BALANCE = type(uint256).max; @@ -33,9 +33,8 @@ library Reserves { } function _getKey(Currency currency) private pure returns (bytes32 key) { - uint256 slot = RESERVES_OF_SLOT; assembly ("memory-safe") { - mstore(0, slot) + mstore(0, RESERVES_OF_SLOT) mstore(32, currency) key := keccak256(0, 64) } diff --git a/src/libraries/TransientStateLibrary.sol b/src/libraries/TransientStateLibrary.sol index 6d746c913..81bfb6212 100644 --- a/src/libraries/TransientStateLibrary.sol +++ b/src/libraries/TransientStateLibrary.sol @@ -24,10 +24,9 @@ library TransientStateLibrary { /// @dev returns 0 if the reserves are not synced /// @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 slot = RESERVES_OF_SLOT; bytes32 key; assembly { - mstore(0, slot) + mstore(0, RESERVES_OF_SLOT) mstore(32, currency) key := keccak256(0, 64) }