github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/dispute/lib/LibUDT.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity ^0.8.15; 3 4 import "src/libraries/DisputeTypes.sol"; 5 6 /// @title LibClock 7 /// @notice This library contains helper functions for working with the `Clock` type. 8 library LibClock { 9 /// @notice Packs a `Duration` and `Timestamp` into a `Clock` type. 10 /// @param _duration The `Duration` to pack into the `Clock` type. 11 /// @param _timestamp The `Timestamp` to pack into the `Clock` type. 12 /// @return clock_ The `Clock` containing the `_duration` and `_timestamp`. 13 function wrap(Duration _duration, Timestamp _timestamp) internal pure returns (Clock clock_) { 14 assembly { 15 clock_ := or(shl(0x40, _duration), _timestamp) 16 } 17 } 18 19 /// @notice Pull the `Duration` out of a `Clock` type. 20 /// @param _clock The `Clock` type to pull the `Duration` out of. 21 /// @return duration_ The `Duration` pulled out of `_clock`. 22 function duration(Clock _clock) internal pure returns (Duration duration_) { 23 // Shift the high-order 64 bits into the low-order 64 bits, leaving only the `duration`. 24 assembly { 25 duration_ := shr(0x40, _clock) 26 } 27 } 28 29 /// @notice Pull the `Timestamp` out of a `Clock` type. 30 /// @param _clock The `Clock` type to pull the `Timestamp` out of. 31 /// @return timestamp_ The `Timestamp` pulled out of `_clock`. 32 function timestamp(Clock _clock) internal pure returns (Timestamp timestamp_) { 33 // Clean the high-order 192 bits by shifting the clock left and then right again, leaving 34 // only the `timestamp`. 35 assembly { 36 timestamp_ := shr(0xC0, shl(0xC0, _clock)) 37 } 38 } 39 40 /// @notice Get the value of a `Clock` type in the form of the underlying uint128. 41 /// @param _clock The `Clock` type to get the value of. 42 /// @return clock_ The value of the `Clock` type as a uint128 type. 43 function raw(Clock _clock) internal pure returns (uint128 clock_) { 44 assembly { 45 clock_ := _clock 46 } 47 } 48 } 49 50 /// @title LibClaim 51 /// @notice This library contains helper functions for working with the `Claim` type. 52 library LibClaim { 53 /// @notice Get the value of a `Claim` type in the form of the underlying bytes32. 54 /// @param _claim The `Claim` type to get the value of. 55 /// @return claim_ The value of the `Claim` type as a bytes32 type. 56 function raw(Claim _claim) internal pure returns (bytes32 claim_) { 57 assembly { 58 claim_ := _claim 59 } 60 } 61 } 62 63 /// @title LibDuration 64 /// @notice This library contains helper functions for working with the `Duration` type. 65 library LibDuration { 66 /// @notice Get the value of a `Duration` type in the form of the underlying uint64. 67 /// @param _duration The `Duration` type to get the value of. 68 /// @return duration_ The value of the `Duration` type as a uint64 type. 69 function raw(Duration _duration) internal pure returns (uint64 duration_) { 70 assembly { 71 duration_ := _duration 72 } 73 } 74 } 75 76 /// @title LibHash 77 /// @notice This library contains helper functions for working with the `Hash` type. 78 library LibHash { 79 /// @notice Get the value of a `Hash` type in the form of the underlying bytes32. 80 /// @param _hash The `Hash` type to get the value of. 81 /// @return hash_ The value of the `Hash` type as a bytes32 type. 82 function raw(Hash _hash) internal pure returns (bytes32 hash_) { 83 assembly { 84 hash_ := _hash 85 } 86 } 87 } 88 89 /// @title LibTimestamp 90 /// @notice This library contains helper functions for working with the `Timestamp` type. 91 library LibTimestamp { 92 /// @notice Get the value of a `Timestamp` type in the form of the underlying uint64. 93 /// @param _timestamp The `Timestamp` type to get the value of. 94 /// @return timestamp_ The value of the `Timestamp` type as a uint64 type. 95 function raw(Timestamp _timestamp) internal pure returns (uint64 timestamp_) { 96 assembly { 97 timestamp_ := _timestamp 98 } 99 } 100 } 101 102 /// @title LibVMStatus 103 /// @notice This library contains helper functions for working with the `VMStatus` type. 104 library LibVMStatus { 105 /// @notice Get the value of a `VMStatus` type in the form of the underlying uint8. 106 /// @param _vmstatus The `VMStatus` type to get the value of. 107 /// @return vmstatus_ The value of the `VMStatus` type as a uint8 type. 108 function raw(VMStatus _vmstatus) internal pure returns (uint8 vmstatus_) { 109 assembly { 110 vmstatus_ := _vmstatus 111 } 112 } 113 } 114 115 /// @title LibGameType 116 /// @notice This library contains helper functions for working with the `GameType` type. 117 library LibGameType { 118 /// @notice Get the value of a `GameType` type in the form of the underlying uint8. 119 /// @param _gametype The `GameType` type to get the value of. 120 /// @return gametype_ The value of the `GameType` type as a uint8 type. 121 function raw(GameType _gametype) internal pure returns (uint8 gametype_) { 122 assembly { 123 gametype_ := _gametype 124 } 125 } 126 }