// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.13; import "@equilibria/root/accumulator/types/Accumulator6.sol"; import "./OracleVersion.sol"; import "./RiskParameter.sol"; import "./Global.sol"; import "./Local.sol"; import "./Order.sol"; import "./Version.sol"; /// @dev Checkpoint type struct Checkpoint { /// @dev The trade fee that the order incurred at the checkpoint settlement Fixed6 tradeFee; // @dev The settlement and liquidation fee that the order incurred at the checkpoint settlement UFixed6 settlementFee; /// @dev The amount deposited or withdrawn at the checkpoint settlement Fixed6 transfer; /// @dev The collateral at the time of the checkpoint settlement Fixed6 collateral; } struct CheckpointStorage { uint256 slot0; } using CheckpointStorageLib for CheckpointStorage global; /// @dev Manually encodes and decodes the Checkpoint struct into storage. /// /// struct StoredCheckpoint { /// /* slot 0 */ /// int48 tradeFee; /// uint48 settlementFee; /// int64 transfer; /// int64 collateral; /// } /// library CheckpointStorageLib { // sig: 0xba85116a error CheckpointStorageInvalidError(); function read(CheckpointStorage storage self) internal view returns (Checkpoint memory) { uint256 slot0 = self.slot0; return Checkpoint( Fixed6.wrap(int256(slot0 << (256 - 48)) >> (256 - 48)), UFixed6.wrap(uint256(slot0 << (256 - 48 - 48)) >> (256 - 48)), Fixed6.wrap(int256(slot0 << (256 - 48 - 48 - 64)) >> (256 - 64)), Fixed6.wrap(int256(slot0 << (256 - 48 - 48 - 64 - 64)) >> (256 - 64)) ); } function store(CheckpointStorage storage self, Checkpoint memory newValue) external { if (newValue.tradeFee.gt(Fixed6.wrap(type(int48).max))) revert CheckpointStorageInvalidError(); if (newValue.tradeFee.lt(Fixed6.wrap(type(int48).min))) revert CheckpointStorageInvalidError(); if (newValue.settlementFee.gt(UFixed6.wrap(type(uint48).max))) revert CheckpointStorageInvalidError(); if (newValue.transfer.gt(Fixed6.wrap(type(int64).max))) revert CheckpointStorageInvalidError(); if (newValue.transfer.lt(Fixed6.wrap(type(int64).min))) revert CheckpointStorageInvalidError(); if (newValue.collateral.gt(Fixed6.wrap(type(int64).max))) revert CheckpointStorageInvalidError(); if (newValue.collateral.lt(Fixed6.wrap(type(int64).min))) revert CheckpointStorageInvalidError(); uint256 encoded0 = uint256(Fixed6.unwrap(newValue.tradeFee) << (256 - 48)) >> (256 - 48) | uint256(UFixed6.unwrap(newValue.settlementFee) << (256 - 48)) >> (256 - 48 - 48) | uint256(Fixed6.unwrap(newValue.transfer) << (256 - 64)) >> (256 - 48 - 48 - 64) | uint256(Fixed6.unwrap(newValue.collateral) << (256 - 64)) >> (256 - 48 - 48 - 64 - 64); assembly { sstore(self.slot, encoded0) } } }