forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLock.sol
33 lines (28 loc) · 1011 Bytes
/
Lock.sol
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
31
32
33
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
import {IHooks} from "../interfaces/IHooks.sol";
/// @notice This is a temporary library that allows us to use transient storage (tstore/tload)
/// 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);
function unlock() internal {
uint256 slot = IS_UNLOCKED_SLOT;
assembly {
// unlock
tstore(slot, true)
}
}
function lock() internal {
uint256 slot = IS_UNLOCKED_SLOT;
assembly {
tstore(slot, false)
}
}
function isUnlocked() internal view returns (bool unlocked) {
uint256 slot = IS_UNLOCKED_SLOT;
assembly {
unlocked := tload(slot)
}
}
}