github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/dispute/lib/LibGameId.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity ^0.8.15; 3 4 import "src/libraries/DisputeTypes.sol"; 5 import "src/dispute/interfaces/IDisputeGame.sol"; 6 7 /// @title LibGameId 8 /// @notice Utility functions for packing and unpacking GameIds. 9 library LibGameId { 10 /// @notice Packs values into a 32 byte GameId type. 11 /// @param _gameType The game type. 12 /// @param _timestamp The timestamp of the game's creation. 13 /// @param _gameProxy The game proxy address. 14 /// @return gameId_ The packed GameId. 15 function pack( 16 GameType _gameType, 17 Timestamp _timestamp, 18 IDisputeGame _gameProxy 19 ) 20 internal 21 pure 22 returns (GameId gameId_) 23 { 24 assembly { 25 gameId_ := or(or(shl(224, _gameType), shl(160, _timestamp)), _gameProxy) 26 } 27 } 28 29 /// @notice Unpacks values from a 32 byte GameId type. 30 /// @param _gameId The packed GameId. 31 /// @return gameType_ The game type. 32 /// @return timestamp_ The timestamp of the game's creation. 33 /// @return gameProxy_ The game proxy address. 34 function unpack(GameId _gameId) 35 internal 36 pure 37 returns (GameType gameType_, Timestamp timestamp_, IDisputeGame gameProxy_) 38 { 39 assembly { 40 gameType_ := shr(224, _gameId) 41 timestamp_ := and(shr(160, _gameId), 0xFFFFFFFFFFFFFFFF) 42 gameProxy_ := and(_gameId, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) 43 } 44 } 45 }